annotate fft/fftw/fftw-3.3.4/reodft/rodft00e-r2hc-pad.c @ 40:223f770b5341 kissfft-double tip

Try a double-precision kissfft
author Chris Cannam
date Wed, 07 Sep 2016 10:40:32 +0100
parents 26056e866c29
children
rev   line source
Chris@19 1 /*
Chris@19 2 * Copyright (c) 2003, 2007-14 Matteo Frigo
Chris@19 3 * Copyright (c) 2003, 2007-14 Massachusetts Institute of Technology
Chris@19 4 *
Chris@19 5 * This program is free software; you can redistribute it and/or modify
Chris@19 6 * it under the terms of the GNU General Public License as published by
Chris@19 7 * the Free Software Foundation; either version 2 of the License, or
Chris@19 8 * (at your option) any later version.
Chris@19 9 *
Chris@19 10 * This program is distributed in the hope that it will be useful,
Chris@19 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@19 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@19 13 * GNU General Public License for more details.
Chris@19 14 *
Chris@19 15 * You should have received a copy of the GNU General Public License
Chris@19 16 * along with this program; if not, write to the Free Software
Chris@19 17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
Chris@19 18 *
Chris@19 19 */
Chris@19 20
Chris@19 21
Chris@19 22 /* Do a RODFT00 problem via an R2HC problem, padded antisymmetrically to
Chris@19 23 twice the size. This is asymptotically a factor of ~2 worse than
Chris@19 24 rodft00e-r2hc.c (the algorithm used in e.g. FFTPACK and Numerical
Chris@19 25 Recipes), but we abandoned the latter after we discovered that it
Chris@19 26 has intrinsic accuracy problems. */
Chris@19 27
Chris@19 28 #include "reodft.h"
Chris@19 29
Chris@19 30 typedef struct {
Chris@19 31 solver super;
Chris@19 32 } S;
Chris@19 33
Chris@19 34 typedef struct {
Chris@19 35 plan_rdft super;
Chris@19 36 plan *cld, *cldcpy;
Chris@19 37 INT is;
Chris@19 38 INT n;
Chris@19 39 INT vl;
Chris@19 40 INT ivs, ovs;
Chris@19 41 } P;
Chris@19 42
Chris@19 43 static void apply(const plan *ego_, R *I, R *O)
Chris@19 44 {
Chris@19 45 const P *ego = (const P *) ego_;
Chris@19 46 INT is = ego->is;
Chris@19 47 INT i, n = ego->n;
Chris@19 48 INT iv, vl = ego->vl;
Chris@19 49 INT ivs = ego->ivs, ovs = ego->ovs;
Chris@19 50 R *buf;
Chris@19 51
Chris@19 52 buf = (R *) MALLOC(sizeof(R) * (2*n), BUFFERS);
Chris@19 53
Chris@19 54 for (iv = 0; iv < vl; ++iv, I += ivs, O += ovs) {
Chris@19 55 buf[0] = K(0.0);
Chris@19 56 for (i = 1; i < n; ++i) {
Chris@19 57 R a = I[(i-1) * is];
Chris@19 58 buf[i] = -a;
Chris@19 59 buf[2*n - i] = a;
Chris@19 60 }
Chris@19 61 buf[i] = K(0.0); /* i == n, Nyquist */
Chris@19 62
Chris@19 63 /* r2hc transform of size 2*n */
Chris@19 64 {
Chris@19 65 plan_rdft *cld = (plan_rdft *) ego->cld;
Chris@19 66 cld->apply((plan *) cld, buf, buf);
Chris@19 67 }
Chris@19 68
Chris@19 69 /* copy n-1 real numbers (imag. parts of hc array) from buf to O */
Chris@19 70 {
Chris@19 71 plan_rdft *cldcpy = (plan_rdft *) ego->cldcpy;
Chris@19 72 cldcpy->apply((plan *) cldcpy, buf+2*n-1, O);
Chris@19 73 }
Chris@19 74 }
Chris@19 75
Chris@19 76 X(ifree)(buf);
Chris@19 77 }
Chris@19 78
Chris@19 79 static void awake(plan *ego_, enum wakefulness wakefulness)
Chris@19 80 {
Chris@19 81 P *ego = (P *) ego_;
Chris@19 82 X(plan_awake)(ego->cld, wakefulness);
Chris@19 83 X(plan_awake)(ego->cldcpy, wakefulness);
Chris@19 84 }
Chris@19 85
Chris@19 86 static void destroy(plan *ego_)
Chris@19 87 {
Chris@19 88 P *ego = (P *) ego_;
Chris@19 89 X(plan_destroy_internal)(ego->cldcpy);
Chris@19 90 X(plan_destroy_internal)(ego->cld);
Chris@19 91 }
Chris@19 92
Chris@19 93 static void print(const plan *ego_, printer *p)
Chris@19 94 {
Chris@19 95 const P *ego = (const P *) ego_;
Chris@19 96 p->print(p, "(rodft00e-r2hc-pad-%D%v%(%p%)%(%p%))",
Chris@19 97 ego->n - 1, ego->vl, ego->cld, ego->cldcpy);
Chris@19 98 }
Chris@19 99
Chris@19 100 static int applicable0(const solver *ego_, const problem *p_)
Chris@19 101 {
Chris@19 102 const problem_rdft *p = (const problem_rdft *) p_;
Chris@19 103 UNUSED(ego_);
Chris@19 104 return (1
Chris@19 105 && p->sz->rnk == 1
Chris@19 106 && p->vecsz->rnk <= 1
Chris@19 107 && p->kind[0] == RODFT00
Chris@19 108 );
Chris@19 109 }
Chris@19 110
Chris@19 111 static int applicable(const solver *ego, const problem *p, const planner *plnr)
Chris@19 112 {
Chris@19 113 return (!NO_SLOWP(plnr) && applicable0(ego, p));
Chris@19 114 }
Chris@19 115
Chris@19 116 static plan *mkplan(const solver *ego_, const problem *p_, planner *plnr)
Chris@19 117 {
Chris@19 118 P *pln;
Chris@19 119 const problem_rdft *p;
Chris@19 120 plan *cld = (plan *) 0, *cldcpy;
Chris@19 121 R *buf = (R *) 0;
Chris@19 122 INT n;
Chris@19 123 INT vl, ivs, ovs;
Chris@19 124 opcnt ops;
Chris@19 125
Chris@19 126 static const plan_adt padt = {
Chris@19 127 X(rdft_solve), awake, print, destroy
Chris@19 128 };
Chris@19 129
Chris@19 130 if (!applicable(ego_, p_, plnr))
Chris@19 131 goto nada;
Chris@19 132
Chris@19 133 p = (const problem_rdft *) p_;
Chris@19 134
Chris@19 135 n = p->sz->dims[0].n + 1;
Chris@19 136 A(n > 0);
Chris@19 137 buf = (R *) MALLOC(sizeof(R) * (2*n), BUFFERS);
Chris@19 138
Chris@19 139 cld = X(mkplan_d)(plnr,X(mkproblem_rdft_1_d)(X(mktensor_1d)(2*n,1,1),
Chris@19 140 X(mktensor_0d)(),
Chris@19 141 buf, buf, R2HC));
Chris@19 142 if (!cld)
Chris@19 143 goto nada;
Chris@19 144
Chris@19 145 X(tensor_tornk1)(p->vecsz, &vl, &ivs, &ovs);
Chris@19 146 cldcpy =
Chris@19 147 X(mkplan_d)(plnr,
Chris@19 148 X(mkproblem_rdft_1_d)(X(mktensor_0d)(),
Chris@19 149 X(mktensor_1d)(n-1,-1,
Chris@19 150 p->sz->dims[0].os),
Chris@19 151 buf+2*n-1,TAINT(p->O, ovs), R2HC));
Chris@19 152 if (!cldcpy)
Chris@19 153 goto nada;
Chris@19 154
Chris@19 155 X(ifree)(buf);
Chris@19 156
Chris@19 157 pln = MKPLAN_RDFT(P, &padt, apply);
Chris@19 158
Chris@19 159 pln->n = n;
Chris@19 160 pln->is = p->sz->dims[0].is;
Chris@19 161 pln->cld = cld;
Chris@19 162 pln->cldcpy = cldcpy;
Chris@19 163 pln->vl = vl;
Chris@19 164 pln->ivs = ivs;
Chris@19 165 pln->ovs = ovs;
Chris@19 166
Chris@19 167 X(ops_zero)(&ops);
Chris@19 168 ops.other = n-1 + 2*n; /* loads + stores (input -> buf) */
Chris@19 169
Chris@19 170 X(ops_zero)(&pln->super.super.ops);
Chris@19 171 X(ops_madd2)(pln->vl, &ops, &pln->super.super.ops);
Chris@19 172 X(ops_madd2)(pln->vl, &cld->ops, &pln->super.super.ops);
Chris@19 173 X(ops_madd2)(pln->vl, &cldcpy->ops, &pln->super.super.ops);
Chris@19 174
Chris@19 175 return &(pln->super.super);
Chris@19 176
Chris@19 177 nada:
Chris@19 178 X(ifree0)(buf);
Chris@19 179 if (cld)
Chris@19 180 X(plan_destroy_internal)(cld);
Chris@19 181 return (plan *)0;
Chris@19 182 }
Chris@19 183
Chris@19 184 /* constructor */
Chris@19 185 static solver *mksolver(void)
Chris@19 186 {
Chris@19 187 static const solver_adt sadt = { PROBLEM_RDFT, mkplan, 0 };
Chris@19 188 S *slv = MKSOLVER(S, &sadt);
Chris@19 189 return &(slv->super);
Chris@19 190 }
Chris@19 191
Chris@19 192 void X(rodft00e_r2hc_pad_register)(planner *p)
Chris@19 193 {
Chris@19 194 REGISTER_SOLVER(p, mksolver());
Chris@19 195 }