BUG: geomspace returns wrong sign for the endpoints when start and stop are negative
Maintainers usually reply within 1 day
Assessment
- Difficulty
- 2/5
- Estimated time
- Under an hour
- Newbie friendliness
- 85/100
Research direction
Find the geomspace implementation in pytensor/tensor/ (search for set_subtensor on result[0] and result[-1]); the endpoints are set before multiplying by sign(start), which flips them again for negative start. Move or reorder so endpoints are correct, e.g. multiply by sign(start) before setting them. Reproduce with pt.geomspace(np.float64(-2.0), np.float64(-30.0), num=4).eval() and compare against np.geomspace; done when endpoints match NumPy for scalar and array inputs. Note: the filer says they have a patch and may open a PR, so check before starting.
Written by the indexing model from the issue text.
Description
Describe the issue:
pt.geomspace returns the wrong sign for the first and last samples when start and stop are negative. The interior samples are correct.
In geomspace, the endpoints are written into the result with set_subtensor(result[0, ...], start) and set_subtensor(result[-1, ...], stop), and only afterwards the whole result is multiplied by sign(start). For a negative start this multiplies the already-negative endpoints by -1 again.
np.geomspace(-2, -30, 4) gives [-2, -4.93, -12.16, -30]; pt.geomspace gives [2, -4.93, -12.16, 30].
Reproducible code example:
import numpy as np
import pytensor.tensor as pt
start, stop = np.float64(-2.0), np.float64(-30.0)
print(pt.geomspace(start, stop, num=4).eval())
print(np.geomspace(start, stop, num=4))
Error message:
[ 2. -4.93242404 -12.16440357 30. ]
[ -2. -4.93242415 -12.16440399 -30. ]
The same happens per element for array inputs, e.g. start=[-1, 2], stop=[-8, 16] gives [1, -2, -4, 8] for the first sequence.
PyTensor version information:
PyTensor main (2e1005b), NumPy 2.5.4, Python 3.12, macOS arm64.
Context for the issue:
A possible fix is to multiply by sign(start) before setting the exact endpoints (a 2-line change). I have a patch with a regression test and can open a PR if that is welcome.
Disclosure: found, reproduced and the draft fix tested locally with the help of an AI coding agent (Claude Code); reviewed before filing.
- Dominant language
- Python
- Stars
- 655
- Forks
- 266
- Avg merge
- 3d 23h
- Merged PRs (30d)
- 43
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from pymc-devs/pytensor
-
BUG: cumsum and cumprod keep bool and small integer dtypes, so cumsum(x > 0) is wrongPossibly taken @rishabhsai claimed this 1 day ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
Maintainers usually reply within 1 day
-
Docs of mode still mentions C/CVM as the default with FAST_RUNPossibly taken @ADITYASINGH1206 claimed this 13 days ago. Opendocs
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
pymc-devs/pytensor#2641 · 1 comment ·
Maintainers usually reply within 1 day
-
Update conditions page in docsPossibly taken @caxaxa claimed this 3 days ago. Opendocs
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
Maintainers usually reply within 1 day
-
Reciprocal.impl computes np.float32(1.0) / x: float32 precision for float64 scalars under NEP 50 (Python linker)May be free again A pull request for this issue was closed without being merged. Open
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
pymc-devs/pytensor#2430 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
pymc-devs/pytensor#2428 · 5 comments ·
Maintainers usually reply within 1 day
All issues in pymc-devs/pytensor
Similar issues
-
triage
Difficulty 1/5 1-3 hours Newbie friendliness 88/100
kornia/kornia-rs#1416 · 1 comment ·
Maintainers usually reply within 2 days
-
ui
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
PolicyEngine/ai-inequality#64 ·
Maintainers usually reply within 1 day
-
LinearGaussianStateSpace.dist splits states and observations wrongly when the transition varies over timePossibly taken @PabloRoque claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
pymc-devs/pymc-extras#839 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
Maintainers usually reply within 1 day