forked from NVIDIA/thrust
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added initial draft of mismatch() and unit tests
- Loading branch information
Showing
13 changed files
with
557 additions
and
12 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
PREAMBLE = \ | ||
""" | ||
#include <thrust/find.h> | ||
#include <thrust/reduce.h> | ||
#include <thrust/extrema.h> | ||
|
||
template <typename Vector> | ||
void find_partial(const Vector& v) | ||
{ | ||
thrust::find(v.begin(), v.end(), 1); | ||
} | ||
|
||
template <typename Vector> | ||
void find_full(const Vector& v) | ||
{ | ||
thrust::max_element(v.begin(), v.end()); | ||
} | ||
|
||
template <typename Vector> | ||
void reduce_full(const Vector& v) | ||
{ | ||
thrust::max_element(v.begin(), v.end()); | ||
} | ||
""" | ||
|
||
INITIALIZE = \ | ||
""" | ||
thrust::host_vector<$InputType> h_input($InputSize, 0); | ||
thrust::device_vector<$InputType> d_input($InputSize, 0); | ||
|
||
size_t pos = $Fraction * $InputSize; | ||
|
||
if (pos < $InputSize) | ||
{ | ||
h_input[pos] = 1; | ||
d_input[pos] = 1; | ||
} | ||
|
||
size_t h_index = thrust::find(h_input.begin(), h_input.end(), 1) - h_input.begin(); | ||
size_t d_index = thrust::find(d_input.begin(), d_input.end(), 1) - d_input.begin(); | ||
|
||
ASSERT_EQUAL(h_index, d_index); | ||
""" | ||
|
||
TIME = \ | ||
""" | ||
$Method(d_input); | ||
""" | ||
|
||
FINALIZE = \ | ||
""" | ||
RECORD_TIME(); | ||
RECORD_BANDWIDTH(sizeof($InputType) * double($InputSize)); | ||
""" | ||
|
||
InputTypes = ['int'] | ||
InputSizes = [2**23] | ||
Fractions = [0.01, 0.99] | ||
Methods = ['find_partial', 'find_full', 'reduce_full'] | ||
|
||
TestVariables = [('InputType', InputTypes), ('InputSize', InputSizes), ('Fraction', Fractions), ('Method', Methods)] | ||
|
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,29 @@ | ||
#include <thrusttest/unittest.h> | ||
#include <thrust/mismatch.h> | ||
|
||
template <class Vector> | ||
void TestMismatchSimple(void) | ||
{ | ||
typedef typename Vector::value_type T; | ||
|
||
Vector a(4); Vector 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; | ||
|
||
ASSERT_EQUAL(thrust::mismatch(a.begin(), a.end(), b.begin()).first - a.begin(), 2); | ||
ASSERT_EQUAL(thrust::mismatch(a.begin(), a.end(), b.begin()).second - b.begin(), 2); | ||
|
||
b[2] = 3; | ||
|
||
ASSERT_EQUAL(thrust::mismatch(a.begin(), a.end(), b.begin()).first - a.begin(), 3); | ||
ASSERT_EQUAL(thrust::mismatch(a.begin(), a.end(), b.begin()).second - b.begin(), 3); | ||
|
||
b[3] = 4; | ||
|
||
ASSERT_EQUAL(thrust::mismatch(a.begin(), a.end(), b.begin()).first - a.begin(), 4); | ||
ASSERT_EQUAL(thrust::mismatch(a.begin(), a.end(), b.begin()).second - b.begin(), 4); | ||
} | ||
DECLARE_VECTOR_UNITTEST(TestMismatchSimple); | ||
|
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,47 @@ | ||
/* | ||
* Copyright 2008-2010 NVIDIA Corporation | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
|
||
/*! \file find.h | ||
* \brief Search for differences between sequences [generic device]. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <thrust/pair.h> | ||
|
||
namespace thrust | ||
{ | ||
namespace detail | ||
{ | ||
namespace device | ||
{ | ||
namespace generic | ||
{ | ||
|
||
template <typename InputIterator1, typename InputIterator2, typename BinaryPredicate> | ||
thrust::pair<InputIterator1, InputIterator2> mismatch(InputIterator1 first1, | ||
InputIterator1 last1, | ||
InputIterator2 first2, | ||
BinaryPredicate pred); | ||
|
||
} // end namespace generic | ||
} // end namespace device | ||
} // end namespace detail | ||
} // end namespace thrust | ||
|
||
#include <thrust/detail/device/generic/mismatch.inl> | ||
|
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,78 @@ | ||
/* | ||
* Copyright 2008-2010 NVIDIA Corporation | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
|
||
#include <thrust/pair.h> | ||
#include <thrust/distance.h> | ||
#include <thrust/iterator/iterator_traits.h> | ||
#include <thrust/iterator/zip_iterator.h> | ||
#include <thrust/iterator/transform_iterator.h> | ||
|
||
#include <thrust/detail/internal_functional.h> | ||
|
||
#include <thrust/detail/device/find.h> | ||
|
||
// Contributed by Erich Elsen | ||
|
||
namespace thrust | ||
{ | ||
namespace detail | ||
{ | ||
namespace device | ||
{ | ||
namespace generic | ||
{ | ||
|
||
template <typename InputIterator1, typename InputIterator2, typename BinaryPredicate> | ||
thrust::pair<InputIterator1, InputIterator2> mismatch(InputIterator1 first1, | ||
InputIterator1 last1, | ||
InputIterator2 first2, | ||
BinaryPredicate pred) | ||
{ | ||
typedef typename thrust::iterator_traits<InputIterator1>::difference_type difference_type; | ||
typedef typename thrust::tuple<bool,difference_type> result_type; | ||
|
||
const difference_type n = thrust::distance(first1, last1); | ||
|
||
difference_type offset = thrust::detail::device::find_if | ||
( | ||
thrust::make_transform_iterator | ||
( | ||
thrust::make_zip_iterator(thrust::make_tuple(first1, first2)), | ||
thrust::detail::tuple_equal_to<BinaryPredicate>(pred) | ||
), | ||
thrust::make_transform_iterator | ||
( | ||
thrust::make_zip_iterator(thrust::make_tuple(first1, first2)), | ||
thrust::detail::tuple_equal_to<BinaryPredicate>(pred) | ||
) + n, | ||
thrust::detail::equal_to_value<bool>(false) | ||
) | ||
- | ||
thrust::make_transform_iterator | ||
( | ||
thrust::make_zip_iterator(thrust::make_tuple(first1, first2)), | ||
thrust::detail::tuple_equal_to<BinaryPredicate>(pred) | ||
); | ||
|
||
return thrust::make_pair(first1 + offset, first2 + offset); | ||
} | ||
|
||
} // end namespace generic | ||
} // end namespace device | ||
} // end namespace detail | ||
} // end namespace thrust | ||
|
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,47 @@ | ||
/* | ||
* Copyright 2008-2010 NVIDIA Corporation | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
|
||
/*! \file mismatch.h | ||
* \brief Search for differences between sequences [device]. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <thrust/pair.h> | ||
|
||
#include <thrust/detail/device/generic/mismatch.h> | ||
|
||
namespace thrust | ||
{ | ||
namespace detail | ||
{ | ||
namespace device | ||
{ | ||
|
||
template <typename InputIterator1, typename InputIterator2, typename BinaryPredicate> | ||
thrust::pair<InputIterator1, InputIterator2> mismatch(InputIterator1 first1, | ||
InputIterator1 last1, | ||
InputIterator2 first2, | ||
BinaryPredicate pred) | ||
{ | ||
return thrust::detail::device::generic::mismatch(first1, last1, first2, pred); | ||
} | ||
|
||
} // end namespace device | ||
} // end namespace detail | ||
} // end namespace thrust | ||
|
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 |
---|---|---|
|
@@ -15,7 +15,7 @@ | |
*/ | ||
|
||
|
||
/*! \file gather.h | ||
/*! \file find.h | ||
* \brief Dispatch layer of the find functions. | ||
*/ | ||
|
||
|
Oops, something went wrong.