Coverage Report

Created: 2025-06-22 06:45

/src/fftw3/reodft/redft00e-r2hc-pad.c
Line
Count
Source (jump to first uncovered line)
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
22
/* Do a REDFT00 problem via an R2HC problem, padded symmetrically to
23
   twice the size.  This is asymptotically a factor of ~2 worse than
24
   redft00e-r2hc.c (the algorithm used in e.g. FFTPACK and Numerical
25
   Recipes), but we abandoned the latter after we discovered that it
26
   has intrinsic accuracy problems. */
27
28
#include "reodft/reodft.h"
29
30
typedef struct {
31
     solver super;
32
} S;
33
34
typedef struct {
35
     plan_rdft super;
36
     plan *cld, *cldcpy;
37
     INT is;
38
     INT n;
39
     INT vl;
40
     INT ivs, ovs;
41
} P;
42
43
static void apply(const plan *ego_, R *I, R *O)
44
0
{
45
0
     const P *ego = (const P *) ego_;
46
0
     INT is = ego->is;
47
0
     INT i, n = ego->n;
48
0
     INT iv, vl = ego->vl;
49
0
     INT ivs = ego->ivs, ovs = ego->ovs;
50
0
     R *buf;
51
52
0
     buf = (R *) MALLOC(sizeof(R) * (2*n), BUFFERS);
53
54
0
     for (iv = 0; iv < vl; ++iv, I += ivs, O += ovs) {
55
0
    buf[0] = I[0];
56
0
    for (i = 1; i < n; ++i) {
57
0
         R a = I[i * is];
58
0
         buf[i] = a;
59
0
         buf[2*n - i] = a;
60
0
    }
61
0
    buf[i] = I[i * is]; /* i == n, Nyquist */
62
    
63
    /* r2hc transform of size 2*n */
64
0
    {
65
0
         plan_rdft *cld = (plan_rdft *) ego->cld;
66
0
         cld->apply((plan *) cld, buf, buf);
67
0
    }
68
    
69
    /* copy n+1 real numbers (real parts of hc array) from buf to O */
70
0
    {
71
0
         plan_rdft *cldcpy = (plan_rdft *) ego->cldcpy;
72
0
         cldcpy->apply((plan *) cldcpy, buf, O);
73
0
    }
74
0
     }
75
76
0
     X(ifree)(buf);
77
0
}
78
79
static void awake(plan *ego_, enum wakefulness wakefulness)
80
0
{
81
0
     P *ego = (P *) ego_;
82
0
     X(plan_awake)(ego->cld, wakefulness);
83
0
     X(plan_awake)(ego->cldcpy, wakefulness);
84
0
}
85
86
static void destroy(plan *ego_)
87
0
{
88
0
     P *ego = (P *) ego_;
89
0
     X(plan_destroy_internal)(ego->cldcpy);
90
0
     X(plan_destroy_internal)(ego->cld);
91
0
}
92
93
static void print(const plan *ego_, printer *p)
94
0
{
95
0
     const P *ego = (const P *) ego_;
96
0
     p->print(p, "(redft00e-r2hc-pad-%D%v%(%p%)%(%p%))", 
97
0
        ego->n + 1, ego->vl, ego->cld, ego->cldcpy);
98
0
}
99
100
static int applicable0(const solver *ego_, const problem *p_)
101
0
{
102
0
     const problem_rdft *p = (const problem_rdft *) p_;
103
0
     UNUSED(ego_);
104
105
0
     return (1
106
0
       && p->sz->rnk == 1
107
0
       && p->vecsz->rnk <= 1
108
0
       && p->kind[0] == REDFT00
109
0
       && p->sz->dims[0].n > 1  /* n == 1 is not well-defined */
110
0
    );
111
0
}
112
113
static int applicable(const solver *ego, const problem *p, const planner *plnr)
114
327
{
115
327
     return (!NO_SLOWP(plnr) && applicable0(ego, p));
116
327
}
117
118
static plan *mkplan(const solver *ego_, const problem *p_, planner *plnr)
119
327
{
120
327
     P *pln;
121
327
     const problem_rdft *p;
122
327
     plan *cld = (plan *) 0, *cldcpy;
123
327
     R *buf = (R *) 0;
124
327
     INT n;
125
327
     INT vl, ivs, ovs;
126
327
     opcnt ops;
127
128
327
     static const plan_adt padt = {
129
327
    X(rdft_solve), awake, print, destroy
130
327
     };
131
132
327
     if (!applicable(ego_, p_, plnr))
133
327
    goto nada;
134
135
0
     p = (const problem_rdft *) p_;
136
137
0
     n = p->sz->dims[0].n - 1;
138
0
     A(n > 0);
139
0
     buf = (R *) MALLOC(sizeof(R) * (2*n), BUFFERS);
140
141
0
     cld = X(mkplan_d)(plnr,X(mkproblem_rdft_1_d)(X(mktensor_1d)(2*n,1,1), 
142
0
              X(mktensor_0d)(), 
143
0
              buf, buf, R2HC));
144
0
     if (!cld)
145
0
    goto nada;
146
147
0
     X(tensor_tornk1)(p->vecsz, &vl, &ivs, &ovs);
148
0
     cldcpy =
149
0
    X(mkplan_d)(plnr,
150
0
          X(mkproblem_rdft_1_d)(X(mktensor_0d)(),
151
0
              X(mktensor_1d)(n+1,1,
152
0
                 p->sz->dims[0].os), 
153
0
              buf, TAINT(p->O, ovs), R2HC));
154
0
     if (!cldcpy)
155
0
    goto nada;
156
157
0
     X(ifree)(buf);
158
159
0
     pln = MKPLAN_RDFT(P, &padt, apply);
160
161
0
     pln->n = n;
162
0
     pln->is = p->sz->dims[0].is;
163
0
     pln->cld = cld;
164
0
     pln->cldcpy = cldcpy;
165
0
     pln->vl = vl;
166
0
     pln->ivs = ivs;
167
0
     pln->ovs = ovs;
168
     
169
0
     X(ops_zero)(&ops);
170
0
     ops.other = n + 2*n; /* loads + stores (input -> buf) */
171
172
0
     X(ops_zero)(&pln->super.super.ops);
173
0
     X(ops_madd2)(pln->vl, &ops, &pln->super.super.ops);
174
0
     X(ops_madd2)(pln->vl, &cld->ops, &pln->super.super.ops);
175
0
     X(ops_madd2)(pln->vl, &cldcpy->ops, &pln->super.super.ops);
176
177
0
     return &(pln->super.super);
178
179
327
 nada:
180
327
     X(ifree0)(buf);
181
327
     if (cld)
182
0
    X(plan_destroy_internal)(cld);  
183
327
     return (plan *)0;
184
0
}
185
186
/* constructor */
187
static solver *mksolver(void)
188
1
{
189
1
     static const solver_adt sadt = { PROBLEM_RDFT, mkplan, 0 };
190
1
     S *slv = MKSOLVER(S, &sadt);
191
1
     return &(slv->super);
192
1
}
193
194
void X(redft00e_r2hc_pad_register)(planner *p)
195
1
{
196
1
     REGISTER_SOLVER(p, mksolver());
197
1
}