akreon-linalg
Fixed-size linear algebra and numerical methods in C++26.
Loading...
Searching...
No Matches
coordinate_map.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 <concepts>
9
10#include "space_traits.hpp"
11
12namespace linalg {
13
22template <class Space>
24
31template <Field T, std::size_t Rows, std::size_t Cols>
32 requires(Rows == 1 || Cols == 1)
34 static constexpr auto to_coordinates(const Vector<T, Rows * Cols>& element) {
35 return element;
36 }
37
38 static constexpr auto from_coordinates(
40 return coordinate;
41 }
42};
43
50template <Field T, std::size_t Rows, std::size_t Cols>
51 requires(Rows > 1 && Cols > 1)
52struct coordinate_map<Matrix<T, Rows, Cols>> {
53 static constexpr auto to_coordinates(const Matrix<T, Rows, Cols>& element) {
55 for (std::size_t row = 0; row < Rows; ++row)
56 for (std::size_t col = 0; col < Cols; ++col)
57 coordinate(row * Cols + col) = element(row, col);
58 return coordinate;
59 }
60
61 static constexpr auto from_coordinates(
64 for (std::size_t row = 0; row < Rows; ++row)
65 for (std::size_t col = 0; col < Cols; ++col)
66 element(row, col) = coordinate(row * Cols + col);
67 return element;
68 }
69};
70
72template <class Space>
74
80template <class Space>
84
90template <class Space>
94
95} // namespace linalg
typename space_traits< remove_cvref_t< Space > >::element_type space_element_t
Canonical element representation registered for a space.
constexpr auto coordinates(const space_element_t< Space > &element)
Convert a registered space element to its coordinate representation.
constexpr std::size_t mat_rows_v
Registered compile-time row count after cv/ref normalization.
typename space_traits< remove_cvref_t< Space > >::coordinate_type space_coordinate_t
Finite coordinate representation registered for a space.
constexpr auto from_coordinates(const space_coordinate_t< Space > &coordinate)
Reconstruct a registered space element from its coordinates.
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 to_coordinates(const Matrix< T, Rows, Cols > &element)
static constexpr auto from_coordinates(const Vector< T, Rows *Cols > &coordinate)
static constexpr auto to_coordinates(const Vector< T, Rows *Cols > &element)
Customization point mapping space elements to finite coordinates.