Skip to content

Preserve signed-zero branch sides in complex square roots - #581

Open
antonsoo wants to merge 1 commit into
pydata:masterfrom
antonsoo:fix/complex-sqrt-branch-side
Open

antonsoo wants to merge 1 commit into
pydata:masterfrom
antonsoo:fix/complex-sqrt-branch-side

Conversation

@antonsoo

Copy link
Copy Markdown

sqrt chooses the wrong side of the complex branch cut after conjugation:

x = np.array([-4 + 0j])
ne.evaluate("sqrt(conj(x))")  # currently +2j; expected -2j

Preserve the imaginary component's sign with copysign and return a nonnegative real zero for zero inputs. This matches NumPy and cmath.sqrt, including negative imaginary zero. Ordinary complex inputs keep their existing arithmetic.

The regression covers signed zeros, quadrants, strides, block-sized arrays, nested conjugation and aliased output. In a spectral image calculation, the corrected adjoint matches the conjugated forward operator across 18 configurations; before, 205,254 frequency-bin results differed. Ordinary complex controls remain byte-identical.

Validation: the new regression fails before and passes after; the full installed native suite passes 6,042 tests on Python 3.12 / NumPy 2.5.4, without VML. Applicable pre-commit hooks pass.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant