This repository has been archived by the owner on Jan 13, 2024. It is now read-only.
/
test_onnxrt_validate_2.py
49 lines (43 loc) · 1.62 KB
/
test_onnxrt_validate_2.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
"""
@brief test log(time=40s)
"""
import unittest
import numpy
from pyquickhelper.pycode import (
ExtTestCase, unittest_require_at_least
)
import skl2onnx
from mlprodict.onnxrt.validate.validate_problems import _modify_dimension
class TestOnnxrtValidate(ExtTestCase):
def test_n_features_float(self):
X = numpy.arange(20).reshape((5, 4)).astype(numpy.float64)
X2 = _modify_dimension(X, 2)
self.assertEqualArray(X[:, :2], X2)
X2 = _modify_dimension(X, None)
self.assertEqualArray(X, X2)
X2 = _modify_dimension(X, 4)
self.assertEqualArray(X, X2)
X2 = _modify_dimension(X, 6)
self.assertEqualArray(X[:, 2:4], X2[:, 2:4])
self.assertNotEqualArray(X[:, :2], X2[:, :2])
self.assertNotEqualArray(X[:, :2], X2[:, 4:6])
cor = numpy.corrcoef(X2)
for i in range(0, 2):
cor = numpy.corrcoef(X[:, i], X2[:, i])
self.assertLess(cor[0, 1], 0.9999)
@unittest_require_at_least(skl2onnx, '1.5.9999')
def test_n_features_int(self):
X = numpy.arange(20).reshape((5, 4)).astype(numpy.int64)
X2 = _modify_dimension(X, 2)
self.assertEqualArray(X[:, :2], X2)
X2 = _modify_dimension(X, None)
self.assertEqualArray(X, X2)
X2 = _modify_dimension(X, 4)
self.assertEqualArray(X, X2)
X2 = _modify_dimension(X, 6)
self.assertEqualArray(X[:, 2:4], X2[:, 2:4])
self.assertNotEqualArray(X[:, :2], X2[:, :2])
self.assertNotEqualArray(X[:, :2], X2[:, 4:6])
if __name__ == "__main__":
# TestOnnxrtValidate().test_n_features_int()
unittest.main()