Coverage Report

Created: 2026-05-30 06:15

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/fftw3/kernel/pickdim.c
Line
Count
Source
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
2.07k
{
31
2.07k
     int i;
32
2.07k
     int count_ok = 0;
33
2.07k
     if (which_dim > 0) {
34
2.18k
          for (i = 0; i < sz->rnk; ++i) {
35
2.02k
               if (oop || sz->dims[i].is == sz->dims[i].os)
36
1.22k
                    if (++count_ok == which_dim) {
37
1.22k
                         *dp = i;
38
1.22k
                         return 1;
39
1.22k
                    }
40
2.02k
          }
41
1.38k
     }
42
689
     else if (which_dim < 0) {
43
862
          for (i = sz->rnk - 1; i >= 0; --i) {
44
701
               if (oop || sz->dims[i].is == sz->dims[i].os)
45
528
                    if (++count_ok == -which_dim) {
46
528
                         *dp = i;
47
528
                         return 1;
48
528
                    }
49
701
          }
50
689
     }
51
0
     else { /* zero: pick the middle, if valid */
52
0
    i = (sz->rnk - 1) / 2;
53
0
    if (i >= 0 && (oop || sz->dims[i].is == sz->dims[i].os)) {
54
0
         *dp = i;
55
0
         return 1;
56
0
    }
57
0
     }
58
322
     return 0;
59
2.07k
}
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
1.54k
{
66
1.54k
     size_t i;
67
1.54k
     int d1;
68
69
1.54k
     if (!really_pickdim(which_dim, sz, oop, dp))
70
322
          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
1.40k
     for (i = 0; i < nbuddies; ++i) {
76
1.40k
          if (buddies[i] == which_dim)
77
873
               break;  /* found self */
78
528
          if (really_pickdim(buddies[i], sz, oop, &d1) && *dp == d1)
79
349
               return 0; /* found equivalent buddy */
80
528
     }
81
873
     return 1;
82
1.22k
}