nns.c  1.0.1
Nanowire Network simulator
tensors.h File Reference

Contains an utilities to work with tensors. Not supposed to be used directly by the user. More...

#include <stdbool.h>
#include <stdlib.h>

Go to the source code of this file.

Macros

#define vector(TYPE, MACRO_LENGTH)
 Allocate a vector with the specified number of elements of the specified type. More...
 
#define zeros_vector(TYPE, MACRO_LENGTH)
 Allocate a vector with the specified number of elements and with the specified type and initialize it to 0. More...
 
#define matrix(TYPE, MACRO_WIDTH, MACRO_HEIGHT)
 Allocate a matrix of the specified type with the specified width and height. More...
 
#define zeros_matrix(TYPE, MACRO_WIDTH, MACRO_HEIGHT)
 Allocate a matrix of the specified type with the specified width and height and initialize it to zero. More...
 
#define free_matrix(MATRIX, MACRO_WIDTH)
 Free a matrix of the given width, including its sub-arrays. More...
 

Detailed Description

Contains an utilities to work with tensors. Not supposed to be used directly by the user.

Macro Definition Documentation

◆ free_matrix

#define free_matrix (   MATRIX,
  MACRO_WIDTH 
)
Value:
({ \
for (int MACRO_i = 0; MACRO_i < (MACRO_WIDTH); MACRO_i++) \
{ \
free(MATRIX[MACRO_i]); \
} \
free(MATRIX); \
})

Free a matrix of the given width, including its sub-arrays.

Parameters
[in]MATRIXThe matrix to free.
[in]MACRO_WIDTHThe width of the matrix, i.e. size of the array of pointers.

◆ matrix

#define matrix (   TYPE,
  MACRO_WIDTH,
  MACRO_HEIGHT 
)
Value:
({ \
TYPE** MATRIX_RESULT = vector(TYPE*, (MACRO_WIDTH)); \
for (int MACRO_i = 0; MACRO_i < (MACRO_WIDTH); MACRO_i++) \
{ \
MATRIX_RESULT[MACRO_i] = vector(TYPE, (MACRO_HEIGHT)); \
} \
MATRIX_RESULT; \
})
#define vector(TYPE, MACRO_LENGTH)
Allocate a vector with the specified number of elements of the specified type.
Definition: tensors.h:19

Allocate a matrix of the specified type with the specified width and height.

Parameters
[in]TYPEThe type of the matrix to allocate.
[in]MACRO_WIDTHThe width of the matrix, i.e. size of the array of pointers.
[in]MACRO_HEIGHTThe height of the matrix, i.e. size of the arrays of values.
Returns
The allocated matrix.

◆ vector

#define vector (   TYPE,
  MACRO_LENGTH 
)
Value:
({ \
TYPE* VECTOR_RESULT = (TYPE*)malloc((MACRO_LENGTH) * sizeof(TYPE)); \
if (VECTOR_RESULT == NULL) \
{ \
exit(EXIT_FAILURE); \
} \
VECTOR_RESULT; \
})

Allocate a vector with the specified number of elements of the specified type.

Parameters
[in]TYPEThe type of the array to allocate.
[in]MACRO_LENGTHThe number of elements contained in the array.
Returns
The allocated array.

◆ zeros_matrix

#define zeros_matrix (   TYPE,
  MACRO_WIDTH,
  MACRO_HEIGHT 
)
Value:
({ \
TYPE** MATRIX_RESULT = zeros_vector(TYPE*, (MACRO_WIDTH)); \
for (int MACRO_i = 0; MACRO_i < (MACRO_WIDTH); MACRO_i++) \
{ \
MATRIX_RESULT[MACRO_i] = zeros_vector(TYPE, (MACRO_HEIGHT)); \
} \
MATRIX_RESULT; \
})
#define zeros_vector(TYPE, MACRO_LENGTH)
Allocate a vector with the specified number of elements and with the specified type and initialize it...
Definition: tensors.h:35

Allocate a matrix of the specified type with the specified width and height and initialize it to zero.

Parameters
[in]TYPEThe type of the matrix to allocate.
[in]MACRO_WIDTHThe width of the matrix, i.e. size of the array of pointers.
[in]MACRO_HEIGHTThe height of the matrix, i.e. size of the arrays of values.
Returns
The allocated and zero-initialized matrix.

◆ zeros_vector

#define zeros_vector (   TYPE,
  MACRO_LENGTH 
)
Value:
({ \
TYPE* VECTOR_RESULT = (TYPE*)calloc((MACRO_LENGTH), sizeof(TYPE)); \
if (VECTOR_RESULT == NULL) \
{ \
exit(EXIT_FAILURE); \
} \
VECTOR_RESULT; \
})

Allocate a vector with the specified number of elements and with the specified type and initialize it to 0.

Parameters
[in]TYPEThe type of the array to allocate.
[in]MACRO_LENGTHThe number of elements contained in the array.
Returns
The allocated and zero-initialized array.