forked from FFTW/fftw3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrodft00e-r2hc.c
190 lines (157 loc) · 4.53 KB
/
rodft00e-r2hc.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
/*
* Copyright (c) 2002 Matteo Frigo
* Copyright (c) 2002 Steven G. Johnson
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
/* $Id: rodft00e-r2hc.c,v 1.20 2003-01-15 11:51:34 athena Exp $ */
/* Do a RODFT00 problem via an R2HC problem, with some pre/post-processing. */
#include "reodft.h"
typedef struct {
solver super;
} S;
typedef struct {
plan_rdft super;
plan *cld;
twid *td;
int is, os;
int n;
int vl;
int ivs, ovs;
} P;
/* Use the trick from FFTPACK, also documented in a similar form
by Numerical Recipes. */
static void apply(plan *ego_, R *I, R *O)
{
P *ego = (P *) ego_;
int is = ego->is, os = ego->os;
int i, n = ego->n;
int iv, vl = ego->vl;
int ivs = ego->ivs, ovs = ego->ovs;
R *W = ego->td->W;
R *buf;
buf = (R *) MALLOC(sizeof(R) * n, BUFFERS);
for (iv = 0; iv < vl; ++iv, I += ivs, O += ovs) {
buf[0] = 0;
for (i = 1; i < n - i; ++i) {
E a, b, apb, amb;
a = I[is * (i - 1)];
b = I[is * ((n - i) - 1)];
apb = 2.0 * W[i] * (a + b);
amb = (a - b);
buf[i] = apb + amb;
buf[n - i] = apb - amb;
}
if (i == n - i) {
buf[i] = 4.0 * I[is * (i - 1)];
}
{
plan_rdft *cld = (plan_rdft *) ego->cld;
cld->apply((plan *) cld, buf, buf);
}
/* FIXME: use recursive/cascade summation for better stability? */
O[0] = buf[0] * 0.5;
for (i = 1; i + i < n - 1; ++i) {
int k = i + i;
O[os * (k - 1)] = -buf[n - i];
O[os * k] = O[os * (k - 2)] + buf[i];
}
if (i + i == n - 1) {
O[os * (n - 2)] = -buf[n - i];
}
}
X(ifree)(buf);
}
static void awake(plan *ego_, int flg)
{
P *ego = (P *) ego_;
static const tw_instr rodft00e_tw[] = {
{ TW_SIN, 0, 1 },
{ TW_NEXT, 1, 0 }
};
AWAKE(ego->cld, flg);
X(twiddle_awake)(flg, &ego->td, rodft00e_tw, 2*ego->n, 1, (ego->n+1)/2);
}
static void destroy(plan *ego_)
{
P *ego = (P *) ego_;
X(plan_destroy_internal)(ego->cld);
}
static void print(plan *ego_, printer *p)
{
P *ego = (P *) ego_;
p->print(p, "(rodft00e-r2hc-%d%v%(%p%))", ego->n - 1, ego->vl, ego->cld);
}
static int applicable0(const solver *ego_, const problem *p_)
{
UNUSED(ego_);
if (RDFTP(p_)) {
const problem_rdft *p = (const problem_rdft *) p_;
return (1
&& p->sz->rnk == 1
&& p->vecsz->rnk <= 1
&& p->kind[0] == RODFT00
);
}
return 0;
}
static int applicable(const solver *ego, const problem *p, const planner *plnr)
{
return (!NO_UGLYP(plnr) && applicable0(ego, p));
}
static plan *mkplan(const solver *ego_, const problem *p_, planner *plnr)
{
P *pln;
const problem_rdft *p;
plan *cld;
R *buf;
int n;
static const plan_adt padt = {
X(rdft_solve), awake, print, destroy
};
if (!applicable(ego_, p_, plnr))
return (plan *)0;
p = (const problem_rdft *) p_;
n = p->sz->dims[0].n + 1;
buf = (R *) MALLOC(sizeof(R) * n, BUFFERS);
cld = X(mkplan_d)(plnr, X(mkproblem_rdft_1_d)(X(mktensor_1d)(n, 1, 1),
X(mktensor_0d)(),
buf, buf, R2HC));
X(ifree)(buf);
if (!cld)
return (plan *)0;
pln = MKPLAN_RDFT(P, &padt, apply);
pln->n = n;
pln->is = p->sz->dims[0].is;
pln->os = p->sz->dims[0].os;
pln->cld = cld;
pln->td = 0;
X(tensor_tornk1)(p->vecsz, &pln->vl, &pln->ivs, &pln->ovs);
pln->super.super.ops = cld->ops;
/* FIXME */
return &(pln->super.super);
}
/* constructor */
static solver *mksolver(void)
{
static const solver_adt sadt = { mkplan };
S *slv = MKSOLVER(S, &sadt);
return &(slv->super);
}
void X(rodft00e_r2hc_register)(planner *p)
{
REGISTER_SOLVER(p, mksolver());
}