Mundy: Multibody Nonlocal Dynamics Version of the Day
Loading...
Searching...
No Matches
Scalar.hpp File Reference

Classes

struct  mundy::is_scalar< TypeToCheck >
 Type trait to determine if a type is an AScalar. More...
class  mundy::AScalar< T, Accessor >
 Class for an owning or viewing scalar-like value (an arithmetic type, or a custom scalar such as an autodiff dual). More...

Namespaces

namespace  mundy

Functions

Output stream
template<typename T, ValidAccessor< T > Accessor>
std::ostream & mundy::operator<< (std::ostream &os, const AScalar< T, Accessor > &s)
Comparison
template<typename U, typename T, ValidAccessor< U > Accessor1, ValidAccessor< T > Accessor2>
constexpr bool mundy::is_close (const AScalar< U, Accessor1 > &a, const AScalar< T, Accessor2 > &b, const decltype(get_comparison_tolerance< T, U >())&tol=get_comparison_tolerance< T, U >())
template<typename U, typename T, ValidAccessor< U > Accessor1, ValidAccessor< T > Accessor2>
constexpr bool mundy::is_approx_close (const AScalar< U, Accessor1 > &a, const AScalar< T, Accessor2 > &b, const decltype(get_relaxed_comparison_tolerance< T, U >())&tol=get_relaxed_comparison_tolerance< T, U >())
Non-member arithmetic: scalar op AScalar
template<typename U, typename T, ValidAccessor< T > Accessor>
constexpr auto mundy::operator+ (const U &scalar, const AScalar< T, Accessor > &s)
template<typename U, typename T, ValidAccessor< T > Accessor>
constexpr auto mundy::operator- (const U &scalar, const AScalar< T, Accessor > &s)
template<typename U, typename T, ValidAccessor< T > Accessor>
constexpr auto mundy::operator* (const U &scalar, const AScalar< T, Accessor > &s)
template<typename U, typename T, ValidAccessor< T > Accessor>
constexpr auto mundy::operator/ (const U &scalar, const AScalar< T, Accessor > &s)
 scalar / AScalar — integral/integral pairs promote to double.
Atomic memory operations on raw scalars
template<typename T>
T mundy::atomic_load (T *const s)
 Atomic load: s_copy = *s.
template<typename T, typename U>
void mundy::atomic_store (T *const s, const U &value)
 Atomic store: *s = value.
template<typename T, typename U>
void mundy::atomic_add (T *const s, const U &value)
 Atomic *s += value.
template<typename T, typename Acc, typename U>
void mundy::atomic_add (AScalar< T, Acc > *const s, const U &value)
 Atomic *s += value — AScalar overload: operates on the underlying scalar, bypassing AScalar's operator+ (which returns a different storage type incompatible with CAS loops).
template<typename T, typename U>
void mundy::atomic_sub (T *const s, const U &value)
 Atomic *s -= value.
template<typename T, typename Acc, typename U>
void mundy::atomic_sub (AScalar< T, Acc > *const s, const U &value)
 Atomic *s -= value — AScalar overload.
template<typename T, typename U>
void mundy::atomic_mul (T *const s, const U &value)
 Atomic *s *= value.
template<typename T, typename Acc, typename U>
void mundy::atomic_mul (AScalar< T, Acc > *const s, const U &value)
 Atomic *s *= value — AScalar overload.
template<typename T, typename U>
void mundy::atomic_div (T *const s, const U &value)
 Atomic *s /= value.
template<typename T, typename Acc, typename U>
void mundy::atomic_div (AScalar< T, Acc > *const s, const U &value)
 Atomic *s /= value — AScalar overload.
template<typename T, typename U>
T mundy::atomic_fetch_add (T *const s, const U &value)
 Atomic *s += value; returns old *s.
template<typename T, typename U>
T mundy::atomic_fetch_sub (T *const s, const U &value)
 Atomic *s -= value; returns old *s.
template<typename T, typename U>
T mundy::atomic_fetch_mul (T *const s, const U &value)
 Atomic *s *= value; returns old *s.
template<typename T, typename U>
T mundy::atomic_fetch_div (T *const s, const U &value)
 Atomic *s /= value; returns old *s.
