Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TMVA::DNN::TCpuTensor< AFloat > Class Template Reference

template<typename AFloat>
class TMVA::DNN::TCpuTensor< AFloat >

Definition at line 50 of file CpuTensor.h.

Public Types

using Matrix_t = TCpuMatrix<AFloat>
 
using MemoryLayout = TMVA::DNN::MemoryLayout
 
using Scalar_t = AFloat
 
using Shape_t = std::vector<std::size_t>
 

Public Member Functions

 TCpuTensor ()
 
 TCpuTensor (AFloat *data, const Shape_t &shape, MemoryLayout memlayout=MemoryLayout::ColumnMajor)
 
 TCpuTensor (const TCpuBuffer< AFloat > &buffer, Shape_t shape, MemoryLayout memlayout=MemoryLayout::ColumnMajor)
 constructors from a TCpuBuffer and a shape
 
 TCpuTensor (const TCpuMatrix< AFloat > &matrix, size_t dim=3, MemoryLayout memlayout=MemoryLayout::ColumnMajor)
 constructors from a TCpuMatrix.
 
 TCpuTensor (Shape_t shape, MemoryLayout memlayout=MemoryLayout::ColumnMajor)
 constructors from a shape.
 
 TCpuTensor (size_t bsize, size_t depth, size_t height, size_t width, MemoryLayout memlayout=MemoryLayout::ColumnMajor)
 constructors from batch size, depth, height, width
 
 TCpuTensor (size_t bsize, size_t depth, size_t hw, MemoryLayout memlayout=MemoryLayout::ColumnMajor)
 constructors from batch size, depth, height*width
 
 TCpuTensor (size_t n, size_t m, MemoryLayout memlayout=MemoryLayout::ColumnMajor)
 constructors from n m
 
 TCpuTensor (std::shared_ptr< TCpuBuffer< AFloat > > container, Shape_t shape, MemoryLayout layout)
 Construct a tensor sharing the given buffer.
 
TCpuTensor< AFloat > At (size_t i)
 
TCpuTensor< AFloat > At (size_t i) const
 
size_t GetBufferUseCount () const
 
std::shared_ptr< TCpuBuffer< AFloat > > GetContainer ()
 
const std::shared_ptr< TCpuBuffer< AFloat > > GetContainer () const
 
size_t GetCSize () const
 
AFloat * GetData ()
 
const AFloat * GetData () const
 
TCpuBuffer< AFloat > & GetDeviceBuffer ()
 
const TCpuBuffer< AFloat > & GetDeviceBuffer () const
 
size_t GetFirstSize () const
 
size_t GetHSize () const
 
MemoryLayout GetLayout () const
 
TCpuMatrix< AFloat > GetMatrix () const
 
MemoryLayout GetMemoryLayout () const
 
size_t GetNcols () const
 
size_t GetNoElements () const
 
size_t GetNrows () const
 
AFloat * GetRawDataPointer ()
 Return raw pointer to the elements stored contiguously in column-major order.
 
const AFloat * GetRawDataPointer () const
 
const Shape_t & GetShape () const
 
std::size_t GetSize () const
 
const Shape_t & GetStrides () const
 
size_t GetWSize () const
 
template<typename Function_t >
void Map (Function_t &f)
 Map the given function over the matrix elements.
 
template<typename Function_t >
void MapFrom (Function_t &f, const TCpuTensor< AFloat > &A)
 Same as maps but takes the input values from the tensor A and writes the results in this tensor.
 
 operator TMatrixT< AFloat > () const
 Convert to a TMatrixT<AFloat_t> object.
 
AFloat & operator() (size_t i, size_t j)
 
AFloat operator() (size_t i, size_t j) const
 
AFloat & operator() (size_t i, size_t j, size_t k)
 
AFloat operator() (size_t i, size_t j, size_t k) const
 
TCpuMatrix< AFloat > operator[] (size_t i) const
 
void Print (const char *name="Tensor") const
 
void PrintShape (const char *name="Tensor") const
 
TCpuTensor< AFloat > Reshape (Shape_t shape) const
 
