Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace thrust::complex with cuda::std::complex #260

Closed
wants to merge 1 commit into from

Conversation

miscco
Copy link
Contributor

@miscco miscco commented Jul 24, 2023

There are some notable differences though. thrust::complex has been a
bit more lenient when determining the type of arithmetic operations.

That said, I believe being more strict is actually a feature not a bug

There are some notable differences though. thrust::complex has been a
bit more lenient when determining the type of arithmetic operations.

That said, I believe being more strict is actually a feature not a bug
@miscco miscco requested review from a team as code owners July 24, 2023 13:48
@miscco miscco requested review from ericniebler, gevtushenko and elstehle and removed request for a team July 24, 2023 13:48
@@ -1781,6 +1783,57 @@ 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__
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those changes might be controversial as we are pulling in quite some machinery. Thoughts?

@miscco miscco added feature request New feature or request. thrust For all items related to Thrust. libcu++ For all items related to libcu++ labels Jul 24, 2023
@miscco miscco changed the title Replace thrust::complex with std::complex Replace thrust::complex with cuda::std::complex Jul 24, 2023
Copy link
Collaborator

@gevtushenko gevtushenko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've left a few comments on places that break API. I haven't covered all the changes, but I think that the comments should be applicable to the rest of them.

Comment on lines -59 to -66
template <typename T0, typename T1>
__host__ __device__
complex<typename detail::promoted_numerical_type<T0, T1>::type>
operator-(const complex<T0>& x, const complex<T1>& y)
{
typedef typename detail::promoted_numerical_type<T0, T1>::type T;
return complex<T>(x.real() - y.real(), x.imag() - y.imag());
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The following code used to work, but now it doesn't:

  thrust::complex<float> a;
  thrust::complex<double> b;
  auto c = a + b;

I think we need to keep this overload and maybe mark it as deprecated. Same with other operators.

Comment on lines -49 to -56
template <typename T0, typename T1>
__host__ __device__
complex<typename detail::promoted_numerical_type<T0, T1>::type>
operator+(const T0& x, const complex<T1>& y)
{
typedef typename detail::promoted_numerical_type<T0, T1>::type T;
return complex<T>(x + y.real(), y.imag());
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The following code used to work, but now it doesn't:

  float a = 84;
  thrust::complex<double> b(42, 42);
  auto c = a + b;

I think we need to keep this overload and maybe mark it as deprecated. Same with other operators.

// As std::hypot is only C++11 we have to use the C interface
template <typename T>
__host__ __device__
T abs(const complex<T>& z)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The following code used to work, now it doesn't:

  thrust::complex<double> a;
  auto b = thrust::abs(a);


template <typename T>
__host__ __device__
T arg(const complex<T>& z)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The following code used to work, now it doesn't:

  thrust::complex<double> a;
  auto b = thrust::arg(a);

@miscco
Copy link
Contributor Author

miscco commented Sep 22, 2023

Dropping in favor of #454

@miscco miscco closed this Sep 22, 2023
@miscco miscco deleted the replace_thrust_complex branch February 26, 2025 11:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request New feature or request. libcu++ For all items related to libcu++ thrust For all items related to Thrust.
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

2 participants