Stratax 0.4.0rc1
Loading...
Searching...
No Matches
Concepts.hpp
Go to the documentation of this file.
1
4#pragma once
5
6#include <concepts>
7#include <cstddef>
8#include <complex>
9#include <iterator>
10#include <type_traits>
11
13
14namespace stratax::core::concept_detail {
15
17template<typename T, typename... Candidates>
18concept SameAsAny =
19 (std::same_as<std::remove_cvref_t<T>, Candidates> || ...);
20
22template<typename T>
23concept BoolLike =
24 std::same_as<std::remove_cvref_t<T>, stratax::dtype::bool_>;
25
27template<typename T>
30 T,
39
41template<typename T>
44 T,
48
50template<typename T>
53 T,
57
58}
59
61template<typename T>
62concept Integral =
64
66template<typename T>
67concept Numeric =
71
73template<typename T>
74concept DType =
75 Numeric<T> ||
77
78namespace stratax::container {
79
81template<typename T>
82requires DType<T>
83class Vector;
84
86template<typename T>
87requires DType<T>
88class Matrix;
89
91template<typename T>
92requires DType<T>
93class Tensor;
94
95} // namespace stratax::container
96
105template<typename T>
106struct is_array : std::false_type {};
107
109template<typename T>
110requires DType<T>
111struct is_array<stratax::container::Vector<T>> : std::true_type {};
112
114template<typename T>
115requires DType<T>
116struct is_array<stratax::container::Matrix<T>> : std::true_type {};
117
119template<typename T>
120requires DType<T>
121struct is_array<stratax::container::Tensor<T>> : std::true_type {};
122
133template<typename T>
134concept Array =
135 requires (
136 const std::remove_cvref_t<T>& array,
137 std::size_t index)
138 {
139 typename std::remove_cvref_t<T>::value_type;
141 { array.size() } -> std::convertible_to<std::size_t>;
142 { array.empty() } -> std::convertible_to<bool>;
143 { array.rank() } -> std::convertible_to<std::size_t>;
144 array.shape();
145 array.strides();
146 { array[index] } -> std::convertible_to<
147 typename std::remove_cvref_t<T>::value_type>;
148 { array.begin() } -> std::input_iterator;
149 { array.end() } -> std::sentinel_for<decltype(array.begin())>;
150 };
151
153template<typename T>
154concept Ordered =
155 DType<T> &&
157
159template<typename T>
160concept RealNumeric =
161 Integral<T> ||
162 std::floating_point<std::remove_cvref_t<T>>;
Supported scalar dtype aliases.
std::int32_t int32
Signed 32-bit integer dtype.
Definition Types.hpp:31
std::uint8_t uint8
Unsigned 8-bit integer dtype.
Definition Types.hpp:36
std::uint16_t uint16
Unsigned 16-bit integer dtype.
Definition Types.hpp:38
std::complex< long double > clongdouble
Complex dtype with native long double components.
Definition Types.hpp:56
double float64
Native double dtype.
Definition Types.hpp:47
float float32
Native float dtype.
Definition Types.hpp:45
std::complex< double > complex128
Complex dtype with native double components.
Definition Types.hpp:54
std::int8_t int8
Signed 8-bit integer dtype.
Definition Types.hpp:27
std::int16_t int16
Signed 16-bit integer dtype.
Definition Types.hpp:29
long double longdouble
Native long double dtype; precision is platform-dependent.
Definition Types.hpp:49
std::uint64_t uint64
Unsigned 64-bit integer dtype.
Definition Types.hpp:42
bool bool_
Boolean dtype.
Definition Types.hpp:24
std::int64_t int64
Signed 64-bit integer dtype.
Definition Types.hpp:33
std::complex< float > complex64
Complex dtype with native float components.
Definition Types.hpp:52
std::uint32_t uint32
Unsigned 32-bit integer dtype.
Definition Types.hpp:40
Identifies array-like types through their common logical interface.
Definition Concepts.hpp:134
Supported numeric or boolean element dtype.
Definition Concepts.hpp:74
Supported integer dtype, excluding bool.
Definition Concepts.hpp:62
Supported integer, floating-point, or complex dtype, excluding bool.
Definition Concepts.hpp:67
Supported non-complex dtype, including bool; floating-point NaNs need not compare ordered.
Definition Concepts.hpp:154
Supported integer or standard floating-point type, excluding bool and complex.
Definition Concepts.hpp:160
Matches the boolean dtype after removing cv/ref qualifiers.
Definition Concepts.hpp:23
Matches any candidate after removing cv/ref qualifiers.
Definition Concepts.hpp:18
Matches a supported std::complex dtype after removing cv/ref qualifiers.
Definition Concepts.hpp:51
Matches float, double, or long double after removing cv/ref qualifiers.
Definition Concepts.hpp:42
Matches a supported fixed-width integer dtype, excluding bool.
Definition Concepts.hpp:28
Trait identifying supported Stratax owning array specializations.
Definition Concepts.hpp:106