https://github.com/pjessesco/peanut
🥜 Header-only C++20 matrix library using expression templates
https://github.com/pjessesco/peanut
cpp20 expression-template header-only matrix matrix-library modern-cpp template-metaprogramming
Last synced: 10 days ago
JSON representation
🥜 Header-only C++20 matrix library using expression templates
- Host: GitHub
- URL: https://github.com/pjessesco/peanut
- Owner: pjessesco
- License: mit
- Created: 2022-05-24T12:16:46.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2025-04-13T08:40:46.000Z (about 1 month ago)
- Last Synced: 2025-05-07T20:45:35.338Z (10 days ago)
- Topics: cpp20, expression-template, header-only, matrix, matrix-library, modern-cpp, template-metaprogramming
- Language: C++
- Homepage: https://pjessesco.github.io/peanut/
- Size: 7.67 MB
- Stars: 9
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Peanut
[](https://github.com/pjessesco/peanut/actions/workflows/unittest_macos_appleclang.yml)
[](https://github.com/pjessesco/peanut/actions/workflows/unittest_macos_clang.yml)
[](https://github.com/pjessesco/peanut/actions/workflows/unittest_windows_msvc.yml)
[](https://github.com/pjessesco/peanut/actions/workflows/unittest_windows_clang.yml)
[](https://github.com/pjessesco/peanut/actions/workflows/docs.yml)**Peanut** is a header-only matrix library using C++20 without any external dependencies, (except unit test), following a `expression templates` concept. It first constructs matrix expression as a user provides, and evaluates it using an automatically generated code in a compile-time.
```
Matrix mat1{1,2,3,4,
1,2,3,4,
1,2,3,4,
1,2,3,4};Matrix mat2{1,2,3,4,5,
1,2,3,4,5,
1,2,3,4,5};// Peanut first build expression tree,
// `result` type is `MatrixMult, MatrixInverse>>, MatrixMinor>>, MatrixSub<2, 1, MatrixMult>, Matrix>>>`.
auto result = (mat1 + Inverse(mat1) - Minor(mat1)) * SubMat<2, 1>(T(mat2) * mat2);// then evaluate it when `eval()` is called or assigned to `Matrix` type variable.
/* Matrix */ auto e1 = result.eval();
Matrix e2 = result;
```### Features
- Arbitrary size matrix expression
- Lazy evaluation
- Unit test### Usage
Copy `Peanut` directory to your project, and add and its path to the include path. If you're using CMake, add :add_subdirectory(ext/peanut)
include_directories(ext/peanut/include)Then include as below :
#include
Refer [documentation](https://pjessesco.github.io/peanut/) for more information.