Skip to content

Commit

Permalink
Deprecate thrust::numeric_limits
Browse files Browse the repository at this point in the history
  • Loading branch information
bernhardmgruber committed Jan 15, 2025
1 parent 43fb061 commit 3f105bc
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
15 changes: 12 additions & 3 deletions thrust/testing/unittest/testframework.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@
#include <thrust/mr/host_memory_resource.h>
#include <thrust/mr/universal_memory_resource.h>

#include <cuda/std/limits>

#include <cstdio>
#include <iostream>
#include <limits>
#include <map>
#include <set>
#include <string>
Expand Down Expand Up @@ -199,22 +202,28 @@ class custom_numeric
}
};

THRUST_NAMESPACE_BEGIN
namespace std
{
template <>
struct numeric_limits<custom_numeric> : numeric_limits<int>
{};
} // namespace std

_LIBCUDACXX_BEGIN_NAMESPACE_STD
template <>
struct numeric_limits<custom_numeric> : numeric_limits<int>
{};
_LIBCUDACXX_END_NAMESPACE_STD

THRUST_NAMESPACE_BEGIN
namespace detail
{

// For random number generation
template <>
class integer_traits<custom_numeric> : public integer_traits_base<int, INT_MIN, INT_MAX>
{};

} // namespace detail

THRUST_NAMESPACE_END

using NumericTypes = unittest::type_list<
Expand Down
4 changes: 2 additions & 2 deletions thrust/testing/unittest/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ typename THRUST_NS_QUALIFIER::detail::disable_if<::cuda::std::is_floating_point<
truncate_to_max_representable(std::size_t n)
{
return static_cast<T>(
THRUST_NS_QUALIFIER::min<std::size_t>(n, static_cast<std::size_t>(THRUST_NS_QUALIFIER::numeric_limits<T>::max())));
THRUST_NS_QUALIFIER::min<std::size_t>(n, static_cast<std::size_t>(::cuda::std::numeric_limits<T>::max())));
}

// TODO: This probably won't work for `half`.
template <typename T>
typename ::cuda::std::enable_if_t<::cuda::std::is_floating_point<T>::value, T>
truncate_to_max_representable(std::size_t n)
{
return THRUST_NS_QUALIFIER::min<T>(static_cast<T>(n), THRUST_NS_QUALIFIER::numeric_limits<T>::max());
return THRUST_NS_QUALIFIER::min<T>(static_cast<T>(n), ::cuda::std::numeric_limits<T>::max());
}

} // namespace unittest
Expand Down
2 changes: 1 addition & 1 deletion thrust/thrust/limits.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
THRUST_NAMESPACE_BEGIN

template <typename T>
struct numeric_limits : std::numeric_limits<T>
struct CCCL_DEPRECATED_BECAUSE("Use cuda::std::numeric_limits") numeric_limits : std::numeric_limits<T>
{};

THRUST_NAMESPACE_END

0 comments on commit 3f105bc

Please sign in to comment.