16#define MKL_Complex8 std::complex<float>
17#define MKL_Complex16 std::complex<double>
36 using vec3d = std::vector<std::vector<std::vector<T>>>;
39 using vec2d = std::vector<std::vector<T>>;
41 typedef double cytnx_double;
42 typedef float cytnx_float;
43 typedef uint64_t cytnx_uint64;
44 typedef uint32_t cytnx_uint32;
45 typedef uint16_t cytnx_uint16;
46 typedef int64_t cytnx_int64;
47 typedef int32_t cytnx_int32;
48 typedef int16_t cytnx_int16;
49 typedef std::size_t cytnx_size_t;
50 typedef std::complex<float> cytnx_complex64;
51 typedef std::complex<double> cytnx_complex128;
52 typedef bool cytnx_bool;
56 struct is_complex_impl : std::false_type {};
59 struct is_complex_impl<std::complex<T>> : std::true_type {};
62 struct is_complex_floating_point_impl : std::false_type {};
65 struct is_complex_floating_point_impl<std::complex<T>> : std::is_floating_point<T> {};
67 template <std::
size_t I,
typename T,
typename Tuple>
68 constexpr std::size_t index_in_tuple_helper() {
69 static_assert(I < std::tuple_size_v<Tuple>,
"Type not found!");
70 if constexpr (std::is_same_v<T, std::tuple_element_t<I, Tuple>>) {
73 return index_in_tuple_helper<I + 1, T, Tuple>();
81 template <
typename V,
template <
typename>
class Transform>
82 struct make_variant_from_transform;
84 template <
template <
typename>
class Transform,
typename... Args>
85 struct make_variant_from_transform<std::variant<Args...>, Transform> {
86 using type = std::variant<typename Transform<Args>::type...>;
90 template <
typename V,
template <
typename>
class Transform>
91 using make_variant_from_transform_t =
typename make_variant_from_transform<V, Transform>::type;
94 using is_complex = internal::is_complex_impl<std::remove_cv_t<T>>;
97 using is_complex_floating_point = internal::is_complex_floating_point_impl<std::remove_cv_t<T>>;
101 template <
typename T>
102 constexpr bool is_complex_v = is_complex<T>::value;
106 template <
typename T>
107 constexpr bool is_complex_floating_point_v = is_complex_floating_point<T>::value;
111 template <
typename T,
typename Variant>
112 struct variant_index;
114 template <
typename T,
typename... Types>
115 struct variant_index<T, std::variant<Types...>> {
116 static constexpr std::size_t value = std::variant_size_v<std::variant<Types...>>;
119 template <
typename T,
typename... Types>
120 struct variant_index<T, std::variant<T, Types...>> {
121 static constexpr std::size_t value = 0;
124 template <
typename T,
typename U,
typename... Types>
125 struct variant_index<T, std::variant<U, Types...>> {
126 static constexpr std::size_t value = 1 + variant_index<T, std::variant<Types...>>::value;
130 template <
typename T,
typename Variant>
131 static constexpr std::size_t variant_index_v = variant_index<T, Variant>::value;
136 template <
typename T>
137 inline constexpr int type_size =
sizeof(T);
139 inline constexpr int type_size<void> = 0;
147 std::variant<void, cytnx_complex128, cytnx_complex64, cytnx_double, cytnx_float, cytnx_int64,
148 cytnx_uint64, cytnx_int32, cytnx_uint32, cytnx_int16, cytnx_uint16, cytnx_bool>;
152 using Type_list_gpu =
153 std::variant<void, cuDoubleComplex, cuComplex, cytnx_double, cytnx_float, cytnx_int64,
154 cytnx_uint64, cytnx_int32, cytnx_uint32, cytnx_int16, cytnx_uint16, cytnx_bool>;
158 constexpr int N_Type = std::variant_size_v<Type_list>;
159 constexpr int N_fType = 5;
162 template <
typename T>
163 inline constexpr char* Type_names =
nullptr;
165 inline constexpr const char* Type_names<void> =
"Void";
167 inline constexpr const char* Type_names<cytnx_complex128> =
"Complex Double (Complex Float64)";
169 inline constexpr const char* Type_names<cytnx_complex64> =
"Complex Float (Complex Float32)";
171 inline constexpr const char* Type_names<cytnx_double> =
"Double (Float64)";
173 inline constexpr const char* Type_names<cytnx_float> =
"Float (Float32)";
175 inline constexpr const char* Type_names<cytnx_int64> =
"Int64";
177 inline constexpr const char* Type_names<cytnx_uint64> =
"Uint64";
179 inline constexpr const char* Type_names<cytnx_int32> =
"Int32";
181 inline constexpr const char* Type_names<cytnx_uint32> =
"Uint32";
183 inline constexpr const char* Type_names<cytnx_int16> =
"Int16";
185 inline constexpr const char* Type_names<cytnx_uint16> =
"Uint16";
187 inline constexpr const char* Type_names<cytnx_bool> =
"Bool";
190 template <
typename T>
191 inline constexpr char* Type_enum_name =
nullptr;
193 inline constexpr const char* Type_enum_name<void> =
"Void";
195 inline constexpr const char* Type_enum_name<cytnx_complex128> =
"ComplexDouble";
197 inline constexpr const char* Type_enum_name<cytnx_complex64> =
"ComplexFloat";
199 inline constexpr const char* Type_enum_name<cytnx_double> =
"Double";
201 inline constexpr const char* Type_enum_name<cytnx_float> =
"Float";
203 inline constexpr const char* Type_enum_name<cytnx_int64> =
"Int64";
205 inline constexpr const char* Type_enum_name<cytnx_uint64> =
"Uint64";
207 inline constexpr const char* Type_enum_name<cytnx_int32> =
"Int32";
209 inline constexpr const char* Type_enum_name<cytnx_uint32> =
"Uint32";
211 inline constexpr const char* Type_enum_name<cytnx_int16> =
"Int16";
213 inline constexpr const char* Type_enum_name<cytnx_uint16> =
"Uint16";
215 inline constexpr const char* Type_enum_name<cytnx_bool> =
"Bool";
219 const char* enum_name;
224 unsigned int typeSize;
227 template <
typename T>
228 struct Type_struct_t {
229 static constexpr unsigned int cy_typeid = variant_index_v<T, Type_list>;
231 static constexpr unsigned int cy_typeid_gpu = variant_index_v<T, Type_list_gpu>;
233 static constexpr const char* name = Type_names<T>;
234 static constexpr const char* enum_name = Type_enum_name<T>;
235 static constexpr bool is_complex = is_complex_v<T>;
236 static constexpr bool is_unsigned = std::is_unsigned_v<T>;
237 static constexpr bool is_float = std::is_floating_point_v<T> || is_complex_floating_point_v<T>;
238 static constexpr bool is_int = std::is_integral_v<T> && !std::is_same_v<T, bool>;
239 static constexpr std::size_t typeSize = internal::type_size<T>;
241 static constexpr Type_struct construct() {
242 return {name, enum_name, is_unsigned, is_complex, is_float, is_int, typeSize};
247 template <
typename Variant, std::size_t... Indices>
248 constexpr auto make_type_array_helper(std::index_sequence<Indices...>) {
249 return std::array<Type_struct,
sizeof...(Indices)>{
250 Type_struct_t<std::variant_alternative_t<Indices, Variant>>::construct()...};
252 template <
typename Variant>
253 constexpr auto make_type_array() {
254 return make_type_array_helper<Variant>(
255 std::make_index_sequence<std::variant_size_v<Variant>>());
263 static constexpr auto Typeinfos = internal::make_type_array<Type_list>();
265 template <
typename T>
266 static constexpr unsigned int cy_typeid_v = variant_index_v<T, Type_list>;
269 template <
typename T>
270 static constexpr unsigned int cy_typeid_gpu_v = variant_index_v<T, Type_list_gpu>;
273 enum Type :
unsigned int {
274 Void = cy_typeid_v<void>,
275 ComplexDouble = cy_typeid_v<cytnx_complex128>,
276 ComplexFloat = cy_typeid_v<cytnx_complex64>,
277 Double = cy_typeid_v<cytnx_double>,
278 Float = cy_typeid_v<cytnx_float>,
279 Int64 = cy_typeid_v<cytnx_int64>,
280 Uint64 = cy_typeid_v<cytnx_uint64>,
281 Int32 = cy_typeid_v<cytnx_int32>,
282 Uint32 = cy_typeid_v<cytnx_uint32>,
283 Int16 = cy_typeid_v<cytnx_int16>,
284 Uint16 = cy_typeid_v<cytnx_uint16>,
285 Bool = cy_typeid_v<cytnx_bool>
288 static constexpr void check_type(
unsigned int type_id) {
289 cytnx_error_msg(type_id >= N_Type,
"[ERROR] invalid type_id: %s", type_id);
294 static std::string getname(
unsigned int type_id) {
296 return Typeinfos[type_id].name;
300 static unsigned int c_typename_to_id(
const std::string& c_name);
301 static char const* enum_name(
unsigned int type_id) {
303 return Typeinfos[type_id].enum_name;
305 static constexpr unsigned int typeSize(
unsigned int type_id) {
307 return Typeinfos[type_id].typeSize;
309 static constexpr bool is_unsigned(
unsigned int type_id) {
311 return Typeinfos[type_id].is_unsigned;
313 static constexpr bool is_complex(
unsigned int type_id) {
315 return Typeinfos[type_id].is_complex;
317 static constexpr bool is_float(
unsigned int type_id) {
319 return Typeinfos[type_id].is_float;
321 static constexpr bool is_int(
unsigned int type_id) {
323 return Typeinfos[type_id].is_int;
327 static constexpr unsigned int cy_typeid(
const T& rc) {
328 return cy_typeid_v<T>;
332 static constexpr unsigned int type_promote(
unsigned int typeL,
unsigned int typeR) {
334 if (typeL == 0)
return 0;
336 if (!is_unsigned(typeR) && is_unsigned(typeL)) {
342 if (typeR == 0)
return 0;
343 if (!is_unsigned(typeL) && is_unsigned(typeR)) {
352 template <
typename TL,
typename TR>
353 using type_promote_t =
354 std::variant_alternative_t<Type_class::type_promote(variant_index_v<TL, Type_list>,
355 variant_index_v<TR, Type_list>),
359 template <
typename TL,
typename TR>
360 struct type_promote_from_pointer {
364 template <
typename TL,
typename TR>
365 struct type_promote_from_pointer<TL*, TR*> {
366 using type = type_promote_t<std::decay_t<TL>, std::decay_t<TR>>;
370 template <
typename TL,
typename TR>
371 using type_promote_from_pointer_t =
typename type_promote_from_pointer<TL, TR>::type;
375 template <
typename TL,
typename TR>
376 using type_promote_gpu_t =
377 std::variant_alternative_t<Type_class::type_promote(variant_index_v<TL, Type_list_gpu>,
378 variant_index_v<TR, Type_list_gpu>),
381 template <
typename TL,
typename TR>
382 struct type_promote_from_gpu_pointer {
386 template <
typename TL,
typename TR>
387 struct type_promote_from_gpu_pointer<TL*, TR*> {
388 using type = type_promote_gpu_t<std::decay_t<TL>, std::decay_t<TR>>;
392 template <
typename TL,
typename TR>
393 using type_promote_from_gpu_pointer_t =
typename type_promote_from_gpu_pointer<TL, TR>::type;
int32_t blas_int
Definition Type.hpp:27
constexpr Type_class Type
data type
Definition Type.hpp:426
#define cytnx_error_msg(is_true, format,...)
Definition cytnx_error.hpp:27
Definition Accessor.hpp:12
@ U
Definition Symmetry.hpp:32