Typed Linear Algebra 0.1.0
Typed Linear Algebra
Loading...
Searching...
No Matches
Typed Linear Algebra

This library provides a C++ strongly-typed facade to a matrix linear algebra backend.

Examples

state x{3. * m,
2. * m / s,
1. * m / s2};
std::println("{}", x * transpose(x));
// [[9 m², 6 m²/s, 3 m²/s²],
// [6 m²/s, 4 m²/s², 2 m²/s³],
// [3 m²/s², 2 m²/s³, 1 m²/s⁴]]

Installation

Example of installation commands in Shell:

git clone --depth 1 "https://github.com/FrancoisCarouge/TypedLinearAlgebra"
cmake -S "TypedLinearAlgebra" -B "build"
cmake --build "build" --parallel
sudo cmake --install "build"

Another variation for your CMake infrastructure via fetch content:

include(FetchContent)
FetchContent_Declare(
fcarouge-typed-linear-algebra
GIT_REPOSITORY "https://github.com/FrancoisCarouge/TypedLinearAlgebra"
FIND_PACKAGE_ARGS NAMES fcarouge-typed-linear-algebra)
FetchContent_MakeAvailable(fcarouge-typed-linear-algebra)
target_link_libraries(your_target PRIVATE fcarouge-typed-linear-algebra::linalg)

For more, see installation instructions.

Reference

Class Typed Matrix

Strongly typed matrix. Compose a linear algebra backend matrix into a typed matrix. Row and column indexes provide each element's index type.

Also documented in the fcarouge/typed_linear_algebra.hpp header.

Declaration

template <typename Matrix, typename RowIndexes, typename ColumnIndexes>
class typed_matrix

Template Parameters

Template Parameter Definition
Matrix The underlying linear algebra matrix.
RowIndexes The tuple type of the row indexes.
ColumnIndexes The tuple type of the row indexes.

Member Types

Member Type Definition
matrix The type of the composed matrix.
underlying The type of the element's underlying storage.
row_indexes The tuple with the row components of the indexes.
column_indexes The tuple with the column components of the indexes.
element<i, j> The type of the element at the given matrix indexes position.

Member Variables

Member Variable Definition
rows The count of rows.
columns The count of columns.

Member Functions

Member Function Definition
(default constructor) Construct a default typed matrix.
(default copy constructor) Copy construct the typed matrix.
(default copy assignment operator) Copy assign a typed matrix.
(default move constructor) Move construct a typed matrix.
(default move assignment operator) Move construct a typed matrix.
(conversion copy constructor) Copy construct generalization of a compatible typed matrix.
(conversion copy assignment operator) Copy assign generalization of a compatible typed matrix.
(conversion move constructor) Move construct generalization of a compatible typed matrix.
(conversion move assignment operator) Move assign generalization of a compatible typed matrix.
(conversion copy constructor) Convert construct a typed matrix from an underlying matrix.
(conversion copy constructor) Convert construct a one-dimension uniformly typed matrix from array.
(conversion copy constructor) Convert construct a uniformly typed matrix from list-initializers.
(conversion copy constructor) Convert construct a row or column typed vector from elements.
(conversion copy constructor) Convert construct a singleton typed matrix from a single value.
operator[i, j] Access the specified element.
operator(i, j) Access the specified element.
at<i, j>() Access the specified element.
(conversion operator) Access the singleton typed matrix element.
(destructor) Destruct a default typed matrix.

Operations

The following useful operations are supported. This library attempts to align its nomenclature aligned with that of the primitives provided by std::linalg. This library attempts some compatibility with other C++ standard library primitives, ranges, and iterators.

Operation Definition
+ Addition where the terms are of identical shapes and addable types.
- Substraction where the terms are of identical shapes and substractable types.
* Multiplication where the factors are of multipliable shapes and multipliable types.
/ Solution, if there exists one, to the inverse multiplication, where the factor are of compatible shapes and types.
== Direct, strict equality comparison, with traditional floating-point comparison pitfalls.

Aliases

template <typename Matrix, typename... ColumnIndexes>
typed_row_vector;
template <typename Matrix, typename... RowIndexes>
typed_column_vector;

Format

A specialization of the standard formatter is provided for the typed matrix. Use std::format to store a formatted representation of the matrix. Standard format parameters to be supported.

Concepts

Concept Definition
is_typed_matrix Concept of a typed matrix type.
is_singleton_typed_matrix Concept of a singleton, one-element typed matrix type.
is_uniform_typed_matrix Concept of a typed matrix in which all element types are the same.
is_one_dimension_typed_matrix Concept of a typed matrix with only one dimension, row, or column.
is_row_typed_matrix Concept of a row typed matrix, vector.
is_column_typed_matrix Concept of a column typed matrix, vector.

Structure Element Caster

Typed matrix element conversions customization point. Specialize this template to allow conversion of element's type and underlying type.

template <typename To, typename From> struct element_caster

Considerations

Lessons Learned

Type safety cannot be guaranteed at compilation time without index safety. The indexes can either be non-type template parameters or strong types overloadings. Converting a runtime index to a dependent template type is not possible in C++. A proxy reference could be used to allow traditional assignment syntax but the runtime check and extra indirection are not interesting tradeoffs. A template call operator can be used for getting a type safe value but impractical syntax for setting. Without index safety, the accepted tradeoff is a templated index at<i, j>() method.

Performance

Projects

The library is used in projects:

  • Kalman: A Kalman filter library.

Your project link here!

Resources

Third Party Acknowledgement

The library is designed, developed, and tested with the help of third-party tools and services acknowledged and thanked here:

  • actions-gh-pages to upload the documentation to GitHub pages.
  • Clang for compilation and code sanitizers.
  • CMake for build automation.
  • cmakelang for pretty CMake list files.
  • cppcheck for static analysis.
  • Doxygen for documentation generation.
  • Doxygen Awesome for pretty documentation.
  • Eigen for linear algebra.
  • GCC for compilation and code sanitizers.
  • lcov to process coverage information.
  • mp-units the quantities and units library for C++.
  • MSVC for compilation and code sanitizers.
  • Valgrind to check for correct memory management.

Sponsors

Become a sponsor today! Support this project with coffee and infrastructure!

Sponsor

Corporations & Institutions

Your group logo and link here!

Individuals

Your name and link here!

Thanks everyone!

Continuous Integration & Deployment Actions

Code Repository

Pipeline

Sanitizer
Format
ClangTidy
CppCheck
Doxygen
Valgrind

Public Domain
License Scan
OpenSSF Best Practices

Deploy Unit Test Code Coverage
Deploy Doxygen

Sponsor

License

TypedLinearAlgebra is public domain:

This is free and unencumbered software released into the public domain.

Anyone is free to copy, modify, publish, use, compile, sell, or distribute this software, either in source code form or as a compiled binary, for any purpose, commercial or non-commercial, and by any means.

In jurisdictions that recognize copyright laws, the author or authors of this software dedicate any and all copyright interest in the software to the public domain. We make this dedication for the benefit of the public at large and to the detriment of our heirs and successors. We intend this dedication to be an overt act of relinquishment in perpetuity of all present and future rights to this software under copyright law.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

For more information, please refer to https://unlicense.org