annotate src/fftw-3.3.3/rdft/dht-r2hc.c @ 83:ae30d91d2ffe

Replace these with versions built using an older toolset (so as to avoid ABI compatibilities when linking on Ubuntu 14.04 for packaging purposes)
author Chris Cannam
date Fri, 07 Feb 2020 11:51:13 +0000
parents 37bf6b4a2645
children
rev   line source
Chris@10 1 /*
Chris@10 2 * Copyright (c) 2003, 2007-11 Matteo Frigo
Chris@10 3 * Copyright (c) 2003, 2007-11 Massachusetts Institute of Technology
Chris@10 4 *
Chris@10 5 * This program is free software; you can redistribute it and/or modify
Chris@10 6 * it under the terms of the GNU General Public License as published by
Chris@10 7 * the Free Software Foundation; either version 2 of the License, or
Chris@10 8 * (at your option) any later version.
Chris@10 9 *
Chris@10 10 * This program is distributed in the hope that it will be useful,
Chris@10 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@10 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@10 13 * GNU General Public License for more details.
Chris@10 14 *
Chris@10 15 * You should have received a copy of the GNU General Public License
Chris@10 16 * along with this program; if not, write to the Free Software
Chris@10 17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
Chris@10 18 *
Chris@10 19 */
Chris@10 20
Chris@10 21
Chris@10 22 /* Solve a DHT problem (Discrete Hartley Transform) via post-processing
Chris@10 23 of an R2HC problem. */
Chris@10 24
Chris@10 25 #include "rdft.h"
Chris@10 26
Chris@10 27 typedef struct {
Chris@10 28 solver super;
Chris@10 29 } S;
Chris@10 30
Chris@10 31 typedef struct {
Chris@10 32 plan_rdft super;
Chris@10 33 plan *cld;
Chris@10 34 INT os;
Chris@10 35 INT n;
Chris@10 36 } P;
Chris@10 37
Chris@10 38 static void apply(const plan *ego_, R *I, R *O)
Chris@10 39 {
Chris@10 40 const P *ego = (const P *) ego_;
Chris@10 41 INT os = ego->os;
Chris@10 42 INT i, n = ego->n;
Chris@10 43
Chris@10 44 {
Chris@10 45 plan_rdft *cld = (plan_rdft *) ego->cld;
Chris@10 46 cld->apply((plan *) cld, I, O);
Chris@10 47 }
Chris@10 48
Chris@10 49 for (i = 1; i < n - i; ++i) {
Chris@10 50 E a, b;
Chris@10 51 a = O[os * i];
Chris@10 52 b = O[os * (n - i)];
Chris@10 53 #if FFT_SIGN == -1
Chris@10 54 O[os * i] = a - b;
Chris@10 55 O[os * (n - i)] = a + b;
Chris@10 56 #else
Chris@10 57 O[os * i] = a + b;
Chris@10 58 O[os * (n - i)] = a - b;
Chris@10 59 #endif
Chris@10 60 }
Chris@10 61 }
Chris@10 62
Chris@10 63 static void awake(plan *ego_, enum wakefulness wakefulness)
Chris@10 64 {
Chris@10 65 P *ego = (P *) ego_;
Chris@10 66 X(plan_awake)(ego->cld, wakefulness);
Chris@10 67 }
Chris@10 68
Chris@10 69 static void destroy(plan *ego_)
Chris@10 70 {
Chris@10 71 P *ego = (P *) ego_;
Chris@10 72 X(plan_destroy_internal)(ego->cld);
Chris@10 73 }
Chris@10 74
Chris@10 75 static void print(const plan *ego_, printer *p)
Chris@10 76 {
Chris@10 77 const P *ego = (const P *) ego_;
Chris@10 78 p->print(p, "(dht-r2hc-%D%(%p%))", ego->n, ego->cld);
Chris@10 79 }
Chris@10 80
Chris@10 81 static int applicable0(const problem *p_, const planner *plnr)
Chris@10 82 {
Chris@10 83 const problem_rdft *p = (const problem_rdft *) p_;
Chris@10 84 return (1
Chris@10 85 && !NO_DHT_R2HCP(plnr)
Chris@10 86 && p->sz->rnk == 1
Chris@10 87 && p->vecsz->rnk == 0
Chris@10 88 && p->kind[0] == DHT
Chris@10 89 );
Chris@10 90 }
Chris@10 91
Chris@10 92 static int applicable(const solver *ego, const problem *p, const planner *plnr)
Chris@10 93 {
Chris@10 94 UNUSED(ego);
Chris@10 95 return (!NO_SLOWP(plnr) && applicable0(p, plnr));
Chris@10 96 }
Chris@10 97
Chris@10 98 static plan *mkplan(const solver *ego_, const problem *p_, planner *plnr)
Chris@10 99 {
Chris@10 100 P *pln;
Chris@10 101 const problem_rdft *p;
Chris@10 102 plan *cld;
Chris@10 103
Chris@10 104 static const plan_adt padt = {
Chris@10 105 X(rdft_solve), awake, print, destroy
Chris@10 106 };
Chris@10 107
Chris@10 108 if (!applicable(ego_, p_, plnr))
Chris@10 109 return (plan *)0;
Chris@10 110
Chris@10 111 p = (const problem_rdft *) p_;
Chris@10 112
Chris@10 113 /* NO_DHT_R2HC stops infinite loops with rdft-dht.c */
Chris@10 114 cld = X(mkplan_f_d)(plnr,
Chris@10 115 X(mkproblem_rdft_1)(p->sz, p->vecsz,
Chris@10 116 p->I, p->O, R2HC),
Chris@10 117 NO_DHT_R2HC, 0, 0);
Chris@10 118 if (!cld) return (plan *)0;
Chris@10 119
Chris@10 120 pln = MKPLAN_RDFT(P, &padt, apply);
Chris@10 121
Chris@10 122 pln->n = p->sz->dims[0].n;
Chris@10 123 pln->os = p->sz->dims[0].os;
Chris@10 124 pln->cld = cld;
Chris@10 125
Chris@10 126 pln->super.super.ops = cld->ops;
Chris@10 127 pln->super.super.ops.other += 4 * ((pln->n - 1)/2);
Chris@10 128 pln->super.super.ops.add += 2 * ((pln->n - 1)/2);
Chris@10 129
Chris@10 130 return &(pln->super.super);
Chris@10 131 }
Chris@10 132
Chris@10 133 /* constructor */
Chris@10 134 static solver *mksolver(void)
Chris@10 135 {
Chris@10 136 static const solver_adt sadt = { PROBLEM_RDFT, mkplan, 0 };
Chris@10 137 S *slv = MKSOLVER(S, &sadt);
Chris@10 138 return &(slv->super);
Chris@10 139 }
Chris@10 140
Chris@10 141 void X(dht_r2hc_register)(planner *p)
Chris@10 142 {
Chris@10 143 REGISTER_SOLVER(p, mksolver());
Chris@10 144 }