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

オープン 初心者向け
#2,561 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

@mayuriphad がすでに取り組んでいます。

2026年10月26日 から。

  • #2570 @mayuriphad による — オープン

評価

難易度
2/5
見積もり時間
1時間未満
初心者へのやさしさ
85/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
python
領域
backend

調査の方向性

pytensor/tensor/ 内の geomspace 実装を探してください(result[0] と result[-1] に対する set_subtensor を検索)。endpoints は sign(start) を掛ける前に設定されており、start が負の場合に再度符号が反転してしまいます。endpoints が正しくなるよう、例えば設定する前に sign(start) を掛けるように移動または並べ替えてください。pt.geomspace(np.float64(-2.0), np.float64(-30.0), num=4).eval() で再現し、np.geomspace と比較してください。スカラー入力と配列入力の両方で endpoints が 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分
マージ済み PR(30日)
42

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

pymc-devs/pytensor のほかの issue

pymc-devs/pytensor の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。