`as_tensor_variable` / `constant` ignore `floatX` for lists and tuples of Python floats
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 初心者へのやさしさ
- 68/100
- issue の種類
- バグ
- 明瞭さ
- 明確に書かれている
- 活発さ
- 活発
- 技術スタック
- numpy, python
調査の方向性
Start in pytensor/scalar/basic.py at ps.convert, then inspect the sequence branch and autocast_float to understand how floatX and cast_policy="numpy+floatX" apply. Run the scalar and core tensor tests under both floatX settings, as described in the issue. Done means lists and tuples of Python floats follow the configured policy while arrays and NumPy scalars keep their dtype; check the behavior for NumPy scalars inside sequences.
索引モデルが issue の本文から書いたものです。
説明
Description
With floatX="float32", a Python float scalar is autocast to floatX, but a list or tuple of Python floats is not. It comes out as float64.
import numpy as np
import pytensor
import pytensor.tensor as pt
pytensor.config.floatX = "float32"
pt.as_tensor_variable(1.0).dtype # float32
pt.as_tensor_variable([1.0, 2.0]).dtype # float64 <- surprising
pt.as_tensor_variable((1.0, 2.0)).dtype # float64 <- surprising
pt.as_tensor_variable(np.array([1.0, 2.0])).dtype # float64 (expected, array has its own dtype)
pt.as_tensor_variable([]).dtype # float32 (empty list already uses floatX)
Cause
ps.convert (pytensor/scalar/basic.py) sends Python float through autocast_float, which respects floatX under the default cast_policy="numpy+floatX". Lists and tuples fall into the final else branch, which only calls np.asarray(x). NumPy infers float64 and nothing downcasts it. The only special case there is the empty one (x_.size == 0), which already uses floatX.
Why it matters
A list of Python floats has no dtype of its own, so it is just as untyped as a bare 1.0. The two paths disagree, and the list/tuple path can silently upcast a float32 graph to float64.
Related
#1073 and #1913 cover the same problem for scalars under the custom cast policy. This is the same gap for lists and tuples.
Proposed fix
Under cast_policy="numpy+floatX", have the sequence branch of ps.convert cast a float64 result to floatX when the input has no dtype attribute. Arrays and numpy scalars keep their dtype. A prototype passes the scalar and core tensor tests under both floatX settings. I haven't run the full suite.
Open question: should a list containing numpy float64 scalars, e.g. [np.float64(1.), 2.], also be downcast? The list has no .dtype, so the prototype would downcast it.
Workaround
pt.as_tensor_variable(x, dtype="floatX")
- 主要言語
- Python
- スター
- 654
- フォーク
- 258
- 平均マージ
- 2日 7時間
- マージ済み PR(30日)
- 39
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- 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 日以内に返信
-
BUG: geomspace returns wrong sign for the endpoints when start and stop are negative対応中かも @mayuriphad が 27 日前に担当しました。 オープン
難易度 2/5 1時間未満 初心者へのやさしさ 85/100
メンテナーはふだん 1 日以内に返信
-
Reciprocal.impl computes np.float32(1.0) / x: float32 precision for float64 scalars under NEP 50 (Python linker)再び着手できるかも このイシューのプルリクエストはマージされずにクローズされました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
pymc-devs/pytensor#2430 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
pymc-devs/pytensor#2428 · コメント 5 件 ·
メンテナーはふだん 1 日以内に返信
pymc-devs/pytensor の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
メンテナーはふだん 1 日以内に返信
-
enhancement
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
dgunning/edgartools#2019 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
topoteretes/cognee#6818 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
source_verification_agent: no outcome when the publisher confirms a work but its DOI resolves to a different record対応中かも @pinjun99 が今日担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
Imbad0202/academic-research-skills#1159 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
[Bug]: DoubleMLData.from_arrays checks the treatment d with force_all_x_finite instead of force_all_d_finite対応中かも @leninworld が今日担当しました。 オープン
難易度 1/5 1時間未満 初心者へのやさしさ 88/100
DoubleML/doubleml-for-py#471 ·
メンテナーはふだん 1 日以内に返信