comparison src/fftw-3.3.3/kernel/pickdim.c @ 95:89f5e221ed7b

Add FFTW3
author Chris Cannam <cannam@all-day-breakfast.com>
date Wed, 20 Mar 2013 15:35:50 +0000
parents
children
comparison
equal deleted inserted replaced
94:d278df1123f9 95:89f5e221ed7b
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 #include "ifftw.h"
22
23
24 /* Given a solver which_dim, a vector sz, and whether or not the
25 transform is out-of-place, return the actual dimension index that
26 it corresponds to. The basic idea here is that we return the
27 which_dim'th valid dimension, starting from the end if
28 which_dim < 0. */
29 static int really_pickdim(int which_dim, const tensor *sz, int oop, int *dp)
30 {
31 int i;
32 int count_ok = 0;
33 if (which_dim > 0) {
34 for (i = 0; i < sz->rnk; ++i) {
35 if (oop || sz->dims[i].is == sz->dims[i].os)
36 if (++count_ok == which_dim) {
37 *dp = i;
38 return 1;
39 }
40 }
41 }
42 else if (which_dim < 0) {
43 for (i = sz->rnk - 1; i >= 0; --i) {
44 if (oop || sz->dims[i].is == sz->dims[i].os)
45 if (++count_ok == -which_dim) {
46 *dp = i;
47 return 1;
48 }
49 }
50 }
51 else { /* zero: pick the middle, if valid */
52 i = (sz->rnk - 1) / 2;
53 if (i >= 0 && (oop || sz->dims[i].is == sz->dims[i].os)) {
54 *dp = i;
55 return 1;
56 }
57 }
58 return 0;
59 }
60
61 /* Like really_pickdim, but only returns 1 if no previous "buddy"
62 which_dim in the buddies list would give the same dim. */
63 int X(pickdim)(int which_dim, const int *buddies, int nbuddies,
64 const tensor *sz, int oop, int *dp)
65 {
66 int i, d1;
67
68 if (!really_pickdim(which_dim, sz, oop, dp))
69 return 0;
70
71 /* check whether some buddy solver would produce the same dim.
72 If so, consider this solver unapplicable and let the buddy
73 take care of it. The smallest-indexed buddy is applicable. */
74 for (i = 0; i < nbuddies; ++i) {
75 if (buddies[i] == which_dim)
76 break; /* found self */
77 if (really_pickdim(buddies[i], sz, oop, &d1) && *dp == d1)
78 return 0; /* found equivalent buddy */
79 }
80 return 1;
81 }