dwavesystems / dwavesystems/dwave-optimization
Split between basic and advanced indexing cannot handle all cases
- Dominant language
- C++
- Stars
- 31
- Forks
- 36
- Avg merge
- 16h 55m
- Merged PRs (30d)
- 8
Description
Consider
```python
from dwave.optimization import Model
model = Model()
arr = np.arange(2*3*4*5).reshape(2, 3, 4, 5)
sym = model.constant(arr)
print(arr[:, 0, :, [2]].shape)
print(sym[:, 0, :, [2]].shape())
```
```
(1, 2, 4)
(2, 4, 1)
```
this is because we distribute the `0` index to basic indexing and `[2]` to advanced indexing. Basic indexing does not have a notion of what we call [type 2 indexing](https://numpy.org/doc/stable/user/basics.indexing.html#combining-advanced-and-basic-indexing). I.e.,
> * The advanced indices are separated by a slice, [Ellipsis](https://docs.python.org/3/library/constants.html#Ellipsis) or [newaxis](https://numpy.org/doc/stable/reference/constants.html#numpy.newaxis). For example x[arr1, :, arr2].
> * The advanced indices are all next to each other. For example x[..., arr1, arr2, :] but not x[arr1, :, 1] since 1 is an advanced index in this regard.
Contributor guide
Assessment
This issue has not been assessed yet.