Skip to content

Commit

Permalink
Rename.
Browse files Browse the repository at this point in the history
  • Loading branch information
trivialfis committed Dec 14, 2021
1 parent 96f629a commit d0b2558
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 56 deletions.
68 changes: 34 additions & 34 deletions cpp/include/raft/common/span.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ namespace raft::common {
constexpr std::size_t dynamic_extent = std::numeric_limits<std::size_t>::max();

template <class ElementType, bool is_device, std::size_t Extent>
class Span;
class span_t;

namespace detail {
/*!
Expand Down Expand Up @@ -72,7 +72,7 @@ struct is_span_oracle_t : std::false_type {
};

template <class T, bool is_device, std::size_t Extent>
struct is_span_oracle_t<Span<T, is_device, Extent>> : std::true_type {
struct is_span_oracle_t<span_t<T, is_device, Extent>> : std::true_type {
};

template <class T>
Expand All @@ -99,7 +99,7 @@ __host__ __device__ constexpr auto lexicographical_compare(InputIt1 first1,
* most of the methods have bound check on debug build.
*/
template <typename T, bool is_device, std::size_t Extent = dynamic_extent>
class Span {
class span_t {
public:
using element_type = T;
using value_type = typename std::remove_cv<T>::type;
Expand All @@ -116,21 +116,21 @@ class Span {
using const_reverse_iterator = thrust::reverse_iterator<const_iterator>;

// constructors
constexpr Span() noexcept = default;
constexpr span_t() noexcept = default;

constexpr Span(pointer _ptr, size_type _count) noexcept : size_(_count), data_(_ptr)
constexpr span_t(pointer _ptr, size_type _count) noexcept : size_(_count), data_(_ptr)
{
assert(!(Extent != dynamic_extent && _count != Extent));
assert(_ptr || _count == 0);
}

constexpr Span(pointer _first, pointer _last) noexcept : size_(_last - _first), data_(_first)
constexpr span_t(pointer _first, pointer _last) noexcept : size_(_last - _first), data_(_first)
{
assert(data_ || size_ == 0);
}

template <std::size_t N>
constexpr Span(element_type (&arr)[N]) noexcept : size_(N), data_(&arr[0])
constexpr span_t(element_type (&arr)[N]) noexcept : size_(N), data_(&arr[0])
{
}

Expand All @@ -139,14 +139,14 @@ class Span {
class = typename std::enable_if<
detail::is_allowed_element_type_conversion_t<U, T>::value &&
detail::is_allowed_extent_conversion_t<OtherExtent, Extent>::value>>
constexpr Span(const Span<U, is_device, OtherExtent>& _other) noexcept
constexpr span_t(const span_t<U, is_device, OtherExtent>& _other) noexcept
: size_(_other.size()), data_(_other.data())
{
}

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 auto operator=(const Span& _other) noexcept -> Span&
constexpr auto operator=(const span_t& _other) noexcept -> span_t&
{
size_ = _other.size();
data_ = _other.data();
Expand Down Expand Up @@ -205,26 +205,26 @@ class Span {

// Subviews
template <std::size_t Count>
constexpr auto first() const -> Span<element_type, is_device, Count>
constexpr auto first() const -> span_t<element_type, is_device, Count>
{
assert(Count <= size());
return {data(), Count};
}

constexpr auto first(std::size_t _count) const -> Span<element_type, is_device, dynamic_extent>
constexpr auto first(std::size_t _count) const -> span_t<element_type, is_device, dynamic_extent>
{
assert(_count <= size());
return {data(), _count};
}

template <std::size_t Count>
constexpr auto last() const -> Span<element_type, is_device, Count>
constexpr auto last() const -> span_t<element_type, is_device, Count>
{
assert(Count <= size());
return {data() + size() - Count, Count};
}

constexpr auto last(std::size_t _count) const -> Span<element_type, is_device, dynamic_extent>
constexpr auto last(std::size_t _count) const -> span_t<element_type, is_device, dynamic_extent>
{
assert(_count <= size());
return subspan(size() - _count, _count);
Expand All @@ -236,14 +236,14 @@ class Span {
*/
template <std::size_t Offset, std::size_t Count = dynamic_extent>
constexpr auto subspan() const
-> Span<element_type, is_device, detail::extent_value_t<Extent, Offset, Count>::value>
-> span_t<element_type, is_device, detail::extent_value_t<Extent, Offset, Count>::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<element_type, is_device, dynamic_extent>
-> span_t<element_type, is_device, dynamic_extent>
{
assert((_count == dynamic_extent) ? (_offset <= size()) : (_offset + _count <= size()));
return {data() + _offset, _count == dynamic_extent ? size() - _offset : _count};
Expand All @@ -255,13 +255,13 @@ class Span {
};

template <typename T, size_t extent = dynamic_extent>
using host_span_t = Span<T, false, extent>;
using host_span_t = span_t<T, false, extent>;

template <typename T, size_t extent = dynamic_extent>
using device_span_t = Span<T, true, extent>;
using device_span_t = span_t<T, true, extent>;

template <class T, std::size_t X, class U, std::size_t Y, bool is_device>
constexpr auto operator==(Span<T, is_device, X> l, Span<U, is_device, Y> r) -> bool
constexpr auto operator==(span_t<T, is_device, X> l, span_t<U, is_device, Y> 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) {
Expand All @@ -271,53 +271,53 @@ constexpr auto operator==(Span<T, is_device, X> l, Span<U, is_device, Y> r) -> b
}

template <class T, std::size_t X, class U, std::size_t Y, bool is_device>
constexpr auto operator!=(Span<T, is_device, X> l, Span<U, is_device, Y> r)
constexpr auto operator!=(span_t<T, is_device, X> l, span_t<U, is_device, Y> r)
{
return !(l == r);
}

template <class T, std::size_t X, class U, std::size_t Y, bool is_device>
constexpr auto operator<(Span<T, is_device, X> l, Span<U, is_device, Y> r)
constexpr auto operator<(span_t<T, is_device, X> l, span_t<U, is_device, Y> r)
{
return detail::lexicographical_compare<
typename Span<T, is_device, X>::iterator,
typename Span<U, is_device, Y>::iterator,
thrust::less<typename Span<T, is_device, X>::element_type>>(
typename span_t<T, is_device, X>::iterator,
typename span_t<U, is_device, Y>::iterator,
thrust::less<typename span_t<T, is_device, X>::element_type>>(
l.begin(), l.end(), r.begin(), r.end());
}

template <class T, std::size_t X, class U, std::size_t Y, bool is_device>
constexpr auto operator<=(Span<T, is_device, X> l, Span<U, is_device, Y> r)
constexpr auto operator<=(span_t<T, is_device, X> l, span_t<U, is_device, Y> r)
{
return !(l > r);
}

template <class T, std::size_t X, class U, std::size_t Y, bool is_device>
constexpr auto operator>(Span<T, is_device, X> l, Span<U, is_device, Y> r)
constexpr auto operator>(span_t<T, is_device, X> l, span_t<U, is_device, Y> r)
{
return detail::lexicographical_compare<
typename Span<T, is_device, X>::iterator,
typename Span<U, is_device, Y>::iterator,
thrust::greater<typename Span<T, is_device, X>::element_type>>(
typename span_t<T, is_device, X>::iterator,
typename span_t<U, is_device, Y>::iterator,
thrust::greater<typename span_t<T, is_device, X>::element_type>>(
l.begin(), l.end(), r.begin(), r.end());
}

template <class T, std::size_t X, class U, std::size_t Y, bool is_device>
constexpr auto operator>=(Span<T, is_device, X> l, Span<U, is_device, Y> r)
constexpr auto operator>=(span_t<T, is_device, X> l, span_t<U, is_device, Y> r)
{
return !(l < r);
}

template <class T, bool is_device, std::size_t E>
auto as_bytes(Span<T, is_device, E> s) noexcept
-> Span<const std::byte, is_device, detail::extent_as_bytes_value_t<T, E>::value>
auto as_bytes(span_t<T, is_device, E> s) noexcept
-> span_t<const std::byte, is_device, detail::extent_as_bytes_value_t<T, E>::value>
{
return {reinterpret_cast<const std::byte*>(s.data()), s.size_bytes()};
}

template <class T, bool is_device, std::size_t E>
auto as_writable_bytes(Span<T, is_device, E> s) noexcept
-> Span<std::byte, is_device, detail::extent_as_bytes_value_t<T, E>::value>
auto as_writable_bytes(span_t<T, is_device, E> s) noexcept
-> span_t<std::byte, is_device, detail::extent_as_bytes_value_t<T, E>::value>
{
return {reinterpret_cast<std::byte*>(s.data()), s.size_bytes()};
}
Expand Down
44 changes: 22 additions & 22 deletions cpp/test/common/test_span.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@ struct test_assignment_t {
__host__ __device__ void operator()() { this->operator()(0); }
__host__ __device__ void operator()(int _idx)
{
Span<float, is_device> s1;
span_t<float, is_device> s1;

float arr[] = {3, 4, 5};

Span<const float, is_device> s2 = arr;
span_t<const float, is_device> s2 = arr;
SPAN_ASSERT_TRUE(s2.size() == 3, status);
SPAN_ASSERT_TRUE(s2.data() == &arr[0], status);

Expand All @@ -75,9 +75,9 @@ struct test_beginend_t {
float arr[16];
initialize_range(arr, arr + 16);

Span<float, is_device> s(arr);
typename Span<float, is_device>::iterator beg{s.begin()};
typename Span<float, is_device>::iterator end{s.end()};
span_t<float, is_device> s(arr);
typename span_t<float, is_device>::iterator beg{s.begin()};
typename span_t<float, is_device>::iterator end{s.end()};

SPAN_ASSERT_TRUE(end == beg + 16, status);
SPAN_ASSERT_TRUE(*beg == arr[0], status);
Expand All @@ -97,17 +97,17 @@ struct test_rbeginrend_t {
float arr[16];
initialize_range(arr, arr + 16);

Span<float, is_device> s(arr);
span_t<float, is_device> s(arr);
s.rbegin();
typename Span<float, is_device>::reverse_iterator rbeg{s.rbegin()};
typename Span<float, is_device>::reverse_iterator rend{s.rend()};
typename span_t<float, is_device>::reverse_iterator rbeg{s.rbegin()};
typename span_t<float, is_device>::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<float, is_device>::const_reverse_iterator crbeg{s.crbegin()};
typename Span<float, is_device>::const_reverse_iterator crend{s.crend()};
typename span_t<float, is_device>::const_reverse_iterator crbeg{s.crbegin()};
typename span_t<float, is_device>::const_reverse_iterator crend{s.crend()};

SPAN_ASSERT_TRUE(crbeg + 16 == crend, status);
SPAN_ASSERT_TRUE(*(crbeg) == arr[15], status);
Expand All @@ -127,14 +127,14 @@ struct test_observers_t {
// empty
{
float* arr = nullptr;
Span<float, is_device> s(arr, static_cast<typename Span<float, is_device>::size_type>(0));
span_t<float, is_device> s(arr, static_cast<typename span_t<float, is_device>::size_type>(0));
SPAN_ASSERT_TRUE(s.empty(), status);
}

// size, size_types
{
float* arr = new float[16];
Span<float, is_device> s(arr, 16);
span_t<float, is_device> s(arr, 16);
SPAN_ASSERT_TRUE(s.size() == 16, status);
SPAN_ASSERT_TRUE(s.size_bytes() == 16 * sizeof(float), status);
delete[] arr;
Expand All @@ -155,8 +155,8 @@ struct test_compare_t {
initialize_range(lhs_arr, lhs_arr + 16);
initialize_range(rhs_arr, rhs_arr + 16);

Span<float, is_device> lhs(lhs_arr);
Span<float, is_device> rhs(rhs_arr);
span_t<float, is_device> lhs(lhs_arr);
span_t<float, is_device> rhs(rhs_arr);

SPAN_ASSERT_TRUE(lhs == rhs, status);
SPAN_ASSERT_FALSE(lhs != rhs, status);
Expand Down Expand Up @@ -185,16 +185,16 @@ struct test_as_bytes_t {
initialize_range(arr, arr + 16);

{
const Span<const float, is_device> s{arr};
const Span<const std::byte, is_device> bs = as_bytes(s);
const span_t<const float, is_device> s{arr};
const span_t<const std::byte, is_device> bs = as_bytes(s);
SPAN_ASSERT_TRUE(bs.size() == s.size_bytes(), status);
SPAN_ASSERT_TRUE(static_cast<const void*>(bs.data()) == static_cast<const void*>(s.data()),
status);
}

{
Span<float, is_device> s;
const Span<const std::byte, is_device> bs = as_bytes(s);
span_t<float, is_device> s;
const span_t<const std::byte, is_device> 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);
Expand All @@ -218,8 +218,8 @@ struct test_as_writable_bytes_t {
initialize_range(arr, arr + 16);

{
Span<float, is_device> s;
Span<std::byte, is_device> byte_s = as_writable_bytes(s);
span_t<float, is_device> s;
span_t<std::byte, is_device> 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);
Expand All @@ -229,8 +229,8 @@ struct test_as_writable_bytes_t {
}

{
Span<float, is_device> s{arr};
Span<std::byte, is_device> bs{as_writable_bytes(s)};
span_t<float, is_device> s{arr};
span_t<std::byte, is_device> bs{as_writable_bytes(s)};
SPAN_ASSERT_TRUE(s.size_bytes() == bs.size_bytes(), status);
SPAN_ASSERT_TRUE(static_cast<void*>(bs.data()) == static_cast<void*>(s.data()), status);
}
Expand Down

0 comments on commit d0b2558

Please sign in to comment.