metrolopy 0.6.3__tar.gz → 0.6.5__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {metrolopy-0.6.3 → metrolopy-0.6.5}/PKG-INFO +19 -7
- {metrolopy-0.6.3 → metrolopy-0.6.5}/metrolopy/budget.py +1 -1
- {metrolopy-0.6.3 → metrolopy-0.6.5}/metrolopy/dfunc.py +4 -1
- {metrolopy-0.6.3 → metrolopy-0.6.5}/metrolopy/distributions.py +1 -1
- {metrolopy-0.6.3 → metrolopy-0.6.5}/metrolopy/fit.py +3 -3
- {metrolopy-0.6.3 → metrolopy-0.6.5}/metrolopy/gummy.py +10 -9
- {metrolopy-0.6.3 → metrolopy-0.6.5}/metrolopy/tests/__init__.py +0 -2
- metrolopy-0.6.5/metrolopy/tests/test_complex.py +227 -0
- metrolopy-0.6.5/metrolopy/tests/test_create.py +390 -0
- metrolopy-0.6.5/metrolopy/tests/test_gummy.py +670 -0
- metrolopy-0.6.5/metrolopy/tests/test_misc.py +127 -0
- metrolopy-0.6.5/metrolopy/tests/test_operations.py +379 -0
- metrolopy-0.6.5/metrolopy/tests/test_ubreakdown.py +374 -0
- {metrolopy-0.6.3 → metrolopy-0.6.5}/metrolopy/unitparser.py +2 -2
- {metrolopy-0.6.3 → metrolopy-0.6.5}/metrolopy/version.py +2 -2
- {metrolopy-0.6.3 → metrolopy-0.6.5}/metrolopy.egg-info/PKG-INFO +19 -7
- metrolopy-0.6.3/metrolopy/tests/test_complex.py +0 -222
- metrolopy-0.6.3/metrolopy/tests/test_create.py +0 -386
- metrolopy-0.6.3/metrolopy/tests/test_gummy.py +0 -668
- metrolopy-0.6.3/metrolopy/tests/test_misc.py +0 -113
- metrolopy-0.6.3/metrolopy/tests/test_operations.py +0 -372
- metrolopy-0.6.3/metrolopy/tests/test_ubreakdown.py +0 -349
- {metrolopy-0.6.3 → metrolopy-0.6.5}/LICENSE +0 -0
- {metrolopy-0.6.3 → metrolopy-0.6.5}/README.md +0 -0
- {metrolopy-0.6.3 → metrolopy-0.6.5}/metrolopy/__init__.py +0 -0
- {metrolopy-0.6.3 → metrolopy-0.6.5}/metrolopy/codata2018.py +0 -0
- {metrolopy-0.6.3 → metrolopy-0.6.5}/metrolopy/constant.py +0 -0
- {metrolopy-0.6.3 → metrolopy-0.6.5}/metrolopy/constcom.py +0 -0
- {metrolopy-0.6.3 → metrolopy-0.6.5}/metrolopy/exceptions.py +0 -0
- {metrolopy-0.6.3 → metrolopy-0.6.5}/metrolopy/functions.py +0 -0
- {metrolopy-0.6.3 → metrolopy-0.6.5}/metrolopy/indexed.py +0 -0
- {metrolopy-0.6.3 → metrolopy-0.6.5}/metrolopy/license.txt +0 -0
- {metrolopy-0.6.3 → metrolopy-0.6.5}/metrolopy/logunit.py +0 -0
- {metrolopy-0.6.3 → metrolopy-0.6.5}/metrolopy/mean.py +0 -0
- {metrolopy-0.6.3 → metrolopy-0.6.5}/metrolopy/miscunits.py +0 -0
- {metrolopy-0.6.3 → metrolopy-0.6.5}/metrolopy/nonlinearunit.py +0 -0
- {metrolopy-0.6.3 → metrolopy-0.6.5}/metrolopy/nummy.py +0 -0
- {metrolopy-0.6.3 → metrolopy-0.6.5}/metrolopy/offsetunit.py +0 -0
- {metrolopy-0.6.3 → metrolopy-0.6.5}/metrolopy/pmethod.py +0 -0
- {metrolopy-0.6.3 → metrolopy-0.6.5}/metrolopy/prefixedunit.py +0 -0
- {metrolopy-0.6.3 → metrolopy-0.6.5}/metrolopy/printing.py +0 -0
- {metrolopy-0.6.3 → metrolopy-0.6.5}/metrolopy/relunits.py +0 -0
- {metrolopy-0.6.3 → metrolopy-0.6.5}/metrolopy/siunits.py +0 -0
- {metrolopy-0.6.3 → metrolopy-0.6.5}/metrolopy/tests/common.py +0 -0
- {metrolopy-0.6.3 → metrolopy-0.6.5}/metrolopy/ummy.py +0 -0
- {metrolopy-0.6.3 → metrolopy-0.6.5}/metrolopy/unit.py +0 -0
- {metrolopy-0.6.3 → metrolopy-0.6.5}/metrolopy/unitutils.py +0 -0
- {metrolopy-0.6.3 → metrolopy-0.6.5}/metrolopy/usunits.py +0 -0
- {metrolopy-0.6.3 → metrolopy-0.6.5}/metrolopy.egg-info/SOURCES.txt +0 -0
- {metrolopy-0.6.3 → metrolopy-0.6.5}/metrolopy.egg-info/dependency_links.txt +0 -0
- {metrolopy-0.6.3 → metrolopy-0.6.5}/metrolopy.egg-info/requires.txt +0 -0
- {metrolopy-0.6.3 → metrolopy-0.6.5}/metrolopy.egg-info/top_level.txt +0 -0
- {metrolopy-0.6.3 → metrolopy-0.6.5}/metrolopy.egg-info/zip-safe +0 -0
- {metrolopy-0.6.3 → metrolopy-0.6.5}/setup.cfg +0 -0
- {metrolopy-0.6.3 → metrolopy-0.6.5}/setup.py +0 -0
|
@@ -1,12 +1,10 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
2
|
Name: metrolopy
|
|
3
|
-
Version: 0.6.
|
|
3
|
+
Version: 0.6.5
|
|
4
4
|
Summary: tools for dealing with measured quantities: uncertainty propagation and unit conversion
|
|
5
5
|
Home-page: http://nrc-cnrc.github.io/MetroloPy/
|
|
6
6
|
Author: Harold Parks, National Research Council Canada
|
|
7
7
|
Author-email: parksh@nrc.ca
|
|
8
|
-
License: UNKNOWN
|
|
9
|
-
Platform: UNKNOWN
|
|
10
8
|
Classifier: Programming Language :: Python :: 3
|
|
11
9
|
Classifier: Operating System :: OS Independent
|
|
12
10
|
Classifier: Development Status :: 4 - Beta
|
|
@@ -18,8 +16,24 @@ Classifier: Intended Audience :: Education
|
|
|
18
16
|
Classifier: Topic :: Scientific/Engineering :: Physics
|
|
19
17
|
Requires-Python: >=3.5
|
|
20
18
|
Description-Content-Type: text/markdown
|
|
21
|
-
Provides-Extra: pretty
|
|
22
19
|
License-File: LICENSE
|
|
20
|
+
Requires-Dist: numpy>=1.13
|
|
21
|
+
Requires-Dist: scipy
|
|
22
|
+
Requires-Dist: matplotlib
|
|
23
|
+
Requires-Dist: pandas
|
|
24
|
+
Provides-Extra: pretty
|
|
25
|
+
Requires-Dist: IPython; extra == "pretty"
|
|
26
|
+
Dynamic: author
|
|
27
|
+
Dynamic: author-email
|
|
28
|
+
Dynamic: classifier
|
|
29
|
+
Dynamic: description
|
|
30
|
+
Dynamic: description-content-type
|
|
31
|
+
Dynamic: home-page
|
|
32
|
+
Dynamic: license-file
|
|
33
|
+
Dynamic: provides-extra
|
|
34
|
+
Dynamic: requires-dist
|
|
35
|
+
Dynamic: requires-python
|
|
36
|
+
Dynamic: summary
|
|
23
37
|
|
|
24
38
|
# MetroloPy
|
|
25
39
|
|
|
@@ -86,5 +100,3 @@ MetroloPy can do much more including Monte-Carlo uncertainty propagation, genera
|
|
|
86
100
|
|
|
87
101
|
|
|
88
102
|
|
|
89
|
-
|
|
90
|
-
|
|
@@ -121,7 +121,6 @@ ddict = {np.sin: np.cos,
|
|
|
121
121
|
|
|
122
122
|
fdict = {np.angle: lambda x: x.angle(),
|
|
123
123
|
np.around: _f_around,
|
|
124
|
-
np.round_: _f_around,
|
|
125
124
|
np.heaviside: _f_heaviside,
|
|
126
125
|
np.absolute: lambda x: abs(x),
|
|
127
126
|
np.add: _f_add,
|
|
@@ -154,6 +153,10 @@ fdict = {np.angle: lambda x: x.angle(),
|
|
|
154
153
|
np.isneginf: lambda x: np.isneginf(x.x),
|
|
155
154
|
np.isposinf: lambda x: np.isposinf(x.x)
|
|
156
155
|
}
|
|
156
|
+
if np.lib.NumpyVersion(np.__version__) >= '1.25.0':
|
|
157
|
+
fdict[np.round] = _f_around
|
|
158
|
+
else:
|
|
159
|
+
fdict[np.round_] = _f_around
|
|
157
160
|
|
|
158
161
|
|
|
159
162
|
try_fconvert = True
|
|
@@ -920,7 +920,7 @@ class UniformDist(Distribution):
|
|
|
920
920
|
if lower_limit >= upper_limit:
|
|
921
921
|
raise ValueError('lower_limit >= upper_limit')
|
|
922
922
|
self.center = (upper_limit + lower_limit)/2
|
|
923
|
-
self.half_width = upper_limit - lower_limit
|
|
923
|
+
self.half_width = (upper_limit - lower_limit)/2
|
|
924
924
|
if upper_limit is not None:
|
|
925
925
|
k += 1
|
|
926
926
|
self.upper_limit = upper_limit
|
|
@@ -415,7 +415,7 @@ class _Fit:
|
|
|
415
415
|
s = self.s
|
|
416
416
|
else:
|
|
417
417
|
s = self.sigma
|
|
418
|
-
return k*(np.sqrt(self.ypred(x).u + s**2))
|
|
418
|
+
return k*(np.sqrt(self.ypred(x).u**2 + s**2))
|
|
419
419
|
|
|
420
420
|
|
|
421
421
|
class Fit(_Fit,PrettyPrinter):
|
|
@@ -2017,7 +2017,7 @@ class DoubleExpFit(Fit):
|
|
|
2017
2017
|
return 'y = p(1)*exp(-x/p(2)) + p(3)*exp(-x/p(4)) + p(5)'
|
|
2018
2018
|
|
|
2019
2019
|
def flatex(self):
|
|
2020
|
-
return '$ y = p_{1}
|
|
2020
|
+
return '$ y = p_{1}\\exp(-x/p_{2}) + p_{3}\\exp(-x/p_{4}) + p_{5} $'
|
|
2021
2021
|
|
|
2022
2022
|
def fhtml(self):
|
|
2023
2023
|
return '<i>y</i> = <i>p</i><sub>1</sub> exp(-<i>x</i>/<i>p</i><sub>2</sub>) + <i>p</i><sub>3</sub> exp(-<i>x</i>/<i>p</i><sub>4</sub>) + <i>p</i><sub>5</sub>'
|
|
@@ -2160,7 +2160,7 @@ class ExpFit(Fit):
|
|
|
2160
2160
|
return 'y = p(1)*exp(x/p(2)) + p(3)'
|
|
2161
2161
|
|
|
2162
2162
|
def flatex(self):
|
|
2163
|
-
return '$ y = p_{1}
|
|
2163
|
+
return '$ y = p_{1}\\exp(x/p_{2}) + p_{3} $'
|
|
2164
2164
|
|
|
2165
2165
|
def fhtml(self):
|
|
2166
2166
|
return '<i>y</i> = <i>p</i><sub>1</sub> exp(<i>x</i>/<i>p</i><sub>2</sub>) + <i>p</i><sub>3</sub>'
|
|
@@ -1695,13 +1695,11 @@ class gummy(Quantity,metaclass=MetaGummy):
|
|
|
1695
1695
|
else:
|
|
1696
1696
|
slashaxis = gummy.slashaxis
|
|
1697
1697
|
|
|
1698
|
-
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
else:
|
|
1704
|
-
name = g
|
|
1698
|
+
try:
|
|
1699
|
+
name = g.name
|
|
1700
|
+
except:
|
|
1701
|
+
name = None
|
|
1702
|
+
|
|
1705
1703
|
if name == '':
|
|
1706
1704
|
name = None
|
|
1707
1705
|
|
|
@@ -1721,7 +1719,10 @@ class gummy(Quantity,metaclass=MetaGummy):
|
|
|
1721
1719
|
name = str(name).replace(' ','\\,').strip()
|
|
1722
1720
|
xl += norm(name)
|
|
1723
1721
|
else:
|
|
1724
|
-
|
|
1722
|
+
try:
|
|
1723
|
+
xl += name.tolatex()
|
|
1724
|
+
except:
|
|
1725
|
+
xl += str(name).strip()
|
|
1725
1726
|
if symbol is not None:
|
|
1726
1727
|
if xl != '':
|
|
1727
1728
|
if slashaxis:
|
|
@@ -2861,7 +2862,7 @@ class gummy(Quantity,metaclass=MetaGummy):
|
|
|
2861
2862
|
return '{:.4f}'.format(x) + pct
|
|
2862
2863
|
if x < 99.9999:
|
|
2863
2864
|
return '{:.5f}'.format(x) + pct
|
|
2864
|
-
return str(x) +
|
|
2865
|
+
return str(x) + pct
|
|
2865
2866
|
|
|
2866
2867
|
@staticmethod
|
|
2867
2868
|
def _k_to_str(k):
|
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
|
|
3
|
+
# module test_complex
|
|
4
|
+
|
|
5
|
+
# Copyright (C) 2019 National Research Council Canada
|
|
6
|
+
# Author: Harold Parks
|
|
7
|
+
|
|
8
|
+
# This file is part of MetroloPy.
|
|
9
|
+
|
|
10
|
+
# MetroloPy is free software: you can redistribute it and/or modify it under
|
|
11
|
+
# the terms of the GNU General Public License as published by the Free Software
|
|
12
|
+
# Foundation, either version 3 of the License, or (at your option) any later
|
|
13
|
+
# version.
|
|
14
|
+
|
|
15
|
+
# MetroloPy is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
16
|
+
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
17
|
+
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
|
18
|
+
# details.
|
|
19
|
+
|
|
20
|
+
# You should have received a copy of the GNU General Public License along with
|
|
21
|
+
# MetroloPy. If not, see <http://www.gnu.org/licenses/>.
|
|
22
|
+
|
|
23
|
+
import numpy as np
|
|
24
|
+
import unittest
|
|
25
|
+
from metrolopy import immy,ummy,jummy,gummy
|
|
26
|
+
from metrolopy.tests.common import display
|
|
27
|
+
|
|
28
|
+
rand = np.random.RandomState()
|
|
29
|
+
|
|
30
|
+
def make_immy(prnt=False):
|
|
31
|
+
if rand.randint(2):
|
|
32
|
+
imake = immy
|
|
33
|
+
make = ummy
|
|
34
|
+
else:
|
|
35
|
+
imake = jummy
|
|
36
|
+
make = gummy
|
|
37
|
+
r = 4*rand.rand() + 1
|
|
38
|
+
if rand.randint(2):
|
|
39
|
+
r = -r
|
|
40
|
+
ru = (0.1*rand.rand() + 0.01)*(abs(r))
|
|
41
|
+
i = 4*rand.rand() + 1
|
|
42
|
+
if rand.randint(2):
|
|
43
|
+
i = -i
|
|
44
|
+
iu = (0.1*rand.rand() + 0.01)*(abs(i))
|
|
45
|
+
c = (2*rand.rand() - 1)*ru*iu
|
|
46
|
+
|
|
47
|
+
cov = [[ru**2,c],[c,iu**2]]
|
|
48
|
+
real,imag = make.create([r,i],covariance_matrix=cov)
|
|
49
|
+
|
|
50
|
+
if rand.randint(2):
|
|
51
|
+
ret = imake(real=real,imag=imag)
|
|
52
|
+
else:
|
|
53
|
+
if rand.randint(2):
|
|
54
|
+
ret = imake(real=r,imag=i,cov=cov)
|
|
55
|
+
assert abs(ret.real.covariance(ret.imag) - cov[0][1]) < 1e-6
|
|
56
|
+
if imake is immy:
|
|
57
|
+
real._ref = ret.real._ref
|
|
58
|
+
imag._ref = ret.imag._ref
|
|
59
|
+
else:
|
|
60
|
+
real.value._ref = ret.real.value._ref
|
|
61
|
+
imag.value._ref = ret.imag.value._ref
|
|
62
|
+
else:
|
|
63
|
+
r = np.sqrt(real**2 + imag**2)
|
|
64
|
+
phi = np.arctan2(imag,real)
|
|
65
|
+
ret = imake(r=r.x,phi=phi.x,cov=make.covariance_matrix([r,phi]))
|
|
66
|
+
assert abs(ret.real.covariance(ret.imag) - cov[0][1]) < 1e-6
|
|
67
|
+
if imake is immy:
|
|
68
|
+
real._ref = ret.real._ref
|
|
69
|
+
imag._ref = ret.imag._ref
|
|
70
|
+
else:
|
|
71
|
+
real.value._ref = ret.real.value._ref
|
|
72
|
+
imag.value._ref = ret.imag.value._ref
|
|
73
|
+
|
|
74
|
+
if prnt:
|
|
75
|
+
display(ret)
|
|
76
|
+
|
|
77
|
+
return (ret,real,imag)
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
class TestComplex(unittest.TestCase):
|
|
81
|
+
def assert_ummy_close(self,u1,u2):
|
|
82
|
+
self.assertTrue(abs(u1.correlation(u2)) > 1 - 1e-4)
|
|
83
|
+
u1x = max(u1.x,u1.u,u2.x,u2.u)
|
|
84
|
+
self.assertTrue(abs((u1.x - u2.x)/(u1x)) < 1e-10)
|
|
85
|
+
self.assertTrue(abs((u1.u - u2.u)/(u1.u)) < 1e-2)
|
|
86
|
+
|
|
87
|
+
if u1.dof == float('inf'):
|
|
88
|
+
self.assertTrue(u2.dof == float('inf'))
|
|
89
|
+
else:
|
|
90
|
+
self.assertTrue(abs((u2.dof - u1.dof)/u1.dof) < 1e-2)
|
|
91
|
+
|
|
92
|
+
def assert_immy_close(self,i1,i2):
|
|
93
|
+
self.assert_ummy_close(i1.real,i2.real)
|
|
94
|
+
self.assert_ummy_close(i1.imag,i2.imag)
|
|
95
|
+
|
|
96
|
+
def test_immy_init(self,n=1000,prnt=False):
|
|
97
|
+
for m in range(n):
|
|
98
|
+
x,xr,xi = make_immy(prnt=prnt)
|
|
99
|
+
|
|
100
|
+
if rand.randint(2):
|
|
101
|
+
if rand.randint(2):
|
|
102
|
+
x = type(x)(x)
|
|
103
|
+
else:
|
|
104
|
+
x = x.copy(formatting=False)
|
|
105
|
+
|
|
106
|
+
self.assert_ummy_close(x.real,xr)
|
|
107
|
+
self.assert_ummy_close(x.imag,xi)
|
|
108
|
+
self.assert_ummy_close(x.angle(),np.arctan2(xi,xr))
|
|
109
|
+
self.assert_ummy_close(abs(x),np.sqrt(xr**2 + xi**2))
|
|
110
|
+
self.assert_immy_close(x.conjugate(),immy(real=xr,imag=-xi))
|
|
111
|
+
self.assert_immy_close(-x,immy(real=-xr,imag=-xi))
|
|
112
|
+
self.assert_immy_close(+x,immy(real=xr,imag=xi))
|
|
113
|
+
|
|
114
|
+
if prnt:
|
|
115
|
+
if rand.randint(2):
|
|
116
|
+
y =1e12*x
|
|
117
|
+
else:
|
|
118
|
+
y = x/1e12
|
|
119
|
+
display(y)
|
|
120
|
+
|
|
121
|
+
def _test_immy_bop(self,f,nf,n=1000,prnt=False,allow_small=True):
|
|
122
|
+
m = 0
|
|
123
|
+
while m < n:
|
|
124
|
+
a,ar,ai = make_immy()
|
|
125
|
+
if True:#rand.randint(2):
|
|
126
|
+
b,br,bi = make_immy()
|
|
127
|
+
else:
|
|
128
|
+
if rand.randint(2):
|
|
129
|
+
b = 4*rand.rand() + 1
|
|
130
|
+
if rand.randint(2):
|
|
131
|
+
b = -b
|
|
132
|
+
if rand.randint(2):
|
|
133
|
+
bu = (0.1*rand.rand()+0.01)*(abs(b))
|
|
134
|
+
b = ummy(b,u=bu)
|
|
135
|
+
else:
|
|
136
|
+
br = 4*rand.rand() + 1
|
|
137
|
+
if rand.randint(2):
|
|
138
|
+
br = -br
|
|
139
|
+
bi = 4*rand.rand() + 1
|
|
140
|
+
if rand.randint(2):
|
|
141
|
+
bi = -bi
|
|
142
|
+
b = complex(br,bi)
|
|
143
|
+
if rand.randint(2):
|
|
144
|
+
bb = b
|
|
145
|
+
b = a
|
|
146
|
+
a = bb
|
|
147
|
+
|
|
148
|
+
if isinstance(a,(immy,ummy)):
|
|
149
|
+
ax = a.x
|
|
150
|
+
else:
|
|
151
|
+
ax = a
|
|
152
|
+
if isinstance(b,(immy,ummy)):
|
|
153
|
+
bx = b.x
|
|
154
|
+
else:
|
|
155
|
+
bx = b
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
cx = f(ax,bx)
|
|
159
|
+
|
|
160
|
+
if allow_small or abs(cx) > 0.1:
|
|
161
|
+
m +=1
|
|
162
|
+
|
|
163
|
+
c = f(a,b)
|
|
164
|
+
cn = type(c).napply(nf,a,b)
|
|
165
|
+
|
|
166
|
+
if prnt:
|
|
167
|
+
display(a)
|
|
168
|
+
display(b)
|
|
169
|
+
display(c)
|
|
170
|
+
display(cn)
|
|
171
|
+
print('---')
|
|
172
|
+
|
|
173
|
+
self.assertTrue(abs((c.real.x - cx.real)/cx.real) < 1e-10)
|
|
174
|
+
self.assertTrue(abs((c.imag.x - cx.imag)/cx.imag) < 1e-10)
|
|
175
|
+
self.assert_immy_close(c,cn)
|
|
176
|
+
|
|
177
|
+
def test_immy_add(self,n=1000,prnt=False):
|
|
178
|
+
self._test_immy_bop(lambda a,b: a + b,np.add,n,prnt)
|
|
179
|
+
|
|
180
|
+
for m in range(10):
|
|
181
|
+
i = make_immy()[0]
|
|
182
|
+
self.assertTrue(i + 0 == i)
|
|
183
|
+
self.assertTrue(0 + i == i)
|
|
184
|
+
|
|
185
|
+
def test_immy_sub(self,n=1000,prnt=False):
|
|
186
|
+
self._test_immy_bop(lambda a,b: a - b,np.subtract,n,prnt)
|
|
187
|
+
|
|
188
|
+
for m in range(10):
|
|
189
|
+
i = make_immy()[0]
|
|
190
|
+
self.assertTrue(i - 0 == i)
|
|
191
|
+
self.assertTrue(0 - i == -i)
|
|
192
|
+
|
|
193
|
+
def test_immy_mul(self,n=1000,prnt=False):
|
|
194
|
+
self._test_immy_bop(lambda a,b: a*b,np.multiply,n,prnt)
|
|
195
|
+
|
|
196
|
+
for m in range(10):
|
|
197
|
+
i = make_immy()[0]
|
|
198
|
+
self.assertTrue(i*0 == 0)
|
|
199
|
+
self.assertTrue(i*immy(0) == 0)
|
|
200
|
+
self.assertTrue(i*1 == i)
|
|
201
|
+
self.assertTrue(i*immy(1) == i)
|
|
202
|
+
self.assertTrue(1*i == i)
|
|
203
|
+
self.assertTrue(immy(1)*i == i)
|
|
204
|
+
|
|
205
|
+
def test_immy_div(self,n=1000,prnt=False):
|
|
206
|
+
self._test_immy_bop(lambda a,b: a/b,np.divide,n,prnt,allow_small=False)
|
|
207
|
+
|
|
208
|
+
for m in range(10):
|
|
209
|
+
i = make_immy()[0]
|
|
210
|
+
self.assertTrue(i/1 == i)
|
|
211
|
+
|
|
212
|
+
def test_immy_pow(self,n=1000,prnt=False):
|
|
213
|
+
#_test_immy_bop(lambda a,b: a**b,np.power,n,prnt,allow_small=False)
|
|
214
|
+
|
|
215
|
+
for m in range(10):
|
|
216
|
+
i = make_immy()[0]
|
|
217
|
+
self.assertTrue(0**i == immy(0))
|
|
218
|
+
self.assertTrue(0**i == ummy(0))
|
|
219
|
+
self.assertTrue(0**i == 0)
|
|
220
|
+
self.assertTrue(i**0 == 1)
|
|
221
|
+
|
|
222
|
+
self.assert_immy_close(i**-1,1/i)
|
|
223
|
+
self.assert_immy_close(i**2,i*i)
|
|
224
|
+
self.assert_immy_close(i**3,i*i*i)
|
|
225
|
+
|
|
226
|
+
if __name__ == '__main__':
|
|
227
|
+
unittest.main()
|