Skip to content

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

Closed
miscco wants to merge 1 commit into
NVIDIA:mainfrom
miscco:replace_thrust_complex
Closed

miscco wants to merge 1 commit into
NVIDIA:mainfrom
miscco:replace_thrust_complex

Conversation

@miscco

@miscco miscco commented Jul 24, 2023

Copy link
Copy Markdown
Contributor

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 elstehle, ericniebler and gevtushenko and removed request for a team July 24, 2023 13:48
return __os << __s.str();
}
#endif // !_LIBCUDACXX_HAS_NO_LOCALIZATION
#else // ^^^ !__cuda_std__ ^^^ / vvv __cuda_std__

Copy link
Copy Markdown
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 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

@gevtushenko gevtushenko left a comment

Copy link
Copy Markdown
Collaborator

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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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

miscco commented Sep 22, 2023

Copy link
Copy Markdown
Contributor Author

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

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