BUG: cumsum and cumprod keep bool and small integer dtypes, so cumsum(x > 0) is wrong
Los mantenedores suelen responder en 1 día
Evaluación
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Aptitud para principiantes
- 76/100
Línea de trabajo
El issue apunta a CumOp.make_node en pytensor/tensor/extra_ops.py y describe diferencias entre el código C, los kernels de Numba y perform. Empieza leyendo CumOp y las pruebas correspondientes de operaciones acumulativas; después, compara los resultados para entradas bool y enteras pequeñas en los distintos backends. Se considera terminado cuando las salidas usan el tipo de dato de acumulación esperado y coinciden en los ejemplos reportados.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
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.
- Lenguaje dominante
- Python
- Estrellas
- 654
- Forks
- 258
- Merge medio
- 3 d 17 h
- PR fusionados (30 d)
- 43
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de pymc-devs/pytensor
-
Docs of mode still mentions C/CVM as the default with FAST_RUNPosiblemente ocupada @ADITYASINGH1206 la tomó hace 12 días. Abiertodocs
Dificultad 2/5 1-3 horas Aptitud para principiantes 62/100
pymc-devs/pytensor#2641 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
Update conditions page in docsPosiblemente ocupada @caxaxa la tomó hace 2 días. Abiertodocs
Dificultad 2/5 1-3 horas Aptitud para principiantes 62/100
Los mantenedores suelen responder en 1 día
-
BUG: geomspace returns wrong sign for the endpoints when start and stop are negativePosiblemente ocupada @mayuriphad la tomó hace 31 días. Abierto
Dificultad 2/5 Menos de una hora Aptitud para principiantes 85/100
Los mantenedores suelen responder en 1 día
-
Reciprocal.impl computes np.float32(1.0) / x: float32 precision for float64 scalars under NEP 50 (Python linker)Quizá libre de nuevo Un pull request para esta issue se cerró sin fusionarse. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 70/100
pymc-devs/pytensor#2430 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
pymc-devs/pytensor#2428 · 5 comentarios ·
Los mantenedores suelen responder en 1 día
Todos los issues de pymc-devs/pytensor
Issues similares
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 79/100
micronaut-projects/micronaut-core#14585 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
langgenius/graphon#443 ·
Los mantenedores suelen responder en 2 días
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 84/100
Los mantenedores suelen responder en 1 día
-
[BUG]: Management endpoints /v1/memory/stats and /v1/memory/counts bypass API key authenticationAbierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 84/100
docling-project/docling-serve#788 ·
Los mantenedores suelen responder en 1 día
-
Mend: dependency security vulnerability untriaged
Dificultad 1/5 Menos de una hora Aptitud para principiantes 78/100
opensearch-project/cross-cluster-replication#1805 ·
Los mantenedores suelen responder en 1 día