smooth
A C++ library for Lie theory
Loading...
Searching...
No Matches
static_matrix.hpp
Go to the documentation of this file.
1// Copyright (C) 2021-2022 Petter Nilsson. MIT License.
2
3#pragma once
4
10#include <array>
11
12#include "../detail/utils.hpp"
13
14SMOOTH_BEGIN_NAMESPACE
15
21template<typename _Scalar, std::size_t _Rows, std::size_t _Cols>
22struct StaticMatrix : public std::array<std::array<_Scalar, _Cols>, _Rows>
23{
25 static constexpr std::size_t Rows = _Rows;
27 static constexpr std::size_t Cols = _Cols;
28
29 using std::array<std::array<_Scalar, _Cols>, _Rows>::operator[];
30
34 constexpr StaticMatrix() : std::array<std::array<_Scalar, _Cols>, _Rows>{}
35 {
36 for (auto i = 0u; i != _Rows; ++i) { operator[](i).fill(_Scalar(0)); }
37 }
38
42 template<std::size_t _NRows, std::size_t _NCols>
43 constexpr StaticMatrix<_Scalar, _NRows, _NCols> block(std::size_t row0, std::size_t col0) const
44 {
46 for (auto i = 0u; i < _NRows; ++i) {
47 for (auto j = 0u; j < _NCols; ++j) { ret[i][j] = operator[](row0 + i)[col0 + j]; }
48 }
49 return ret;
50 }
51
56 {
58 for (auto i = 0u; i < _Rows; ++i) {
59 for (auto j = 0u; j < _Cols; ++j) { ret[i][j] = operator[](i)[j] + o[i][j]; }
60 }
61 return ret;
62 }
63
68 {
70 for (auto i = 0u; i < _Rows; ++i) {
71 for (auto j = 0u; j < _Cols; ++j) { ret[j][i] = operator[](i)[j]; }
72 }
73 return ret;
74 }
75
79 template<std::size_t _NCols>
81 {
83 for (auto i = 0u; i < _Rows; ++i) {
84 for (auto j = 0u; j < _NCols; ++j) {
85 for (auto k = 0u; k < _Cols; ++k) { ret[i][j] += operator[](i)[k] * o[k][j]; }
86 }
87 }
88 return ret;
89 }
90};
91
92SMOOTH_END_NAMESPACE
Elementary structure for compile-time matrix algebra.
constexpr StaticMatrix< _Scalar, _NRows, _NCols > block(std::size_t row0, std::size_t col0) const
Extract sub-block of size _NRows x _NCols anchored at (row0, col0)
constexpr StaticMatrix()
Construct matrix filled with zeros.
constexpr StaticMatrix< _Scalar, _Rows, _Cols > operator+(const StaticMatrix< _Scalar, _Rows, _Cols > &o) const
Matrix addition.
constexpr StaticMatrix< _Scalar, _Rows, _Cols > transpose() const
Matrix transpose.
static constexpr std::size_t Cols
Number of columns in matrix.
constexpr StaticMatrix< _Scalar, _Rows, _NCols > operator*(const StaticMatrix< _Scalar, _Cols, _NCols > &o) const
Matrix multiplication.
static constexpr std::size_t Rows
Number of rows in matrix.