Uni20
Asynchronous tensor and runtime library.
Loading...
Searching...
No Matches
Files | Concepts | Classes | Typedefs | Enumerations | Functions | Variables
Scalar helper utilities

Scalar helper utilities shared across Uni20 core algorithms. More...

Files

file  scalar_precision.hpp
 Runtime selection of configured Uni20 real scalar precisions.
 

Concepts

concept  uni20::Integer
 Concept for integer scalar types (excluding char and bool).
 
concept  uni20::Real
 Concept for real scalar types (float, double, etc.).
 
concept  uni20::Complex
 Concept for complex scalar types.
 
concept  uni20::Scalar
 Concept for numeric scalar types (integer, real, or complex).
 
concept  uni20::RealOrComplex
 Concept for types that are either real or complex.
 
concept  uni20::BlasReal
 Real scalar types supported by the configured raw-pointer BLAS wrappers.
 
concept  uni20::BlasComplex
 Complex scalar types supported by the configured raw-pointer BLAS wrappers.
 
concept  uni20::BlasScalar
 Scalar types supported by the configured raw-pointer BLAS wrappers.
 
concept  uni20::LapackReal
 Real scalar types supported by the configured raw-pointer LAPACK wrappers.
 
concept  uni20::LapackComplex
 Complex scalar types supported by the configured raw-pointer LAPACK wrappers.
 
concept  uni20::LapackRealOrComplex
 Concept for real or complex scalar fields with real LAPACK coverage.
 
concept  uni20::LapackComplexReal
 Concept for real precisions whose Uni20 complex scalar has LAPACK coverage.
 
concept  uni20::LapackScalar
 Concept for scalar types with a configured dense LAPACK backend.
 
concept  uni20::ScalarValued
 Concept for scalar types or types whose recursive value_type resolves to a scalar.
 
concept  uni20::IntegerScalarValued
 Concept for scalar-valued types whose scalar_t<T> is an integer scalar.
 
concept  uni20::RealScalarValued
 Concept for scalar-valued types whose scalar_t<T> is a real scalar.
 
concept  uni20::ComplexScalarValued
 Concept for scalar-valued types whose scalar_t<T> is a complex scalar.
 
concept  uni20::RealOrComplexScalarValued
 Concept for scalar-valued types whose scalar_t<T> is real or complex.
 

Classes

struct  uni20::is_complex_t< T >
 Trait to detect whether a type is a complex scalar type. More...
 
struct  uni20::is_integer_t< T >
 Trait to detect whether a type is an integer scalar (excluding bool). More...
 
struct  uni20::is_real_t< T >
 Trait to detect whether a type is a real-valued scalar. More...
 
struct  uni20::make_complex< T >
 Metafunction to convert a type to its complexified analog. More...
 
struct  uni20::make_complex< T >
 Metafunction that produces the complex counterpart of a real-valued scalar. More...
 
struct  uni20::make_real< T >
 Metafunction to convert a type to its real-valued analog. More...
 
struct  uni20::numeric_limits< T >
 Project-level numeric limits customization point. More...
 
struct  uni20::scalar_format_options
 Formatting options for Uni20 real and complex scalars. More...
 
struct  uni20::scalar_type< T >
 Trait to extract the scalar type from a type T. More...
 

Typedefs

template<typename Real >
using uni20::complex = typename detail::complex_type< Real >::type
 Project-level complex scalar spelling.
 
template<typename T >
using uni20::make_complex_t = typename make_complex< T >::type
 Alias for the complexified version of T.
 
template<typename T >
using uni20::make_real_t = typename make_real< T >::type
 Alias for the underlying real-valued type of T.
 

Enumerations

enum class  uni20::real_format_notation { uni20::real_format_notation::general , uni20::real_format_notation::fixed , uni20::real_format_notation::scientific }
 Selects how real scalar values are rendered as text. More...
 

Functions

template<typename T >
uni20::complex< T > uni20::conj (detail::standard_complex< T > x)
 Returns the complex conjugate for complex-valued scalars.
 
template<Integer I>
constexpr I uni20::conj (I const &x)
 Returns the conjugate of an integer scalar.
 
template<Real R>
constexpr R uni20::conj (R const &x)
 Returns the conjugate of a real-valued scalar.
 
template<Complex T>
std::string uni20::format_complex (T const &value, scalar_format_options const &options={})
 Format a Uni20 complex scalar as real+imagi.
 
template<Real T>
std::string uni20::format_real (T value, scalar_format_options const &options={})
 Format a Uni20 real scalar.
 
template<RealOrComplex T>
std::string uni20::format_scalar (T const &value, scalar_format_options const &options={})
 Format any Uni20 real or complex scalar.
 
template<Scalar S>
constexpr auto uni20::herm (S x)
 Computes the Hermitian adjoint of a scalar value.
 
template<typename T >
constexpr T & uni20::imag (detail::standard_complex< T > &z) noexcept
 Provides mutable access to the imaginary component of a uni20::complex value.
 
template<Complex C>
constexpr bool uni20::isfinite (C const &z)
 Returns whether both components of a complex scalar are finite.
 
template<Integer I>
constexpr bool uni20::isfinite (I const &x) noexcept
 Returns whether an integer scalar is finite.
 
template<Real R>
constexpr bool uni20::isfinite (R const &x)
 Returns whether a real scalar is neither NaN nor positive/negative infinity.
 
template<Real T>
T uni20::parse_real (std::string_view text)
 Parse a Uni20 real scalar from text.
 
template<Real T>
std::istream & uni20::read_real (std::istream &stream, T &value)
 Read a Uni20 real scalar from a stream token.
 
template<typename T >
constexpr T & uni20::real (detail::standard_complex< T > &z) noexcept
 Provides mutable access to the real component of a uni20::complex value.
 

Variables

template<typename T >
constexpr bool uni20::has_numeric_limits_v
 True when Uni20 has numeric limits for T.
 
template<typename T >
constexpr bool uni20::has_trivial_conj = Real<T> || Integer<T>
 Indicates whether the Uni20 conjugation helper is a no-op for the provided scalar type.
 
template<typename T >
constexpr bool uni20::is_complex_scalar_valued_v = is_scalar_valued_v<T> && is_complex_v<scalar_t<T>>
 Trait to detect whether T is scalar-valued with a complex scalar.
 
template<typename T >
constexpr bool uni20::is_complex_v = is_complex_t<std::remove_cvref_t<T>>::value
 Convenience alias that exposes the value of is_complex_t.
 
template<typename T >
constexpr bool uni20::is_integer_scalar_valued_v = is_scalar_valued_v<T> && is_integer_v<scalar_t<T>>
 Trait to detect whether T is scalar-valued with an integer scalar.
 
template<typename T >
constexpr bool uni20::is_integer_v = is_integer_t<std::remove_cvref_t<T>>::value
 Convenience alias that exposes the value of is_integer_t.
 
template<typename T >
constexpr bool uni20::is_real_or_complex_scalar_valued_v = is_scalar_valued_v<T> && is_real_or_complex_v<scalar_t<T>>
 Trait to detect whether T is scalar-valued with a real or complex scalar.
 
template<typename T >
constexpr bool uni20::is_real_or_complex_v = is_real_v<T> || is_complex_v<T>
 Trait to detect whether a type is a real or complex scalar.
 
template<typename T >
constexpr bool uni20::is_real_scalar_valued_v = is_scalar_valued_v<T> && is_real_v<scalar_t<T>>
 Trait to detect whether T is scalar-valued with a real scalar.
 
template<typename T >
constexpr bool uni20::is_real_v = is_real_t<std::remove_cvref_t<T>>::value
 Convenience alias that exposes the value of is_real_t.
 
template<typename T >
constexpr bool uni20::is_scalar_v = is_real_v<T> || is_complex_v<T> || is_integer_v<T>
 Trait to detect whether a type is a numeric scalar (real, complex, or integer).
 
template<typename T >
constexpr bool uni20::is_scalar_valued_v = !std::same_as<scalar_t<T>, void>
 Trait to detect whether T is scalar-valued.
 

Detailed Description

Scalar helper utilities shared across Uni20 core algorithms.

Typedef Documentation

◆ complex

template<typename Real >
using uni20::complex = typedef typename detail::complex_type<Real>::type

Project-level complex scalar spelling.

Native real types retain std::complex identity and ABI. With MPC enabled, mpreal selects the owning MPC scalar. Generic functions should deduce the complex value type directly rather than deducing through this alias.

Template Parameters
RealUnderlying real scalar type.

◆ make_complex_t

template<typename T >
using uni20::make_complex_t = typedef typename make_complex<T>::type

Alias for the complexified version of T.

Template Parameters
TType to complexify.

◆ make_real_t

template<typename T >
using uni20::make_real_t = typedef typename make_real<T>::type

Alias for the underlying real-valued type of T.

Template Parameters
TType to convert.

Enumeration Type Documentation

◆ real_format_notation

enum class uni20::real_format_notation
strong

Selects how real scalar values are rendered as text.

Enumerator
general 
fixed 
scientific 

Function Documentation

◆ conj() [1/3]

template<typename T >
uni20::complex< T > uni20::conj ( detail::standard_complex< T >  x)

Returns the complex conjugate for complex-valued scalars.

