Skip to content

Reshape throws AssertionError depending on order of arguments #881

@jeremyherbert

Description

@jeremyherbert

Not a whole lot to add on this one, I'm really not sure where to look. It seems that reshape is sensitive to the order of arguments?

import numpy as np
import dask.array as da

dataset = np.arange(200)
dataset.reshape((25, 8))  # all good

dask_dataset = da.from_array(dataset, chunks=(25,))
dask_dataset.reshape((8, 25)).compute()  # all good

##########

dask_dataset = da.from_array(dataset, chunks=(25,))
dask_dataset.reshape((25, 8)).compute()  # AssertionError

dask_dataset = da.from_array(dataset, chunks=(8,))
dask_dataset.reshape((25, 8)).compute()  # AssertionError

dask_dataset = da.from_array(dataset, chunks=(100,1))
dask_dataset.reshape((25, 8)).compute()  # AssertionError
---------------------------------------------------------------------------
AssertionError                            Traceback (most recent call last)
<ipython-input-23-0c250c1ead37> in <module>()
     11 
     12 dask_dataset = da.from_array(dataset, chunks=(25,))
---> 13 dask_dataset.reshape((25, 8)).compute()  # AssertionError
     14 
     15 dask_dataset = da.from_array(dataset, chunks=(8,))

/Users/jeremy/anaconda/lib/python3.5/site-packages/dask/array/core.py in reshape(self, *shape)
    888         if len(shape) == 1 and not isinstance(shape[0], Number):
    889             shape = shape[0]
--> 890         return reshape(self, shape)
    891 
    892     @wraps(topk)

/Users/jeremy/anaconda/lib/python3.5/site-packages/dask/array/core.py in reshape(array, shape)
   2222     if np.prod(shape) != array.size:
   2223         raise ValueError('total size of new array must be unchanged')
-> 2224     return unravel(ravel(array), shape)
   2225 
   2226 

/Users/jeremy/anaconda/lib/python3.5/site-packages/dask/array/core.py in unravel(array, shape)
   2207             return stack([unravel(array[n * trailing_size
   2208                                         : (n + 1) * trailing_size], shape[1:])
-> 2209                           for n in range(shape[0])])
   2210 
   2211 

/Users/jeremy/anaconda/lib/python3.5/site-packages/dask/array/core.py in stack(seq, axis)
   1492                 "\nData has %d dimensions, but got axis=%d" % (ndim, axis))
   1493 
-> 1494     assert len(set(a.chunks for a in seq)) == 1  # same chunks
   1495     shape = seq[0].shape[:axis] + (len(seq),) + seq[0].shape[axis:]
   1496     chunks = (  seq[0].chunks[:axis]

AssertionError:

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions