Mercurial > hg > sv-dependency-builds
comparison src/fftw-3.3.8/kernel/pickdim.c @ 82:d0c2a83c1364
Add FFTW 3.3.8 source, and a Linux build
author | Chris Cannam |
---|---|
date | Tue, 19 Nov 2019 14:52:55 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
81:7029a4916348 | 82:d0c2a83c1364 |
---|---|
1 /* | |
2 * Copyright (c) 2003, 2007-14 Matteo Frigo | |
3 * Copyright (c) 2003, 2007-14 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 "kernel/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, size_t nbuddies, | |
64 const tensor *sz, int oop, int *dp) | |
65 { | |
66 size_t i; | |
67 int d1; | |
68 | |
69 if (!really_pickdim(which_dim, sz, oop, dp)) | |
70 return 0; | |
71 | |
72 /* check whether some buddy solver would produce the same dim. | |
73 If so, consider this solver unapplicable and let the buddy | |
74 take care of it. The smallest-indexed buddy is applicable. */ | |
75 for (i = 0; i < nbuddies; ++i) { | |
76 if (buddies[i] == which_dim) | |
77 break; /* found self */ | |
78 if (really_pickdim(buddies[i], sz, oop, &d1) && *dp == d1) | |
79 return 0; /* found equivalent buddy */ | |
80 } | |
81 return 1; | |
82 } |