Skip to content

Commit

Permalink
Use transparent functionals in placeholder expressions.
Browse files Browse the repository at this point in the history
Fixes and adds regression tests for NVIDIA#1178 & NVIDIA#1229.
  • Loading branch information
alliepiper committed Jul 17, 2020
1 parent 0c81f42 commit 412f699
Show file tree
Hide file tree
Showing 9 changed files with 560 additions and 327 deletions.
33 changes: 33 additions & 0 deletions testing/find.cu
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <unittest/unittest.h>
#include <thrust/sequence.h>
#include <thrust/find.h>
#include <thrust/iterator/retag.h>

Expand Down Expand Up @@ -338,3 +339,35 @@ void TestFindWithBigIndexes()
TestFindWithBigIndexesHelper(33);
}
DECLARE_UNITTEST(TestFindWithBigIndexes);

namespace
{

class Weird
{
int value;

public:
__host__ __device__ Weird(int val, int)
: value(val)
{}

friend __host__ __device__
bool operator==(int x, Weird y)
{
return x == y.value;
}
};

} // end anon namespace

void TestFindAsymmetricEquality()
{ // Regression test for thrust/thrust#1229
thrust::host_vector<int> v(1000);
thrust::sequence(v.begin(), v.end());
thrust::device_vector<int> dv(v);
auto result = thrust::find(dv.begin(), dv.end(), Weird(333, 0));
ASSERT_EQUAL(*result, 333);
ASSERT_EQUAL(result - dv.begin(), 333);
}
DECLARE_UNITTEST(TestFindAsymmetricEquality);
18 changes: 18 additions & 0 deletions testing/inner_product.cu
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
#include <unittest/unittest.h>
#include <thrust/inner_product.h>

#include <thrust/functional.h>
#include <thrust/iterator/retag.h>
#include <thrust/device_malloc.h>
#include <thrust/device_free.h>
#include <thrust/device_vector.h>

template <class Vector>
void TestInnerProductSimple(void)
Expand Down Expand Up @@ -153,3 +156,18 @@ void TestInnerProductWithBigIndexes()
TestInnerProductWithBigIndexesHelper(33);
}
DECLARE_UNITTEST(TestInnerProductWithBigIndexes);

void TestInnerProductPlaceholders()
{ // Regression test for thrust/thrust#1178
using namespace thrust::placeholders;

thrust::device_vector<float> v1(100, 1.f);
thrust::device_vector<float> v2(100, 1.f);

auto result = thrust::inner_product(v1.begin(), v1.end(), v2.begin(), 0.0f,
thrust::plus<float>{},
_1 * _2 + 1.0f);

ASSERT_ALMOST_EQUAL(result, 200.f);
}
DECLARE_UNITTEST(TestInnerProductPlaceholders);
Loading

0 comments on commit 412f699

Please sign in to comment.