Logo ROOT  
Reference Guide
TMVA::Experimental::RTensor< V, C > Class Template Reference

template<typename V, typename C = std::vector<V>>
class TMVA::Experimental::RTensor< V, C >

RTensor is a container with contiguous memory and shape information.

Template Parameters
TData-type of the tensor

An RTensor is a vector-like container, which has additional shape information. The elements of the multi-dimensional container can be accessed by their indices in a coherent way without taking care about the one-dimensional memory layout of the contiguous storage. This also allows to manipulate the shape of the container without moving the actual elements in memory. Another feature is that an RTensor can own the underlying contiguous memory but can also represent only a view on existing data without owning it.

Definition at line 162 of file RTensor.hxx.

Classes

class  Iterator
 

Public Types

using Container_t = C
 
using Index_t = Shape_t
 
using Shape_t = std::vector< std::size_t >
 
using Slice_t = std::vector< Shape_t >
 
using Value_t = V
 

Public Member Functions

 RTensor (Shape_t shape, MemoryLayout layout=MemoryLayout::RowMajor)
 Construct a tensor owning data initialized with new container. More...
 
 RTensor (std::shared_ptr< Container_t > container, Shape_t shape, MemoryLayout layout=MemoryLayout::RowMajor)
 Construct a tensor owning externally provided data. More...
 
 RTensor (Value_t *data, Shape_t shape, MemoryLayout layout=MemoryLayout::RowMajor)
 Construct a tensor as view on data. More...
 
 RTensor (Value_t *data, Shape_t shape, Shape_t strides, MemoryLayout layout=MemoryLayout::RowMajor)
 Construct a tensor as view on data. More...
 
Iterator begin () noexcept
 
RTensor< Value_t, Container_tCopy (MemoryLayout layout=MemoryLayout::RowMajor)
 Copy RTensor to new object. More...
 
Iterator end () noexcept
 
RTensor< Value_t, Container_tExpandDims (int idx)
 Expand dimensions. More...
 
std::shared_ptr< Container_tGetContainer ()
 
const std::shared_ptr< Container_tGetContainer () const
 
Value_tGetData ()
 
const Value_tGetData () const
 
MemoryLayout GetMemoryLayout () const
 
const Shape_tGetShape () const
 
std::size_t GetSize () const
 
const Shape_tGetStrides () const
 
bool IsOwner () const
 
bool IsView () const
 
Value_toperator() (const Index_t &idx)
 Access elements. More...
 
const Value_toperator() (const Index_t &idx) const
 Access elements. More...
 
template<typename... Idx>
Value_toperator() (Idx... idx)
 Access elements. More...
 
template<typename... Idx>
const Value_toperator() (Idx... idx) const
 Access elements. More...
 
RTensor< Value_t, Container_tReshape (const Shape_t &shape)
 Reshape tensor. More...
 
RTensor< Value_t, Container_tSlice (const Slice_t &slice)
 Create a slice of the tensor. More...
 
RTensor< Value_t, Container_tSqueeze ()
 Squeeze dimensions. More...
 
RTensor< Value_t, Container_tTranspose ()
 Transpose. More...
 

Protected Member Functions

void ReshapeInplace (const Shape_t &shape)
 Reshape tensor in place. More...
 

Private Attributes

std::shared_ptr< Container_tfContainer
 
Value_tfData
 
MemoryLayout fLayout
 
Shape_t fShape
 
std::size_t fSize
 
Shape_t fStrides
 

#include <TMVA/RTensor.hxx>

Member Typedef Documentation

◆ Container_t

template<typename V , typename C = std::vector<V>>
using TMVA::Experimental::RTensor< V, C >::Container_t = C

Definition at line 169 of file RTensor.hxx.

◆ Index_t

template<typename V , typename C = std::vector<V>>
using TMVA::Experimental::RTensor< V, C >::Index_t = Shape_t

Definition at line 167 of file RTensor.hxx.

◆ Shape_t

template<typename V , typename C = std::vector<V>>
using TMVA::Experimental::RTensor< V, C >::Shape_t = std::vector<std::size_t>

Definition at line 166 of file RTensor.hxx.

◆ Slice_t

template<typename V , typename C = std::vector<V>>
using TMVA::Experimental::RTensor< V, C >::Slice_t = std::vector<Shape_t>

Definition at line 168 of file RTensor.hxx.

◆ Value_t

template<typename V , typename C = std::vector<V>>
using TMVA::Experimental::RTensor< V, C >::Value_t = V

Definition at line 165 of file RTensor.hxx.

Constructor & Destructor Documentation

◆ RTensor() [1/4]

template<typename V , typename C = std::vector<V>>
TMVA::Experimental::RTensor< V, C >::RTensor ( Value_t data,
Shape_t  shape,
MemoryLayout  layout = MemoryLayout::RowMajor 
)
inline

