6 #ifndef XGBOOST_LINALG_H_
7 #define XGBOOST_LINALG_H_
9 #include <dmlc/endian.h>
23 #include <type_traits>
33 #if defined(__CUDA__) || defined(__NVCC__)
34 #define LINALG_HD __host__ __device__
46 return (std::is_floating_point_v<T>
48 : (std::is_integral_v<T> ? (std::is_signed_v<T> ?
'i' :
'u') :
'\0'));
52 template <
size_t dim,
typename S,
typename Head,
size_t D>
53 constexpr
size_t Offset(S (&strides)[D],
size_t n, Head head) {
54 static_assert(dim < D);
55 return n + head * strides[dim];
58 template <
size_t dim,
typename S,
size_t D,
typename Head,
typename... Tail>
59 constexpr std::enable_if_t<
sizeof...(Tail) != 0,
size_t>
Offset(S (&strides)[D],
size_t n,
60 Head head, Tail &&...rest) {
61 static_assert(dim < D);
62 return Offset<dim + 1>(strides, n + (head * strides[dim]), std::forward<Tail>(rest)...);
65 template <
int32_t D,
bool f_array = false>
66 constexpr
void CalcStride(
size_t const (&shape)[D],
size_t (&stride)[D]) {
69 for (int32_t s = 1; s < D; ++s) {
70 stride[s] = shape[s - 1] * stride[s - 1];
74 for (int32_t s = D - 2; s >= 0; --s) {
75 stride[s] = shape[s + 1] * stride[s + 1];
88 [[nodiscard]] constexpr
size_t Size()
const {
return end -
beg; }
96 return std::is_same_v<T, IntTag> ? 0 : 1;
99 template <
typename T,
typename... S>
100 constexpr std::enable_if_t<
sizeof...(S) != 0, int32_t>
CalcSliceDim() {
107 for (
auto d : shape) {
113 template <
typename S>
116 template <
typename S>
119 template <
int32_t n,
typename Fn>
121 #if defined __CUDA_ARCH__
124 for (int32_t i = 0; i < n; ++i) {
129 template <
typename T>
132 for (; v != 0; v &= v - 1) c++;
137 #if defined(__CUDA_ARCH__)
139 #elif defined(__GNUC__) || defined(__clang__)
140 return __builtin_popcount(v);
141 #elif defined(_MSC_VER)
149 #if defined(__CUDA_ARCH__)
151 #elif defined(__GNUC__) || defined(__clang__)
152 return __builtin_popcountll(v);
153 #elif defined(_MSC_VER) && defined(_M_X64)
154 return __popcnt64(v);
160 template <std::
size_t D,
typename Head>
162 static_assert(std::is_integral_v<std::remove_reference_t<Head>>,
"Invalid index type.");
169 template <std::size_t D,
typename Head,
typename... Rest>
171 static_assert(
sizeof...(Rest) < D,
"Index overflow.");
172 static_assert(std::is_integral_v<std::remove_reference_t<Head>>,
"Invalid index type.");
173 arr[D -
sizeof...(Rest) - 1] = head;
174 IndexToArr(arr, std::forward<Rest>(index)...);
177 template <
class T, std::size_t N, std::size_t... Idx>
178 constexpr
auto ArrToTuple(T (&arr)[N], std::index_sequence<Idx...>) {
179 return std::make_tuple(arr[Idx]...);
185 template <
class T, std::
size_t N>
187 return ArrToTuple(arr, std::make_index_sequence<N>{});
193 template <
typename I, std::
int32_t D>
195 std::size_t index[D]{0};
196 static_assert(std::is_signed_v<decltype(D)>,
197 "Don't change the type without changing the for loop.");
198 auto const sptr = shape.
data();
199 for (int32_t dim = D; --dim > 0;) {
200 auto s =
static_cast<std::remove_const_t<std::remove_reference_t<I>
>>(sptr[dim]);
203 index[dim] = idx - t * s;
206 index[dim] = idx & (s - 1);
214 template <
size_t dim,
typename I,
int32_t D>
216 static_assert(dim < D);
220 template <
size_t dim, int32_t D,
typename... S,
typename I,
221 std::enable_if_t<
sizeof...(S) != 0> * =
nullptr>
223 static_assert(dim < D);
225 ReshapeImpl<dim + 1>(out_shape, std::forward<S>(rest)...);
235 template <
class B1,
class... Bn>
237 : std::conditional_t<static_cast<bool>(B1::value), Conjunction<Bn...>, B1> {};
239 template <
typename... Index>
242 template <
typename... Index>
253 template <
typename I>
276 template <
typename T,
int32_t kDim>
303 template <
size_t old_dim,
size_t new_dim,
int32_t D,
typename I>
304 LINALG_HD size_t MakeSliceDim(std::size_t new_shape[D], std::size_t new_stride[D],
305 detail::RangeTag<I> &&range)
const {
306 static_assert(new_dim < D);
307 static_assert(old_dim < kDim);
308 new_stride[new_dim] = stride_[old_dim];
309 new_shape[new_dim] = range.Size();
310 assert(
static_cast<decltype(shape_[old_dim])
>(range.end) <= shape_[old_dim]);
312 auto offset = stride_[old_dim] * range.beg;
318 template <
size_t old_dim,
size_t new_dim, int32_t D,
typename I,
typename... S>
319 LINALG_HD size_t MakeSliceDim(
size_t new_shape[D],
size_t new_stride[D],
320 detail::RangeTag<I> &&range, S &&...slices)
const {
321 static_assert(new_dim < D);
322 static_assert(old_dim < kDim);
323 new_stride[new_dim] = stride_[old_dim];
324 new_shape[new_dim] = range.Size();
325 assert(
static_cast<decltype(shape_[old_dim])
>(range.end) <= shape_[old_dim]);
327 auto offset = stride_[old_dim] * range.beg;
328 return MakeSliceDim<old_dim + 1, new_dim + 1, D>(new_shape, new_stride,
329 std::forward<S>(slices)...) +
333 template <
size_t old_dim,
size_t new_dim,
int32_t D>
334 LINALG_HD size_t MakeSliceDim(
size_t new_shape[D],
size_t new_stride[D], detail::AllTag)
const {
335 static_assert(new_dim < D);
336 static_assert(old_dim < kDim);
337 new_stride[new_dim] = stride_[old_dim];
338 new_shape[new_dim] = shape_[old_dim];
344 template <
size_t old_dim,
size_t new_dim, int32_t D,
typename... S>
345 LINALG_HD size_t MakeSliceDim(
size_t new_shape[D],
size_t new_stride[D], detail::AllTag,
346 S &&...slices)
const {
347 static_assert(new_dim < D);
348 static_assert(old_dim < kDim);
349 new_stride[new_dim] = stride_[old_dim];
350 new_shape[new_dim] = shape_[old_dim];
351 return MakeSliceDim<old_dim + 1, new_dim + 1, D>(new_shape, new_stride,
352 std::forward<S>(slices)...);
355 template <
size_t old_dim,
size_t new_dim,
int32_t D,
typename Index>
356 LINALG_HD size_t MakeSliceDim(DMLC_ATTRIBUTE_UNUSED
size_t new_shape[D],
357 DMLC_ATTRIBUTE_UNUSED
size_t new_stride[D], Index i)
const {
358 static_assert(old_dim < kDim);
359 return stride_[old_dim] * i;
364 template <
size_t old_dim,
size_t new_dim, int32_t D,
typename Index,
typename... S>
365 LINALG_HD std::enable_if_t<std::is_integral_v<Index>,
size_t> MakeSliceDim(
366 size_t new_shape[D],
size_t new_stride[D], Index i, S &&...slices)
const {
367 static_assert(old_dim < kDim);
368 auto offset = stride_[old_dim] * i;
370 MakeSliceDim<old_dim + 1, new_dim, D>(new_shape, new_stride, std::forward<S>(slices)...);
390 template <
typename I, std::
int32_t D>
394 template <
typename I,
int32_t D>
396 : data_{data}, ptr_{data_.data()}, device_{device} {
397 static_assert(D > 0 && D <= kDim,
"Invalid shape.");
399 detail::UnrollLoop<D>([&](
auto i) { shape_[i] = shape[i]; });
400 for (
auto i = D; i < kDim; ++i) {
410 detail::CalcStride<kDim, true>(shape_, stride_);
425 template <
typename I, std::
int32_t D>
428 : data_{data}, ptr_{data_.data()}, device_{device} {
429 static_assert(D == kDim,
"Invalid shape & stride.");
430 detail::UnrollLoop<D>([&](
auto i) {
431 shape_[i] = shape[i];
432 stride_[i] = stride[i];
439 std::enable_if_t<common::detail::IsAllowedElementTypeConversion<U, T>::value> * =
nullptr>
441 : data_{that.
Values()}, ptr_{data_.data()}, size_{that.
Size()}, device_{that.
Device()} {
442 detail::UnrollLoop<kDim>([&](
auto i) {
443 stride_[i] = that.
Stride(i);
444 shape_[i] = that.
Shape(i);
463 static_assert(
sizeof...(index) <= kDim,
"Invalid index.");
464 size_t offset = detail::Offset<0ul>(stride_, 0ul, std::forward<Index>(index)...);
465 assert(offset < data_.
size() &&
"Out of bound access.");
473 static_assert(
sizeof...(index) <= kDim,
"Invalid index.");
474 size_t offset = detail::Offset<0ul>(stride_, 0ul, std::forward<Index>(index)...);
475 assert(offset < data_.
size() &&
"Out of bound access.");
492 template <
typename... S>
494 static_assert(
sizeof...(slices) <= kDim,
"Invalid slice.");
495 int32_t constexpr kNewDim{detail::CalcSliceDim<detail::IndexToTag<S>...>()};
496 size_t new_shape[kNewDim];
497 size_t new_stride[kNewDim];
498 auto offset = MakeSliceDim<0, 0, kNewDim>(new_shape, new_stride, std::forward<S>(slices)...);
521 [[nodiscard]]
bool Empty()
const {
return Size() == 0; }
533 static_assert(std::is_same_v<decltype(stride), decltype(stride_)>);
543 static_assert(std::is_same_v<decltype(stride), decltype(stride_)>);
545 detail::CalcStride<kDim, true>(shape_, stride);
561 template <
typename Container,
typename... S,
562 std::enable_if_t<!common::detail::IsSpan<Container>::value &&
563 !std::is_pointer_v<Container>> * =
nullptr>
565 using T = std::conditional_t<std::is_const_v<Container>,
566 std::add_const_t<typename Container::value_type>,
567 typename Container::value_type>;
568 std::size_t in_shape[
sizeof...(S)];
575 std::size_t in_shape[
sizeof...(S)];
577 return TensorView<T,
sizeof...(S)>{data, in_shape, device};
587 std::size_t in_shape[
sizeof...(S)];
592 template <
typename T,
typename... S>
598 template <
typename T,
typename... S>
609 if (idx > std::numeric_limits<uint32_t>::max()) {
610 return detail::UnravelImpl<uint64_t, D>(
static_cast<uint64_t
>(idx), shape);
612 return detail::UnravelImpl<uint32_t, D>(
static_cast<uint32_t
>(idx), shape);
621 template <
typename... S>
623 std::size_t s[
sizeof...(S)];
633 template <
typename T>
643 template <
typename T>
648 template <
typename T>
654 template <
typename T>
665 template <
typename T>
674 template <
typename T, std::
int32_t D>
677 array_interface[
"data"] = std::vector<Json>(2);
678 array_interface[
"data"][0] =
Integer{
reinterpret_cast<int64_t
>(t.
Values().data())};
679 array_interface[
"data"][1] =
Boolean{
true};
680 if (t.
Device().IsCUDA()) {
682 array_interface[
"stream"] =
Integer{2};
684 std::vector<Json> shape(t.
Shape().size());
685 std::vector<Json> stride(t.
Stride().size());
686 for (
size_t i = 0; i < t.
Shape().size(); ++i) {
690 array_interface[
"shape"] =
Array{shape};
691 array_interface[
"strides"] =
Array{stride};
692 array_interface[
"version"] = 3;
694 char constexpr kT = detail::ArrayInterfaceHandler::TypeChar<T>();
695 static_assert(kT !=
'\0');
696 if (DMLC_LITTLE_ENDIAN) {
697 array_interface[
"typestr"] =
String{
"<" + (kT + std::to_string(
sizeof(T)))};
699 array_interface[
"typestr"] =
String{
">" + (kT + std::to_string(
sizeof(T)))};
701 return array_interface;
707 template <
typename T,
int32_t D>
711 res[
"data"][1] =
Boolean{
false};
718 template <
typename T,
int32_t D>
725 template <
typename T,
int32_t D>
732 template <
typename T>
744 template <
typename T,
int32_t kDim = 5>
755 template <
typename I, std::
int32_t D>
756 void Initialize(I
const (&shape)[D],
DeviceOrd device) {
757 static_assert(D <= kDim,
"Invalid shape.");
758 std::copy(shape, shape + D, shape_);
759 for (
auto i = D; i < kDim; ++i) {
762 if (!device.
IsCPU()) {
778 template <
typename I,
int32_t D>
780 :
Tensor{common::
Span<I const, D>{shape}, device, order} {}
782 template <
typename I,
size_t D>
786 std::copy(shape.
data(), shape.
data() + D, shape_);
787 for (
auto i = D; i < kDim; ++i) {
791 if (!device.
IsCPU()) {
795 if (!device.
IsCPU()) {
802 template <
typename It,
typename I,
int32_t D>
806 h_vec.insert(h_vec.begin(), begin, end);
808 this->Initialize(shape, device);
811 template <
typename I,
int32_t D>
818 this->Initialize(shape, device);
824 template <
typename... Index>
826 return this->HostView()(std::forward<Index>(idx)...);
832 template <
typename... Index>
834 return this->HostView()(std::forward<Index>(idx)...);
841 if (device.
IsCPU()) {
851 if (device.
IsCPU()) {
864 [[nodiscard]] std::size_t
Size()
const {
return data_.
Size(); }
865 [[nodiscard]]
bool Empty()
const {
return Size() == 0; }
868 auto Shape(
size_t i)
const {
return shape_[i]; }
879 template <
typename Fn>
883 <<
"Inconsistent size after modification.";
893 static_assert(
sizeof...(S) <= kDim,
"Invalid shape.");
894 detail::ReshapeImpl<0>(shape_, std::forward<S>(s)...);
895 auto constexpr kEnd =
sizeof...(S);
896 static_assert(kEnd <= kDim,
"Invalid shape.");
897 std::fill(shape_ + kEnd, shape_ + kDim, 1);
909 static_assert(D <= kDim,
"Invalid shape.");
910 std::copy(shape.
data(), shape.
data() + D, this->shape_);
911 std::fill(shape_ + D, shape_ + kDim, 1);
923 template <
typename... S>
925 return this->HostView().Slice(std::forward<S>(slices)...);
930 template <
typename... S>
932 return this->HostView().Slice(std::forward<S>(slices)...);
942 template <
typename T>
945 template <
typename T>
951 template <
typename T,
typename... Index>
953 Tensor<T,
sizeof...(Index)> t;
962 template <
typename T,
typename... Index>
964 Tensor<T,
sizeof...(Index)> t;
967 t.Data()->Fill(std::move(v));
974 template <
typename T,
typename... Index>
976 return Constant(ctx,
static_cast<T
>(0), index...);
980 template <
typename T,
int32_t D>
986 for (
size_t i = 1; i < D; ++i) {
988 shape[i] = r.
Shape(i);
990 CHECK_EQ(shape[i], r.
Shape(i));
999 #if defined(LINALG_HD)
Defines configuration macros and basic types for xgboost.
Definition: host_device_vector.h:87
const T * ConstDevicePointer() const
void Extend(const HostDeviceVector< T > &other)
common::Span< T const > ConstHostSpan() const
Definition: host_device_vector.h:116
std::vector< T > & HostVector()
common::Span< const T > ConstDeviceSpan() const
T * HostPointer()
Definition: host_device_vector.h:113
common::Span< T > DeviceSpan()
common::Span< T > HostSpan()
Definition: host_device_vector.h:114
void SetDevice(DeviceOrd device) const
void Resize(std::size_t new_size)
const T * ConstHostPointer() const
Definition: host_device_vector.h:117
Describes both true and false.
Definition: json.h:350
Data structure representing JSON format.
Definition: json.h:392
static void Dump(Json json, std::string *out, std::ios::openmode mode=std::ios::out)
Encode the JSON object. Optional parameter mode for choosing between text and binary (ubjson) output.
span class implementation, based on ISO++20 span<T>. The interface should be the same.
Definition: span.h:431
constexpr XGBOOST_DEVICE pointer data() const __span_noexcept
Definition: span.h:550
XGBOOST_DEVICE auto subspan() const -> Span< element_type, detail::ExtentValue< Extent, Offset, Count >::value >
Definition: span.h:597
constexpr XGBOOST_DEVICE index_type size() const __span_noexcept
Definition: span.h:555
constexpr XGBOOST_DEVICE bool empty() const __span_noexcept
Definition: span.h:562
A tensor view with static type and dimension. It implements indexing and slicing.
Definition: linalg.h:277
LINALG_HD std::size_t Size() const
Number of items in the tensor.
Definition: linalg.h:520
LINALG_HD TensorView(common::Span< T > data, I const (&shape)[D], DeviceOrd device)
Create a tensor with data and shape.
Definition: linalg.h:391
std::remove_cv_t< T > value_type
Definition: linalg.h:283
T element_type
Definition: linalg.h:282
LINALG_HD bool CContiguous() const
Whether it's a c-contiguous array.
Definition: linalg.h:531
LINALG_HD auto Stride(size_t i) const
Definition: linalg.h:515
LINALG_HD TensorView(common::Span< T > data, I const (&shape)[D], DeviceOrd device, Order order)
Definition: linalg.h:395
LINALG_HD auto Shape() const
Definition: linalg.h:506
ShapeT StrideT
Definition: linalg.h:280
constexpr static size_t kDimension
Definition: linalg.h:376
LINALG_HD auto Stride() const
Definition: linalg.h:511
LINALG_HD auto Slice(S &&...slices) const
Slice the tensor. The returned tensor has inferred dim and shape. Scalar result is not supported.
Definition: linalg.h:493
LINALG_HD auto Values() const -> decltype(data_) const &
Obtain a reference to the raw data.
Definition: linalg.h:551
LINALG_HD bool Contiguous() const
Whether this is a contiguous array, both C and F contiguous returns true.
Definition: linalg.h:525
bool Empty() const
Definition: linalg.h:521
LINALG_HD T const & operator()(Index &&...index) const
Index the tensor to obtain a scalar value.
Definition: linalg.h:472
LINALG_HD TensorView(TensorView< U, kDim > const &that)
Definition: linalg.h:440
LINALG_HD T & operator()(Index &&...index)
Index the tensor to obtain a scalar value.
Definition: linalg.h:462
constexpr static size_t kValueSize
Definition: linalg.h:375
LINALG_HD bool FContiguous() const
Whether it's a f-contiguous array.
Definition: linalg.h:541
LINALG_HD auto Shape(size_t i) const
Definition: linalg.h:510
LINALG_HD TensorView(common::Span< T > data, I const (&shape)[D], I const (&stride)[D], DeviceOrd device)
Create a tensor with data, shape and strides. Don't use this constructor if stride can be calculated ...
Definition: linalg.h:426
std::size_t[kDim] ShapeT
Definition: linalg.h:279
LINALG_HD auto Device() const
Obtain the CUDA device ordinal.
Definition: linalg.h:555
A tensor storage. To use it for other functionality like slicing one needs to obtain a view first....
Definition: linalg.h:745
auto Slice(S &&...slices)
Get a host view on the slice.
Definition: linalg.h:931
bool Empty() const
Definition: linalg.h:865
Tensor(It begin, It end, I const (&shape)[D], DeviceOrd device, Order order=kC)
Definition: linalg.h:803
auto Slice(S &&...slices) const
Get a host view on the slice.
Definition: linalg.h:924
HostDeviceVector< T > const * Data() const
Definition: linalg.h:871
void Reshape(size_t(&shape)[D])
Definition: linalg.h:917
auto View(DeviceOrd device) const
Definition: linalg.h:850
auto HostView()
Definition: linalg.h:861
auto Shape(size_t i) const
Definition: linalg.h:868
HostDeviceVector< T > * Data()
Definition: linalg.h:870
T & operator()(Index &&...idx)
Index operator. Not thread safe, should not be used in performance critical region....
Definition: linalg.h:825
auto View(DeviceOrd device)
Get a TensorView for this tensor.
Definition: linalg.h:840
Tensor(common::Span< I const, D > shape, DeviceOrd device, Order order=kC)
Definition: linalg.h:783
auto Shape() const
Definition: linalg.h:867
void ModifyInplace(Fn &&fn)
Visitor function for modification that changes shape and data.
Definition: linalg.h:880
void SetDevice(DeviceOrd device) const
Set device ordinal for this tensor.
Definition: linalg.h:938
Tensor(std::initializer_list< T > data, I const (&shape)[D], DeviceOrd device, Order order=kC)
Definition: linalg.h:812
void Reshape(common::Span< size_t const, D > shape)
Reshape the tensor.
Definition: linalg.h:908
DeviceOrd Device() const
Definition: linalg.h:939
auto HostView() const
Definition: linalg.h:862
Tensor(I const (&shape)[D], DeviceOrd device, Order order=kC)
Create a tensor with shape and device ordinal. The storage is initialized automatically.
Definition: linalg.h:779
T const & operator()(Index &&...idx) const
Index operator. Not thread safe, should not be used in performance critical region....
Definition: linalg.h:833
std::size_t[kDim] ShapeT
Definition: linalg.h:747
void Reshape(S &&...s)
Reshape the tensor.
Definition: linalg.h:892
ShapeT StrideT
Definition: linalg.h:748
std::size_t Size() const
Definition: linalg.h:864
A device-and-host vector abstraction layer.
#define LINALG_HD
Definition: linalg.h:36
constexpr std::size_t dynamic_extent
Definition: span.h:150
Span(std::vector< T > const &) -> Span< T const >
std::conditional_t< std::is_integral_v< RemoveCRType< S > >, IntTag, S > IndexToTag
Definition: linalg.h:117
LINALG_HD auto UnravelImpl(I idx, common::Span< size_t const, D > shape)
Definition: linalg.h:194
void ReshapeImpl(size_t(&out_shape)[D], I s)
Definition: linalg.h:215
LINALG_HD int Popc(uint32_t v)
Definition: linalg.h:136
std::remove_const_t< std::remove_reference_t< S > > RemoveCRType
Definition: linalg.h:114
constexpr int32_t CalcSliceDim()
Calculate the dimension of sliced tensor.
Definition: linalg.h:95
constexpr LINALG_HD auto UnrollLoop(Fn fn)
Definition: linalg.h:120
constexpr size_t Offset(S(&strides)[D], size_t n, Head head)
Definition: linalg.h:53
LINALG_HD void IndexToArr(std::size_t(&arr)[D], Head head)
Definition: linalg.h:161
constexpr void CalcStride(size_t const (&shape)[D], size_t(&stride)[D])
Definition: linalg.h:66
constexpr auto ArrToTuple(T(&arr)[N], std::index_sequence< Idx... >)
Definition: linalg.h:178
int32_t NativePopc(T v)
Definition: linalg.h:130
std::enable_if_t< IsAllIntegral< Index... >::value > EnableIfIntegral
Definition: linalg.h:243
constexpr size_t CalcSize(size_t(&shape)[D])
Definition: linalg.h:105
constexpr detail::RangeTag< I > Range(I beg, I end)
Specify a range of elements in the axis for slicing.
Definition: linalg.h:254
auto Make1dInterface(T const *vec, std::size_t len)
Definition: linalg.h:733
auto MakeTensorView(Context const *ctx, Container &data, S &&...shape)
Constructor for automatic type deduction.
Definition: linalg.h:564
auto ArrayInterfaceStr(TensorView< T const, D > const &t)
Return string representation of array interface.
Definition: linalg.h:719
auto MakeVec(T *ptr, size_t s, DeviceOrd device=DeviceOrd::CPU())
Create a vector view from contigious memory.
Definition: linalg.h:644
LINALG_HD auto UnravelIndex(size_t idx, common::Span< size_t const, D > shape)
Turns linear index into multi-dimension index. Similar to numpy unravel.
Definition: linalg.h:608
void Stack(Tensor< T, D > *l, Tensor< T, D > const &r)
Definition: linalg.h:981
auto Constant(Context const *ctx, T v, Index &&...index)
Create an array with value v.
Definition: linalg.h:963
auto Zeros(Context const *ctx, Index &&...index)
Like np.zeros, return a new array of given shape and type, filled with zeros.
Definition: linalg.h:975
auto Empty(Context const *ctx, Index &&...index)
Create an array without initialization.
Definition: linalg.h:952
constexpr detail::AllTag All()
Specify all elements in the axis for slicing.
Definition: linalg.h:249
Json ArrayInterface(TensorView< T const, D > const &t)
Array Interface defined by numpy.
Definition: linalg.h:675
Order
Definition: linalg.h:258
@ kC
Definition: linalg.h:259
@ kF
Definition: linalg.h:260
JsonInteger Integer
Definition: json.h:621
#define SPAN_CHECK(cond)
Definition: span.h:127
Runtime context for XGBoost. Contains information like threads and device.
Definition: context.h:133
DeviceOrd Device() const
Get the current device and ordinal.
Definition: context.h:200
bool IsCPU() const
Is XGBoost running on CPU?
Definition: context.h:173
A type for device ordinal. The type is packed into 32-bit for efficient use in viewing types like lin...
Definition: context.h:34
bool IsCUDA() const
Definition: context.h:44
bool IsCPU() const
Definition: context.h:45
constexpr static auto CPU()
Constructor for CPU.
Definition: context.h:64
static constexpr char TypeChar()
Definition: linalg.h:45
constexpr size_t Size() const
Definition: linalg.h:88
I end
Definition: linalg.h:87
I beg
Definition: linalg.h:86