Eigh of a constant gets a different eigenvector sign inside Scan than outside

オープン
#2,724 コメント 10 件 リアクション 0 件 担当者 0 名 GitHub で見る

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

まだ誰も着手していません。

  • #2725 @lyn1dev による — マージされずにクローズ

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
35/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
停滞
技術スタック
numpy, python

調査の方向性

Start by reading the scan_push_out_non_seq change referenced by commit 14da9a865 and trace how constant-only expressions are handled inside Scan. Compare the constant-folding path through NumPy with the compiled inner path described in the report. The issue is resolved when the repeated-eigenvalue example returns consistent eigenvector signs inside and outside Scan; a linked closed pull request may contain relevant work.

索引モデルが issue の本文から書いたものです。

説明

bug graph rewriting scan

A compiled function that reads the same pt.linalg.eigh output inside and outside a Scan gets two different values for it. Since 14da9a865, scan_push_out_non_seq keeps constant-only expressions inside the scan, so the Eigh runs twice. Constant folding evaluates the outer copy through numpy, and the numba-compiled inner function evaluates the inner one, and the two pick opposite signs for the eigenvectors of a repeated eigenvalue.

import pytensor
import pytensor.tensor as pt

_, eigenvectors = pt.linalg.eigh(25.0 * pt.eye(2))
corner = eigenvectors[0, 0]

trace = pytensor.scan(
    lambda total: total + corner, outputs_info=[pt.zeros(())], n_steps=2, return_updates=False
)
f = pytensor.function([], [trace[-1], corner])

print(f())  # [-2.0, 1.0], expected [2.0, 1.0] as on ae782b0fb
主要言語
Python
スター
655
フォーク
266
平均マージ
3日 23時間
マージ済み PR(30日)
43

環境構築

はじめの一歩

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

pymc-devs/pytensor のほかの issue

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

似ている issue

Python の issue をもっと見る

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

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