Skip to content

Real of a weak complex scalar drops the weak flag (NEP 50 promotion) #126

Open

Description

@tannevaled

Real of a weak complex scalar drops the weak flag, so the scalar no longer takes the other operand's dtype.

  • NumPy 2 (NEP 50): np.float32(1) + np.real(1+0j) stays float32, because the Python complex's real part is a weak float.
  • ndarray: float32Array.Add(Scalar(1+0i).Real()) gives Float64. Real on a complex array goes through AsType(complexPart(...)), which builds a new array without the weak field.

The real-scalar case is right: Scalar(1).Real() keeps weakInt, and int8 + Scalar(1).Real() stays int8. This was found while reviewing #125 and predates it.

Fix: in Real (and Imag, which has the same shape), carry weakComplex → weakFloat onto the result, with a test per dtype pair.

Refs #125

Prior art: priorart "weak scalar Real complex flag" at 2026-11-15 20:23 CET reported prior art; checked: priorart 'weak scalar Real complex flag': 64 entries, all single-word matches (weak/scalar/real); #42 introduced weak scalars and #125 touches Real for real dtypes only; none covers the complex-scalar weak flag

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions