This repository has been archived by the owner on Jan 13, 2024. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
49 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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() |