Broadcasting rule allows broadcasting 0d array to empty 1d array
まだ誰も着手していません。
評価
調査の方向性
提供された Python の broadcasted_shape 実装と array API のブロードキャスト仕様から始め、次に、示されている 0d から空の 1d へのケースを NumPy の動作と比較します。互換性が意図されたものかどうかを判断し、仕様上の決定または根拠を記録してください。この issue では、更新対象のプロジェクトファイルやテストは指定されていません。
索引モデルが issue の本文から書いたものです。
説明
Here is an implementation of the broadcasting algorithm from the spec:
import operator
def broadcasted_shape(sh1, sh2):
if not isinstance(sh1, (tuple, list)) or not isinstance(sh2, (tuple, list)):
raise TypeError
shape1 = tuple(operator.index(i) for i in sh1)
shape2 = tuple(operator.index(i) for i in sh2)
n1 = len(shape1)
n2 = len(shape2)
n = max(n1, n2)
shape = [0] * n
i = n - 1
while i>=0:
_n1 = n1 - n + i
d1 = shape1[_n1] if (_n1 >=0) else 1
_n2 = n2 - n + i
d2 = shape2[_n2] if (_n2 >=0) else 1
if d1 == 1:
shape[i] = d2
elif d2 == 1 or d2 == d1:
shape[i] = d1
else:
raise ValueError
i = i - 1
return tuple(shape)
With this implementation broadcasting from 0d array to empty 1d array is allowed, which is also consistent with NumPy.
I am not sure why this is a logic thing to do other than to stay compatible with NumPy.
In [1]: from broadcast import broadcasted_shape
In [2]: broadcasted_shape((1,), (0,))
Out[2]: (0,)
In [3]: broadcasted_shape(tuple(), (0,))
Out[3]: (0,)
In [4]: import numpy as np
In [5]: np.broadcast_to(np.array(0), (0,)).shape
Out[5]: (0,)
In [6]: np.broadcast_to(np.array([0]), (0,)).shape
Out[6]: (0,)
The purpose of this issue is to discuss this behavior. If this is as designed, please feel free to close.
- 主要言語
- Python
- スター
- 281
- フォーク
- 52
- PR マージ指標
- 30日以内にマージされた PR はありません
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
data-apis/array-api のほかの issue
-
bug Maintenance Narrative Content
難易度 1/5 1〜3時間 初心者へのやさしさ 88/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
-
難易度 5/5 1週間以上 初心者へのやさしさ 35/100
-
Maintenance
-
難易度 5/5 1週間以上 初心者へのやさしさ 25/100
data-apis/array-api の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
syfoud/Simulated_Scepter#172 ·
-
A cancelled tests run makes the coverage comment workflow fail and reports it as a red check on main オープンarea: ci bug perceived difficulty: 3
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
Nitjsefnie-Harness-Commons/daedalus#921 · コメント 1 件 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 86/100
EleutherAI/lm-evaluation-harness#4207 ·
-
難易度 1/5 1時間未満 初心者へのやさしさ 92/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
ClickHouse/clickhouse-connect#1057 ·