Skip to content

Commit ebc90b0

Browse files
codereportalliepiper
authored andcommitted
Add unit test for inclusive_scan with User Defined Type
1 parent c7fc0eb commit ebc90b0

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

dependencies/cub

Submodule cub updated from ff56e89 to 6943751

testing/scan.cu

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -648,3 +648,27 @@ void TestExclusiveScanWithBigIndexes()
648648

649649
DECLARE_UNITTEST(TestExclusiveScanWithBigIndexes);
650650

651+
#if THRUST_CPP_DIALECT >= 2011
652+
653+
struct Int {
654+
int i{};
655+
__host__ __device__ explicit Int(int num) : i(num) {}
656+
__host__ __device__ Int() : i{} {}
657+
__host__ __device__ Int operator+(Int const& o) const { return Int{this->i + o.i}; }
658+
};
659+
660+
void TestInclusiveScanWithUserDefinedType()
661+
{
662+
thrust::device_vector<Int> vec(5, Int{1});
663+
664+
thrust::inclusive_scan(
665+
thrust::device,
666+
vec.cbegin(),
667+
vec.cend(),
668+
vec.begin());
669+
670+
ASSERT_EQUAL(static_cast<Int>(vec.back()).i, 5);
671+
}
672+
DECLARE_UNITTEST(TestInclusiveScanWithUserDefinedType);
673+
674+
#endif // c++11

0 commit comments

Comments
 (0)