You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
x = da.arange(100, chunks=32)
y = x.map_blocks(lambda blk: numpy.repeat(blk, blk))
print(y.compute().shape, y.shape)
Output
(4950,) (100,)
Expected output is (4950,) (4950,), or an Exception("shape of output changed, but the chunks argument is not provided)
Manually providing the chunks gives correct output (as documented)
x = da.arange(100, chunks=32)
N = x.map_blocks(lambda blk: blk.sum().reshape(1), chunks=(1,))
y = x.map_blocks(lambda blk: numpy.repeat(blk, blk), chunks=(tuple(N.compute()),))
print(y.compute().shape, y.shape)
Output
(4950,) (4950,)
However, this is inefficient and verbose. The x array is mapped one extra time, for a piece of information that is already available during the second map_blocks, as the shape of the output.
If the output array can be constructed after the function call (e.g. use a concentrate operation), then the use case can produce expected output instead of raising an exception.
Expected output is (4950,) (4950,), or an Exception("shape of output changed, but the chunks argument is not provided)
Yeah, I think that there is a tradeoff between being permissive and strict. My guess is that users appreciate being allowed to be a bit sloppy here, but I agree that this can cause issues.
However, this is inefficient and verbose. The x array is mapped one extra time, for a piece of information that is already available during the second map_blocks, as the shape of the output.
Agreed
If the output array can be constructed after the function call (e.g. use a concentrate operation), then the use case can produce expected output instead of raising an exception.
You can also use NaN to indicate unknown chunks, i.e., y = x.map_blocks(lambda blk: numpy.repeat(blk, blk), chunks=(numpy.nan,)). Many operations work with unknown chunks.
Dask arrays have fixed chunks at construction time. That's pretty baked into the data model -- I don't know what else we could do here.
@shoyer the nan chunk does not feel very enjoyable. (likely due to using nan as a placeholder). I think it would work in cases where I do not actually care the result of map, e.g. if I am using map to submit futures over every chunk of the array.
I worry that the mandate of supporting code that depends on this sloppiness makes it difficult for the API to evolve in the future. For now I think I will depend on the sloppiness here too, so yes don't fix this yet.
Since this would require computing shape information before constructing the graph (going against dask-array's data model), I'm closing this as won't fix. We recommend either specifying your known shapes beforehand, or specifying them as nan (unknown). You may also be interested in #3293.
Activity
mrocklin commentedon Dec 12, 2018
Yeah, I think that there is a tradeoff between being permissive and strict. My guess is that users appreciate being allowed to be a bit sloppy here, but I agree that this can cause issues.
Agreed
I'm not sure I understand this last statement.
shoyer commentedon Dec 13, 2018
You can also use NaN to indicate unknown chunks, i.e.,
y = x.map_blocks(lambda blk: numpy.repeat(blk, blk), chunks=(numpy.nan,)). Many operations work with unknown chunks.Dask arrays have fixed chunks at construction time. That's pretty baked into the data model -- I don't know what else we could do here.
mrocklin commentedon Dec 20, 2018
Any further thoughts on this @rainwoodman ?
Otherwise I'm inclined to close as "wont fix"
rainwoodman commentedon Dec 22, 2018
@shoyer the nan chunk does not feel very enjoyable. (likely due to using nan as a placeholder). I think it would work in cases where I do not actually care the result of map, e.g. if I am using map to submit futures over every chunk of the array.
I worry that the mandate of supporting code that depends on this sloppiness makes it difficult for the API to evolve in the future. For now I think I will depend on the sloppiness here too, so yes don't fix this yet.
jcrist commentedon Apr 30, 2019
Since this would require computing shape information before constructing the graph (going against dask-array's data model), I'm closing this as won't fix. We recommend either specifying your known shapes beforehand, or specifying them as
nan(unknown). You may also be interested in #3293.