xgboost
Classes | Namespaces | Macros | Typedefs | Enumerations | Functions
linalg.h File Reference

Linear algebra related utilities. More...

#include <dmlc/endian.h>
#include <xgboost/base.h>
#include <xgboost/context.h>
#include <xgboost/host_device_vector.h>
#include <xgboost/json.h>
#include <xgboost/span.h>
#include <algorithm>
#include <cassert>
#include <cinttypes>
#include <cstddef>
#include <limits>
#include <string>
#include <tuple>
#include <type_traits>
#include <utility>
#include <vector>
Include dependency graph for linalg.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  xgboost::linalg::detail::ArrayInterfaceHandler
 
struct  xgboost::linalg::detail::AllTag
 
struct  xgboost::linalg::detail::IntTag
 
struct  xgboost::linalg::detail::RangeTag< I >
 
struct  xgboost::linalg::detail::Conjunction<... >
 
struct  xgboost::linalg::detail::Conjunction< B1 >
 
struct  xgboost::linalg::detail::Conjunction< B1, Bn... >
 
class  xgboost::linalg::TensorView< T, kDim >
 A tensor view with static type and dimension. It implements indexing and slicing. More...
 
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. More...
 

Namespaces

 xgboost
 Core data structure for multi-target trees.
 
 xgboost::linalg
 
 xgboost::linalg::detail
 

Macros

#define LINALG_HD
 

Typedefs

template<typename S >
using xgboost::linalg::detail::RemoveCRType = std::remove_const_t< std::remove_reference_t< S > >
 
template<typename S >
using xgboost::linalg::detail::IndexToTag = std::conditional_t< std::is_integral< RemoveCRType< S > >::value, IntTag, S >
 
template<typename... Index>
using xgboost::linalg::detail::IsAllIntegral = Conjunction< std::is_integral< std::remove_reference_t< Index > >... >
 
template<typename... Index>
using xgboost::linalg::detail::EnableIfIntegral = std::enable_if_t< IsAllIntegral< Index... >::value >
 
template<typename T >
using xgboost::linalg::VectorView = TensorView< T, 1 >
 A view over a vector, specialization of Tensor. More...
 
template<typename T >
using xgboost::linalg::MatrixView = TensorView< T, 2 >
 A view over a matrix, specialization of Tensor. More...
 
template<typename T >
using xgboost::linalg::Matrix = Tensor< T, 2 >
 
template<typename T >
using xgboost::linalg::Vector = Tensor< T, 1 >
 

Enumerations

enum  xgboost::linalg::Order : std::uint8_t { xgboost::linalg::kC , xgboost::linalg::kF }
 

Functions

template<size_t dim, typename S , typename Head , size_t D>
constexpr size_t xgboost::linalg::detail::Offset (S(&strides)[D], size_t n, Head head)
 
template<size_t dim, typename S , size_t D, typename Head , typename... Tail>
constexpr std::enable_if_t< sizeof...(Tail) !=0, size_t > xgboost::linalg::detail::Offset (S(&strides)[D], size_t n, Head head, Tail &&...rest)
 
template<int32_t D, bool f_array = false>
constexpr void xgboost::linalg::detail::CalcStride (size_t const (&shape)[D], size_t(&stride)[D])
 
template<typename T >
constexpr int32_t xgboost::linalg::detail::CalcSliceDim ()
 Calculate the dimension of sliced tensor. More...
 
template<typename T , typename... S>
constexpr std::enable_if_t< sizeof...(S) !=0, int32_t > xgboost::linalg::detail::CalcSliceDim ()
 
template<int32_t D>
constexpr size_t xgboost::linalg::detail::CalcSize (size_t(&shape)[D])
 
template<int32_t n, typename Fn >
constexpr LINALG_HD auto xgboost::linalg::detail::UnrollLoop (Fn fn)
 
template<typename T >
int32_t xgboost::linalg::detail::NativePopc (T v)
 
LINALG_HD int xgboost::linalg::detail::Popc (uint32_t v)
 
LINALG_HD int xgboost::linalg::detail::Popc (uint64_t v)
 
template<std::size_t D, typename Head >
LINALG_HD void xgboost::linalg::detail::IndexToArr (std::size_t(&arr)[D], Head head)
 
template<std::size_t D, typename Head , typename... Rest>
LINALG_HD void xgboost::linalg::detail::IndexToArr (std::size_t(&arr)[D], Head head, Rest &&...index)
 Convert index from parameter pack to C-style array. More...
 
template<class T , std::size_t N, std::size_t... Idx>
constexpr auto xgboost::linalg::detail::ArrToTuple (T(&arr)[N], std::index_sequence< Idx... >)
 
template<class T , std::size_t N>
constexpr auto xgboost::linalg::detail::ArrToTuple (T(&arr)[N])
 Convert C-styple array to std::tuple. More...
 
template<typename I , std::int32_t D>
LINALG_HD auto xgboost::linalg::detail::UnravelImpl (I idx, common::Span< size_t const, D > shape)
 
template<size_t dim, typename I , int32_t D>
void xgboost::linalg::detail::ReshapeImpl (size_t(&out_shape)[D], I s)
 
template<size_t dim, int32_t D, typename... S, typename I , std::enable_if_t< sizeof...(S) !=0 > * = nullptr>
void xgboost::linalg::detail::ReshapeImpl (size_t(&out_shape)[D], I &&s, S &&...rest)
 
template<typename Fn , typename Tup , size_t... I>
decltype(auto) constexpr LINALG_HD xgboost::linalg::detail::Apply (Fn &&f, Tup &&t, std::index_sequence< I... >)
 
template<typename Fn , typename Tup >
decltype(auto) constexpr LINALG_HD xgboost::linalg::detail::Apply (Fn &&f, Tup &&t)
 
constexpr detail::AllTag xgboost::linalg::All ()
 Specify all elements in the axis for slicing. More...
 
template<typename I >
constexpr detail::RangeTag< I > xgboost::linalg::Range (I beg, I end)
 Specify a range of elements in the axis for slicing. More...
 
template<typename Container , typename... S, std::enable_if_t<!common::detail::IsSpan< Container >::value &&!std::is_pointer_v< Container >> * = nullptr>
auto xgboost::linalg::MakeTensorView (Context const *ctx, Container &data, S &&...shape)
 Constructor for automatic type deduction. More...
 
template<typename T , decltype(common::dynamic_extent) ext, typename... S>
LINALG_HD auto xgboost::linalg::MakeTensorView (DeviceOrd device, common::Span< T, ext > data, S &&...shape)
 
template<typename T , decltype(common::dynamic_extent) ext, typename... S>
auto xgboost::linalg::MakeTensorView (Context const *ctx, common::Span< T, ext > data, S &&...shape)
 
template<typename T , decltype(common::dynamic_extent) ext, typename... S>
auto xgboost::linalg::MakeTensorView (Context const *ctx, Order order, common::Span< T, ext > data, S &&...shape)
 
template<typename T , typename... S>
auto xgboost::linalg::MakeTensorView (Context const *ctx, HostDeviceVector< T > *data, S &&...shape)
 
template<typename T , typename... S>
auto xgboost::linalg::MakeTensorView (Context const *ctx, HostDeviceVector< T > const *data, S &&...shape)
 
template<size_t D>
LINALG_HD auto xgboost::linalg::UnravelIndex (size_t idx, common::Span< size_t const, D > shape)
 Turns linear index into multi-dimension index. Similar to numpy unravel. More...
 
template<size_t D>
LINALG_HD auto xgboost::linalg::UnravelIndex (size_t idx, std::size_t const (&shape)[D])
 
template<typename... S>
LINALG_HD auto xgboost::linalg::UnravelIndex (std::size_t idx, S... shape)
 
template<typename T >
auto xgboost::linalg::MakeVec (T *ptr, size_t s, DeviceOrd device=DeviceOrd::CPU())
 Create a vector view from contigious memory. More...
 
template<typename T >
auto xgboost::linalg::MakeVec (HostDeviceVector< T > *data)
 
template<typename T >
auto xgboost::linalg::MakeVec (HostDeviceVector< T > const *data)
 
template<typename T , std::int32_t D>
Json xgboost::linalg::ArrayInterface (TensorView< T const, D > const &t)
 Array Interface defined by numpy. More...
 
template<typename T , int32_t D>
Json xgboost::linalg::ArrayInterface (TensorView< T, D > const &t)
 Same as const version, but returns non-readonly data pointer. More...
 
template<typename T , int32_t D>
auto xgboost::linalg::ArrayInterfaceStr (TensorView< T const, D > const &t)
 Return string representation of array interface. More...
 
template<typename T , int32_t D>
auto xgboost::linalg::ArrayInterfaceStr (TensorView< T, D > const &t)
 
template<typename T >
auto xgboost::linalg::Make1dInterface (T const *vec, std::size_t len)
 
template<typename T , typename... Index>
auto xgboost::linalg::Empty (Context const *ctx, Index &&...index)
 Create an array without initialization. More...
 
template<typename T , typename... Index>
auto xgboost::linalg::Constant (Context const *ctx, T v, Index &&...index)
 Create an array with value v. More...
 
template<typename T , typename... Index>
auto xgboost::linalg::Zeros (Context const *ctx, Index &&...index)
 Like np.zeros, return a new array of given shape and type, filled with zeros. More...
 
template<typename T , int32_t D>
void xgboost::linalg::Stack (Tensor< T, D > *l, Tensor< T, D > const &r)
 

Detailed Description

Linear algebra related utilities.

Copyright 2021-2023 by XGBoost Contributors

Macro Definition Documentation

◆ LINALG_HD

#define LINALG_HD