Coverage Report

Created: 2026-03-07 06:53

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.03k
{
31
2.03k
     int i;
32
2.03k
     int count_ok = 0;
33
2.03k
     if (which_dim > 0) {
34
2.15k
          for (i = 0; i < sz->rnk; ++i) {
35
1.99k
               if (oop || sz->dims[i].is == sz->dims[i].os)
36
1.20k
                    if (++count_ok == which_dim) {
37
1.20k
                         *dp = i;
38
1.20k
                         return 1;
39
1.20k
                    }
40
1.99k
          }
41
1.36k
     }
42
675
     else if (which_dim < 0) {
43
845
          for (i = sz->rnk - 1; i >= 0; --i) {
44
687
               if (oop || sz->dims[i].is == sz->dims[i].os)
45
517
                    if (++count_ok == -which_dim) {
46
517
                         *dp = i;
47
517
                         return 1;
48
517
                    }
49
687
          }
50
675
     }
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
316
     return 0;
59
2.03k
}
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.52k
{
66
1.52k
     size_t i;
67
1.52k
     int d1;
68
69
1.52k
     if (!really_pickdim(which_dim, sz, oop, dp))
70
316
          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.38k
     for (i = 0; i < nbuddies; ++i) {
76
1.38k
          if (buddies[i] == which_dim)
77
866
               break;  /* found self */
78
517
          if (really_pickdim(buddies[i], sz, oop, &d1) && *dp == d1)
79
340
               return 0; /* found equivalent buddy */
80
517
     }
81
866
     return 1;
82
1.20k
}