Skip to content

Commit

Permalink
Revert "Refactor thrust::complex as a struct derived from `cuda::st…
Browse files Browse the repository at this point in the history
…d::complex` (#454)" (#1497)

This reverts commit 1f6e4bc.

We face numerical issues with our cuda::std::complex implementation but did not have the capacity to work on it
  • Loading branch information
miscco authored Mar 7, 2024
1 parent 8b1110f commit d88fbd7
Show file tree
Hide file tree
Showing 27 changed files with 5,496 additions and 542 deletions.
52 changes: 0 additions & 52 deletions libcudacxx/include/cuda/std/detail/libcxx/include/complex
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,6 @@ template<class T> complex<T> tanh (const complex<T>&);
*/

#include "__cccl/diagnostic.h"
#ifndef __cuda_std__
# include <__config>
#endif // __cuda_std__
Expand Down Expand Up @@ -1777,57 +1776,6 @@ operator<<(basic_ostream<_CharT, _Traits>& __os, const complex<_Tp>& __x)
return __os << __s.str();
}
#endif // !_LIBCUDACXX_HAS_NO_LOCALIZATION
#else // ^^^ !__cuda_std__ ^^^ / vvv __cuda_std__
#ifndef _CCCL_COMPILER_NVRTC
template<typename ValueType,class charT, class traits>
::std::basic_ostream<charT, traits>& operator<<(::std::basic_ostream<charT, traits>& os, const complex<ValueType>& z)
{
os << '(' << z.real() << ',' << z.imag() << ')';
return os;
}

template<typename ValueType, typename charT, class traits>
::std::basic_istream<charT, traits>&
operator>>(::std::basic_istream<charT, traits>& is, complex<ValueType>& z)
{
ValueType re, im;

charT ch;
is >> ch;

if(ch == '(')
{
is >> re >> ch;
if (ch == ',')
{
is >> im >> ch;
if (ch == ')')
{
z = complex<ValueType>(re, im);
}
else
{
is.setstate(::std::ios_base::failbit);
}
}
else if (ch == ')')
{
z = re;
}
else
{
is.setstate(::std::ios_base::failbit);
}
}
else
{
is.putback(ch);
is >> re;
z = re;
}
return is;
}
#endif // _CCCL_COMPILER_NVRTC
#endif // __cuda_std__

#if _CCCL_STD_VER > 2011 && defined(_LIBCUDACXX_HAS_STL_LITERALS)
Expand Down
12 changes: 0 additions & 12 deletions thrust/testing/complex.cu
Original file line number Diff line number Diff line change
Expand Up @@ -54,18 +54,6 @@ struct TestComplexSizeAndAlignment
};
SimpleUnitTest<TestComplexSizeAndAlignment, FloatingPointTypes> TestComplexSizeAndAlignmentInstance;

template <typename T>
struct TestComplexTypeCheck
{
void operator()()
{
THRUST_STATIC_ASSERT(thrust::is_complex<thrust::complex<T>>::value);
THRUST_STATIC_ASSERT(thrust::is_complex<std::complex<T>>::value);
THRUST_STATIC_ASSERT(thrust::is_complex<cuda::std::complex<T>>::value);
}
};
SimpleUnitTest<TestComplexTypeCheck, FloatingPointTypes> TestComplexTypeCheckInstance;

template <typename T>
struct TestComplexConstructionAndAssignment
{
Expand Down
29 changes: 23 additions & 6 deletions thrust/testing/unittest/assertions.h
Original file line number Diff line number Diff line change
Expand Up @@ -304,14 +304,31 @@ bool almost_equal(double a, double b, double a_tol, double r_tol)
return true;
}

namespace
{ // anonymous namespace

template <typename>
struct is_complex : public THRUST_NS_QUALIFIER::false_type
{};

template <typename T>
struct is_complex<THRUST_NS_QUALIFIER::complex<T>> : public THRUST_NS_QUALIFIER::true_type
{};

template <typename T>
struct is_complex<std::complex<T>> : public THRUST_NS_QUALIFIER::true_type
{};

} // namespace

template <typename T1, typename T2>
typename THRUST_NS_QUALIFIER::detail::enable_if<THRUST_NS_QUALIFIER::is_complex<T1>::value &&
THRUST_NS_QUALIFIER::is_complex<T2>::value,
bool>::type
almost_equal(const T1 &a, const T2 &b, double a_tol, double r_tol)
inline
typename THRUST_NS_QUALIFIER::detail::enable_if<is_complex<T1>::value && is_complex<T2>::value,
bool>::type
almost_equal(const T1 &a, const T2 &b, double a_tol, double r_tol)
{
return almost_equal(a.real(), b.real(), a_tol, r_tol) &&
almost_equal(a.imag(), b.imag(), a_tol, r_tol);
return almost_equal(a.real(), b.real(), a_tol, r_tol) &&
almost_equal(a.imag(), b.imag(), a_tol, r_tol);
}

template <typename T1, typename T2>
Expand Down
Loading

0 comments on commit d88fbd7

Please sign in to comment.