@@ -323,13 +323,13 @@ def __nonzero__(self) -> bool:
323
323
class double (_SimpleParameterTypeBase ):
324
324
@staticmethod
325
325
def _isValid (value ) -> bool :
326
- return isinstance (value , (int , long , float ))
326
+ return isinstance (value , (int , long , builtins . float ))
327
327
@staticmethod
328
328
def _valueFromString (value :str ):
329
329
"""only used for cfg-parsing"""
330
- return double (float (value ))
330
+ return double (builtins . float (value ))
331
331
def insertInto (self , parameterSet , myname :str ):
332
- parameterSet .addDouble (self .isTracked (), myname , float (self .value ()))
332
+ parameterSet .addDouble (self .isTracked (), myname , builtins . float (self .value ()))
333
333
def __nonzero__ (self ) -> bool :
334
334
return self .value ()!= 0.
335
335
def configValue (self , options :PrintOptions = PrintOptions ()) -> str :
@@ -345,7 +345,30 @@ def _pythonValue(value) -> str:
345
345
return "float('nan')"
346
346
return str (value )
347
347
348
-
348
+ class float (_SimpleParameterTypeBase ):
349
+ @staticmethod
350
+ def _isValid (value ) -> bool :
351
+ return isinstance (value , (int , long , builtins .float ))
352
+ @staticmethod
353
+ def _valueFromString (value :str ):
354
+ """only used for cfg-parsing"""
355
+ return float (builtins .float (value ))
356
+ def insertInto (self , parameterSet , myname :str ):
357
+ parameterSet .addFloat (self .isTracked (), myname , builtins .float (self .value ()))
358
+ def __nonzero__ (self ) -> bool :
359
+ return self .value ()!= 0.
360
+ def configValue (self , options :PrintOptions = PrintOptions ()) -> str :
361
+ return float ._pythonValue (self ._value )
362
+ @staticmethod
363
+ def _pythonValue (value ) -> str :
364
+ if math .isinf (value ):
365
+ if value > 0 :
366
+ return "float('inf')"
367
+ else :
368
+ return "-float('inf')"
369
+ if math .isnan (value ):
370
+ return "float('nan')"
371
+ return str (value )
349
372
350
373
class bool (_SimpleParameterTypeBase ):
351
374
@staticmethod
@@ -1010,7 +1033,6 @@ def _place(self,name:str,proc):
1010
1033
proc ._placePSet (name ,self )
1011
1034
def __str__ (self ) -> str :
1012
1035
return object .__str__ (self )
1013
-
1014
1036
class PSet (_ParameterTypeBase ,_Parameterizable ,_ConfigureComponent ,_Labelable ):
1015
1037
def __init__ (self ,* arg ,** args ):
1016
1038
#need to call the inits separately
@@ -1145,7 +1167,19 @@ def insertInto(self, parameterSet, myname:str):
1145
1167
def pythonValueForItem (self ,item , options ) -> str :
1146
1168
return double ._pythonValue (item )
1147
1169
1148
-
1170
+ class vfloat (_ValidatingParameterListBase ):
1171
+ def __init__ (self ,* arg ,** args ):
1172
+ super (vfloat ,self ).__init__ (* arg ,** args )
1173
+ @classmethod
1174
+ def _itemIsValid (cls ,item ) -> builtins .bool :
1175
+ return float ._isValid (item )
1176
+ @staticmethod
1177
+ def _valueFromString (value :str ):
1178
+ return vfloat (* _ValidatingParameterListBase ._itemsFromStrings (value ,float ._valueFromString ))
1179
+ def insertInto (self , parameterSet , myname :str ):
1180
+ parameterSet .addVFloat (self .isTracked (), myname , self .value ())
1181
+ def pythonValueForItem (self ,item , options ) -> str :
1182
+ return float ._pythonValue (item )
1149
1183
1150
1184
1151
1185
class vbool (_ValidatingParameterListBase ):
@@ -1427,6 +1461,10 @@ def addDouble(self,tracked:bool,label:str,value):
1427
1461
v = double (value )
1428
1462
v .setIsTracked (tracked )
1429
1463
setattr (self .pset ,label ,v )
1464
+ def addFloat (self ,tracked :bool ,label :str ,value ):
1465
+ v = float (value )
1466
+ v .setIsTracked (tracked )
1467
+ setattr (self .pset ,label ,v )
1430
1468
def addString (self ,tracked :bool ,label :str ,value ):
1431
1469
v = string (value )
1432
1470
v .setIsTracked (tracked )
@@ -1479,6 +1517,11 @@ def addVDouble(self,tracked:bool,label:str,value):
1479
1517
v = vdouble (value )
1480
1518
v .setIsTracked (tracked )
1481
1519
setattr (self .pset ,label ,v )
1520
+
1521
+ def addVFloat (self ,tracked :bool ,label :str ,value ):
1522
+ v = vfloat (value )
1523
+ v .setIsTracked (tracked )
1524
+ setattr (self .pset ,label ,v )
1482
1525
def addVString (self ,tracked :bool ,label :str ,value ):
1483
1526
v = vstring (value )
1484
1527
v .setIsTracked (tracked )
@@ -1668,26 +1711,26 @@ def testdouble(self):
1668
1711
d = double (1 )
1669
1712
self .assertEqual (d .value (),1 )
1670
1713
self .assertEqual (d .pythonValue (),'1' )
1671
- d = double (float ('Inf' ))
1672
- self .assertEqual (d ,float ('Inf' ))
1714
+ d = double (builtins . float ('Inf' ))
1715
+ self .assertEqual (d ,builtins . float ('Inf' ))
1673
1716
self .assertEqual (d .pythonValue (),"float('inf')" )
1674
- d = double (- float ('Inf' ))
1675
- self .assertEqual (d ,- float ('Inf' ))
1717
+ d = double (- builtins . float ('Inf' ))
1718
+ self .assertEqual (d ,- builtins . float ('Inf' ))
1676
1719
self .assertEqual (d .pythonValue (),"-float('inf')" )
1677
- d = double (float ('Nan' ))
1720
+ d = double (builtins . float ('Nan' ))
1678
1721
self .assertTrue (math .isnan (d .value ()))
1679
1722
self .assertEqual (d .pythonValue (),"float('nan')" )
1680
1723
def testvdouble (self ):
1681
1724
d = vdouble (1 )
1682
1725
self .assertEqual (d .value (),[1 ])
1683
1726
self .assertEqual (d .dumpPython (),'cms.vdouble(1)' )
1684
- d = vdouble (float ('inf' ))
1685
- self .assertEqual (d ,[float ('inf' )])
1727
+ d = vdouble (builtins . float ('inf' ))
1728
+ self .assertEqual (d ,[builtins . float ('inf' )])
1686
1729
self .assertEqual (d .dumpPython (),"cms.vdouble(float('inf'))" )
1687
- d = vdouble (- float ('Inf' ))
1688
- self .assertEqual (d ,[- float ('inf' )])
1730
+ d = vdouble (- builtins . float ('Inf' ))
1731
+ self .assertEqual (d ,[- builtins . float ('inf' )])
1689
1732
self .assertEqual (d .dumpPython (),"cms.vdouble(-float('inf'))" )
1690
- d = vdouble (float ('nan' ))
1733
+ d = vdouble (builtins . float ('nan' ))
1691
1734
self .assertTrue (math .isnan (d [0 ]))
1692
1735
self .assertEqual (d .dumpPython (),"cms.vdouble(float('nan'))" )
1693
1736
def testvint32 (self ):
@@ -2510,12 +2553,12 @@ def testincompatibletypes(self):
2510
2553
with self .assertRaises (TypeError ):
2511
2554
3 < string ("I am a string" )
2512
2555
def testinfinity (self ):
2513
- self .assertLess (1e99 , double (float ("inf" )))
2514
- self .assertLess (double (1e99 ), float ("inf" ))
2515
- self .assertGreater (1e99 , double (float ("-inf" )))
2516
- self .assertEqual (double (float ("inf" )), float ("inf" ))
2556
+ self .assertLess (1e99 , double (builtins . float ("inf" )))
2557
+ self .assertLess (double (1e99 ), builtins . float ("inf" ))
2558
+ self .assertGreater (1e99 , double (builtins . float ("-inf" )))
2559
+ self .assertEqual (double (builtins . float ("inf" )), builtins . float ("inf" ))
2517
2560
def testnan (self ):
2518
- nan = double (float ("nan" ))
2561
+ nan = double (builtins . float ("nan" ))
2519
2562
self .assertNotEqual (nan , nan )
2520
2563
self .assertFalse (nan > 3 or nan < 3 or nan == 3 )
2521
2564
0 commit comments