numerics 0.1.0
Loading...
Searching...
No Matches
concepts.hpp
Go to the documentation of this file.
1/// @file core/concepts.hpp
2/// @brief Storage concepts for numerical routines.
3#pragma once
4
5#include "core/types.hpp"
6#include <concepts>
7
8namespace num {
9
10/// @brief Indexed real-valued vector interface.
11template<class V>
12concept VectorLike = requires(V v, const V cv, idx i) {
13 { cv.size() } -> std::convertible_to<idx>;
14 { cv[i] } -> std::convertible_to<real>;
15 { v[i] } -> std::convertible_to<real>;
16};
17
18/// @brief Mutable indexed real-valued vector interface.
19template<class V>
20concept MutableVectorLike = VectorLike<V> && requires(V v, idx i, real a) {
21 { v[i] = a } -> std::same_as<real&>;
22};
23
24/// @brief Contiguous real-valued vector storage.
25template<class V>
26concept ContiguousVectorLike = VectorLike<V> && requires(V v, const V cv) {
27 { cv.data() } -> std::convertible_to<const real*>;
28 { v.data() } -> std::convertible_to<real*>;
29};
30
31/// @brief Dense row-major real matrix interface.
32template<class A>
33concept DenseMatrixLike = requires(A a, const A ca, idx i, idx j) {
34 { ca.rows() } -> std::convertible_to<idx>;
35 { ca.cols() } -> std::convertible_to<idx>;
36 { ca(i, j) } -> std::convertible_to<real>;
37 { a(i, j) } -> std::convertible_to<real>;
38};
39
40/// @brief Mutable dense row-major real matrix interface.
41template<class A>
43 DenseMatrixLike<A> && requires(A a, idx i, idx j, real x) {
44 { a(i, j) = x } -> std::same_as<real&>;
45 };
46
47/// @brief Contiguous dense row-major real matrix storage.
48template<class A>
49concept ContiguousDenseMatrixLike = DenseMatrixLike<A> && requires(A a, const A ca) {
50 { ca.data() } -> std::convertible_to<const real*>;
51 { a.data() } -> std::convertible_to<real*>;
52};
53
54} // namespace num
Contiguous dense row-major real matrix storage.
Definition concepts.hpp:49
Contiguous real-valued vector storage.
Definition concepts.hpp:26
Dense row-major real matrix interface.
Definition concepts.hpp:33
Mutable dense row-major real matrix interface.
Definition concepts.hpp:42
Mutable indexed real-valued vector interface.
Definition concepts.hpp:20
Indexed real-valued vector interface.
Definition concepts.hpp:12
Core type definitions.
double real
Definition types.hpp:10
std::size_t idx
Definition types.hpp:11