akreon-linalg
Fixed-size linear algebra and numerical methods in C++26.
Loading...
Searching...
No Matches
matrix_traits.hpp
Go to the documentation of this file.
1/*
2 * Copyright © 2025-2026 Akreon LLC
3 * SPDX-License-Identifier: Apache-2.0
4 */
5
6#pragma once
7
8#include <complex>
9#include <cstddef>
10#include <utility>
11
12#include "matrix.hpp"
13
14namespace linalg {
15
17template <typename T, std::size_t Dim>
19
21template <typename T, std::size_t Dim>
23
35template <class Mat>
37
46template <typename T, std::size_t Rows, std::size_t Cols>
47struct mat_traits<Matrix<T, Rows, Cols>> {
49 using value_type = T;
51 static constexpr std::size_t ROWS = Rows;
53 static constexpr std::size_t COLS = Cols;
54
60 template <typename... Ts>
61 static constexpr auto operator()(Ts&&... xs) {
62 static_assert(sizeof...(xs) == Rows * Cols,
63 "mat_traits::operator() requires Rows*Cols coordinates");
65 std::size_t i = 0;
66 auto set_element = [&](const T& x) {
67 const auto col = i % Cols;
68 const auto row = i / Cols;
69 matrix(row, col) = x;
70 ++i;
71 };
72 ((void)set_element(std::forward<Ts>(xs)), ...);
73 return matrix;
74 }
75
77 static constexpr auto fill(const T& x) {
79 for (std::size_t i = 0; i < Rows; ++i)
80 for (std::size_t j = 0; j < Cols; ++j) matrix(i, j) = x;
81 return matrix;
82 }
83};
84
86template <class Mat>
87using matrix_scalar_t = typename mat_traits<remove_cvref_t<Mat>>::value_type;
88
90template <class Mat>
91inline constexpr std::size_t mat_rows_v = mat_traits<remove_cvref_t<Mat>>::ROWS;
92
94template <class Mat>
95inline constexpr std::size_t mat_cols_v = mat_traits<remove_cvref_t<Mat>>::COLS;
96
104template <std::size_t Dim>
106
107template <std::size_t Dim>
109
110template <std::size_t Dim>
112
113template <std::size_t Dim>
115
116template <std::size_t Rows, std::size_t Cols>
118
119template <std::size_t Dim>
121
122template <std::size_t Dim>
124
125template <std::size_t Rows, std::size_t Cols>
127
128template <std::size_t Dim>
130
131template <std::size_t Dim>
133
134template <std::size_t Rows, std::size_t Cols>
136
137template <std::size_t Dim>
139
140template <std::size_t Dim>
142
143template <std::size_t Rows, std::size_t Cols>
145
146template <std::size_t Dim>
148
149template <std::size_t Dim>
153} // namespace linalg
constexpr std::size_t mat_rows_v
Registered compile-time row count after cv/ref normalization.
constexpr std::size_t mat_cols_v
Registered compile-time column count after cv/ref normalization.
typename mat_traits< remove_cvref_t< Mat > >::value_type matrix_scalar_t
Registered matrix scalar type after cv/ref normalization.
Owning, fixed-size, row-major matrix container over a scalar field.
Definition matrix.hpp:44
Owning, fixed-size vector container.
Definition vector.hpp:36
static constexpr auto operator()(Ts &&... xs)
Construct a matrix from Rows * Cols row-major coordinates.
T value_type
Scalar field stored by the matrix.
static constexpr auto fill(const T &x)
Construct a matrix whose elements are all equal to x.
Customization point for compile-time matrix metadata.