Construct a tensor as view on data.

Parameters
[in]dataPointer to data contiguous in memory
[in]shapeShape vector
[in]layoutMemory layout

Definition at line 189 of file RTensor.hxx.

◆ RTensor() [2/4]

template<typename V , typename C = std::vector<V>>
TMVA::Experimental::RTensor< V, C >::RTensor ( Value_t data,
Shape_t  shape,
Shape_t  strides,
MemoryLayout  layout = MemoryLayout::RowMajor 
)
inline

Construct a tensor as view on data.

Parameters
[in]dataPointer to data contiguous in memory
[in]shapeShape vector
[in]stridesStrides vector
[in]layoutMemory layout

Definition at line 201 of file RTensor.hxx.

◆ RTensor() [3/4]

template<typename V , typename C = std::vector<V>>
TMVA::Experimental::RTensor< V, C >::RTensor ( std::shared_ptr< Container_t container,
Shape_t  shape,
MemoryLayout  layout = MemoryLayout::RowMajor 
)
inline

Construct a tensor owning externally provided data.

Parameters
[in]containerShared pointer to data container
[in]shapeShape vector
[in]layoutMemory layout

Definition at line 211 of file RTensor.hxx.

◆ RTensor() [4/4]

template<typename V , typename C = std::vector<V>>
TMVA::Experimental::RTensor< V, C >::RTensor ( Shape_t  shape,
MemoryLayout  layout = MemoryLayout::RowMajor 
)
inline

Construct a tensor owning data initialized with new container.

Parameters
[in]shapeShape vector
[in]layoutMemory layout

Definition at line 223 of file RTensor.hxx.

Member Function Documentation

◆ begin()

template<typename V , typename C = std::vector<V>>
Iterator TMVA::Experimental::RTensor< V, C >::begin ( )
inlinenoexcept

Definition at line 300 of file RTensor.hxx.

◆ Copy()

Copy RTensor to new object.

Parameters
[in]layoutMemory layout of the new RTensor
Returns
New RTensor The operation copies all elements of the current RTensor to a new RTensor with the given layout contiguous in memory. Note that this copies by default to a row major memory layout.

Definition at line 542 of file RTensor.hxx.

◆ end()

template<typename V , typename C = std::vector<V>>
Iterator TMVA::Experimental::RTensor< V, C >::end ( )
inlinenoexcept

Definition at line 303 of file RTensor.hxx.

◆ ExpandDims()

template<typename Value_t , typename Container_t >
RTensor< Value_t, Container_t > TMVA::Experimental::RTensor< Value_t, Container_t >::ExpandDims ( int  idx)
inline

Expand dimensions.

Parameters
[in]idxIndex in shape vector where dimension is added
Returns
New RTensor Inserts a dimension of one into the shape.

Definition at line 444 of file RTensor.hxx.

◆ GetContainer() [1/2]

template<typename V , typename C = std::vector<V>>
std::shared_ptr< Container_t > TMVA::Experimental::RTensor< V, C >::GetContainer ( )
inline

Definition at line 246 of file RTensor.hxx.

◆ GetContainer() [2/2]

template<typename V , typename C = std::vector<V>>
const std::shared_ptr< Container_t > TMVA::Experimental::RTensor< V, C >::GetContainer ( ) const
inline

Definition at line 247 of file RTensor.hxx.

◆ GetData() [1/2]

template<typename V , typename C = std::vector<V>>
Value_t * TMVA::Experimental::RTensor< V, C >::GetData ( )
inline

Definition at line 244 of file RTensor.hxx.

◆ GetData() [2/2]

template<typename V , typename C = std::vector<V>>
const Value_t * TMVA::Experimental::RTensor< V, C >::GetData ( ) const
inline

Definition at line 245 of file RTensor.hxx.

◆ GetMemoryLayout()

template<typename V , typename C = std::vector<V>>
MemoryLayout TMVA::Experimental::RTensor< V, C >::GetMemoryLayout ( ) const
inline

Definition at line 248 of file RTensor.hxx.

◆ GetShape()

template<typename V , typename C = std::vector<V>>
const Shape_t & TMVA::Experimental::RTensor< V, C >::GetShape ( ) const
inline

Definition at line 242 of file RTensor.hxx.

◆ GetSize()

template<typename V , typename C = std::vector<V>>
std::size_t TMVA::Experimental::RTensor< V, C >::GetSize ( ) const
inline

Definition at line 241 of file RTensor.hxx.

◆ GetStrides()

template<typename V , typename C = std::vector<V>>
const Shape_t & TMVA::Experimental::RTensor< V, C >::GetStrides ( ) const
inline

Definition at line 243 of file RTensor.hxx.

◆ IsOwner()

template<typename V , typename C = std::vector<V>>
bool TMVA::Experimental::RTensor< V, C >::IsOwner ( ) const
inline

