Scalar and array values
Value containers, array shapes, and concrete value types.
The ArrayValue<std::string> implementation specialization is omitted;
use the ArrayValue template reference and the ArrayValueStr type.
-
template<typename T>
using snt::val::ArrayStorage = std::vector<T, ArrayStorageAllocator<T>>
-
template<typename T, typename U>
bool snt::val::operator==(const ArrayStorageAllocator<T>&, const ArrayStorageAllocator<U>&) noexcept
-
template<typename T, typename U>
bool snt::val::operator!=(const ArrayStorageAllocator<T>&, const ArrayStorageAllocator<U>&) noexcept
-
template<typename T>
ArrayExpressionView<T> snt::val::array_expression(const T *data, std::size_t size, const Array::ShapeType &shape) Create a read-only expression over existing array data.
-
template<typename Input, typename Transform>
auto snt::val::map_array_expression(Input input, Transform transform) Append one elementwise operation to an expression pipeline.
-
template<typename Expression>
ArrayStorage<typename Expression::value_type> snt::val::evaluate_array_expression(const Expression &expression) Evaluate a composed elementwise expression into one owned output buffer.
-
using snt::val::Array::RangeType = std::vector<RangeStruct>
Array dimension ranges.
-
template<typename T>
class ArrayExpressionView Read-only view used as the input to a lazy elementwise expression.
Public Functions
-
inline std::size_t get_size() const
Number of source elements.
-
inline std::size_t get_size() const
-
template<typename T>
class ArrayStorageAllocator Allocator for array storage whose elements are assigned before they are read.
Default construction leaves scalar elements uninitialized. Array operation kernels write each output element before exposing the resulting value.
Public Functions
-
ArrayStorageAllocator() noexcept = default
-
template<typename U>
inline ArrayStorageAllocator(const ArrayStorageAllocator<U>&) noexcept
-
template<typename U>
struct rebind Public Types
-
using other = ArrayStorageAllocator<U>
-
using other = ArrayStorageAllocator<U>
-
ArrayStorageAllocator() noexcept = default
-
template<typename T>
class ArrayValue : public snt::val::BaseArrayValue<T> Numeric array value implementation for one scalar storage type.
Public Functions
-
inline ArrayValue(const T &val, const core::DataType dtype)
Create a scalar typed array value.
- Parameters:
val – Scalar value to store.
dtype – Data type tag exposed to callers.
-
inline ArrayValue(const std::vector<T> &arr, const Array::ShapeType &sh, const core::DataType dtype)
-
inline ArrayValue(const ArrayStorage<T> &arr, const Array::ShapeType &sh, const core::DataType dtype)
-
inline ArrayValue(ArrayStorage<T> &&arr, const Array::ShapeType &sh, const core::DataType dtype)
-
inline ArrayValue(const std::vector<T> &arr, const core::DataType dtype)
Create a one-dimensional typed array value.
- Parameters:
arr – Values to store; the shape is set to
{arr.size()}.dtype – Data type tag exposed to callers.
-
inline ArrayValue(const ArrayStorage<T> &arr, const core::DataType dtype)
-
inline ArrayValue(const BaseValue *other, const core::DataType dtype)
Construct a typed array by converting an existing VAL value.
- Parameters:
other – Source value to convert.
dtype – Data type tag for the new value.
-
inline virtual BaseValue::PointerType clone() const override
-
inline virtual BaseValue::PointerType cast_as(core::DataType dt) const override
Convert the value to the requested data type.
- Parameters:
dt – Target data type flag.
-
inline virtual BaseValue::PointerType slice(const Array::RangeType &slice) override
Return the requested array slice.
- Parameters:
slice – Ranges selecting the requested elements.
-
inline virtual BaseValue::PointerType math_sin() const override
-
inline virtual BaseValue::PointerType math_cos() const override
-
inline virtual BaseValue::PointerType math_tan() const override
-
inline virtual BaseValue::PointerType math_log() const override
-
inline virtual BaseValue::PointerType math_log10() const override
-
inline virtual BaseValue::PointerType math_sqrt() const override
-
inline virtual BaseValue::PointerType math_cbrt() const override
-
inline virtual BaseValue::PointerType math_exp() const override
-
inline virtual BaseValue::PointerType math_floor() const override
-
inline virtual BaseValue::PointerType math_ceil() const override
-
inline virtual BaseValue::PointerType math_round() const override
-
inline virtual BaseValue::PointerType math_abs() const override
-
inline virtual BaseValue::PointerType math_neg() const override
-
inline virtual BaseValue::PointerType math_add(const BaseValue *other) const override
Add another value.
- Parameters:
other – Other value used in the operation.
-
inline virtual void math_add_equal(const BaseValue *other) override
Add another value in place.
- Parameters:
other – Other value used in the operation.
-
inline virtual BaseValue::PointerType math_sub(const BaseValue *other) const override
Subtract another value.
- Parameters:
other – Other value used in the operation.
-
inline virtual void math_sub_equal(const BaseValue *other) override
Subtract another value in place.
- Parameters:
other – Other value used in the operation.
-
inline virtual BaseValue::PointerType math_inv() const override
-
inline virtual BaseValue::PointerType math_mul(const BaseValue *other) const override
Multiply by another value.
- Parameters:
other – Other value used in the operation.
-
inline virtual void math_mul_equal(const BaseValue *other) override
Multiply by another value in place.
- Parameters:
other – Other value used in the operation.
-
inline virtual BaseValue::PointerType math_div(const BaseValue *other) const override
Divide by another value.
- Parameters:
other – Other value used in the operation.
-
inline virtual void math_div_equal(const BaseValue *other) override
Divide by another value in place.
- Parameters:
other – Other value used in the operation.
-
inline virtual BaseValue::PointerType math_pow(const BaseValue *other) const override
Raise the value to an element-wise exponent value.
- Parameters:
other – Exponent value represented as another VAL object.
-
inline virtual BaseValue::PointerType math_pow(const double exp) const override
-
inline virtual BaseValue::PointerType math_max(const BaseValue *other) const override
Return the element-wise maximum with another value.
- Parameters:
other – Other value used in the operation.
-
inline virtual BaseValue::PointerType math_min(const BaseValue *other) const override
Return the element-wise minimum with another value.
- Parameters:
other – Other value used in the operation.
-
inline virtual BaseValue::PointerType math_inf() const override
-
inline virtual BaseValue::PointerType logical_and(const BaseValue *other) const override
Apply a logical AND operation.
- Parameters:
other – Other value used in the operation.
-
inline virtual BaseValue::PointerType logical_or(const BaseValue *other) const override
Apply a logical OR operation.
- Parameters:
other – Other value used in the operation.
-
inline virtual BaseValue::PointerType logical_not() const override
-
inline virtual bool any_of() const override
-
inline virtual bool all_of() const override
-
inline virtual bool none_of() const override
-
inline virtual bool is_unity() const override
-
inline ArrayValue(const T &val, const core::DataType dtype)
-
class ArrayValueBool : public snt::val::ArrayValue<uint8_t>
-
class ArrayValueChar : public snt::val::ArrayValue<int8_t>
-
class ArrayValueFloat128 : public snt::val::ArrayValue<long double>
-
class ArrayValueFloat32 : public snt::val::ArrayValue<double>
Public Functions
-
inline ArrayValueFloat32(const float &val)
-
inline ArrayValueFloat32(const std::vector<float> &arr)
-
inline void get_data(std::vector<float> &output_value) const
Copy the stored values into an output container.
- Parameters:
output_value – Destination container receiving the converted values.
-
inline ArrayValueFloat32(const float &val)
-
class ArrayValueFloat64 : public snt::val::ArrayValue<double>
Public Functions
-
inline ArrayValueFloat64(const double &val)
-
inline ArrayValueFloat64(ArrayStorage<double> &&arr, const Array::ShapeType &sh)
-
inline ArrayValueFloat64(const std::vector<double> &arr)
-
inline ArrayValueFloat64(const double &val)
-
class ArrayValueInt16 : public snt::val::ArrayValue<int64_t>
-
class ArrayValueInt32 : public snt::val::ArrayValue<int64_t>
-
class ArrayValueInt64 : public snt::val::ArrayValue<int64_t>
-
class ArrayValueInt8 : public snt::val::ArrayValue<int64_t>
Concrete value classes selected by the VAL data type.
-
class ArrayValueStr : public snt::val::ArrayValue<std::string>
Public Functions
-
inline ArrayValueStr(const std::string &val)
-
inline ArrayValueStr(const val::Array::StringType &arr, const val::Array::ShapeType &sh)
-
inline ArrayValueStr(const val::Array::StringType &arr)
-
inline ArrayValueStr(const std::string &val)
-
class ArrayValueUint16 : public snt::val::ArrayValue<uint64_t>
-
class ArrayValueUint32 : public snt::val::ArrayValue<uint64_t>
-
class ArrayValueUint64 : public snt::val::ArrayValue<uint64_t>
-
class ArrayValueUint8 : public snt::val::ArrayValue<uint64_t>
-
template<typename T>
class BaseArrayValue : public snt::val::BaseValue Base class for all array values
- Template Parameters:
T – Data type of a values Typed array storage and arithmetic implementation.
Subclassed by snt::val::ArrayValue< T >
Public Functions
-
inline BaseArrayValue(const T &val, const core::DataType dtype)
Base array value constructor from a scalar value
- Parameters:
val – Scalar value
dtype – Datatype flag
-
inline BaseArrayValue(const std::vector<T> &arr, const Array::ShapeType &sh, const core::DataType dtype)
Base array value constructor from a flattened vector of values and a shape
- Parameters:
arr – Vector of values
sh – Array shape
dtype – Datatype flag
-
inline BaseArrayValue(std::vector<T> &&arr, const Array::ShapeType &sh, const core::DataType dtype)
Take ownership of an already allocated value vector.
- Parameters:
arr – Owned flattened values to move into this array.
sh – Array shape.
dtype – Datatype flag.
-
inline BaseArrayValue(const ArrayStorage<T> &arr, const Array::ShapeType &sh, const core::DataType dtype)
Copy from storage produced by an array operation.
- Parameters:
arr – Array values to copy.
sh – Array shape.
dtype – Data type flag.
-
inline BaseArrayValue(ArrayStorage<T> &&arr, const Array::ShapeType &sh, const core::DataType dtype)
Take ownership of array-operation output storage without copying it.
- Parameters:
arr – Internal storage produced by an array operation.
sh – Array shape.
dtype – Data type flag.
-
inline BaseArrayValue(const BaseValue *other, const core::DataType dtype)
Base array value constructor from a BaseValue pointer
- Parameters:
other – Pointer to a BaseValue object
dtype – Datatype flag
-
inline virtual void print() override
Print object as a string
-
inline std::vector<T> get_values() const
Get copy of the array values
- Returns:
Flattened array of values
-
inline T get_value(const size_t index) const
Get copy of a particular value
- Parameters:
index – Index of a value
- Returns:
Single value
-
inline const T *get_data() const
Get read-only access to the internal data container.
- Returns:
Const pointer to the flattened array values.
-
inline virtual size_t get_size() const override
Get size of an array
- Returns:
Size of the flattened array value
-
inline virtual std::string to_string(const core::StringFormatType &format = core::StringFormatType()) const override
Return string representation of this array object
- Parameters:
format – Object with an output string format
- Returns:
String representation
-
inline virtual BaseValue::PointerType compare_equal(const BaseValue *other) const override
Compare this value for equality.
- Parameters:
other – Other value used in the operation.
-
inline virtual BaseValue::PointerType compare_not_equal(const BaseValue *other) const override
Compare this value for inequality.
- Parameters:
other – Other value used in the operation.
-
inline virtual BaseValue::PointerType compare_less(const BaseValue *other) const override
Compare this value as less than another value.
- Parameters:
other – Other value used in the operation.
-
inline virtual BaseValue::PointerType compare_greater(const BaseValue *other) const override
Compare this value as greater than another value.
- Parameters:
other – Other value used in the operation.
-
inline virtual BaseValue::PointerType compare_less_equal(const BaseValue *other) const override
Compare this value as less than or equal to another value.
- Parameters:
other – Other value used in the operation.
-
inline virtual BaseValue::PointerType compare_greater_equal(const BaseValue *other) const override
Compare this value as greater than or equal to another value.
- Parameters:
other – Other value used in the operation.
-
inline BaseValue::PointerType slice_value(const Array::RangeType &slice)
Create a value containing the selected array ranges.
- Parameters:
slice – Ranges selecting the requested elements.
-
inline virtual BaseValue::PointerType where(const BaseValue *condition, const BaseValue *other) const override
Select values according to a Boolean condition.
- Parameters:
condition – Boolean condition used to select the result.
other – Other value used in the operation.
Friends
-
inline friend std::ostream &operator<<(std::ostream &os, const ArrayValue<T> &val)
Print value into a string stream
- Parameters:
os – String stream
val – Value object
-
class BaseValue
Polymorphic base class for scalar and array values.
Subclassed by snt::val::BaseArrayValue< std::string >, snt::val::BaseArrayValue< uint8_t >, snt::val::BaseArrayValue< int8_t >, snt::val::BaseArrayValue< long double >, snt::val::BaseArrayValue< double >, snt::val::BaseArrayValue< int64_t >, snt::val::BaseArrayValue< uint64_t >, snt::val::BaseArrayValue< T >
Public Functions
-
inline BaseValue(core::DataType dt, Array::ShapeType sh)
Initialize a value with its data type and shape.
- Parameters:
dt – Target data type flag.
sh – Array shape.
-
virtual ~BaseValue() = default
-
virtual void print() = 0
-
virtual std::string to_string(const core::StringFormatType &format = core::StringFormatType()) const = 0
Format the object as text.
- Parameters:
format – Formatting options controlling the textual representation.
-
virtual size_t get_size() const = 0
-
virtual BaseValue::PointerType clone() const = 0
-
virtual BaseValue::PointerType cast_as(core::DataType dt) const = 0
Convert the value to the requested data type.
- Parameters:
dt – Target data type flag.
-
virtual BaseValue::PointerType slice(const Array::RangeType &slice) = 0
Return the requested array slice.
- Parameters:
slice – Ranges selecting the requested elements.
-
inline virtual BaseValue::PointerType math_add(const BaseValue *other) const
Add another value.
- Parameters:
other – Other value used in the operation.
-
inline virtual void math_add_equal(const BaseValue *other)
Add another value in place.
- Parameters:
other – Other value used in the operation.
-
inline virtual BaseValue::PointerType math_sub(const BaseValue *other) const
Subtract another value.
- Parameters:
other – Other value used in the operation.
-
inline virtual void math_sub_equal(const BaseValue *other)
Subtract another value in place.
- Parameters:
other – Other value used in the operation.
-
inline virtual BaseValue::PointerType math_inv() const
-
inline virtual BaseValue::PointerType math_mul(const BaseValue *other) const
Multiply by another value.
- Parameters:
other – Other value used in the operation.
-
inline virtual void math_mul_equal(const BaseValue *other)
Multiply by another value in place.
- Parameters:
other – Other value used in the operation.
-
inline virtual BaseValue::PointerType math_div(const BaseValue *other) const
Divide by another value.
- Parameters:
other – Other value used in the operation.
-
inline virtual void math_div_equal(const BaseValue *other)
Divide by another value in place.
- Parameters:
other – Other value used in the operation.
-
inline virtual BaseValue::PointerType math_sin() const
-
inline virtual BaseValue::PointerType math_cos() const
-
inline virtual BaseValue::PointerType math_tan() const
-
inline virtual BaseValue::PointerType math_log() const
-
inline virtual BaseValue::PointerType math_log10() const
-
inline virtual BaseValue::PointerType math_sqrt() const
-
inline virtual BaseValue::PointerType math_cbrt() const
-
inline virtual BaseValue::PointerType math_exp() const
-
inline virtual BaseValue::PointerType math_floor() const
-
inline virtual BaseValue::PointerType math_ceil() const
-
inline virtual BaseValue::PointerType math_round() const
-
inline virtual BaseValue::PointerType math_abs() const
-
inline virtual BaseValue::PointerType math_neg() const
-
inline virtual BaseValue::PointerType math_pow(const BaseValue *other) const
Raise the value to an element-wise exponent value.
- Parameters:
other – Exponent value represented as another VAL object.
-
inline virtual BaseValue::PointerType math_pow(const double exp) const
-
inline virtual BaseValue::PointerType math_max(const BaseValue *other) const
Return the element-wise maximum with another value.
- Parameters:
other – Other value used in the operation.
-
inline virtual BaseValue::PointerType math_min(const BaseValue *other) const
Return the element-wise minimum with another value.
- Parameters:
other – Other value used in the operation.
-
inline virtual BaseValue::PointerType math_inf() const
-
inline virtual BaseValue::PointerType compare_equal(const BaseValue *other) const
Compare this value for equality.
- Parameters:
other – Other value used in the operation.
-
inline virtual BaseValue::PointerType compare_not_equal(const BaseValue *other) const
Compare this value for inequality.
- Parameters:
other – Other value used in the operation.
-
inline virtual BaseValue::PointerType compare_less(const BaseValue *other) const
Compare this value as less than another value.
- Parameters:
other – Other value used in the operation.
-
inline virtual BaseValue::PointerType compare_greater(const BaseValue *other) const
Compare this value as greater than another value.
- Parameters:
other – Other value used in the operation.
-
inline virtual BaseValue::PointerType compare_less_equal(const BaseValue *other) const
Compare this value as less than or equal to another value.
- Parameters:
other – Other value used in the operation.
-
inline virtual BaseValue::PointerType compare_greater_equal(const BaseValue *other) const
Compare this value as greater than or equal to another value.
- Parameters:
other – Other value used in the operation.
-
inline virtual BaseValue::PointerType logical_and(const BaseValue *other) const
Apply a logical AND operation.
- Parameters:
other – Other value used in the operation.
-
inline virtual BaseValue::PointerType logical_or(const BaseValue *other) const
Apply a logical OR operation.
- Parameters:
other – Other value used in the operation.
-
inline virtual BaseValue::PointerType logical_not() const
-
virtual BaseValue::PointerType where(const BaseValue *condition, const BaseValue *other) const = 0
Select values according to a Boolean condition.
- Parameters:
condition – Boolean condition used to select the result.
other – Other value used in the operation.
-
virtual bool any_of() const = 0
-
virtual bool all_of() const = 0
-
virtual bool none_of() const = 0
-
virtual bool is_unity() const = 0
-
inline BaseValue(core::DataType dt, Array::ShapeType sh)
-
template<typename Input, typename Transform>
class MappedArrayExpression Elementwise expression that maps each input value without allocating an intermediate array.
Public Types
Public Functions
-
inline value_type operator[](std::size_t index) const
Evaluate the mapped value for one element.
-
inline std::size_t get_size() const
Number of elements in the expression.
-
inline value_type operator[](std::size_t index) const
-
struct RangeStruct
Array dimension range
Public Functions
-
inline bool operator==(const RangeStruct &other) const
Compare equalit of two ranges
- Parameters:
other – Other range that will be compared
-
inline bool operator==(const RangeStruct &other) const