Tensor Network Theory Library  Beta release 1.2.1 A library of routines for performing TNT-based operations

## Detailed Description

Functions for dealing with simple 1D and 2D arrays. Always use these functions to free and allocate arrays to avoid memory errors.

## Functions

tntComplexArray tntComplexArrayAlloc (unsigned numrows, unsigned numcols)

tntComplexArray tntComplexArrayCreate (const char *array_string)

tntComplexArray tntComplexArrayCreateDiag (const char *array_string, int offs)

void tntComplexArrayFree (tntComplexArray *arr)

int tntComplexArrayIsReal (tntComplexArray *arr)

void tntComplexArrayPrint (tntComplexArray arr)

tntDoubleArray tntComplexArrayToReal (tntComplexArray *arr)

tntDoubleArray tntDoubleArrayAlloc (unsigned numrows, unsigned numcols)

tntDoubleArray tntDoubleArrayCreate (const char *array_string)

tntDoubleArray tntDoubleArrayCreateDiag (const char *array_string, int offs)

void tntDoubleArrayFree (tntDoubleArray *arr)

void tntDoubleArrayPrint (tntDoubleArray arr)

tntIntArray tntIntArrayAlloc (unsigned numrows, unsigned numcols)

tntIntArray tntIntArrayCreate (const char *array_string)

tntIntArray tntIntArrayCreateDiag (const char *array_string, int offs)

void tntIntArrayFree (tntIntArray *arr)

void tntIntArrayPrint (tntIntArray arr)

tntNodeArray tntNodeArrayAlloc (unsigned num_elems)

tntNodeArray tntNodeArrayCreate (tntNode A, tntNode B, tntNode C...)

void tntNodeArrayFree (tntNodeArray *arr)

void tntReshapeReuseEnable (void)

tntStringArray tntStringArrayAlloc (unsigned num_elems)

tntStringArray tntStringArrayCreate (const char *A, const char *B, const char *C...)

void tntStringArrayFree (tntStringArray *arr)

## Function Documentation

 tntComplexArray tntComplexArrayAlloc ( unsigned numrows, unsigned numcols )

Allocates an array for the tntComplexArray type, and sets the elements describing the dimensions with the appropriate value. If only one argument is given, an array with only one column is created. The array values are initialised to zero.

Returns
The allocated array.
Parameters
 numrows The number of rows. numcols The number of columns (optional argument).

Definition at line 392 of file tntArray.c.

 tntComplexArray tntComplexArrayCreate ( const char * array_string )

This function can be used to allocate and array and fill it with values at the same time.

It takes as an argument a string which represents the values to fill the array with.

Columns should be separated with a comma, and rows with a semicolon. Complex numbers must be printed without spaces e.g. the following types of numbers would be recognised 2.1,-1e4,10i,3-2i,-4i+1e-5 but 3 + 3i would not. All rows must have the same number of elements. For example the string "12.2+1i, 62, 93, -8, 1e-5; 16i, 2, 87, 43, 91; -4, 17e-4i, -72i+2, 95, 6" creates a 3-by-5 array

$\begin{pmatrix} 12.2 + 1\mathrm{i} & 62 & 93 & -8 & 10^{-5} \\ 16\mathrm{i} & 2 & 87 & 43 & 91 \\ -4 & 17 \cdot 10^{-4}\mathrm{i} & 2-72i & 95 & 6 \end{pmatrix}$

Returns
The allocated and filled array.
Parameters
 array_string The string representing the values to fill
Examples:
create_matrices.c, and create_nodes.c.

Definition at line 165 of file tntArray.c.

References tntAtoC().

 tntComplexArray tntComplexArrayCreateDiag ( const char * array_string, int offs )

This function can be used to allocate and array and fill it with values at the same time.

It takes as an argument a string which represents a row or column vector i.e. entries should be separated by a comma or space (for a row vector) or by semi-colons (for a column vector).

It forms a diagonal matrix from this vector offset from the main diagonal by the amount specified in the second argument.

A positive offset places the elements above the main diagonal, and a negative offset places the elements below the main diagonal.

The size of the returned array will be $$(L + |o|) \times (L + |o|)$$ where $$L$$ is the length of the vector and $$o$$ is the offset.

Returns
The allocated and filled array.
Parameters
 offs The string representing the values to fill
Examples:
create_matrices.c, and create_nodes.c.

Definition at line 316 of file tntArray.c.

References tntAtoC().

 void tntComplexArrayFree ( tntComplexArray * arr )

Frees the memory associated with the dynamically allocated array in the the tntComplexArray type, and sets the size to zero.

Returns
No return value.
Parameters
 arr The array to free
Examples:
create_matrices.c, create_nodes.c, and tntEvolve_if.c.

