BUG: geomspace returns wrong sign for the endpoints when start and stop are negative

Aperta Adatta ai principianti
#2,561 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@mayuriphad ci sta già lavorando.

Dal 26/10/2026.

  • #2570 di @mayuriphad — aperta

Valutazione

Difficoltà
2/5
Tempo stimato
Meno di un'ora
Idoneità per principianti
85/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
python
Ambito
backend

Direzione di ricerca

Trova l'implementazione di geomspace in pytensor/tensor/ (cerca set_subtensor su result[0] e result[-1]); gli endpoint vengono impostati prima di moltiplicare per sign(start), il che li inverte di nuovo per start negativi. Sposta o riordina in modo che gli endpoint siano corretti, ad esempio moltiplicando per sign(start) prima di impostarli. Riproduci con pt.geomspace(np.float64(-2.0), np.float64(-30.0), num=4).eval() e confronta con np.geomspace; fatto quando gli endpoint corrispondono a NumPy per input scalari e di array. Nota: chi ha aperto l'issue dice di avere una patch e potrebbe aprire una PR, quindi verifica prima di iniziare.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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.

Lingua principale
Python
Stelle
654
Fork
258
Merge medio
2g 7h
PR unite (30g)
39

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di pymc-devs/pytensor

Tutte le issue di pymc-devs/pytensor

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.