@@ -302,7 +302,12 @@ def sort(self, order: str | list[str] | None = None) -> blosc2.LazyArray:
302302 pass
303303
304304 @abstractmethod
305- def compute (self , item : slice | list [slice ] | None = None , ** kwargs : Any ) -> blosc2 .NDArray :
305+ def compute (
306+ self ,
307+ item : slice | list [slice ] | None = None ,
308+ fp_accuracy : blosc2 .FPAccuracy = blosc2 .FPAccuracy .DEFAULT ,
309+ ** kwargs : Any ,
310+ ) -> blosc2 .NDArray :
306311 """
307312 Return a :ref:`NDArray` containing the evaluation of the :ref:`LazyArray`.
308313
@@ -313,9 +318,14 @@ def compute(self, item: slice | list[slice] | None = None, **kwargs: Any) -> blo
313318 the evaluated result. This difference between slicing operands and slicing the final expression
314319 is important when reductions or a where clause are used in the expression.
315320
321+ fp_accuracy: :ref:`blosc2.FPAccuracy`, optional
322+ Specifies the floating-point accuracy to be used during computation.
323+ By default, :ref:`blosc2.FPAccuracy.DEFAULT` is used.
324+
316325 kwargs: Any, optional
317326 Keyword arguments that are supported by the :func:`empty` constructor.
318327 These arguments will be set in the resulting :ref:`NDArray`.
328+ Additionally, the following special kwargs are supported:
319329
320330 Returns
321331 -------
@@ -1296,10 +1306,11 @@ def fast_eval( # noqa: C901
12961306 if use_miniexpr :
12971307 cparams = kwargs .pop ("cparams" , blosc2 .CParams ())
12981308 # All values will be overwritten, so we can use an uninitialized array
1309+ fp_accuracy = kwargs .pop ("fp_accuracy" , blosc2 .FPAccuracy .DEFAULT )
12991310 res_eval = blosc2 .uninit (shape , dtype , chunks = chunks , blocks = blocks , cparams = cparams , ** kwargs )
13001311 try :
13011312 print ("expr->miniexpr:" , expression )
1302- res_eval ._set_pref_expr (expression , operands )
1313+ res_eval ._set_pref_expr (expression , operands , fp_accuracy = fp_accuracy )
13031314 # Data to compress is fetched from operands, so it can be uninitialized here
13041315 data = np .empty (res_eval .schunk .chunksize , dtype = np .uint8 )
13051316 # Exercise prefilter for each chunk
@@ -2001,6 +2012,7 @@ def reduce_slices( # noqa: C901
20012012 if use_miniexpr :
20022013 # Experiments say that not splitting is best (at least on Apple Silicon M4 Pro)
20032014 cparams = kwargs .pop ("cparams" , blosc2 .CParams (splitmode = blosc2 .SplitMode .NEVER_SPLIT ))
2015+ fp_accuracy = kwargs .pop ("fp_accuracy" , blosc2 .FPAccuracy .DEFAULT )
20042016 # Create a fake NDArray just to drive the miniexpr evaluation (values won't be used)
20052017 res_eval = blosc2 .uninit (shape , dtype , chunks = chunks , blocks = blocks , cparams = cparams , ** kwargs )
20062018 # Compute the number of blocks in the result
@@ -2027,7 +2039,7 @@ def reduce_slices( # noqa: C901
20272039 try :
20282040 print ("expr->miniexpr:" , expression , reduce_op )
20292041 expression = f"{ reduce_op_str } ({ expression } )"
2030- res_eval ._set_pref_expr (expression , operands , aux_reduc )
2042+ res_eval ._set_pref_expr (expression , operands , fp_accuracy , aux_reduc )
20312043 # Data won't even try to be compressed, so buffers can be unitialized and reused
20322044 data = np .empty (res_eval .schunk .chunksize , dtype = np .uint8 )
20332045 chunk_data = np .empty (res_eval .schunk .chunksize + blosc2 .MAX_OVERHEAD , dtype = np .uint8 )
@@ -3142,7 +3154,9 @@ def sort(self, order: str | list[str] | None = None) -> blosc2.LazyArray:
31423154 lazy_expr ._order = order
31433155 return lazy_expr
31443156
3145- def compute (self , item = (), ** kwargs ) -> blosc2 .NDArray :
3157+ def compute (
3158+ self , item = (), fp_accuracy : blosc2 .FPAccuracy = blosc2 .FPAccuracy .DEFAULT , ** kwargs
3159+ ) -> blosc2 .NDArray :
31463160 # When NumPy ufuncs are called, the user may add an `out` parameter to kwargs
31473161 if "out" in kwargs : # use provided out preferentially
31483162 kwargs ["_output" ] = kwargs .pop ("out" )
@@ -3452,7 +3466,7 @@ def sort(self, order: str | list[str] | None = None) -> blosc2.LazyArray:
34523466 lazy_expr ._order = order
34533467 return lazy_expr
34543468
3455- def compute (self , item = (), ** kwargs ):
3469+ def compute (self , item = (), fp_accuracy : blosc2 . FPAccuracy = blosc2 . FPAccuracy . DEFAULT , ** kwargs ):
34563470 # Get kwargs
34573471 if kwargs is None :
34583472 kwargs = {}
0 commit comments