libdl  0.0.1
Simple yet powerful deep learning
Loading...
Searching...
No Matches
dl::TensorImpl Class Referenceabstract
Collaboration diagram for dl::TensorImpl:

Public Member Functions

TensorPtr to (Device const &other) const noexcept
 Creates a copy of this tensor on the requested device and returns a pointer to it. If the new device is the same as the device the tensor is already on, the tensor will be copied.
 
Device const & device () const noexcept
 Returns the device this tensor is stored on.
 
void setRequiresGrad (bool requiresGrad) noexcept
 Set this tensors requirements for a gradient.
 
bool requiresGrad () const noexcept
 Returns true iff this tensor requires a gradient, i.e., needs to be updated during backpropagation.
 
void backward (bool enableAutodiff=false) noexcept
 
const TensorPtrgradient () const noexcept
 
void discardGradient () noexcept
 
virtual std::ostreamwriteToStream (std::ostream &stream) const noexcept=0
 
virtual bool operator== (const TensorPtr &other) const noexcept=0
 
virtual bool allclose (const TensorPtr &other, float rtol=1e-5, float atol=1e-8) const noexcept=0
 
virtual TensorPtr add (const TensorPtr &other) const noexcept=0
 
virtual TensorPtr sub (const TensorPtr &other) const noexcept=0
 
virtual TensorPtr mul (const TensorPtr &other) const noexcept=0
 
virtual TensorPtr div (const TensorPtr &other) const noexcept=0
 
virtual TensorPtr fma (const TensorPtr &factor, const TensorPtr &summand) const noexcept=0
 Performs "fused multiply and add".
 
virtual TensorPtr matmul (const TensorPtr &other) const noexcept=0
 
virtual TensorPtr transpose (std::vector< size_t > &&permutation) const noexcept=0
 
virtual TensorPtr pow (float exponent) const noexcept=0
 
virtual TensorPtr exp () const noexcept=0
 
virtual TensorPtr log () const noexcept=0
 
virtual TensorPtr sqrt () const noexcept=0
 
virtual TensorPtr rsqrt () const noexcept=0
 
virtual TensorPtr mean () const noexcept=0
 
virtual TensorPtr mean (int dim, bool keepdim) const noexcept=0
 
virtual TensorPtr sum () const noexcept=0
 
virtual TensorPtr sum (int dim, bool keepdim) const noexcept=0
 
virtual TensorPtr min () const noexcept=0
 
virtual TensorPtr min (int dim, bool keepdim) const noexcept=0
 
virtual TensorPtr min (const TensorPtr &other) const noexcept=0
 Computes the element-wise minimum between this tensor and the other.
 
virtual TensorPtr max () const noexcept=0
 
virtual TensorPtr max (int dim, bool keepdim) const noexcept=0
 
virtual TensorPtr max (const TensorPtr &other) const noexcept=0
 
virtual TensorPtr var (DOF dof) const noexcept=0
 
virtual TensorPtr var (int dim, DOF dof) const noexcept=0
 
virtual TensorPtr erf () const noexcept=0
 
virtual void mul_inplace (const TensorPtr &other) noexcept=0
 
virtual void reshape (SShape shape) noexcept=0
 Reshapes the tensor to fit the specified size.
 
virtual TensorPtr clone () const noexcept=0
 
virtual Shape shape () const noexcept=0
 
virtual size_t shape (int dim) const noexcept=0
 
size_t numDim () const noexcept
 
virtual TensorPtr flatten () const noexcept=0
 
virtual size_t toBytes (char *buffer, size_t buflen) const noexcept=0
 Writes this tensor's data into the byte array.
 

Public Attributes

GradFn gradfn = nullptr
 
TensorPtr grad = nullptr
 

Protected Member Functions

 TensorImpl (Device const &device, bool requiresGrad) noexcept
 

Detailed Description

Definition at line 13 of file tensorimpl.hpp.

Member Function Documentation

◆ device()

Device const & dl::TensorImpl::device ( ) const
noexcept

Returns the device this tensor is stored on.

Returns
The device this tensor is stored on.
See also
TensorImpl::to(const Device& other)

◆ discardGradient()

void dl::TensorImpl::discardGradient ( )
inlinenoexcept

Definition at line 63 of file tensorimpl.hpp.

63 {
64 gradfn = nullptr;
65 grad = nullptr;
66 }

◆ fma()

virtual TensorPtr dl::TensorImpl::fma ( const TensorPtr factor,
const TensorPtr summand 
) const
pure virtualnoexcept

Performs "fused multiply and add".

Multiplies this tensor by factor and adds summand to the result. This specialized function exists since some devices (e.g., CUDA and some SIMD instruction sets) provide such a function.

Parameters
factorthe factor to multiply with this tensor.
summandthe summand to add to the product of this with factor.
Returns
the result.

◆ gradient()

const TensorPtr & dl::TensorImpl::gradient ( ) const
inlinenoexcept

Definition at line 62 of file tensorimpl.hpp.

62{ return grad; }

◆ min()

virtual TensorPtr dl::TensorImpl::min ( const TensorPtr other) const
pure virtualnoexcept

Computes the element-wise minimum between this tensor and the other.

Parameters
other
Returns
TensorPtr

◆ numDim()

size_t dl::TensorImpl::numDim ( ) const
inlinenoexcept

Definition at line 133 of file tensorimpl.hpp.

133{ return shape().size(); }
T size(T... args)

◆ requiresGrad()

bool dl::TensorImpl::requiresGrad ( ) const
noexcept

Returns true iff this tensor requires a gradient, i.e., needs to be updated during backpropagation.

Returns
True iff this tensor requires a gradient, i.e., needs to be updated during backpropagation.
See also
TensorImpl::setRequiresGrad()

◆ reshape()

virtual void dl::TensorImpl::reshape ( SShape  shape)
pure virtualnoexcept

Reshapes the tensor to fit the specified size.

At most one of the entries in the shape may be -1 and will then be inferred by the remaining shape. The element count may not change through reshaping.

Parameters
shapeThe new shape for the tensor.

◆ setRequiresGrad()

void dl::TensorImpl::setRequiresGrad ( bool  requiresGrad)
noexcept

Set this tensors requirements for a gradient.

Parameters
requiresGradwether the tensor requires a gradient.
See also
TensorImpl::requiresGrad()

◆ to()

TensorPtr dl::TensorImpl::to ( Device const &  other) const
noexcept

Creates a copy of this tensor on the requested device and returns a pointer to it. If the new device is the same as the device the tensor is already on, the tensor will be copied.

Parameters
otherThe device to copy the tensor onto.
Returns
The newly created tensor on the specified device.
See also
TensorImpl::device()

◆ toBytes()

virtual size_t dl::TensorImpl::toBytes ( char *  buffer,
size_t  buflen 
) const
pure virtualnoexcept

Writes this tensor's data into the byte array.

Parameters
bufferThe byte to write to. If it is a nullpointer, no data will be written but the number of bytes that the tensor uses will still be returned.
buflenThe maximum number of bytes to write.
Returns
The number of bytes that were written. If the buffer was too small, 0 is returned.

Member Data Documentation

◆ grad

TensorPtr dl::TensorImpl::grad = nullptr

Definition at line 22 of file tensorimpl.hpp.

◆ gradfn

GradFn dl::TensorImpl::gradfn = nullptr

Definition at line 21 of file tensorimpl.hpp.


The documentation for this class was generated from the following file: