Skip to content
Snippets Groups Projects
Commit bb984679 authored by Richard Angersbach's avatar Richard Angersbach
Browse files

Fix usage of numerical limits for init value of reduction

parent fff5a079
Branches
Tags
1 merge request!438Reduction Support
...@@ -100,8 +100,12 @@ class NumericLimitsFunctions(Enum): ...@@ -100,8 +100,12 @@ class NumericLimitsFunctions(Enum):
Each platform has to materialize these functions to a concrete implementation. Each platform has to materialize these functions to a concrete implementation.
""" """
min = ("min", 0) Min = ("min", 0)
max = ("max", 0) Max = ("max", 0)
def __init__(self, func_name, num_args):
self.function_name = func_name
self.num_args = num_args
class PsMathFunction(PsFunction): class PsMathFunction(PsFunction):
......
...@@ -206,10 +206,10 @@ class FreezeExpressions: ...@@ -206,10 +206,10 @@ class FreezeExpressions:
# TODO: unsure if sp.Min & sp.Max are mapped by map_Min/map_Max afterwards # TODO: unsure if sp.Min & sp.Max are mapped by map_Min/map_Max afterwards
case "min": case "min":
op = sp.Min op = sp.Min
init_val = NumericLimitsFunctions("min") init_val = PsCall(PsMathFunction(NumericLimitsFunctions.Min), [])
case "max": case "max":
op = sp.Max op = sp.Max
init_val = NumericLimitsFunctions("max") init_val = PsCall(PsMathFunction(NumericLimitsFunctions.Max), [])
case _: case _:
raise FreezeError(f"Unsupported reduced assignment: {expr.op}.") raise FreezeError(f"Unsupported reduced assignment: {expr.op}.")
......
...@@ -62,7 +62,7 @@ class GenericCpu(Platform): ...@@ -62,7 +62,7 @@ class GenericCpu(Platform):
dtype = call.get_dtype() dtype = call.get_dtype()
arg_types = (dtype,) * func.num_args arg_types = (dtype,) * func.num_args
if isinstance(dtype, PsScalarType) and func in (NumericLimitsFunctions.min, NumericLimitsFunctions.max): if isinstance(dtype, PsScalarType) and func in (NumericLimitsFunctions.Min, NumericLimitsFunctions.Max):
cfunc = CFunction(f"{dtype.c_string()}_{func.function_name}".capitalize(), arg_types, dtype) cfunc = CFunction(f"{dtype.c_string()}_{func.function_name}".capitalize(), arg_types, dtype)
call.function = cfunc call.function = cfunc
return call return call
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment