| AIfES 2 2.0.0

Functions
aimath_basic.h File Reference

Basic data-type independent math operations. More...

Go to the source code of this file.

## Functions
void | print_aitensor (const aitensor_t *tensor)
| Printing a tensor to console. More...
void | print_aiscalar (const void *scalar, const aimath_dtype_t *dtype)
| Printing a scalar to console. More...
void | aimath_transpose_vector (aitensor_t *vector)
| Transposes a vector. More...
uint32_t | aimath_tensor_elements (const aitensor_t *tensor)
| Calculates the number of elements in a tensor. More...
uint32_t | aimath_sizeof_dtype (const aimath_dtype_t *dtype)
| Returns the size of one value in the given data type in bytes. More...
uint32_t | aimath_sizeof_tensor_data (const aitensor_t *tensor)
| Returns size of the data array of the tensor in bytes. More...
uint32_t | aimath_sizeof_tensor_params (const aitensor_t *tensor)
| Returns size of the aitensor.tensor_params for the data type of the tensor. More...
uint32_t | aimath_sizeof_tensor (const aitensor_t *tensor)
| Returns size of tensor in bytes. More...

## Detailed Description

Basic data-type independent math operations.

Version
  2.2.0

Copyright
  Copyright (C) 2020-2023 Fraunhofer Institute for Microelectronic Circuits and Systems. All rights reserved.
  AIfES is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
  This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.
  You should have received a copy of the GNU Affero General Public License along with this program. If not, see https://www.gnu.org/licenses/.

## Function Documentation

## ◆ aimath_sizeof_dtype()

uint32_t aimath_sizeof_dtype | ( | const aimath_dtype_t * | dtype | ) |

Returns the size of one value in the given data type in bytes.

Parameters

  *dtype | The data type to get the size of

Returns
  Size of one value in the given data type in bytes

## ◆ aimath_sizeof_tensor()

uint32_t aimath_sizeof_tensor | ( | const aitensor_t * | tensor | ) |

Returns size of tensor in bytes.

The size is calculated by:

sizeof(aitensor_t) + aimath_sizeof_tensor_data(tensor) + aimath_sizeof_tensor_params(tensor)
aimath_sizeof_tensor_data
uint32_t aimath_sizeof_tensor_data(const aitensor_t *tensor)
Returns size of the data array of the tensor in bytes.
aimath_sizeof_tensor_params
uint32_t aimath_sizeof_tensor_params(const aitensor_t *tensor)
Returns size of the aitensor.tensor_params for the data type of the tensor.
aitensor
A tensor in AIfES.
Definition: aifes_math.h:89

Parameters

  *tensor | The tensor to get the size of

Returns
  Size of tensor in bytes

## ◆ aimath_sizeof_tensor_data()

uint32_t aimath_sizeof_tensor_data | ( | const aitensor_t * | tensor | ) |

Returns size of the data array of the tensor in bytes.

The size is calculated by:

aimath_tensor_elements(tensor) * aimath_sizeof_dtype(tensor.dtype)
aimath_sizeof_dtype
uint32_t aimath_sizeof_dtype(const aimath_dtype_t *dtype)
Returns the size of one value in the given data type in bytes.
aimath_tensor_elements
uint32_t aimath_tensor_elements(const aitensor_t *tensor)
Calculates the number of elements in a tensor.

Parameters

  *tensor | The tensor to get the data size of

Returns
  Size of tensor data in bytes

## ◆ aimath_sizeof_tensor_params()

uint32_t aimath_sizeof_tensor_params | ( | const aitensor_t * | tensor | ) |

Returns size of the aitensor.tensor_params for the data type of the tensor.

Parameters

  *tensor | The tensor to get the parameters size of

Returns
  Size of tensor parameters in bytes

## ◆ aimath_tensor_elements()

uint32_t aimath_tensor_elements | ( | const aitensor_t * | tensor | ) |

Calculates the number of elements in a tensor.

Parameters

  *tensor | The tensor to count the elements of

Returns
  Number of elements in tensor

## ◆ aimath_transpose_vector()

void aimath_transpose_vector | ( | aitensor_t * | vector | ) |

Transposes a vector.

\[ vector \leftarrow vector^T \]

Make sure that the given tensor is a vector (with shape [1 x N] or [N x 1])

Parameters

  *vector | The vector to transpose (2D tensor of shape [1 x N] or [N x 1])

## ◆ print_aiscalar()

void print_aiscalar | ( | const void * | scalar,
|  | const aimath_dtype_t * | dtype
| ) |  |

Printing a scalar to console.

Calls the corresponding print function of the used aimath_dtype.

Example:

aiscalar_f32_t scalar = 42.0f;
print_aiscalar(&scalar, aif32);
print_aiscalar
void print_aiscalar(const void *scalar, const aimath_dtype_t *dtype)
Printing a scalar to console.
aif32
const aimath_dtype_t * aif32
The F32 data-type indicator.
aiscalar_f32_t
float aiscalar_f32_t
Scalar for F32 (aif32) data-type.
Definition: aimath_f32.h:120

Parameters

  *scalar | The scalar to print.
  *dtype | The data type of the scalar

## ◆ print_aitensor()

void print_aitensor | ( | const aitensor_t * | tensor | ) |

Printing a tensor to console.

Calls the corresponding print function of the used aimath_dtype.

Example:

uint16_t tensor_shape[2] = {2, 3};
float tensor_data[2*3] = {1.0f, 2.0f, 3.0f,
4.0f, 5.0f, 6.0f};
aitensor_t tensor = AITENSOR_2D_F32(tensor_shape, tensor_data);
print_aitensor(&tensor);
print_aitensor
void print_aitensor(const aitensor_t *tensor)
Printing a tensor to console.

Parameters

  *tensor | The tensor to print.