annotate src/fftw-3.3.8/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 bd3cc4d1df30
children
rev   line source
cannam@167 1 /*
cannam@167 2 * Copyright (c) 2003, 2007-14 Matteo Frigo
cannam@167 3 * Copyright (c) 2003, 2007-14 Massachusetts Institute of Technology
cannam@167 4 *
cannam@167 5 * This program is free software; you can redistribute it and/or modify
cannam@167 6 * it under the terms of the GNU General Public License as published by
cannam@167 7 * the Free Software Foundation; either version 2 of the License, or
cannam@167 8 * (at your option) any later version.
cannam@167 9 *
cannam@167 10 * This program is distributed in the hope that it will be useful,
cannam@167 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
cannam@167 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
cannam@167 13 * GNU General Public License for more details.
cannam@167 14 *
cannam@167 15 * You should have received a copy of the GNU General Public License
cannam@167 16 * along with this program; if not, write to the Free Software
cannam@167 17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
cannam@167 18 *
cannam@167 19 */
cannam@167 20
cannam@167 21
cannam@167 22 /* Compute the complex DFT by combining R2HC RDFTs on the real
cannam@167 23 and imaginary parts. This could be useful for people just wanting
cannam@167 24 to link to the real codelets and not the complex ones. It could
cannam@167 25 also even be faster than the complex algorithms for split (as opposed
cannam@167 26 to interleaved) real/imag complex data. */
cannam@167 27
cannam@167 28 #include "rdft/rdft.h"
cannam@167 29 #include "dft/dft.h"
cannam@167 30
cannam@167 31 typedef struct {
cannam@167 32 solver super;
cannam@167 33 } S;
cannam@167 34
cannam@167 35 typedef struct {
cannam@167 36 plan_dft super;
cannam@167 37 plan *cld;
cannam@167 38 INT ishift, oshift;
cannam@167 39 INT os;
cannam@167 40 INT n;
cannam@167 41 } P;
cannam@167 42
cannam@167 43 static void apply(const plan *ego_, R *ri, R *ii, R *ro, R *io)
cannam@167 44 {
cannam@167 45 const P *ego = (const P *) ego_;
cannam@167 46 INT n;
cannam@167 47
cannam@167 48 UNUSED(ii);
cannam@167 49
cannam@167 50 { /* transform vector of real & imag parts: */
cannam@167 51 plan_rdft *cld = (plan_rdft *) ego->cld;
cannam@167 52 cld->apply((plan *) cld, ri + ego->ishift, ro + ego->oshift);
cannam@167 53 }
cannam@167 54
cannam@167 55 n = ego->n;
cannam@167 56 if (n > 1) {
cannam@167 57 INT i, os = ego->os;
cannam@167 58 for (i = 1; i < (n + 1)/2; ++i) {
cannam@167 59 E rop, iop, iom, rom;
cannam@167 60 rop = ro[os * i];
cannam@167 61 iop = io[os * i];
cannam@167 62 rom = ro[os * (n - i)];
cannam@167 63 iom = io[os * (n - i)];
cannam@167 64 ro[os * i] = rop - iom;
cannam@167 65 io[os * i] = iop + rom;
cannam@167 66 ro[os * (n - i)] = rop + iom;
cannam@167 67 io[os * (n - i)] = iop - rom;
cannam@167 68 }
cannam@167 69 }
cannam@167 70 }
cannam@167 71
cannam@167 72 static void awake(plan *ego_, enum wakefulness wakefulness)
cannam@167 73 {
cannam@167 74 P *ego = (P *) ego_;
cannam@167 75 X(plan_awake)(ego->cld, wakefulness);
cannam@167 76 }
cannam@167 77
cannam@167 78 static void destroy(plan *ego_)
cannam@167 79 {
cannam@167 80 P *ego = (P *) ego_;
cannam@167 81 X(plan_destroy_internal)(ego->cld);
cannam@167 82 }
cannam@167 83
cannam@167 84 static void print(const plan *ego_, printer *p)
cannam@167 85 {
cannam@167 86 const P *ego = (const P *) ego_;
cannam@167 87 p->print(p, "(dft-r2hc-%D%(%p%))", ego->n, ego->cld);
cannam@167 88 }
cannam@167 89
cannam@167 90
cannam@167 91 static int applicable0(const problem *p_)
cannam@167 92 {
cannam@167 93 const problem_dft *p = (const problem_dft *) p_;
cannam@167 94 return ((p->sz->rnk == 1 && p->vecsz->rnk == 0)
cannam@167 95 || (p->sz->rnk == 0 && FINITE_RNK(p->vecsz->rnk))
cannam@167 96 );
cannam@167 97 }
cannam@167 98
cannam@167 99 static int splitp(R *r, R *i, INT n, INT s)
cannam@167 100 {
cannam@167 101 return ((r > i ? (r - i) : (i - r)) >= n * (s > 0 ? s : 0-s));
cannam@167 102 }
cannam@167 103
cannam@167 104 static int applicable(const problem *p_, const planner *plnr)
cannam@167 105 {
cannam@167 106 if (!applicable0(p_)) return 0;
cannam@167 107
cannam@167 108 {
cannam@167 109 const problem_dft *p = (const problem_dft *) p_;
cannam@167 110
cannam@167 111 /* rank-0 problems are always OK */
cannam@167 112 if (p->sz->rnk == 0) return 1;
cannam@167 113
cannam@167 114 /* this solver is ok for split arrays */
cannam@167 115 if (p->sz->rnk == 1 &&
cannam@167 116 splitp(p->ri, p->ii, p->sz->dims[0].n, p->sz->dims[0].is) &&
cannam@167 117 splitp(p->ro, p->io, p->sz->dims[0].n, p->sz->dims[0].os))
cannam@167 118 return 1;
cannam@167 119
cannam@167 120 return !(NO_DFT_R2HCP(plnr));
cannam@167 121 }
cannam@167 122 }
cannam@167 123
cannam@167 124 static plan *mkplan(const solver *ego_, const problem *p_, planner *plnr)
cannam@167 125 {
cannam@167 126 P *pln;
cannam@167 127 const problem_dft *p;
cannam@167 128 plan *cld;
cannam@167 129 INT ishift = 0, oshift = 0;
cannam@167 130
cannam@167 131 static const plan_adt padt = {
cannam@167 132 X(dft_solve), awake, print, destroy
cannam@167 133 };
cannam@167 134
cannam@167 135 UNUSED(ego_);
cannam@167 136 if (!applicable(p_, plnr))
cannam@167 137 return (plan *)0;
cannam@167 138
cannam@167 139 p = (const problem_dft *) p_;
cannam@167 140
cannam@167 141 {
cannam@167 142 tensor *ri_vec = X(mktensor_1d)(2, p->ii - p->ri, p->io - p->ro);
cannam@167 143 tensor *cld_vec = X(tensor_append)(ri_vec, p->vecsz);
cannam@167 144 int i;
cannam@167 145 for (i = 0; i < cld_vec->rnk; ++i) { /* make all istrides > 0 */
cannam@167 146 if (cld_vec->dims[i].is < 0) {
cannam@167 147 INT nm1 = cld_vec->dims[i].n - 1;
cannam@167 148 ishift -= nm1 * (cld_vec->dims[i].is *= -1);
cannam@167 149 oshift -= nm1 * (cld_vec->dims[i].os *= -1);
cannam@167 150 }
cannam@167 151 }
cannam@167 152 cld = X(mkplan_d)(plnr,
cannam@167 153 X(mkproblem_rdft_1)(p->sz, cld_vec,
cannam@167 154 p->ri + ishift,
cannam@167 155 p->ro + oshift, R2HC));
cannam@167 156 X(tensor_destroy2)(ri_vec, cld_vec);
cannam@167 157 }
cannam@167 158 if (!cld) return (plan *)0;
cannam@167 159
cannam@167 160 pln = MKPLAN_DFT(P, &padt, apply);
cannam@167 161
cannam@167 162 if (p->sz->rnk == 0) {
cannam@167 163 pln->n = 1;
cannam@167 164 pln->os = 0;
cannam@167 165 }
cannam@167 166 else {
cannam@167 167 pln->n = p->sz->dims[0].n;
cannam@167 168 pln->os = p->sz->dims[0].os;
cannam@167 169 }
cannam@167 170 pln->ishift = ishift;
cannam@167 171 pln->oshift = oshift;
cannam@167 172
cannam@167 173 pln->cld = cld;
cannam@167 174
cannam@167 175 pln->super.super.ops = cld->ops;
cannam@167 176 pln->super.super.ops.other += 8 * ((pln->n - 1)/2);
cannam@167 177 pln->super.super.ops.add += 4 * ((pln->n - 1)/2);
cannam@167 178 pln->super.super.ops.other += 1; /* estimator hack for nop plans */
cannam@167 179
cannam@167 180 return &(pln->super.super);
cannam@167 181 }
cannam@167 182
cannam@167 183 /* constructor */
cannam@167 184 static solver *mksolver(void)
cannam@167 185 {
cannam@167 186 static const solver_adt sadt = { PROBLEM_DFT, mkplan, 0 };
cannam@167 187 S *slv = MKSOLVER(S, &sadt);
cannam@167 188 return &(slv->super);
cannam@167 189 }
cannam@167 190
cannam@167 191 void X(dft_r2hc_register)(planner *p)
cannam@167 192 {
cannam@167 193 REGISTER_SOLVER(p, mksolver());
cannam@167 194 }