xgboost

span.h
Go to the documentation of this file.
1
29 #ifndef XGBOOST_SPAN_H_
30 #define XGBOOST_SPAN_H_
31
32 #include <xgboost/base.h>
33 #include <xgboost/logging.h>
34
35 #include <cinttypes> // size_t
36 #include <limits> // numeric_limits
37 #include <iterator>
38 #include <type_traits>
39 #include <cstdio>
40
58 #if defined(_MSC_VER) && _MSC_VER < 1910
59
60 #define __span_noexcept
61
62 #pragma push_macro("constexpr")
63 #define constexpr /*constexpr*/
64
65 #else
66
67 #define __span_noexcept noexcept
68
69 #endif // defined(_MSC_VER) && _MSC_VER < 1910
70
71 namespace xgboost {
72 namespace common {
73
74 // Usual logging facility is not available inside device code.
75 // assert is not supported in mac as of CUDA 10.0
76 #define KERNEL_CHECK(cond) \
77 do { \
78 if (!(cond)) { \
79 printf("\nKernel error:\n" \
80 "In: %s: %d\n" \
81 "\t%s\n\tExpecting: %s\n" \
82 "\tBlock: [%d, %d, %d], Thread: [%d, %d, %d]\n\n", \
83 __FILE__, __LINE__, __PRETTY_FUNCTION__, #cond, blockIdx.x, \
84 blockIdx.y, blockIdx.z, threadIdx.x, threadIdx.y, threadIdx.z); \
85 asm("trap;"); \
86 } \
87 } while (0);
88
89 #if defined(__CUDA_ARCH__)
90 #define SPAN_CHECK KERNEL_CHECK
91 #elif defined(XGBOOST_STRICT_R_MODE) && XGBOOST_STRICT_R_MODE == 1 // R package
92 #define SPAN_CHECK CHECK // check from dmlc
93 #else // not CUDA, not R
94 #define SPAN_CHECK(cond) \
95 do { \
96 if (XGBOOST_EXPECT(!(cond), false)) { \
97 fprintf(stderr, "[xgboost] Condition %s failed.\n", #cond); \
98 fflush(stderr); /* It seems stderr on Windows is beffered? */ \
99 std::terminate(); \
100 } \
101 } while (0);
102 #endif // __CUDA_ARCH__
103
104 namespace detail {
111 using ptrdiff_t = typename std::conditional< // NOLINT
112 std::is_same<std::ptrdiff_t, std::int64_t>::value,
113 std::ptrdiff_t, std::int64_t>::type;
114 } // namespace detail
115
116 #if defined(_MSC_VER) && _MSC_VER < 1910
117 constexpr const std::size_t
118 dynamic_extent = std::numeric_limits<std::size_t>::max(); // NOLINT
119 #else
120 constexpr std::size_t dynamic_extent = std::numeric_limits<std::size_t>::max(); // NOLINT
121 #endif // defined(_MSC_VER) && _MSC_VER < 1910
122
123 enum class byte : unsigned char {}; // NOLINT
124
125 template <class ElementType, std::size_t Extent>
126 class Span;
127
128 namespace detail {
129
130 template <typename SpanType, bool IsConst>
131 class SpanIterator {
132 using ElementType = typename SpanType::element_type;
133
134 public:
135 using iterator_category = std::random_access_iterator_tag; // NOLINT
136 using value_type = typename SpanType::value_type; // NOLINT
137 using difference_type = detail::ptrdiff_t; // NOLINT
138
139 using reference = typename std::conditional< // NOLINT
140 IsConst, const ElementType, ElementType>::type&;
141 using pointer = typename std::add_pointer<reference>::type; // NOLINT
142
143 constexpr SpanIterator() = default;
144
145 XGBOOST_DEVICE constexpr SpanIterator(
146 const SpanType* _span,
147 typename SpanType::index_type _idx) __span_noexcept :
148 span_(_span), index_(_idx) {}
149
150 friend SpanIterator<SpanType, true>;
151 template <bool B, typename std::enable_if<!B && IsConst>::type* = nullptr>
152 XGBOOST_DEVICE constexpr SpanIterator( // NOLINT
153 const SpanIterator<SpanType, B>& other_) __span_noexcept
154 : SpanIterator(other_.span_, other_.index_) {}
155
156 XGBOOST_DEVICE reference operator*() const {
157 SPAN_CHECK(index_ < span_->size());
158 return *(span_->data() + index_);
159 }
160 XGBOOST_DEVICE reference operator[](difference_type n) const {
161 return *(*this + n);
162 }
163
164 XGBOOST_DEVICE pointer operator->() const {
165 SPAN_CHECK(index_ != span_->size());
166 return span_->data() + index_;
167 }
168
169 XGBOOST_DEVICE SpanIterator& operator++() {
170 SPAN_CHECK(index_ != span_->size());
171 index_++;
172 return *this;
173 }
174
175 XGBOOST_DEVICE SpanIterator operator++(int) {
176 auto ret = *this;
177 ++(*this);
178 return ret;
179 }
180
181 XGBOOST_DEVICE SpanIterator& operator--() {
182 SPAN_CHECK(index_ != 0 && index_ <= span_->size());
183 index_--;
184 return *this;
185 }
186
187 XGBOOST_DEVICE SpanIterator operator--(int) {
188 auto ret = *this;
189 --(*this);
190 return ret;
191 }
192
193 XGBOOST_DEVICE SpanIterator operator+(difference_type n) const {
194 auto ret = *this;
195 return ret += n;
196 }
197
198 XGBOOST_DEVICE SpanIterator& operator+=(difference_type n) {
199 SPAN_CHECK((index_ + n) <= span_->size());
200 index_ += n;
201 return *this;
202 }
203
204 XGBOOST_DEVICE difference_type operator-(SpanIterator rhs) const {
205 SPAN_CHECK(span_ == rhs.span_);
206 return index_ - rhs.index_;
207 }
208
209 XGBOOST_DEVICE SpanIterator operator-(difference_type n) const {
210 auto ret = *this;
211 return ret -= n;
212 }
213
214 XGBOOST_DEVICE SpanIterator& operator-=(difference_type n) {
215 return *this += -n;
216 }
217
218 // friends
219 XGBOOST_DEVICE constexpr friend bool operator==(
220 SpanIterator _lhs, SpanIterator _rhs) __span_noexcept {
221 return _lhs.span_ == _rhs.span_ && _lhs.index_ == _rhs.index_;
222 }
223
224 XGBOOST_DEVICE constexpr friend bool operator!=(
225 SpanIterator _lhs, SpanIterator _rhs) __span_noexcept {
226 return !(_lhs == _rhs);
227 }
228
229 XGBOOST_DEVICE constexpr friend bool operator<(
230 SpanIterator _lhs, SpanIterator _rhs) __span_noexcept {
231 return _lhs.index_ < _rhs.index_;
232 }
233
234 XGBOOST_DEVICE constexpr friend bool operator<=(
235 SpanIterator _lhs, SpanIterator _rhs) __span_noexcept {
236 return !(_rhs < _lhs);
237 }
238
239 XGBOOST_DEVICE constexpr friend bool operator>(
240 SpanIterator _lhs, SpanIterator _rhs) __span_noexcept {
241 return _rhs < _lhs;
242 }
243
244 XGBOOST_DEVICE constexpr friend bool operator>=(
245 SpanIterator _lhs, SpanIterator _rhs) __span_noexcept {
246 return !(_rhs > _lhs);
247 }
248
249 protected:
250 const SpanType *span_ { nullptr };
251 typename SpanType::index_type index_ { 0 };
252 };
253
254
255 // It's tempting to use constexpr instead of structs to do the following meta
256 // programming. But remember that we are supporting MSVC 2013 here.
257
265 template <std::size_t Extent, std::size_t Offset, std::size_t Count>
266 struct ExtentValue : public std::integral_constant<
267 std::size_t, Count != dynamic_extent ?
268 Count : (Extent != dynamic_extent ? Extent - Offset : Extent)> {};
269
274 template <typename T, std::size_t Extent>
275 struct ExtentAsBytesValue : public std::integral_constant<
276 std::size_t,
277 Extent == dynamic_extent ?
278 Extent : sizeof(T) * Extent> {};
279
280 template <std::size_t From, std::size_t To>
281 struct IsAllowedExtentConversion : public std::integral_constant<
282 bool, From == To || From == dynamic_extent || To == dynamic_extent> {};
283
284 template <class From, class To>
285 struct IsAllowedElementTypeConversion : public std::integral_constant<
286 bool, std::is_convertible<From(*)[], To(*)[]>::value> {};
287
288 template <class T>
289 struct IsSpanOracle : std::false_type {};
290
291 template <class T, std::size_t Extent>
292 struct IsSpanOracle<Span<T, Extent>> : std::true_type {};
293
294 template <class T>
295 struct IsSpan : public IsSpanOracle<typename std::remove_cv<T>::type> {};
296
297 // Re-implement std algorithms here to adopt CUDA.
298 template <typename T>
299 struct Less {
300 XGBOOST_DEVICE constexpr bool operator()(const T& _x, const T& _y) const {
301 return _x < _y;
302 }
303 };
304
305 template <typename T>
306 struct Greater {
307 XGBOOST_DEVICE constexpr bool operator()(const T& _x, const T& _y) const {
308 return _x > _y;
309 }
310 };
311
312 template <class InputIt1, class InputIt2,
313 class Compare =
314 detail::Less<decltype(std::declval<InputIt1>().operator*())>>
315 XGBOOST_DEVICE bool LexicographicalCompare(InputIt1 first1, InputIt1 last1,
316 InputIt2 first2, InputIt2 last2) {
317 Compare comp;
318 for (; first1 != last1 && first2 != last2; ++first1, ++first2) {
319 if (comp(*first1, *first2)) {
320 return true;
321 }
322 if (comp(*first2, *first1)) {
323 return false;
324 }
325 }
326 return first1 == last1 && first2 != last2;
327 }
328
329 } // namespace detail
330
331
399 template <typename T,
400 std::size_t Extent = dynamic_extent>
401 class Span {
402 public:
403 using element_type = T; // NOLINT
404 using value_type = typename std::remove_cv<T>::type; // NOLINT
405 using index_type = std::size_t; // NOLINT
406 using difference_type = detail::ptrdiff_t; // NOLINT
407 using pointer = T*; // NOLINT
408 using reference = T&; // NOLINT
409
410 using iterator = detail::SpanIterator<Span<T, Extent>, false>; // NOLINT
411 using const_iterator = const detail::SpanIterator<Span<T, Extent>, true>; // NOLINT
412 using reverse_iterator = detail::SpanIterator<Span<T, Extent>, false>; // NOLINT
413 using const_reverse_iterator = const detail::SpanIterator<Span<T, Extent>, true>; // NOLINT
414
415 // constructors
416 constexpr Span() __span_noexcept = default;
417
418 XGBOOST_DEVICE Span(pointer _ptr, index_type _count) :
419 size_(_count), data_(_ptr) {
420 SPAN_CHECK(!(Extent != dynamic_extent && _count != Extent));
421 SPAN_CHECK(_ptr || _count == 0);
422 }
423
424 XGBOOST_DEVICE Span(pointer _first, pointer _last) :
425 size_(_last - _first), data_(_first) {
426 SPAN_CHECK(data_ || size_ == 0);
427 }
428
429 template <std::size_t N>
430 XGBOOST_DEVICE constexpr Span(element_type (&arr)[N]) // NOLINT
431 __span_noexcept : size_(N), data_(&arr[0]) {}
432
433 template <class Container,
434 class = typename std::enable_if<
435 !std::is_const<element_type>::value &&
436 !detail::IsSpan<Container>::value &&
437 std::is_convertible<typename Container::pointer, pointer>::value &&
438 std::is_convertible<typename Container::pointer,
439 decltype(std::declval<Container>().data())>::value>::type>
440 Span(Container& _cont) : // NOLINT
441 size_(_cont.size()), data_(_cont.data()) {
442 static_assert(!detail::IsSpan<Container>::value, "Wrong constructor of Span is called.");
443 }
444
445 template <class Container,
446 class = typename std::enable_if<
447 std::is_const<element_type>::value &&
448 !detail::IsSpan<Container>::value &&
449 std::is_convertible<typename Container::pointer, pointer>::value &&
450 std::is_convertible<typename Container::pointer,
451 decltype(std::declval<Container>().data())>::value>::type>
452 Span(const Container& _cont) : size_(_cont.size()), // NOLINT
453 data_(_cont.data()) {
454 static_assert(!detail::IsSpan<Container>::value, "Wrong constructor of Span is called.");
455 }
456
457 template <class U, std::size_t OtherExtent,
458 class = typename std::enable_if<
459 detail::IsAllowedElementTypeConversion<U, T>::value &&
460 detail::IsAllowedExtentConversion<OtherExtent, Extent>::value>>
461 XGBOOST_DEVICE constexpr Span(const Span<U, OtherExtent>& _other) // NOLINT
462 __span_noexcept : size_(_other.size()), data_(_other.data()) {}
463
464 XGBOOST_DEVICE constexpr Span(const Span& _other)
465 __span_noexcept : size_(_other.size()), data_(_other.data()) {}
466
467 XGBOOST_DEVICE Span& operator=(const Span& _other) __span_noexcept {
468 size_ = _other.size();
469 data_ = _other.data();
470 return *this;
471 }
472
473 XGBOOST_DEVICE ~Span() __span_noexcept {}; // NOLINT
474
475 XGBOOST_DEVICE constexpr iterator begin() const __span_noexcept { // NOLINT
476 return {this, 0};
477 }
478
479 XGBOOST_DEVICE constexpr iterator end() const __span_noexcept { // NOLINT
480 return {this, size()};
481 }
482
483 XGBOOST_DEVICE constexpr const_iterator cbegin() const __span_noexcept { // NOLINT
484 return {this, 0};
485 }
486
487 XGBOOST_DEVICE constexpr const_iterator cend() const __span_noexcept { // NOLINT
488 return {this, size()};
489 }
490
491 XGBOOST_DEVICE constexpr reverse_iterator rbegin() const __span_noexcept { // NOLINT
492 return reverse_iterator{end()};
493 }
494
495 XGBOOST_DEVICE constexpr reverse_iterator rend() const __span_noexcept { // NOLINT
496 return reverse_iterator{begin()};
497 }
498
499 XGBOOST_DEVICE constexpr const_reverse_iterator crbegin() const __span_noexcept { // NOLINT
500 return const_reverse_iterator{cend()};
501 }
502
503 XGBOOST_DEVICE constexpr const_reverse_iterator crend() const __span_noexcept { // NOLINT
504 return const_reverse_iterator{cbegin()};
505 }
506
507 // element access
508
509 XGBOOST_DEVICE reference front() const { // NOLINT
510 return (*this)[0];
511 }
512
513 XGBOOST_DEVICE reference back() const { // NOLINT
514 return (*this)[size() - 1];
515 }
516
517 XGBOOST_DEVICE reference operator[](index_type _idx) const {
518 SPAN_CHECK(_idx < size());
519 return data()[_idx];
520 }
521
522 XGBOOST_DEVICE reference operator()(index_type _idx) const {
523 return this->operator[](_idx);
524 }
525
526 XGBOOST_DEVICE constexpr pointer data() const __span_noexcept { // NOLINT
527 return data_;
528 }
529
530 // Observers
531 XGBOOST_DEVICE constexpr index_type size() const __span_noexcept { // NOLINT
532 return size_;
533 }
534 XGBOOST_DEVICE constexpr index_type size_bytes() const __span_noexcept { // NOLINT
535 return size() * sizeof(T);
536 }
537
538 XGBOOST_DEVICE constexpr bool empty() const __span_noexcept { // NOLINT
539 return size() == 0;
540 }
541
542 // Subviews
543 template <std::size_t Count>
544 XGBOOST_DEVICE Span<element_type, Count> first() const { // NOLINT
545 SPAN_CHECK(Count <= size());
546 return {data(), Count};
547 }
548
549 XGBOOST_DEVICE Span<element_type, dynamic_extent> first( // NOLINT
550 std::size_t _count) const {
551 SPAN_CHECK(_count <= size());
552 return {data(), _count};
553 }
554
555 template <std::size_t Count>
556 XGBOOST_DEVICE Span<element_type, Count> last() const { // NOLINT
557 SPAN_CHECK(Count <= size());
558 return {data() + size() - Count, Count};
559 }
560
561 XGBOOST_DEVICE Span<element_type, dynamic_extent> last( // NOLINT
562 std::size_t _count) const {
563 SPAN_CHECK(_count <= size());
564 return subspan(size() - _count, _count);
565 }
566
571 template <std::size_t Offset,
572 std::size_t Count = dynamic_extent>
573 XGBOOST_DEVICE auto subspan() const -> // NOLINT
574 Span<element_type,
575 detail::ExtentValue<Extent, Offset, Count>::value> {
576 SPAN_CHECK(Offset < size() || size() == 0);
577 SPAN_CHECK(Count == dynamic_extent || (Offset + Count <= size()));
578
579 return {data() + Offset, Count == dynamic_extent ? size() - Offset : Count};
580 }
581
582 XGBOOST_DEVICE Span<element_type, dynamic_extent> subspan( // NOLINT
583 index_type _offset,
584 index_type _count = dynamic_extent) const {
585 SPAN_CHECK(_offset < size() || size() == 0);
586 SPAN_CHECK((_count == dynamic_extent) || (_offset + _count <= size()));
587
588 return {data() + _offset, _count ==
589 dynamic_extent ? size() - _offset : _count};
590 }
591
592 private:
593 index_type size_ { 0 };
594 pointer data_ { nullptr };
595 };
596
597 template <class T, std::size_t X, class U, std::size_t Y>
598 XGBOOST_DEVICE bool operator==(Span<T, X> l, Span<U, Y> r) {
599 if (l.size() != r.size()) {
600 return false;
601 }
602 for (auto l_beg = l.cbegin(), r_beg = r.cbegin(); l_beg != l.cend();
603 ++l_beg, ++r_beg) {
604 if (*l_beg != *r_beg) {
605 return false;
606 }
607 }
608 return true;
609 }
610
611 template <class T, std::size_t X, class U, std::size_t Y>
612 XGBOOST_DEVICE constexpr bool operator!=(Span<T, X> l, Span<U, Y> r) {
613 return !(l == r);
614 }
615
616 template <class T, std::size_t X, class U, std::size_t Y>
617 XGBOOST_DEVICE constexpr bool operator<(Span<T, X> l, Span<U, Y> r) {
618 return detail::LexicographicalCompare(l.begin(), l.end(),
619 r.begin(), r.end());
620 }
621
622 template <class T, std::size_t X, class U, std::size_t Y>
623 XGBOOST_DEVICE constexpr bool operator<=(Span<T, X> l, Span<U, Y> r) {
624 return !(l > r);
625 }
626
627 template <class T, std::size_t X, class U, std::size_t Y>
628 XGBOOST_DEVICE constexpr bool operator>(Span<T, X> l, Span<U, Y> r) {
629 return detail::LexicographicalCompare<
630 typename Span<T, X>::iterator, typename Span<U, Y>::iterator,
631 detail::Greater<typename Span<T, X>::element_type>>(l.begin(), l.end(),
632 r.begin(), r.end());
633 }
634
635 template <class T, std::size_t X, class U, std::size_t Y>
636 XGBOOST_DEVICE constexpr bool operator>=(Span<T, X> l, Span<U, Y> r) {
637 return !(l < r);
638 }
639
640 template <class T, std::size_t E>
641 XGBOOST_DEVICE auto as_bytes(Span<T, E> s) __span_noexcept -> // NOLINT
642 Span<const byte, detail::ExtentAsBytesValue<T, E>::value> {
643 return {reinterpret_cast<const byte*>(s.data()), s.size_bytes()};
644 }
645
646 template <class T, std::size_t E>
647 XGBOOST_DEVICE auto as_writable_bytes(Span<T, E> s) __span_noexcept -> // NOLINT
648 Span<byte, detail::ExtentAsBytesValue<T, E>::value> {
649 return {reinterpret_cast<byte*>(s.data()), s.size_bytes()};
650 }
651
652 } // namespace common
653 } // namespace xgboost
654
655 #if defined(_MSC_VER) &&_MSC_VER < 1910
656 #undef constexpr
657 #pragma pop_macro("constexpr")
658 #undef __span_noexcept
659 #endif // _MSC_VER < 1910
660
661 #endif // XGBOOST_SPAN_H_
xgboost::common::byte
byte
Definition: span.h:123
xgboost::common::operator>=
XGBOOST_DEVICE constexpr bool operator>=(Span< T, X > l, Span< U, Y > r)
Definition: span.h:636
xgboost::common::detail::SpanIterator::operator>=
XGBOOST_DEVICE constexpr friend bool operator>=(SpanIterator _lhs, SpanIterator _rhs) __span_noexcept
Definition: span.h:244
SPAN_CHECK
#define SPAN_CHECK(cond)
Definition: span.h:94
xgboost::common::Span::first
XGBOOST_DEVICE Span< element_type, Count > first() const
Definition: span.h:544
xgboost::common::Span::size
XGBOOST_DEVICE constexpr index_type size() const __span_noexcept
Definition: span.h:531
xgboost::common::Span::Span
XGBOOST_DEVICE Span(pointer _first, pointer _last)
Definition: span.h:424
xgboost::common::Span::empty
XGBOOST_DEVICE constexpr bool empty() const __span_noexcept
Definition: span.h:538
xgboost::common::Span::operator()
XGBOOST_DEVICE reference operator()(index_type _idx) const
Definition: span.h:522
xgboost::common::detail::SpanIterator::operator--
XGBOOST_DEVICE SpanIterator & operator--()
Definition: span.h:181
xgboost::common::detail::SpanIterator::operator--
XGBOOST_DEVICE SpanIterator operator--(int)
Definition: span.h:187
xgboost::common::Span< const BinIdxType >::index_type
std::size_t index_type
Definition: span.h:405
xgboost::common::Span::subspan
XGBOOST_DEVICE Span< element_type, dynamic_extent > subspan(index_type _offset, index_type _count=dynamic_extent) const
Definition: span.h:582
xgboost::common::detail::SpanIterator::SpanIterator
XGBOOST_DEVICE constexpr SpanIterator(const SpanIterator< SpanType, B > &other_) __span_noexcept
Definition: span.h:152
xgboost::common::operator>
XGBOOST_DEVICE constexpr bool operator>(Span< T, X > l, Span< U, Y > r)
Definition: span.h:628
xgboost::common::Span::end
XGBOOST_DEVICE constexpr iterator end() const __span_noexcept
Definition: span.h:479
xgboost::common::detail::SpanIterator::operator-
XGBOOST_DEVICE SpanIterator operator-(difference_type n) const
Definition: span.h:209
xgboost::common::detail::SpanIterator::operator+=
XGBOOST_DEVICE SpanIterator & operator+=(difference_type n)
Definition: span.h:198
xgboost::common::detail::ExtentAsBytesValue
Definition: span.h:275
xgboost::common::Span::Span
Span(const Container &_cont)
Definition: span.h:452
xgboost::common::detail::SpanIterator::operator<=
XGBOOST_DEVICE constexpr friend bool operator<=(SpanIterator _lhs, SpanIterator _rhs) __span_noexcept
Definition: span.h:234
xgboost::common::detail::Less
Definition: span.h:299
xgboost::common::detail::SpanIterator::operator+
XGBOOST_DEVICE SpanIterator operator+(difference_type n) const
Definition: span.h:193
xgboost::common::Span< const BinIdxType >::element_type
const BinIdxType element_type
Definition: span.h:403
xgboost::common::detail::IsAllowedExtentConversion
Definition: span.h:281
xgboost::common::detail::Greater
Definition: span.h:306
xgboost::common::detail::SpanIterator
Definition: span.h:131
xgboost::common::as_bytes
XGBOOST_DEVICE auto as_bytes(Span< T, E > s) __span_noexcept -> Span< const byte, detail::ExtentAsBytesValue< T, E >::value >
Definition: span.h:641
xgboost::common::Span::Span
Span(Container &_cont)
Definition: span.h:440
xgboost::common::detail::SpanIterator::operator[]
XGBOOST_DEVICE reference operator[](difference_type n) const
Definition: span.h:160
xgboost::common::Span< const BinIdxType >::difference_type
detail::ptrdiff_t difference_type
Definition: span.h:406
xgboost::common::detail::SpanIterator::value_type
typename SpanType::value_type value_type
Definition: span.h:136
xgboost::common::Span::back
XGBOOST_DEVICE reference back() const
Definition: span.h:513
xgboost::common::Span::Span
XGBOOST_DEVICE constexpr Span(const Span &_other) __span_noexcept
Definition: span.h:464
xgboost::common::Span< const BinIdxType >::reference
const BinIdxType & reference
Definition: span.h:408
xgboost::common::as_writable_bytes
XGBOOST_DEVICE auto as_writable_bytes(Span< T, E > s) __span_noexcept -> Span< byte, detail::ExtentAsBytesValue< T, E >::value >
Definition: span.h:647
xgboost::common::detail::SpanIterator::operator!=
XGBOOST_DEVICE constexpr friend bool operator!=(SpanIterator _lhs, SpanIterator _rhs) __span_noexcept
Definition: span.h:224
xgboost::common::detail::Greater::operator()
XGBOOST_DEVICE constexpr bool operator()(const T &_x, const T &_y) const
Definition: span.h:307
xgboost::common::detail::IsSpan
Definition: span.h:295
xgboost::common::detail::SpanIterator::iterator_category
std::random_access_iterator_tag iterator_category
Definition: span.h:135
xgboost::common::Span::first
XGBOOST_DEVICE Span< element_type, dynamic_extent > first(std::size_t _count) const
Definition: span.h:549
xgboost::common::Span
span class implementation, based on ISO++20 span<T>. The interface should be the same.
Definition: span.h:126
xgboost::common::detail::SpanIterator::operator++
XGBOOST_DEVICE SpanIterator & operator++()
Definition: span.h:169
xgboost::common::detail::SpanIterator::reference
typename std::conditional< IsConst, const ElementType, ElementType >::type & reference
Definition: span.h:140
xgboost::common::detail::SpanIterator::operator-=
XGBOOST_DEVICE SpanIterator & operator-=(difference_type n)
Definition: span.h:214
xgboost::common::detail::LexicographicalCompare
XGBOOST_DEVICE bool LexicographicalCompare(InputIt1 first1, InputIt1 last1, InputIt2 first2, InputIt2 last2)
Definition: span.h:315
xgboost::common::detail::SpanIterator::operator>
XGBOOST_DEVICE constexpr friend bool operator>(SpanIterator _lhs, SpanIterator _rhs) __span_noexcept
Definition: span.h:239
xgboost::common::Span< const BinIdxType >::value_type
typename std::remove_cv< const BinIdxType >::type value_type
Definition: span.h:404
xgboost::common::detail::ptrdiff_t
typename std::conditional< std::is_same< std::ptrdiff_t, std::int64_t >::value, std::ptrdiff_t, std::int64_t >::type ptrdiff_t
Definition: span.h:113
xgboost::common::Span::last
XGBOOST_DEVICE Span< element_type, Count > last() const
Definition: span.h:556
xgboost::common::Span::data
XGBOOST_DEVICE constexpr pointer data() const __span_noexcept
Definition: span.h:526
xgboost::common::Span::crend
XGBOOST_DEVICE constexpr const_reverse_iterator crend() const __span_noexcept
Definition: span.h:503
xgboost::common::detail::SpanIterator::SpanIterator
XGBOOST_DEVICE constexpr SpanIterator(const SpanType *_span, typename SpanType::index_type _idx) __span_noexcept
Definition: span.h:145
xgboost::common::dynamic_extent
constexpr std::size_t dynamic_extent
Definition: span.h:120
xgboost::common::Span::rbegin
XGBOOST_DEVICE constexpr reverse_iterator rbegin() const __span_noexcept
Definition: span.h:491
xgboost::common::detail::Less::operator()
XGBOOST_DEVICE constexpr bool operator()(const T &_x, const T &_y) const
Definition: span.h:300
xgboost::common::operator!=
XGBOOST_DEVICE constexpr bool operator!=(Span< T, X > l, Span< U, Y > r)
Definition: span.h:612
XGBOOST_DEVICE
#define XGBOOST_DEVICE
Tag function as usable by device.
Definition: base.h:84
xgboost::common::detail::SpanIterator::index_
SpanType::index_type index_
Definition: span.h:251
xgboost
namespace of xgboost
Definition: base.h:102
xgboost::common::Span::rend
XGBOOST_DEVICE constexpr reverse_iterator rend() const __span_noexcept
Definition: span.h:495
xgboost::common::detail::ExtentValue
Definition: span.h:266
xgboost::common::Span::last
XGBOOST_DEVICE Span< element_type, dynamic_extent > last(std::size_t _count) const
Definition: span.h:561
xgboost::common::Span::front
XGBOOST_DEVICE reference front() const
Definition: span.h:509
base.h
defines configuration macros of xgboost.
xgboost::common::Span::crbegin
XGBOOST_DEVICE constexpr const_reverse_iterator crbegin() const __span_noexcept
Definition: span.h:499
xgboost::common::detail::SpanIterator::span_
const SpanType * span_
Definition: span.h:250
xgboost::common::Span::subspan
XGBOOST_DEVICE auto subspan() const -> Span< element_type, detail::ExtentValue< Extent, Offset, Count >::value >
Definition: span.h:573
xgboost::common::Span::Span
XGBOOST_DEVICE constexpr Span(element_type(&arr)[N]) __span_noexcept
Definition: span.h:430
xgboost::common::Span::cbegin
XGBOOST_DEVICE constexpr const_iterator cbegin() const __span_noexcept
Definition: span.h:483
xgboost::common::detail::SpanIterator::operator++
XGBOOST_DEVICE SpanIterator operator++(int)
Definition: span.h:175
xgboost::common::Span< const BinIdxType >::pointer
const BinIdxType * pointer
Definition: span.h:407
xgboost::common::Span::operator[]
XGBOOST_DEVICE reference operator[](index_type _idx) const
Definition: span.h:517
xgboost::common::detail::SpanIterator::operator<
XGBOOST_DEVICE constexpr friend bool operator<(SpanIterator _lhs, SpanIterator _rhs) __span_noexcept
Definition: span.h:229
xgboost::common::Span::size_bytes
XGBOOST_DEVICE constexpr index_type size_bytes() const __span_noexcept
Definition: span.h:534
xgboost::common::Span::cend
XGBOOST_DEVICE constexpr const_iterator cend() const __span_noexcept
Definition: span.h:487
__span_noexcept
#define __span_noexcept
span class based on ISO++20 span
Definition: span.h:67
xgboost::common::Span::operator=
XGBOOST_DEVICE Span & operator=(const Span &_other) __span_noexcept
Definition: span.h:467
xgboost::common::detail::SpanIterator::operator==
XGBOOST_DEVICE constexpr friend bool operator==(SpanIterator _lhs, SpanIterator _rhs) __span_noexcept
Definition: span.h:219
xgboost::common::detail::SpanIterator::pointer
typename std::add_pointer< reference >::type pointer
Definition: span.h:141
xgboost::common::Span::Span
XGBOOST_DEVICE constexpr Span(const Span< U, OtherExtent > &_other) __span_noexcept
Definition: span.h:461
xgboost::common::detail::SpanIterator::difference_type
detail::ptrdiff_t difference_type
Definition: span.h:137
xgboost::common::Span::begin
XGBOOST_DEVICE constexpr iterator begin() const __span_noexcept
Definition: span.h:475
xgboost::common::detail::SpanIterator::operator-
XGBOOST_DEVICE difference_type operator-(SpanIterator rhs) const
Definition: span.h:204
xgboost::common::detail::IsAllowedElementTypeConversion
Definition: span.h:285
xgboost::common::Span::~Span
XGBOOST_DEVICE ~Span() __span_noexcept
Definition: span.h:473
xgboost::common::detail::IsSpanOracle
Definition: span.h:289
xgboost::common::detail::SpanIterator::operator*
XGBOOST_DEVICE reference operator*() const
Definition: span.h:156
xgboost::common::detail::SpanIterator::operator->
XGBOOST_DEVICE pointer operator->() const
Definition: span.h:164
xgboost::common::operator==
XGBOOST_DEVICE bool operator==(Span< T, X > l, Span< U, Y > r)
Definition: span.h:598