ARTS 2.5.4 (git: 31ce4f0e)
matpack_concepts.h
Go to the documentation of this file.
1#pragma once
2
3#include <complex>
4#include <concepts>
5#include <type_traits>
6
7namespace matpack {
8template <typename T>
9concept has_nelem = requires(T a) {
10 { a.nelem() } -> std::integral;
11};
12
13template <typename T>
14concept has_ncols = requires(T a) {
15 { a.ncols() } -> std::integral;
16};
17
18template <typename T>
19concept has_nrows = requires(T a) {
20 { a.nrows() } -> std::integral;
21};
22
23template <typename T>
24concept has_npages = requires(T a) {
25 { a.npages() } -> std::integral;
26};
27
28template <typename T>
29concept has_nbooks = requires(T a) {
30 { a.nbooks() } -> std::integral;
31};
32
33template <typename T>
34concept has_nshelves = requires(T a) {
35 { a.nshelves() } -> std::integral;
36};
37
38template <typename T>
39concept has_nvitrines = requires(T a) {
40 { a.nvitrines() } -> std::integral;
41};
42
43template <typename T>
44concept has_nlibraries = requires(T a) {
45 { a.nlibraries() } -> std::integral;
46};
47
49namespace external_class {
51template <typename T>
52concept has_cols = requires(T a) {
53 { a.cols() } -> std::integral;
54};
55
57template <typename T>
58concept has_rows = requires(T a) {
59 { a.rows() } -> std::integral;
60};
61} // namespace external_class
62
64template <typename T> concept column_keeper = has_ncols<T> or external_class::has_cols<T>;
65
67template <typename T> concept row_keeper = has_nrows<T> or external_class::has_rows<T>;
68
70constexpr auto column_size(column_keeper auto&& x) {
71 using internal_type = decltype(x);
72 if constexpr (external_class::has_cols<internal_type>) return x.cols();
73 else return x.ncols();
74}
75
77constexpr auto row_size(row_keeper auto&& x) {
78 using internal_type = decltype(x);
79 if constexpr (external_class::has_rows<internal_type>) return x.rows();
80 else return x.nrows();
81}
82
84template <typename T>
85struct is_complex : std::false_type {};
86
88template <std::floating_point T>
89struct is_complex<std::complex<T>> : std::true_type {};
90
92template <typename T>
94 std::floating_point<std::remove_cvref_t<T>> or
95 is_complex<std::remove_cvref_t<T>>::value;
96
98template <typename T>
99concept vector_like = requires(T a) {
100 { a.size() } -> std::integral;
101 { a[0] } -> complex_or_real;
102};
103
105template <typename T>
106concept vector = vector_like<T> and requires(T a) {
107 { a.nelem() } -> std::integral;
108 { a.delem() } -> std::integral;
109 { a.selem() } -> std::integral;
110 { *a.get_c_array() } -> complex_or_real;
111};
112
114template <typename T>
115concept matrix_like = requires(T a) {
116 { column_size(a) } -> std::integral;
117 { row_size(a) } -> std::integral;
118 { a.size() } -> std::integral;
119 { a(0, 0) } -> complex_or_real;
120};
121
123template <typename T>
124concept matrix = matrix_like<T> and has_ncols<T> and has_nrows<T> and requires(T a) {
125 { a.drows() } -> std::integral;
126 { a.dcols() } -> std::integral;
127 { a.selem() } -> std::integral;
128 { *a.get_c_array() } -> complex_or_real;
129};
130} // namespace matpack
Checks if the type has any accepted types of columns.
A concept to state if the type is a floating point or a floating point complex.
Eigen uses cols() for column index.
Eigen uses rows() for column index.
A concept for an Arts matrix-like type with access operations.
A concept for any of the Arts matrix types.
Checks if the type has any accepted types of rows.
A concept for an Arts vector-like type with access operations.
A concept for any of the Arts vector types.
VectorView std(VectorView std, const Vector &y, const ArrayOfVector &ys, const Index start, const Index end_tmp)
Compute the standard deviation of the ranged ys.
Definition: raw.cc:205
constexpr auto column_size(column_keeper auto &&x)
Get a column size from x.
constexpr auto row_size(row_keeper auto &&x)
Get a row size from x.
A concept overload to remove non std::complex<> from list.
#define a