Skip to content

About

This repository is a collection of examples and unit tests for the compact linear algebra (CLA) component.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

Compact Linear Algebra (CLA) Component Unit Tests

K0I05 License: MIT Language Framework Edited with VS Code Build with PlatformIO PlatformIO CI Maintenance

This repository is a collection of examples and unit tests for the compact linear algebra (CLA) component that is optimized and compatible with the ESP32 espressif IoT development framework (esp-idf). The development environment is under Visual Studio Code with the PlatformIO (6.1.18) and ESP-IDF (v5.5.1) extensions. The CLA test cases, matrix features and functionality was inspired by the Neat Matrix Library (NML) written in standard C. There is an official digital signal processing library (ESP-DSP) by expressif system. However, the codebase is a mixure of C/C++ which was a key driver behind developing the CLA component in native C.

The CLA component currently supports the following features and functionality:

  • Matrix Operations (row swaps, column swaps, multiplication, addition, etc.)
    • Transpose
    • Determinant
    • DOT Product
    • LUP Decomposition
    • LUP Inverse
    • LUP Determinant
    • Solving Linear Systems of Equations
    • QR Decomposition
  • Vector Operations (multiplication, addition, etc.)
    • DOT Product
    • CROSS Product
  • Common Matrix & Vector Operations
    • Convert Vector to Matrix
    • Convert Matrix to Vector
    • Multiply Matrix by Vector
    • Ellipsoid Coefficients
ESP32-S3_CLA_COMPONENT_UNIT_TESTS
├── assets
|   ├── data
|   |   └── cla_matrix_ls_solve_bck_data.h
|   |   └── ...
|   |   └── cla_matrix_lup_solve_data.h
|   └── generator
|       └── cla_matrix_ls_solve_bck_data_gen.py
|       └── ...
|       └── cls_matrix_lup_determinant_data_gen.py
├── components
│   └── esp_cla
├── include
├── src
│   └── CMakeLists.txt
│   └── main.c
├── test
|   ├── test_cla_ellipsoid
|   |   └── test_cla_ellipsoid.c
|   ├── test_cla_matrix
|   |   └── test_cla_matrix.c
|   ├── test_cla_matrix_ls
|   |   └── test_cla_matrix_ls.c
│   └── test_cla_matrix_lup
|       └── test_cla_matrix_lup.c
└── CMakeLists.txt
└── LICENSE
└── platformio.ini
└── README.md
└── sdkconfig
└── sdkconfig.esp32s3box

Data Generators

The data generators included with the CLA component unit tests are written in python and generate a C header file with datasets for up to 5 test cases by default. The generated header file is stored in the assets\data folder by default, data in the datasets is generated randomly, and updated every time the data generator is executed. The header file generated from a data generator should not be modified, otherwise, changes will get overwritten when the data generator is executed again.

The following data generators have been implemented to date:

  • cla_ellipsoid_calibration_data_gen.py: Generates data to validate ellipsoid calibration calculations and algorithms.
  • cla_ellipsoid_fitting_data_gen.py: Generates data to validate ellipsoid fitting calculations and algorithms.
  • cla_matrix_ls_solve_bck_data_gen.py: Generates data to validate upper triangular system of equations calculations and algorithms.
  • cla_matrix_ls_solve_data_gen.py: Generates data to validate system of equations calculations and algorithms.
  • cla_matrix_ls_solve_fwd_data_gen.py: Generates data to validate lower triangular system of equations calculations and algorithms.
  • cls_matrix_lup_inverse_data_gen.py: Generates data to validate LUP inverse calculations and algorithms.
  • cls_matrix_lup_solve_data_gen.py: Generates data to validate LUP solve calculations and algorithms.
  • cls_matrix_lup_determinant_data_gen.py: Generates data to validate LUP determinant calculations and algorithms.
  • cls_matrix_qr_solve_data_gen.py: Generates data to validate QR solve calculations and algorithms.
  • cla_matrix_qr_decomposition_data_gen.py: Generates data to validate QR decomposition calculations and algorithms.
  • cla_matrix_ref_data_gen.py: Generates data to validate matrix row echelon form calculations and algorithms.
  • cla_matrix_rref_data_gen.py: Generates data to validate matrix reduced row echelon form calculations and algorithms.

The generated data stored in the header file use a common nomenclature for variables as shown in the following example (cla_matrix_ls_solve_data_gen.py):

static const uint8_t cla_matrix_ls_solve_cases = 5;

static const uint16_t cla_matrix_ls_solve_x_rows[5] = {14, 7, 9, 2, 7, };

static const uint16_t cla_matrix_ls_solve_x_cols[5] = {1, 1, 1, 1, 1, };

static const double cla_matrix_ls_solve_x_mats[5][15][15] = {
{ {-0.150637782454419},
  {-0.293251384632263},
  { 0.120902195051887},
  {0.0511852044547286},
  {0.0751961937150376},
  { 0.971495478434766},
  { 0.583349427047727},
  { 0.299955419749627},
  {-0.648982869152492},
  {-0.335563455016736},
  { 0.517541400934789},
  { 0.252475218679566},
  {-0.223853617835992},
  {0.0129360044520968},}, 
  { {-0.0926139239206371},
  {   4.55513520348043},
  {  -1.77580203705454},
  {  -4.72630652732494},
  {   3.88297097007127},
  {  -1.97880278032137},
  {   1.15425121867773},}, 
  { {-6.13730138921696},
  {0.836873931153083},
  { 3.31849204974839},
  {0.640722020115444},
  { 2.74292973787276},
  {-1.16857250786019},
  {0.924854533524301},
  { 1.92448463437127},
  {-1.51336484987018},}, 
  { {-2.12130177514793},
  { 2.22189349112426},}, 
  { { -1.59542875325154},
  {  4.61547687474465},
  {-0.907466180245292},
  {-0.264875482576947},
  {  3.89096665972596},
  { 0.372870045587604},
  { -5.58438741500493},}, };

Test Cases

The following test cases have been implemented to date:

  • test_cla_ellipsoid.c: Tests solving ellipsoid coefficients and soft and hard-iron calibration parameters.
  • test_cla_matrix.c: Tests matrix QR decomposition, reduced row echelon form, and row echelon form calculations.
  • test_cla_matrix_ls.c: Tests matrix system of equations for solving an equation, upper and lower triangle calculations.
  • test_cla_matrix_lup.c: Tests matrix LUP decomposition, inverse, and determinant calculations.

The test cases reference test data header files generated from the python data generators and compare computed versus expected results. Please review individual test files for details on test cases implemented to date by test group i.e. ellipsoid, matrix, matrix linear system (LS), matrix LUP, and vector.

A verbose test command example with test results is shown below (platformio.exe test -vvv --environment esp32s3box):

================================================================================================== SUMMARY ================================================================================================== 
Environment    Test                 Status    Duration
-------------  -------------------  --------  ------------
esp32s3box     test_cla_ellipsoid   PASSED    00:00:30.689
esp32s3box     test_cla_matrix      PASSED    00:00:20.986
esp32s3box     test_cla_matrix_ls   PASSED    00:00:23.530
esp32s3box     test_cla_matrix_lup  PASSED    00:00:23.623
================================================================================ 11 test cases: 11 succeeded in 00:01:38.828 ================================================================================ 

The above test results show that a total of 11 test cases were executed and succeeded. Additional documentation on performing unit tests in Viual Studio Code with PlatformIO extension can be found in the PlatformIO documentation, Unit Testing.

Copyright (c) 2025 Eric Gionet (gionet.c.eric@gmail.com)

About

This repository is a collection of examples and unit tests for the compact linear algebra (CLA) component.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages