/* tensor/gsl_tensor_double.h * * 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. */ /* * This file contains the basic declarations for a tensor. * * Gosh, someone changes this temporary entry! */ #ifndef __GSL_TENSOR_DOUBLE_H__ #define __GSL_TENSOR_DOUBLE_H__ /* I am not sure they are neede here, but anyway */ #include #include #include #undef __BEGIN_DECLS #undef __END_DECLS #ifdef __cplusplus # define __BEGIN_DECLS extern "C" { # define __END_DECLS } #else # define __BEGIN_DECLS /* empty */ # define __END_DECLS /* empty */ #endif __BEGIN_DECLS /* * A tensor is a struct with the rank of the tensor (number of indices * it has), the dimension of the vectorial space it is in (number of * different possible values for each index) and an array to store the * dimension^rank values. * * For the moment, there is no tda, as opossed to matrices, because it * would complicate quite a bit the algorithms and probably it is not * worth it. */ typedef struct { unsigned int rank; size_t dimension; double * data; } gsl_tensor; /* * There is not such a thing as "tensor views", in contrast with the * case for gsl_matrix. */ /* Allocation */ gsl_tensor * gsl_tensor_alloc (const unsigned int rank, const size_t dimension); gsl_tensor * gsl_tensor_calloc (const unsigned int rank, const size_t dimension); gsl_tensor * gsl_tensor_copy (gsl_tensor * t); void gsl_tensor_free (gsl_tensor * t); /* Views */ /* * There are no views. */ /* Operations */ double gsl_tensor_get(const gsl_tensor * t, ...); void gsl_tensor_set(gsl_tensor * t, const double x, ...); double * gsl_tensor_ptr(gsl_tensor * t, ...); const double * gsl_tensor_const_ptr(const gsl_tensor * t, ...); void gsl_tensor_set_zero (gsl_tensor * t); void gsl_tensor_set_all (gsl_tensor * t, double x); int gsl_tensor_fread (FILE * stream, gsl_tensor * t); int gsl_tensor_fwrite (FILE * stream, const gsl_tensor * t); int gsl_tensor_fscanf (FILE * stream, gsl_tensor * t); int gsl_tensor_fprintf (FILE * stream, const gsl_tensor * t, const char * format); int gsl_tensor_memcpy(gsl_tensor * dest, const gsl_tensor * src); int gsl_tensor_swap(gsl_tensor * t1, gsl_tensor * t2); int gsl_tensor_swap_indices (gsl_tensor * t, unsigned int i, unsigned int j); double gsl_tensor_max (const gsl_tensor * t); double gsl_tensor_min (const gsl_tensor * t); void gsl_tensor_minmax (const gsl_tensor * t, double * min_out, double * max_out); void gsl_tensor_max_index (const gsl_tensor * t, ...); void gsl_tensor_min_index (const gsl_tensor * t, ...); void gsl_tensor_minmax_index (const gsl_tensor * t, ...); int gsl_tensor_isnull (const gsl_tensor * t); int gsl_tensor_add (gsl_tensor * a, const gsl_tensor * b); int gsl_tensor_sub (gsl_tensor * a, const gsl_tensor * b); int gsl_tensor_mul_elements (gsl_tensor * a, const gsl_tensor * b); int gsl_tensor_div_elements (gsl_tensor * a, const gsl_tensor * b); int gsl_tensor_scale (gsl_tensor * a, const double x); int gsl_tensor_add_constant (gsl_tensor * a, const double x); int gsl_tensor_add_diagonal (gsl_tensor * a, const double x); GSL_VAR int gsl_check_range ; /* inline functions if you are using GCC */ #ifdef HAVE_INLINE extern inline size_t gsl_tensor_position(va_list argptr, const gsl_tensor * t) { size_t shift, position; unsigned int i; shift = quick_pow(t->dimension, t->rank-1); position = 0; for (i = 0; i < t->rank; i++) { position += shift * va_arg(argptr, unsigned int); shift /= m_dimension; } return position; } extern inline double gsl_tensor_get(const gsl_tensor * t, ...) { size_t position; va_list argptr; va_start(argptr, t); position = gsl_tensor_position(argptr, t); va_end(argptr); return t->data[position]; } extern inline void gsl_tensor_set(const gsl_tensor * t, const double x, ...) { size_t position; va_list argptr; va_start(argptr, t); position = gsl_tensor_position(argptr, t); va_end(argptr); t->data[position] = x; } extern inline double * gsl_tensor_ptr(gsl_tensor * t, ...) { size_t position; va_list argptr; va_start(argptr, t); position = gsl_tensor_position(argptr, t); va_end(argptr); return (double *) (m->data + position); } extern inline const double * gsl_tensor_const_ptr(const gsl_tensor * m, ...) { size_t position; va_list argptr; va_start(argptr, t); position = gsl_tensor_position(argptr, t); va_end(argptr); return (const double *) (m->data + position); } #endif __END_DECLS #endif /* __GSL_TENSOR_DOUBLE_H__ */