void ReshapeInplace (const Shape_t &shape)
 Reshape tensor in place.
 
void Zero ()
 

Static Private Member Functions

static Shape_t ComputeStridesFromShape (const Shape_t &shape, MemoryLayout layout)
 Compute strides from a shape vector.
 
static std::size_t GetSizeFromShape (const Shape_t &shape)
 Compute the total number of elements from a shape vector.
 

Private Attributes

std::shared_ptr< TCpuBuffer< AFloat > > fContainer
 Buffer owning the data.
 
AFloat * fData = nullptr
 Pointer to the first element.
 
MemoryLayout fLayout
 Memory layout of the tensor.
 
Shape_t fShape
 Shape of the tensor.
 
std::size_t fSize
 Total number of elements.
 
Shape_t fStrides
 Strides of the tensor.
 

Friends

class TCpuMatrix< AFloat >
 

#include <TMVA/DNN/Architectures/Cpu/CpuTensor.h>

Member Typedef Documentation

◆ Matrix_t

template<typename AFloat >
using TMVA::DNN::TCpuTensor< AFloat >::Matrix_t = TCpuMatrix<AFloat>

Definition at line 57 of file CpuTensor.h.

◆ MemoryLayout

template<typename AFloat >
using TMVA::DNN::TCpuTensor< AFloat >::MemoryLayout = TMVA::DNN::MemoryLayout

Definition at line 56 of file CpuTensor.h.

◆ Scalar_t

template<typename AFloat >
using TMVA::DNN::TCpuTensor< AFloat >::Scalar_t = AFloat

Definition at line 58 of file CpuTensor.h.

◆ Shape_t

template<typename AFloat >
using TMVA::DNN::TCpuTensor< AFloat >::Shape_t = std::vector<std::size_t>

Definition at line 55 of file CpuTensor.h.

Constructor & Destructor Documentation

◆ TCpuTensor() [1/9]

template<typename AFloat >
TMVA::DNN::TCpuTensor< AFloat >::TCpuTensor ( std::shared_ptr< TCpuBuffer< AFloat > > container,
Shape_t shape,
MemoryLayout layout )
inline

Construct a tensor sharing the given buffer.

The container holds the memory and its destructor releases it when all tensors sharing it are destroyed.

Definition at line 112 of file CpuTensor.h.

◆ TCpuTensor() [2/9]

template<typename AFloat >
TMVA::DNN::TCpuTensor< AFloat >::TCpuTensor ( )
inline

Definition at line 121 of file CpuTensor.h.

◆ TCpuTensor() [3/9]

template<typename AFloat >
TMVA::DNN::TCpuTensor< AFloat >::TCpuTensor ( size_t n,
size_t m,
MemoryLayout memlayout = MemoryLayout::ColumnMajor )
inline

constructors from n m

Definition at line 124 of file CpuTensor.h.

◆ TCpuTensor() [4/9]

template<typename AFloat >
TMVA::DNN::TCpuTensor< AFloat >::TCpuTensor ( size_t bsize,
size_t depth,
size_t hw,
MemoryLayout memlayout = MemoryLayout::ColumnMajor )
inline

constructors from batch size, depth, height*width

Definition at line 129 of file CpuTensor.h.

◆ TCpuTensor() [5/9]

template<typename AFloat >
TMVA::DNN::TCpuTensor< AFloat >::TCpuTensor ( size_t bsize,
size_t depth,
size_t height,
size_t width,
MemoryLayout memlayout = MemoryLayout::ColumnMajor )
inline

constructors from batch size, depth, height, width

Definition at line 137 of file CpuTensor.h.

◆ TCpuTensor() [6/9]

template<typename AFloat >
TMVA::DNN::TCpuTensor< AFloat >::TCpuTensor ( Shape_t shape,
MemoryLayout memlayout = MemoryLayout::ColumnMajor )
inline

constructors from a shape.

Definition at line 147 of file CpuTensor.h.

◆ TCpuTensor() [7/9]

template<typename AFloat >
TMVA::DNN::TCpuTensor< AFloat >::TCpuTensor ( AFloat * data,
const Shape_t & shape,
MemoryLayout memlayout = MemoryLayout::ColumnMajor )
inline

