The functions tensor_f work with elements of type double.
There are other versions of the form tensor_TYPE_f where TYPE is any of:
Allocation
tensor * tensor_alloc (const unsigned int rank, const size_t dimension); ¶Allocate memory for a tensor of rank rank and dimension dimension, and return a pointer to its position in memory.
tensor * tensor_calloc (const unsigned int rank, const size_t dimension); ¶Allocate memory for a tensor of rank rank and dimension dimension, set all its elements to 0 and return a pointer to its position in memory.
tensor * tensor_copy (tensor * t); ¶Create a copy of tensor t and return a pointer to its position in memory.
void tensor_free (tensor * t); ¶Release the memory used by tensor t.
Conversion
gsl_matrix * tensor_2matrix (tensor * t); ¶Convert a rank 2 tensor to a gsl_matrix.
gsl_vector * tensor_2vector (tensor * t); ¶Convert a rank 1 tensor to a gsl_vector.
Get/Set elements
double tensor_get (const tensor * t, const size_t * indices); ¶t[indices]
void tensor_set (tensor * t, const size_t * indices, const double x); ¶t[indices] = x
Access pointer
double * tensor_ptr (tensor * t, const size_t * indices); ¶&t[indices]
const double * tensor_const_ptr (const tensor * t, const size_t * indices); ¶&t[indices] (const pointer)
Set to a value
void tensor_set_zero (tensor * t); ¶t = 0
void tensor_set_all (tensor * t, double x); ¶t = x
IO
int tensor_fread (FILE * stream, tensor * t); ¶Read binary representation of tensor from stream and save it in t.
int tensor_fwrite (FILE * stream, const tensor * t); ¶Write binary representation of tensor t to stream.
int tensor_fscanf (FILE * stream, tensor * t); ¶Read text representation of tensor from stream and save it in t.
int tensor_fprintf (FILE * stream, const tensor * t, const char * format); ¶Write text representation of tensor t to stream, using format format for its elements.
Copy
int tensor_memcpy (tensor * dest, const tensor * src); ¶dest = src
int tensor_swap (tensor * t1, tensor * t2); ¶t1, t2 = t2, t1
Swap indices
tensor * tensor_swap_indices (const tensor * t_ij, size_t i, size_t j); ¶t[i,j] = t[j,i]
Maxima
double tensor_max (const tensor * t); ¶Maximum element of tensor t.
double tensor_min (const tensor * t); ¶Minimum element of tensor t.
void tensor_minmax (const tensor * t, double * min_out, double * max_out); ¶Copy the minimum and maximum elements of t in min_out and max_out respectively.
void tensor_max_index (const tensor * t, size_t * indices); ¶Get the indices of the maximum element of t.
void tensor_min_index (const tensor * t, size_t * indices); ¶Get the indices of the minimum element of t.
void tensor_minmax_index (const tensor * t, size_t * imin, size_t * imax); ¶Get the indices of the minimum and maximum elements of t.
Properties
int tensor_isnull (const tensor * t); ¶t == 0
Operations
int tensor_add (tensor * a, const tensor * b); ¶a += b
int tensor_sub (tensor * a, const tensor * b); ¶a -= b
int tensor_mul_elements (tensor * a, const tensor * b); ¶a .*= b
int tensor_div_elements (tensor * a, const tensor * b); ¶a ./= b
int tensor_scale (tensor * a, const double x); ¶a *= x
int tensor_add_constant (tensor * a, const double x); ¶a += x
int tensor_add_diagonal (tensor * a, const double x); ¶a += x*I
tensor * tensor_product (const tensor * a, const tensor * b); ¶a * b (generalization of matrix product)
tensor * tensor_contract (const tensor * t_ij, size_t i, size_t j); ¶t[i1,i2,i3,...] with indices i=j.