xgboost
公共类型 | 公共成员函数 | 公共静态属性 | 所有成员列表
xgboost::linalg::TensorView< T, kDim > 类模板引用

具有静态类型和维度的张量视图。它实现了索引和切片。 更多...

#include <linalg.h>

xgboost::linalg::TensorView< T, kDim > 的协作图
Collaboration graph

公共类型

使用 ShapeT = std::size_t[kDim]
 
使用 StrideT = ShapeT
 
使用 element_type = T
 
使用 value_type = std::remove_cv_t< T >
 

公共成员函数

template<typename I , std::int32_t D>
LINALG_HD TensorView (common::Span< T > data, I const (&shape)[D], DeviceOrd device)
 使用数据和形状创建张量。 更多...
 
template<typename I , int32_t D>
LINALG_HD TensorView (common::Span< T > data, I const (&shape)[D], DeviceOrd device, Order order)
 
template<typename I , std::int32_t D>
LINALG_HD TensorView (common::Span< T > data, I const (&shape)[D], I const (&stride)[D], DeviceOrd device)
 使用数据、形状和步幅创建张量。如果步幅可以从形状计算出来,请勿使用此构造函数。 更多...
 
template<typename U , std::enable_if_t< common::detail::IsAllowedElementTypeConversion< U, T >::value > * = nullptr>
LINALG_HD TensorView (TensorView< U, kDim > const &that)
 
template<typename... Index, detail::EnableIfIntegral< Index... > * = nullptr>
LINALG_HD T & operator() (Index &&...index)
 对张量进行索引以获取标量值。 更多...
 
template<typename... Index, detail::EnableIfIntegral< Index... > * = nullptr>
LINALG_HD T const & operator() (Index &&...index) const
 对张量进行索引以获取标量值。 更多...
 
template<typename... S>
LINALG_HD auto Slice (S &&...slices) const
 切片张量。返回的张量具有推断的维度和形状。不支持标量结果。 更多...
 
LINALG_HD auto Shape () const
 
LINALG_HD auto Shape (size_t i) const
 
LINALG_HD auto Stride () const
 
LINALG_HD auto Stride (size_t i) const
 
LINALG_HD std::size_t Size () const
 张量中的项数。 更多...
 
bool Empty () const
 
LINALG_HD bool Contiguous () const
 这是否是一个连续数组,C 连续和 F 连续都返回 true。 更多...
 
LINALG_HD bool CContiguous () const
 它是否是 C 连续数组。 更多...
 
LINALG_HD bool FContiguous () const
 它是否是 F 连续数组。 更多...
 
LINALG_HD auto Values () const -> decltype(data_) const &
 获取原始数据的引用。 更多...
 
LINALG_HD auto Device () const
 获取 CUDA 设备序号。 更多...
 

静态公共属性

constexpr static size_t kValueSize = sizeof(T)
 
constexpr static size_t kDimension = kDim
 

详细描述

template<typename T, int32_t kDim>
class xgboost::linalg::TensorView< T, kDim >

具有静态类型和维度的张量视图。它实现了索引和切片。

XGBoost 中的大多数算法都是为 CPU 和 GPU 实现的,没有使用太多线性代数例程,这个类是一个辅助工具,旨在简化一些高级操作,例如对预测张量或梯度矩阵进行索引。它可以作为普通参数传递给 CUDA 内核,用于 GPU 算法。

理想情况下,我们应该添加一个模板参数 bool on_host,以便编译器可以防止传递/访问错误的视图,但 XGBoost 中大量使用继承,因此一些函数需要可以在任何地方使用的数据类型(例如更新预测缓存)。

成员类型定义文档

◆ element_type

template<typename T , int32_t kDim>
using xgboost::linalg::TensorView< T, kDim >::element_type = T

◆ ShapeT

template<typename T , int32_t kDim>
using xgboost::linalg::TensorView< T, kDim >::ShapeT = std::size_t[kDim]

◆ StrideT

template<typename T , int32_t kDim>
using xgboost::linalg::TensorView< T, kDim >::StrideT = ShapeT

◆ value_type

template<typename T , int32_t kDim>
using xgboost::linalg::TensorView< T, kDim >::value_type = std::remove_cv_t<T>

构造函数和析构函数文档

◆ TensorView() [1/4]

template<typename T , int32_t kDim>
template<typename I , std::int32_t D>
LINALG_HD xgboost::linalg::TensorView< T, kDim >::TensorView ( common::Span< T >  数据,
I const (&)  shape[D],
DeviceOrd  device 
)
inline

使用数据和形状创建张量。

模板参数
I形状数组元素的类型。
D形状数组的大小,可以小于或等于张量维度。
参数
数据原始数据输入,如果此张量的模板参数中具有 const 类型,则可以是 const。
shape张量的形状
device设备序号

◆ TensorView() [2/4]

template<typename T , int32_t kDim>
template<typename I , int32_t D>
LINALG_HD xgboost::linalg::TensorView< T, kDim >::TensorView ( common::Span< T >  数据,
I const (&)  shape[D],
DeviceOrd  device,
Order  order 
)
inline

◆ TensorView() [3/4]

template<typename T , int32_t kDim>
template<typename I , std::int32_t D>
LINALG_HD xgboost::linalg::TensorView< T, kDim >::TensorView ( common::Span< T >  数据,
I const (&)  shape[D],
I const (&)  stride[D],
DeviceOrd  device 
)
inline

使用数据、形状和步幅创建张量。如果步幅可以从形状计算出来,请勿使用此构造函数。

◆ TensorView() [4/4]

template<typename T , int32_t kDim>
template<typename U , std::enable_if_t< common::detail::IsAllowedElementTypeConversion< U, T >::value > * = nullptr>
LINALG_HD xgboost::linalg::TensorView< T, kDim >::TensorView ( TensorView< U, kDim > const &  that)
inline

成员函数文档

◆ CContiguous()

template<typename T , int32_t kDim>
LINALG_HD bool xgboost::linalg::TensorView< T, kDim >::CContiguous ( ) const
inline

它是否是 C 连续数组。

◆ Contiguous()

template<typename T , int32_t kDim>
LINALG_HD bool xgboost::linalg::TensorView< T, kDim >::Contiguous ( ) const
inline

这是否是一个连续数组,C 连续和 F 连续都返回 true。

◆ Device()

template<typename T , int32_t kDim>
LINALG_HD auto xgboost::linalg::TensorView< T, kDim >::Device ( ) const
inline

获取 CUDA 设备序号。

◆ Empty()

template<typename T , int32_t kDim>
bool xgboost::linalg::TensorView< T, kDim >::Empty ( ) const
inline

◆ FContiguous()

template<typename T , int32_t kDim>
LINALG_HD bool xgboost::linalg::TensorView< T, kDim >::FContiguous ( ) const
inline

它是否是 F 连续数组。

◆ operator()() [1/2]

template<typename T , int32_t kDim>
template<typename... Index, detail::EnableIfIntegral< Index... > * = nullptr>
LINALG_HD T& xgboost::linalg::TensorView< T, kDim >::operator() ( Index &&...  index)
inline

对张量进行索引以获取标量值。

// 创建一个 3 维张量。
Tensor<float, 3> t {data, shape, 0};
float pi = 3.14159;
t(1, 2, 3) = pi;
ASSERT_EQ(t(1, 2, 3), pi);

◆ operator()() [2/2]

template<typename T , int32_t kDim>
template<typename... Index, detail::EnableIfIntegral< Index... > * = nullptr>
LINALG_HD T const& xgboost::linalg::TensorView< T, kDim >::operator() ( Index &&...  index) const
inline

对张量进行索引以获取标量值。

◆ Shape() [1/2]

template<typename T , int32_t kDim>
LINALG_HD auto xgboost::linalg::TensorView< T, kDim >::Shape ( ) const
inline

◆ Shape() [2/2]

template<typename T , int32_t kDim>
LINALG_HD auto xgboost::linalg::TensorView< T, kDim >::Shape ( size_t  i) const
inline

获取第 i 维度的形状

◆ Size()

template<typename T , int32_t kDim>
LINALG_HD std::size_t xgboost::linalg::TensorView< T, kDim >::Size ( ) const
inline

张量中的项数。

◆ Slice()

template<typename T , int32_t kDim>
template<typename... S>
LINALG_HD auto xgboost::linalg::TensorView< T, kDim >::Slice ( S &&...  切片) const
inline

切片张量。返回的张量具有推断的维度和形状。不支持标量结果。

// 创建一个 3 维张量。
Tensor<float, 3> t {data, shape, 0};
// s 有 2 个维度(矩阵)
auto s = t.Slice(1, All(), All());
constexpr detail::AllTag All()
指定切片轴中的所有元素。
定义: linalg.h:249

◆ Stride() [1/2]

template<typename T , int32_t kDim>
LINALG_HD auto xgboost::linalg::TensorView< T, kDim >::Stride ( ) const
inline

◆ Stride() [2/2]

template<typename T , int32_t kDim>
LINALG_HD auto xgboost::linalg::TensorView< T, kDim >::Stride ( size_t  i) const
inline

获取第 i 维度的步幅,步幅指定为项数而不是字节数。

◆ Values()

template<typename T , int32_t kDim>
LINALG_HD auto xgboost::linalg::TensorView< T, kDim >::Values ( ) const -> decltype(data_) const &
inline

获取原始数据的引用。

成员数据文档

◆ kDimension

template<typename T , int32_t kDim>
constexpr static size_t xgboost::linalg::TensorView< T, kDim >::kDimension = kDim
staticconstexpr

◆ kValueSize

template<typename T , int32_t kDim>
constexpr static size_t xgboost::linalg::TensorView< T, kDim >::kValueSize = sizeof(T)
staticconstexpr

此类的文档由以下文件生成