MCPcopy Create free account
hub / github.com/numpy/numpy / PhysicalQuantity

Class PhysicalQuantity

numpy/core/tests/test_function_base.py:11–36  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

9
10
11class PhysicalQuantity(float):
12 def __new__(cls, value):
13 return float.__new__(cls, value)
14
15 def __add__(self, x):
16 assert_(isinstance(x, PhysicalQuantity))
17 return PhysicalQuantity(float(x) + float(self))
18 __radd__ = __add__
19
20 def __sub__(self, x):
21 assert_(isinstance(x, PhysicalQuantity))
22 return PhysicalQuantity(float(self) - float(x))
23
24 def __rsub__(self, x):
25 assert_(isinstance(x, PhysicalQuantity))
26 return PhysicalQuantity(float(x) - float(self))
27
28 def __mul__(self, x):
29 return PhysicalQuantity(float(x) * float(self))
30 __rmul__ = __mul__
31
32 def __div__(self, x):
33 return PhysicalQuantity(float(self) / float(x))
34
35 def __rdiv__(self, x):
36 return PhysicalQuantity(float(x) / float(self))
37
38
39class PhysicalQuantity2(ndarray):

Callers 9

__add__Method · 0.85
__sub__Method · 0.85
__rsub__Method · 0.85
__mul__Method · 0.85
__div__Method · 0.85
__rdiv__Method · 0.85

Calls

no outgoing calls

Tested by 9

__add__Method · 0.68
__sub__Method · 0.68
__rsub__Method · 0.68
__mul__Method · 0.68
__div__Method · 0.68
__rdiv__Method · 0.68