@@ -1983,11 +1983,13 @@ def reduce_slices( # noqa: C901
19831983 chunks = temp .chunks
19841984 del temp
19851985
1986- # if (where is None and fast_path and all_ndarray) and (expression == "o0" or expression == "(o0)"):
1987- # miniexpr does not shine specially for single operand reductions
1988- if (where is None and fast_path and all_ndarray ) and not (
1989- expression == "o0" or expression == "(o0)"
1990- ): # or 1: # XXX make tests pass
1986+ # miniexpr reduction path only supported for some cases so far
1987+ if where is None and fast_path and all_ndarray and reduced_shape == ():
1988+ if reduce_op in (ReduceOp .ARGMAX , ReduceOp .ARGMIN ):
1989+ use_miniexpr = False # not supported yet
1990+ elif len (operands ) <= 2 :
1991+ # This is supported, but performance is generally worse than manual chunked evaluation
1992+ use_miniexpr = False
19911993 # Only this case is supported so far
19921994 if use_miniexpr :
19931995 for op in operands .values ():
@@ -2007,7 +2009,6 @@ def reduce_slices( # noqa: C901
20072009 res_eval = blosc2 .empty (shape , dtype , chunks = chunks , blocks = blocks , cparams = cparams , ** kwargs )
20082010 # Compute the number of blocks in the result
20092011 nblocks = res_eval .nbytes // res_eval .blocksize
2010- print ("nblocks:" , nblocks , dtype )
20112012 aux_reduc = np .empty (nblocks , dtype = dtype )
20122013 try :
20132014 print ("expr->miniexpr:" , expression , reduce_op )
@@ -2032,13 +2033,12 @@ def reduce_slices( # noqa: C901
20322033 # (continue to the manual chunked evaluation below)
20332034 pass
20342035 else :
2035- from time import time
2036-
2037- t0 = time ()
2038- result = reduce_op .value .reduce (aux_reduc , ** reduce_args )
2039- t = time () - t0
2040- print (f"reduction of aux_reduc took { t * 1e6 :.6f} us" )
2041- # print(f"res_eval.info:", res_eval.info)
2036+ if reduce_op == ReduceOp .ANY :
2037+ result = np .any (aux_reduc , ** reduce_args )
2038+ elif reduce_op == ReduceOp .ALL :
2039+ result = np .all (aux_reduc , ** reduce_args )
2040+ else :
2041+ result = reduce_op .value .reduce (aux_reduc , ** reduce_args )
20422042 return result
20432043
20442044 # Iterate over the operands and get the chunks
0 commit comments