2
* Copyright (c) 2003, 2006 Matteo Frigo
3
* Copyright (c) 2003, 2006 Massachusetts Institute of Technology
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.
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.
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23
/* $Id: pickdim.c,v 1.6 2006-01-05 03:04:27 stevenj Exp $ */
25
/* Given a solver which_dim, a vector sz, and whether or not the
26
transform is out-of-place, return the actual dimension index that
27
it corresponds to. The basic idea here is that we return the
28
which_dim'th valid dimension, starting from the end if
30
static int really_pickdim(int which_dim, const tensor *sz, int oop, int *dp)
35
for (i = 0; i < sz->rnk; ++i) {
36
if (oop || sz->dims[i].is == sz->dims[i].os)
37
if (++count_ok == which_dim) {
43
else if (which_dim < 0) {
44
for (i = sz->rnk - 1; i >= 0; --i) {
45
if (oop || sz->dims[i].is == sz->dims[i].os)
46
if (++count_ok == -which_dim) {
52
else { /* zero: pick the middle, if valid */
53
i = (sz->rnk - 1) / 2;
54
if (i >= 0 && (oop || sz->dims[i].is == sz->dims[i].os)) {
62
/* Like really_pickdim, but only returns 1 if no previous "buddy"
63
which_dim in the buddies list would give the same dim. */
64
int X(pickdim)(int which_dim, const int *buddies, int nbuddies,
65
const tensor *sz, int oop, int *dp)
69
if (!really_pickdim(which_dim, sz, oop, dp))
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 */