Fix span reverse iterator. (#7387)

* Fix span reverse iterator.

* Disable `rbegin` on device code to avoid calling host function.
* Add `trbegin` and friends.
This commit is contained in:
Jiaming Yuan
2021-11-02 13:35:59 +08:00
committed by GitHub
parent 8211e5f341
commit 6295dc3b67
3 changed files with 37 additions and 11 deletions

View File

@@ -98,12 +98,18 @@ struct TestRBeginREnd {
InitializeRange(arr, arr + 16);
Span<float> s (arr);
Span<float>::iterator rbeg { s.rbegin() };
Span<float>::iterator rend { s.rend() };
SPAN_ASSERT_TRUE(rbeg == rend + 16, status_);
SPAN_ASSERT_TRUE(*(rbeg - 1) == arr[15], status_);
SPAN_ASSERT_TRUE(*rend == arr[0], status_);
#if defined(__CUDA_ARCH__)
auto rbeg = dh::trbegin(s);
auto rend = dh::trend(s);
#else
Span<float>::reverse_iterator rbeg{s.rbegin()};
Span<float>::reverse_iterator rend{s.rend()};
#endif
SPAN_ASSERT_TRUE(rbeg + 16 == rend, status_);
SPAN_ASSERT_TRUE(*(rbeg) == arr[15], status_);
SPAN_ASSERT_TRUE(*(rend - 1) == arr[0], status_);
}
};