MIT license MIT license Download as .zip Download as .tar.gz
Contact tom@geus.me Website www.geus.me Github tdegeus/cppmat
Website cppmat.geus.me


This library is free to use under the MIT license. Any additions are very much appreciated, in terms of suggested functionality, code, documentation, testimonials, word of mouth advertisement, …. Bugs or feature requests can be filed on GitHub. As always, the code comes with no guarantee. None of the developers can be held responsible for possible mistakes.


This document should be considered as a quick-start guide. A lot effort has been spent on the readability of the code itself (in particular the *.h files should be instructive). One is highly encouraged to answer more advanced questions that arise from this guide directly using the code. Download buttons to the relevant files are included throughout this reader.

This header-only module provides C++ classes and several accompanying methods to work with n-d arrays and/or tensors. It’s usage, programmatically and from a compilation perspective, is really simple. One just has to #include <cppmat/cppmat.h> and tell your compiler where cppmat is located (and to use the C++14 or younger standard). Really, that’s it!


The following dynamically sized classes can be used.

Class Description
cppmat::array array of arbitrary rank
cppmat::matrix matrix (array of rank 2)
cppmat::vector vector (array of rank 1)
cppmat::symmetric::matrix symmetric, square, matrix
cppmat::diagonal::matrix diagonal, square, matrix
cppmat::cartesian::tensor4 4th-order tensor
cppmat::cartesian::tensor2 2nd-order tensor
cppmat::cartesian::tensor2s 2nd-order symmetric tensor
cppmat::cartesian::tensor2d 2nd-order diagonal tensor
cppmat::cartesian::vector 1st-order tensor (a.k.a. vector)

Each of these classes has a fixed size equivalent (that is usually more efficient):

Fixed size Dynamical size
cppmat::tiny::array cppmat::array
cppmat::tiny::matrix cppmat::matrix
cppmat::tiny::vector cppmat::vector
cppmat::tiny::symmetric::matrix cppmat::symmetric::matrix
cppmat::tiny::diagonal::matrix cppmat::diagonal::matrix
cppmat::tiny::cartesian::tensor4 cppmat::cartesian::tensor4
cppmat::tiny::cartesian::tensor2 cppmat::cartesian::tensor2
cppmat::tiny::cartesian::tensor2s cppmat::cartesian::tensor2s
cppmat::tiny::cartesian::tensor2d cppmat::cartesian::tensor2d
cppmat::tiny::cartesian::vector cppmat::cartesian::vector

Each fixed size class has an equivalent which can view a const-pointer (with limited functionality):

View pointer Fixed size
cppmat::view::array cppmat::tiny::array
cppmat::view::matrix cppmat::tiny::matrix
cppmat::view::vector cppmat::tiny::vector
cppmat::view::symmetric::matrix cppmat::tiny::symmetric::matrix
cppmat::view::diagonal::matrix cppmat::tiny::diagonal::matrix
cppmat::view::cartesian::tensor4 cppmat::tiny::cartesian::tensor4
cppmat::view::cartesian::tensor2 cppmat::tiny::cartesian::tensor2
cppmat::view::cartesian::tensor2s cppmat::tiny::cartesian::tensor2s
cppmat::view::cartesian::tensor2d cppmat::tiny::cartesian::tensor2d
cppmat::view::cartesian::vector cppmat::tiny::cartesian::vector


#include <cppmat/cppmat.h>

int main()
    cppmat::array<double> A({10,10,10});

    A(0,0,0) = ...


    return 0;