Uni20
Asynchronous tensor and runtime library.
Loading...
Searching...
No Matches
types.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <uni20/config.hpp>
4#if UNI20_HAS_FLOAT128 && UNI20_FLOAT128_PROVIDER_MPLAPACK
5#include <mplapack_config.h>
6#endif
7#include <complex>
8#include <concepts>
9#include <limits>
10
11namespace uni20
12{
13
14// Fundamental types used throughout the library
15
18using size_type = std::ptrdiff_t;
19using index_type = std::ptrdiff_t;
20
21// Type aliases for explicit precision and complex values
22using float32 = float;
23using float64 = double;
24
25#if UNI20_HAS_MPREAL
26class mpreal;
27class mpcomplex;
28#endif
29
30namespace detail
31{
32// Preserve deduction where code specifically adapts the standard-library family.
33template <typename Real> using standard_complex = std::complex<Real>;
34template <typename Real> struct complex_type
35{
36 using type = standard_complex<Real>;
37};
38#if UNI20_HAS_MPREAL
39template <> struct complex_type<mpreal>
40{
41 using type = mpcomplex;
42};
43#endif
44} // namespace detail
45
46#if UNI20_HAS_FLOAT80
51using float80 = long double;
52static_assert(std::numeric_limits<float80>::is_iec559 && std::numeric_limits<float80>::radix == 2 &&
53 std::numeric_limits<float80>::digits == 64 && std::numeric_limits<float80>::min_exponent == -16381 &&
54 std::numeric_limits<float80>::max_exponent == 16384 &&
55 std::numeric_limits<float80>::denorm_min() > 0 &&
56 std::numeric_limits<float80>::denorm_min() < std::numeric_limits<float80>::min(),
57 "Uni20's configured fp80 format must match the consuming compiler's long double");
58#endif
59
66template <typename Real> using complex = typename detail::complex_type<Real>::type;
67
70#if UNI20_HAS_FLOAT80
72using complex160 = complex<float80>;
73#endif
74
77
78#if UNI20_HAS_FLOAT128 && UNI20_FLOAT128_PROVIDER_MPLAPACK
85using float128 = mplapack_binary128_t;
86
89using complex256 = complex<float128>;
90
91using cfloat128 = complex256;
92#endif
93
101template <typename R> struct remove_proxy_reference : std::remove_reference<R>
102{};
103
108template <typename R>
109constexpr bool is_proxy_reference_v =
110 !std::is_same_v<typename remove_proxy_reference<std::remove_cvref_t<R>>::type, std::remove_cvref_t<R>>;
111
116template <typename R>
118 std::conditional_t<is_proxy_reference_v<R>, typename remove_proxy_reference<std::remove_cvref_t<R>>::type,
119 std::remove_reference_t<R>>;
120
126template <typename Value> struct logical_value
127{
128 using type = std::remove_cvref_t<Value>;
129};
130
132template <typename Value> using logical_value_t = typename logical_value<std::remove_cvref_t<Value>>::type;
133
134} // namespace uni20
Exact rational complex value or owning finite-precision MPC approximation.
Definition mpcomplex.hpp:57
Owning exact rational or finite-precision MPFR real, with eager arithmetic.
Definition mpreal.hpp:74
typename detail::complex_type< Real >::type complex
Project-level complex scalar spelling.
Definition types.hpp:66
Definition async/async.hpp:26
float float32
Definition types.hpp:22
double float64
Definition types.hpp:23
complex< double > complex128
Definition types.hpp:69
constexpr bool is_proxy_reference_v
Detects whether a type is considered a proxy reference.
Definition types.hpp:109
std::ptrdiff_t size_type
Signed size and index type, used for tensor extents and indexing.
Definition types.hpp:18
std::conditional_t< is_proxy_reference_v< R >, typename remove_proxy_reference< std::remove_cvref_t< R > >::type, std::remove_reference_t< R > > remove_proxy_reference_t
Extracts the underlying value type of a proxy (or normal) reference.
Definition types.hpp:119
complex< float > complex64
Definition types.hpp:68
std::ptrdiff_t index_type
Definition types.hpp:19
typename logical_value< std::remove_cvref_t< Value > >::type logical_value_t
Backend-neutral logical value represented by an execution expression.
Definition types.hpp:132
complex< double > cdouble
Definition types.hpp:76
complex< float > cfloat
Definition types.hpp:75
Map an execution expression type to its backend-neutral logical value type.
Definition types.hpp:127
std::remove_cvref_t< Value > type
Definition types.hpp:128
Trait for extracting the element type from a proxy reference.
Definition types.hpp:102