annotate src/fftw-3.3.5/kernel/tensor.c @ 82:d0c2a83c1364

Add FFTW 3.3.8 source, and a Linux build
author Chris Cannam
date Tue, 19 Nov 2019 14:52:55 +0000
parents 2cd0e3b3e1fd
children
rev   line source
Chris@42 1 /*
Chris@42 2 * Copyright (c) 2003, 2007-14 Matteo Frigo
Chris@42 3 * Copyright (c) 2003, 2007-14 Massachusetts Institute of Technology
Chris@42 4 *
Chris@42 5 * This program is free software; you can redistribute it and/or modify
Chris@42 6 * it under the terms of the GNU General Public License as published by
Chris@42 7 * the Free Software Foundation; either version 2 of the License, or
Chris@42 8 * (at your option) any later version.
Chris@42 9 *
Chris@42 10 * This program is distributed in the hope that it will be useful,
Chris@42 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@42 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@42 13 * GNU General Public License for more details.
Chris@42 14 *
Chris@42 15 * You should have received a copy of the GNU General Public License
Chris@42 16 * along with this program; if not, write to the Free Software
Chris@42 17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
Chris@42 18 *
Chris@42 19 */
Chris@42 20
Chris@42 21
Chris@42 22 #include "ifftw.h"
Chris@42 23
Chris@42 24 tensor *X(mktensor)(int rnk)
Chris@42 25 {
Chris@42 26 tensor *x;
Chris@42 27
Chris@42 28 A(rnk >= 0);
Chris@42 29
Chris@42 30 #if defined(STRUCT_HACK_KR)
Chris@42 31 if (FINITE_RNK(rnk) && rnk > 1)
Chris@42 32 x = (tensor *)MALLOC(sizeof(tensor) + (unsigned)(rnk - 1) * sizeof(iodim),
Chris@42 33 TENSORS);
Chris@42 34 else
Chris@42 35 x = (tensor *)MALLOC(sizeof(tensor), TENSORS);
Chris@42 36 #elif defined(STRUCT_HACK_C99)
Chris@42 37 if (FINITE_RNK(rnk))
Chris@42 38 x = (tensor *)MALLOC(sizeof(tensor) + (unsigned)rnk * sizeof(iodim),
Chris@42 39 TENSORS);
Chris@42 40 else
Chris@42 41 x = (tensor *)MALLOC(sizeof(tensor), TENSORS);
Chris@42 42 #else
Chris@42 43 x = (tensor *)MALLOC(sizeof(tensor), TENSORS);
Chris@42 44 if (FINITE_RNK(rnk) && rnk > 0)
Chris@42 45 x->dims = (iodim *)MALLOC(sizeof(iodim) * (unsigned)rnk, TENSORS);
Chris@42 46 else
Chris@42 47 x->dims = 0;
Chris@42 48 #endif
Chris@42 49
Chris@42 50 x->rnk = rnk;
Chris@42 51 return x;
Chris@42 52 }
Chris@42 53
Chris@42 54 void X(tensor_destroy)(tensor *sz)
Chris@42 55 {
Chris@42 56 #if !defined(STRUCT_HACK_C99) && !defined(STRUCT_HACK_KR)
Chris@42 57 X(ifree0)(sz->dims);
Chris@42 58 #endif
Chris@42 59 X(ifree)(sz);
Chris@42 60 }
Chris@42 61
Chris@42 62 INT X(tensor_sz)(const tensor *sz)
Chris@42 63 {
Chris@42 64 int i;
Chris@42 65 INT n = 1;
Chris@42 66
Chris@42 67 if (!FINITE_RNK(sz->rnk))
Chris@42 68 return 0;
Chris@42 69
Chris@42 70 for (i = 0; i < sz->rnk; ++i)
Chris@42 71 n *= sz->dims[i].n;
Chris@42 72 return n;
Chris@42 73 }
Chris@42 74
Chris@42 75 void X(tensor_md5)(md5 *p, const tensor *t)
Chris@42 76 {
Chris@42 77 int i;
Chris@42 78 X(md5int)(p, t->rnk);
Chris@42 79 if (FINITE_RNK(t->rnk)) {
Chris@42 80 for (i = 0; i < t->rnk; ++i) {
Chris@42 81 const iodim *q = t->dims + i;
Chris@42 82 X(md5INT)(p, q->n);
Chris@42 83 X(md5INT)(p, q->is);
Chris@42 84 X(md5INT)(p, q->os);
Chris@42 85 }
Chris@42 86 }
Chris@42 87 }
Chris@42 88
Chris@42 89 /* treat a (rank <= 1)-tensor as a rank-1 tensor, extracting
Chris@42 90 appropriate n, is, and os components */
Chris@42 91 int X(tensor_tornk1)(const tensor *t, INT *n, INT *is, INT *os)
Chris@42 92 {
Chris@42 93 A(t->rnk <= 1);
Chris@42 94 if (t->rnk == 1) {
Chris@42 95 const iodim *vd = t->dims;
Chris@42 96 *n = vd[0].n;
Chris@42 97 *is = vd[0].is;
Chris@42 98 *os = vd[0].os;
Chris@42 99 } else {
Chris@42 100 *n = 1;
Chris@42 101 *is = *os = 0;
Chris@42 102 }
Chris@42 103 return 1;
Chris@42 104 }
Chris@42 105
Chris@42 106 void X(tensor_print)(const tensor *x, printer *p)
Chris@42 107 {
Chris@42 108 if (FINITE_RNK(x->rnk)) {
Chris@42 109 int i;
Chris@42 110 int first = 1;
Chris@42 111 p->print(p, "(");
Chris@42 112 for (i = 0; i < x->rnk; ++i) {
Chris@42 113 const iodim *d = x->dims + i;
Chris@42 114 p->print(p, "%s(%D %D %D)",
Chris@42 115 first ? "" : " ",
Chris@42 116 d->n, d->is, d->os);
Chris@42 117 first = 0;
Chris@42 118 }
Chris@42 119 p->print(p, ")");
Chris@42 120 } else {
Chris@42 121 p->print(p, "rank-minfty");
Chris@42 122 }
Chris@42 123 }