Defined in File tensor_util.hpp
-
struct TensorUtils
Tensor Utilities.
NoteA tensor whose values are laid out in the storage starting from the rightmost dimension onward (that is, moving along rows for a 2D tensor) is defined as contiguous.
Public Types
-
using shape_type_t = std::vector<TensorIndex>
Public Static Functions
-
static void write_shape_to_stream(const shape_type_t &shape, std::ostream &os)
Write a formatted shape to a stream.
- Parameters
shape –
os –
-
static std::string shape_to_string(const shape_type_t &shape)
Convenience method to get a string from write_shape_to_stream.
- Parameters
shape –
- Returns
std::string
-
static void set_contiguous_stride(const std::vector<TensorIndex> &shape, std::vector<TensorIndex> &stride)
Set stride to be contiguous with respect to row-major layouts.
- Parameters
shape –
stride –
-
static bool has_contiguous_stride(const std::vector<TensorIndex> &shape, const shape_type_t &stride)
Determines if the tensor layout is both contiguous and ordered.
NoteA tensor whose values are laid out in the storage starting from the rightmost dimension onward (that is, moving along rows for a 2D tensor) is defined as contiguous.
-
static bool validate_shape_and_stride(const std::vector<TensorIndex> &shape, const std::vector<TensorIndex> &stride)
Validate the shape and stride are compatible.
- Parameters
shape –
stride –
- Returns
true
- Returns
false
-
template<typename IndexT, typename SrcIndexT = IndexT>
static inline std::vector<IndexT> get_element_stride(const std::vector<SrcIndexT> &stride) Returns a stride expressed in terms of elements given a stride expressed either in terms of bytes or elements.
- Parameters
stride –
- Returns
shape_type_t
-
using shape_type_t = std::vector<TensorIndex>