Definition at line 153 of file CpuTensor.h.

◆ TCpuTensor() [8/9]

template<typename AFloat >
TMVA::DNN::TCpuTensor< AFloat >::TCpuTensor ( const TCpuBuffer< AFloat > & buffer,
Shape_t shape,
MemoryLayout memlayout = MemoryLayout::ColumnMajor )
inline

constructors from a TCpuBuffer and a shape

Definition at line 164 of file CpuTensor.h.

◆ TCpuTensor() [9/9]

template<typename AFloat >
TMVA::DNN::TCpuTensor< AFloat >::TCpuTensor ( const TCpuMatrix< AFloat > & matrix,
size_t dim = 3,
MemoryLayout memlayout = MemoryLayout::ColumnMajor )
inline

constructors from a TCpuMatrix.

Memory layout is forced to be same as matrix (i.e. columnlayout)

Definition at line 172 of file CpuTensor.h.

Member Function Documentation

◆ At() [1/2]

template<typename AFloat >
TCpuTensor< AFloat > TMVA::DNN::TCpuTensor< AFloat >::At ( size_t i)
inline

Definition at line 318 of file CpuTensor.h.

◆ At() [2/2]

template<typename AFloat >
TCpuTensor< AFloat > TMVA::DNN::TCpuTensor< AFloat >::At ( size_t i) const
inline

Definition at line 331 of file CpuTensor.h.

◆ ComputeStridesFromShape()

template<typename AFloat >
static Shape_t TMVA::DNN::TCpuTensor< AFloat >::ComputeStridesFromShape ( const Shape_t & shape,
MemoryLayout layout )
inlinestaticprivate

Compute strides from a shape vector.

This information is needed for the multi-dimensional indexing: for row-major layout the last dimension varies fastest, while for column-major layout the first dimension varies fastest.

Definition at line 84 of file CpuTensor.h.

◆ GetBufferUseCount()

template<typename AFloat >
size_t TMVA::DNN::TCpuTensor< AFloat >::GetBufferUseCount ( ) const
inline

Definition at line 397 of file CpuTensor.h.

◆ GetContainer() [1/2]

template<typename AFloat >
std::shared_ptr< TCpuBuffer< AFloat > > TMVA::DNN::TCpuTensor< AFloat >::GetContainer ( )
inline

Definition at line 209 of file CpuTensor.h.

◆ GetContainer() [2/2]

template<typename AFloat >
const std::shared_ptr< TCpuBuffer< AFloat > > TMVA::DNN::TCpuTensor< AFloat >::GetContainer ( ) const
inline

Definition at line 210 of file CpuTensor.h.

◆ GetCSize()

template<typename AFloat >
size_t TMVA::DNN::TCpuTensor< AFloat >::GetCSize ( ) const
inline

Definition at line 258 of file CpuTensor.h.

◆ GetData() [1/2]

template<typename AFloat >
AFloat * TMVA::DNN::TCpuTensor< AFloat >::GetData ( )
inline

Definition at line 207 of file CpuTensor.h.

◆ GetData() [2/2]

template<typename AFloat >
const AFloat * TMVA::DNN::TCpuTensor< AFloat >::GetData ( ) const
inline

Definition at line 208 of file CpuTensor.h.

◆ GetDeviceBuffer() [1/2]

template<typename AFloat >
TCpuBuffer< AFloat > & TMVA::DNN::TCpuTensor< AFloat >::GetDeviceBuffer ( )
inline

Definition at line 243 of file CpuTensor.h.

◆ GetDeviceBuffer() [2/2]

template<typename AFloat >
const TCpuBuffer< AFloat > & TMVA::DNN::TCpuTensor< AFloat >::GetDeviceBuffer ( ) const
inline

Definition at line 242 of file CpuTensor.h.

◆ GetFirstSize()

template<typename AFloat >
size_t TMVA::DNN::TCpuTensor< AFloat >::GetFirstSize ( ) const
inline

Definition at line 252 of file CpuTensor.h.

