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

BUG: Fix weak promotion with some mixed float/int dtypes #24681

Merged
merged 2 commits into from
Sep 28, 2023

Conversation

seberg
Copy link
Member

@seberg seberg commented Sep 11, 2023

This reorganizes/simplifies promotion a bit, but unfortunately this means moving the promotion of our concrete DTypes with the abstract "weak" ones into the concrete DTypes making the order of "who deals with whom" fully defined by:

complex' > floats > pycomplex > pyfloat > ints > pyint > bool

where py<...> is the DType corresponding to the Python type. There are two points here:

  • "inexact" is the meaningful category not complex
  • previously, the abstract DTypes pyfloat, etc. knew about the concrete ones and there was some special handling for that. (as mentioned above, this is gone now)

Why was it this complicated?! I think the initial code wanted to deal with value-based promotion and the abstract DTypes could have had a value attached to them.
There was thus more code later on, dealing with abstract DTypes more concretely (rather than identical to the rest).

This is now gone, concrete DTypes promote basically the same as their concrete counter-parts. This makes the promotion logic simpler (and I think still just as correct), although the concrete type promotion now needs to know about it.

This reorganizes/simplifies promotion a bit, but unfortunately this
means moving the promotion of our concrete DTypes with the abstract
"weak" ones into the concrete DTypes making the order of "who deals
with whom" fully defined by:

    complex' > floats > pycomplex > pyfloat > ints > pyint > bool

where py<...> is the DType corresponding to the Python type.
There are two points here:
* "inexact" is the meaningful category not complex
* previously, the abstract DTypes `pyfloat`, etc. knew about the
  concrete ones and there was some special handling for that.
  (as mentioned above, this is gone now)

Why was it this complicated?!  I think the initial code wanted to
deal with value-based promotion and the abstract DTypes could have
had a value attached to them.
There was thus more code later on, dealing with abstract DTypes
more concretely (rather than identical to the rest).

This is now gone, concrete DTypes promote basically the same as
their concrete counter-parts.  This makes the promotion logic simpler
(and I think still just as correct), although the concrete type
promotion now needs to know about it.
@tylerjereddy
Copy link
Contributor

A bit over my head, but I did check that this branch against SciPy main doesn't change our full test suite result with NPY_PROMOTION_STATE=weak from the one reported at scipy/scipy#19239

@lezcano
Copy link

lezcano commented Sep 22, 2023

@ev-br can you have a look at this one and see if we need to change anything in our implementation?

@seberg
Copy link
Member Author

seberg commented Sep 28, 2023

Can we please review/merge this? It's a clear bug fix in something that is vital to move forward. (not that it is a big thing in that, but still)

Copy link
Member

@mattip mattip left a comment

Choose a reason for hiding this comment

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

LGTM, a few small documentation nits. I will merge soon if you want to ignore them.

numpy/core/src/multiarray/common_dtype.c Outdated Show resolved Hide resolved
numpy/core/src/multiarray/common_dtype.c Outdated Show resolved Hide resolved
Co-authored-by: Matti Picus <matti.picus@gmail.com>
@mattip mattip merged commit eabefa4 into numpy:main Sep 28, 2023
50 checks passed
@mattip
Copy link
Member

mattip commented Sep 28, 2023

Thanks @seberg

@seberg seberg deleted the nep50-bad-promotion branch October 26, 2023 09:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants