Vulpes  0.1.0
Versatile and parallel compUtational Library for high-order discontinuous Polytopal Element Simulations
Loading...
Searching...
No Matches
vulpes::vmath Namespace Reference

Classes

struct  is_gnump
 Type trait to check if a type is one of the GNU Multiple Precision (GMP) classes (mpf_class, mpq_class, or mpz_class). More...
struct  is_pseudoaritmetic
 Type trait to check if a type is either a GMP class or a built-in arithmetic type. More...
struct  is_pseudofloating
 Type trait to check if a type is either the GMP floating-point class (mpf_class) or a built-in floating-point type. More...

Functions

template<typename U, typename V, typename = std::enable_if_t<std::is_unsigned_v<V> && std::is_integral_v<V>>>
constexpr U upow (U base, V exp, U result=U(1))
 Computes the unsigned power of a number.
template<typename U, typename V, typename = std::enable_if_t<std::is_signed_v<V> && std::is_integral_v<V>>>
constexpr U ipow (U base, V exp, U result=U(1))
 Computes the signed power of a number.
template<typename U, typename V, typename = std::enable_if_t<std::is_integral_v<V>>>
constexpr U pow (U base, V exp, U result=U(1))
 Computes the power of a number.
template<typename T, typename = std::enable_if_t<is_pseudoaritmetic<T>::value>>
T abs (const T &value)
 Computes the absolute value of a number.
template<typename T, typename = std::enable_if_t<is_pseudoaritmetic<T>::value>>
T sqrt (const T &value)
template<typename T, typename = std::enable_if_t<is_pseudofloating<T>::value>>
constexpr T pi ()
 Returns the value of pi.
template<typename T, typename = std::enable_if_t<is_pseudofloating<T>::value>>
constexpr T epsilon (const T &instance=T(0))
 Returns the machine epsilon for floating-point types or a rough approximation for GMP types.
template<typename T, typename = std::enable_if_t<is_pseudofloating<T>::value>>
std::size_t precision (const T &instance)
 Returns the precision of the input value in bits.
template<typename V, typename U, typename = std::enable_if_t< is_pseudoaritmetic<U>::value && is_pseudoaritmetic<V>::value>>
V to (const U &src)
 Converts a value of one pseudo-arithmetic type to another.
template<typename T, typename = std::enable_if_t<is_pseudoaritmetic<T>::value>>
constexpr T factorial (T n)
 Computes the factorial of a pseudo-arithmetic number iteratively.
template<typename T, typename = std::enable_if_t<is_pseudoaritmetic<T>::value>>
T gamma (const T &value)
template<typename T, typename = std::enable_if_t<std::is_integral_v<T>>>
constexpr int64_t pow1 (T exp)
 Computes (-1)^exp.
template<typename T, typename = std::enable_if_t<std::is_integral_v<T>>>
constexpr T binomial (T n, T k)
template<typename T, int Options>
T sarrus_det (const Eigen::Matrix< T, 3, 3, Options > &mat)
 Computes the determinant of a 3x3 matrix using Sarrus' rule.
template<typename T, int Dim, int Options>
T determinant (const Eigen::Matrix< T, Dim, Dim, Options > &mat)
 Computes the determinant of a 2x2 or 3x3 matrix.
template<typename T, int Dim, int Options>
T area (const Eigen::Matrix< T, Dim, Dim - 1, Options > &mat)
template<typename FloatType, typename IndexType>
void newellNormal (const FloatType *vertices_data, const IndexType *face_indices_data, IndexType num_face_vertices, FloatType *out_normal)
 Accumulates the unnormalized normal of a polygon using Newell's method.

Function Documentation

◆ abs()

template<typename T, typename = std::enable_if_t<is_pseudoaritmetic<T>::value>>
T vulpes::vmath::abs ( const T & value)
inline

Computes the absolute value of a number.

Template Parameters
TThe type of the input value.
DummyA dummy template parameter used for SFINAE.
Parameters
valueThe input value whose absolute value is to be computed.
Returns
The absolute value of value.

This function computes the absolute value of value. If T is a built-in arithmetic type, it uses std::abs. If T is a GMP class, it uses the GMP library's abs function.

◆ area()

template<typename T, int Dim, int Options>
T vulpes::vmath::area ( const Eigen::Matrix< T, Dim, Dim - 1, Options > & mat)
inline

