BUG: geomspace returns wrong sign for the endpoints when start and stop are negative
维护者通常 1 天内回复
评估
调研方向
在 pytensor/tensor/ 中找到 geomspace 的实现(搜索对 result[0] 和 result[-1] 的 set_subtensor);端点在乘以 sign(start) 之前就被设置,这会在 start 为负时再次翻转它们。移动或调整顺序使端点正确,例如在设置端点之前先乘以 sign(start)。用 pt.geomspace(np.float64(-2.0), np.float64(-30.0), num=4).eval() 复现,并与 np.geomspace 比较;当标量和数组输入下端点都与 NumPy 一致时即完成。注意:提交者说他们已有补丁并可能开 PR,所以开始前请先确认。
由索引模型根据 Issue 内容生成。
描述
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.
- 主要语言
- Python
- 星标
- 654
- 派生
- 258
- 平均合并
- 3 天 41 分钟
- 30 天内合并 PR
- 42
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
pymc-devs/pytensor 的其他 Issue
-
Docs of mode still mentions C/CVM as the default with FAST_RUN可能已有人在做 @ADITYASINGH1206 于 8 天前认领。 未关闭docs
难度 2/5 1-3 小时 新手友好度 62/100
pymc-devs/pytensor#2641 · 1 条评论 ·
维护者通常 1 天内回复
-
docs
难度 2/5 1-3 小时 新手友好度 62/100
维护者通常 1 天内回复
-
Reciprocal.impl computes np.float32(1.0) / x: float32 precision for float64 scalars under NEP 50 (Python linker)可能重新可做 关联的 PR 已关闭且未合并。 未关闭
难度 2/5 1-3 小时 新手友好度 70/100
pymc-devs/pytensor#2430 · 1 条评论 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 78/100
pymc-devs/pytensor#2428 · 5 条评论 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 84/100
维护者通常 1 天内回复
查看 pymc-devs/pytensor 的全部 Issue
相似的 Issue
-
难度 1/5 1 小时以内 新手友好度 72/100
pathintegral-institute/mcpm.sh#568 ·
维护者通常 21 天内回复
-
难度 2/5 1-3 小时 新手友好度 62/100
invarislabs/invaris-agentsec#98 ·
维护者通常 1 天内回复
-
5-minutes beginner-friendly documentation good first issue hacktoberfest help wanted no-code-needed python
难度 1/5 1 小时以内 新手友好度 65/100
Huerte/algo-solutions-python#364 ·
-
难度 1/5 1 小时以内 新手友好度 85/100
Becksteinlab/imdclient#161 ·
-
难度 2/5 1-3 小时 新手友好度 72/100
维护者通常 1 天内回复