AIfES 2  2.0.0
aimath_f32_default.h File Reference

Math functions for F32 data type, default implementation. More...

Go to the source code of this file.

Functions

void aimath_f32_default_linear (const aitensor_t *a, const aitensor_t *b, const aitensor_t *c, aitensor_t *result)
 Performs a matrix multiplication of F32 matrices a and b and adds a vector c to each row. More...
 
void aimath_f32_default_linear_at (const aitensor_t *a, const aitensor_t *b, const aitensor_t *c, aitensor_t *result)
 Performs a matrix multiplication of F32 matrices a (transposed) and b and adds a vector c to each row. More...
 
void aimath_f32_default_linear_bt (const aitensor_t *a, const aitensor_t *b, const aitensor_t *c, aitensor_t *result)
 Performs a matrix multiplication of F32 matrices a and b (transposed) and adds a vector c to each row. More...
 
void aimath_f32_default_linear_atrt (const aitensor_t *a, const aitensor_t *b, const aitensor_t *c, aitensor_t *result)
 Performs a matrix multiplication with transposed result of F32 matrices a (transposed) and b and adds a vector c to each row. More...
 
void aimath_f32_default_mat_mul (const aitensor_t *a, const aitensor_t *b, aitensor_t *result)
 Performs a matrix multiplication of F32 matrices a and b. More...
 
void aimath_f32_default_mat_mul_at (const aitensor_t *a, const aitensor_t *b, aitensor_t *result)
 Performs a matrix multiplication of F32 matrices a (transposed) and b. More...
 
void aimath_f32_default_mat_mul_bt (const aitensor_t *a, const aitensor_t *b, aitensor_t *result)
 Performs a matrix multiplication of F32 matrices a and b (transposed) More...
 
void aimath_f32_default_mat_mul_atrt (const aitensor_t *a, const aitensor_t *b, aitensor_t *result)
 Performs a matrix multiplication with transposed result of F32 matrices a (transposed) and b. More...
 
void aimath_f32_default_multiply (const aitensor_t *a, const aitensor_t *b, aitensor_t *result)
 Performs an element wise multiplication of F32 tensors a and b (Hadamard product) More...
 
void aimath_f32_default_divide (const aitensor_t *a, const aitensor_t *b, aitensor_t *result)
 Performs an element wise division of F32 tensors a and b (Hadamard division) More...
 
void aimath_f32_default_scalar_mul (const void *scalar, const aitensor_t *a, aitensor_t *result)
 Performs a scalar multiplication (scaling) of F32 tensor a and a scalar. More...
 
void aimath_f32_default_scalar_add (const void *scalar, const aitensor_t *a, aitensor_t *result)
 Performs an element wise addition of a scalar to a F32 tensor. More...
 
void aimath_f32_default_tensor_add (const aitensor_t *a, const aitensor_t *b, aitensor_t *result)
 Performs an element wise addition of F32 tensors a and b. More...
 
void aimath_f32_default_tensor_sub (const aitensor_t *a, const aitensor_t *b, aitensor_t *result)
 Performs a element wise subtraction of F32 tensors a and b. More...
 
void aimath_f32_default_tensor_sub_sparse8 (const aitensor_t *a, const aitensor_t *b, aitensor_t *result)
 Performs a subtraction between a F32 matrix a and a U8 sparse matrix b. More...
 
void aimath_f32_default_copy_tensor (const aitensor_t *from, aitensor_t *to)
 Performs an element wise copy of F32 tensors. More...
 
void aimath_f32_default_transpose_vector (aitensor_t *vector)
 Transposes a F32 vector. More...
 
void aimath_f32_default_transpose_matrix (aitensor_t *x)
 Transpose a F32 tensor. More...
 
void aimath_f32_default_norm_squared (const aitensor_t *x, void *result)
 Calculates the squared sum of all elements in a F32 tensor. More...
 
void aimath_f32_default_sum (const aitensor_t *x, void *result)
 Calculates the sum of all elements in a F32 tensor. More...
 
void aimath_f32_default_min (const aitensor_t *x, void *result)
 Identifies the minimum value in a F32 tensor. More...
 
void aimath_f32_default_max (const aitensor_t *x, void *result)
 Identifies the maximum value in a F32 tensor. More...
 
void aimath_f32_default_sigmoid (const aitensor_t *x, aitensor_t *result)
 Calculates the sigmoid of each element in a F32 tensor. More...
 
void aimath_f32_default_d_sigmoid (const aitensor_t *sigmoid_x, aitensor_t *result)
 Calculates the derivative sigmoid of each element in a F32 tensor. More...
 
void aimath_f32_default_tanh (const aitensor_t *x, aitensor_t *result)
 Calculates the tanh of each element in a F32 tensor. More...
 
void aimath_f32_default_d_tanh (const aitensor_t *tanh_x, aitensor_t *result)
 Calculates the tanh derivative of each element in a F32 tensor. More...
 
void aimath_f32_default_relu (const aitensor_t *x, aitensor_t *result)
 Calculates the rectifier (ReLU) value of each element in a F32 tensor. More...
 
void aimath_f32_default_d_relu (const aitensor_t *x, aitensor_t *result)
 Calculates the rectifier (ReLU) derivative of each element in a F32 tensor. More...
 
void aimath_f32_default_leaky_relu (const aitensor_t *x, const void *alpha, aitensor_t *result)
 Calculates the leaky rectifier (leaky ReLU) value of each element in a F32 tensor. More...
 
void aimath_f32_default_d_leaky_relu (const aitensor_t *x, const void *alpha, aitensor_t *result)
 Calculates the leaky rectifier (leaky ReLU) derivative of each element in a F32 tensor. More...
 
void aimath_f32_default_elu (const aitensor_t *x, const void *alpha, aitensor_t *result)
 Calculates the exponential rectifier (ELU) value of each element in a F32 tensor. More...
 
void aimath_f32_default_d_elu (const aitensor_t *x, const void *alpha, aitensor_t *result)
 Calculates the exponential rectifier (ELU) derivative of each element in a F32 tensor. More...
 
void aimath_f32_default_softmax (const aitensor_t *x, aitensor_t *result)
 Calculates the softmax value of each row of a F32 matrix. More...
 
void aimath_f32_default_softsign (const aitensor_t *x, aitensor_t *result)
 Calculates the softsign value of each element in a F32 tensor. More...
 
void aimath_f32_default_d_softsign (const aitensor_t *x, aitensor_t *result)
 Calculates the softsign derivative of each element in a F32 tensor. More...
 
void aimath_f32_default_binary_crossentropy_sum (const aitensor_t *predicted_data, const aitensor_t *target_data, void *result)
 Calculates the binary cross entropy between the F32 predicted and the target data using a sum reduction. More...
 
void aimath_f32_default_binary_crossentropy_mean (const aitensor_t *predicted_data, const aitensor_t *target_data, void *result)
 Calculates the binary cross entropy between the F32 predicted and the target data using a mean reduction. More...
 
void aimath_f32_default_categorical_crossentropy_sum (const aitensor_t *predicted_data, const aitensor_t *target_data, void *result)
 Calculates the categorical cross entropy between the F32 predicted and the target data using a sum reduction. More...
 
void aimath_f32_default_categorical_crossentropy_mean (const aitensor_t *predicted_data, const aitensor_t *target_data, void *result)
 Calculates the categorical cross entropy between the F32 predicted and the target data using a mean reduction. More...
 
void aimath_f32_default_categorical_crossentropy_sum_sparse8 (const aitensor_t *predicted_data, const aitensor_t *target_data, void *result)
 Calculates the categorical Cross-Entropy between the F32 predicted data and the U8 target data in sparse representation using a sum reduction. More...
 
void aimath_f32_default_categorical_crossentropy_mean_sparse8 (const aitensor_t *predicted_data, const aitensor_t *target_data, void *result)
 Calculates the categorical Cross-Entropy between the F32 predicted data and the U8 target data in sparse representation using a mean reduction. More...
 
void aimath_f32_default_sqrt (const aitensor_t *x, aitensor_t *result)
 Calculates the element wise square root of a F32 tensor. More...
 
void aimath_f32_default_zero_tensor (aitensor_t *tensor)
 Fills a F32 tensor with zeros. More...
 
void aimath_f32_default_init_zeros (aitensor_t *tensor)
 Fills a F32 tensor with zeros. More...
 
void aimath_f32_default_init_ones (aitensor_t *tensor)
 Fills a F32 tensor with ones. More...
 
void aimath_f32_default_tensor_init_uniform (aitensor_t *tensor, float from, float to)
 Fills a F32 tensor with random numbers created from a uniform distribution within given range. More...
 
void aimath_f32_default_init_glorot_uniform (aitensor_t *tensor)
 Fills a F32 tensor with random numbers uniformly within given range, according to Glorot et al. More...
 
void aimath_f32_default_init_glorot_uniform_cdim (aitensor_t *tensor, int8_t cin_axis, int8_t cout_axis)
 Fills a F32 tensor with random numbers uniformly within given range, according to Glorot et al. More...
 
void aimath_f32_default_init_he_uniform (aitensor_t *tensor)
 Fills a F32 tensor with uniformly drawn random numbers within given range, according to He et al. More...
 
void aimath_f32_default_init_he_uniform_cdim (aitensor_t *tensor, int8_t cout_axis)
 Fills a F32 tensor with uniformly drawn random numbers within given range, according to He et al. More...
 
float aimath_f32_default_expf_fast (const float x)
 Fast approximation of the exponential function. More...
 
void aimath_f32_default_mean_channelwise (const aitensor_t *x, int8_t channel_axis, aitensor_t *result)
 Sums up all values of a channel of the F32 tensor x. More...
 
void aimath_f32_default_variance_channelwise (const aitensor_t *x, int8_t channel_axis, const aitensor_t *means, aitensor_t *result)
 Calculate the channel-wise variances of the F32 tensor x. More...
 
void aimath_f32_default_exponential_moving_average (const aitensor_t *new_data, const void *momentum, aitensor_t *average)
 Perform an exponential moving average. More...
 
void aimath_f32_default_mse_gradients_sum (const aitensor_t *predicted, const aitensor_t *target, aitensor_t *result)
 Calculates the gradients of the mean squared error between the F32 predicted and the target data using a sum reduction. More...
 
void aimath_f32_default_mse_gradients_mean (const aitensor_t *predicted, const aitensor_t *target, aitensor_t *result)
 Calculates the gradients of the mean squared error between the F32 predicted and the target data using a mean reduction. More...
 
void aimath_f32_default_mse_loss_sum (const aitensor_t *predicted, const aitensor_t *target, void *result)
 Calculates the mean squared error between the F32 predicted and the target data using a sum reduction. More...
 
void aimath_f32_default_mse_loss_mean (const aitensor_t *predicted, const aitensor_t *target, void *result)
 Calculates the mean squared error between the F32 predicted and the target data using a mean reduction. More...
 
void aimath_f32_default_scale_by_batch_size (const aitensor_t *a, aitensor_t *result)
 Scales a F32 tensor by batch size (size of first dimension) More...
 

Detailed Description

Math functions for F32 data type, default implementation.

Version
2.2.0

These functions can be used when no hardware specific implementation is available.

Function Documentation

◆ aimath_f32_default_binary_crossentropy_mean()

void aimath_f32_default_binary_crossentropy_mean ( const aitensor_t predicted_data,
const aitensor_t target_data,
void *  result 
)

Calculates the binary cross entropy between the F32 predicted and the target data using a mean reduction.

\[ result = - \sum_i (target_i \cdot \log(predicted_i) + (1 - target_i) \cdot \log(1 - predicted_i)) \]

Example:

uint16_t p_shape[2] = {2, 3};
float p_data[2*3] = {0.8f, 0.1f, 0.7f,
0.2f, 0.3f, 0.0f};
aitensor_t p = AITENSOR_2D_F32(p_shape, p_data);
uint16_t t_shape[2] = {2, 3};
float t_data[2*3] = {1.0f, 0.0f, 1.0f,
0.0f, 0.0f, 0.0f};
aitensor_t t = AITENSOR_2D_F32(t_shape, t_data);
float result;
void print_aiscalar(const void *scalar, const aimath_dtype_t *dtype)
Printing a scalar to console.
const aimath_dtype_t * aif32
The F32 data-type indicator.
void aimath_f32_default_binary_crossentropy_mean(const aitensor_t *predicted_data, const aitensor_t *target_data, void *result)
Calculates the binary cross entropy between the F32 predicted and the target data using a mean reduc...
A tensor in AIfES.
Definition: aifes_math.h:89
Parameters
*predicted_dataF32 matrix with the predicted or calculated values (2D tensor)
*target_dataF32 matrix with the target data / true values / labels (2D tensor with binary values 0 or 1)
*resultResulting F32 matrix (2D tensor)

◆ aimath_f32_default_binary_crossentropy_sum()

void aimath_f32_default_binary_crossentropy_sum ( const aitensor_t predicted_data,
const aitensor_t target_data,
void *  result 
)

Calculates the binary cross entropy between the F32 predicted and the target data using a sum reduction.

\[ result = - \sum_i (target_i \cdot \log(predicted_i) + (1 - target_i) \cdot \log(1 - predicted_i)) \]

Example:

uint16_t p_shape[2] = {2, 3};
float p_data[2*3] = {0.8f, 0.1f, 0.7f,
0.2f, 0.3f, 0.0f};
aitensor_t p = AITENSOR_2D_F32(p_shape, p_data);
uint16_t t_shape[2] = {2, 3};
float t_data[2*3] = {1.0f, 0.0f, 1.0f,
0.0f, 0.0f, 0.0f};
aitensor_t t = AITENSOR_2D_F32(t_shape, t_data);
float result;
void aimath_f32_default_binary_crossentropy_sum(const aitensor_t *predicted_data, const aitensor_t *target_data, void *result)
Calculates the binary cross entropy between the F32 predicted and the target data using a sum reduct...
Parameters
*predicted_dataF32 matrix with the predicted or calculated values (2D tensor)
*target_dataF32 matrix with the target data / true values / labels (2D tensor with binary values 0 or 1)
*resultResulting F32 matrix (2D tensor)

◆ aimath_f32_default_categorical_crossentropy_mean()

void aimath_f32_default_categorical_crossentropy_mean ( const aitensor_t predicted_data,
const aitensor_t target_data,
void *  result 
)

Calculates the categorical cross entropy between the F32 predicted and the target data using a mean reduction.

\[ result = - \sum_i target_i \cdot \log(predicted_i) \]

Example:

uint16_t p_shape[2] = {2, 3};
float p_data[2*3] = {0.2f, 0.1f, 0.7f,
0.9f, 0.1f, 0.0f};
aitensor_t p = AITENSOR_2D_F32(p_shape, p_data);
uint16_t t_shape[2] = {2, 3};
float t_data[2*3] = {0.0f, 0.0f, 1.0f,
1.0f, 0.0f, 0.0f};
aitensor_t t = AITENSOR_2D_F32(t_shape, t_data);
float result;
void aimath_f32_default_categorical_crossentropy_mean(const aitensor_t *predicted_data, const aitensor_t *target_data, void *result)
Calculates the categorical cross entropy between the F32 predicted and the target data using a mean ...
Parameters
*predicted_dataF32 matrix with the predicted or calculated values (2D tensor)
*target_dataF32 matrix with the target data / true values / labels (2D tensor, rows one-hot encoded)
*resultResulting F32 matrix (2D tensor)

◆ aimath_f32_default_categorical_crossentropy_mean_sparse8()

void aimath_f32_default_categorical_crossentropy_mean_sparse8 ( const aitensor_t predicted_data,
const aitensor_t target_data,
void *  result 
)

Calculates the categorical Cross-Entropy between the F32 predicted data and the U8 target data in sparse representation using a mean reduction.

This function can calculate the crossentropy between a row wise one-hot encoded matrix in sparse representation (just the integer index of the 1 is stored) and a normal F32 matrix a.

For example the matrix

\[ \left( \begin{array}{ccc} 0 & 0 & 0 & 1 \\ 1 & 0 & 0 & 0 \\ 0 & 0 & 1 & 0 \end{array}\right) \]

in sparse representation is

\[ \left( \begin{array}{ccc} 3 \\ 0 \\ 2 \end{array}\right) \]

The result is then calculated from the one-hot encoded target matrix:

\[ result = - \sum_i target_{one-hot,i} \cdot \log(predicted_i) \]

Example:

uint16_t p_shape[2] = {2, 3};
float p_data[2*3] = {0.2f, 0.1f, 0.7f,
0.9f, 0.1f, 0.0f};
aitensor_t p = AITENSOR_2D_F32(p_shape, p_data);
uint16_t t_shape[2] = {2, 1};
uint8_t t_data[2*1] = {2,
0};
aitensor_t t = AITENSOR_2D_U8(t_shape, t_data);
float result;
void aimath_f32_default_categorical_crossentropy_mean_sparse8(const aitensor_t *predicted_data, const aitensor_t *target_data, void *result)
Calculates the categorical Cross-Entropy between the F32 predicted data and the U8 target data in s...
Parameters
*predicted_dataF32 matrix with the predicted or calculated values (2D tensor of shape [N x M])
*target_dataU8 matrix with the target data / true values / labels (2D tensor of shape [N x 1] with true class indices)
*resultResulting F32 matrix (2D tensor of shape [N x M])

◆ aimath_f32_default_categorical_crossentropy_sum()

void aimath_f32_default_categorical_crossentropy_sum ( const aitensor_t predicted_data,
const aitensor_t target_data,
void *  result 
)

Calculates the categorical cross entropy between the F32 predicted and the target data using a sum reduction.

\[ result = - \sum_i target_i \cdot \log(predicted_i) \]

Example:

uint16_t p_shape[2] = {2, 3};
float p_data[2*3] = {0.2f, 0.1f, 0.7f,
0.9f, 0.1f, 0.0f};
aitensor_t p = AITENSOR_2D_F32(p_shape, p_data);
uint16_t t_shape[2] = {2, 3};
float t_data[2*3] = {0.0f, 0.0f, 1.0f,
1.0f, 0.0f, 0.0f};
aitensor_t t = AITENSOR_2D_F32(t_shape, t_data);
float result;
void aimath_f32_default_categorical_crossentropy_sum(const aitensor_t *predicted_data, const aitensor_t *target_data, void *result)
Calculates the categorical cross entropy between the F32 predicted and the target data using a sum r...
Parameters
*predicted_dataF32 matrix with the predicted or calculated values (2D tensor)
*target_dataF32 matrix with the target data / true values / labels (2D tensor, rows one-hot encoded)
*resultResulting F32 matrix (2D tensor)

◆ aimath_f32_default_categorical_crossentropy_sum_sparse8()

void aimath_f32_default_categorical_crossentropy_sum_sparse8 ( const aitensor_t predicted_data,
const aitensor_t target_data,
void *  result 
)

Calculates the categorical Cross-Entropy between the F32 predicted data and the U8 target data in sparse representation using a sum reduction.

This function can calculate the crossentropy between a row wise one-hot encoded matrix in sparse representation (just the integer index of the 1 is stored) and a normal F32 matrix a.

For example the matrix

\[ \left( \begin{array}{ccc} 0 & 0 & 0 & 1 \\ 1 & 0 & 0 & 0 \\ 0 & 0 & 1 & 0 \end{array}\right) \]

in sparse representation is

\[ \left( \begin{array}{ccc} 3 \\ 0 \\ 2 \end{array}\right) \]

The result is then calculated from the one-hot encoded target matrix:

\[ result = - \sum_i target_{one-hot,i} \cdot \log(predicted_i) \]

Example:

