comparison src/fftw-3.3.3/kernel/tensor.c @ 10:37bf6b4a2645

Add FFTW3
author Chris Cannam
date Wed, 20 Mar 2013 15:35:50 +0000
parents
children
comparison
equal deleted inserted replaced
9:c0fb53affa76 10:37bf6b4a2645
1 /*
2 * Copyright (c) 2003, 2007-11 Matteo Frigo
3 * Copyright (c) 2003, 2007-11 Massachusetts Institute of Technology
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 *
19 */
20
21
22 #include "ifftw.h"
23
24 tensor *X(mktensor)(int rnk)
25 {
26 tensor *x;
27
28 A(rnk >= 0);
29
30 #if defined(STRUCT_HACK_KR)
31 if (FINITE_RNK(rnk) && rnk > 1)
32 x = (tensor *)MALLOC(sizeof(tensor) + (rnk - 1) * sizeof(iodim),
33 TENSORS);
34 else
35 x = (tensor *)MALLOC(sizeof(tensor), TENSORS);
36 #elif defined(STRUCT_HACK_C99)
37 if (FINITE_RNK(rnk))
38 x = (tensor *)MALLOC(sizeof(tensor) + rnk * sizeof(iodim),
39 TENSORS);
40 else
41 x = (tensor *)MALLOC(sizeof(tensor), TENSORS);
42 #else
43 x = (tensor *)MALLOC(sizeof(tensor), TENSORS);
44 if (FINITE_RNK(rnk) && rnk > 0)
45 x->dims = (iodim *)MALLOC(sizeof(iodim) * rnk, TENSORS);
46 else
47 x->dims = 0;
48 #endif
49
50 x->rnk = rnk;
51 return x;
52 }
53
54 void X(tensor_destroy)(tensor *sz)
55 {
56 #if !defined(STRUCT_HACK_C99) && !defined(STRUCT_HACK_KR)
57 X(ifree0)(sz->dims);
58 #endif
59 X(ifree)(sz);
60 }
61
62 INT X(tensor_sz)(const tensor *sz)
63 {
64 int i;
65 INT n = 1;
66
67 if (!FINITE_RNK(sz->rnk))
68 return 0;
69
70 for (i = 0; i < sz->rnk; ++i)
71 n *= sz->dims[i].n;
72 return n;
73 }
74
75 void X(tensor_md5)(md5 *p, const tensor *t)
76 {
77 int i;
78 X(md5int)(p, t->rnk);
79 if (FINITE_RNK(t->rnk)) {
80 for (i = 0; i < t->rnk; ++i) {
81 const iodim *q = t->dims + i;
82 X(md5INT)(p, q->n);
83 X(md5INT)(p, q->is);
84 X(md5INT)(p, q->os);
85 }
86 }
87 }
88
89 /* treat a (rank <= 1)-tensor as a rank-1 tensor, extracting
90 appropriate n, is, and os components */
91 int X(tensor_tornk1)(const tensor *t, INT *n, INT *is, INT *os)
92 {
93 A(t->rnk <= 1);
94 if (t->rnk == 1) {
95 const iodim *vd = t->dims;
96 *n = vd[0].n;
97 *is = vd[0].is;
98 *os = vd[0].os;
99 } else {
100 *n = 1;
101 *is = *os = 0;
102 }
103 return 1;
104 }
105
106 void X(tensor_print)(const tensor *x, printer *p)
107 {
108 if (FINITE_RNK(x->rnk)) {
109 int i;
110 int first = 1;
111 p->print(p, "(");
112 for (i = 0; i < x->rnk; ++i) {
113 const iodim *d = x->dims + i;
114 p->print(p, "%s(%D %D %D)",
115 first ? "" : " ",
116 d->n, d->is, d->os);
117 first = 0;
118 }
119 p->print(p, ")");
120 } else {
121 p->print(p, "rank-minfty");
122 }
123 }