◆ GetHSize()

template<typename AFloat >
size_t TMVA::DNN::TCpuTensor< AFloat >::GetHSize ( ) const
inline

Definition at line 265 of file CpuTensor.h.

◆ GetLayout()

template<typename AFloat >
MemoryLayout TMVA::DNN::TCpuTensor< AFloat >::GetLayout ( ) const
inline

Definition at line 291 of file CpuTensor.h.

◆ GetMatrix()

template<typename AFloat >
TCpuMatrix< AFloat > TMVA::DNN::TCpuTensor< AFloat >::GetMatrix ( ) const
inline

Definition at line 294 of file CpuTensor.h.

◆ GetMemoryLayout()

template<typename AFloat >
MemoryLayout TMVA::DNN::TCpuTensor< AFloat >::GetMemoryLayout ( ) const
inline

Definition at line 211 of file CpuTensor.h.

◆ GetNcols()

template<typename AFloat >
size_t TMVA::DNN::TCpuTensor< AFloat >::GetNcols ( ) const
inline

Definition at line 288 of file CpuTensor.h.

◆ GetNoElements()

template<typename AFloat >
size_t TMVA::DNN::TCpuTensor< AFloat >::GetNoElements ( ) const
inline

Definition at line 246 of file CpuTensor.h.

◆ GetNrows()

template<typename AFloat >
size_t TMVA::DNN::TCpuTensor< AFloat >::GetNrows ( ) const
inline

Definition at line 287 of file CpuTensor.h.

◆ GetRawDataPointer() [1/2]

template<typename AFloat >
AFloat * TMVA::DNN::TCpuTensor< AFloat >::GetRawDataPointer ( )
inline

Return raw pointer to the elements stored contiguously in column-major order.

Definition at line 238 of file CpuTensor.h.

◆ GetRawDataPointer() [2/2]

template<typename AFloat >
const AFloat * TMVA::DNN::TCpuTensor< AFloat >::GetRawDataPointer ( ) const
inline

Definition at line 239 of file CpuTensor.h.

◆ GetShape()

template<typename AFloat >
const Shape_t & TMVA::DNN::TCpuTensor< AFloat >::GetShape ( ) const
inline

Definition at line 205 of file CpuTensor.h.

◆ GetSize()

template<typename AFloat >
std::size_t TMVA::DNN::TCpuTensor< AFloat >::GetSize ( ) const
inline

Definition at line 204 of file CpuTensor.h.

◆ GetSizeFromShape()

template<typename AFloat >
static std::size_t TMVA::DNN::TCpuTensor< AFloat >::GetSizeFromShape ( const Shape_t & shape)
inlinestaticprivate

Compute the total number of elements from a shape vector.

An empty shape has size 0.

Definition at line 70 of file CpuTensor.h.

◆ GetStrides()

template<typename AFloat >
const Shape_t & TMVA::DNN::TCpuTensor< AFloat >::GetStrides ( ) const
inline

Definition at line 206 of file CpuTensor.h.

◆ GetWSize()

template<typename AFloat >
size_t TMVA::DNN::TCpuTensor< AFloat >::GetWSize ( ) const
inline

Definition at line 274 of file CpuTensor.h.

◆ Map()

template<typename AFloat >
template<typename Function_t >
void TMVA::DNN::TCpuTensor< AFloat >::Map ( Function_t & f)
inline

Map the given function over the matrix elements.

Executed in parallel using TThreadExecutor.

Definition at line 422 of file CpuTensor.h.

◆ MapFrom()

template<typename AFloat >
template<typename Function_t >
void TMVA::DNN::TCpuTensor< AFloat >::MapFrom ( Function_t & f,
const TCpuTensor< AFloat > & A )
inline

Same as maps but takes the input values from the tensor A and writes the results in this tensor.

Definition at line 451 of file CpuTensor.h.

◆ operator TMatrixT< AFloat >()

template<typename AFloat >
TMVA::DNN::TCpuTensor< AFloat >::operator TMatrixT< AFloat > ( ) const
inline

Convert to a TMatrixT<AFloat_t> object.

Performs a deep copy of the matrix elements.

Definition at line 193 of file CpuTensor.h.

◆ operator()() [1/4]

template<typename AFloat >
AFloat & TMVA::DNN::TCpuTensor< AFloat >::operator() ( size_t i,
size_t j )
inline

Definition at line 348 of file CpuTensor.h.

◆ operator()() [2/4]

template<typename AFloat >
AFloat TMVA::DNN::TCpuTensor< AFloat >::operator() ( size_t i,
size_t j ) const
inline

Definition at line 369 of file CpuTensor.h.

◆ operator()() [3/4]

template<typename AFloat >
AFloat & TMVA::DNN::TCpuTensor< AFloat >::operator() ( size_t i,
size_t j,
size_t k )
inline

Definition at line 358 of file CpuTensor.h.

◆ operator()() [4/4]

template<typename AFloat >
AFloat TMVA::DNN::TCpuTensor< AFloat >::operator() ( size_t i,
size_t j,
size_t k ) const
inline

Definition at line 377 of file CpuTensor.h.

◆ operator[]()

template<typename AFloat >
TCpuMatrix< AFloat > TMVA::DNN::TCpuTensor< AFloat >::operator[] ( size_t i) const
inline

Definition at line 334 of file CpuTensor.h.

◆ Print()

template<typename AFloat >
void TMVA::DNN::TCpuTensor< AFloat >::Print ( const char * name = "Tensor") const
inline

Definition at line 399 of file CpuTensor.h.

◆ PrintShape()

template<typename AFloat >
void TMVA::DNN::TCpuTensor< AFloat >::PrintShape ( const char * name = "Tensor") const
inline

Definition at line 407 of file CpuTensor.h.

◆ Reshape()

template<typename AFloat >
TCpuTensor< AFloat > TMVA::DNN::TCpuTensor< AFloat >::Reshape ( Shape_t shape) const
inline

Definition at line 309 of file CpuTensor.h.

◆ ReshapeInplace()

template<typename AFloat >
void TMVA::DNN::TCpuTensor< AFloat >::ReshapeInplace ( const Shape_t & shape)
inline

Reshape tensor in place.

The new shape must have the same overall size as the old one.

Definition at line 215 of file CpuTensor.h.

◆ Zero()

template<typename AFloat >
void TMVA::DNN::TCpuTensor< AFloat >::Zero ( )
inline

Definition at line 340 of file CpuTensor.h.

Friends And Related Symbol Documentation

◆ TCpuMatrix< AFloat >

template<typename AFloat >
friend class TCpuMatrix< AFloat >
friend

Definition at line 451 of file CpuTensor.h.

Member Data Documentation

◆ fContainer

template<typename AFloat >
std::shared_ptr<TCpuBuffer<AFloat> > TMVA::DNN::TCpuTensor< AFloat >::fContainer
private

Buffer owning the data.

Definition at line 66 of file CpuTensor.h.

◆ fData

template<typename AFloat >
AFloat* TMVA::DNN::TCpuTensor< AFloat >::fData = nullptr
private

Pointer to the first element.

Definition at line 65 of file CpuTensor.h.

◆ fLayout

template<typename AFloat >
MemoryLayout TMVA::DNN::TCpuTensor< AFloat >::fLayout
private

Memory layout of the tensor.

Definition at line 64 of file CpuTensor.h.

◆ fShape

template<typename AFloat >
Shape_t TMVA::DNN::TCpuTensor< AFloat >::fShape
private

Shape of the tensor.

Definition at line 61 of file CpuTensor.h.

◆ fSize

template<typename AFloat >
std::size_t TMVA::DNN::TCpuTensor< AFloat >::fSize
private

Total number of elements.

Definition at line 63 of file CpuTensor.h.

◆ fStrides

template<typename AFloat >
Shape_t TMVA::DNN::TCpuTensor< AFloat >::fStrides
private

Strides of the tensor.

Definition at line 62 of file CpuTensor.h.

  • tmva/tmva/inc/TMVA/DNN/Architectures/Cpu/CpuTensor.h