AIfES 2 2.0.0
aimath_f32_avr_pgm.h File Reference

Math functions for F32 data type using AVR pgmspace.h library for constant data storage. More...

Go to the source code of this file.

Functions

void aimath_f32_avr_pgm_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...
 

Detailed Description

Math functions for F32 data type using AVR pgmspace.h library for constant data storage.

Version
2.0alpha

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/.

These functions modify the default implementation of the F32 math functions to work with parameters, stored in the program memory of AVR controllers.

The library avr/pgmspace.h is required.

Function Documentation

◆ aimath_f32_avr_pgm_linear()

void aimath_f32_avr_pgm_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 data of b and c must be defined constant in PROGMEM.

Same functionality as aimath_f32_default_linear().

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 * b

\[ result = a \cdot b + \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};
const float b_data[3*2] PROGMEM = {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};
const float c_data[1*2] PROGMEM = {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_avr_pgm_linear(&a, &b, &c, &result);
void aimath_f32_avr_pgm_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.
A tensor in AIfES.
Definition: aifes_math.h:92
Parameters
*aF32 matrix a (2D tensor of shape [N x K])
*bF32 matrix b (2D tensor of shape [K x M]) (data const in PROGMEM)
*cF32 vector c (2D tensor of shape [1 x M]) (data const in PROGMEM)
*resultResulting F32 matrix (2D tensor of shape [N x M])