<commit_before>#include <unittest/unittest.h>
#include <thrust/mismatch.h>
#include <thrust/execution_policy.h>


template<typename Iterator1, typename Iterator2, typename Iterator3>
__global__ void mismatch_kernel(Iterator1 first1, Iterator1 last1, Iterator2 first2, Iterator3 result)
{
  *result = thrust::mismatch(thrust::seq, first1, last1, first2);
}


void TestMismatchDeviceSeq()
{
  thrust::device_vector<int> a(4);
  thrust::device_vector<int> b(4);
  a[0] = 1; b[0] = 1;
  a[1] = 2; b[1] = 2;
  a[2] = 3; b[2] = 4;
  a[3] = 4; b[3] = 3;

  typedef thrust::pair<
    typename thrust::device_vector<int>::iterator,
    typename thrust::device_vector<int>::iterator
  > pair_type;

  thrust::device_vector<pair_type> d_result(1);
  
  mismatch_kernel<<<1,1>>>(a.begin(), a.end(), b.begin(), d_result.begin());

  ASSERT_EQUAL(2, ((pair_type)d_result[0]).first  - a.begin());
  ASSERT_EQUAL(2, ((pair_type)d_result[0]).second - b.begin());
  
  b[2] = 3;
  
  mismatch_kernel<<<1,1>>>(a.begin(), a.end(), b.begin(), d_result.begin());
  ASSERT_EQUAL(3, ((pair_type)d_result[0]).first  - a.begin());
  ASSERT_EQUAL(3, ((pair_type)d_result[0]).second - b.begin());
  
  b[3] = 4;
  
  mismatch_kernel<<<1,1>>>(a.begin(), a.end(), b.begin(), d_result.begin());
  ASSERT_EQUAL(4, ((pair_type)d_result[0]).first  - a.begin());
  ASSERT_EQUAL(4, ((pair_type)d_result[0]).second - b.begin());
}
DECLARE_UNITTEST(TestMismatchDeviceSeq);

<commit_msg>Test mismatch with thrust::device in __device__ code.<commit_after>#include <unittest/unittest.h>
#include <thrust/mismatch.h>
#include <thrust/execution_policy.h>


template<typename ExecutionPolicy, typename Iterator1, typename Iterator2, typename Iterator3>
__global__ void mismatch_kernel(ExecutionPolicy exec, Iterator1 first1, Iterator1 last1, Iterator2 first2, Iterator3 result)
{
  *result = thrust::mismatch(exec, first1, last1, first2);
}


template<typename ExecutionPolicy>
void TestMismatchDevice(ExecutionPolicy exec)
{
  thrust::device_vector<int> a(4);
  thrust::device_vector<int> b(4);
  a[0] = 1; b[0] = 1;
  a[1] = 2; b[1] = 2;
  a[2] = 3; b[2] = 4;
  a[3] = 4; b[3] = 3;

  typedef thrust::pair<
    typename thrust::device_vector<int>::iterator,
    typename thrust::device_vector<int>::iterator
  > pair_type;

  thrust::device_vector<pair_type> d_result(1);
  
  mismatch_kernel<<<1,1>>>(exec, a.begin(), a.end(), b.begin(), d_result.begin());

  ASSERT_EQUAL(2, ((pair_type)d_result[0]).first  - a.begin());
  ASSERT_EQUAL(2, ((pair_type)d_result[0]).second - b.begin());
  
  b[2] = 3;
  
  mismatch_kernel<<<1,1>>>(exec, a.begin(), a.end(), b.begin(), d_result.begin());
  ASSERT_EQUAL(3, ((pair_type)d_result[0]).first  - a.begin());
  ASSERT_EQUAL(3, ((pair_type)d_result[0]).second - b.begin());
  
  b[3] = 4;
  
  mismatch_kernel<<<1,1>>>(exec, a.begin(), a.end(), b.begin(), d_result.begin());
  ASSERT_EQUAL(4, ((pair_type)d_result[0]).first  - a.begin());
  ASSERT_EQUAL(4, ((pair_type)d_result[0]).second - b.begin());
}


void TestMismatchDeviceSeq()
{
  TestMismatchDevice(thrust::seq);
}
DECLARE_UNITTEST(TestMismatchDeviceSeq);


void TestMismatchDeviceDevice()
{
  TestMismatchDevice(thrust::device);
}
DECLARE_UNITTEST(TestMismatchDeviceDevice);


{'fraction_non_alphanumeric': 0.18937287611986406, 'fraction_numerical': 0.033364226135310475, 'mean_word_length': 5.594704684317719, 'pattern_counts': {'":': 0, '<': 42, '<?xml version=': 0, '>': 42, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5428446', 'n_tokens_mistral': 1303, 'n_tokens_neox': 1264, 'n_words': 209}