Definition at line 250 of file RTensor.hxx.

◆ IsView()

template<typename V , typename C = std::vector<V>>
bool TMVA::Experimental::RTensor< V, C >::IsView ( ) const
inline

Definition at line 249 of file RTensor.hxx.

◆ operator()() [1/4]

template<typename Value_t , typename Container_t >
Value_t & TMVA::Experimental::RTensor< Value_t, Container_t >::operator() ( const Index_t idx)
inline

Access elements.

Parameters
[in]idxIndex vector
Returns
Reference to element

Definition at line 339 of file RTensor.hxx.

◆ operator()() [2/4]

template<typename Value_t , typename Container_t >
const Value_t & TMVA::Experimental::RTensor< Value_t, Container_t >::operator() ( const Index_t idx) const
inline

Access elements.

Parameters
[in]idxIndex vector
Returns
Reference to element

Definition at line 349 of file RTensor.hxx.

◆ operator()() [3/4]

template<typename Value_t , typename Container_t >
template<typename... Idx>
Value_t & TMVA::Experimental::RTensor< Value_t, Container_t >::operator() ( Idx...  idx)

Access elements.

Parameters
[in]idxIndices
Returns
Reference to element

Definition at line 360 of file RTensor.hxx.

◆ operator()() [4/4]

template<typename Value_t , typename Container_t >
template<typename... Idx>
const Value_t & TMVA::Experimental::RTensor< Value_t, Container_t >::operator() ( Idx...  idx) const

Access elements.

Parameters
[in]idxIndices
Returns
Reference to element

Definition at line 372 of file RTensor.hxx.

◆ Reshape()

template<typename Value_t , typename Container_t >
RTensor< Value_t, Container_t > TMVA::Experimental::RTensor< Value_t, Container_t >::Reshape ( const Shape_t shape)
inline

Reshape tensor.

Parameters
[in]shapeShape vector
Returns
New RTensor Reshape tensor without changing the overall size

Definition at line 476 of file RTensor.hxx.

◆ ReshapeInplace()

template<typename Value_t , typename Container_t >
void TMVA::Experimental::RTensor< Value_t, Container_t >::ReshapeInplace ( const Shape_t shape)
inlineprotected

Reshape tensor in place.

Parameters
[in]shapeShape vector Reshape tensor without changing the overall size

Definition at line 312 of file RTensor.hxx.

◆ Slice()

template<typename Value_t , typename Container_t >
RTensor< Value_t, Container_t > TMVA::Experimental::RTensor< Value_t, Container_t >::Slice ( const Slice_t slice)
inline

Create a slice of the tensor.

Parameters
[in]sliceSlice vector
Returns
New RTensor A slice is a subset of the tensor defined by a vector of pairs of indices.

Definition at line 489 of file RTensor.hxx.

◆ Squeeze()

template<typename Value_t , typename Container_t >
RTensor< Value_t, Container_t > TMVA::Experimental::RTensor< Value_t, Container_t >::Squeeze
inline

Squeeze dimensions.

Returns
New RTensor Squeeze removes the dimensions of size one from the shape.

Definition at line 412 of file RTensor.hxx.

◆ Transpose()

template<typename Value_t , typename Container_t >
RTensor< Value_t, Container_t > TMVA::Experimental::RTensor< Value_t, Container_t >::Transpose
inline

Transpose.

Returns
New RTensor The tensor is transposed by inverting the associated memory layout from row- major to column-major and vice versa. Therefore, the underlying data is not touched.

Definition at line 385 of file RTensor.hxx.

Member Data Documentation

◆ fContainer

template<typename V , typename C = std::vector<V>>
std::shared_ptr<Container_t> TMVA::Experimental::RTensor< V, C >::fContainer
private

Definition at line 177 of file RTensor.hxx.

◆ fData

template<typename V , typename C = std::vector<V>>
Value_t* TMVA::Experimental::RTensor< V, C >::fData
private

Definition at line 176 of file RTensor.hxx.

◆ fLayout

template<typename V , typename C = std::vector<V>>
MemoryLayout TMVA::Experimental::RTensor< V, C >::fLayout
private

Definition at line 175 of file RTensor.hxx.

◆ fShape

template<typename V , typename C = std::vector<V>>
Shape_t TMVA::Experimental::RTensor< V, C >::fShape
private

Definition at line 172 of file RTensor.hxx.

◆ fSize

template<typename V , typename C = std::vector<V>>
std::size_t TMVA::Experimental::RTensor< V, C >::fSize
private

Definition at line 174 of file RTensor.hxx.

◆ fStrides

template<typename V , typename C = std::vector<V>>
Shape_t TMVA::Experimental::RTensor< V, C >::fStrides
private

Definition at line 173 of file RTensor.hxx.


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