Skip to content
This repository has been archived by the owner on Mar 21, 2024. It is now read-only.

thrust::complex divided by int #1847

Closed
kanglcn opened this issue Jan 6, 2023 · 2 comments
Closed

thrust::complex divided by int #1847

kanglcn opened this issue Jan 6, 2023 · 2 comments

Comments

@kanglcn
Copy link

kanglcn commented Jan 6, 2023

Hi, I find thrust::operator/ (const complex< T0 > & x, const T1 & y) can not handle the case when T0 is float and T1 is int. I have to cast T1 to float explicitly which is not intuitive.

I am working on speeding up my python code with cupy elementwise kernel. I have no experience on c++ before so I cannot provide an example. Sorry about that.

@jrhemstad
Copy link
Collaborator

This by design as thrust::complex is intended to be consistent with std::complex: https://godbolt.org/z/d4oGb3xMs

The operator/ is only defined for a complex<T> when dividing by a T scalar:

template< class T >
constexpr std::complex<T> operator/(const std::complex<T>& lhs, const T& rhs );

If you're wondering why the conversion from int to float doesn't happen implicitly, it's because lhs is in a "deduced context", which means the template type T is deduced from the type of rhs and lhs and the T needs to match between the two.

@kanglcn
Copy link
Author

kanglcn commented Jan 9, 2023

Thanks a lot!

@kanglcn kanglcn closed this as completed Jan 9, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
Archived in project
Development

No branches or pull requests

2 participants