Skip to content

BUG FIX: scalar Pow.impl returning complex for fractional powers of negative floats#1945

Open
vybhav72954 wants to merge 2 commits intopymc-devs:v3from
vybhav72954:bug/scalar-pow-complex
Open

BUG FIX: scalar Pow.impl returning complex for fractional powers of negative floats#1945
vybhav72954 wants to merge 2 commits intopymc-devs:v3from
vybhav72954:bug/scalar-pow-complex

Conversation

@vybhav72954
Copy link

Description

Pow.impl in pytensor/scalar/basic.py uses Python's native ** operator, which returns complex numbers for fractional powers of negative floats (e.g., (-1.0) ** 0.01 returns (0.999+0.031j)). This is inconsistent with the tensor path, which already uses np.power via nfunc_spec and correctly returns nan.

The complex result then crashes _cast_to_promised_scalar_dtype when it tries to cast to float64.

Fix: Replace x**y with np.power(x, y) in Pow.impl, making the scalar path consistent with the tensor path.

Related Issue

Checklist

Type of change

  • New feature / enhancement
  • Bug fix
  • Documentation
  • Maintenance
  • Other (please specify):

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.

BUG: Scalar Pow.impl returns complex instead of nan for fractional powers of negative floats

1 participant