lamppp
Loading...
Searching...
No Matches
Public Member Functions | Friends | List of all members
lmp::tensor::Tensor Class Reference

Main tensor object for Lamppp. More...

#include <tensor.hpp>

Public Member Functions

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)
 

Friends

class TensorOpFact
 
class detail::UnsafeTensorAccessor
 
std::ostream & operator<< (std::ostream &os, const Tensor &obj)
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ 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
dataFlat vector in row-major order
shapeDimensions, e.g. {28, 28} for MNIST
deviceDestination device (CPU/GPU)
dtypeElement type (defaults to float64)

Member Function Documentation

◆ 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: