forked from NVIDIA/thrust
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement is_sorted with is_sorted_until Move is_sorted to thrust/sort.h Deprecate thrust/is_sorted.h Replace #include <thrust/is_sorted.h> with #include <thrust/sort.h> Fixes issue 214
- Loading branch information
1 parent
6472386
commit ad8e187
Showing
11 changed files
with
346 additions
and
186 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
PREAMBLE = \ | ||
""" | ||
#include <thrust/sort.h> | ||
#include <thrust/is_sorted.h> | ||
#include <algorithm> | ||
""" | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
PREAMBLE = \ | ||
""" | ||
#include <thrust/sort.h> | ||
#include <thrust/is_sorted.h> | ||
""" | ||
|
||
INITIALIZE = \ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
#include <unittest/unittest.h> | ||
#include <thrust/sort.h> | ||
|
||
template<typename Vector> | ||
void TestIsSortedUntilSimple(void) | ||
{ | ||
typedef typename Vector::value_type T; | ||
typedef typename Vector::iterator Iterator; | ||
|
||
Vector v(4); | ||
v[0] = 0; v[1] = 5; v[2] = 8; v[3] = 0; | ||
|
||
Iterator first = v.begin(); | ||
|
||
Iterator last = v.begin() + 0; | ||
Iterator ref = last; | ||
ASSERT_EQUAL_QUIET(ref, thrust::is_sorted_until(first, last)); | ||
|
||
last = v.begin() + 1; | ||
ref = last; | ||
ASSERT_EQUAL_QUIET(ref, thrust::is_sorted_until(first, last)); | ||
|
||
last = v.begin() + 2; | ||
ref = last; | ||
ASSERT_EQUAL_QUIET(ref, thrust::is_sorted_until(first, last)); | ||
|
||
last = v.begin() + 3; | ||
ref = v.begin() + 3; | ||
ASSERT_EQUAL_QUIET(ref, thrust::is_sorted_until(first, last)); | ||
|
||
last = v.begin() + 4; | ||
ref = v.begin() + 3; | ||
ASSERT_EQUAL_QUIET(ref, thrust::is_sorted_until(first, last)); | ||
|
||
last = v.begin() + 3; | ||
ref = v.begin() + 3; | ||
ASSERT_EQUAL_QUIET(ref, thrust::is_sorted_until(first, last, thrust::less<T>())); | ||
|
||
last = v.begin() + 4; | ||
ref = v.begin() + 3; | ||
ASSERT_EQUAL_QUIET(ref, thrust::is_sorted_until(first, last, thrust::less<T>())); | ||
|
||
last = v.begin() + 1; | ||
ref = v.begin() + 1; | ||
ASSERT_EQUAL_QUIET(ref, thrust::is_sorted_until(first, last, thrust::greater<T>())); | ||
|
||
last = v.begin() + 4; | ||
ref = v.begin() + 1; | ||
ASSERT_EQUAL_QUIET(ref, thrust::is_sorted_until(first, last, thrust::greater<T>())); | ||
|
||
first = v.begin() + 2; | ||
last = v.begin() + 4; | ||
ref = v.begin() + 4; | ||
ASSERT_EQUAL_QUIET(ref, thrust::is_sorted_until(first, last, thrust::greater<T>())); | ||
} | ||
DECLARE_VECTOR_UNITTEST(TestIsSortedUntilSimple); | ||
|
||
template<typename Vector> | ||
void TestIsSortedUntilRepeatedElements(void) | ||
{ | ||
Vector v(10); | ||
|
||
v[0] = 0; | ||
v[1] = 1; | ||
v[2] = 1; | ||
v[3] = 2; | ||
v[4] = 3; | ||
v[5] = 4; | ||
v[6] = 5; | ||
v[7] = 5; | ||
v[8] = 5; | ||
v[9] = 6; | ||
|
||
ASSERT_EQUAL_QUIET(v.end(), thrust::is_sorted_until(v.begin(), v.end())); | ||
} | ||
DECLARE_VECTOR_UNITTEST(TestIsSortedUntilRepeatedElements); | ||
|
||
template <class Vector> | ||
void TestIsSortedUntil(void) | ||
{ | ||
typedef typename Vector::value_type T; | ||
|
||
const size_t n = (1 << 16) + 13; | ||
|
||
Vector v = unittest::random_integers<T>(n); | ||
|
||
v[0] = 1; | ||
v[1] = 0; | ||
|
||
ASSERT_EQUAL_QUIET(v.begin() + 1, thrust::is_sorted_until(v.begin(), v.end())); | ||
|
||
thrust::sort(v.begin(), v.end()); | ||
|
||
ASSERT_EQUAL_QUIET(v.end(), thrust::is_sorted_until(v.begin(), v.end())); | ||
} | ||
DECLARE_VECTOR_UNITTEST(TestIsSortedUntil); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.