uint16_t p_shape[2] = {2, 3};
float p_data[2*3] = {0.2f, 0.1f, 0.7f,
0.9f, 0.1f, 0.0f};
aitensor_t p = AITENSOR_2D_F32(p_shape, p_data);
uint16_t t_shape[2] = {2, 1};
uint8_t t_data[2*1] = {2,
0};
aitensor_t t = AITENSOR_2D_U8(t_shape, t_data);
float result;
void aimath_f32_default_categorical_crossentropy_sum_sparse8(const aitensor_t *predicted_data, const aitensor_t *target_data, void *result)
Calculates the categorical Cross-Entropy between the F32 predicted data and the U8 target data in s...
Parameters
*predicted_dataF32 matrix with the predicted or calculated values (2D tensor of shape [N x M])
*target_dataU8 matrix with the target data / true values / labels (2D tensor of shape [N x 1] with true class indices)
*resultResulting F32 matrix (2D tensor of shape [N x M])

◆ aimath_f32_default_copy_tensor()

void aimath_f32_default_copy_tensor ( const aitensor_t from,
aitensor_t to 
)

Performs an element wise copy of F32 tensors.

\[ to \leftarrow from \]

Dimension and shape of from and to tensors have to be the same.

Example:

uint16_t from_shape[2] = {2, 3};
float from_data[2*3] = {1.0f, 2.0f, 3.0f,
4.0f, 5.0f, 6.0f};
aitensor_t from = AITENSOR_2D_F32(from_shape, from_data);
uint16_t to_shape[2] = {2, 3};
float to_data[2*3];
aitensor_t to = AITENSOR_2D_F32(to_shape, to_data);
void print_aitensor(const aitensor_t *tensor)
Printing a tensor to console.
void aimath_f32_default_copy_tensor(const aitensor_t *from, aitensor_t *to)
Performs an element wise copy of F32 tensors.
Parameters
*fromF32 tensor to copy from (N-D tensor)
*toF32 tensor to copy to (N-D tensor)

◆ aimath_f32_default_d_elu()

void aimath_f32_default_d_elu ( const aitensor_t x,
const void *  alpha,
aitensor_t result 
)

Calculates the exponential rectifier (ELU) derivative of each element in a F32 tensor.

\[ result_{i} = \begin{cases} \alpha \cdot e^{x_i} & \text{if } x_i < 0\\ 1 & \text{if } x_i \geq 0 \end{cases} \]

Example:

uint16_t x_shape[2] = {2, 3};
float x_data[2*3] = { 1.0f, -2.0f, 3.0f,
-4.0f, 5.0f, -6.0f};
aitensor_t x = AITENSOR_2D_F32(x_shape, x_data);
float alpha = 1.0f;
uint16_t result_shape[2] = {2, 3};
float result_data[2*3];
aitensor_t result = AITENSOR_2D_F32(result_shape, result_data);
aimath_f32_default_d_elu(&x, &alpha, &result);
print_aitensor(&result);
void aimath_f32_default_d_elu(const aitensor_t *x, const void *alpha, aitensor_t *result)
Calculates the exponential rectifier (ELU) derivative of each element in a F32 tensor.
Parameters
*xF32 tensor to calculate the ELU derivative from (N-D tensor)
*alphaScalar \( \alpha \) (type aiscalar_f32_t / float)
*resultResulting F32 tensor (N-D tensor)

◆ aimath_f32_default_d_leaky_relu()

void aimath_f32_default_d_leaky_relu ( const aitensor_t x,
const void *  alpha,
aitensor_t result 
)

Calculates the leaky rectifier (leaky ReLU) derivative of each element in a F32 tensor.

\[ result_{i} = \begin{cases} \alpha & \text{if } x_i < 0\\ 1 & \text{if } x_i \geq 0 \end{cases} \]

Example:

uint16_t x_shape[2] = {2, 3};
float x_data[2*3] = { 1.0f, -2.0f, 3.0f,
-4.0f, 5.0f, -6.0f};
aitensor_t x = AITENSOR_2D_F32(x_shape, x_data);
float alpha = 0.01f;
uint16_t result_shape[2] = {2, 3};
float result_data[2*3];
aitensor_t result = AITENSOR_2D_F32(result_shape, result_data);
aimath_f32_default_d_leaky_relu(&x, &alpha, &result);
print_aitensor(&result);
void aimath_f32_default_d_leaky_relu(const aitensor_t *x, const void *alpha, aitensor_t *result)
Calculates the leaky rectifier (leaky ReLU) derivative of each element in a F32 tensor.
Parameters
*xF32 tensor to calculate the leaky ReLU derivative from (N-D tensor)
*alphaScalar \( \alpha \) (type aiscalar_f32_t / float) for the leakage
*resultResulting F32 tensor (N-D tensor)

◆ aimath_f32_default_d_relu()

void aimath_f32_default_d_relu ( const aitensor_t x,
aitensor_t result 
)

Calculates the rectifier (ReLU) derivative of each element in a F32 tensor.

\[ result_{ij} = \begin{cases} 0 & \text{if } x_i < 0\\ 1 & \text{if } x_i \geq 0 \end{cases} \]

Example:

uint16_t x_shape[2] = {2, 3};
float x_data[2*3] = { 1.0f, -2.0f, 3.0f,
-4.0f, 5.0f, -6.0f};
aitensor_t x = AITENSOR_2D_F32(x_shape, x_data);
uint16_t result_shape[2] = {2, 3};
float result_data[2*3];
aitensor_t result = AITENSOR_2D_F32(result_shape, result_data);
print_aitensor(&result);
void aimath_f32_default_d_relu(const aitensor_t *x, aitensor_t *result)
Calculates the rectifier (ReLU) derivative of each element in a F32 tensor.
Parameters
*xF32 tensor to calculate the ReLU derivative from (N-D tensor)
*resultResulting F32 tensor (N-D tensor)

◆ aimath_f32_default_d_sigmoid()

void aimath_f32_default_d_sigmoid ( const aitensor_t sigmoid_x,
aitensor_t result 
)

Calculates the derivative sigmoid of each element in a F32 tensor.

