annotate 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
rev   line source
Chris@82 1 /*
Chris@82 2 * Copyright (c) 2003, 2007-14 Matteo Frigo
Chris@82 3 * Copyright (c) 2003, 2007-14 Massachusetts Institute of Technology
Chris@82 4 *
Chris@82 5 * This program is free software; you can redistribute it and/or modify
Chris@82 6 * it under the terms of the GNU General Public License as published by
Chris@82 7 * the Free Software Foundation; either version 2 of the License, or
Chris@82 8 * (at your option) any later version.
Chris@82 9 *
Chris@82 10 * This program is distributed in the hope that it will be useful,
Chris@82 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@82 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@82 13 * GNU General Public License for more details.
Chris@82 14 *
Chris@82 15 * You should have received a copy of the GNU General Public License
Chris@82 16 * along with this program; if not, write to the Free Software
Chris@82 17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
Chris@82 18 *
Chris@82 19 */
Chris@82 20
Chris@82 21 #include "kernel/ifftw.h"
Chris@82 22
Chris@82 23
Chris@82 24 /* Given a solver which_dim, a vector sz, and whether or not the
Chris@82 25 transform is out-of-place, return the actual dimension index that
Chris@82 26 it corresponds to. The basic idea here is that we return the
Chris@82 27 which_dim'th valid dimension, starting from the end if
Chris@82 28 which_dim < 0. */
Chris@82 29 static int really_pickdim(int which_dim, const tensor *sz, int oop, int *dp)
Chris@82 30 {
Chris@82 31 int i;
Chris@82 32 int count_ok = 0;
Chris@82 33 if (which_dim > 0) {
Chris@82 34 for (i = 0; i < sz->rnk; ++i) {
Chris@82 35 if (oop || sz->dims[i].is == sz->dims[i].os)
Chris@82 36 if (++count_ok == which_dim) {
Chris@82 37 *dp = i;
Chris@82 38 return 1;
Chris@82 39 }
Chris@82 40 }
Chris@82 41 }
Chris@82 42 else if (which_dim < 0) {
Chris@82 43 for (i = sz->rnk - 1; i >= 0; --i) {
Chris@82 44 if (oop || sz->dims[i].is == sz->dims[i].os)
Chris@82 45 if (++count_ok == -which_dim) {
Chris@82 46 *dp = i;
Chris@82 47 return 1;
Chris@82 48 }
Chris@82 49 }
Chris@82 50 }
Chris@82 51 else { /* zero: pick the middle, if valid */
Chris@82 52 i = (sz->rnk - 1) / 2;
Chris@82 53 if (i >= 0 && (oop || sz->dims[i].is == sz->dims[i].os)) {
Chris@82 54 *dp = i;
Chris@82 55 return 1;
Chris@82 56 }
Chris@82 57 }
Chris@82 58 return 0;
Chris@82 59 }
Chris@82 60
Chris@82 61 /* Like really_pickdim, but only returns 1 if no previous "buddy"
Chris@82 62 which_dim in the buddies list would give the same dim. */
Chris@82 63 int X(pickdim)(int which_dim, const int *buddies, size_t nbuddies,
Chris@82 64 const tensor *sz, int oop, int *dp)
Chris@82 65 {
Chris@82 66 size_t i;
Chris@82 67 int d1;
Chris@82 68
Chris@82 69 if (!really_pickdim(which_dim, sz, oop, dp))
Chris@82 70 return 0;
Chris@82 71
Chris@82 72 /* check whether some buddy solver would produce the same dim.
Chris@82 73 If so, consider this solver unapplicable and let the buddy
Chris@82 74 take care of it. The smallest-indexed buddy is applicable. */
Chris@82 75 for (i = 0; i < nbuddies; ++i) {
Chris@82 76 if (buddies[i] == which_dim)
Chris@82 77 break; /* found self */
Chris@82 78 if (really_pickdim(buddies[i], sz, oop, &d1) && *dp == d1)
Chris@82 79 return 0; /* found equivalent buddy */
Chris@82 80 }
Chris@82 81 return 1;
Chris@82 82 }