BUG: cumsum and cumprod keep bool and small integer dtypes, so cumsum(x > 0) is wrong
I maintainer di solito rispondono entro 1 giorno
Valutazione
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Idoneità per principianti
- 76/100
Direzione di ricerca
L’issue rimanda a CumOp.make_node in pytensor/tensor/extra_ops.py e descrive differenze tra il codice C, i kernel Numba e perform. Inizia leggendo CumOp e i test corrispondenti per le operazioni cumulative, poi confronta i risultati per input bool e interi di piccole dimensioni tra i backend. Il lavoro è completato quando gli output usano il tipo di dato di accumulazione previsto e corrispondono negli esempi segnalati.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Describe the issue:
pt.cumsum and pt.cumprod give the result the input's dtype. NumPy and pt.sum accumulate bool and small integers in int64 (uint64 for unsigned), so a running count over a mask comes out wrong. In the default (Numba) mode pt.cumsum(x > 0, axis=1) is all True, and pt.cumsum(x > 0).max() returns True instead of 3. The C backend also wraps int8 totals.
The output type comes from CumOp.make_node (return Apply(self, [x], [x.type()]) in pytensor/tensor/extra_ops.py). The C code and the Numba kernels for ndim > 1 accumulate in the input dtype, while perform and the 1-d Numba kernel call np.cumsum, which upcasts and returns int64 data for a variable typed bool or int8. So the backends disagree with each other as well as with NumPy.
Reproducible code example:
import numpy as np
import pytensor
import pytensor.tensor as pt
x = pt.matrix("x")
n = pt.cumsum(x > 0, axis=1)
v = np.array([[1.0, 2.0, -1.0, 3.0]])
print(n.dtype)
print(pytensor.function([x], n)(v), np.cumsum(v > 0, axis=1))
print(pytensor.function([x], n.max())(v), np.cumsum(v > 0, axis=1).max())
i = pt.vector("i", dtype="int8")
c_mode = pytensor.compile.mode.Mode(linker="cvm", optimizer="fast_run")
print(pytensor.function([i], pt.cumsum(i), mode=c_mode)(np.array([100, 100, 2], dtype="int8")))
Error message:
bool
[[ True True True True]] [[1 2 2 3]]
True 3
[100 -56 -54]
PyTensor version information:
main at e213406 (3.3.8+65), NumPy 2.5.5, Numba 0.68.1, Python 3.12.7, macOS arm64
Context for the issue:
cumsum(mask) is a common way to number the selected entries. Casting these inputs to int64/uint64 in cumsum/cumprod, with the same mapping Sum uses, fixes it for every backend. I have that change with a test and can open a PR.
- Lingua principale
- Python
- Stelle
- 654
- Fork
- 258
- Merge medio
- 3g 17h
- PR unite (30g)
- 43
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di pymc-devs/pytensor
-
Docs of mode still mentions C/CVM as the default with FAST_RUNForse già presa @ADITYASINGH1206 l’ha presa 11 giorni fa. Apertadocs
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
pymc-devs/pytensor#2641 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Update conditions page in docsForse già presa @caxaxa l’ha presa 2 giorni fa. Apertadocs
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
I maintainer di solito rispondono entro 1 giorno
-
BUG: geomspace returns wrong sign for the endpoints when start and stop are negativeForse già presa @mayuriphad l’ha presa 31 giorni fa. Aperta
Difficoltà 2/5 Meno di un'ora Idoneità per principianti 85/100
I maintainer di solito rispondono entro 1 giorno
-
Reciprocal.impl computes np.float32(1.0) / x: float32 precision for float64 scalars under NEP 50 (Python linker)Forse di nuovo libera Una pull request per questa issue è stata chiusa senza essere unita. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
pymc-devs/pytensor#2430 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
pymc-devs/pytensor#2428 · 5 commenti ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di pymc-devs/pytensor
Issue simili
-
🧫10장-투향
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
hyunjimoon/golden-cage-book#188 ·
-
agent/scanner bug stage/010-actionable
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 88/100
torch-spyre/spyre-inference#1812 ·
I maintainer di solito rispondono entro 1 giorno
-
Bug: fenced drafts inside <think> tags break parsing or are returned instead of the answerForse già presa @aad1tyaaaaa l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
google/langextract#639 ·
I maintainer di solito rispondono entro 1 giorno
-
[oblt-aw][autodoc] Update autodoc routing docs for relative in-repo lock usesForse già presa @github-actions l’ha presa oggi. Aperta
Difficoltà 1/5 1-3 ore Idoneità per principianti 87/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
I maintainer di solito rispondono entro 1 giorno