Stratax
Scientific computing containers and operations
Loading...
Searching...
No Matches
stratax::core::validation Namespace Reference

Functions

template<typename Actual, typename Expected>
void require_type (const char *message)
 Requires a type to exactly match an expected type after cv/ref removal.
template<typename T>
void require_numeric_type (const char *message)
 Requires a type to satisfy Stratax's numeric type rules.
template<typename Lhs, typename Rhs>
requires requires { typename Lhs::value_type; typename Rhs::value_type; }
void require_same_value_type (const Lhs &, const Rhs &, const char *message)
 Requires two array-like objects to have the same value type.
std::size_t nonnegative_size (long long value, const char *message)
 Converts a signed value to std::size_t after rejecting negatives.
std::size_t nonnegative_shape_dimension (long long value, const char *message)
 Converts a signed shape dimension to std::size_t after rejecting negatives.
std::size_t positive_shape_dimension (long long value, const char *message)
 Converts a signed shape dimension to std::size_t after requiring it to be positive.
void require_positive_shape_dimension (std::size_t value, const char *message)
 Requires an unsigned shape dimension to be positive.
std::size_t nonnegative_index (long long value, const char *message)
 Converts a signed index to std::size_t after rejecting negatives.
void require_rank (std::size_t actual, std::size_t expected, const char *message)
 Requires a rank value to match an expected rank.
template<typename Ranked>
requires requires(const Ranked& object) { object.rank(); }
const Ranked & require_rank (const Ranked &object, std::size_t expected, const char *message)
 Requires an object with rank() to match an expected rank.
void require_index (std::size_t index, std::size_t size, const char *message)
 Requires an index to be less than a size.
void require_at_most (std::size_t value, std::size_t upper, const char *message)
 Requires a value to be less than or equal to an upper bound.
std::size_t checked_multiply (std::size_t lhs, std::size_t rhs, const char *message)
 Multiplies two sizes while checking for overflow.
std::size_t checked_add (std::size_t lhs, std::size_t rhs, const char *message)
 Adds two sizes while checking for overflow.
template<typename Lhs, typename Rhs>
bool same_shape (const Lhs &lhs, const Rhs &rhs)
 Returns whether two array-like objects have identical size and shape.
template<typename Lhs, typename Rhs>
void require_same_shape (const Lhs &lhs, const Rhs &rhs, const char *message)
 Requires two array-like objects to have identical size and shape.
void require_equal_size (std::size_t lhs, std::size_t rhs, const char *message)
 Requires two sizes to be equal.

Function Documentation

◆ checked_add()

std::size_t stratax::core::validation::checked_add ( std::size_t lhs,
std::size_t rhs,
const char * message )
inline

Adds two sizes while checking for overflow.

Parameters
lhsLeft operand.
rhsRight operand.
messageError message used on overflow.
Returns
Sum of lhs and rhs.
Exceptions
Exceptions::DimensionErrorIf the addition would overflow.

Definition at line 278 of file Validation.hpp.

Referenced by offset(), and slice().

◆ checked_multiply()

std::size_t stratax::core::validation::checked_multiply ( std::size_t lhs,
std::size_t rhs,
const char * message )
inline

Multiplies two sizes while checking for overflow.

Parameters
lhsLeft operand.
rhsRight operand.
messageError message used on overflow.
Returns
Product of lhs and rhs.
Exceptions
Exceptions::DimensionErrorIf the multiplication would overflow.

Definition at line 254 of file Validation.hpp.

Referenced by stratax::core::Shape::elements(), stratax::container::Matrix< U >::Matrix(), offset(), and slice().

◆ nonnegative_index()

std::size_t stratax::core::validation::nonnegative_index ( long long value,
const char * message )
inline

Converts a signed index to std::size_t after rejecting negatives.

Parameters
valueSigned index to validate.
messageError message used when value is negative.
Returns
value converted to std::size_t.
Exceptions
Exceptions::IndexErrorIf value is negative.

Definition at line 158 of file Validation.hpp.

◆ nonnegative_shape_dimension()

std::size_t stratax::core::validation::nonnegative_shape_dimension ( long long value,
const char * message )
inline

Converts a signed shape dimension to std::size_t after rejecting negatives.

Parameters
valueSigned dimension to validate.
messageError message used when value is negative.
Returns
value converted to std::size_t.
Exceptions
Exceptions::ShapeErrorIf value is negative.

Definition at line 102 of file Validation.hpp.

◆ nonnegative_size()

std::size_t stratax::core::validation::nonnegative_size ( long long value,
const char * message )
inline

Converts a signed value to std::size_t after rejecting negatives.

Parameters
valueSigned value to validate.
messageError message used when value is negative.
Returns
value converted to std::size_t.
Exceptions
Exceptions::DimensionErrorIf value is negative.

Definition at line 82 of file Validation.hpp.

◆ positive_shape_dimension()

std::size_t stratax::core::validation::positive_shape_dimension ( long long value,
const char * message )
inline

Converts a signed shape dimension to std::size_t after requiring it to be positive.

Parameters
valueSigned dimension to validate.
messageError message used when value <= 0.
Returns
value converted to std::size_t.
Exceptions
Exceptions::ShapeErrorIf value <= 0.

Definition at line 122 of file Validation.hpp.

◆ require_at_most()

void stratax::core::validation::require_at_most ( std::size_t value,
std::size_t upper,
const char * message )
inline

Requires a value to be less than or equal to an upper bound.

This is useful for half-open range stops, where stop == size is valid.

Parameters
valueValue to validate.
upperInclusive upper bound.
messageError message used when value > upper.
Exceptions
Exceptions::IndexErrorIf value > upper.

Definition at line 235 of file Validation.hpp.

Referenced by slice(), slice(), and slice().

◆ require_equal_size()

void stratax::core::validation::require_equal_size ( std::size_t lhs,
std::size_t rhs,
const char * message )
inline

Requires two sizes to be equal.

Parameters
lhsLeft size.
rhsRight size.
messageError message used on mismatch.
Exceptions
Exceptions::ShapeErrorIf the sizes differ.

Definition at line 332 of file Validation.hpp.

Referenced by reshape().

◆ require_index()

void stratax::core::validation::require_index ( std::size_t index,
std::size_t size,
const char * message )
inline

Requires an index to be less than a size.

Parameters
indexIndex to validate.
sizeExclusive upper bound.
messageError message used when out of bounds.
Exceptions
Exceptions::IndexErrorIf index >= size.

Definition at line 216 of file Validation.hpp.

Referenced by stratax::container::Tensor< U >::at(), stratax::container::Tensor< U >::at(), stratax::container::Vector< U >::at(), stratax::container::Vector< U >::at(), stratax::core::Strides::at(), stratax::container::Matrix< U >::operator()(), stratax::container::Matrix< U >::operator()(), and stratax::core::Shape::operator()().

◆ require_numeric_type()

template<typename T>
void stratax::core::validation::require_numeric_type ( const char * message)

Requires a type to satisfy Stratax's numeric type rules.

Template Parameters
TType being validated.
Parameters
messageError message used when the type is unsupported.
Exceptions
Exceptions::TypeErrorIf T is not a supported numeric type.

Definition at line 44 of file Validation.hpp.

◆ require_positive_shape_dimension()

void stratax::core::validation::require_positive_shape_dimension ( std::size_t value,
const char * message )
inline

Requires an unsigned shape dimension to be positive.

Parameters
valueDimension to validate.
messageError message used when value == 0.
Exceptions
Exceptions::ShapeErrorIf value == 0.

Definition at line 140 of file Validation.hpp.

◆ require_rank() [1/2]

template<typename Ranked>
requires requires(const Ranked& object) { object.rank(); }
const Ranked & stratax::core::validation::require_rank ( const Ranked & object,
std::size_t expected,
const char * message )

Requires an object with rank() to match an expected rank.

Parameters
objectObject to validate.
expectedRequired rank.
messageError message used on mismatch.
Returns
Reference to object.
Exceptions
Exceptions::DimensionErrorIf the object rank differs.

Definition at line 201 of file Validation.hpp.

References require_rank().

◆ require_rank() [2/2]

void stratax::core::validation::require_rank ( std::size_t actual,
std::size_t expected,
const char * message )
inline

Requires a rank value to match an expected rank.

Parameters
actualActual rank.
expectedRequired rank.
messageError message used on mismatch.
Exceptions
Exceptions::DimensionErrorIf the ranks differ.

Definition at line 177 of file Validation.hpp.

Referenced by offset(), require_rank(), slice(), to_matrix(), and to_vector().

◆ require_same_shape()

template<typename Lhs, typename Rhs>
void stratax::core::validation::require_same_shape ( const Lhs & lhs,
const Rhs & rhs,
const char * message )

Requires two array-like objects to have identical size and shape.

Parameters
lhsLeft object.
rhsRight object.
messageError message used on mismatch.
Exceptions
Exceptions::ShapeErrorIf size or shape differ.

Definition at line 315 of file Validation.hpp.

References same_shape().

Referenced by require_same_arithmetic_shape().

◆ require_same_value_type()

template<typename Lhs, typename Rhs>
requires requires { typename Lhs::value_type; typename Rhs::value_type; }
void stratax::core::validation::require_same_value_type ( const Lhs & ,
const Rhs & ,
const char * message )

Requires two array-like objects to have the same value type.

Parameters
lhsLeft object.
rhsRight object.
messageError message used on mismatch.
Exceptions
Exceptions::TypeErrorIf the objects' normalized value_types differ.

Definition at line 67 of file Validation.hpp.

References require_type().

◆ require_type()

template<typename Actual, typename Expected>
void stratax::core::validation::require_type ( const char * message)

Requires a type to exactly match an expected type after cv/ref removal.

Template Parameters
ActualType being validated.
ExpectedRequired type.
Parameters
messageError message used on mismatch.
Exceptions
Exceptions::TypeErrorIf the normalized types differ.

Definition at line 27 of file Validation.hpp.

Referenced by require_same_value_type().

◆ same_shape()

template<typename Lhs, typename Rhs>
bool stratax::core::validation::same_shape ( const Lhs & lhs,
const Rhs & rhs )
nodiscard

Returns whether two array-like objects have identical size and shape.

Parameters
lhsLeft object.
rhsRight object.
Returns
true if size and shape match.

Definition at line 300 of file Validation.hpp.

Referenced by operator==(), and require_same_shape().