Boolean indexing when elements of mask shape are zero?
Nobody has claimed this yet.
Assessment
- Difficulty
- 5/5
- Estimated time
- Over a week
- Newbie friendliness
- 35/100
- Issue type
- Documentation
- Clarity
- Mostly clear
- Activity status
- Stale
- Tech stack
- python
- Domain
- documentation
Research direction
Read the linked Boolean Array Indexing section first, then compare the behaviors shown for NumPy, CuPy, array_api_strict, jax.numpy, PyTorch, and dask.array. Done means the specification explicitly states whether zero-sized boolean mask dimensions are valid and what result or error backends should produce.
Written by the indexing model from the issue text.
Description
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
Aor be0,
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.
- Dominant language
- Python
- Stars
- 281
- Forks
- 52
- PR merge metrics
- No merged PRs in 30d
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from data-apis/array-api
-
Difficulty 1/5 1-3 hours Newbie friendliness 88/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
-
Difficulty 5/5 Over a week Newbie friendliness 35/100
-
Maintenance
-
Difficulty 5/5 Over a week Newbie friendliness 25/100
All issues in data-apis/array-api
Similar issues
-
documentation help wanted
Difficulty 2/5 1-3 hours Newbie friendliness 90/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 90/100
simonw/sqlite-utils#872 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100