This overload forwards to std::conj and therefore returns a uni20::complex<T> copy of the input value. It inherits the constexpr availability of std::conj (currently not constexpr).

Template Parameters
TComponent type of the complex scalar.
Parameters
xComplex value whose conjugate is requested.
Returns
The complex conjugate of x.

◆ conj() [2/3]

template<Integer I>
constexpr I uni20::conj ( I const &  x)
constexpr

Returns the conjugate of an integer scalar.

Integer values are treated as reals for conjugation and therefore returned unchanged. The overload is constexpr, enabling compile-time evaluation for literal arguments.

Template Parameters
IInteger scalar type.
Parameters
xInteger scalar to return.
Returns
x, unchanged.

◆ conj() [3/3]

template<Real R>
constexpr R uni20::conj ( R const &  x)
constexpr

Returns the conjugate of a real-valued scalar.

Real numbers are unchanged by conjugation, so the value is returned verbatim. The overload is constexpr, enabling compile-time evaluation for literal arguments.

Template Parameters
RReal scalar type.
Parameters
xReal scalar to return.
Returns
x, unchanged.

◆ format_complex()

template<Complex T>
std::string uni20::format_complex ( T const &  value,
scalar_format_options const &  options = {} 
)

Format a Uni20 complex scalar as real+imagi.

Template Parameters
TComplex scalar type.
Parameters
valueValue to format.
optionsText formatting options.
Returns
Formatted scalar text.

◆ format_real()

template<Real T>
std::string uni20::format_real ( T  value,
scalar_format_options const &  options = {} 
)

Format a Uni20 real scalar.

Template Parameters
TReal scalar type.
Parameters
valueValue to format.
optionsText formatting options.
Returns
Formatted scalar text.

◆ format_scalar()

template<RealOrComplex T>
std::string uni20::format_scalar ( T const &  value,
scalar_format_options const &  options = {} 
)

Format any Uni20 real or complex scalar.

Template Parameters
TReal or complex scalar type.
Parameters
valueValue to format.
optionsText formatting options.
Returns
Formatted scalar text.

◆ herm()

template<Scalar S>
constexpr auto uni20::herm ( S  x)
constexpr

Computes the Hermitian adjoint of a scalar value.

For scalar inputs the Hermitian adjoint is equivalent to the complex conjugate, so this helper simply forwards to conj. When the selected conj overload is constexpr, this helper is as well, preserving compile-time evaluation.

Template Parameters
SScalar type satisfying Scalar.
Parameters
xScalar value whose Hermitian adjoint is requested.
Returns
The result of calling conj(x).

◆ imag()

template<typename T >
constexpr T & uni20::imag ( detail::standard_complex< T > &  z)
constexprnoexcept

Provides mutable access to the imaginary component of a uni20::complex value.

This helper mirrors the std::imag overload for lvalues while remaining constexpr and noexcept for direct reference access.

Template Parameters
TComponent type of the complex scalar.
Parameters
zComplex number whose imaginary component will be exposed.
Returns
Reference to the imaginary component of z.

◆ isfinite() [1/3]

template<Complex C>
constexpr bool uni20::isfinite ( C const &  z)
constexpr

Returns whether both components of a complex scalar are finite.

Template Parameters
TReal component type.
Parameters
zComplex scalar to inspect.
Returns
true when both the real and imaginary components are finite.

◆ isfinite() [2/3]

template<Integer I>
constexpr bool uni20::isfinite ( I const &  x)
constexprnoexcept

Returns whether an integer scalar is finite.

Integer Uni20 scalars have no NaN or infinity representation, so every value is finite.

Template Parameters
IInteger scalar type.
Parameters
xInteger scalar to inspect.
Returns
Always true.

◆ isfinite() [3/3]

template<Real R>
constexpr bool uni20::isfinite ( R const &  x)
constexpr

Returns whether a real scalar is neither NaN nor positive/negative infinity.

This uses uni20::numeric_limits<T> so extension real scalar types can define their own infinity representation without depending on standard-library overload coverage for std::isfinite. Runtime-precision mpreal uses its native classification instead of type-only limits.

Template Parameters
RReal scalar type.
Parameters
xReal scalar to inspect.
Returns
true when x is finite.

◆ parse_real()

template<Real T>
T uni20::parse_real ( std::string_view  text)

Parse a Uni20 real scalar from text.

Template Parameters
TReal scalar type.
Parameters
textText containing one complete real literal.
Returns
Parsed value.
Exceptions
std::invalid_argumentif the text is not a complete real literal.
std::out_of_rangeif the literal overflows or underflows the target type.

◆ read_real()

template<Real T>
std::istream & uni20::read_real ( std::istream &  stream,
T &  value 
)

Read a Uni20 real scalar from a stream token.

