Main tensor object for Lamppp.
More...
#include <tensor.hpp>
|
template<typename T > |
| Tensor (const std::vector< T > &data, const std::vector< size_t > &shape, DeviceType device=DeviceType::CPU, DataType dtype=DataType::Float64) |
| Construct a tensor from a vector.
|
|
void * | data () const noexcept |
|
DataType | type () const noexcept |
|
DeviceType | device () const noexcept |
|
const std::vector< size_t > & | shape () const noexcept |
|
const std::vector< detail::stride_t > & | strides () const noexcept |
|
size_t | numel () const noexcept |
|
template<typename T > |
std::vector< T > | to_vector () const |
|
Scalar | index (const std::vector< size_t > &idx) const |
|
Tensor | reshape (std::vector< size_t > new_shape) const |
|
Tensor | squeeze (size_t dim) const |
|
Tensor | expand_dims (size_t dim) const |
|
Tensor | to (DeviceType device) const |
|
void | copy (const Tensor &other) |
|
void | fill (Scalar item) |
|
|
class | TensorOpFact |
|
class | detail::UnsafeTensorAccessor |
|
std::ostream & | operator<< (std::ostream &os, const Tensor &obj) |
|
Main tensor object for Lamppp.
A thin, type-erased handle that shares ownership of an underlying TensorImpl
. Multiple Tensor
objects can point to the same storage, so no deep copies occur.
◆ Tensor()
template<typename T >
lmp::tensor::Tensor::Tensor |
( |
const std::vector< T > & |
data, |
|
|
const std::vector< size_t > & |
shape, |
|
|
DeviceType |
device = DeviceType::CPU , |
|
|
DataType |
dtype = DataType::Float64 |
|
) |
| |
|
inlineexplicit |
Construct a tensor from a vector.
- Parameters
-
data | Flat vector in row-major order |
shape | Dimensions, e.g. {28, 28} for MNIST |
device | Destination device (CPU/GPU) |
dtype | Element type (defaults to float64) |
◆ copy()
void lmp::tensor::Tensor::copy |
( |
const Tensor & |
other | ) |
|
- Note
- These functions modify the actual data in-place.
◆ reshape()
Tensor lmp::tensor::Tensor::reshape |
( |
std::vector< size_t > |
new_shape | ) |
const |
- Note
- These functions are similar to Pytorch in that they return a VIEW i.e. don't change the underlying storage
- See also
- storage.hpp
◆ to()
Tensor lmp::tensor::Tensor::to |
( |
DeviceType |
device | ) |
const |
- Note
to
is similar to a unary operation because it returns a completely new object (NOT a view, which is what Pytorch does).
◆ to_vector()
template<typename T >
std::vector< T > lmp::tensor::Tensor::to_vector |
( |
| ) |
const |
|
inline |
- Note
- These functions return an object representing the underlying data
The documentation for this class was generated from the following files:
- include/lamppp/tensor/tensor.hpp
- src/tensor/tensor.cpp