Span: use size_t' for index_type, add front' and `back'. (#4935)
* Use `size_t' for index_type. Add `front' and `back'. * Remove a batch of `static_cast'.
This commit is contained in:
@@ -380,9 +380,7 @@ class DoubleBuffer {
|
||||
|
||||
T *Current() { return buff.Current(); }
|
||||
xgboost::common::Span<T> CurrentSpan() {
|
||||
return xgboost::common::Span<T>{
|
||||
buff.Current(),
|
||||
static_cast<typename xgboost::common::Span<T>::index_type>(Size())};
|
||||
return xgboost::common::Span<T>{buff.Current(), Size()};
|
||||
}
|
||||
|
||||
T *other() { return buff.Alternate(); }
|
||||
@@ -1120,17 +1118,16 @@ template <typename T,
|
||||
xgboost::common::Span<T> ToSpan(
|
||||
device_vector<T>& vec,
|
||||
IndexT offset = 0,
|
||||
IndexT size = -1) {
|
||||
size = size == -1 ? vec.size() : size;
|
||||
IndexT size = std::numeric_limits<size_t>::max()) {
|
||||
size = size == std::numeric_limits<size_t>::max() ? vec.size() : size;
|
||||
CHECK_LE(offset + size, vec.size());
|
||||
return {vec.data().get() + offset, static_cast<IndexT>(size)};
|
||||
return {vec.data().get() + offset, size};
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
xgboost::common::Span<T> ToSpan(thrust::device_vector<T>& vec,
|
||||
size_t offset, size_t size) {
|
||||
using IndexT = typename xgboost::common::Span<T>::index_type;
|
||||
return ToSpan(vec, static_cast<IndexT>(offset), static_cast<IndexT>(size));
|
||||
return ToSpan(vec, offset, size);
|
||||
}
|
||||
|
||||
// thrust begin, similiar to std::begin
|
||||
|
||||
@@ -343,7 +343,7 @@ struct GHistIndexBlock {
|
||||
|
||||
// get i-th row
|
||||
inline GHistIndexRow operator[](size_t i) const {
|
||||
return {&index[0] + row_ptr[i], detail::ptrdiff_t(row_ptr[i + 1] - row_ptr[i])};
|
||||
return {&index[0] + row_ptr[i], row_ptr[i + 1] - row_ptr[i]};
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -69,13 +69,12 @@ class HostDeviceVectorImpl {
|
||||
|
||||
common::Span<T> DeviceSpan() {
|
||||
LazySyncDevice(GPUAccess::kWrite);
|
||||
return {data_d_.data().get(), static_cast<typename common::Span<T>::index_type>(Size())};
|
||||
return {data_d_.data().get(), Size()};
|
||||
}
|
||||
|
||||
common::Span<const T> ConstDeviceSpan() {
|
||||
LazySyncDevice(GPUAccess::kRead);
|
||||
using SpanInd = typename common::Span<const T>::index_type;
|
||||
return {data_d_.data().get(), static_cast<SpanInd>(Size())};
|
||||
return {data_d_.data().get(), Size()};
|
||||
}
|
||||
|
||||
void Fill(T v) { // NOLINT
|
||||
|
||||
Reference in New Issue
Block a user