Chris@42: /* Chris@42: * Copyright (c) 2003, 2007-14 Matteo Frigo Chris@42: * Copyright (c) 2003, 2007-14 Massachusetts Institute of Technology Chris@42: * Chris@42: * This program is free software; you can redistribute it and/or modify Chris@42: * it under the terms of the GNU General Public License as published by Chris@42: * the Free Software Foundation; either version 2 of the License, or Chris@42: * (at your option) any later version. Chris@42: * Chris@42: * This program is distributed in the hope that it will be useful, Chris@42: * but WITHOUT ANY WARRANTY; without even the implied warranty of Chris@42: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Chris@42: * GNU General Public License for more details. Chris@42: * Chris@42: * You should have received a copy of the GNU General Public License Chris@42: * along with this program; if not, write to the Free Software Chris@42: * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA Chris@42: * Chris@42: */ Chris@42: Chris@42: Chris@42: #include "ifftw.h" Chris@42: Chris@42: static void dimcpy(iodim *dst, const iodim *src, int rnk) Chris@42: { Chris@42: int i; Chris@42: if (FINITE_RNK(rnk)) Chris@42: for (i = 0; i < rnk; ++i) Chris@42: dst[i] = src[i]; Chris@42: } Chris@42: Chris@42: tensor *X(tensor_copy)(const tensor *sz) Chris@42: { Chris@42: tensor *x = X(mktensor)(sz->rnk); Chris@42: dimcpy(x->dims, sz->dims, sz->rnk); Chris@42: return x; Chris@42: } Chris@42: Chris@42: /* like X(tensor_copy), but makes strides in-place by Chris@42: setting os = is if k == INPLACE_IS or is = os if k == INPLACE_OS. */ Chris@42: tensor *X(tensor_copy_inplace)(const tensor *sz, inplace_kind k) Chris@42: { Chris@42: tensor *x = X(tensor_copy)(sz); Chris@42: if (FINITE_RNK(x->rnk)) { Chris@42: int i; Chris@42: if (k == INPLACE_OS) Chris@42: for (i = 0; i < x->rnk; ++i) Chris@42: x->dims[i].is = x->dims[i].os; Chris@42: else Chris@42: for (i = 0; i < x->rnk; ++i) Chris@42: x->dims[i].os = x->dims[i].is; Chris@42: } Chris@42: return x; Chris@42: } Chris@42: Chris@42: /* Like X(tensor_copy), but copy all of the dimensions *except* Chris@42: except_dim. */ Chris@42: tensor *X(tensor_copy_except)(const tensor *sz, int except_dim) Chris@42: { Chris@42: tensor *x; Chris@42: Chris@42: A(FINITE_RNK(sz->rnk) && sz->rnk >= 1 && except_dim < sz->rnk); Chris@42: x = X(mktensor)(sz->rnk - 1); Chris@42: dimcpy(x->dims, sz->dims, except_dim); Chris@42: dimcpy(x->dims + except_dim, sz->dims + except_dim + 1, Chris@42: x->rnk - except_dim); Chris@42: return x; Chris@42: } Chris@42: Chris@42: /* Like X(tensor_copy), but copy only rnk dimensions starting Chris@42: with start_dim. */ Chris@42: tensor *X(tensor_copy_sub)(const tensor *sz, int start_dim, int rnk) Chris@42: { Chris@42: tensor *x; Chris@42: Chris@42: A(FINITE_RNK(sz->rnk) && start_dim + rnk <= sz->rnk); Chris@42: x = X(mktensor)(rnk); Chris@42: dimcpy(x->dims, sz->dims + start_dim, rnk); Chris@42: return x; Chris@42: } Chris@42: Chris@42: tensor *X(tensor_append)(const tensor *a, const tensor *b) Chris@42: { Chris@42: if (!FINITE_RNK(a->rnk) || !FINITE_RNK(b->rnk)) { Chris@42: return X(mktensor)(RNK_MINFTY); Chris@42: } else { Chris@42: tensor *x = X(mktensor)(a->rnk + b->rnk); Chris@42: dimcpy(x->dims, a->dims, a->rnk); Chris@42: dimcpy(x->dims + a->rnk, b->dims, b->rnk); Chris@42: return x; Chris@42: } Chris@42: }