Skip to content

BUG: NEP 50 promotion for python scalars is not followed for <ufunc>.outer and <ufunc>.at #32076

Closed

Description

@mhvk

Describe the issue:

NEP-50 nicely promotes, e.g., python floats to whatever float dtype an array has. However, for outer functions, this is not followed.

Reproduce the code example:

import numpy as np
a = np.arange(10.0, dtype="f4").reshape(5, 2)
np.add(1.0, a).dtype
# dtype('float32')
np.add.outer(1.0, a).dtype
# dtype('float64')

Error message:

Python and NumPy Versions:

2.4.6
3.14.6 (main, Jun 10 2026, 18:54:31) [GCC 15.2.0]

Runtime Environment:

Not relevant.

How does this issue affect you or how did you find it:

Found while reviewing #32040.

Activity

  1. jorenham commented on Jul 23, 2026

    @jorenham
    Member

    This still seems to be the case with 2.5.1

  2. ngoldbaum commented on Jul 24, 2026

    @ngoldbaum
    Member

    @mhvk hmm, maybe there are issues in ufunc.at as well?

    >>> arr = np.array([2**63], dtype=np.uint64)
    >>> np.add(arr, 1)[0]
    np.uint64(9223372036854775809)
    >>> # correct
    >>> np.add.at(arr, 0, 1)
    >>> arr[0]
    np.uint64(9223372036854775808)
    >>> # +1 silently lost
    >>> arr = np.zeros(1, dtype=np.uint8)
    >>> np.add(arr, -1)
    OverflowError: Python integer -1 out of bounds for uint8
    >>> np.add.at(arr, 0, -1)
    >>> arr[0]
    np.uint8(255)
  3. mhvk commented on Jul 24, 2026

    @mhvk
    ContributorAuthor

    Oops... It looks like the initial work missed these other cases where the ufunc has to deal with multiple inputs (.reduce, .reduceat, and .accumulate thankfully cannot suffer from this...). Ping also @seberg...

  4. ngoldbaum commented on Jul 24, 2026

    @ngoldbaum
    Member

    I opened #32094

  5. seberg commented on Jul 24, 2026

    @seberg
    Member

    Hmmm yeah, I wonder if these even ever supported the value-based paths, but maybe not even and I just forgot the follow-up for these after much time had passed...

    Anyway, the past is the past, and I guess it is nice to fix it and aligning things...

    (In theory, I always had the half wish that we deferred the construction of the final array until after the promotion is finished, but in practice that diff was too large to push for it at the time.)

  6. changed the title [-]BUG: NEP 50 promotion for python scalars is not followed for <ufunc>.outer[/-] [+]BUG: NEP 50 promotion for python scalars is not followed for <ufunc>.outer and <ufunc>.at[/+] on Jul 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions