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::StringType = std::vector<std::string>

Holds raw string values.

using snt::val::Array::RangeType = std::vector<RangeStruct>

Array dimension ranges.

using snt::val::Array::ShapeType = std::vector<size_t>

Array shape.

size_t snt::val::Array::max_range

Maximum size value indicates open range.

template<typename T>
class ArrayExpressionView

Read-only view used as the input to a lazy elementwise expression.

Public Types

using value_type = T

Public Functions

inline ArrayExpressionView(const T *values, std::size_t count, const Array::ShapeType &dimensions)
inline T operator[](std::size_t index) const

Read one source element.

inline std::size_t get_size() const

Number of source elements.

inline const Array::ShapeType &get_shape() const

Shape retained by the expression.

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 Types

using value_type = T
using is_always_equal = std::true_type

Public Functions

ArrayStorageAllocator() noexcept = default
template<typename U>
inline ArrayStorageAllocator(const ArrayStorageAllocator<U>&) noexcept
inline T *allocate(const std::size_t count)
inline void deallocate(T *pointer, const std::size_t count) noexcept
template<typename U, typename ...Args>
inline void construct(U *pointer, Args&&... args)
template<typename U>
inline void destroy(U *pointer) noexcept
template<typename U>
struct rebind

Public Types

using other = ArrayStorageAllocator<U>
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(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
class ArrayValueBool : public snt::val::ArrayValue<uint8_t>

Public Functions

inline ArrayValueBool(const bool &val)
inline ArrayValueBool(const std::vector<bool> &arr, const Array::ShapeType &sh)
inline ArrayValueBool(const std::vector<bool> &arr)
inline ArrayValueBool(const BaseValue *other)
class ArrayValueChar : public snt::val::ArrayValue<int8_t>

Public Functions

inline ArrayValueChar(const char &val)
inline ArrayValueChar(const std::vector<char> &arr, const Array::ShapeType &sh)
inline ArrayValueChar(const std::vector<char> &arr)
inline ArrayValueChar(const BaseValue *other)
class ArrayValueFloat128 : public snt::val::ArrayValue<long double>

Public Functions

inline ArrayValueFloat128(const long double &val)
inline ArrayValueFloat128(const std::vector<long double> &arr, const Array::ShapeType &sh)
inline ArrayValueFloat128(const std::vector<long double> &arr)
inline ArrayValueFloat128(const BaseValue *other)
class ArrayValueFloat32 : public snt::val::ArrayValue<double>

Public Functions

inline ArrayValueFloat32(const float &val)
inline ArrayValueFloat32(const std::vector<float> &arr, const Array::ShapeType &sh)
inline ArrayValueFloat32(const std::vector<float> &arr)
inline ArrayValueFloat32(const BaseValue *other)
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.

class ArrayValueFloat64 : public snt::val::ArrayValue<double>

Public Functions

inline ArrayValueFloat64(const double &val)
inline ArrayValueFloat64(const std::vector<double> &arr, const Array::ShapeType &sh)
inline ArrayValueFloat64(std::vector<double> &&arr, const Array::ShapeType &sh)
inline ArrayValueFloat64(ArrayStorage<double> &&arr, const Array::ShapeType &sh)
inline ArrayValueFloat64(const std::vector<double> &arr)
inline ArrayValueFloat64(const BaseValue *other)
class ArrayValueInt16 : public snt::val::ArrayValue<int64_t>

Public Functions

inline ArrayValueInt16(const int16_t &val)
inline ArrayValueInt16(const std::vector<int16_t> &arr, const Array::ShapeType &sh)
inline ArrayValueInt16(const std::vector<int16_t> &arr)
inline ArrayValueInt16(const BaseValue *other)
class ArrayValueInt32 : public snt::val::ArrayValue<int64_t>

Public Functions

inline ArrayValueInt32(const int32_t &val)
inline ArrayValueInt32(const std::vector<int32_t> &arr, const Array::ShapeType &sh)
inline ArrayValueInt32(const std::vector<int32_t> &arr)
inline ArrayValueInt32(const BaseValue *other)
class ArrayValueInt64 : public snt::val::ArrayValue<int64_t>

Public Functions

inline ArrayValueInt64(const int64_t &val)
inline ArrayValueInt64(const std::vector<int64_t> &arr, const Array::ShapeType &sh)
inline ArrayValueInt64(const std::vector<int64_t> &arr)
inline ArrayValueInt64(const BaseValue *other)
class ArrayValueInt8 : public snt::val::ArrayValue<int64_t>

Concrete value classes selected by the VAL data type.

Public Functions

inline ArrayValueInt8(const int8_t &val)
inline ArrayValueInt8(const std::vector<int8_t> &arr, const Array::ShapeType &sh)
inline ArrayValueInt8(const std::vector<int8_t> &arr)
inline ArrayValueInt8(const BaseValue *other)
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 BaseValue *other)
class ArrayValueUint16 : public snt::val::ArrayValue<uint64_t>

Public Functions

inline ArrayValueUint16(const uint16_t &val)
inline ArrayValueUint16(const std::vector<uint16_t> &arr, const Array::ShapeType &sh)
inline ArrayValueUint16(const std::vector<uint16_t> &arr)
inline ArrayValueUint16(const BaseValue *other)
class ArrayValueUint32 : public snt::val::ArrayValue<uint64_t>

Public Functions

inline ArrayValueUint32(const uint32_t &val)
inline ArrayValueUint32(const std::vector<uint32_t> &arr, const Array::ShapeType &sh)
inline ArrayValueUint32(const std::vector<uint32_t> &arr)
inline ArrayValueUint32(const BaseValue *other)
class ArrayValueUint64 : public snt::val::ArrayValue<uint64_t>

Public Functions

inline ArrayValueUint64(const uint64_t &val)
inline ArrayValueUint64(const std::vector<uint64_t> &arr, const Array::ShapeType &sh)
inline ArrayValueUint64(const std::vector<uint64_t> &arr)
inline ArrayValueUint64(const BaseValue *other)
class ArrayValueUint8 : public snt::val::ArrayValue<uint64_t>

Public Functions

inline ArrayValueUint8(const uint8_t &val)
inline ArrayValueUint8(const std::vector<uint8_t> &arr, const Array::ShapeType &sh)
inline ArrayValueUint8(const std::vector<uint8_t> &arr)
inline ArrayValueUint8(const BaseValue *other)
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 T *get_data()

Get pointer to the internal data container

Returns:

Pointer to the value data

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 Types

using PointerType = std::unique_ptr<BaseValue>

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.

inline Array::ShapeType get_shape() const
inline core::DataType get_dtype() const
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
template<typename Input, typename Transform>
class MappedArrayExpression

Elementwise expression that maps each input value without allocating an intermediate array.

Public Types

using value_type = std::decay_t<std::invoke_result_t<Transform, typename Input::value_type>>

Public Functions

inline MappedArrayExpression(Input source, Transform operation)
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 const Array::ShapeType &get_shape() const

Shape retained by the expression.

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

Public Members

size_t dmin

Dimension range minimum.

size_t dmax

Dimension range maximum.