Chris@10
|
1 /*
|
Chris@10
|
2 * Copyright (c) 2003, 2007-11 Matteo Frigo
|
Chris@10
|
3 * Copyright (c) 2003, 2007-11 Massachusetts Institute of Technology
|
Chris@10
|
4 *
|
Chris@10
|
5 * This program is free software; you can redistribute it and/or modify
|
Chris@10
|
6 * it under the terms of the GNU General Public License as published by
|
Chris@10
|
7 * the Free Software Foundation; either version 2 of the License, or
|
Chris@10
|
8 * (at your option) any later version.
|
Chris@10
|
9 *
|
Chris@10
|
10 * This program is distributed in the hope that it will be useful,
|
Chris@10
|
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
Chris@10
|
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
Chris@10
|
13 * GNU General Public License for more details.
|
Chris@10
|
14 *
|
Chris@10
|
15 * You should have received a copy of the GNU General Public License
|
Chris@10
|
16 * along with this program; if not, write to the Free Software
|
Chris@10
|
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
Chris@10
|
18 *
|
Chris@10
|
19 */
|
Chris@10
|
20
|
Chris@10
|
21
|
Chris@10
|
22 #include "ifftw.h"
|
Chris@10
|
23
|
Chris@10
|
24 static void dimcpy(iodim *dst, const iodim *src, int rnk)
|
Chris@10
|
25 {
|
Chris@10
|
26 int i;
|
Chris@10
|
27 if (FINITE_RNK(rnk))
|
Chris@10
|
28 for (i = 0; i < rnk; ++i)
|
Chris@10
|
29 dst[i] = src[i];
|
Chris@10
|
30 }
|
Chris@10
|
31
|
Chris@10
|
32 tensor *X(tensor_copy)(const tensor *sz)
|
Chris@10
|
33 {
|
Chris@10
|
34 tensor *x = X(mktensor)(sz->rnk);
|
Chris@10
|
35 dimcpy(x->dims, sz->dims, sz->rnk);
|
Chris@10
|
36 return x;
|
Chris@10
|
37 }
|
Chris@10
|
38
|
Chris@10
|
39 /* like X(tensor_copy), but makes strides in-place by
|
Chris@10
|
40 setting os = is if k == INPLACE_IS or is = os if k == INPLACE_OS. */
|
Chris@10
|
41 tensor *X(tensor_copy_inplace)(const tensor *sz, inplace_kind k)
|
Chris@10
|
42 {
|
Chris@10
|
43 tensor *x = X(tensor_copy)(sz);
|
Chris@10
|
44 if (FINITE_RNK(x->rnk)) {
|
Chris@10
|
45 int i;
|
Chris@10
|
46 if (k == INPLACE_OS)
|
Chris@10
|
47 for (i = 0; i < x->rnk; ++i)
|
Chris@10
|
48 x->dims[i].is = x->dims[i].os;
|
Chris@10
|
49 else
|
Chris@10
|
50 for (i = 0; i < x->rnk; ++i)
|
Chris@10
|
51 x->dims[i].os = x->dims[i].is;
|
Chris@10
|
52 }
|
Chris@10
|
53 return x;
|
Chris@10
|
54 }
|
Chris@10
|
55
|
Chris@10
|
56 /* Like X(tensor_copy), but copy all of the dimensions *except*
|
Chris@10
|
57 except_dim. */
|
Chris@10
|
58 tensor *X(tensor_copy_except)(const tensor *sz, int except_dim)
|
Chris@10
|
59 {
|
Chris@10
|
60 tensor *x;
|
Chris@10
|
61
|
Chris@10
|
62 A(FINITE_RNK(sz->rnk) && sz->rnk >= 1 && except_dim < sz->rnk);
|
Chris@10
|
63 x = X(mktensor)(sz->rnk - 1);
|
Chris@10
|
64 dimcpy(x->dims, sz->dims, except_dim);
|
Chris@10
|
65 dimcpy(x->dims + except_dim, sz->dims + except_dim + 1,
|
Chris@10
|
66 x->rnk - except_dim);
|
Chris@10
|
67 return x;
|
Chris@10
|
68 }
|
Chris@10
|
69
|
Chris@10
|
70 /* Like X(tensor_copy), but copy only rnk dimensions starting
|
Chris@10
|
71 with start_dim. */
|
Chris@10
|
72 tensor *X(tensor_copy_sub)(const tensor *sz, int start_dim, int rnk)
|
Chris@10
|
73 {
|
Chris@10
|
74 tensor *x;
|
Chris@10
|
75
|
Chris@10
|
76 A(FINITE_RNK(sz->rnk) && start_dim + rnk <= sz->rnk);
|
Chris@10
|
77 x = X(mktensor)(rnk);
|
Chris@10
|
78 dimcpy(x->dims, sz->dims + start_dim, rnk);
|
Chris@10
|
79 return x;
|
Chris@10
|
80 }
|
Chris@10
|
81
|
Chris@10
|
82 tensor *X(tensor_append)(const tensor *a, const tensor *b)
|
Chris@10
|
83 {
|
Chris@10
|
84 if (!FINITE_RNK(a->rnk) || !FINITE_RNK(b->rnk)) {
|
Chris@10
|
85 return X(mktensor)(RNK_MINFTY);
|
Chris@10
|
86 } else {
|
Chris@10
|
87 tensor *x = X(mktensor)(a->rnk + b->rnk);
|
Chris@10
|
88 dimcpy(x->dims, a->dims, a->rnk);
|
Chris@10
|
89 dimcpy(x->dims + a->rnk, b->dims, b->rnk);
|
Chris@10
|
90 return x;
|
Chris@10
|
91 }
|
Chris@10
|
92 }
|