Definition at line 650 of file tntArray.c.

 int tntComplexArrayIsReal ( tntComplexArray * arr )

Determines whether there are any complex values in the array.

Returns
Returns 1 if there are no array entries with a non-negligible imaginary part, and 0 otherwise.
Parameters
 arr They array to free.

Definition at line 570 of file tntArray.c.

Referenced by tntComplexArrayToReal().

 void tntComplexArrayPrint ( tntComplexArray arr )

Prints the array to screen.

Returns
No return value.
Parameters
 arr The array to print.
Examples:
create_matrices.c.

Definition at line 60 of file tntPrint.c.

 tntDoubleArray tntComplexArrayToReal ( tntComplexArray * arr )

Converts a complex array to a double array. If any of the elements have a non-negligible imaginary part, then the absolute value of all elements is returned. Otherwise if all values are real then the real part is returned (i.e. a negative real number remains negative). The original complex matrix is destroyed.

Returns
A double array containing either the real part of the absolute value, depending on whether the original array was complex.
Parameters
 arr They array to free.

Definition at line 591 of file tntArray.c.

References tntComplexArrayFree(), and tntComplexArrayIsReal().

 tntDoubleArray tntDoubleArrayAlloc ( unsigned numrows, unsigned numcols )

Allocates an array for the tntDoubleArray type, and sets the elements describing the dimensions with the appropriate value. If only one argument is given, an array with only one column is created. The array values are initialised to zero.

Returns
The allocated array.
Parameters
 numrows The number of rows. numcols The number of columns (optional argument).

Definition at line 363 of file tntArray.c.

 tntDoubleArray tntDoubleArrayCreate ( const char * array_string )

This function can be used to allocate and array and fill it with values at the same time.

It takes as an argument a string which represents the values to fill the array with.

Columns should be separated with a comma, and rows with a semicolon. All rows must have the same number of elements. For example the string "12.2, 62, 93, -8, 1e-5; 16, 2, 87, 43, 91; -4, 17, -72, 95, 6" creates a 3-by-5 array

$\begin{pmatrix} 12.2 & 62 & 93 & -8 & 10^{-5} \\ 16 & 2 & 87 & 43 & 91 \\ -4 & 17 & -72 & 95 & 6 \end{pmatrix}$

Returns
The allocated and filled array.
Parameters
 array_string The string representing the values to fill
Examples:
create_matrices.c.

Definition at line 118 of file tntArray.c.

 tntDoubleArray tntDoubleArrayCreateDiag ( const char * array_string, int offs )

This function can be used to allocate and array and fill it with values at the same time.

It takes as an argument a string which represents a row or column vector i.e. entries should be separated by a comma or space (for a row vector) or by semi-colons (for a column vector).

It forms a diagonal matrix from this vector offset from the main diagonal by the amount specified in the second argument.

A positive offset places the elements above the main diagonal, and a negative offset places the elements below the main diagonal.

The size of the returned array will be $$(L + |o|) \times (L + |o|)$$ where $$L$$ is the length of the vector and $$o$$ is the offset.

Returns
The allocated and filled array.
Parameters
 offs The string representing the values to fill
Examples:
create_matrices.c.

Definition at line 262 of file tntArray.c.

 void tntDoubleArrayFree ( tntDoubleArray * arr )

Frees the memory associated with the dynamically allocated array in the the tntDoubleArray type, and sets the size to zero.

Returns
No return value.
Parameters
 arr The array to free.
Examples:
create_matrices.c.

Definition at line 635 of file tntArray.c.

Referenced by tntNodePrintAll().

 void tntDoubleArrayPrint ( tntDoubleArray arr )

Prints the array to screen.

Returns
No return value.
Parameters
 arr The array to print.
Examples:
create_matrices.c.

Definition at line 42 of file tntPrint.c.

 tntIntArray tntIntArrayAlloc ( unsigned numrows, unsigned numcols )

Allocates an array for the tntIntArray type, and sets the elements describing the dimensions with the appropriate value. If only one argument is given, an array with only one column is created. The array values are initialised to zero.

Returns
The allocated array.
Parameters
 numrows The number of rows. numcols The number of columns (optional argument).

Definition at line 29 of file tntArray.c.

 tntIntArray tntIntArrayCreate ( const char * array_string )

This function can be used to allocate and array and fill it with values at the same time.

It takes as an argument a string which represents the values to fill the array with.

Columns should be separated with a comma, and rows with a semicolon. All rows must have the same number of elements. For example the string "12, 62, 93, -8, 22; 16, 2, 87, 43, 91; -4, 17, -72, 95, 6" creates a 3-by-5 array

