Boolean indexing when elements of mask shape are zero?

オープン
#929 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

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

評価

難易度
5/5
見積もり時間
1週間以上
初心者へのやさしさ
35/100
issue の種類
ドキュメント
明瞭さ
おおむね明確
活発さ
停滞
技術スタック
python
領域
documentation

調査の方向性

まずリンク先の Boolean Array Indexing セクションを読み、その後、NumPy、CuPy、array_api_strict、jax.numpy、PyTorch、dask.array について示されている挙動を比較します。仕様に、サイズ 0 のブールマスク次元が有効かどうか、およびバックエンドがどのような結果またはエラーを生成すべきかが明記されれば完了です。

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

説明

The standard seems to allow elements of a boolean index's shape to be zero.

The size of each dimension in B must equal the size of the corresponding dimension in A or be 0,

But I have read a few times, and I don't think it specifies what should happen in this case.

This returns an empty array in NumPy, CuPy, array_api_strict, and jax.numpy.

import array_api_strict as xp
x = xp.asarray([1, 2, 3])
i = xp.asarray([], dtype=xp.bool)
x[i]  # array([], dtype=int64)

The behavior would follow from the usual rules if the index were integral, but it's not obvious to me that this should work for a boolean index of zero size. Indeed, PyTorch fails with:

IndexError: The shape of the mask [0] at index 0 does not match the shape of the indexed tensor [3] at index 0

and dask.array fails with:

ValueError: operands could not be broadcast together with shapes (3,) (0,)

If the NumPy behavior is desired, does it follow from the usual rule, or is it a special case? Either way, it would help to spell out the desired behavior to ensure consistency among backends.

主要言語
Python
スター
281
フォーク
52
PR マージ指標
30日以内にマージされた PR はありません

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

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

data-apis/array-api のほかの issue

data-apis/array-api の issue をすべて見る

似ている issue

Python の issue をもっと見る

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

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