template<typename T, typename U>
T mundy::atomic_add_fetch (T *const s, const U &value)
 Atomic *s += value; returns new *s.
template<typename T, typename U>
T mundy::atomic_sub_fetch (T *const s, const U &value)
 Atomic *s -= value; returns new *s.
template<typename T, typename U>
T mundy::atomic_mul_fetch (T *const s, const U &value)
 Atomic *s *= value; returns new *s.
template<typename T, typename U>
T mundy::atomic_div_fetch (T *const s, const U &value)
 Atomic *s /= value; returns new *s.
View and owning helpers
template<typename T, ValidAccessor< T > Accessor>
constexpr auto mundy::get_scalar (Accessor &&data)
 Create a non-owning AScalar view over an existing accessor.

Utility free functions

#define MUNDY_MATH_SCALAR_UNARY(func)
 Unary cmath functions: forward to the mundy dispatch on the underlying value.
#define MUNDY_MATH_SCALAR_BINARY(func)
template<typename T, ValidAccessor< T > Accessor>
constexpr auto mundy::abs (const AScalar< T, Accessor > &s)
 Absolute value of a scalar.
 mundy::MUNDY_MATH_SCALAR_UNARY (sqrt) MUNDY_MATH_SCALAR_UNARY(cbrt) MUNDY_MATH_SCALAR_UNARY(sin) MUNDY_MATH_SCALAR_UNARY(cos) MUNDY_MATH_SCALAR_UNARY(tan) MUNDY_MATH_SCALAR_UNARY(asin) MUNDY_MATH_SCALAR_UNARY(acos) MUNDY_MATH_SCALAR_UNARY(atan) MUNDY_MATH_SCALAR_UNARY(exp) MUNDY_MATH_SCALAR_UNARY(log) MUNDY_MATH_SCALAR_UNARY(log10) MUNDY_MATH_SCALAR_UNARY(floor) MUNDY_MATH_SCALAR_UNARY(ceil) MUNDY_MATH_SCALAR_UNARY(round) MUNDY_MATH_SCALAR_BINARY(atan2) MUNDY_MATH_SCALAR_BINARY(pow) MUNDY_MATH_SCALAR_BINARY(copysign) MUNDY_MATH_SCALAR_BINARY(min) MUNDY_MATH_SCALAR_BINARY(max) template< ValidScalarType ScalarType > const expr auto copy(const ScalarType &s)
 Deep copy (mirrors the AVector free function).
template<typename U, ValidScalarType ScalarType>
constexpr auto mundy::cast (const ScalarType &s)
 Cast a scalar to a different type.

AScalar type traits

template<typename T>
using mundy::Scalar = AScalar<T, Array<T, 1>>
 Owning scalar with the default Array<T,1> accessor.
template<typename TypeToCheck>
constexpr bool mundy::is_scalar_v = is_scalar<TypeToCheck>::value

Macro Definition Documentation

◆ MUNDY_MATH_SCALAR_UNARY

#define MUNDY_MATH_SCALAR_UNARY ( func)
Value:
template <typename T, ValidAccessor<T> Accessor> \
KOKKOS_INLINE_FUNCTION constexpr auto func(const AScalar<T, Accessor>& s) { \
return AScalar<T>{func(s.value())}; \
}

◆ MUNDY_MATH_SCALAR_BINARY

#define MUNDY_MATH_SCALAR_BINARY ( func)
Value:
template <typename T, ValidAccessor<T> Accessor> \
KOKKOS_INLINE_FUNCTION constexpr auto func(const AScalar<T, Accessor>& a, const AScalar<T, Accessor>& b) { \
return AScalar<T>{func(a.value(), b.value())}; \
} \
template <typename T, ValidAccessor<T> Accessor1, ValidAccessor<T> Accessor2> \
MUNDY_REQUIRES(!std::is_same_v<Accessor1, Accessor2>) \
KOKKOS_INLINE_FUNCTION constexpr auto func(const AScalar<T, Accessor1>& a, const AScalar<T, Accessor2>& b) { \
return AScalar<T>{func(a.value(), b.value())}; \
}

Binary cmath functions: forward to the mundy dispatch on the underlying values. The same-accessor overload must exist separately so it is more specialized than the generic func(const T&, const T&) dispatch.