Struct TensorUtils
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 Static Functions
-
static void write_shape_to_stream(const ShapeType &shape, std::ostream &os)
Write a formatted shape to a stream.
- Parameters
shape –
os –
-
static std::string shape_to_string(const ShapeType &shape)
Convenience method to get a string from write_shape_to_stream.
- Parameters
shape –
- Returns
std::string
-
static void set_contiguous_stride(const ShapeType &shape, ShapeType &stride)
Set stride to be contiguous with respect to row-major layouts.
- Parameters
shape –
stride –
-
static bool has_contiguous_stride(const ShapeType &shape, const ShapeType &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 ShapeType &shape, const ShapeType &stride)
Validate the shape and stride are compatible.
- Parameters
shape –
stride –
- Returns
true
- Returns
false
-
template<typename IndexT = TensorIndex, 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
ShapeType
-
template<typename IndexT>
static inline TensorSize get_elem_count(const std::vector<IndexT> &shape) Compute the number of elements in a tensor based on the shape.
- Template Parameters
IndexT –
- Parameters
shape –
- Returns
TensorSize
-
static void write_shape_to_stream(const ShapeType &shape, std::ostream &os)