Skip to content

Commit

Permalink
Add a test for Thrust scan with non-commutative op
Browse files Browse the repository at this point in the history
  • Loading branch information
bernhardmgruber committed Jul 23, 2024
1 parent 8635429 commit a73398e
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions thrust/testing/scan.cu
Original file line number Diff line number Diff line change
Expand Up @@ -749,3 +749,16 @@ void TestInclusiveScanWithUserDefinedType()
ASSERT_EQUAL(static_cast<Int>(vec.back()).i, 5);
}
DECLARE_UNITTEST(TestInclusiveScanWithUserDefinedType);

void TestInclusiveScanWithNonCommutativeOp()
{
thrust::device_vector<int> input = {1, 3, -2, 4, -5};
thrust::device_vector<int> output(5);

thrust::inclusive_scan(input.begin(), input.end(), output.begin(), thrust::minus<int>{});
ASSERT_EQUAL(output, (thrust::device_vector<int>{1, -2, 0, -4, 1}));

thrust::exclusive_scan(input.begin(), input.end(), output.begin(), -200, thrust::minus<int>{});
ASSERT_EQUAL(output, (thrust::device_vector<int>{-200, -201, -204, -202, -206}));
}
DECLARE_UNITTEST(TestInclusiveScanWithNonCommutativeOp);

0 comments on commit a73398e

Please sign in to comment.