Skip to content

Check for tricky cases when fusing fancy indices - #2313

Merged
mrocklin merged 2 commits into
dask:masterfrom
jcrist:dont-fuse-fancy-indices-when-bad
May 11, 2017
Merged

mrocklin merged 2 commits into
dask:masterfrom
jcrist:dont-fuse-fancy-indices-when-bad

Conversation

@jcrist

@jcrist jcrist commented May 8, 2017

Copy link
Copy Markdown
Member

Previously we'd fuse normal and fancy indexing like:

a[:, :, [0, 1], :][0, :, :, :] -> a[0, :, [0, 1], :]

This is incorrect, and was leading to bugs:

>>> a = np.ones((11, 13, 20, 12))
>>> a[:, :, [0, 1], :][0, :, :, :].shape
(13, 2, 12)
>>> a[0, :, [0, 1], :].shape
(2, 13, 12)

Let ind1 and ind2 represent two index operations as in
x[ind1][ind2]. We now only fuse indices involving fancy indexing if:

  • Only one of the two uses fancy indexing
  • Dimensions where fancy indexing isn't used are non-integers

This means that the following will be fused:

a[:10, [1, 2, 3]][:5, 0]

but this won't:

a[:10, [1, 2, 3][0, 0]

This does exclude some valid cases, but is easier to write than
following all the checks required when mixing fancy and non-fancy
indexing.

jcrist added 2 commits May 8, 2017 17:26
Previously we'd fuse normal and fancy indexing like:

```python
a[:, :, [0, 1], :][0, :, :, :] -> a[0, :, [0, 1], :]
```

This is incorrect, and was leading to bugs:

```python
>>> a = np.ones((11, 13, 20, 12))
>>> a[:, :, [0, 1], :][0, :, :, :].shape
(13, 2, 12)
>>> a[0, :, [0, 1], :].shape
(2, 13, 12)
```

Let `ind1` and `ind2` represent two index operations as in
`x[ind1][ind2]`. We now only fuse indices involving fancy indexing if:
- Only one of the two uses fancy indexing
- Dimensions where fancy indexing isn't used are non-integers

This means that the following will be fused:

```
a[:10, [1, 2, 3]][:5, 0]
```

but this won't:

```
a[:10, [1, 2, 3][0, 0]
```

This does exclude some valid cases, but is easier to write than
following all the checks required when mixing fancy and non-fancy
indexing.
@jcrist

jcrist commented May 9, 2017

Copy link
Copy Markdown
Member Author

Looks like this also fixes #1770.

In [1]: import dask.array as da

In [2]: d1 = da.zeros((1, 9, 3), chunks=(1, 5, 3))

In [3]: d2 = d1[0, :, [0, 2]]

In [4]: d2.compute()
Out[4]:
array([[ 0.,  0.],
       [ 0.,  0.],
       [ 0.,  0.],
       [ 0.,  0.],
       [ 0.,  0.],
       [ 0.,  0.],
       [ 0.,  0.],
       [ 0.,  0.],
       [ 0.,  0.]])

@mrocklin
mrocklin merged commit e8a2dca into dask:master May 11, 2017
@jcrist
jcrist deleted the dont-fuse-fancy-indices-when-bad branch May 11, 2017 16:17
@jcrist jcrist mentioned this pull request May 11, 2017
@sinhrks sinhrks added this to the 0.15.0 milestone Aug 30, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants