|
| Tensor (type dtype, Shape shape) |
| Constructs an uninitialized tensor with default (contiguous) strides.
|
|
| Tensor (type dtype, Shape shape, Strides strides, std::ptrdiff_t offset=0) |
| Constructs an uninitialized tensor with custom strides and offset.
|
|
template<Expression Expression> |
| Tensor (const Expression &expression) |
| Constructs a tensor by forwarding an Expression -like object.
|
|
template<Expression Expression> |
Tensor & | operator= (const Expression &expression) |
| Assigns the result of an expression to the tensor.
|
|
template<typename T > |
| Tensor (std::initializer_list< T > const &values) |
| Constructs a 1D tensor from an initializer list.
|
|
template<typename T > |
| Tensor (std::initializer_list< std::initializer_list< T > > const &values) |
| Constructs a 2D tensor from a nested initializer list.
|
|
template<typename T > |
| Tensor (std::initializer_list< std::initializer_list< std::initializer_list< T > > > const &values) |
| Constructs a 3D tensor from a triple-nested initializer list.
|
|
template<typename T > |
| Tensor (std::initializer_list< std::initializer_list< std::initializer_list< std::initializer_list< T > > > > const &values) |
| Constructs a 4D tensor from a quadruple-nested initializer list.
|
|
template<typename T > |
Tensor & | operator= (std::initializer_list< T > const &values) |
| Assigns values to a 1D tensor from an initializer list.
|
|
template<typename T > |
Tensor & | operator= (std::initializer_list< std::initializer_list< T > > const &values) |
| Assigns values to a 2D tensor from a nested initializer list.
|
|
template<typename T > |
Tensor & | operator= (std::initializer_list< std::initializer_list< std::initializer_list< std::initializer_list< T > > > > const &values) |
| Assigns values to a 4D tensor from a quadruple-nested initializer list.
|
|
| Tensor (type dtype, Shape shape, std::ptrdiff_t offset, std::shared_ptr< Buffer > storage) |
|
| Tensor (type dtype, Shape shape, Strides strides, std::ptrdiff_t offset, std::shared_ptr< Buffer > storage) |
|
Node * | node () const |
|
|
type | dtype () const |
| Returns the tensor's data type.
|
|
rank_type | rank () const |
| Returns the number of dimensions (rank) of the tensor.
|
|
Shape const & | shape () const |
| Returns the tensor's shape (dimension sizes per dimension).
|
|
Shape::size_type | size (int dimension) const |
| Returns the tensor's size at a given dimension.
|
|
Strides const & | strides () const |
| Returns the tensor's strides (step sizes per dimension).
|
|
std::ptrdiff_t | offset () const |
| Returns the offset of the tensor in the current buffer.
|
|
std::size_t | nbytes () const |
| Returns the total number of bytes occupied by the tensor's elements.
|
|
bool | is_contiguous () const |
| Returns whether the tensor's elements are in contiguous layout or not.
|
|
Tensor & | forward () |
| Returns a reference to this tensor (const-qualified).
|
|
Tensor const & | forward () const |
| Returns a reference to this tensor (non-const).
|
|
|
void | initialize (Environment environment=Host{}) const |
| Allocates the memory buffer for the tensor.
|
|
std::byte * | bytes () const |
| Returns a pointer to the beginning of the tensor's data (accounting for offset).
|
|
bool | is_initialized () const |
| Checks whether the tensor has been initialized with memory.
|
|
Environment const & | environment () const |
| Returns a reference to the environment variant used to allocate this tensor's buffer.
|
|
|
template<Integral Index> |
auto | operator[] (Index index) const |
| Indexes the tensor with a single integral index.
|
|
auto | operator[] (indexing::Range range) const |
| Indexes the tensor with a Range object.
|
|
template<class ... Indexes> |
auto | operator[] (Indexes... indexes) const |
| Indexes the tensor with multiple indices (e.g., integers or ranges).
|
|
auto | transpose (int first=-1, int second=-2) const |
| Returns a view of the tensor with two dimensions transposed.
|
|
template<Integral ... Indexes> |
auto | permute (Indexes... indexes) const |
| Returns a view of the tensor with dimensions permuted.
|
|
template<Integral ... Sizes> |
auto | view (Sizes... sizes) const |
| Returns a view of the tensor with given sizes.
|
|
auto | squeeze () const |
| Returns a view of the tensor with all dimensions of size 1 removed.
|
|
template<Integral... Axes> |
auto | unsqueeze (Axes... axes) |
| Returns a view of the tensor with a dimension of size 1 inserted at the given axis.
|
|
A multidimensional, strided tensor data structure.
The Tensor
class is the primary data structure in the Tannic Tensor Library. It represents a dynamic typed intention of a computation. It supports slicing, transposition, and expression composition.
Evaluation Mode:
- Tensors are currently eager: expressions assigned to them are immediately evaluated and stored.
- A lazy
constexpr
evaluation mode is planned for future versions, enabling compile-time computational graphs.
Memory:
- Host and Device (e.g., CUDA) allocations are supported using environments like
Host()
or Device()
.
- Memory must be explicitly allocated via
initialize(Host())
or initialize(Device()) but maybe removed in the future.
Example:
X[1,0] = 3;
X[1,1] = 4;
Y[0,0] = 4;
Y[0,1] = 6;
std::cout <<
log(X) + Y * Y -
exp(X) +
matmul(X, Y.transpose());
A multidimensional, strided tensor data structure.
Definition: tensor.hpp:105
void initialize(Environment environment=Host{}) const
Allocates the memory buffer for the tensor.
constexpr auto exp(Operand &&operand)
Creates a lazy-evaluated exponential function expression.
Definition: functions.hpp:247
constexpr auto log(Operand &&operand)
Creates a lazy-evaluated natural logarithm expression.
Definition: functions.hpp:235
Definition: buffer.hpp:41
constexpr auto matmul(Multiplicand &&multiplicand, Multiplier &&multiplier, double scale=1.0)
Matrix multiplication convenience function.
Definition: transformations.hpp:578
Represents a half-open interval [start, stop) for slicing.
Definition: indexing.hpp:56
This example demonstrates eager initialization, advanced indexing, broadcasting, and composite expression evaluation.
- Warning
- : Explicit inialization required for now but maybe removed in the future. If not properly initialized the tensors may segfault instead of throwing assertion error. This will be fixed when resources can be infered at the end of a templated expression.