This helper exists because extension real aliases such as uni20::float128 cannot portably receive ordinary overloaded stream extraction operators. For mpreal, parsing retains the destination's working precision; invalid input leaves its value unchanged.

Template Parameters
TReal scalar type.
Parameters
streamInput stream.
valueDestination value.
Returns
The input stream.

◆ real()

template<typename T >
constexpr T & uni20::real ( detail::standard_complex< T > &  z)
constexprnoexcept

Provides mutable access to the real component of a uni20::complex value.

This helper mirrors the std::real overload for lvalues while remaining constexpr and noexcept for direct reference access.

Template Parameters
TComponent type of the complex scalar.
Parameters
zComplex number whose real component will be exposed.
Returns
Reference to the real component of z.

Variable Documentation

◆ has_numeric_limits_v

template<typename T >
constexpr bool uni20::has_numeric_limits_v
inlineconstexpr
Initial value:
=
requires { requires numeric_limits<std::remove_cvref_t<T>>::is_specialized; }

True when Uni20 has numeric limits for T.

Runtime-precision specializations require a value or precision for precision-dependent queries; this trait does not promise static limits.

Template Parameters
TType to inspect.

◆ has_trivial_conj

template<typename T >
constexpr bool uni20::has_trivial_conj = Real<T> || Integer<T>
inlineconstexpr

Indicates whether the Uni20 conjugation helper is a no-op for the provided scalar type.

Evaluates to true when the scalar is already real-valued or integral, allowing callers to skip complex conjugation work. The variable template is constexpr, so the result may be used in constant-expression contexts.

Template Parameters
TScalar type to inspect.

◆ is_complex_scalar_valued_v

template<typename T >
constexpr bool uni20::is_complex_scalar_valued_v = is_scalar_valued_v<T> && is_complex_v<scalar_t<T>>
inlineconstexpr

Trait to detect whether T is scalar-valued with a complex scalar.

Template Parameters
TType to inspect.

◆ is_complex_v

template<typename T >
constexpr bool uni20::is_complex_v = is_complex_t<std::remove_cvref_t<T>>::value
inlineconstexpr

Convenience alias that exposes the value of is_complex_t.

Template Parameters
TType to inspect.

◆ is_integer_scalar_valued_v

template<typename T >
constexpr bool uni20::is_integer_scalar_valued_v = is_scalar_valued_v<T> && is_integer_v<scalar_t<T>>
inlineconstexpr

Trait to detect whether T is scalar-valued with an integer scalar.

Template Parameters
TType to inspect.

◆ is_integer_v

template<typename T >
constexpr bool uni20::is_integer_v = is_integer_t<std::remove_cvref_t<T>>::value
inlineconstexpr

Convenience alias that exposes the value of is_integer_t.

Template Parameters
TType to inspect.

◆ is_real_or_complex_scalar_valued_v

template<typename T >
constexpr bool uni20::is_real_or_complex_scalar_valued_v = is_scalar_valued_v<T> && is_real_or_complex_v<scalar_t<T>>
inlineconstexpr

Trait to detect whether T is scalar-valued with a real or complex scalar.

Template Parameters
TType to inspect.

◆ is_real_or_complex_v

template<typename T >
constexpr bool uni20::is_real_or_complex_v = is_real_v<T> || is_complex_v<T>
inlineconstexpr

Trait to detect whether a type is a real or complex scalar.

Template Parameters
TType to inspect.

◆ is_real_scalar_valued_v

template<typename T >
constexpr bool uni20::is_real_scalar_valued_v = is_scalar_valued_v<T> && is_real_v<scalar_t<T>>
inlineconstexpr

Trait to detect whether T is scalar-valued with a real scalar.

Template Parameters
TType to inspect.

◆ is_real_v

template<typename T >
constexpr bool uni20::is_real_v = is_real_t<std::remove_cvref_t<T>>::value
inlineconstexpr

Convenience alias that exposes the value of is_real_t.

Template Parameters
TType to inspect.

◆ is_scalar_v

template<typename T >
constexpr bool uni20::is_scalar_v = is_real_v<T> || is_complex_v<T> || is_integer_v<T>
inlineconstexpr

Trait to detect whether a type is a numeric scalar (real, complex, or integer).

Template Parameters
TType to inspect.

◆ is_scalar_valued_v

template<typename T >
constexpr bool uni20::is_scalar_valued_v = !std::same_as<scalar_t<T>, void>
inlineconstexpr

Trait to detect whether T is scalar-valued.

A scalar-valued type is either a scalar itself or a type whose recursive value_type chain resolves to a Uni20 scalar. Use is_scalar_v<T> when constraining a type that must be the scalar value itself.

Template Parameters
TType to inspect.