◆ binomial()

template<typename T, typename = std::enable_if_t<std::is_integral_v<T>>>
T vulpes::vmath::binomial ( T n,
T k )
inlineconstexpr

◆ determinant()

template<typename T, int Dim, int Options>
T vulpes::vmath::determinant ( const Eigen::Matrix< T, Dim, Dim, Options > & mat)
inline

Computes the determinant of a 2x2 or 3x3 matrix.

Template Parameters
TThe scalar type of the matrix elements (e.g., float, double).
DimDimension of the matrix: 2 or 3.
OptionsThe storage options for the Eigen matrix (e.g., RowMajor or ColMajor).
Parameters
matAn Eigen matrix whose determinant is to be calculated.
Returns
The determinant of the given matrix.

◆ epsilon()

template<typename T, typename = std::enable_if_t<is_pseudofloating<T>::value>>
T vulpes::vmath::epsilon ( const T & instance = T(0))
constexpr

Returns the machine epsilon for floating-point types or a rough approximation for GMP types.

Template Parameters
TThe type of the input value (must be a floating-point or GMP floating-point type).
DummyA dummy template parameter used for SFINAE.
Parameters
instanceAn optional instance of T used to determine precision (default is 0).
Returns
The machine epsilon for floating-point types or a rough approximation for GMP types.

This function returns the machine epsilon for floating-point types, which is the difference between 1 and the smallest value greater than 1 that is representable by the floating-point type. For GMP types, it returns a rough approximation of the precision.

◆ factorial()

template<typename T, typename = std::enable_if_t<is_pseudoaritmetic<T>::value>>
T vulpes::vmath::factorial ( T n)
inlineconstexpr

Computes the factorial of a pseudo-arithmetic number iteratively.

Template Parameters
TThe type of the input value.
DummyA dummy template parameter used for SFINAE.
Parameters
nThe input value .
Returns
The factorial of n.

◆ gamma()

template<typename T, typename = std::enable_if_t<is_pseudoaritmetic<T>::value>>
T vulpes::vmath::gamma ( const T & value)
inline

◆ ipow()

template<typename U, typename V, typename = std::enable_if_t<std::is_signed_v<V> && std::is_integral_v<V>>>
U vulpes::vmath::ipow ( U base,
V exp,
U result = U(1) )
inlineconstexpr

Computes the signed power of a number.

Template Parameters
UThe type of the base and result.
VThe type of the exponent (must be a signed integral type).
DummyA dummy template parameter used for SFINAE.
Parameters
baseThe base value to be raised to the power.
expThe exponent value.
resultValue from which start accumulate the result
Returns
The computed power base^exp. If exp is negative, returns 1/(base^|exp|).

This function computes base^exp using exponentiation by squaring, and handles negative exponents by inverting the base. The type U must support multiplication, division, and assignment operations. The type V must be a signed integral type.

◆ newellNormal()

template<typename FloatType, typename IndexType>
void vulpes::vmath::newellNormal ( const FloatType * vertices_data,
const IndexType * face_indices_data,
IndexType num_face_vertices,
FloatType * out_normal )
inline

Accumulates the unnormalized normal of a polygon using Newell's method.

This function calculates the geometric normal of an ordered, nearly-planar polygon and adds it to the provided output buffer out_normal. It is robust for non-convex polygons and operates on raw pointer data for high performance.

Note
This is an accumulator function. It does not initialize out_normal to zero before computation. The caller is responsible for zeroing the output buffer if they are not accumulating results.
Template Parameters
FloatTypeThe floating-point type for coordinates (e.g., float, double).
IndexTypeThe integer type for vertex indices (e.g., int, uint32_t, size_t).
Parameters
[in]vertices_dataPointer to a contiguous array of vertex coordinates, laid out as [x0, y0, z0, x1, y1, z1, ...].
[in]face_indices_dataPointer to an array of vertex indices that define the polygon in counter-clockwise order.
[in]num_face_verticesThe number of vertices in the polygon face.
[in,out]out_normalPointer to a buffer of 3 FloatTypes. The calculated normal components are added to the existing values in this buffer.

◆ pi()

template<typename T, typename = std::enable_if_t<is_pseudofloating<T>::value>>
T vulpes::vmath::pi ( )
constexpr

Returns the value of pi.

