Boolean indexing when elements of mask shape are zero?

Abierto
#929 1 comentario 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
5/5
Tiempo estimado
Más de una semana
Aptitud para principiantes
35/100
Tipo de issue
Documentación
Claridad
Bastante claro
Estado de actividad
Estancado
Stack tecnológico
python

Línea de trabajo

Lee primero la sección enlazada Boolean Array Indexing y, después, compara los comportamientos mostrados para NumPy, CuPy, array_api_strict, jax.numpy, PyTorch y dask.array. Se considera terminado cuando la especificación establece explícitamente si las dimensiones de máscara booleana de tamaño cero son válidas y qué resultado o error deben producir los backends.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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.

Lenguaje dominante
Python
Estrellas
281
Forks
52
Métricas de merge de PR
Sin PR fusionados en 30 d

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de data-apis/array-api

Todos los issues de data-apis/array-api

Issues similares

Más issues de Python

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.