C++ API¶
Generated from the //! doc-comments in source/silt via Doxygen and
Breathe, one section per header, grouped the same way the source tree already
is (core/, op/) rather than by C++ namespace – namespaces don’t
otherwise carve up this library, so file/directory grouping is the natural
fit. Internal helpers (the detail namespaces, see Design Details) are
excluded throughout.
Core¶
The tensor/view type hierarchy, shape and slice arithmetic, dtype dispatch, and error types.
-
namespace silt¶
-
namespace error¶
-
template<typename From, typename To>
struct cast_error : public std::exception¶ -
Private Members
-
std::string msg¶
-
std::string msg¶
-
struct mismatch_size : public std::exception¶
Public Functions
-
inline mismatch_size(size_t want, size_t have)¶
-
inline const char *what() const noexcept override¶
Private Members
-
std::string msg¶
-
inline mismatch_size(size_t want, size_t have)¶
-
struct mismatch_type : public std::exception¶
Public Functions
-
inline const char *what() const noexcept override¶
Private Members
-
std::string msg¶
-
inline const char *what() const noexcept override¶
-
struct mismatch_host : public std::exception¶
Public Functions
-
inline const char *what() const noexcept override¶
Private Members
-
std::string msg¶
-
inline const char *what() const noexcept override¶
-
struct out_of_bounds : public std::exception¶
Public Functions
-
inline out_of_bounds(size_t index, size_t max)¶
-
inline const char *what() const noexcept override¶
Private Members
-
std::string msg¶
-
inline out_of_bounds(size_t index, size_t max)¶
-
struct bad_reshape : public std::exception¶
Public Functions
-
inline bad_reshape(size_t want, size_t have)¶
-
inline const char *what() const noexcept override¶
Private Members
-
std::string msg¶
-
inline bad_reshape(size_t want, size_t have)¶
-
struct unsupported_host : public std::exception¶
Public Functions
-
inline const char *what() const noexcept override¶
Private Members
-
std::string msg¶
-
inline const char *what() const noexcept override¶
-
template<typename From, typename To>
-
namespace error¶
-
namespace silt
Typedefs
-
typedef curandState rng¶
Enums
Functions
-
template<typename F, typename ...Args>
auto select(const silt::host_t host, F lambda, Args&&... args)¶
-
template<typename F, typename ...Args>
auto select(const silt::dtype type, F lambda, Args&&... args)¶ select accepts a type enumerator and a templated lambda, which it subsequently calls with a strict-typed evaluation.
this effectively instantiates every required template of the desired lambda expression, and executes the runtime selection.
-
template<typename ...Types>
struct dtype_list¶
-
template<>
struct hostdesc Public Static Attributes
-
static constexpr const char *name = "GPU"
-
static constexpr const char *name = "GPU"
-
template<typename Type, typename F>
struct type_op_error : public std::exception¶ -
Private Members
-
std::string msg¶
-
std::string msg¶
-
struct typedbase¶
Subclassed by silt::tensor_t< int64_t >, silt::tensor_t< T >, silt::view_t< T >
-
template<typename T>
struct typedesc¶ - #include <types.hpp>
typedesc is a generic compile-time type descriptor, which provides common properties like string names, or statically related types for specific purposes.
Public Types
-
typedef void value_t¶
-
typedef void value_t¶
-
template<>
struct typedesc¶ Public Types
-
typedef double value_t
Public Static Attributes
-
static constexpr const char *name = "double"
-
static constexpr dtype type = FLOAT64
-
typedef double value_t
-
template<>
struct typedesc Public Types
-
typedef float value_t
Public Static Attributes
-
static constexpr const char *name = "float"
-
static constexpr dtype type = FLOAT32
-
typedef float value_t
-
template<>
struct typedesc Public Types
-
typedef int value_t
Public Static Attributes
-
static constexpr const char *name = "int"
-
static constexpr dtype type = INT32
-
typedef int value_t
-
template<>
struct typedesc Public Types
-
typedef int64_t value_t
Public Static Attributes
-
static constexpr const char *name = "int64"
-
static constexpr dtype type = INT64
-
typedef int64_t value_t
-
typedef curandState rng¶
-
namespace silt
Typedefs
Variables
-
constexpr auto defaultp = glm::qualifier::packed_highp¶
-
constexpr auto defaultp = glm::qualifier::packed_highp¶
-
namespace silt
-
struct shape¶
- #include <shape.hpp>
shape is a D-dimensional compact extent, with indexing procedures for lookup into linearized tensors and views.
shape is intended for 2D and 3D applications, with a D of max 4, for 3D buffers of arbitrary depth.
Note that we use count_dim and count_elem methods so that higher nested dimensions can still contribute to the shape.
- Todo:
simplify flattening / unflattening procedures.
Public Types
-
using vec_t = glm::vec<4, int>¶
Public Functions
-
inline shape(int d0, int d1, int d2, int d3)¶
-
inline shape(int d0, int d1, int d2)¶
-
inline shape(int d0, int d1)¶
-
inline shape(int d0)¶
-
inline shape()¶
-
inline int dim() const¶
-
inline int64_t elem() const¶
-
inline int operator[](const size_t d) const¶
Dimension Subscript Operator.
-
inline void reshape(int d0, int d1 = 1, int d2 = 1, int d3 = 1)¶
Public Static Functions
-
struct shape¶
-
namespace silt
-
struct slice¶
- #include <slice.hpp>
slice is a type for index conversions that supports multi-dimensional slicing.
This type exists primarily so that tensor operations can be executed on subspaces. This is distinct from a shape because it performs additional computations to transform coordinates, whereas the regular shape assumes densely packed regular data.
- Todo:
Consider copy-free transpositions and other ordering implementations.
Public Types
-
using vec_t = glm::vec<4, int>¶
Public Functions
-
inline slice(int d0, int d1, int d2, int d3)¶
-
inline slice(int d0, int d1, int d2)¶
-
inline slice(int d0, int d1)¶
-
inline slice(int d0)¶
-
inline slice()¶
-
inline int dim() const¶
-
inline int64_t maxelem() const¶
-
inline int64_t elem() const¶
-
inline void reshape(int d0, int d1 = 1, int d2 = 1, int d3 = 1)¶
-
inline void flatten()¶
-
inline void index(const int dim, int offset, int stride, int extent)¶
Slice Index along individual Dimension. This is the single place slicing is validated and clamped – callers (e.g. the Python getitem binding) should unpack raw offset/stride/ extent and forward here rather than re-implementing this logic.
-
inline void reset()¶
-
inline int64_t transform(const int64_t index) const¶
Private Functions
-
struct slice¶
-
namespace silt
-
template<typename T>
struct view_t : public silt::typedbase¶ - #include <view_t.hpp>
view_t is a strict-typed, lightweight data-view for vectorized memory reads.
A view_t is intended to be constructed on the fly from another data-type, so that any memory read operations from the view are compiler optimized.
The view is non-owning and shares its underlying memory, so that it can be passed cheaply while the owning data-types remaing untouched.
A check to see whether the construction of a view is valid should be done at construction time, and not at lookup time, to guarantee performance.
Public Functions
-
inline view_t()¶
-
inline size_t elem() const¶
Number of Elements.
-
inline T operator[](const size_t index) const noexcept¶
Const Subscript Operator: With Slice Transform!
-
inline T &operator[](const size_t index) noexcept¶
Non-Const Subscript Operator: With Slice Transform!
-
inline void reshape(int d0, int d1, int d2, int d3)¶
-
inline void index(const int dim, const int offset, const int stride, const int extent)¶
-
inline void reset()¶
-
inline view_t()¶
-
template<typename T>
-
namespace silt
-
struct view¶
- #include <view.hpp>
view is a tag-poylymorphic view_t wrapper type.
Public Functions
-
view() = default¶
-
template<typename T>
inline view(const silt::view_t<T> &view, silt::tensor owner = silt::tensor())¶ Strict-Typed Tensor Copy Constructor.
owner, if given, is kept alive for as long as this view is – see the non-owning-view lifetime note on view_t in view_t.hpp. Defaults to nothing, preserving the non-owning behaviour for internal constructions that don’t need it (e.g. views never handed to Python).
-
template<typename T>
inline view(silt::view_t<T> &&ten, silt::tensor owner = silt::tensor())¶ Strict-Typed Tensor Move Constructor.
-
inline ~view()¶
-
template<typename T>
inline const view_t<T> &as() const noexcept¶ Polymorphic Strict-Type Cast (Const).
-
inline size_t elem() const¶
-
inline void *data()¶
-
inline void reshape(int d0, int d1, int d2, int d3)¶
-
inline void index(const int dim, const int offset, const int stride, const int extent)¶
-
inline void reset()¶
Private Functions
-
inline void clear()¶
Private Members
-
silt::tensor _owner¶
Keeps a slice’s source tensor alive by refcount (see the constructor above). A silt::tensor, not std::shared_ptr, for the same DLL-boundary reason tensor itself avoids std::shared_ptr (see its comment above).
-
view() = default¶
-
struct view¶
-
namespace silt
-
template<typename T>
struct tensor_t : public silt::typedbase¶ - #include <tensor_t.hpp>
tensor_t<T> is a strict-typed, owning raw-data extent.
tensor_t<T> is reference counting with correct move semantics, making copying and moving tensor_t<T> values cheap and easy.
tensor_t<T> data can be on the CPU or on the GPU.
Public Functions
-
inline tensor_t()¶
Default Empty Constructor.
-
inline ~tensor_t()¶
-
inline tensor_t &operator=(const tensor_t<T> &other)¶
Copy Assignment Operator (Reference Increment).
-
inline size_t elem() const¶
Number of Elements.
-
inline size_t size() const¶
Total Size in Bytes.
-
inline size_t refs() const¶
Reference Count (0 if non-owning).
-
inline void reshape(const int d0 = 1, const int d1 = 1, const int d2 = 1, const int d3 = 1)¶
-
inline void flatten()¶
-
void to(const host_t target)¶
In-Place Transfer to
target– the guard logic (no-op if already ontarget, or if there is nothing to move) lives here; to_cpu()/ to_gpu() are simple aliases for it.
-
void to_cpu()¶
Alias for to(CPU).
-
void to_gpu()¶
Alias for to(GPU).
Public Members
-
size_t *_refs = NULL¶
Pointer to Reference Count.
-
inline tensor_t()¶
-
template<typename T>
-
namespace silt
-
struct tensor¶
- #include <tensor.hpp>
tensor is a tag-poylymorphic tensor_t wrapper type.
This type stores a pointer to a tensor_t<T>, which it can cast to the appropriate type when required.
Because of the dll exported type, tensor cannot use std::shared pointer, which is why we do the funny business with the move and copy constructors:
Public Functions
-
tensor() = default¶
-
template<typename T>
inline tensor(const silt::tensor_t<T> &ten)¶ Strict-Typed Tensor Copy Constructor.
-
inline ~tensor()¶
-
template<typename T>
inline const tensor_t<T> &as() const noexcept¶ Polymorphic Strict-Type Cast (Const).
-
inline size_t elem() const¶
-
inline size_t size() const¶
-
inline size_t refs() const¶
-
inline void *data()¶
-
inline void reshape(const int d0 = 1, const int d1 = 1, const int d2 = 1, const int d3 = 1)¶
-
inline void flatten()¶
Private Functions
-
inline void clear()¶
-
tensor() = default¶
-
struct tensor¶
-
namespace silt
Enums
-
namespace silt
-
namespace op¶
-
namespace op¶
Operations¶
Tensor operations, dispatched through silt::op – also the extension
point user code hooks into to add new operations (see Extending silt).
-
namespace silt
Functions
-
namespace silt
-
Functions
-
index_t index_slice(const silt::slice &slice)¶
Flat indices of every cell a slice (offset/stride/extent per dimension) visits, in slice order. Enumeration, not compaction – every candidate is included, so this needs no predicate.
-
template<typename T>
constexpr T positive_infinity()¶ +infinity for T (numeric_limits::max() for an integral T, which has no infinity).
-
template<typename T>
constexpr T negative_infinity()¶ -infinity for T (numeric_limits::min() for an integral T, which has no infinity).
-
template<typename T>
index_t index_range(const tensor_t<T> &data, const T lo, const T hi)¶ Selects by value rather than position: lo <= data[n] <= hi.
-
template<typename T>
index_t index_greater(const tensor_t<T> &data, const T value)¶ Alias for index_range(data, value, +infinity) – data[n] >= value.
-
template<typename T>
index_t index_lesser(const tensor_t<T> &data, const T value)¶ Alias for index_range(data, -infinity, value) – data[n] <= value.
-
template<typename T>
index_t index_match(const tensor_t<T> &data, const T value)¶ Alias for index_range(data, value, value) – data[n] == value.
-
template<typename T>
void indexed_set(tensor_t<T> lhs, const T rhs, const index_t ind)¶ lhs[i] = rhs, for i in ind.
-
template<typename T>
void indexed_add(tensor_t<T> lhs, const T rhs, const index_t ind)¶ lhs[i] += rhs, for i in ind.
-
template<typename T>
void indexed_add(tensor_t<T> lhs, const tensor_t<T> rhs, const index_t ind)¶ lhs[i] += rhs[i], for i in ind.
-
template<typename T>
void indexed_multiply(tensor_t<T> lhs, const T rhs, const index_t ind)¶ lhs[i] *= rhs, for i in ind.
-
template<typename T>
void indexed_multiply(tensor_t<T> lhs, const tensor_t<T> rhs, const index_t ind)¶ lhs[i] *= rhs[i], for i in ind.
-
template<typename T>
void indexed_divide(tensor_t<T> lhs, const T rhs, const index_t ind)¶ lhs[i] /= rhs, for i in ind.
-
template<typename T>
void indexed_divide(tensor_t<T> lhs, const tensor_t<T> rhs, const index_t ind)¶ lhs[i] /= rhs[i], for i in ind.
-
template<typename T>
void indexed_mix(tensor_t<T> lhs, const tensor_t<T> rhs, const index_t ind, const float w)¶ lhs[i] = mix(lhs[i], rhs[i], w), for i in ind.
-
template<typename T>
T indexed_sum(const tensor_t<T> lhs, const index_t ind)¶ Sum of lhs[i], for i in ind.
-
template<typename T>
T indexed_mean(const tensor_t<T> lhs, const index_t ind)¶ Mean of lhs[i], for i in ind.
-
template<typename T>
T indexed_min(const tensor_t<T> lhs, const index_t ind)¶ Min of lhs[i], for i in ind. NaN-skipping, like the dense min().
-
template<typename T>
T indexed_max(const tensor_t<T> lhs, const index_t ind)¶ Max of lhs[i], for i in ind. NaN-skipping, like the dense max().
-
struct box_predicate¶
- #include <indexed.hpp>
All cells in the half-open box [lo, hi).
Public Functions
-
inline bool operator()(const int64_t n) const¶
-
inline bool operator()(const int64_t n) const¶
-
struct polygon_predicate¶
- #include <indexed.hpp>
Point-in-polygon (even-odd / ray-casting rule).
Public Functions
-
inline bool operator()(const int64_t n) const¶
-
inline bool operator()(const int64_t n) const¶
-
index_t index_slice(const silt::slice &slice)¶
-
namespace silt
Functions
-
void seed(tensor_t<rng> &buf, const size_t seed, const size_t offset)¶
Seed a Random Number Generator Tensor.
-
tensor_t<float> sample_uniform(tensor_t<rng> &buf)¶
Generate Uniform Samples from a Random Number Generator Tensor.
-
void seed(tensor_t<rng> &buf, const size_t seed, const size_t offset)¶