Template Parameters
TThe type of the return value (must be a floating-point or GMP floating-point type).
DummyA dummy template parameter used for SFINAE.
Returns
The value of pi.

This function returns the value of pi. If T is a built-in floating-point type, it uses the value from <numbers> (if available) or M_PI. If T is mpf_class, it returns a 1024-digit approximation of pi.

◆ pow()

template<typename U, typename V, typename = std::enable_if_t<std::is_integral_v<V>>>
U vulpes::vmath::pow ( U base,
V exp,
U result = U(1) )
inlineconstexpr

Computes the power of a number.

Template Parameters
UThe type of the base and result.
VThe type of the exponent (must be a signed integral type).
DummyA dummy template parameter used for SFINAE.
Parameters
baseThe base value to be raised to the power.
expThe exponent value.
resultValue from which start accumulate the result
Returns
The computed power base^exp. If exp is negative, returns 1/(base^|exp|).

This function computes base^exp using exponentiation by squaring, and handles negative exponents by inverting the base. The type U must support multiplication, division, and assignment operations. The type V must be a signed integral type.

◆ pow1()

template<typename T, typename = std::enable_if_t<std::is_integral_v<T>>>
int64_t vulpes::vmath::pow1 ( T exp)
inlineconstexpr

Computes (-1)^exp.

Template Parameters
TThe type of the input value.
DummyA dummy template parameter used for SFINAE.
Parameters
expThe input value .
Returns
The value of (-1)^exp.

Computes efficiently (-1)^exp in a branchless way by explointing the relation (-1)^exp == (1 - 2 * (exp % 2))

◆ precision()

template<typename T, typename = std::enable_if_t<is_pseudofloating<T>::value>>
std::size_t vulpes::vmath::precision ( const T & instance)
inline

Returns the precision of the input value in bits.

Template Parameters
TThe type of the input value (must be a floating-point or GMP floating-point type).
DummyA dummy template parameter used for SFINAE.
Parameters
instanceThe input value whose precision is to be determined.
Returns
The precision of the input value in bits.

This function returns the precision of the input value. For floating-point types, it returns the size of the type in bits. For GMP types, it returns the precision as set in the GMP instance.

◆ sarrus_det()

template<typename T, int Options>
T vulpes::vmath::sarrus_det ( const Eigen::Matrix< T, 3, 3, Options > & mat)
inline

Computes the determinant of a 3x3 matrix using Sarrus' rule.

Template Parameters
TThe scalar type of the matrix elements (e.g., float, double).
OptionsThe storage options for the Eigen matrix (e.g., RowMajor or ColMajor).
Parameters
matA 3x3 Eigen matrix whose determinant is to be calculated.
Returns
The determinant of the given 3x3 matrix.

◆ sqrt()

template<typename T, typename = std::enable_if_t<is_pseudoaritmetic<T>::value>>
T vulpes::vmath::sqrt ( const T & value)
inline

◆ to()

template<typename V, typename U, typename = std::enable_if_t< is_pseudoaritmetic<U>::value && is_pseudoaritmetic<V>::value>>
V vulpes::vmath::to ( const U & src)
inline

Converts a value of one pseudo-arithmetic type to another.

Template Parameters
UThe type of the input value.
VThe type to which the value is to be converted.
DummyA dummy template parameter used for SFINAE.
Parameters
srcThe input value to be converted.
Returns
The converted value of type V.

This function converts a value of type U to type V. If both U and V are the same type, it returns the input value directly. If both are arithmetic types, it uses static_cast<V>(src). For conversions involving GMP types, it uses the appropriate GMP constructors or methods.

◆ upow()

template<typename U, typename V, typename = std::enable_if_t<std::is_unsigned_v<V> && std::is_integral_v<V>>>
U vulpes::vmath::upow ( U base,
V exp,
U result = U(1) )
inlineconstexpr

Computes the unsigned power of a number.

Template Parameters
UThe type of the base and result.
VThe type of the exponent (must be an unsigned integral type).
DummyA dummy template parameter used for SFINAE.
Parameters
baseThe base value to be raised to the power.
expThe exponent value.
resultThe initial value of the result (default is 1).
Returns
The computed power base^exp.

This function computes base^exp using exponentiation by squaring, which is efficient for large exponents. The type U must support multiplication and assignment operations. The type V must be an unsigned integral type.