annotate src/fftw-3.3.3/rdft/dft-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 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 /* Compute the complex DFT by combining R2HC RDFTs on the real
cannam@95 23 and imaginary parts. This could be useful for people just wanting
cannam@95 24 to link to the real codelets and not the complex ones. It could
cannam@95 25 also even be faster than the complex algorithms for split (as opposed
cannam@95 26 to interleaved) real/imag complex data. */
cannam@95 27
cannam@95 28 #include "rdft.h"
cannam@95 29 #include "dft.h"
cannam@95 30
cannam@95 31 typedef struct {
cannam@95 32 solver super;
cannam@95 33 } S;
cannam@95 34
cannam@95 35 typedef struct {
cannam@95 36 plan_dft super;
cannam@95 37 plan *cld;
cannam@95 38 INT ishift, oshift;
cannam@95 39 INT os;
cannam@95 40 INT n;
cannam@95 41 } P;
cannam@95 42
cannam@95 43 static void apply(const plan *ego_, R *ri, R *ii, R *ro, R *io)
cannam@95 44 {
cannam@95 45 const P *ego = (const P *) ego_;
cannam@95 46 INT n;
cannam@95 47
cannam@95 48 UNUSED(ii);
cannam@95 49
cannam@95 50 { /* transform vector of real & imag parts: */
cannam@95 51 plan_rdft *cld = (plan_rdft *) ego->cld;
cannam@95 52 cld->apply((plan *) cld, ri + ego->ishift, ro + ego->oshift);
cannam@95 53 }
cannam@95 54
cannam@95 55 n = ego->n;
cannam@95 56 if (n > 1) {
cannam@95 57 INT i, os = ego->os;
cannam@95 58 for (i = 1; i < (n + 1)/2; ++i) {
cannam@95 59 E rop, iop, iom, rom;
cannam@95 60 rop = ro[os * i];
cannam@95 61 iop = io[os * i];
cannam@95 62 rom = ro[os * (n - i)];
cannam@95 63 iom = io[os * (n - i)];
cannam@95 64 ro[os * i] = rop - iom;
cannam@95 65 io[os * i] = iop + rom;
cannam@95 66 ro[os * (n - i)] = rop + iom;
cannam@95 67 io[os * (n - i)] = iop - rom;
cannam@95 68 }
cannam@95 69 }
cannam@95 70 }
cannam@95 71
cannam@95 72 static void awake(plan *ego_, enum wakefulness wakefulness)
cannam@95 73 {
cannam@95 74 P *ego = (P *) ego_;
cannam@95 75 X(plan_awake)(ego->cld, wakefulness);
cannam@95 76 }
cannam@95 77
cannam@95 78 static void destroy(plan *ego_)
cannam@95 79 {
cannam@95 80 P *ego = (P *) ego_;
cannam@95 81 X(plan_destroy_internal)(ego->cld);
cannam@95 82 }
cannam@95 83
cannam@95 84 static void print(const plan *ego_, printer *p)
cannam@95 85 {
cannam@95 86 const P *ego = (const P *) ego_;
cannam@95 87 p->print(p, "(dft-r2hc-%D%(%p%))", ego->n, ego->cld);
cannam@95 88 }
cannam@95 89
cannam@95 90
cannam@95 91 static int applicable0(const problem *p_)
cannam@95 92 {
cannam@95 93 const problem_dft *p = (const problem_dft *) p_;
cannam@95 94 return ((p->sz->rnk == 1 && p->vecsz->rnk == 0)
cannam@95 95 || (p->sz->rnk == 0 && FINITE_RNK(p->vecsz->rnk))
cannam@95 96 );
cannam@95 97 }
cannam@95 98
cannam@95 99 static int splitp(R *r, R *i, INT n, INT s)
cannam@95 100 {
cannam@95 101 return ((r > i ? (r - i) : (i - r)) >= n * (s > 0 ? s : 0-s));
cannam@95 102 }
cannam@95 103
cannam@95 104 static int applicable(const problem *p_, const planner *plnr)
cannam@95 105 {
cannam@95 106 if (!applicable0(p_)) return 0;
cannam@95 107
cannam@95 108 {
cannam@95 109 const problem_dft *p = (const problem_dft *) p_;
cannam@95 110
cannam@95 111 /* rank-0 problems are always OK */
cannam@95 112 if (p->sz->rnk == 0) return 1;
cannam@95 113
cannam@95 114 /* this solver is ok for split arrays */
cannam@95 115 if (p->sz->rnk == 1 &&
cannam@95 116 splitp(p->ri, p->ii, p->sz->dims[0].n, p->sz->dims[0].is) &&
cannam@95 117 splitp(p->ro, p->io, p->sz->dims[0].n, p->sz->dims[0].os))
cannam@95 118 return 1;
cannam@95 119
cannam@95 120 return !(NO_DFT_R2HCP(plnr));
cannam@95 121 }
cannam@95 122 }
cannam@95 123
cannam@95 124 static plan *mkplan(const solver *ego_, const problem *p_, planner *plnr)
cannam@95 125 {
cannam@95 126 P *pln;
cannam@95 127 const problem_dft *p;
cannam@95 128 plan *cld;
cannam@95 129 INT ishift = 0, oshift = 0;
cannam@95 130
cannam@95 131 static const plan_adt padt = {
cannam@95 132 X(dft_solve), awake, print, destroy
cannam@95 133 };
cannam@95 134
cannam@95 135 UNUSED(ego_);
cannam@95 136 if (!applicable(p_, plnr))
cannam@95 137 return (plan *)0;
cannam@95 138
cannam@95 139 p = (const problem_dft *) p_;
cannam@95 140
cannam@95 141 {
cannam@95 142 tensor *ri_vec = X(mktensor_1d)(2, p->ii - p->ri, p->io - p->ro);
cannam@95 143 tensor *cld_vec = X(tensor_append)(ri_vec, p->vecsz);
cannam@95 144 int i;
cannam@95 145 for (i = 0; i < cld_vec->rnk; ++i) { /* make all istrides > 0 */
cannam@95 146 if (cld_vec->dims[i].is < 0) {
cannam@95 147 INT nm1 = cld_vec->dims[i].n - 1;
cannam@95 148 ishift -= nm1 * (cld_vec->dims[i].is *= -1);
cannam@95 149 oshift -= nm1 * (cld_vec->dims[i].os *= -1);
cannam@95 150 }
cannam@95 151 }
cannam@95 152 cld = X(mkplan_d)(plnr,
cannam@95 153 X(mkproblem_rdft_1)(p->sz, cld_vec,
cannam@95 154 p->ri + ishift,
cannam@95 155 p->ro + oshift, R2HC));
cannam@95 156 X(tensor_destroy2)(ri_vec, cld_vec);
cannam@95 157 }
cannam@95 158 if (!cld) return (plan *)0;
cannam@95 159
cannam@95 160 pln = MKPLAN_DFT(P, &padt, apply);
cannam@95 161
cannam@95 162 if (p->sz->rnk == 0) {
cannam@95 163 pln->n = 1;
cannam@95 164 pln->os = 0;
cannam@95 165 }
cannam@95 166 else {
cannam@95 167 pln->n = p->sz->dims[0].n;
cannam@95 168 pln->os = p->sz->dims[0].os;
cannam@95 169 }
cannam@95 170 pln->ishift = ishift;
cannam@95 171 pln->oshift = oshift;
cannam@95 172
cannam@95 173 pln->cld = cld;
cannam@95 174
cannam@95 175 pln->super.super.ops = cld->ops;
cannam@95 176 pln->super.super.ops.other += 8 * ((pln->n - 1)/2);
cannam@95 177 pln->super.super.ops.add += 4 * ((pln->n - 1)/2);
cannam@95 178 pln->super.super.ops.other += 1; /* estimator hack for nop plans */
cannam@95 179
cannam@95 180 return &(pln->super.super);
cannam@95 181 }
cannam@95 182
cannam@95 183 /* constructor */
cannam@95 184 static solver *mksolver(void)
cannam@95 185 {
cannam@95 186 static const solver_adt sadt = { PROBLEM_DFT, mkplan, 0 };
cannam@95 187 S *slv = MKSOLVER(S, &sadt);
cannam@95 188 return &(slv->super);
cannam@95 189 }
cannam@95 190
cannam@95 191 void X(dft_r2hc_register)(planner *p)
cannam@95 192 {
cannam@95 193 REGISTER_SOLVER(p, mksolver());
cannam@95 194 }