annotate src/fftw-3.3.3/reodft/rodft00e-r2hc-pad.c @ 152:ffc6df9c760c

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