Medial Code Documentation
Loading...
Searching...
No Matches
Public Types | Public Member Functions
xgboost::linalg::Tensor< T, kDim > Class Template Reference

A tensor storage. More...

#include <linalg.h>

Public Types

using ShapeT = size_t[kDim]
 
using StrideT = ShapeT
 

Public Member Functions

template<typename I , int32_t D>
 Tensor (I const (&shape)[D], std::int32_t device, Order order=kC)
 Create a tensor with shape and device ordinal.
 
template<typename I , size_t D>
 Tensor (common::Span< I const, D > shape, std::int32_t device, Order order=kC)
 
template<typename It , typename I , int32_t D>
 Tensor (It begin, It end, I const (&shape)[D], std::int32_t device, Order order=kC)
 Initialize from 2 host iterators.
 
template<typename I , int32_t D>
 Tensor (std::initializer_list< T > data, I const (&shape)[D], std::int32_t device, Order order=kC)
 
template<typename... Index>
T & operator() (Index &&...idx)
 Index operator.
 
template<typename... Index>
T const & operator() (Index &&...idx) const
 Index operator.
 
TensorView< T, kDim > View (int32_t device)
 Get a TensorView for this tensor.
 
TensorView< T const, kDim > View (int32_t device) const
 
auto HostView () const
 
auto HostView ()
 
size_t Size () const
 
auto Shape () const
 
auto Shape (size_t i) const
 
HostDeviceVector< T > * Data ()
 
HostDeviceVector< T > const * Data () const
 
template<typename Fn >
void ModifyInplace (Fn &&fn)
 Visitor function for modification that changes shape and data.
 
template<typename... S, detail::EnableIfIntegral< S... > * = nullptr>
void Reshape (S &&...s)
 Reshape the tensor.
 
template<size_t D>
void Reshape (common::Span< size_t const, D > shape)
 Reshape the tensor.
 
template<size_t D>
void Reshape (size_t(&shape)[D])
 
template<typename... S>
auto Slice (S &&...slices) const
 Get a host view on the slice.
 
template<typename... S>
auto Slice (S &&...slices)
 Get a host view on the slice.
 
void SetDevice (int32_t device) const
 Set device ordinal for this tensor.
 
int32_t DeviceIdx () const
 

Detailed Description

template<typename T, int32_t kDim = 5>
class xgboost::linalg::Tensor< T, kDim >

A tensor storage.

To use it for other functionality like slicing one needs to obtain a view first. This way we can use it on both host and device.

Constructor & Destructor Documentation

◆ Tensor()

template<typename T , int32_t kDim = 5>
template<typename I , int32_t D>
xgboost::linalg::Tensor< T, kDim >::Tensor ( I const (&)  shape[D],
std::int32_t  device,
Order  order = kC 
)
inlineexplicit

Create a tensor with shape and device ordinal.

The storage is initialized automatically.

See TensorView for parameters of this constructor.

Member Function Documentation

◆ ModifyInplace()

template<typename T , int32_t kDim = 5>
template<typename Fn >
void xgboost::linalg::Tensor< T, kDim >::ModifyInplace ( Fn &&  fn)
inline

Visitor function for modification that changes shape and data.

Template Parameters
Fnfunction that takes a pointer to HostDeviceVector and a static sized span as parameters.

◆ operator()() [1/2]

template<typename T , int32_t kDim = 5>
template<typename... Index>
T & xgboost::linalg::Tensor< T, kDim >::operator() ( Index &&...  idx)
inline

Index operator.

Not thread safe, should not be used in performance critical region. For more efficient indexing, consider getting a view first.

◆ operator()() [2/2]

template<typename T , int32_t kDim = 5>
template<typename... Index>
T const & xgboost::linalg::Tensor< T, kDim >::operator() ( Index &&...  idx) const
inline

Index operator.

Not thread safe, should not be used in performance critical region. For more efficient indexing, consider getting a view first.

◆ Reshape() [1/2]

template<typename T , int32_t kDim = 5>
template<size_t D>
void xgboost::linalg::Tensor< T, kDim >::Reshape ( common::Span< size_t const, D >  shape)
inline

Reshape the tensor.

If the total size is changed, then data in this tensor is no longer valid.

◆ Reshape() [2/2]

template<typename T , int32_t kDim = 5>
template<typename... S, detail::EnableIfIntegral< S... > * = nullptr>
void xgboost::linalg::Tensor< T, kDim >::Reshape ( S &&...  s)
inline

Reshape the tensor.

If the total size is changed, then data in this tensor is no longer valid.


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