Skip to content

Commit 5dbf6a9

Browse files
committed
fix unit test
1 parent 28d12f4 commit 5dbf6a9

4 files changed

Lines changed: 21 additions & 19 deletions

File tree

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,3 +278,5 @@ _doc/sphinxdoc/source/c_ml/*.html
278278
_unittests/ut_graph/*.prof
279279
_doc/notebooks/ml/onnxruntime*.json
280280
_doc/notebooks/ml/tree_*.onnx
281+
*.out
282+
*.err

_unittests/ut_ml/test_matrices.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def test_gram_schmidt(self):
2121

2222
mat = numpy.array([[1, 0.5], [0.5, 1]], dtype=float)
2323
res = gram_schmidt(mat)
24-
self.assertEqualArray(mat1, res @ res.T)
24+
self.assertEqualArray(mat1, res @ res.T, atol=1e-10)
2525
res2 = gram_schmidt(mat.T).T
2626

2727
res2, change2 = gram_schmidt(mat, change=True)
@@ -40,7 +40,7 @@ def test_gram_schmidt(self):
4040
mat1 = numpy.array(
4141
[[1, 0.5, 0], [0, 0.5, 1], [1, 0.5, 1]], dtype=float)
4242
res = gram_schmidt(mat1)
43-
self.assertEqualArray(numpy.identity(3), res @ res.T)
43+
self.assertEqualArray(numpy.identity(3), res @ res.T, atol=1e-10)
4444

4545
def test_gram_schmidt_xx(self):
4646
X = numpy.array([[1, 0.5, 0], [0, 0.4, 2]], dtype=float).T
@@ -49,11 +49,11 @@ def test_gram_schmidt_xx(self):
4949
T = T.T
5050
m = P.T @ X.T
5151
z = m @ m.T
52-
self.assertEqual(z, numpy.identity(2))
52+
self.assertEqualArray(z, numpy.identity(2), atol=1e-10)
5353
m = X @ P
54-
self.assertEqual(m, T)
54+
self.assertEqualArray(m, T, atol=1e-10)
5555
z2 = m.T @ m
56-
self.assertEqual(z2, numpy.identity(2))
56+
self.assertEqualArray(z2, numpy.identity(2), atol=1e-10)
5757

5858
def test_linear_regression(self):
5959
X = numpy.array([[1, 0.5, 0], [0, 0.4, 2]], dtype=float).T
@@ -118,7 +118,7 @@ def test_inner_code(self):
118118
self.assertEqual(Pt.shape, (X.shape[1], X.shape[1]))
119119
_Tt = Pt @ Xt
120120
self.assertEqualArray(_Tt, Tt)
121-
self.assertEqualArray(Tt @ Tt.T, numpy.identity(Tt.shape[0]))
121+
self.assertEqualArray(Tt @ Tt.T, numpy.identity(Tt.shape[0]), atol=1e-10)
122122

123123
beta1 = numpy.linalg.inv(Xt @ X) @ Xt @ y
124124
beta2 = Tt @ y @ Pt
@@ -140,8 +140,8 @@ def test_streaming_gram_schmidt(self):
140140
algo1_t.append(t)
141141
algo1.append(p)
142142
t_ = X[:i] @ p.T
143-
self.assertEqualArray(t @ t.T, idd)
144-
self.assertEqualArray(t_.T @ t_, idd)
143+
self.assertEqualArray(t @ t.T, idd, atol=1e-10)
144+
self.assertEqualArray(t_.T @ t_, idd, atol=1e-10)
145145
algo2 = []
146146
self.assertRaise(lambda: list(streaming_gram_schmidt(X)), # pylint: disable=W0640
147147
RuntimeError)
@@ -151,7 +151,7 @@ def test_streaming_gram_schmidt(self):
151151
algo2.append(p2)
152152
self.assertNotEmpty(t2)
153153
self.assertNotEmpty(p2)
154-
self.assertEqualArray(t2.T @ t2, idd)
154+
self.assertEqualArray(t2.T @ t2, idd, atol=1e-10)
155155
self.assertEqual(len(algo1), len(algo2))
156156

157157
def test_streaming_linear_regression(self):
@@ -210,17 +210,17 @@ def test_profile(self):
210210
res = self.profile(lambda: list(
211211
streaming_linear_regression_gram_schmidt(X, y)))
212212
if __name__ == "__main__":
213-
print(res[1])
213+
print("***", res[1])
214214
self.assertIn("streaming", res[1])
215215
res = self.profile(lambda: list(streaming_linear_regression(X, y)))
216216
if __name__ == "__main__":
217-
print(res[1])
217+
print("***", res[1])
218218
self.assertIn("streaming", res[1])
219219

220220
def test_norm2(self):
221221
X = numpy.array([[1, 0.5, 0], [0, 0.4, 2]], dtype=float).T
222222
n2 = norm2(X)
223-
print(n2)
223+
self.assertNotEmpty(n2)
224224

225225

226226
if __name__ == "__main__":

_unittests/ut_ml/test_neural_tree.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ def test_convert(self):
105105
exp = tree.predict_proba(X)
106106
got = root.predict(X)
107107
self.assertEqual(exp.shape[0], got.shape[0])
108-
self.assertEqualArray(exp, got[:, -2:])
108+
self.assertEqualArray(exp, got[:, -2:], atol=1e-10)
109109

110110
def test_dot(self):
111111
data = load_iris()
@@ -550,7 +550,7 @@ def test_convert_compact_skl(self):
550550

551551
skl = NeuralTreeNetClassifier(root)
552552
prob = skl.predict_proba(X)
553-
self.assertEqualArray(exp, prob)
553+
self.assertEqualArray(exp, prob, atol=1e-10)
554554
lab = skl.predict(X)
555555
self.assertEqual(lab.shape, (X.shape[0], ))
556556

@@ -564,7 +564,7 @@ def test_convert_compact_skl_fit(self):
564564
skl.fit(X, y)
565565
exp = tree.predict_proba(X)
566566
got = skl.predict_proba(X)
567-
self.assertEqualArray(exp, got)
567+
self.assertEqualArray(exp, got, atol=1e-10)
568568

569569
def test_convert_compact_skl_onnx(self):
570570
from mlprodict.onnx_conv import to_onnx
@@ -578,9 +578,9 @@ def test_convert_compact_skl_onnx(self):
578578
skl = NeuralTreeNetClassifier(root)
579579
got = skl.predict_proba(X)
580580
exp = tree.predict_proba(X)
581-
self.assertEqualArray(exp, got)
581+
self.assertEqualArray(exp, got, atol=1e-10)
582582
dec = root.predict(X)
583-
self.assertEqualArray(exp, dec[:, -2:])
583+
self.assertEqualArray(exp, dec[:, -2:], atol=1e-10)
584584

585585
x32 = X.astype(numpy.float32)
586586
onx = to_onnx(skl, x32, target_opset=15)
@@ -589,7 +589,7 @@ def test_convert_compact_skl_onnx(self):
589589
self.assertIn('Softmax(', text)
590590
oinf = OnnxInference(onx)
591591
got2 = oinf.run({'X': x32})['probabilities']
592-
self.assertEqualArray(exp, got2)
592+
self.assertEqualArray(exp, got2, atol=1e-10)
593593

594594
def test_convert_reg_compact(self):
595595
X = numpy.arange(32).astype(numpy.float64).reshape((-1, 2))

_unittests/ut_module/test_code_style.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""
2-
@brief test log(time=0s)
2+
@brief test log(time=100s)
33
"""
44
import os
55
import unittest

0 commit comments

Comments
 (0)