| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
This library is a collection of functions and classes for doing math on small matrices with less than 2kb of instruction memory and 1kb of RAM.
It is available as:
It sacrifices some of the power of more feature-rich libraries like Basic Linear Algebra or Eigen to minimize memory footprint and standardize matrix storage across devices, possibly simplifying the process of passing matrices around across devices.
The Sheldrake library employs this library to send matrices between desktop environments and microcontrollers.
Despite this library being "tiny", it supports many common matrix operations including:
Elements with 🚧 are not yet stable or implemented.
Most common mistakes with matrix operations are checked for at compile-time, so there's no need to worry about deploying code with the following issues:
Matrices with less than 256 rows and 256 columns are supported by this library (if your device can store a matrix with a whopping 263kb RAM!). Larger matrices might be processed more efficiently with Eigen.
Here are some examples of how to use the library:
Including the library
#include "TinyMatrixMath.hpp"Creating a 3x3 identity matrix:
tmm::Matrix<3,3> eye = tmm::Identity<3>();Creating a 3x3 matrix from a float array
const tmm::Scalar A_raw[3][3] = {
{1, 2, 3},
{4, 5, 6},
{9, 8, 9}
};
tmm::Matrix<3,3> A(A_raw);Getting the inverse of a square matrix
tmm::Matrix<3,3> A_inv = A.inverse();Printing a matrix to Serial if the Arduio library is available
A.printTo(Serial); // Arduino
A.printTo(std::cout); // CMakeGetting the determinant of a square matrix
tmm::Scalar det_A = A.determinant();Use any sized matrix
tmm::Matrix<4,5> B; // 4 rows, 5 columns
tmm::Matrix<5,2> C; // 5 rows, 2 columns
tmm::Matrix<5,2> D; // 5 rows, 2 columns
// Matrix-matrix multiplication
tmm::Matrix<4,2> E = B * C; // 4 rows, 2 columns
// Elementwise addition
tmm::Matrix<5,2> F = C + D;
// Elementwise multiplication
F = C.elementwise_times(D);
// Elementwise subtraction, and print the result to Serial
(C - D).printTo(Serial); // Arduino
(C - D).printTo(std::cout); // CMakeInvalid matrix multiplication is checked at compile-time.
tmm::Matrix<4,2> G = C * B; // error: no match for 'operator*' (operand types are 'tmm::Matrix<5, 2, float>' and 'tmm::Matrix<4, 5, float>')Elementwise scalar operations are supported
tmm::Matrix<2> H = 5; // set all elements to 5
H = H+1; // add 1 to every element
H = H-2; // reduce every element by 2
H = H*3; // multiply every element by 3
H = H/4; // divide every element by 41x1 matrices can be implicitly cast to Scalars
tmm::Matrix<1,1> I = 5;
tmm::Scalar s = I; // s = 5
s = H; // error: cannot convert 'tmm::Matrix<2,2,float>' to 'float' in assignmentThe following projects were initially generated from this template:
For making your own CMake/Arduino library from this template, complete the following steps:
git switch --orphan docs
git commit --allow-empty -m "Initial commit on orphan branch"
git push -u origin docsAnd you're finally done!
If you run into any issues along the way, file them here
| Back | FazBrowse Home | New Git URL |