annotate src/fftw-3.3.8/reodft/rodft00e-r2hc.c @ 169:223a55898ab9 tip default

Add null config files
author Chris Cannam <cannam@all-day-breakfast.com>
date Mon, 02 Mar 2020 14:03:47 +0000
parents bd3cc4d1df30
children
rev   line source
cannam@167 1 /*
cannam@167 2 * Copyright (c) 2003, 2007-14 Matteo Frigo
cannam@167 3 * Copyright (c) 2003, 2007-14 Massachusetts Institute of Technology
cannam@167 4 *
cannam@167 5 * This program is free software; you can redistribute it and/or modify
cannam@167 6 * it under the terms of the GNU General Public License as published by
cannam@167 7 * the Free Software Foundation; either version 2 of the License, or
cannam@167 8 * (at your option) any later version.
cannam@167 9 *
cannam@167 10 * This program is distributed in the hope that it will be useful,
cannam@167 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
cannam@167 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
cannam@167 13 * GNU General Public License for more details.
cannam@167 14 *
cannam@167 15 * You should have received a copy of the GNU General Public License
cannam@167 16 * along with this program; if not, write to the Free Software
cannam@167 17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
cannam@167 18 *
cannam@167 19 */
cannam@167 20
cannam@167 21
cannam@167 22 /* Do a RODFT00 problem via an R2HC problem, with some pre/post-processing.
cannam@167 23
cannam@167 24 This code uses the trick from FFTPACK, also documented in a similar
cannam@167 25 form by Numerical Recipes. Unfortunately, this algorithm seems to
cannam@167 26 have intrinsic numerical problems (similar to those in
cannam@167 27 reodft11e-r2hc.c), possibly due to the fact that it multiplies its
cannam@167 28 input by a sine, causing a loss of precision near the zero. For
cannam@167 29 transforms of 16k points, it has already lost three or four decimal
cannam@167 30 places of accuracy, which we deem unacceptable.
cannam@167 31
cannam@167 32 So, we have abandoned this algorithm in favor of the one in
cannam@167 33 rodft00-r2hc-pad.c, which unfortunately sacrifices 30-50% in speed.
cannam@167 34 The only other alternative in the literature that does not have
cannam@167 35 similar numerical difficulties seems to be the direct adaptation of
cannam@167 36 the Cooley-Tukey decomposition for antisymmetric data, but this
cannam@167 37 would require a whole new set of codelets and it's not clear that
cannam@167 38 it's worth it at this point. However, we did implement the latter
cannam@167 39 algorithm for the specific case of odd n (logically adapting the
cannam@167 40 split-radix algorithm); see reodft00e-splitradix.c. */
cannam@167 41
cannam@167 42 #include "reodft/reodft.h"
cannam@167 43
cannam@167 44 typedef struct {
cannam@167 45 solver super;
cannam@167 46 } S;
cannam@167 47
cannam@167 48 typedef struct {
cannam@167 49 plan_rdft super;
cannam@167 50 plan *cld;
cannam@167 51 twid *td;
cannam@167 52 INT is, os;
cannam@167 53 INT n;
cannam@167 54 INT vl;
cannam@167 55 INT ivs, ovs;
cannam@167 56 } P;
cannam@167 57
cannam@167 58 static void apply(const plan *ego_, R *I, R *O)
cannam@167 59 {
cannam@167 60 const P *ego = (const P *) ego_;
cannam@167 61 INT is = ego->is, os = ego->os;
cannam@167 62 INT i, n = ego->n;
cannam@167 63 INT iv, vl = ego->vl;
cannam@167 64 INT ivs = ego->ivs, ovs = ego->ovs;
cannam@167 65 R *W = ego->td->W;
cannam@167 66 R *buf;
cannam@167 67
cannam@167 68 buf = (R *) MALLOC(sizeof(R) * n, BUFFERS);
cannam@167 69
cannam@167 70 for (iv = 0; iv < vl; ++iv, I += ivs, O += ovs) {
cannam@167 71 buf[0] = 0;
cannam@167 72 for (i = 1; i < n - i; ++i) {
cannam@167 73 E a, b, apb, amb;
cannam@167 74 a = I[is * (i - 1)];
cannam@167 75 b = I[is * ((n - i) - 1)];
cannam@167 76 apb = K(2.0) * W[i] * (a + b);
cannam@167 77 amb = (a - b);
cannam@167 78 buf[i] = apb + amb;
cannam@167 79 buf[n - i] = apb - amb;
cannam@167 80 }
cannam@167 81 if (i == n - i) {
cannam@167 82 buf[i] = K(4.0) * I[is * (i - 1)];
cannam@167 83 }
cannam@167 84
cannam@167 85 {
cannam@167 86 plan_rdft *cld = (plan_rdft *) ego->cld;
cannam@167 87 cld->apply((plan *) cld, buf, buf);
cannam@167 88 }
cannam@167 89
cannam@167 90 /* FIXME: use recursive/cascade summation for better stability? */
cannam@167 91 O[0] = buf[0] * 0.5;
cannam@167 92 for (i = 1; i + i < n - 1; ++i) {
cannam@167 93 INT k = i + i;
cannam@167 94 O[os * (k - 1)] = -buf[n - i];
cannam@167 95 O[os * k] = O[os * (k - 2)] + buf[i];
cannam@167 96 }
cannam@167 97 if (i + i == n - 1) {
cannam@167 98 O[os * (n - 2)] = -buf[n - i];
cannam@167 99 }
cannam@167 100 }
cannam@167 101
cannam@167 102 X(ifree)(buf);
cannam@167 103 }
cannam@167 104
cannam@167 105 static void awake(plan *ego_, enum wakefulness wakefulness)
cannam@167 106 {
cannam@167 107 P *ego = (P *) ego_;
cannam@167 108 static const tw_instr rodft00e_tw[] = {
cannam@167 109 { TW_SIN, 0, 1 },
cannam@167 110 { TW_NEXT, 1, 0 }
cannam@167 111 };
cannam@167 112
cannam@167 113 X(plan_awake)(ego->cld, wakefulness);
cannam@167 114
cannam@167 115 X(twiddle_awake)(wakefulness,
cannam@167 116 &ego->td, rodft00e_tw, 2*ego->n, 1, (ego->n+1)/2);
cannam@167 117 }
cannam@167 118
cannam@167 119 static void destroy(plan *ego_)
cannam@167 120 {
cannam@167 121 P *ego = (P *) ego_;
cannam@167 122 X(plan_destroy_internal)(ego->cld);
cannam@167 123 }
cannam@167 124
cannam@167 125 static void print(const plan *ego_, printer *p)
cannam@167 126 {
cannam@167 127 const P *ego = (const P *) ego_;
cannam@167 128 p->print(p, "(rodft00e-r2hc-%D%v%(%p%))", ego->n - 1, ego->vl, ego->cld);
cannam@167 129 }
cannam@167 130
cannam@167 131 static int applicable0(const solver *ego_, const problem *p_)
cannam@167 132 {
cannam@167 133 const problem_rdft *p = (const problem_rdft *) p_;
cannam@167 134 UNUSED(ego_);
cannam@167 135
cannam@167 136 return (1
cannam@167 137 && p->sz->rnk == 1
cannam@167 138 && p->vecsz->rnk <= 1
cannam@167 139 && p->kind[0] == RODFT00
cannam@167 140 );
cannam@167 141 }
cannam@167 142
cannam@167 143 static int applicable(const solver *ego, const problem *p, const planner *plnr)
cannam@167 144 {
cannam@167 145 return (!NO_SLOWP(plnr) && applicable0(ego, p));
cannam@167 146 }
cannam@167 147
cannam@167 148 static plan *mkplan(const solver *ego_, const problem *p_, planner *plnr)
cannam@167 149 {
cannam@167 150 P *pln;
cannam@167 151 const problem_rdft *p;
cannam@167 152 plan *cld;
cannam@167 153 R *buf;
cannam@167 154 INT n;
cannam@167 155 opcnt ops;
cannam@167 156
cannam@167 157 static const plan_adt padt = {
cannam@167 158 X(rdft_solve), awake, print, destroy
cannam@167 159 };
cannam@167 160
cannam@167 161 if (!applicable(ego_, p_, plnr))
cannam@167 162 return (plan *)0;
cannam@167 163
cannam@167 164 p = (const problem_rdft *) p_;
cannam@167 165
cannam@167 166 n = p->sz->dims[0].n + 1;
cannam@167 167 buf = (R *) MALLOC(sizeof(R) * n, BUFFERS);
cannam@167 168
cannam@167 169 cld = X(mkplan_d)(plnr, X(mkproblem_rdft_1_d)(X(mktensor_1d)(n, 1, 1),
cannam@167 170 X(mktensor_0d)(),
cannam@167 171 buf, buf, R2HC));
cannam@167 172 X(ifree)(buf);
cannam@167 173 if (!cld)
cannam@167 174 return (plan *)0;
cannam@167 175
cannam@167 176 pln = MKPLAN_RDFT(P, &padt, apply);
cannam@167 177
cannam@167 178 pln->n = n;
cannam@167 179 pln->is = p->sz->dims[0].is;
cannam@167 180 pln->os = p->sz->dims[0].os;
cannam@167 181 pln->cld = cld;
cannam@167 182 pln->td = 0;
cannam@167 183
cannam@167 184 X(tensor_tornk1)(p->vecsz, &pln->vl, &pln->ivs, &pln->ovs);
cannam@167 185
cannam@167 186 X(ops_zero)(&ops);
cannam@167 187 ops.other = 4 + (n-1)/2 * 5 + (n-2)/2 * 5;
cannam@167 188 ops.add = (n-1)/2 * 4 + (n-2)/2 * 1;
cannam@167 189 ops.mul = 1 + (n-1)/2 * 2;
cannam@167 190 if (n % 2 == 0)
cannam@167 191 ops.mul += 1;
cannam@167 192
cannam@167 193 X(ops_zero)(&pln->super.super.ops);
cannam@167 194 X(ops_madd2)(pln->vl, &ops, &pln->super.super.ops);
cannam@167 195 X(ops_madd2)(pln->vl, &cld->ops, &pln->super.super.ops);
cannam@167 196
cannam@167 197 return &(pln->super.super);
cannam@167 198 }
cannam@167 199
cannam@167 200 /* constructor */
cannam@167 201 static solver *mksolver(void)
cannam@167 202 {
cannam@167 203 static const solver_adt sadt = { PROBLEM_RDFT, mkplan, 0 };
cannam@167 204 S *slv = MKSOLVER(S, &sadt);
cannam@167 205 return &(slv->super);
cannam@167 206 }
cannam@167 207
cannam@167 208 void X(rodft00e_r2hc_register)(planner *p)
cannam@167 209 {
cannam@167 210 REGISTER_SOLVER(p, mksolver());
cannam@167 211 }