annotate src/fftw-3.3.5/rdft/problem2.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 7867fa7e1b6b
children
rev   line source
cannam@127 1 /*
cannam@127 2 * Copyright (c) 2003, 2007-14 Matteo Frigo
cannam@127 3 * Copyright (c) 2003, 2007-14 Massachusetts Institute of Technology
cannam@127 4 *
cannam@127 5 * This program is free software; you can redistribute it and/or modify
cannam@127 6 * it under the terms of the GNU General Public License as published by
cannam@127 7 * the Free Software Foundation; either version 2 of the License, or
cannam@127 8 * (at your option) any later version.
cannam@127 9 *
cannam@127 10 * This program is distributed in the hope that it will be useful,
cannam@127 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
cannam@127 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
cannam@127 13 * GNU General Public License for more details.
cannam@127 14 *
cannam@127 15 * You should have received a copy of the GNU General Public License
cannam@127 16 * along with this program; if not, write to the Free Software
cannam@127 17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
cannam@127 18 *
cannam@127 19 */
cannam@127 20
cannam@127 21
cannam@127 22 #include "dft.h"
cannam@127 23 #include "rdft.h"
cannam@127 24 #include <stddef.h>
cannam@127 25
cannam@127 26 static void destroy(problem *ego_)
cannam@127 27 {
cannam@127 28 problem_rdft2 *ego = (problem_rdft2 *) ego_;
cannam@127 29 X(tensor_destroy2)(ego->vecsz, ego->sz);
cannam@127 30 X(ifree)(ego_);
cannam@127 31 }
cannam@127 32
cannam@127 33 static void hash(const problem *p_, md5 *m)
cannam@127 34 {
cannam@127 35 const problem_rdft2 *p = (const problem_rdft2 *) p_;
cannam@127 36 X(md5puts)(m, "rdft2");
cannam@127 37 X(md5int)(m, p->r0 == p->cr);
cannam@127 38 X(md5INT)(m, p->r1 - p->r0);
cannam@127 39 X(md5INT)(m, p->ci - p->cr);
cannam@127 40 X(md5int)(m, X(ialignment_of)(p->r0));
cannam@127 41 X(md5int)(m, X(ialignment_of)(p->r1));
cannam@127 42 X(md5int)(m, X(ialignment_of)(p->cr));
cannam@127 43 X(md5int)(m, X(ialignment_of)(p->ci));
cannam@127 44 X(md5int)(m, p->kind);
cannam@127 45 X(tensor_md5)(m, p->sz);
cannam@127 46 X(tensor_md5)(m, p->vecsz);
cannam@127 47 }
cannam@127 48
cannam@127 49 static void print(const problem *ego_, printer *p)
cannam@127 50 {
cannam@127 51 const problem_rdft2 *ego = (const problem_rdft2 *) ego_;
cannam@127 52 p->print(p, "(rdft2 %d %d %T %T)",
cannam@127 53 (int)(ego->cr == ego->r0),
cannam@127 54 (int)(ego->kind),
cannam@127 55 ego->sz,
cannam@127 56 ego->vecsz);
cannam@127 57 }
cannam@127 58
cannam@127 59 static void recur(const iodim *dims, int rnk, R *I0, R *I1)
cannam@127 60 {
cannam@127 61 if (rnk == RNK_MINFTY)
cannam@127 62 return;
cannam@127 63 else if (rnk == 0)
cannam@127 64 I0[0] = K(0.0);
cannam@127 65 else if (rnk > 0) {
cannam@127 66 INT i, n = dims[0].n, is = dims[0].is;
cannam@127 67
cannam@127 68 if (rnk == 1) {
cannam@127 69 for (i = 0; i < n - 1; i += 2) {
cannam@127 70 *I0 = *I1 = K(0.0);
cannam@127 71 I0 += is; I1 += is;
cannam@127 72 }
cannam@127 73 if (i < n)
cannam@127 74 *I0 = K(0.0);
cannam@127 75 } else {
cannam@127 76 for (i = 0; i < n; ++i)
cannam@127 77 recur(dims + 1, rnk - 1, I0 + i * is, I1 + i * is);
cannam@127 78 }
cannam@127 79 }
cannam@127 80 }
cannam@127 81
cannam@127 82 static void vrecur(const iodim *vdims, int vrnk,
cannam@127 83 const iodim *dims, int rnk, R *I0, R *I1)
cannam@127 84 {
cannam@127 85 if (vrnk == RNK_MINFTY)
cannam@127 86 return;
cannam@127 87 else if (vrnk == 0)
cannam@127 88 recur(dims, rnk, I0, I1);
cannam@127 89 else if (vrnk > 0) {
cannam@127 90 INT i, n = vdims[0].n, is = vdims[0].is;
cannam@127 91
cannam@127 92 for (i = 0; i < n; ++i)
cannam@127 93 vrecur(vdims + 1, vrnk - 1,
cannam@127 94 dims, rnk, I0 + i * is, I1 + i * is);
cannam@127 95 }
cannam@127 96 }
cannam@127 97
cannam@127 98 INT X(rdft2_complex_n)(INT real_n, rdft_kind kind)
cannam@127 99 {
cannam@127 100 switch (kind) {
cannam@127 101 case R2HC:
cannam@127 102 case HC2R:
cannam@127 103 return (real_n / 2) + 1;
cannam@127 104 case R2HCII:
cannam@127 105 case HC2RIII:
cannam@127 106 return (real_n + 1) / 2;
cannam@127 107 default:
cannam@127 108 /* can't happen */
cannam@127 109 A(0);
cannam@127 110 return 0;
cannam@127 111 }
cannam@127 112 }
cannam@127 113
cannam@127 114 static void zero(const problem *ego_)
cannam@127 115 {
cannam@127 116 const problem_rdft2 *ego = (const problem_rdft2 *) ego_;
cannam@127 117 if (R2HC_KINDP(ego->kind)) {
cannam@127 118 /* FIXME: can we avoid the double recursion somehow? */
cannam@127 119 vrecur(ego->vecsz->dims, ego->vecsz->rnk,
cannam@127 120 ego->sz->dims, ego->sz->rnk,
cannam@127 121 UNTAINT(ego->r0), UNTAINT(ego->r1));
cannam@127 122 } else {
cannam@127 123 tensor *sz;
cannam@127 124 tensor *sz2 = X(tensor_copy)(ego->sz);
cannam@127 125 int rnk = sz2->rnk;
cannam@127 126 if (rnk > 0) /* ~half as many complex outputs */
cannam@127 127 sz2->dims[rnk-1].n =
cannam@127 128 X(rdft2_complex_n)(sz2->dims[rnk-1].n, ego->kind);
cannam@127 129 sz = X(tensor_append)(ego->vecsz, sz2);
cannam@127 130 X(tensor_destroy)(sz2);
cannam@127 131 X(dft_zerotens)(sz, UNTAINT(ego->cr), UNTAINT(ego->ci));
cannam@127 132 X(tensor_destroy)(sz);
cannam@127 133 }
cannam@127 134 }
cannam@127 135
cannam@127 136 static const problem_adt padt =
cannam@127 137 {
cannam@127 138 PROBLEM_RDFT2,
cannam@127 139 hash,
cannam@127 140 zero,
cannam@127 141 print,
cannam@127 142 destroy
cannam@127 143 };
cannam@127 144
cannam@127 145 problem *X(mkproblem_rdft2)(const tensor *sz, const tensor *vecsz,
cannam@127 146 R *r0, R *r1, R *cr, R *ci,
cannam@127 147 rdft_kind kind)
cannam@127 148 {
cannam@127 149 problem_rdft2 *ego;
cannam@127 150
cannam@127 151 A(kind == R2HC || kind == R2HCII || kind == HC2R || kind == HC2RIII);
cannam@127 152 A(X(tensor_kosherp)(sz));
cannam@127 153 A(X(tensor_kosherp)(vecsz));
cannam@127 154 A(FINITE_RNK(sz->rnk));
cannam@127 155
cannam@127 156 /* require in-place problems to use r0 == cr */
cannam@127 157 if (UNTAINT(r0) == UNTAINT(ci))
cannam@127 158 return X(mkproblem_unsolvable)();
cannam@127 159
cannam@127 160 /* FIXME: should check UNTAINT(r1) == UNTAINT(cr) but
cannam@127 161 only if odd elements exist, which requires compressing the
cannam@127 162 tensors first */
cannam@127 163
cannam@127 164 if (UNTAINT(r0) == UNTAINT(cr))
cannam@127 165 r0 = cr = JOIN_TAINT(r0, cr);
cannam@127 166
cannam@127 167 ego = (problem_rdft2 *)X(mkproblem)(sizeof(problem_rdft2), &padt);
cannam@127 168
cannam@127 169 if (sz->rnk > 1) { /* have to compress rnk-1 dims separately, ugh */
cannam@127 170 tensor *szc = X(tensor_copy_except)(sz, sz->rnk - 1);
cannam@127 171 tensor *szr = X(tensor_copy_sub)(sz, sz->rnk - 1, 1);
cannam@127 172 tensor *szcc = X(tensor_compress)(szc);
cannam@127 173 if (szcc->rnk > 0)
cannam@127 174 ego->sz = X(tensor_append)(szcc, szr);
cannam@127 175 else
cannam@127 176 ego->sz = X(tensor_compress)(szr);
cannam@127 177 X(tensor_destroy2)(szc, szr); X(tensor_destroy)(szcc);
cannam@127 178 } else {
cannam@127 179 ego->sz = X(tensor_compress)(sz);
cannam@127 180 }
cannam@127 181 ego->vecsz = X(tensor_compress_contiguous)(vecsz);
cannam@127 182 ego->r0 = r0;
cannam@127 183 ego->r1 = r1;
cannam@127 184 ego->cr = cr;
cannam@127 185 ego->ci = ci;
cannam@127 186 ego->kind = kind;
cannam@127 187
cannam@127 188 A(FINITE_RNK(ego->sz->rnk));
cannam@127 189 return &(ego->super);
cannam@127 190
cannam@127 191 }
cannam@127 192
cannam@127 193 /* Same as X(mkproblem_rdft2), but also destroy input tensors. */
cannam@127 194 problem *X(mkproblem_rdft2_d)(tensor *sz, tensor *vecsz,
cannam@127 195 R *r0, R *r1, R *cr, R *ci, rdft_kind kind)
cannam@127 196 {
cannam@127 197 problem *p = X(mkproblem_rdft2)(sz, vecsz, r0, r1, cr, ci, kind);
cannam@127 198 X(tensor_destroy2)(vecsz, sz);
cannam@127 199 return p;
cannam@127 200 }
cannam@127 201
cannam@127 202 /* Same as X(mkproblem_rdft2_d), but with only one R pointer.
cannam@127 203 Used by the API. */
cannam@127 204 problem *X(mkproblem_rdft2_d_3pointers)(tensor *sz, tensor *vecsz,
cannam@127 205 R *r0, R *cr, R *ci, rdft_kind kind)
cannam@127 206 {
cannam@127 207 problem *p;
cannam@127 208 int rnk = sz->rnk;
cannam@127 209 R *r1;
cannam@127 210
cannam@127 211 if (rnk == 0)
cannam@127 212 r1 = r0;
cannam@127 213 else if (R2HC_KINDP(kind)) {
cannam@127 214 r1 = r0 + sz->dims[rnk-1].is;
cannam@127 215 sz->dims[rnk-1].is *= 2;
cannam@127 216 } else {
cannam@127 217 r1 = r0 + sz->dims[rnk-1].os;
cannam@127 218 sz->dims[rnk-1].os *= 2;
cannam@127 219 }
cannam@127 220
cannam@127 221 p = X(mkproblem_rdft2)(sz, vecsz, r0, r1, cr, ci, kind);
cannam@127 222 X(tensor_destroy2)(vecsz, sz);
cannam@127 223 return p;
cannam@127 224 }