@@ -10,9 +10,11 @@ def apply_gufunc(
1010 * args ,
1111 axes = None ,
1212 axis = None ,
13+ keepdims = False ,
1314 output_dtypes = None ,
1415 output_sizes = None ,
1516 vectorize = None ,
17+ allow_rechunk = False ,
1618 ** kwargs ,
1719):
1820 """
@@ -22,17 +24,19 @@ def apply_gufunc(
2224 `equivalent function <https://docs.dask.org/en/stable/generated/dask.array.gufunc.apply_gufunc.html>`_
2325 in Dask. Refer there for usage information.
2426
25- Current limitations: ``keepdims``, and ``allow_rechunk`` are not supported;
27+ Current limitations: ``keepdims=True ``, and ``allow_rechunk=True `` are not supported;
2628 and multiple outputs are not supported.
2729
2830 Cubed assumes that ``func`` will allocate a new output array. However, if it allocates more memory
2931 than than, then you need to tell Cubed about it by setting the ``extra_projected_mem`` parameter
3032 to the amount needed in bytes (per task).
3133 """
3234
33- # Currently the following parameters cannot be changed
34- # keepdims = False
35- allow_rechunk = False
35+ if keepdims :
36+ raise NotImplementedError ("keepdims is not supported in apply_gufunc" )
37+
38+ # Don't fail immediately if allow_rechunk=True, since rechunking may not be necessary.
39+ # However, if rechunking is necessary, the code below with raise an exception.
3640
3741 # based on dask's apply_gufunc
3842
@@ -128,23 +132,23 @@ def apply_gufunc(
128132 # Check that the arrays have same length for same dimensions or dimension `1`
129133 if set (sizes ) | {1 } != {1 , max (sizes )}:
130134 raise ValueError (f"Dimension `'{ dim } '` with different lengths in arrays" )
131- if not allow_rechunk :
132- chunksizes = chunksizess [dim ]
133- # Check if core dimensions consist of only one chunk
134- if (dim in core_shapes ) and (chunksizes [0 ][0 ] < core_shapes [dim ]):
135- raise ValueError (
136- "Core dimension `'{}'` consists of multiple chunks. To fix, rechunk into a single \
137- chunk along this dimension or set `allow_rechunk=True`, but beware that this may increase memory usage \
135+
136+ # Check that chunking is correct, but don't rechunk
137+ # TODO(#833): rechunk if allow_rechunk=True
138+ chunksizes = chunksizess [dim ]
139+ # Check if core dimensions consist of only one chunk
140+ if (dim in core_shapes ) and (chunksizes [0 ][0 ] < core_shapes [dim ]):
141+ raise ValueError (
142+ "Core dimension `'{}'` consists of multiple chunks. To fix, rechunk into a single \
143+ chunk along this dimension, but beware that this may increase memory usage \
138144 significantly." .format (dim )
139- )
140- # Check if loop dimensions consist of same chunksizes, when they have sizes > 1
141- relevant_chunksizes = list (
142- unique (c for s , c in zip (sizes , chunksizes ) if s > 1 )
143145 )
144- if len (relevant_chunksizes ) > 1 :
145- raise ValueError (
146- f"Dimension `'{ dim } '` with different chunksize present"
147- )
146+ # Check if loop dimensions consist of same chunksizes, when they have sizes > 1
147+ relevant_chunksizes = list (
148+ unique (c for s , c in zip (sizes , chunksizes ) if s > 1 )
149+ )
150+ if len (relevant_chunksizes ) > 1 :
151+ raise ValueError (f"Dimension `'{ dim } '` with different chunksize present" )
148152
149153 # Apply function - use blockwise here
150154 arginds = list (concat (zip (args , input_dimss )))
0 commit comments