Stratax 0.4.0rc1
Loading...
Searching...
No Matches
DTypeTraits.hpp
Go to the documentation of this file.
1
4#pragma once
5
6#include <climits>
7#include <cstddef>
8#include <limits>
9#include <string_view>
10#include <type_traits>
11
13
14namespace stratax::core {
15
19enum class DTypeKind
20{
21 Bool,
22 SignedInteger,
23 UnsignedInteger,
24 Floating,
25 Complex
26};
27
28namespace dtype_detail {
29
36template<typename T>
38
42#define STRATAX_DEFINE_DTYPE_TRAITS(TYPE, KIND, NAME) \
43 \
44 template<> \
45 struct DTypeTraitsImpl<TYPE> \
46 { \
47 using type = TYPE; \
48 static constexpr DTypeKind kind = DTypeKind::KIND; \
49 static constexpr std::size_t bits = sizeof(type) * CHAR_BIT; \
50 static constexpr int digits = std::numeric_limits<type>::digits; \
51 static constexpr std::string_view name = NAME; \
52 }
53
57#define STRATAX_DEFINE_FLOAT_DTYPE_TRAITS(TYPE, RANK, NAME) \
58 \
59 template<> \
60 struct DTypeTraitsImpl<TYPE> \
61 { \
62 using type = TYPE; \
63 static constexpr DTypeKind kind = DTypeKind::Floating; \
64 static constexpr std::size_t bits = sizeof(type) * CHAR_BIT; \
65 static constexpr int digits = std::numeric_limits<type>::digits; \
66 static constexpr std::size_t rank = RANK; \
67 static constexpr std::string_view name = NAME; \
68 }
69
76#define STRATAX_DEFINE_COMPLEX_DTYPE_TRAITS(TYPE, COMPONENT, RANK, NAME) \
77 \
78 template<> \
79 struct DTypeTraitsImpl<TYPE> \
80 { \
81 using type = TYPE; \
82 using component_type = COMPONENT; \
83 static constexpr DTypeKind kind = DTypeKind::Complex; \
84 static constexpr std::size_t bits = sizeof(type) * CHAR_BIT; \
85 static constexpr int digits = std::numeric_limits<component_type>::digits; \
86 static constexpr std::size_t rank = RANK; \
87 static constexpr std::string_view name = NAME; \
88 }
89
91
96
97STRATAX_DEFINE_DTYPE_TRAITS(dtype::uint8, UnsignedInteger, "uint8");
98STRATAX_DEFINE_DTYPE_TRAITS(dtype::uint16, UnsignedInteger, "uint16");
99STRATAX_DEFINE_DTYPE_TRAITS(dtype::uint32, UnsignedInteger, "uint32");
100STRATAX_DEFINE_DTYPE_TRAITS(dtype::uint64, UnsignedInteger, "uint64");
101
105
109
110#undef STRATAX_DEFINE_DTYPE_TRAITS
111#undef STRATAX_DEFINE_FLOAT_DTYPE_TRAITS
112#undef STRATAX_DEFINE_COMPLEX_DTYPE_TRAITS
113
114} // namespace dtype_detail
115
123template<typename T>
125 : dtype_detail::DTypeTraitsImpl<std::remove_cvref_t<T>>
126{};
127
131template<typename T>
133
135#define STRATAX_DEFINE_COMPLEX_COMPONENT(COMPLEX, REAL) \
136 \
137 template<> \
138 struct ComplexComponent<COMPLEX> \
139 { \
140 using type = REAL; \
141 }
142
146
147#undef STRATAX_DEFINE_COMPLEX_COMPONENT
148
152template<typename T>
155
159template<typename T>
161
163#define STRATAX_DEFINE_COMPLEX_FROM_REAL(REAL, COMPLEX) \
164 \
165 template<> \
166 struct ComplexFromReal<REAL> \
167 { \
168 using type = COMPLEX; \
169 }
170
174
175#undef STRATAX_DEFINE_COMPLEX_FROM_REAL
176
180template<typename T>
183
184} // namespace stratax::core
typename ComplexComponent< std::remove_cvref_t< T > >::type complex_component_t
Underlying real dtype of a complex dtype.
#define STRATAX_DEFINE_FLOAT_DTYPE_TRAITS(TYPE, RANK, NAME)
Defines metadata for a ranked floating-point Stratax dtype.
#define STRATAX_DEFINE_DTYPE_TRAITS(TYPE, KIND, NAME)
Defines metadata for a non-complex Stratax dtype.
DTypeKind
Identifies the general category of a Stratax dtype.
#define STRATAX_DEFINE_COMPLEX_FROM_REAL(REAL, COMPLEX)
Defines a real-to-complex dtype specialization.
#define STRATAX_DEFINE_COMPLEX_DTYPE_TRAITS(TYPE, COMPONENT, RANK, NAME)
Defines metadata for a complex Stratax dtype.
#define STRATAX_DEFINE_COMPLEX_COMPONENT(COMPLEX, REAL)
Defines a complex-to-real component specialization.
typename ComplexFromReal< std::remove_cvref_t< T > >::type complex_from_real_t
Complex dtype corresponding to a real floating-point dtype.
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
Maps a complex dtype to its underlying real component dtype.
Maps a real floating-point dtype to its corresponding complex dtype.
Provides compile-time metadata for a supported Stratax dtype.
Implementation registry for supported Stratax dtypes.