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
- Returns
shape –
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.
-
static bool validate_shape_and_stride(const ShapeType &shape, const ShapeType &stride)
Validate the shape and stride are compatible.
- Parameters
shape –
stride –
- Returns
- Returns
true
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
- Returns
stride –
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
- Parameters
- Returns
IndexT –
shape –
TensorSize
-
static void write_shape_to_stream(const ShapeType &shape, std::ostream &os)