@@ -179,6 +179,8 @@ def return_type(op: Any, *args: Any) -> Any:
179179 operator .and_ : ("__and__" , "__rand__" ),
180180 operator .xor : ("__xor__" , "__rxor__" ),
181181 operator .or_ : ("__or__" , "__ror__" ),
182+ min : ("__add__" , "__radd__" ),
183+ max : ("__sub__" , "__rsub__" ),
182184}
183185
184186
@@ -211,21 +213,6 @@ def _return_type_closure(a, b):
211213 register_property (T , meth , "return_type" , _return_type_reflexive (meth ))
212214 register_property (T , rmeth , "return_type" , _return_type_reflexive (rmeth ))
213215
214- register_property (
215- min ,
216- "__call__" ,
217- "return_type" ,
218- lambda op , a , b : query_property (a , "__add__" , "return_type" , b ),
219- )
220- register_property (
221- max ,
222- "__call__" ,
223- "return_type" ,
224- lambda op , a , b : query_property (a , "__add__" , "return_type" , b ),
225- )
226- register_property (any , "__call__" , "return_type" , lambda op , a , b : bool )
227- register_property (all , "__call__" , "return_type" , lambda op , a , b : bool )
228-
229216
230217_unary_operators : dict [Callable , str ] = {
231218 operator .abs : "__abs__" ,
@@ -421,34 +408,6 @@ def init_value(op, arg) -> Any:
421408 register_property (T , "__or__" , "init_value" , lambda a , b : a (False ))
422409
423410
424- def _min_init (arg ):
425- dtype = np .dtype (arg ) if isinstance (arg , np .ndarray ) else np .dtype (arg )
426- if np .issubdtype (dtype , np .floating ):
427- return math .inf
428- if np .issubdtype (dtype , np .integer ):
429- return np .iinfo (dtype ).max
430- if np .issubdtype (dtype , np .bool_ ):
431- return True
432- raise TypeError ("Unsupported dtype for min" )
433-
434-
435- def _max_init (arg ):
436- dtype = np .dtype (arg ) if isinstance (arg , np .ndarray ) else np .dtype (arg )
437- if np .issubdtype (dtype , np .floating ):
438- return - math .inf
439- if np .issubdtype (dtype , np .integer ):
440- return np .iinfo (dtype ).min
441- if np .issubdtype (dtype , np .bool_ ):
442- return False
443- raise TypeError ("Unsupported dtype for max" )
444-
445-
446- register_property (
447- min , "__call__" , "init_value" , lambda op , arg : _min_init (element_type (arg ))
448- )
449- register_property (
450- max , "__call__" , "init_value" , lambda op , arg : _max_init (element_type (arg ))
451- )
452- register_property (any , "__call__" , "init_value" , lambda op , arg : False )
453- register_property (all , "__call__" , "init_value" , lambda op , arg : True )
411+ register_property (min , "__call__" , "init_value" , lambda op , arg : math .inf )
412+ register_property (max , "__call__" , "init_value" , lambda op , arg : - math .inf )
454413register_property (operator .truth , "__call__" , "init_value" , lambda op , arg : True )
0 commit comments