|
NForge
Tensor library
|
#include <tensor_shape.h>
Public Member Functions | |
| Shape ()=default | |
| Default constructor. Creates an empty (0-dim) shape. | |
| Shape (const std::vector< size_t > &dims) | |
| From a vector of dimension sizes. Empty vector becomes {1}. | |
| Shape (const std::initializer_list< size_t > &dims) | |
| From an initializer list. Empty list becomes {1}. | |
| Shape (const TensorLayout &layout) | |
| From a layout's active rank dimensions. Empty layout becomes {1}. | |
| bool | operator== (const Tensor::Shape &other) const |
Equality, ignoring trailing ones. So {3, 4, 1} == {3, 4}. | |
| bool | operator!= (const Tensor::Shape &other) const |
| Negation of operator==. | |
| size_t | getNumDims () const |
| Returns the number of dimensions. | |
| size_t | getNumElements () const |
| Returns the product of all dimension sizes. | |
| size_t | getDim (size_t idx) const |
Returns the extent of dimension idx. | |
| bool | isScalar () const |
| True if the shape is {1}. | |
| Tensor::Shape | operator[] (size_t index) const |
| Tensor::Shape | operator[] (const std::vector< size_t > &position) const |
| Tensor::Shape | removeLeadingDimension () const |
| Removes the first dimension. Throws if the shape is empty. | |
| Tensor::Shape | getSlice (size_t start, size_t end) const |
| Returns shape with dimensions in [start, end). | |
| std::string | toString () const |
| Returns a string like "{ 3 4 5 }". | |
| std::vector< size_t > | toVector () const |
| Returns the dimension sizes as a vector. | |
| std::vector< size_t > | withoutTrailingOnes () const |
| Strips trailing 1s, always keeping at least one dimension. | |
| TensorLayout | toContiguousLayout () const |
| Creates a row-major contiguous layout (last dim stride 1). | |
| std::vector< size_t > | getContiguousStrides () const |
| Returns the row-major strides as a vector. | |
Describes the extent of each dimension of a Tensor.
Trailing ones are stripped during equality comparison, so {3, 4, 1} == {3, 4}.
| Tensor::Shape Tensor::Shape::operator[] | ( | const std::vector< size_t > & | position | ) | const |
Shape of the sub-tensor after indexing with a multi-dim position. Returns {1} if no dimensions remain.
| Tensor::Shape Tensor::Shape::operator[] | ( | size_t | index | ) | const |
Shape of the sub-tensor after indexing the first dimension. Returns {1} if already 1D.