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