diff --git a/cpp/include/raft/common/span.hpp b/cpp/include/raft/common/span.hpp index 587fb4ea0e..6f907eba5a 100644 --- a/cpp/include/raft/common/span.hpp +++ b/cpp/include/raft/common/span.hpp @@ -29,7 +29,7 @@ namespace raft::common { constexpr std::size_t dynamic_extent = std::numeric_limits::max(); template -class span_t; +class span; namespace detail { /*! @@ -72,7 +72,7 @@ struct is_span_oracle_t : std::false_type { }; template -struct is_span_oracle_t> : std::true_type { +struct is_span_oracle_t> : std::true_type { }; template @@ -99,7 +99,7 @@ __host__ __device__ constexpr auto lexicographical_compare(InputIt1 first1, * most of the methods have bound check on debug build. */ template -class span_t { +class span { public: using element_type = T; using value_type = typename std::remove_cv::type; @@ -116,21 +116,21 @@ class span_t { using const_reverse_iterator = thrust::reverse_iterator; // constructors - constexpr span_t() noexcept = default; + constexpr span() noexcept = default; - constexpr span_t(pointer _ptr, size_type _count) noexcept : size_(_count), data_(_ptr) + constexpr span(pointer _ptr, size_type _count) noexcept : size_(_count), data_(_ptr) { assert(!(Extent != dynamic_extent && _count != Extent)); assert(_ptr || _count == 0); } - constexpr span_t(pointer _first, pointer _last) noexcept : size_(_last - _first), data_(_first) + constexpr span(pointer _first, pointer _last) noexcept : size_(_last - _first), data_(_first) { assert(data_ || size_ == 0); } template - constexpr span_t(element_type (&arr)[N]) noexcept : size_(N), data_(&arr[0]) + constexpr span(element_type (&arr)[N]) noexcept : size_(N), data_(&arr[0]) { } @@ -139,14 +139,14 @@ class span_t { class = typename std::enable_if< detail::is_allowed_element_type_conversion_t::value && detail::is_allowed_extent_conversion_t::value>> - constexpr span_t(const span_t& _other) noexcept + constexpr span(const span& _other) noexcept : size_(_other.size()), data_(_other.data()) { } - constexpr span_t(const span_t& _other) noexcept : size_(_other.size()), data_(_other.data()) {} + constexpr span(const span& _other) noexcept : size_(_other.size()), data_(_other.data()) {} - constexpr auto operator=(const span_t& _other) noexcept -> span_t& + constexpr auto operator=(const span& _other) noexcept -> span& { size_ = _other.size(); data_ = _other.data(); @@ -186,7 +186,8 @@ class span_t { constexpr auto back() const -> reference { return (*this)[size() - 1]; } - constexpr auto operator[](size_type _idx) const -> reference + template + constexpr auto operator[](Index _idx) const -> reference { assert(_idx < size()); return data()[_idx]; @@ -205,26 +206,26 @@ class span_t { // Subviews template - constexpr auto first() const -> span_t + constexpr auto first() const -> span { assert(Count <= size()); return {data(), Count}; } - constexpr auto first(std::size_t _count) const -> span_t + constexpr auto first(std::size_t _count) const -> span { assert(_count <= size()); return {data(), _count}; } template - constexpr auto last() const -> span_t + constexpr auto last() const -> span { assert(Count <= size()); return {data() + size() - Count, Count}; } - constexpr auto last(std::size_t _count) const -> span_t + constexpr auto last(std::size_t _count) const -> span { assert(_count <= size()); return subspan(size() - _count, _count); @@ -236,14 +237,14 @@ class span_t { */ template constexpr auto subspan() const - -> span_t::value> + -> span::value> { assert((Count == dynamic_extent) ? (Offset <= size()) : (Offset + Count <= size())); return {data() + Offset, Count == dynamic_extent ? size() - Offset : Count}; } constexpr auto subspan(size_type _offset, size_type _count = dynamic_extent) const - -> span_t + -> span { assert((_count == dynamic_extent) ? (_offset <= size()) : (_offset + _count <= size())); return {data() + _offset, _count == dynamic_extent ? size() - _offset : _count}; @@ -255,13 +256,13 @@ class span_t { }; template -using host_span_t = span_t; +using host_span = span; template -using device_span_t = span_t; +using device_span = span; template -constexpr auto operator==(span_t l, span_t r) -> bool +constexpr auto operator==(span l, span r) -> bool { if (l.size() != r.size()) { return false; } for (auto l_beg = l.cbegin(), r_beg = r.cbegin(); l_beg != l.cend(); ++l_beg, ++r_beg) { @@ -271,53 +272,53 @@ constexpr auto operator==(span_t l, span_t r) } template -constexpr auto operator!=(span_t l, span_t r) +constexpr auto operator!=(span l, span r) { return !(l == r); } template -constexpr auto operator<(span_t l, span_t r) +constexpr auto operator<(span l, span r) { return detail::lexicographical_compare< - typename span_t::iterator, - typename span_t::iterator, - thrust::less::element_type>>( + typename span::iterator, + typename span::iterator, + thrust::less::element_type>>( l.begin(), l.end(), r.begin(), r.end()); } template -constexpr auto operator<=(span_t l, span_t r) +constexpr auto operator<=(span l, span r) { return !(l > r); } template -constexpr auto operator>(span_t l, span_t r) +constexpr auto operator>(span l, span r) { return detail::lexicographical_compare< - typename span_t::iterator, - typename span_t::iterator, - thrust::greater::element_type>>( + typename span::iterator, + typename span::iterator, + thrust::greater::element_type>>( l.begin(), l.end(), r.begin(), r.end()); } template -constexpr auto operator>=(span_t l, span_t r) +constexpr auto operator>=(span l, span r) { return !(l < r); } template -auto as_bytes(span_t s) noexcept - -> span_t::value> +auto as_bytes(span s) noexcept + -> span::value> { return {reinterpret_cast(s.data()), s.size_bytes()}; } template -auto as_writable_bytes(span_t s) noexcept - -> span_t::value> +auto as_writable_bytes(span s) noexcept + -> span::value> { return {reinterpret_cast(s.data()), s.size_bytes()}; } diff --git a/cpp/test/common/span.cpp b/cpp/test/common/span.cpp index e1e7245718..2e2837866c 100644 --- a/cpp/test/common/span.cpp +++ b/cpp/test/common/span.cpp @@ -23,33 +23,33 @@ TEST(Span, DlfConstructors) { // Dynamic extent { - host_span_t s; + host_span s; ASSERT_EQ(s.size(), 0); ASSERT_EQ(s.data(), nullptr); - host_span_t cs; + host_span cs; ASSERT_EQ(cs.size(), 0); ASSERT_EQ(cs.data(), nullptr); } // Static extent { - host_span_t s; + host_span s; ASSERT_EQ(s.size(), 0); ASSERT_EQ(s.data(), nullptr); - host_span_t cs; + host_span cs; ASSERT_EQ(cs.size(), 0); ASSERT_EQ(cs.data(), nullptr); } // Init list. { - host_span_t s{}; + host_span s{}; ASSERT_EQ(s.size(), 0); ASSERT_EQ(s.data(), nullptr); - host_span_t cs{}; + host_span cs{}; ASSERT_EQ(cs.size(), 0); ASSERT_EQ(cs.data(), nullptr); } @@ -59,21 +59,21 @@ TEST(Span, FromNullPtr) { // dynamic extent { - host_span_t s{nullptr, static_cast::size_type>(0)}; + host_span s{nullptr, static_cast::size_type>(0)}; ASSERT_EQ(s.size(), 0); ASSERT_EQ(s.data(), nullptr); - host_span_t cs{nullptr, static_cast::size_type>(0)}; + host_span cs{nullptr, static_cast::size_type>(0)}; ASSERT_EQ(cs.size(), 0); ASSERT_EQ(cs.data(), nullptr); } // static extent { - host_span_t s{nullptr, static_cast::size_type>(0)}; + host_span s{nullptr, static_cast::size_type>(0)}; ASSERT_EQ(s.size(), 0); ASSERT_EQ(s.data(), nullptr); - host_span_t cs{nullptr, static_cast::size_type>(0)}; + host_span cs{nullptr, static_cast::size_type>(0)}; ASSERT_EQ(cs.size(), 0); ASSERT_EQ(cs.data(), nullptr); } @@ -86,26 +86,26 @@ TEST(Span, FromPtrLen) // static extent { - host_span_t s(arr, 16); + host_span s(arr, 16); ASSERT_EQ(s.size(), 16); ASSERT_EQ(s.data(), arr); - for (host_span_t::size_type i = 0; i < 16; ++i) { + for (host_span::size_type i = 0; i < 16; ++i) { ASSERT_EQ(s[i], arr[i]); } - host_span_t cs(arr, 16); + host_span cs(arr, 16); ASSERT_EQ(cs.size(), 16); ASSERT_EQ(cs.data(), arr); - for (host_span_t::size_type i = 0; i < 16; ++i) { + for (host_span::size_type i = 0; i < 16; ++i) { ASSERT_EQ(cs[i], arr[i]); } } // dynamic extent { - host_span_t s(arr, 16); + host_span s(arr, 16); ASSERT_EQ(s.size(), 16); ASSERT_EQ(s.data(), arr); @@ -113,11 +113,11 @@ TEST(Span, FromPtrLen) ASSERT_EQ(s[i], arr[i]); } - host_span_t cs(arr, 16); + host_span cs(arr, 16); ASSERT_EQ(cs.size(), 16); ASSERT_EQ(cs.data(), arr); - for (host_span_t::size_type i = 0; i < 16; ++i) { + for (host_span::size_type i = 0; i < 16; ++i) { ASSERT_EQ(cs[i], arr[i]); } } @@ -130,7 +130,7 @@ TEST(Span, FromFirstLast) // dynamic extent { - host_span_t s(arr, arr + 16); + host_span s(arr, arr + 16); ASSERT_EQ(s.size(), 16); ASSERT_EQ(s.data(), arr); ASSERT_EQ(s.data() + s.size(), arr + 16); @@ -139,7 +139,7 @@ TEST(Span, FromFirstLast) ASSERT_EQ(s[i], arr[i]); } - host_span_t cs(arr, arr + 16); + host_span cs(arr, arr + 16); ASSERT_EQ(cs.size(), 16); ASSERT_EQ(cs.data(), arr); ASSERT_EQ(cs.data() + cs.size(), arr + 16); @@ -151,7 +151,7 @@ TEST(Span, FromFirstLast) // static extent { - host_span_t s(arr, arr + 16); + host_span s(arr, arr + 16); ASSERT_EQ(s.size(), 16); ASSERT_EQ(s.data(), arr); ASSERT_EQ(s.data() + s.size(), arr + 16); @@ -160,7 +160,7 @@ TEST(Span, FromFirstLast) ASSERT_EQ(s[i], arr[i]); } - host_span_t cs(arr, arr + 16); + host_span cs(arr, arr + 16); ASSERT_EQ(cs.size(), 16); ASSERT_EQ(cs.data(), arr); ASSERT_EQ(cs.data() + cs.size(), arr + 16); @@ -184,8 +184,8 @@ TEST(Span, FromOther) { // convert constructor { - host_span_t derived; - host_span_t base{derived}; + host_span derived; + host_span base{derived}; ASSERT_EQ(base.size(), derived.size()); ASSERT_EQ(base.data(), derived.data()); } @@ -195,8 +195,8 @@ TEST(Span, FromOther) // default copy constructor { - host_span_t s0(arr); - host_span_t s1(s0); + host_span s0(arr); + host_span s1(s0); ASSERT_EQ(s0.size(), s1.size()); ASSERT_EQ(s0.data(), s1.data()); } @@ -208,7 +208,7 @@ TEST(Span, FromArray) initialize_range(arr, arr + 16); { - host_span_t s(arr); + host_span s(arr); ASSERT_EQ(&arr[0], s.data()); ASSERT_EQ(s.size(), 16); for (size_t i = 0; i < 16; ++i) { @@ -217,7 +217,7 @@ TEST(Span, FromArray) } { - host_span_t s(arr); + host_span s(arr); ASSERT_EQ(&arr[0], s.data()); ASSERT_EQ(s.size(), 16); for (size_t i = 0; i < 16; ++i) { @@ -245,7 +245,7 @@ TEST(Span, ElementAccess) float arr[16]; initialize_range(arr, arr + 16); - host_span_t s(arr); + host_span s(arr); size_t j = 0; for (auto i : s) { ASSERT_EQ(i, arr[j]); @@ -264,13 +264,13 @@ TEST(Span, FrontBack) { { float arr[4]{0, 1, 2, 3}; - host_span_t s(arr); + host_span s(arr); ASSERT_EQ(s.front(), 0); ASSERT_EQ(s.back(), 3); } { std::vector arr{0, 1, 2, 3}; - host_span_t s(arr.data(), arr.size()); + host_span s(arr.data(), arr.size()); ASSERT_EQ(s.front(), 0); ASSERT_EQ(s.back(), 3); } @@ -283,8 +283,8 @@ TEST(Span, FirstLast) float arr[16]; initialize_range(arr, arr + 16); - host_span_t s(arr); - host_span_t first = s.first<4>(); + host_span s(arr); + host_span first = s.first<4>(); ASSERT_EQ(first.size(), 4); ASSERT_EQ(first.data(), arr); @@ -298,8 +298,8 @@ TEST(Span, FirstLast) float arr[16]; initialize_range(arr, arr + 16); - host_span_t s(arr); - host_span_t last = s.last<4>(); + host_span s(arr); + host_span last = s.last<4>(); ASSERT_EQ(last.size(), 4); ASSERT_EQ(last.data(), arr + 12); @@ -313,8 +313,8 @@ TEST(Span, FirstLast) { float* arr = new float[16]; initialize_range(arr, arr + 16); - host_span_t s(arr, 16); - host_span_t first = s.first(4); + host_span s(arr, 16); + host_span first = s.first(4); ASSERT_EQ(first.size(), 4); ASSERT_EQ(first.data(), s.data()); @@ -329,8 +329,8 @@ TEST(Span, FirstLast) { float* arr = new float[16]; initialize_range(arr, arr + 16); - host_span_t s(arr, 16); - host_span_t last = s.last(4); + host_span s(arr, 16); + host_span last = s.last(4); ASSERT_EQ(last.size(), 4); ASSERT_EQ(last.data(), s.data() + 12); @@ -346,7 +346,7 @@ TEST(Span, FirstLast) TEST(Span, Subspan) { int arr[16]{0}; - host_span_t s1(arr); + host_span s1(arr); auto s2 = s1.subspan<4>(); ASSERT_EQ(s1.size() - 4, s2.size()); @@ -383,7 +383,7 @@ TEST(Span, AsWritableBytes) TEST(Span, Empty) { { - host_span_t s{nullptr, static_cast::size_type>(0)}; + host_span s{nullptr, static_cast::size_type>(0)}; auto res = s.subspan(0); ASSERT_EQ(res.data(), nullptr); ASSERT_EQ(res.size(), 0); @@ -394,7 +394,7 @@ TEST(Span, Empty) } { - host_span_t s{nullptr, static_cast::size_type>(0)}; + host_span s{nullptr, static_cast::size_type>(0)}; auto res = s.subspan(0); ASSERT_EQ(res.data(), nullptr); ASSERT_EQ(res.size(), 0); diff --git a/cpp/test/common/span.cu b/cpp/test/common/span.cu index 9bd0be5c92..c5646d1a1c 100644 --- a/cpp/test/common/span.cu +++ b/cpp/test/common/span.cu @@ -46,7 +46,7 @@ struct TestStatus { int* Data() { return status_; } }; -__global__ void TestFromOtherKernel(device_span_t span) +__global__ void TestFromOtherKernel(device_span span) { // don't get optimized out size_t idx = threadIdx.x + blockIdx.x * blockDim.x; @@ -54,7 +54,7 @@ __global__ void TestFromOtherKernel(device_span_t span) if (idx >= span.size()) { return; } } // Test converting different T -__global__ void TestFromOtherKernelConst(device_span_t span) +__global__ void TestFromOtherKernelConst(device_span span) { // don't get optimized out size_t idx = threadIdx.x + blockIdx.x * blockDim.x; @@ -74,20 +74,20 @@ TEST(GPUSpan, FromOther) thrust::copy(h_vec.begin(), h_vec.end(), d_vec.begin()); // dynamic extent { - device_span_t span(d_vec.data().get(), d_vec.size()); + device_span span(d_vec.data().get(), d_vec.size()); TestFromOtherKernel<<<1, 16>>>(span); } { - device_span_t span(d_vec.data().get(), d_vec.size()); + device_span span(d_vec.data().get(), d_vec.size()); TestFromOtherKernelConst<<<1, 16>>>(span); } // static extent { - device_span_t span(d_vec.data().get(), d_vec.data().get() + 16); + device_span span(d_vec.data().get(), d_vec.data().get() + 16); TestFromOtherKernel<<<1, 16>>>(span); } { - device_span_t span(d_vec.data().get(), d_vec.data().get() + 16); + device_span span(d_vec.data().get(), d_vec.data().get() + 16); TestFromOtherKernelConst<<<1, 16>>>(span); } } @@ -139,7 +139,7 @@ TEST(GPUSpan, WithTrust) // Can't initialize span with device_vector, since d_vec.data() is not raw // pointer { - device_span_t s(d_vec.data().get(), d_vec.size()); + device_span s(d_vec.data().get(), d_vec.size()); ASSERT_EQ(d_vec.size(), s.size()); ASSERT_EQ(d_vec.data().get(), s.data()); @@ -149,7 +149,7 @@ TEST(GPUSpan, WithTrust) TestStatus status; thrust::device_vector d_vec1(d_vec.size()); thrust::copy(thrust::device, d_vec.begin(), d_vec.end(), d_vec1.begin()); - device_span_t s(d_vec1.data().get(), d_vec.size()); + device_span s(d_vec1.data().get(), d_vec.size()); thrust::for_each_n( thrust::make_counting_iterator(0ul), @@ -176,7 +176,7 @@ TEST(GPUSpan, RBeginREnd) ASSERT_EQ(status.Get(), 1); } -__global__ void TestModifyKernel(device_span_t span) +__global__ void TestModifyKernel(device_span span) { size_t idx = threadIdx.x + blockIdx.x * blockDim.x; @@ -192,7 +192,7 @@ TEST(GPUSpan, Modify) thrust::device_vector d_vec(h_vec.size()); thrust::copy(h_vec.begin(), h_vec.end(), d_vec.begin()); - device_span_t span(d_vec.data().get(), d_vec.size()); + device_span span(d_vec.data().get(), d_vec.size()); TestModifyKernel<<<1, 16>>>(span); diff --git a/cpp/test/common/test_span.hpp b/cpp/test/common/test_span.hpp index 3eb2ca74ad..63fbda8652 100644 --- a/cpp/test/common/test_span.hpp +++ b/cpp/test/common/test_span.hpp @@ -50,11 +50,11 @@ struct test_assignment_t { __host__ __device__ void operator()() { this->operator()(0); } __host__ __device__ void operator()(int _idx) { - span_t s1; + span s1; float arr[] = {3, 4, 5}; - span_t s2 = arr; + span s2 = arr; SPAN_ASSERT_TRUE(s2.size() == 3, status); SPAN_ASSERT_TRUE(s2.data() == &arr[0], status); @@ -75,9 +75,9 @@ struct test_beginend_t { float arr[16]; initialize_range(arr, arr + 16); - span_t s(arr); - typename span_t::iterator beg{s.begin()}; - typename span_t::iterator end{s.end()}; + span s(arr); + typename span::iterator beg{s.begin()}; + typename span::iterator end{s.end()}; SPAN_ASSERT_TRUE(end == beg + 16, status); SPAN_ASSERT_TRUE(*beg == arr[0], status); @@ -97,17 +97,17 @@ struct test_rbeginrend_t { float arr[16]; initialize_range(arr, arr + 16); - span_t s(arr); + span s(arr); s.rbegin(); - typename span_t::reverse_iterator rbeg{s.rbegin()}; - typename span_t::reverse_iterator rend{s.rend()}; + typename span::reverse_iterator rbeg{s.rbegin()}; + typename span::reverse_iterator rend{s.rend()}; SPAN_ASSERT_TRUE(rbeg + 16 == rend, status); SPAN_ASSERT_TRUE(*(rbeg) == arr[15], status); SPAN_ASSERT_TRUE(*(rend - 1) == arr[0], status); - typename span_t::const_reverse_iterator crbeg{s.crbegin()}; - typename span_t::const_reverse_iterator crend{s.crend()}; + typename span::const_reverse_iterator crbeg{s.crbegin()}; + typename span::const_reverse_iterator crend{s.crend()}; SPAN_ASSERT_TRUE(crbeg + 16 == crend, status); SPAN_ASSERT_TRUE(*(crbeg) == arr[15], status); @@ -127,14 +127,14 @@ struct test_observers_t { // empty { float* arr = nullptr; - span_t s(arr, static_cast::size_type>(0)); + span s(arr, static_cast::size_type>(0)); SPAN_ASSERT_TRUE(s.empty(), status); } // size, size_types { float* arr = new float[16]; - span_t s(arr, 16); + span s(arr, 16); SPAN_ASSERT_TRUE(s.size() == 16, status); SPAN_ASSERT_TRUE(s.size_bytes() == 16 * sizeof(float), status); delete[] arr; @@ -155,8 +155,8 @@ struct test_compare_t { initialize_range(lhs_arr, lhs_arr + 16); initialize_range(rhs_arr, rhs_arr + 16); - span_t lhs(lhs_arr); - span_t rhs(rhs_arr); + span lhs(lhs_arr); + span rhs(rhs_arr); SPAN_ASSERT_TRUE(lhs == rhs, status); SPAN_ASSERT_FALSE(lhs != rhs, status); @@ -185,16 +185,16 @@ struct test_as_bytes_t { initialize_range(arr, arr + 16); { - const span_t s{arr}; - const span_t bs = as_bytes(s); + const span s{arr}; + const span bs = as_bytes(s); SPAN_ASSERT_TRUE(bs.size() == s.size_bytes(), status); SPAN_ASSERT_TRUE(static_cast(bs.data()) == static_cast(s.data()), status); } { - span_t s; - const span_t bs = as_bytes(s); + span s; + const span bs = as_bytes(s); SPAN_ASSERT_TRUE(bs.size() == s.size(), status); SPAN_ASSERT_TRUE(bs.size() == 0, status); SPAN_ASSERT_TRUE(bs.size_bytes() == 0, status); @@ -218,8 +218,8 @@ struct test_as_writable_bytes_t { initialize_range(arr, arr + 16); { - span_t s; - span_t byte_s = as_writable_bytes(s); + span s; + span byte_s = as_writable_bytes(s); SPAN_ASSERT_TRUE(byte_s.size() == s.size(), status); SPAN_ASSERT_TRUE(byte_s.size_bytes() == s.size_bytes(), status); SPAN_ASSERT_TRUE(byte_s.size() == 0, status); @@ -229,8 +229,8 @@ struct test_as_writable_bytes_t { } { - span_t s{arr}; - span_t bs{as_writable_bytes(s)}; + span s{arr}; + span bs{as_writable_bytes(s)}; SPAN_ASSERT_TRUE(s.size_bytes() == bs.size_bytes(), status); SPAN_ASSERT_TRUE(static_cast(bs.data()) == static_cast(s.data()), status); }