Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion docs/thrust/api_docs/function_objects/predefined.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,5 @@ Users are encouraged to use the standard C++ function objects available from `<c
Thrust provides the following additional function objects:

- :cpp:struct:`thrust::square <thrust::square>`
- :cpp:struct:`thrust::identity <thrust::identity>`
- :cpp:struct:`thrust::project1st <thrust::project1st>`
- :cpp:struct:`thrust::project2nd <thrust::project2nd>`
37 changes: 0 additions & 37 deletions thrust/testing/functional.cu
Original file line number Diff line number Diff line change
Expand Up @@ -187,43 +187,6 @@ typename ::cuda::std::add_const<_Tp>::type& as_const(_Tp& __t) noexcept
return __t;
}

// Ad-hoc testing for other functionals
THRUST_DISABLE_BROKEN_GCC_VECTORIZER void TestIdentityFunctional()
{
_CCCL_SUPPRESS_DEPRECATED_PUSH
int i = 42;
double d = 3.14;

// pass through
ASSERT_EQUAL(thrust::identity<int>{}(i), 42);
ASSERT_EQUAL(thrust::identity<int>{}(d), 3);

// modification through
thrust::identity<int>{}(i) = 1337;
ASSERT_EQUAL(i, 1337);

// value categories and const
static_assert(::cuda::std::is_same<decltype(thrust::identity<int>{}(42)), int&&>::value, "");
static_assert(::cuda::std::is_same<decltype(thrust::identity<int>{}(i)), int&>::value, "");
static_assert(::cuda::std::is_same<decltype(thrust::identity<int>{}(as_const(i))), const int&>::value, "");
static_assert(::cuda::std::is_same<decltype(thrust::identity<int>{}(::cuda::std::move(i))), int&&>::value, "");
static_assert(::cuda::std::is_same<decltype(thrust::identity<int>{}(static_cast<const int&&>(i))), const int&>::value,
"");

// value categories when casting to different type
static_assert(::cuda::std::is_same<decltype(thrust::identity<int>{}(3.14)), int&&>::value, "");
// unfortunately, old versions of MSVC or nvcc in MSVC mode pick the `const int&` overload instead of `int&&`
#if !_CCCL_COMPILER(MSVC, <, 19, 29) && !(_CCCL_COMPILER(MSVC) && _CCCL_CUDA_COMPILER(NVCC, <, 12, 1))
static_assert(::cuda::std::is_same<decltype(thrust::identity<int>{}(d)), int&&>::value, "");
static_assert(::cuda::std::is_same<decltype(thrust::identity<int>{}(as_const(d))), int&&>::value, "");
#endif
static_assert(::cuda::std::is_same<decltype(thrust::identity<int>{}(::cuda::std::move(d))), int&&>::value, "");
static_assert(::cuda::std::is_same<decltype(thrust::identity<int>{}(static_cast<const double&&>(d))), int&&>::value,
"");
_CCCL_SUPPRESS_DEPRECATED_POP
}
DECLARE_UNITTEST(TestIdentityFunctional);

template <class Vector>
THRUST_DISABLE_BROKEN_GCC_VECTORIZER void TestIdentityFunctionalVector()
{
Expand Down
37 changes: 0 additions & 37 deletions thrust/testing/transform_iterator.cu
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
#include <cuda/__cccl_config>

#if _CCCL_COMPILER(NVHPC)
// suppress warnings on thrust::identity
_CCCL_SUPPRESS_DEPRECATED_PUSH
#endif // _CCCL_COMPILER(NVHPC)

#include <thrust/copy.h>
#include <thrust/functional.h>
#include <thrust/iterator/counting_iterator.h>
Expand All @@ -18,10 +11,6 @@ _CCCL_SUPPRESS_DEPRECATED_PUSH

#include <unittest/unittest.h>

#if _CCCL_COMPILER(NVHPC)
_CCCL_SUPPRESS_DEPRECATED_POP
#endif // _CCCL_COMPILER(NVHPC)

template <class Vector>
void TestTransformIterator()
{
Expand Down Expand Up @@ -146,7 +135,6 @@ struct forward

void TestTransformIteratorReferenceAndValueType()
{
_CCCL_SUPPRESS_DEPRECATED_PUSH
using ::cuda::std::is_same;
using ::cuda::std::negate;
{
Expand All @@ -171,11 +159,6 @@ void TestTransformIteratorReferenceAndValueType()
static_assert(is_same<decltype(it_tr_fwd)::value_type, bool>::value, "");
(void) it_tr_fwd;

auto it_tr_tid = thrust::make_transform_iterator(it, thrust::identity<bool>{});
static_assert(is_same<decltype(it_tr_tid)::reference, bool>::value, ""); // identity<bool>::value_type
static_assert(is_same<decltype(it_tr_tid)::value_type, bool>::value, "");
(void) it_tr_tid;

auto it_tr_cid = thrust::make_transform_iterator(it, cuda::std::identity{});
static_assert(is_same<decltype(it_tr_cid)::reference, bool>::value, ""); // special handling by
// transform_iterator_reference
Expand Down Expand Up @@ -205,11 +188,6 @@ void TestTransformIteratorReferenceAndValueType()
static_assert(is_same<decltype(it_tr_fwd)::value_type, bool>::value, "");
(void) it_tr_fwd;

auto it_tr_tid = thrust::make_transform_iterator(it, thrust::identity<bool>{});
static_assert(is_same<decltype(it_tr_tid)::reference, bool>::value, ""); // identity<bool>::value_type
static_assert(is_same<decltype(it_tr_tid)::value_type, bool>::value, "");
(void) it_tr_tid;

auto it_tr_cid = thrust::make_transform_iterator(it, cuda::std::identity{});
static_assert(is_same<decltype(it_tr_cid)::reference, bool>::value, ""); // special handling by
// transform_iterator_reference
Expand Down Expand Up @@ -239,37 +217,22 @@ void TestTransformIteratorReferenceAndValueType()
static_assert(is_same<decltype(it_tr_fwd)::value_type, bool>::value, "");
(void) it_tr_fwd;

auto it_tr_ide = thrust::make_transform_iterator(it, thrust::identity<bool>{});
static_assert(is_same<decltype(it_tr_ide)::reference, bool>::value, ""); // identity<bool>::value_type
static_assert(is_same<decltype(it_tr_ide)::value_type, bool>::value, "");
(void) it_tr_ide;

auto it_tr_tid = thrust::make_transform_iterator(it, thrust::identity<bool>{});
static_assert(is_same<decltype(it_tr_tid)::reference, bool>::value, ""); // identity<bool>::value_type
static_assert(is_same<decltype(it_tr_tid)::value_type, bool>::value, "");
(void) it_tr_tid;

auto it_tr_cid = thrust::make_transform_iterator(it, cuda::std::identity{});
static_assert(is_same<decltype(it_tr_cid)::reference, bool>::value, ""); // special handling by
// transform_iterator_reference
static_assert(is_same<decltype(it_tr_cid)::value_type, bool>::value, "");
(void) it_tr_cid;
}
_CCCL_SUPPRESS_DEPRECATED_POP
}
DECLARE_UNITTEST(TestTransformIteratorReferenceAndValueType);

void TestTransformIteratorIdentity()
{
_CCCL_SUPPRESS_DEPRECATED_PUSH
thrust::device_vector<int> v(3, 42);

ASSERT_EQUAL(*thrust::make_transform_iterator(v.begin(), thrust::identity<int>{}), 42);
ASSERT_EQUAL(*thrust::make_transform_iterator(v.begin(), thrust::identity<>{}), 42);
ASSERT_EQUAL(*thrust::make_transform_iterator(v.begin(), cuda::std::identity{}), 42);
using namespace thrust::placeholders;
ASSERT_EQUAL(*thrust::make_transform_iterator(v.begin(), _1), 42);
_CCCL_SUPPRESS_DEPRECATED_POP
}

DECLARE_UNITTEST(TestTransformIteratorIdentity);
19 changes: 5 additions & 14 deletions thrust/testing/type_traits.cu
Original file line number Diff line number Diff line change
Expand Up @@ -38,23 +38,14 @@ void TestIsContiguousIterator()

using HostIteratorTuple = thrust::tuple<HostVector::iterator, HostVector::iterator>;

using ConstantIterator = thrust::constant_iterator<int>;
using CountingIterator = thrust::counting_iterator<int>;
_CCCL_SUPPRESS_DEPRECATED_PUSH
using TransformIterator1 = thrust::transform_iterator<thrust::identity<int>, HostVector::iterator>;
_CCCL_SUPPRESS_DEPRECATED_POP
using TransformIterator2 = thrust::transform_iterator<cuda::std::identity, HostVector::iterator>;
using ZipIterator = thrust::zip_iterator<HostIteratorTuple>;
using ConstantIterator = thrust::constant_iterator<int>;
using CountingIterator = thrust::counting_iterator<int>;
using TransformIterator = thrust::transform_iterator<cuda::std::identity, HostVector::iterator>;
using ZipIterator = thrust::zip_iterator<HostIteratorTuple>;

ASSERT_EQUAL((bool) thrust::is_contiguous_iterator<ConstantIterator>::value, false);
ASSERT_EQUAL((bool) thrust::is_contiguous_iterator<CountingIterator>::value, false);
#if !_CCCL_COMPILER(NVHPC)
// thrust::identity creates a deprecated warning that could not be worked around
_CCCL_SUPPRESS_DEPRECATED_PUSH
ASSERT_EQUAL((bool) thrust::is_contiguous_iterator<TransformIterator1>::value, false);
_CCCL_SUPPRESS_DEPRECATED_POP
#endif // !_CCCL_COMPILER(NVHPC)
ASSERT_EQUAL((bool) thrust::is_contiguous_iterator<TransformIterator2>::value, false);
ASSERT_EQUAL((bool) thrust::is_contiguous_iterator<TransformIterator>::value, false);
ASSERT_EQUAL((bool) thrust::is_contiguous_iterator<ZipIterator>::value, false);
}
DECLARE_UNITTEST(TestIsContiguousIterator);
Expand Down
53 changes: 0 additions & 53 deletions thrust/thrust/functional.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,59 +151,6 @@ using ::cuda::std::bit_xor;
* \{
*/

/*! \p identity is a Unary Function that represents the identity function: it takes
* a single argument \c x, and returns \c x.
*
* \tparam T No requirements on \p T.
*
* The following code snippet demonstrates that \p identity returns its
* argument.
*
* \code
* #include <thrust/functional.h>
* #include <assert.h>
* ...
* int x = 137;
* thrust::identity<int> id;
* assert(x == id(x));
* \endcode
*
* \see https://en.cppreference.com/w/cpp/utility/functional/identity
*/
// TODO(bgruber): this version can also act as a functor casting to T making it not equivalent to ::cuda::std::identity
template <typename T = void>
struct CCCL_DEPRECATED_BECAUSE("use cuda::std::identity instead") identity
{
using result_type _LIBCUDACXX_DEPRECATED_IN_CXX11 = T;

_CCCL_EXEC_CHECK_DISABLE
_CCCL_HOST_DEVICE constexpr const T& operator()(const T& x) const
{
return x;
}

_CCCL_EXEC_CHECK_DISABLE
_CCCL_HOST_DEVICE constexpr T& operator()(T& x) const
{
return x;
}

// we cannot add an overload for `const T&&` because then calling e.g. `thrust::identity<int>{}(3.14);` is ambiguous
// on MSVC

_CCCL_EXEC_CHECK_DISABLE
_CCCL_HOST_DEVICE constexpr T&& operator()(T&& x) const
{
return _CUDA_VSTD::move(x);
}
};

_CCCL_SUPPRESS_DEPRECATED_PUSH
template <>
struct CCCL_DEPRECATED_BECAUSE("use cuda::std::identity instead") identity<void> : ::cuda::std::__identity
{};
_CCCL_SUPPRESS_DEPRECATED_POP

using ::cuda::maximum;
using ::cuda::minimum;

Expand Down
12 changes: 0 additions & 12 deletions thrust/thrust/iterator/detail/transform_iterator.inl
Original file line number Diff line number Diff line change
Expand Up @@ -50,18 +50,6 @@ struct transform_iterator_reference

// for certain function objects, we need to tweak the reference type. Notably, identity functions must decay to values.
// See the implementation of transform_iterator<...>::dereference() for several comments on why this is necessary.
_CCCL_SUPPRESS_DEPRECATED_PUSH
template <typename T, class Iterator>
struct transform_iterator_reference<identity<T>, Iterator>
{
using type = T;
};
template <class Iterator>
struct transform_iterator_reference<identity<>, Iterator>
{
using type = iterator_value_t<Iterator>;
};
_CCCL_SUPPRESS_DEPRECATED_POP
template <class Iterator>
struct transform_iterator_reference<::cuda::std::identity, Iterator>
{
Expand Down