annotate src/fftw-3.3.8/kernel/tensor.c @ 84:08ae793730bd

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