/* tensor/tensor_source.c * * Copyright (C) 2003 Jordi Burguet-Castell * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or (at * your option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #ifndef HIDE_INLINE_STATIC size_t FUNCTION (gsl_tensor, position) (va_list argptr, const TYPE (gsl_tensor) * t) { size_t shift, position; int i; shift = quick_pow(t->dimension, t->rank-1); position = 0; for (i = 0; i < t->rank; i++) { position += shift * va_arg(argptr, int); shift /= m_dimension; } return position; } BASE FUNCTION (gsl_tensor, get) (const TYPE (gsl_tensor) * t, ...) { size_t position; va_list argptr; va_start(argptr, t); position = FUNCTION (gsl_tensor, position) (argptr, t); va_end(argptr); return *(BASE *) (m->data + MULTIPLICITY * position); } void FUNCTION (gsl_tensor, set) (TYPE (gsl_tensor) * t, const BASE x, ...) { size_t position; va_list argptr; va_start(argptr, t); position = FUNCTION (gsl_tensor, position) (argptr, t); va_end(argptr); *(BASE *) (m->data + MULTIPLICITY * position) = x; } BASE * FUNCTION (gsl_tensor, ptr) (TYPE (gsl_tensor) * t, ...) { size_t position; va_list argptr; va_start(argptr, t); position = FUNCTION (gsl_tensor, position) (argptr, t); va_end(argptr); return (BASE *) (m->data + MULTIPLICITY * position); } const BASE * FUNCTION (gsl_tensor, const_ptr) (const TYPE (gsl_tensor) * t, ...) { size_t position; va_list argptr; va_start(argptr, t); position = FUNCTION (gsl_tensor, position) (argptr, t); va_end(argptr); return (const BASE *) (m->data + MULTIPLICITY * position); } #endif