-
Notifications
You must be signed in to change notification settings - Fork 26.3k
WIP: Define complex type promotions and support complex binary operators #11641
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
Conversation
- add some C macros to support the dispatch in Dispatch.h - fix the following indexing by add support for complex number in `_local_scalar_dense_cpu` from torch_complex import torch a = torch.empty(2, 2, dtype=torch.complex128) a[1, 1]
aten/src/ATen/core/ScalarType.h
Outdated
| if (isComplexType(a) || isComplexType(b)) { | ||
| AT_ERROR("promoteTypes with complex numbers is not handled yet; figure out what the correct rules should be"); | ||
| } | ||
| // if (isComplexType(a) || isComplexType(b)) { |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
| constexpr auto f2 = ScalarType::Half; | ||
| constexpr auto f4 = ScalarType::Float; | ||
| constexpr auto f8 = ScalarType::Double; | ||
| constexpr auto c4 = ScalarType::ComplexFloat; |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
|
It looks like our vectorizer doesn't know how to deal with complex numbers, unfortunately. Happy to take the promotion logic patch separately. |
|
Discussed on slack. We will allow promotion between |
| } else if (type_ == ParameterType::DOUBLE) { | ||
| default_double = atof(str.c_str()); | ||
| } else if (type_ == ParameterType::COMPLEX) { | ||
| default_complex[0] = atof(str.c_str()); // TODO: parse "x + xj"? |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
|
@Roger-luo This needs a rebase to trigger CI again. Also, I wonder if we can have some tests for this. |
Remove AVX support for complex Revert "Remove AVX support for complex" This reverts commit 8ed90ea18bec7629274aafb6e9c9fdef306dbda7.
da3292b to
aeea5af
Compare
|
@ssnl thanks! I'll need to fix the CI error I got with Then I'll be able to add some tests. |
|
(For the record: I helped Roger repro the issue offline) |
|
On the |
|
Okay... this is related to different gcc versions, MWE: #include <iostream>
#include <complex>
template <class T>
struct Vec256 {
public:
T values[32 / sizeof(T)] = {0};
static constexpr int size = 32 / sizeof(T);
Vec256() {}
Vec256(T val) {
for (int i = 0; i != size; i++) {
values[i] = val;
}
}
};
int main() {
Vec256<std::complex<double>> r(1);
std::cout << r.values[1] << std::endl;
return 0;
}This works fine with |
4339d6c to
50a5be8
Compare
| #include "vec256_double.h" | ||
| #include "vec256_complex.h" | ||
| // #include "vec256_complex_float.h" | ||
| // #include "vec256_complex_double.h" |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
|
It seems that something breaks cuda tests: Is it a type promotion problem? |
|
Looks like a promotion problem to me! By the way, @gchanan brought to my attention that we have a bunch of latent bugs in PyTorch, owing to the fact that in a number of places we do |
|
@Roger-luo Do you need any help with this patch? |
|
Hi @Roger-luo! Thank you for your pull request and welcome to our community. Action RequiredIn order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you. ProcessIn order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with If you have received this in error or have any questions, please contact us at [email protected]. Thanks! |
|
Ah I think I should just close this PR since there's complex number now! |
Promotion inherits
numpy.promote_types's rule (mostly), butnumpydo not define promotion betweencharandcomplex. Should we delete promotion for these types too?Binary operators are not working on tensors and complex values. Still figuring out why...
cc: @ezyang