$\begin{pmatrix} 12 & 62 & 93 & -8 & 22 \\ 16 & 2 & 87 & 43 & 91 \\ -4 & 17 & -72 & 95 & 6 \end{pmatrix}$

Returns
The allocated and filled array.
Parameters
 array_string The string representing the values to fill
Examples:
create_matrices.c.

Definition at line 70 of file tntArray.c.

 tntIntArray tntIntArrayCreateDiag ( const char * array_string, int offs )

This function can be used to allocate and array and fill it with values at the same time.

It takes as an argument a string which represents a row or column vector i.e. entries should be separated by a comma or space (for a row vector) or by semi-colons (for a column vector).

It forms a diagonal matrix from this vector offset from the main diagonal by the amount specified in the second argument.

A positive offset places the elements above the main diagonal, and a negative offset places the elements below the main diagonal.

The size of the returned array will be $$(L + |o|) \times (L + |o|)$$ where $$L$$ is the length of the vector and $$o$$ is the offset.

Returns
The allocated and filled array.
Parameters
 offs The string representing the values to fill
Examples:
create_matrices.c.

Definition at line 208 of file tntArray.c.

 void tntIntArrayFree ( tntIntArray * arr )

Frees the memory associated with the dynamically allocated array in the the tntIntArray type, and sets the size to zero.

Returns
No return value.
Parameters
 arr They array to free.
Examples:
create_matrices.c, and tntEvolve_if.c.

Definition at line 620 of file tntArray.c.

 void tntIntArrayPrint ( tntIntArray arr )

Prints the array to screen.

Returns
No return value.
Parameters
 arr The array to print.
Examples:
create_matrices.c.

Definition at line 23 of file tntPrint.c.

 tntNodeArray tntNodeArrayAlloc ( unsigned num_elems )

Allocates an array for the tntNodeArray type, and sets the element sz with the appropriate value. The array values themselves are initialised to NULL. To avoid memory errors when freeing the array, ensure that each entry corresponds to a different node. Use tntNodeCopy() if entries should contain the same node.

Returns
The allocated array.
Parameters
 num_elems Number of elements needed in array.

Definition at line 428 of file tntArray.c.

 tntNodeArray tntNodeArrayCreate ( tntNode A, tntNode B, tntNode C... )

This function can be used to create an array and fill it with values at the same time. This function accepts a minimum of 1 and a maximum of 24 nodes as arguments. Copies of the nodes are used, rather than the nodes passed as arguments. Any NULL arguments are ignored.

Returns
The allocated and filled array.
Parameters
 A First node to add to list B Second node to add to list C... (optional) Third to twenty-fourth nodes to add to array
Examples:
create_exop.c.

Definition at line 450 of file tntArray.c.

References tntNodeCopy().

 void tntNodeArrayFree ( tntNodeArray * arr )

Frees the memory associated with the dynamically allocated array in the the tntNodeArray type, and sets the size to zero.

If an entry is not NULL, also frees the node associated with that entry.

Returns
No return value.
Parameters
 arr The array to free
Examples:
tntEvolve_if.c, and tntGS_cl.c.

Definition at line 668 of file tntArray.c.

 void tntReshapeReuseEnable ( void )

Enables the storage of the translations done in the reshape component. This will consume memory but typically at a great saving of computational time. Enabled by default.

Returns
No return value.

Definition at line 549 of file tntSys.c.

 tntStringArray tntStringArrayAlloc ( unsigned num_elems )

Allocates an array for the tntStringArray type, and sets the element sz with the appropriate value. Each string has a maximum length of TNT_STRLEN. The array values themselves are uninitialised to NULL.

Returns
The allocated array.
Parameters
 num_elems Number of elements needed in array.

Definition at line 492 of file tntArray.c.

Referenced by tntMpsProcessExpecOptions().

 tntStringArray tntStringArrayCreate ( const char * A, const char * B, const char * C... )

This function can be used to create an array and fill it with values at the same time. This function accepts a minimum of 1 and a maximum of 24 strings as arguments. Any NULL arguments are ignored.

Returns
The allocated and filled array.
Parameters
 A First string to add to list B Second string to add to list C... (optional) Third to twenty-fourth nodes to add to array
Examples:
create_exop.c.

Definition at line 522 of file tntArray.c.

 void tntStringArrayFree ( tntStringArray * arr )

Frees the memory associated with the dynamically allocated array in the the tntStringArray type, and sets the size to zero.

It also assumes that the character arrays representing the strings themselves have been dynamically allocated (which is the case if the array was created using tntStringArrayAlloc()) and frees these too.

Returns
No return value.
Parameters
 arr The array to free

Definition at line 684 of file tntArray.c.

Referenced by tntMpsExOpFree(), and tntMpsProcessExpecOptions().