annotate src/fftw-3.3.5/kernel/pickdim.c @ 83:ae30d91d2ffe

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