2 Functions
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:
- complex: complex double
- long_double: long double
- float: float
- ulong: unsigned long
- long: long
- uint: unsigned int
- int: int
- ushort: unsigned short
- short: short
- uchar: unsigned char
- char: char
Allocation
- Function: 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.
- Function: 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.
- Function: tensor * tensor_copy (tensor * t);
Create a copy of tensor t and return a pointer to its position in memory.
- Function: void tensor_free (tensor * t);
Release the memory used by tensor t.
Conversion
- Function: gsl_matrix * tensor_2matrix (tensor * t);
Convert a rank 2 tensor to a gsl_matrix.
- Function: gsl_vector * tensor_2vector (tensor * t);
Convert a rank 1 tensor to a gsl_vector.
Get/Set elements
- Function: double tensor_get (const tensor * t, const size_t * indices);
t[indices]
- Function: void tensor_set (tensor * t, const size_t * indices, const double x);
t[indices] = x
Access pointer
- Function: double * tensor_ptr (tensor * t, const size_t * indices);
&t[indices]
- Function: const double * tensor_const_ptr (const tensor * t, const size_t * indices);
&t[indices] (const pointer)
Set to a value
- Function: void tensor_set_zero (tensor * t);
t = 0
- Function: void tensor_set_all (tensor * t, double x);
t = x
IO
- Function: int tensor_fread (FILE * stream, tensor * t);
Read binary representation of tensor from stream and save it in t.
- Function: int tensor_fwrite (FILE * stream, const tensor * t);
Write binary representation of tensor t to stream.
- Function: int tensor_fscanf (FILE * stream, tensor * t);
Read text representation of tensor from stream and save it in t.
- Function: 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
- Function: int tensor_memcpy (tensor * dest, const tensor * src);
dest = src
- Function: int tensor_swap (tensor * t1, tensor * t2);
t1, t2 = t2, t1
Swap indices
- Function: tensor * tensor_swap_indices (const tensor * t_ij, size_t i, size_t j);
t[i,j] = t[j,i]
Maxima
- Function: double tensor_max (const tensor * t);
Maximum element of tensor t.
- Function: double tensor_min (const tensor * t);
Minimum element of tensor t.
- Function: 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.
- Function: void tensor_max_index (const tensor * t, size_t * indices);
Get the indices of the maximum element of t.
- Function: void tensor_min_index (const tensor * t, size_t * indices);
Get the indices of the minimum element of t.
- Function: 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
- Function: int tensor_isnull (const tensor * t);
t == 0
Operations
- Function: int tensor_add (tensor * a, const tensor * b);
a += b
- Function: int tensor_sub (tensor * a, const tensor * b);
a -= b
- Function: int tensor_mul_elements (tensor * a, const tensor * b);
a .*= b
- Function: int tensor_div_elements (tensor * a, const tensor * b);
a ./= b
- Function: int tensor_scale (tensor * a, const double x);
a *= x
- Function: int tensor_add_constant (tensor * a, const double x);
a += x
- Function: int tensor_add_diagonal (tensor * a, const double x);
a += x*I
- Function: tensor * tensor_product (const tensor * a, const tensor * b);
a * b (generalization of matrix product)
- Function: tensor * tensor_contract (const tensor * t_ij, size_t i, size_t j);
t[i1,i2,i3,...] with indices i=j.