AIfES 2
2.0.0
|
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... | |
Math functions for F32 data type, default implementation.
These functions can be used when no hardware specific implementation is available.
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:
*predicted_data | F32 matrix with the predicted or calculated values (2D tensor) |
*target_data | F32 matrix with the target data / true values / labels (2D tensor with binary values 0 or 1) |
*result | Resulting F32 matrix (2D tensor) |
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:
*predicted_data | F32 matrix with the predicted or calculated values (2D tensor) |
*target_data | F32 matrix with the target data / true values / labels (2D tensor with binary values 0 or 1) |
*result | Resulting F32 matrix (2D tensor) |
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:
*predicted_data | F32 matrix with the predicted or calculated values (2D tensor) |
*target_data | F32 matrix with the target data / true values / labels (2D tensor, rows one-hot encoded) |
*result | Resulting F32 matrix (2D tensor) |
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:
*predicted_data | F32 matrix with the predicted or calculated values (2D tensor of shape [N x M]) |
*target_data | U8 matrix with the target data / true values / labels (2D tensor of shape [N x 1] with true class indices) |
*result | Resulting F32 matrix (2D tensor of shape [N x M]) |
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:
*predicted_data | F32 matrix with the predicted or calculated values (2D tensor) |
*target_data | F32 matrix with the target data / true values / labels (2D tensor, rows one-hot encoded) |
*result | Resulting F32 matrix (2D tensor) |
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:
*predicted_data | F32 matrix with the predicted or calculated values (2D tensor of shape [N x M]) |
*target_data | U8 matrix with the target data / true values / labels (2D tensor of shape [N x 1] with true class indices) |
*result | Resulting F32 matrix (2D tensor of shape [N x M]) |
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:
*from | F32 tensor to copy from (N-D tensor) |
*to | F32 tensor to copy to (N-D tensor) |
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:
*x | F32 tensor to calculate the ELU derivative from (N-D tensor) |
*alpha | Scalar \( \alpha \) (type aiscalar_f32_t / float) |
*result | Resulting F32 tensor (N-D tensor) |
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:
*x | F32 tensor to calculate the leaky ReLU derivative from (N-D tensor) |
*alpha | Scalar \( \alpha \) (type aiscalar_f32_t / float) for the leakage |
*result | Resulting F32 tensor (N-D tensor) |
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:
*x | F32 tensor to calculate the ReLU derivative from (N-D tensor) |
*result | Resulting F32 tensor (N-D tensor) |
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:
*sigmoid_x | F32 tensor with the sigmoid values \( \sigma(x_{i}) \) (N-D tensor) |
*result | Resulting F32 tensor (N-D tensor) |
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:
*x | F32 tensor to calculate the softsign derivative from (N-D tensor) |
*result | Resulting F32 tensor (N-D tensor) |
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:
*tanh_x | F32 tensor with the tanh values \( \tanh(x_{i}) \) (N-D tensor) |
*result | Resulting F32 tensor (N-D tensor) |
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:
*a | F32 tensor a (N-D tensor) |
*b | F32 tensor b (N-D tensor) |
*result | Resulting F32 tensor of the element wise division (N-D tensor) |
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:
*x | F32 tensor to calculate the ELU from (N-D tensor) |
*alpha | Scalar \( \alpha \) (type aiscalar_f32_t / float) |
*result | Resulting F32 tensor (N-D tensor) |
float aimath_f32_default_expf_fast | ( | const float | x | ) |
Fast approximation of the exponential function.
x | Input of the exponential function |
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 \]
new_data | Input tensor (N-D) with the new data point. |
momentum | aiscalar_t (float value) which controls the momentum of the average (range [0, 1]). |
average | The average tensor (N-D) that is modified (input and output value), |
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:
*tensor | F32 tensor to initialize with random numbers (N-D 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.
\[ fan_{avg} = \frac{fan_{in} + fan_{out}}{2} \]
\[ r = \sqrt{\frac{3}{fan_{avg}}} \]
\[ tensor_i \in \mathcal{U(-r, r)} \]
Example:
*tensor | F32 tensor to initialize with random numbers (N-D tensor) |
cin_axis | Axis of the input channels (negative number means indexing from the end) |
cout_axis | Axis of the output channels (negative number means indexing from the end) |
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:
*tensor | F32 tensor to initialize with random numbers (N-D 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.
\[ fan_{avg} = \frac{fan_{in}}{2} \]
\[ r = \sqrt{\frac{3}{fan_{avg}}} \]
\[ tensor_i \in \mathcal{U(-r, r)} \]
Example:
*tensor | F32 tensor to initialize with random numbers (N-D tensor) |
cout_axis | Axis of the output channels (negative number means indexing from the end) |
void aimath_f32_default_init_ones | ( | aitensor_t * | tensor | ) |
Fills a F32 tensor with ones.
\[ tensor_{i} = 1 \]
Example:
*tensor | F32 tensor to set to zero (N-D tensor) |
void aimath_f32_default_init_zeros | ( | aitensor_t * | tensor | ) |
Fills a F32 tensor with zeros.
\[ tensor_{i} = 0 \]
Example:
In the F32 implementation of this function, there is no difference between aimath_f32_default_zero_tensor() and aimath_f32_default_init_zeros().
*tensor | F32 tensor to set to zero (N-D tensor) |
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:
*x | F32 tensor to calculate the leaky ReLU from (N-D tensor) |
*alpha | Scalar \( \alpha \) (type aiscalar_f32_t / float) for the leakage |
*result | Resulting F32 tensor (N-D tensor) |
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:
*a | F32 matrix a (2D tensor of shape [N x K]) |
*b | F32 matrix b (2D tensor of shape [K x M]) |
*c | F32 vector c (2D tensor of shape [1 x M] or 1D tensor of shape [M]) |
*result | Resulting F32 matrix (2D tensor of shape [N x M]) |
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:
*a | F32 matrix a (2D tensor of shape [K x N]) |
*b | F32 matrix b (2D tensor of shape [K x M]) |
*c | F32 vector c (2D tensor of shape [1 x M] or 1D tensor of shape [M]) |
*result | Resulting F32 matrix (2D tensor of shape [N x M]) |
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:
*a | F32 matrix a (2D tensor of shape [K x N]) |
*b | F32 matrix b (2D tensor of shape [K x M]) |
*c | F32 vector c (2D tensor of shape [1 x M] or 1D tensor of shape [M]) |
*result | Resulting F32 matrix (2D tensor of shape [M x N]) |
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:
*a | F32 matrix a (2D tensor of shape [N x K]) |
*b | F32 matrix b (2D tensor of shape [M x K]) |
*c | F32 vector c (2D tensor of shape [1 x M] or 1D tensor of shape [M]) |
*result | Resulting F32 matrix (2D tensor of shape [N x M]) |
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:
*a | F32 matrix a (2D tensor of shape [N x K]) |
*b | F32 matrix b (2D tensor of shape [K x M]) |
*result | Resulting F32 matrix of the multiplication (2D tensor of shape [N x M]) |
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:
*a | F32 matrix a (2D tensor of shape [K x N]) |
*b | F32 matrix b (2D tensor of shape [K x M]) |
*result | Resulting F32 matrix of the multiplication (2D tensor of shape [N x M]) |
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:
*a | F32 matrix a (2D tensor of shape [K x N]) |
*b | F32 matrix b (2D tensor of shape [K x M]) |
*result | Resulting F32 matrix of the multiplication (2D tensor of shape [M x N]) |
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:
*a | F32 matrix a (2D tensor of shape [N x K]) |
*b | F32 matrix b (2D tensor of shape [M x K]) |
*result | Resulting F32 matrix of the multiplication (2D tensor of shape [N x M]) |
void aimath_f32_default_max | ( | const aitensor_t * | x, |
void * | result | ||
) |
Identifies the maximum value in a F32 tensor.
\[ result = max(x) \]
Example:
*x | F32 tensor x to get the maximum value of (N-D tensor) |
*result | Scalar result (type aiscalar_f32_t / float) |
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} \]
x | F32 input tensor (N-D) |
channel_axis | Index of the channel axis (negative values mean indexing from the end) |
result | F32 result vector (1D) |
void aimath_f32_default_min | ( | const aitensor_t * | x, |
void * | result | ||
) |
Identifies the minimum value in a F32 tensor.
\[ result = min(x) \]
Example:
*x | F32 tensor x to get the minimum value of (N-D tensor) |
*result | Scalar result (type aiscalar_f32_t / float) |
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.
*predicted_data | F32 matrix with the predicted or calculated values (2D tensor) |
*target_data | F32 matrix with the target data / true values / labels (2D tensor, rows one-hot encoded) |
*result | F32 tensor containing the gradients |
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.
*predicted_data | F32 matrix with the predicted or calculated values (2D tensor) |
*target_data | F32 matrix with the target data / true values / labels (2D tensor, rows one-hot encoded) |
*result | F32 tensor containing the gradients |
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.
*predicted_data | F32 matrix with the predicted or calculated values (2D tensor) |
*target_data | F32 matrix with the target data / true values / labels (2D tensor, rows one-hot encoded) |
*result | Resulting loss (float) |
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.
*predicted_data | F32 matrix with the predicted or calculated values (2D tensor) |
*target_data | F32 matrix with the target data / true values / labels (2D tensor, rows one-hot encoded) |
*result | Resulting loss (float) |
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:
*a | F32 tensor a (N-D tensor) |
*b | F32 tensor b (N-D tensor) |
*result | Resulting F32 tensor of the element wise multiplication (N-D tensor) |
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:
*x | F32 tensor x (N-D tensor) |
*result | Scalar result (type aiscalar_f32_t / float) |
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:
*x | F32 tensor to calculate the ReLU from (N-D tensor) |
*result | Resulting F32 tensor (N-D tensor) |
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:
*scalar | Scalar (type aiscalar_f32_t / float) |
*a | F32 tensor a (N-D tensor) |
*result | Resulting F32 tensor of the element wise scalar addition (N-D tensor) |
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:
*scalar | Scalar (type aiscalar_f32_t / float) |
*a | F32 tensor a (N-D tensor) |
*result | Resulting F32 tensor of the scalar multiplication (N-D tensor) |
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)
*a | F32 tensor that is going to be scaled by its batch size |
*result | Scaled F32 tensor |
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:
*x | F32 tensor to calculate the sigmoid from (N-D tensor) |
*result | Resulting F32 tensor (N-D tensor) |
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:
*x | F32 matrix to calculate the softmax from (2D tensor) |
*result | Resulting F32 matrix (2D tensor) |
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:
*x | F32 tensor to calculate the softsign from (N-D tensor) |
*result | Resulting F32 tensor (N-D tensor) |
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:
*x | F32 tensor to calculate the square root from (N-D tensor) |
*result | Resulting F32 tensor (N-D tensor) |
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:
*x | F32 tensor x (N-D tensor) |
*result | Scalar result (type aiscalar_f32_t / float) |
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:
*x | F32 tensor to calculate the tanh from (N-D tensor) |
*result | Resulting F32 tensor (N-D tensor) |
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:
*a | F32 tensor a (N-D tensor) |
*b | F32 tensor b (N-D tensor) |
*result | Resulting F32 tensor of the element wise addition (N-D 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.
\[ tensor_i \in \mathcal{U(from, to)} \]
Example:
*tensor | F32 tensor to initialize with random numbers (N-D tensor) |
from | Minimum value of the uniform distribution |
to | Maximum value of the uniform distribution |
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:
*a | F32 tensor a (N-D tensor) |
*b | F32 tensor b (N-D tensor) |
*result | Resulting F32 tensor of the element wise subtraction (N-D tensor) |
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:
*a | F32 matrix a (2D tensor of shape [N x M]) |
*b | U8 sparse matrix b (2D tensor of shape [N x 1]) |
*result | Resulting F32 tensor of the subtraction (2D tensor of shape [N x M]) |
void aimath_f32_default_transpose_matrix | ( | aitensor_t * | x | ) |
Transpose a F32 tensor.
\[ x \leftarrow x^T \]
Example:
*x | F32 tensor to be transposed (2D tensor) |
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:
*vector | F32 vector (2D tensor of shape [1 x N] or [N x 1]) |
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 \]
x | F32 input tensor (N-D) |
channel_axis | Index of the channel axis (negative values mean indexing from the end) |
means | F32 mean vector (1D) for variance calculation |
result | F32 result vector (1D) |
void aimath_f32_default_zero_tensor | ( | aitensor_t * | tensor | ) |
Fills a F32 tensor with zeros.
\[ tensor_{i} = 0 \]
Example:
In the F32 implementation of this function, there is no difference between aimath_f32_default_zero_tensor() and aimath_f32_default_init_zeros().
*tensor | F32 tensor to set to zero (N-D tensor) |