\[ result_{i} = \sigma'(x_{i}) = \sigma(x_{i}) \cdot (1 - \sigma(x_{i})) \]

Example:

uint16_t x_shape[2] = {2, 3};
float x_data[2*3] = { 1.0f, -2.0f, 3.0f,
-4.0f, 5.0f, -6.0f};
aitensor_t x = AITENSOR_2D_F32(x_shape, x_data);
uint16_t result_shape[2] = {2, 3};
float result_data[2*3];
aitensor_t result = AITENSOR_2D_F32(result_shape, result_data);
aimath_f32_default_d_sigmoid(&result, &result);
print_aitensor(&result);
void aimath_f32_default_d_sigmoid(const aitensor_t *sigmoid_x, aitensor_t *result)
Calculates the derivative sigmoid of each element in a F32 tensor.
void aimath_f32_default_sigmoid(const aitensor_t *x, aitensor_t *result)
Calculates the sigmoid of each element in a F32 tensor.
Parameters
*sigmoid_xF32 tensor with the sigmoid values \( \sigma(x_{i}) \) (N-D tensor)
*resultResulting F32 tensor (N-D tensor)

◆ aimath_f32_default_d_softsign()

void aimath_f32_default_d_softsign ( const aitensor_t x,
aitensor_t result 
)

Calculates the softsign derivative of each element in a F32 tensor.

\[ result_{i} = \frac {x_i} {(1 + |x_i|)^2} \]

Example:

uint16_t x_shape[2] = {2, 3};
float x_data[2*3] = { 1.0f, -2.0f, 3.0f,
-4.0f, 5.0f, -6.0f};
aitensor_t x = AITENSOR_2D_F32(x_shape, x_data);
uint16_t result_shape[2] = {2, 3};
float result_data[2*3];
aitensor_t result = AITENSOR_2D_F32(result_shape, result_data);
print_aitensor(&result);
void aimath_f32_default_d_softsign(const aitensor_t *x, aitensor_t *result)
Calculates the softsign derivative of each element in a F32 tensor.
Parameters
*xF32 tensor to calculate the softsign derivative from (N-D tensor)
*resultResulting F32 tensor (N-D tensor)

◆ aimath_f32_default_d_tanh()

void aimath_f32_default_d_tanh ( const aitensor_t tanh_x,
aitensor_t result 
)

Calculates the tanh derivative of each element in a F32 tensor.

\[ result_{i} = tanh'(x_{i}) = 1 - tanh(x_{i})^2 \]

Example:

uint16_t x_shape[2] = {2, 3};
float x_data[2*3] = { 1.0f, -2.0f, 3.0f,
-4.0f, 5.0f, -6.0f};
aitensor_t x = AITENSOR_2D_F32(x_shape, x_data);
uint16_t result_shape[2] = {2, 3};
float result_data[2*3];
aitensor_t result = AITENSOR_2D_F32(result_shape, result_data);
aimath_f32_default_d_tanh(&result, &result);
print_aitensor(&result);
void aimath_f32_default_d_tanh(const aitensor_t *tanh_x, aitensor_t *result)
Calculates the tanh derivative of each element in a F32 tensor.
void aimath_f32_default_tanh(const aitensor_t *x, aitensor_t *result)
Calculates the tanh of each element in a F32 tensor.
Parameters
*tanh_xF32 tensor with the tanh values \( \tanh(x_{i}) \) (N-D tensor)
*resultResulting F32 tensor (N-D tensor)

◆ aimath_f32_default_divide()

void aimath_f32_default_divide ( const aitensor_t a,
const aitensor_t b,
aitensor_t result 
)

Performs an element wise division of F32 tensors a and b (Hadamard division)

\[ result = a \oslash b \]

Example:

uint16_t a_shape[2] = {2, 3};
float a_data[2*3] = {1.0f, 2.0f, 3.0f,
4.0f, 5.0f, 6.0f};
aitensor_t a = AITENSOR_2D_F32(a_shape, a_data);
uint16_t b_shape[2] = {2, 3};
float b_data[2*3] = {1.0f, 2.0f, 3.0f,
4.0f, 5.0f, 6.0f};
aitensor_t b = AITENSOR_2D_F32(b_shape, b_data);
uint16_t result_shape[2] = {2, 3};
float result_data[2*3];
aitensor_t result = AITENSOR_2D_F32(result_shape, result_data);
aimath_f32_default_divide(&a, &b, &result);
print_aitensor(&result);
void aimath_f32_default_divide(const aitensor_t *a, const aitensor_t *b, aitensor_t *result)
Performs an element wise division of F32 tensors a and b (Hadamard division)
Parameters
*aF32 tensor a (N-D tensor)
*bF32 tensor b (N-D tensor)
*resultResulting F32 tensor of the element wise division (N-D tensor)

◆ aimath_f32_default_elu()

void aimath_f32_default_elu ( const aitensor_t x,
const void *  alpha,
aitensor_t result 
)

Calculates the exponential rectifier (ELU) value of each element in a F32 tensor.

\[ result_{i} = \begin{cases} \alpha \cdot (e^{x_i} - 1) & \text{if } x_i < 0 \\ x_i & \text{if } x_i \geq 0 \end{cases} \]

Example:

uint16_t x_shape[2] = {2, 3};
float x_data[2*3] = { 1.0f, -2.0f, 3.0f,
-4.0f, 5.0f, -6.0f};
aitensor_t x = AITENSOR_2D_F32(x_shape, x_data);
float alpha = 1.0f;
uint16_t result_shape[2] = {2, 3};
float result_data[2*3];
aitensor_t result = AITENSOR_2D_F32(result_shape, result_data);
aimath_f32_default_elu(&x, &alpha, &result);
print_aitensor(&result);
void aimath_f32_default_elu(const aitensor_t *x, const void *alpha, aitensor_t *result)
Calculates the exponential rectifier (ELU) value of each element in a F32 tensor.
Parameters
*xF32 tensor to calculate the ELU from (N-D tensor)
*alphaScalar \( \alpha \) (type aiscalar_f32_t / float)
*resultResulting F32 tensor (N-D tensor)

◆ aimath_f32_default_expf_fast()

float aimath_f32_default_expf_fast ( const float  x)

Fast approximation of the exponential function.

See also
http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.9.4508&rep=rep1&type=pdf
Parameters
xInput of the exponential function

◆ aimath_f32_default_exponential_moving_average()

void aimath_f32_default_exponential_moving_average ( const aitensor_t new_data,
const void *  momentum,
aitensor_t average 
)

Perform an exponential moving average.

Updates the moving average with a new data point:

\[ average \leftarrow momentum \cdot average + (1 - momentum) \cdot newdata \]

Parameters
new_dataInput tensor (N-D) with the new data point.
momentumaiscalar_t (float value) which controls the momentum of the average (range [0, 1]).
averageThe average tensor (N-D) that is modified (input and output value),

◆ aimath_f32_default_init_glorot_uniform()

void aimath_f32_default_init_glorot_uniform ( aitensor_t tensor)

Fills a F32 tensor with random numbers uniformly within given range, according to Glorot et al.

Same functionality as aimath_f32_default_init_glorot_uniform_cdim() with cin_axis = 0 and cout_axis = 1 (channels last dataformat).

\[ fan_{avg} = \frac{fan_{in} + fan_{out}}{2} \]

\[ r = \sqrt{\frac{3}{fan_{avg}}} \]

\[ tensor_i \in \mathcal{U(-r, r)} \]

Example:

uint16_t tensor_shape[2] = {2, 3};
float tensor_data[2*3];
aitensor_t tensor = AITENSOR_2D_F32(tensor_shape, tensor_data);
print_aitensor(&tensor);
void aimath_f32_default_init_glorot_uniform(aitensor_t *tensor)
Fills a F32 tensor with random numbers uniformly within given range, according to Glorot et al.
See also
Glorot et al., 2010 ( http://jmlr.org/proceedings/papers/v9/glorot10a/glorot10a.pdf )
Parameters
*tensorF32 tensor to initialize with random numbers (N-D tensor)

◆ aimath_f32_default_init_glorot_uniform_cdim()

void aimath_f32_default_init_glorot_uniform_cdim ( aitensor_t tensor,
int8_t  cin_axis,
int8_t  cout_axis 
)

Fills a F32 tensor with random numbers uniformly within given range, according to Glorot et al.

\[ fan_{avg} = \frac{fan_{in} + fan_{out}}{2} \]

\[ r = \sqrt{\frac{3}{fan_{avg}}} \]

\[ tensor_i \in \mathcal{U(-r, r)} \]

Example:

uint16_t tensor_shape[2] = {2, 3};
float tensor_data[2*3];
aitensor_t tensor = AITENSOR_2D_F32(tensor_shape, tensor_data);
print_aitensor(&tensor);
void aimath_f32_default_init_glorot_uniform_cdim(aitensor_t *tensor, int8_t cin_axis, int8_t cout_axis)
Fills a F32 tensor with random numbers uniformly within given range, according to Glorot et al.
See also
Glorot et al., 2010 ( http://jmlr.org/proceedings/papers/v9/glorot10a/glorot10a.pdf )
Parameters
*tensorF32 tensor to initialize with random numbers (N-D tensor)
cin_axisAxis of the input channels (negative number means indexing from the end)
cout_axisAxis of the output channels (negative number means indexing from the end)

◆ aimath_f32_default_init_he_uniform()

void aimath_f32_default_init_he_uniform ( aitensor_t tensor)

Fills a F32 tensor with uniformly drawn random numbers within given range, according to He et al.

Same functionality as aimath_f32_default_init_he_uniform_cdim() with cout_axis = 1 (channels last dataformat).

\[ fan_{avg} = \frac{fan_{in}}{2} \]

\[ r = \sqrt{\frac{3}{fan_{avg}}} \]

\[ tensor_i \in \mathcal{U(-r, r)} \]

Example:

uint16_t tensor_shape[2] = {2, 3};
float tensor_data[2*3];
aitensor_t tensor = AITENSOR_2D_F32(tensor_shape, tensor_data);
print_aitensor(&tensor);
void aimath_f32_default_init_he_uniform(aitensor_t *tensor)
Fills a F32 tensor with uniformly drawn random numbers within given range, according to He et al.
See also
He et al., 2015 ( https://www.cv-foundation.org/openaccess/content_iccv_2015/html/He_Delving_Deep_into_ICCV_2015_paper.html )
Parameters
*tensorF32 tensor to initialize with random numbers (N-D tensor)

◆ aimath_f32_default_init_he_uniform_cdim()

void aimath_f32_default_init_he_uniform_cdim ( aitensor_t tensor,
int8_t  cout_axis 
)

Fills a F32 tensor with uniformly drawn random numbers within given range, according to He et al.

\[ fan_{avg} = \frac{fan_{in}}{2} \]

\[ r = \sqrt{\frac{3}{fan_{avg}}} \]

\[ tensor_i \in \mathcal{U(-r, r)} \]

Example:

uint16_t tensor_shape[2] = {2, 3};
float tensor_data[2*3];
aitensor_t tensor = AITENSOR_2D_F32(tensor_shape, tensor_data);
print_aitensor(&tensor);
void aimath_f32_default_init_he_uniform_cdim(aitensor_t *tensor, int8_t cout_axis)
Fills a F32 tensor with uniformly drawn random numbers within given range, according to He et al.
See also
He et al., 2015 ( https://www.cv-foundation.org/openaccess/content_iccv_2015/html/He_Delving_Deep_into_ICCV_2015_paper.html )
Parameters
*tensorF32 tensor to initialize with random numbers (N-D tensor)
cout_axisAxis of the output channels (negative number means indexing from the end)

◆ aimath_f32_default_init_ones()

void aimath_f32_default_init_ones ( aitensor_t tensor)

Fills a F32 tensor with ones.

\[ tensor_{i} = 1 \]

Example:

uint16_t tensor_shape[2] = {2, 3};
float tensor_data[2*3];
aitensor_t tensor = AITENSOR_2D_F32(tensor_shape, tensor_data);
print_aitensor(&tensor);
void aimath_f32_default_init_ones(aitensor_t *tensor)
Fills a F32 tensor with ones.
Parameters
*tensorF32 tensor to set to zero (N-D tensor)

◆ aimath_f32_default_init_zeros()

void aimath_f32_default_init_zeros ( aitensor_t tensor)

Fills a F32 tensor with zeros.

\[ tensor_{i} = 0 \]

Example:

uint16_t tensor_shape[2] = {2, 3};
float tensor_data[2*3];
aitensor_t tensor = AITENSOR_2D_F32(tensor_shape, tensor_data);
print_aitensor(&tensor);
void aimath_f32_default_init_zeros(aitensor_t *tensor)
Fills a F32 tensor with zeros.

In the F32 implementation of this function, there is no difference between aimath_f32_default_zero_tensor() and aimath_f32_default_init_zeros().

Parameters
*tensorF32 tensor to set to zero (N-D tensor)

◆ aimath_f32_default_leaky_relu()

void aimath_f32_default_leaky_relu ( const aitensor_t x,
const void *  alpha,
aitensor_t result 
)

Calculates the leaky rectifier (leaky ReLU) value of each element in a F32 tensor.

\[ result_{i} = \begin{cases} \alpha \cdot x_i & \text{if } x_i < 0 \\ x_i & \text{if } x_i \geq 0 \end{cases} \]

Example:

uint16_t x_shape[2] = {2, 3};
float x_data[2*3] = { 1.0f, -2.0f, 3.0f,
-4.0f, 5.0f, -6.0f};
aitensor_t x = AITENSOR_2D_F32(x_shape, x_data);
float alpha = 0.01f;
uint16_t result_shape[2] = {2, 3};
float result_data[2*3];
aitensor_t result = AITENSOR_2D_F32(result_shape, result_data);
aimath_f32_default_leaky_relu(&x, &alpha, &result);
print_aitensor(&result);
void aimath_f32_default_leaky_relu(const aitensor_t *x, const void *alpha, aitensor_t *result)
Calculates the leaky rectifier (leaky ReLU) value of each element in a F32 tensor.
Parameters
*xF32 tensor to calculate the leaky ReLU from (N-D tensor)
*alphaScalar \( \alpha \) (type aiscalar_f32_t / float) for the leakage
*resultResulting F32 tensor (N-D tensor)

◆ aimath_f32_default_linear()

void aimath_f32_default_linear ( const aitensor_t a,
const aitensor_t b,
const aitensor_t c,
aitensor_t result 
)

Performs a matrix multiplication of F32 matrices a and b and adds a vector c to each row.

The addition of the horizontal vector c is performed via broadcast, i.e. element wise in each column Mathematically this broadcast is equal to multiplying c with an vertical vector (with the same number of elements as c) and adding the result to \( a \cdot b \).

\[ result = a \cdot b + \left( \begin{array}{c} 1 \\ 1 \\ \vdots \\ 1 \\ \end{array}\right) \cdot c \]

Example:

\[ a = \left( \begin{array}{rrr} 1 & 2 & 3 \\ 4 & 5 & 6 \\ 7 & 8 & 9 \end{array}\right) \]

\[ b = \left( \begin{array}{rr} 1 & 0 \\ 0 & 1 \\ 0 & 0 \end{array}\right) \]

\[ c = \left( \begin{array}{rr} 2 & 5 \end{array}\right) \]

\[ result = a \cdot b + \left( \begin{array}{r} 1 \\ 1 \\ 1 \\ \end{array}\right) \cdot c \]

\[ = \left( \begin{array}{rr} 1 & 2 \\ 4 & 5 \\ 7 & 8 \end{array}\right) + \left( \begin{array}{rr} 2 & 5 \\ 2 & 5 \\ 2 & 5 \end{array}\right) \]

\[ = \left( \begin{array}{rr} 3 & 7 \\ 6 & 10 \\ 9 & 13 \end{array}\right) \]

Example:

uint16_t a_shape[2] = {3, 3};
float a_data[3*3] = {1.0f, 2.0f, 3.0f,
4.0f, 5.0f, 6.0f,
7.0f, 8.0f, 9.0f};
aitensor_t a = AITENSOR_2D_F32(a_shape, a_data);
uint16_t b_shape[2] = {3, 2};
float b_data[3*2] = {1.0f, 0.0f,
0.0f, 1.0f,
0.0f, 0.0f};
aitensor_t b = AITENSOR_2D_F32(b_shape, b_data);
uint16_t c_shape[2] = {1, 2};
float c_data[1*2] = {2.0f, 5.0f};
aitensor_t c = AITENSOR_2D_F32(c_shape, c_data);
uint16_t result_shape[2] = {3, 2};
float result_data[3*2];
aitensor_t result = AITENSOR_2D_F32(result_shape, result_data);
aimath_f32_default_linear(&a, &b, &c, &result);
print_aitensor(&result);
void aimath_f32_default_linear(const aitensor_t *a, const aitensor_t *b, const aitensor_t *c, aitensor_t *result)
Performs a matrix multiplication of F32 matrices a and b and adds a vector c to each row.
Parameters
*aF32 matrix a (2D tensor of shape [N x K])
*bF32 matrix b (2D tensor of shape [K x M])
*cF32 vector c (2D tensor of shape [1 x M] or 1D tensor of shape [M])
*resultResulting F32 matrix (2D tensor of shape [N x M])

◆ aimath_f32_default_linear_at()

void aimath_f32_default_linear_at ( const aitensor_t a,
const aitensor_t b,
const aitensor_t c,
aitensor_t result 
)

Performs a matrix multiplication of F32 matrices a (transposed) and b and adds a vector c to each row.

Same operation as aimath_f32_default_linear() but with a transposed a matrix.

The addition of the horizontal vector c is performed via broadcast, i.e. element wise in each column Mathematically this broadcast is equal to multiplying c with an vertical vector (with the same number of elements as c) and adding the result to \( a^T \cdot b \).

\[ result = a \cdot b^T + \left( \begin{array}{c} 1 \\ 1 \\ \vdots \\ 1 \\ \end{array}\right) \cdot c \]

Example:

uint16_t a_shape[2] = {3, 3};
float a_data[3*3] = {1.0f, 2.0f, 3.0f,
4.0f, 5.0f, 6.0f,
7.0f, 8.0f, 9.0f};
aitensor_t a = AITENSOR_2D_F32(a_shape, a_data);
uint16_t b_shape[2] = {3, 2};
float b_data[3*2] = {1.0f, 0.0f,
0.0f, 1.0f,
0.0f, 0.0f};
aitensor_t b = AITENSOR_2D_F32(b_shape, b_data);
uint16_t c_shape[2] = {1, 2};
float c_data[1*2] = {2.0f, 5.0f};
aitensor_t c = AITENSOR_2D_F32(c_shape, c_data);
uint16_t result_shape[2] = {3, 2};
float result_data[3*2];
aitensor_t result = AITENSOR_2D_F32(result_shape, result_data);
aimath_f32_default_linear_at(&a, &b, &c, &result);
print_aitensor(&result);
void aimath_f32_default_linear_at(const aitensor_t *a, const aitensor_t *b, const aitensor_t *c, aitensor_t *result)
Performs a matrix multiplication of F32 matrices a (transposed) and b and adds a vector c to each ro...
Parameters
*aF32 matrix a (2D tensor of shape [K x N])
*bF32 matrix b (2D tensor of shape [K x M])
*cF32 vector c (2D tensor of shape [1 x M] or 1D tensor of shape [M])
*resultResulting F32 matrix (2D tensor of shape [N x M])

◆ aimath_f32_default_linear_atrt()

void aimath_f32_default_linear_atrt ( const aitensor_t a,
const aitensor_t b,
const aitensor_t c,
aitensor_t result 
)

Performs a matrix multiplication with transposed result of F32 matrices a (transposed) and b and adds a vector c to each row.

Same operation as aimath_f32_default_linear() but with a transposed a matrix and transposed result.

The addition of the horizontal vector c is performed via broadcast, i.e. element wise in each column Mathematically this broadcast is equal to multiplying c with an vertical vector (with the same number of elements as c) and adding the result to \( a^T \cdot b \).

\[ result = \left( a \cdot b^T + \left( \begin{array}{c} 1 \\ 1 \\ \vdots \\ 1 \\ \end{array}\right) \cdot c \right)^T \]

Example:

uint16_t a_shape[2] = {3, 3};
float a_data[3*3] = {1.0f, 2.0f, 3.0f,
4.0f, 5.0f, 6.0f,
7.0f, 8.0f, 9.0f};
aitensor_t a = AITENSOR_2D_F32(a_shape, a_data);
uint16_t b_shape[2] = {3, 2};
float b_data[3*2] = {1.0f, 0.0f,
0.0f, 1.0f,
0.0f, 0.0f};
aitensor_t b = AITENSOR_2D_F32(b_shape, b_data);
uint16_t c_shape[2] = {1, 2};
float c_data[1*2] = {2.0f, 5.0f};
aitensor_t c = AITENSOR_2D_F32(c_shape, c_data);
uint16_t result_shape[2] = {2, 3};
float result_data[2*3];
aitensor_t result = AITENSOR_2D_F32(result_shape, result_data);
aimath_f32_default_linear_atrt(&a, &b, &c, &result);
print_aitensor(&result);
void aimath_f32_default_linear_atrt(const aitensor_t *a, const aitensor_t *b, const aitensor_t *c, aitensor_t *result)
Performs a matrix multiplication with transposed result of F32 matrices a (transposed) and b and add...
Parameters
*aF32 matrix a (2D tensor of shape [K x N])
*bF32 matrix b (2D tensor of shape [K x M])
*cF32 vector c (2D tensor of shape [1 x M] or 1D tensor of shape [M])
*resultResulting F32 matrix (2D tensor of shape [M x N])

◆ aimath_f32_default_linear_bt()

void aimath_f32_default_linear_bt ( const aitensor_t a,
const aitensor_t b,
const aitensor_t c,
aitensor_t result 
)

Performs a matrix multiplication of F32 matrices a and b (transposed) and adds a vector c to each row.

Same operation as aimath_f32_default_linear() but with a transposed b matrix.

The addition of the horizontal vector c is performed via broadcast, i.e. element wise in each column Mathematically this broadcast is equal to multiplying c with an vertical vector (with the same number of elements as c) and adding the result to \( a \cdot b^T \).

\[ result = a \cdot b^T + \left( \begin{array}{c} 1 \\ 1 \\ \vdots \\ 1 \\ \end{array}\right) \cdot c \]

Example:

uint16_t a_shape[2] = {3, 3};
float a_data[3*3] = {1.0f, 2.0f, 3.0f,
4.0f, 5.0f, 6.0f,
7.0f, 8.0f, 9.0f};
aitensor_t a = AITENSOR_2D_F32(a_shape, a_data);
uint16_t b_shape[2] = {2, 3};
float b_data[2*3] = {1.0f, 0.0f, 0.0f,
0.0f, 1.0f, 0.0f};
aitensor_t b = AITENSOR_2D_F32(b_shape, b_data);
uint16_t c_shape[2] = {1, 2};
float c_data[1*2] = {2.0f, 5.0f};
aitensor_t c = AITENSOR_2D_F32(c_shape, c_data);
uint16_t result_shape[2] = {3, 2};
float result_data[3*2];
aitensor_t result = AITENSOR_2D_F32(result_shape, result_data);
aimath_f32_default_linear_bt(&a, &b, &c, &result);
print_aitensor(&result);
void aimath_f32_default_linear_bt(const aitensor_t *a, const aitensor_t *b, const aitensor_t *c, aitensor_t *result)
Performs a matrix multiplication of F32 matrices a and b (transposed) and adds a vector c to each ro...
Parameters
*aF32 matrix a (2D tensor of shape [N x K])
*bF32 matrix b (2D tensor of shape [M x K])
*cF32 vector c (2D tensor of shape [1 x M] or 1D tensor of shape [M])
*resultResulting F32 matrix (2D tensor of shape [N x M])

◆ aimath_f32_default_mat_mul()

void aimath_f32_default_mat_mul ( const aitensor_t a,
const aitensor_t b,
aitensor_t result 
)

Performs a matrix multiplication of F32 matrices a and b.

\[ result = a \cdot b \]

Example:

uint16_t a_shape[2] = {2, 3};
float a_data[2*3] = {1.0f, 2.0f, 3.0f,
4.0f, 5.0f, 6.0f};
aitensor_t a = AITENSOR_2D_F32(a_shape, a_data);
uint16_t b_shape[2] = {3, 2};
float b_data[3*2] = {1.0f, 0.0f,
0.0f, 1.0f,
0.0f, 0.0f};
aitensor_t b = AITENSOR_2D_F32(b_shape, b_data);
uint16_t result_shape[2] = {2, 2};
float result_data[2*2];
aitensor_t result = AITENSOR_2D_F32(result_shape, result_data);
aimath_f32_default_mat_mul(&a, &b, &result);
print_aitensor(&result);
void aimath_f32_default_mat_mul(const aitensor_t *a, const aitensor_t *b, aitensor_t *result)
Performs a matrix multiplication of F32 matrices a and b.
Parameters
*aF32 matrix a (2D tensor of shape [N x K])
*bF32 matrix b (2D tensor of shape [K x M])
*resultResulting F32 matrix of the multiplication (2D tensor of shape [N x M])

◆ aimath_f32_default_mat_mul_at()

void aimath_f32_default_mat_mul_at ( const aitensor_t a,
const aitensor_t b,
aitensor_t result 
)

Performs a matrix multiplication of F32 matrices a (transposed) and b.

Same operation as aimath_f32_default_mat_mul() but with a transposed a matrix.

\[ result = a^T \cdot b \]

Example:

uint16_t a_shape[2] = {3, 2};
float a_data[3*2] = {1.0f, 2.0f,
4.0f, 5.0f,
7.0f, 8.0f,};
aitensor_t a = AITENSOR_2D_F32(a_shape, a_data);
uint16_t b_shape[2] = {3, 2};
float b_data[3*2] = {1.0f, 0.0f,
0.0f, 1.0f,
0.0f, 0.0f};
aitensor_t b = AITENSOR_2D_F32(b_shape, b_data);
uint16_t result_shape[2] = {2, 2};
float result_data[2*2];
aitensor_t result = AITENSOR_2D_F32(result_shape, result_data);
print_aitensor(&result);
void aimath_f32_default_mat_mul_at(const aitensor_t *a, const aitensor_t *b, aitensor_t *result)
Performs a matrix multiplication of F32 matrices a (transposed) and b.
Parameters
*aF32 matrix a (2D tensor of shape [K x N])
*bF32 matrix b (2D tensor of shape [K x M])
*resultResulting F32 matrix of the multiplication (2D tensor of shape [N x M])

◆ aimath_f32_default_mat_mul_atrt()

void aimath_f32_default_mat_mul_atrt ( const aitensor_t a,
const aitensor_t b,
aitensor_t result 
)

Performs a matrix multiplication with transposed result of F32 matrices a (transposed) and b.

Same operation as aimath_f32_default_mat_mul() but with a transposed a matrix.

\[ result = a^T \cdot b \]

Example:

uint16_t a_shape[2] = {3, 2};
float a_data[3*2] = {1.0f, 2.0f,
4.0f, 5.0f,
7.0f, 8.0f,};
aitensor_t a = AITENSOR_2D_F32(a_shape, a_data);
uint16_t b_shape[2] = {3, 1};
float b_data[3*2] = {1.0f,
0.0f,
0.0f};
aitensor_t b = AITENSOR_2D_F32(b_shape, b_data);
uint16_t result_shape[2] = {1, 2};
float result_data[1*2];
aitensor_t result = AITENSOR_2D_F32(result_shape, result_data);
print_aitensor(&result);
void aimath_f32_default_mat_mul_atrt(const aitensor_t *a, const aitensor_t *b, aitensor_t *result)
Performs a matrix multiplication with transposed result of F32 matrices a (transposed) and b.
Parameters
*aF32 matrix a (2D tensor of shape [K x N])
*bF32 matrix b (2D tensor of shape [K x M])
*resultResulting F32 matrix of the multiplication (2D tensor of shape [M x N])

◆ aimath_f32_default_mat_mul_bt()

void aimath_f32_default_mat_mul_bt ( const aitensor_t a,
const aitensor_t b,
aitensor_t result 
)

Performs a matrix multiplication of F32 matrices a and b (transposed)

Same operation as aimath_f32_default_mat_mul() but with a transposed b matrix.

\[ result = a \cdot b^T \]

Example:

uint16_t a_shape[2] = {2, 3};
float a_data[2*3] = {1.0f, 2.0f, 3.0f,
4.0f, 5.0f, 6.0f};
aitensor_t a = AITENSOR_2D_F32(a_shape, a_data);
uint16_t b_shape[2] = {2, 3};
float b_data[2*3] = {1.0f, 0.0f, 0.0f,
0.0f, 1.0f, 0.0f};
aitensor_t b = AITENSOR_2D_F32(b_shape, b_data);
uint16_t result_shape[2] = {2, 2};
float result_data[2*2];
aitensor_t result = AITENSOR_2D_F32(result_shape, result_data);
print_aitensor(&result);
void aimath_f32_default_mat_mul_bt(const aitensor_t *a, const aitensor_t *b, aitensor_t *result)
Performs a matrix multiplication of F32 matrices a and b (transposed)
Parameters
*aF32 matrix a (2D tensor of shape [N x K])
*bF32 matrix b (2D tensor of shape [M x K])
*resultResulting F32 matrix of the multiplication (2D tensor of shape [N x M])

◆ aimath_f32_default_max()

void aimath_f32_default_max ( const aitensor_t x,
void *  result 
)

Identifies the maximum value in a F32 tensor.

\[ result = max(x) \]

Example:

uint16_t x_shape[2] = {2, 3};
float x_data[2*3] = {0.0f, 1.0f, 2.0f,
3.0f, 4.0f, 5.0f};
aitensor_t x = AITENSOR_2D_F32(x_shape, x_data);
float result;
void aimath_f32_default_max(const aitensor_t *x, void *result)
Identifies the maximum value in a F32 tensor.
Parameters
*xF32 tensor x to get the maximum value of (N-D tensor)
*resultScalar result (type aiscalar_f32_t / float)

◆ aimath_f32_default_mean_channelwise()

void aimath_f32_default_mean_channelwise ( const aitensor_t x,
int8_t  channel_axis,
aitensor_t result 
)

Sums up all values of a channel of the F32 tensor x.

Calculates the sum of all elements of each channel c. The result tensor is 1D:

\[ result_c = \sum_i(x_{ci}) @f @param x F32 input tensor (N-D) @param channel_axis Index of the channel axis (negative values mean indexing from the end). @param result F32 result vector (1D) */ void aimath_f32_default_sum_channelwise(const aitensor_t *x, int8_t channel_axis, aitensor_t *result); /** @brief Calculate the channel-wise mean values of the \link aimath_f32.h F32 \endlink tensor x Calculates the empirical mean for each channel of the given axis:\n @f[ means_i = \frac{1}{m} \sum_{j=1}^{m} x_{i,j} \]

Parameters
xF32 input tensor (N-D)
channel_axisIndex of the channel axis (negative values mean indexing from the end)
resultF32 result vector (1D)

◆ aimath_f32_default_min()

void aimath_f32_default_min ( const aitensor_t x,
void *  result 
)

Identifies the minimum value in a F32 tensor.

\[ result = min(x) \]

Example:

uint16_t x_shape[2] = {2, 3};
float x_data[2*3] = {0.0f, 1.0f, 2.0f,
3.0f, 4.0f, 5.0f};
aitensor_t x = AITENSOR_2D_F32(x_shape, x_data);
float result;
void aimath_f32_default_min(const aitensor_t *x, void *result)
Identifies the minimum value in a F32 tensor.
Parameters
*xF32 tensor x to get the minimum value of (N-D tensor)
*resultScalar result (type aiscalar_f32_t / float)

◆ aimath_f32_default_mse_gradients_mean()

void aimath_f32_default_mse_gradients_mean ( const aitensor_t predicted,
const aitensor_t target,
aitensor_t result 
)

Calculates the gradients of the mean squared error between the F32 predicted and the target data using a mean reduction.

Parameters
*predicted_dataF32 matrix with the predicted or calculated values (2D tensor)
*target_dataF32 matrix with the target data / true values / labels (2D tensor, rows one-hot encoded)
*resultF32 tensor containing the gradients

◆ aimath_f32_default_mse_gradients_sum()

void aimath_f32_default_mse_gradients_sum ( const aitensor_t predicted,
const aitensor_t target,
aitensor_t result 
)

Calculates the gradients of the mean squared error between the F32 predicted and the target data using a sum reduction.

Parameters
*predicted_dataF32 matrix with the predicted or calculated values (2D tensor)
*target_dataF32 matrix with the target data / true values / labels (2D tensor, rows one-hot encoded)
*resultF32 tensor containing the gradients

◆ aimath_f32_default_mse_loss_mean()

void aimath_f32_default_mse_loss_mean ( const aitensor_t predicted,
const aitensor_t target,
void *  result 
)

Calculates the mean squared error between the F32 predicted and the target data using a mean reduction.

Parameters
*predicted_dataF32 matrix with the predicted or calculated values (2D tensor)
*target_dataF32 matrix with the target data / true values / labels (2D tensor, rows one-hot encoded)
*resultResulting loss (float)

◆ aimath_f32_default_mse_loss_sum()

void aimath_f32_default_mse_loss_sum ( const aitensor_t predicted,
const aitensor_t target,
void *  result 
)

Calculates the mean squared error between the F32 predicted and the target data using a sum reduction.

Parameters
*predicted_dataF32 matrix with the predicted or calculated values (2D tensor)
*target_dataF32 matrix with the target data / true values / labels (2D tensor, rows one-hot encoded)
*resultResulting loss (float)

◆ aimath_f32_default_multiply()

void aimath_f32_default_multiply ( const aitensor_t a,
const aitensor_t b,
aitensor_t result 
)

Performs an element wise multiplication of F32 tensors a and b (Hadamard product)

\[ result = a \circ b \]

Example:

uint16_t a_shape[2] = {2, 3};
float a_data[2*3] = {1.0f, 2.0f, 3.0f,
4.0f, 5.0f, 6.0f};
aitensor_t a = AITENSOR_2D_F32(a_shape, a_data);
uint16_t b_shape[2] = {2, 3};
float b_data[2*3] = {1.0f, 2.0f, 3.0f,
4.0f, 5.0f, 6.0f};
aitensor_t b = AITENSOR_2D_F32(b_shape, b_data);
uint16_t result_shape[2] = {2, 3};
float result_data[2*3];
aitensor_t result = AITENSOR_2D_F32(result_shape, result_data);
aimath_f32_default_multiply(&a, &b, &result);
print_aitensor(&result);
void aimath_f32_default_multiply(const aitensor_t *a, const aitensor_t *b, aitensor_t *result)
Performs an element wise multiplication of F32 tensors a and b (Hadamard product)
Parameters
*aF32 tensor a (N-D tensor)
*bF32 tensor b (N-D tensor)
*resultResulting F32 tensor of the element wise multiplication (N-D tensor)

◆ aimath_f32_default_norm_squared()

void aimath_f32_default_norm_squared ( const aitensor_t x,
void *  result 
)

Calculates the squared sum of all elements in a F32 tensor.

\[ result = \sum_i x_{i}^2 \]

Example:

uint16_t x_shape[2] = {2, 3};
float x_data[2*3] = {0.0f, 1.0f, 2.0f,
3.0f, 4.0f, 5.0f};
aitensor_t x = AITENSOR_2D_F32(x_shape, x_data);
float result;
void aimath_f32_default_norm_squared(const aitensor_t *x, void *result)
Calculates the squared sum of all elements in a F32 tensor.
Parameters
*xF32 tensor x (N-D tensor)
*resultScalar result (type aiscalar_f32_t / float)

◆ aimath_f32_default_relu()

void aimath_f32_default_relu ( const aitensor_t x,
aitensor_t result 
)

Calculates the rectifier (ReLU) value of each element in a F32 tensor.

\[ result_{i} = max(0, x_{i}) \]

Example:

uint16_t x_shape[2] = {2, 3};
float x_data[2*3] = { 1.0f, -2.0f, 3.0f,
-4.0f, 5.0f, -6.0f};
aitensor_t x = AITENSOR_2D_F32(x_shape, x_data);
uint16_t result_shape[2] = {2, 3};
float result_data[2*3];
aitensor_t result = AITENSOR_2D_F32(result_shape, result_data);
print_aitensor(&result);
void aimath_f32_default_relu(const aitensor_t *x, aitensor_t *result)
Calculates the rectifier (ReLU) value of each element in a F32 tensor.
Parameters
*xF32 tensor to calculate the ReLU from (N-D tensor)
*resultResulting F32 tensor (N-D tensor)

◆ aimath_f32_default_scalar_add()

void aimath_f32_default_scalar_add ( const void *  scalar,
const aitensor_t a,
aitensor_t result 
)

Performs an element wise addition of a scalar to a F32 tensor.

\[ result = a + \left( \begin{array}{ccc} 1 & \ldots & 1 \\ \vdots & \ddots & \vdots \\ 1 & \ldots & 1 \end{array}\right) \cdot scalar \]

Example:

uint16_t a_shape[2] = {2, 3};
float a_data[2*3] = {0.0f, 1.0f, 2.0f,
3.0f, 4.0f, 5.0f};
aitensor_t a = AITENSOR_2D_F32(a_shape, a_data);
float scalar = 0.1f;
uint16_t result_shape[2] = {2, 3};
float result_data[2*3];
aitensor_t result = AITENSOR_2D_F32(result_shape, result_data);
aimath_f32_default_scalar_add(&scalar, &a, &result);
print_aitensor(&result);
void aimath_f32_default_scalar_add(const void *scalar, const aitensor_t *a, aitensor_t *result)
Performs an element wise addition of a scalar to a F32 tensor.
Parameters
*scalarScalar (type aiscalar_f32_t / float)
*aF32 tensor a (N-D tensor)
*resultResulting F32 tensor of the element wise scalar addition (N-D tensor)

◆ aimath_f32_default_scalar_mul()

void aimath_f32_default_scalar_mul ( const void *  scalar,
const aitensor_t a,
aitensor_t result 
)

Performs a scalar multiplication (scaling) of F32 tensor a and a scalar.

\[ result = scalar \cdot a \]

Example:

uint16_t a_shape[2] = {2, 3};
float a_data[2*3] = {0.0f, 1.0f, 2.0f,
3.0f, 4.0f, 5.0f};
aitensor_t a = AITENSOR_2D_F32(a_shape, a_data);
float scalar = 0.1f;
uint16_t result_shape[2] = {2, 3};
float result_data[2*3];
aitensor_t result = AITENSOR_2D_F32(result_shape, result_data);
aimath_f32_default_scalar_mul(&scalar, &a, &result);
print_aitensor(&result);
void aimath_f32_default_scalar_mul(const void *scalar, const aitensor_t *a, aitensor_t *result)
Performs a scalar multiplication (scaling) of F32 tensor a and a scalar.
Parameters
*scalarScalar (type aiscalar_f32_t / float)
*aF32 tensor a (N-D tensor)
*resultResulting F32 tensor of the scalar multiplication (N-D tensor)

◆ aimath_f32_default_scale_by_batch_size()

void aimath_f32_default_scale_by_batch_size ( const aitensor_t a,
aitensor_t result 
)

Scales a F32 tensor by batch size (size of first dimension)

Parameters
*aF32 tensor that is going to be scaled by its batch size
*resultScaled F32 tensor

◆ aimath_f32_default_sigmoid()

void aimath_f32_default_sigmoid ( const aitensor_t x,
aitensor_t result 
)

Calculates the sigmoid of each element in a F32 tensor.

\[ result_{i} = \sigma(x_{i}) = \frac{1}{1 + e^{-x_{i}}} \]

Example:

uint16_t x_shape[2] = {2, 3};
float x_data[2*3] = { 1.0f, -2.0f, 3.0f,
-4.0f, 5.0f, -6.0f};
aitensor_t x = AITENSOR_2D_F32(x_shape, x_data);
uint16_t result_shape[2] = {2, 3};
float result_data[2*3];
aitensor_t result = AITENSOR_2D_F32(result_shape, result_data);
print_aitensor(&result);
Parameters
*xF32 tensor to calculate the sigmoid from (N-D tensor)
*resultResulting F32 tensor (N-D tensor)

◆ aimath_f32_default_softmax()

void aimath_f32_default_softmax ( const aitensor_t x,
aitensor_t result 
)

Calculates the softmax value of each row of a F32 matrix.

\[ result_{i} = \frac{e^{x_i}}{\sum_{j=1}^{K} e^{x_j}} \]

Example:

uint16_t x_shape[2] = {2, 3};
float x_data[2*3] = { 1.0f, -2.0f, 3.0f,
-4.0f, 5.0f, -6.0f};
aitensor_t x = AITENSOR_2D_F32(x_shape, x_data);
uint16_t result_shape[2] = {2, 3};
float result_data[2*3];
aitensor_t result = AITENSOR_2D_F32(result_shape, result_data);
print_aitensor(&result);
void aimath_f32_default_softmax(const aitensor_t *x, aitensor_t *result)
Calculates the softmax value of each row of a F32 matrix.
Parameters
*xF32 matrix to calculate the softmax from (2D tensor)
*resultResulting F32 matrix (2D tensor)

◆ aimath_f32_default_softsign()

void aimath_f32_default_softsign ( const aitensor_t x,
aitensor_t result 
)

Calculates the softsign value of each element in a F32 tensor.

\[ result_{i} = \frac {x_i} {1 + |x_i|} \]

Example:

uint16_t x_shape[2] = {2, 3};
float x_data[2*3] = { 1.0f, -2.0f, 3.0f,
-4.0f, 5.0f, -6.0f};
aitensor_t x = AITENSOR_2D_F32(x_shape, x_data);
uint16_t result_shape[2] = {2, 3};
float result_data[2*3];
aitensor_t result = AITENSOR_2D_F32(result_shape, result_data);
print_aitensor(&result);
void aimath_f32_default_softsign(const aitensor_t *x, aitensor_t *result)
Calculates the softsign value of each element in a F32 tensor.
Parameters
*xF32 tensor to calculate the softsign from (N-D tensor)
*resultResulting F32 tensor (N-D tensor)

◆ aimath_f32_default_sqrt()

void aimath_f32_default_sqrt ( const aitensor_t x,
aitensor_t result 
)

Calculates the element wise square root of a F32 tensor.

\[ result_{i} = \sqrt{x_{i}} \]

Example:

uint16_t x_shape[2] = {2, 3};
float x_data[2*3] = {1.0f, 2.0f, 3.0f,
4.0f, 5.0f, 6.0f};
aitensor_t x = AITENSOR_2D_F32(x_shape, x_data);
uint16_t result_shape[2] = {2, 3};
float result_data[2*3];
aitensor_t result = AITENSOR_2D_F32(result_shape, result_data);
print_aitensor(&result);
void aimath_f32_default_sqrt(const aitensor_t *x, aitensor_t *result)
Calculates the element wise square root of a F32 tensor.
Parameters
*xF32 tensor to calculate the square root from (N-D tensor)
*resultResulting F32 tensor (N-D tensor)

◆ aimath_f32_default_sum()

void aimath_f32_default_sum ( const aitensor_t x,
void *  result 
)

Calculates the sum of all elements in a F32 tensor.

\[ result = \sum_i x_{i} \]

Example:

uint16_t x_shape[2] = {2, 3};
float x_data[2*3] = {0.0f, 1.0f, 2.0f,
3.0f, 4.0f, 5.0f};
aitensor_t x = AITENSOR_2D_F32(x_shape, x_data);
float result;
void aimath_f32_default_sum(const aitensor_t *x, void *result)
Calculates the sum of all elements in a F32 tensor.
Parameters
*xF32 tensor x (N-D tensor)
*resultScalar result (type aiscalar_f32_t / float)

◆ aimath_f32_default_tanh()

void aimath_f32_default_tanh ( const aitensor_t x,
aitensor_t result 
)

Calculates the tanh of each element in a F32 tensor.

\[ result_{i} = \tanh(x_{i}) = \frac{e^{x_i} - e^{-x_i}}{e^{x_i} + e^{-x_i}} \]

Example:

uint16_t x_shape[2] = {2, 3};
float x_data[2*3] = { 1.0f, -2.0f, 3.0f,
-4.0f, 5.0f, -6.0f};
aitensor_t x = AITENSOR_2D_F32(x_shape, x_data);
uint16_t result_shape[2] = {2, 3};
float result_data[2*3];
aitensor_t result = AITENSOR_2D_F32(result_shape, result_data);
print_aitensor(&result);
Parameters
*xF32 tensor to calculate the tanh from (N-D tensor)
*resultResulting F32 tensor (N-D tensor)

◆ aimath_f32_default_tensor_add()

void aimath_f32_default_tensor_add ( const aitensor_t a,
const aitensor_t b,
aitensor_t result 
)

Performs an element wise addition of F32 tensors a and b.

\[ result = a + b \]

Example:

uint16_t a_shape[2] = {2, 3};
float a_data[2*3] = {1.0f, 2.0f, 3.0f,
4.0f, 5.0f, 6.0f};
aitensor_t a = AITENSOR_2D_F32(a_shape, a_data);
uint16_t b_shape[2] = {2, 3};
float b_data[2*3] = {1.0f, 2.0f, 3.0f,
4.0f, 5.0f, 6.0f};
aitensor_t b = AITENSOR_2D_F32(b_shape, b_data);
uint16_t result_shape[2] = {2, 3};
float result_data[2*3];
aitensor_t result = AITENSOR_2D_F32(result_shape, result_data);
print_aitensor(&result);
void aimath_f32_default_tensor_add(const aitensor_t *a, const aitensor_t *b, aitensor_t *result)
Performs an element wise addition of F32 tensors a and b.
Parameters
*aF32 tensor a (N-D tensor)
*bF32 tensor b (N-D tensor)
*resultResulting F32 tensor of the element wise addition (N-D tensor)

◆ aimath_f32_default_tensor_init_uniform()

void aimath_f32_default_tensor_init_uniform ( aitensor_t tensor,
float  from,
float  to 
)

Fills a F32 tensor with random numbers created from a uniform distribution within given range.

\[ tensor_i \in \mathcal{U(from, to)} \]

Example:

uint16_t tensor_shape[2] = {2, 3};
float tensor_data[2*3];
aitensor_t tensor = AITENSOR_2D_F32(tensor_shape, tensor_data);
print_aitensor(&tensor);
void aimath_f32_default_tensor_init_uniform(aitensor_t *tensor, float from, float to)
Fills a F32 tensor with random numbers created from a uniform distribution within given range.
Parameters
*tensorF32 tensor to initialize with random numbers (N-D tensor)
fromMinimum value of the uniform distribution
toMaximum value of the uniform distribution

◆ aimath_f32_default_tensor_sub()

void aimath_f32_default_tensor_sub ( const aitensor_t a,
const aitensor_t b,
aitensor_t result 
)

Performs a element wise subtraction of F32 tensors a and b.

\[ result = a - b \]

Example:

uint16_t a_shape[2] = {2, 3};
float a_data[2*3] = {1.0f, 2.0f, 3.0f,
4.0f, 5.0f, 6.0f};
aitensor_t a = AITENSOR_2D_F32(a_shape, a_data);
uint16_t b_shape[2] = {2, 3};
float b_data[2*3] = {1.0f, 2.0f, 3.0f,
4.0f, 5.0f, 6.0f};
aitensor_t b = AITENSOR_2D_F32(b_shape, b_data);
uint16_t result_shape[2] = {2, 3};
float result_data[2*3];
aitensor_t result = AITENSOR_2D_F32(result_shape, result_data);
print_aitensor(&result);
void aimath_f32_default_tensor_sub(const aitensor_t *a, const aitensor_t *b, aitensor_t *result)
Performs a element wise subtraction of F32 tensors a and b.
Parameters
*aF32 tensor a (N-D tensor)
*bF32 tensor b (N-D tensor)
*resultResulting F32 tensor of the element wise subtraction (N-D tensor)

◆ aimath_f32_default_tensor_sub_sparse8()

void aimath_f32_default_tensor_sub_sparse8 ( const aitensor_t a,
const aitensor_t b,
aitensor_t result 
)

Performs a subtraction between a F32 matrix a and a U8 sparse matrix b.

This function can subtract a row wise one-hot encoded matrix in sparse representation (just the integer index of the 1 is stored) from a normal F32 matrix a.

For example the matrix

\[ \left( \begin{array}{ccc} 0 & 0 & 0 & 1 \\ 1 & 0 & 0 & 0 \\ 0 & 0 & 1 & 0 \end{array}\right) \]

in sparse representation is

\[ \left( \begin{array}{ccc} 3 \\ 0 \\ 2 \end{array}\right) \]

The result is then calculated as

\[ result_{ij} = \begin{cases} a_{ij} - 1 & \text{if } j = b_i\\ a_{ij} & \text{if } j \neq b_i \end{cases} \]

Example:

uint16_t a_shape[2] = {2, 3};
float a_data[2*3] = {0.2f, 0.1f, 0.7f,
0.9f, 0.1f, 0.0f};
aitensor_t a = AITENSOR_2D_F32(a_shape, a_data);
uint16_t b_shape[2] = {2, 1};
uint8_t b_data[2*1] = {2,
0};
aitensor_t b = AITENSOR_2D_U8(b_shape, b_data);
uint16_t result_shape[2] = {2, 3};
float result_data[2*3];
aitensor_t result = AITENSOR_2D_F32(result_shape, result_data);
print_aitensor(&result);
void aimath_f32_default_tensor_sub_sparse8(const aitensor_t *a, const aitensor_t *b, aitensor_t *result)
Performs a subtraction between a F32 matrix a and a U8 sparse matrix b.
Parameters
*aF32 matrix a (2D tensor of shape [N x M])
*bU8 sparse matrix b (2D tensor of shape [N x 1])
*resultResulting F32 tensor of the subtraction (2D tensor of shape [N x M])

◆ aimath_f32_default_transpose_matrix()

void aimath_f32_default_transpose_matrix ( aitensor_t x)

Transpose a F32 tensor.

\[ x \leftarrow x^T \]

Example:

uint16_t x_shape[2] = {2, 3};
float x_data[2*3] = { 2.0f, -4.0f, 6.0f,
-8.0f, 10.0f, -12.0f};
aitensor_t x = AITENSOR_2D_F32(x_shape, x_data);
void aimath_f32_default_transpose_matrix(aitensor_t *x)
Transpose a F32 tensor.
Parameters
*xF32 tensor to be transposed (2D tensor)

◆ aimath_f32_default_transpose_vector()

void aimath_f32_default_transpose_vector ( aitensor_t vector)

Transposes a F32 vector.

The given tensor must be a vector (2D tensor of shape [1 x N] or [N x 1]).

\[ vector \leftarrow vector^T \]

Example:

uint16_t vector_shape[2] = {1, 3};
float vector_data[1*3] = {1.0f, 2.0f, 3.0f};
aitensor_t vector = AITENSOR_2D_F32(vector_shape, vector_data);
print_aitensor(&vector);
void aimath_f32_default_transpose_vector(aitensor_t *vector)
Transposes a F32 vector.
Parameters
*vectorF32 vector (2D tensor of shape [1 x N] or [N x 1])

◆ aimath_f32_default_variance_channelwise()

void aimath_f32_default_variance_channelwise ( const aitensor_t x,
int8_t  channel_axis,
const aitensor_t means,
aitensor_t result 
)

Calculate the channel-wise variances of the F32 tensor x.

Calculates the empirical variance for each channel of the given axis:

\[ variances_i = \frac{1}{m} \sum_{j=1}^{m} (x_{i,j} - \mu_i)^2 \]

Parameters
xF32 input tensor (N-D)
channel_axisIndex of the channel axis (negative values mean indexing from the end)
meansF32 mean vector (1D) for variance calculation
resultF32 result vector (1D)

◆ aimath_f32_default_zero_tensor()

void aimath_f32_default_zero_tensor ( aitensor_t tensor)

Fills a F32 tensor with zeros.

\[ tensor_{i} = 0 \]

Example:

uint16_t tensor_shape[2] = {2, 3};
float tensor_data[2*3];
aitensor_t tensor = AITENSOR_2D_F32(tensor_shape, tensor_data);
print_aitensor(&tensor);
void aimath_f32_default_zero_tensor(aitensor_t *tensor)
Fills a F32 tensor with zeros.

In the F32 implementation of this function, there is no difference between aimath_f32_default_zero_tensor() and aimath_f32_default_init_zeros().

Parameters
*tensorF32 tensor to set to zero (N-D tensor)