Stratax 0.3.1
Loading...
Searching...
No Matches
Concepts.hpp
1#pragma once
2
3#include <concepts>
4#include <cstddef>
5#include <complex>
6#include <iterator>
7#include <type_traits>
8
9#include <stratax/core/dtypes/Types.hpp>
10
11namespace stratax::core::concept_detail {
12
13template<typename T, typename... Candidates>
14concept SameAsAny =
15 (std::same_as<std::remove_cvref_t<T>, Candidates> || ...);
16
17template<typename T>
18concept BoolLike =
19 std::same_as<std::remove_cvref_t<T>, stratax::dtype::bool_>;
20
21template<typename T>
24 T,
25 stratax::dtype::int8,
26 stratax::dtype::int16,
27 stratax::dtype::int32,
28 stratax::dtype::int64,
29 stratax::dtype::uint8,
30 stratax::dtype::uint16,
31 stratax::dtype::uint32,
32 stratax::dtype::uint64>;
33
34template<typename T>
37 T,
38 stratax::dtype::float32,
39 stratax::dtype::float64,
40 stratax::dtype::longdouble>;
41
42template<typename T>
45 T,
46 stratax::dtype::complex64,
47 stratax::dtype::complex128,
48 stratax::dtype::clongdouble>;
49
50}
51
52template<typename T>
53concept Integral =
55
56template<typename T>
57concept Numeric =
61
62template<typename T>
63concept DType =
64 Numeric<T> ||
66
67namespace stratax::container {
68
70template<typename T>
71requires DType<T>
72class Vector;
73
75template<typename T>
76requires DType<T>
77class Matrix;
78
80template<typename T>
81requires DType<T>
82class Tensor;
83
84} // namespace stratax::container
85
94template<typename T>
95struct is_array : std::false_type {};
96
98template<typename T>
99requires DType<T>
100struct is_array<stratax::container::Vector<T>> : std::true_type {};
101
103template<typename T>
104requires DType<T>
105struct is_array<stratax::container::Matrix<T>> : std::true_type {};
106
108template<typename T>
109requires DType<T>
110struct is_array<stratax::container::Tensor<T>> : std::true_type {};
111
122template<typename T>
123concept Array =
124 requires (
125 const std::remove_cvref_t<T>& array,
126 std::size_t index)
127 {
128 typename std::remove_cvref_t<T>::value_type;
130 { array.size() } -> std::convertible_to<std::size_t>;
131 { array.empty() } -> std::convertible_to<bool>;
132 { array.rank() } -> std::convertible_to<std::size_t>;
133 array.shape();
134 array.strides();
135 { array[index] } -> std::convertible_to<
136 typename std::remove_cvref_t<T>::value_type>;
137 { array.begin() } -> std::input_iterator;
138 { array.end() } -> std::sentinel_for<decltype(array.begin())>;
139 };
140
141template<typename T>
142concept Ordered =
143 DType<T> &&
145
146template<typename T>
147concept RealNumeric =
148 Integral<T> ||
149 std::floating_point<std::remove_cvref_t<T>>;
Identifies array-like types through their common logical interface.
Definition Concepts.hpp:123
Trait identifying supported Stratax owning array specializations.
Definition Concepts.hpp:95