From f4a802aba5883f464030ed87568b33dfc979781f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?xavier=20dupr=C3=A9?= Date: Thu, 3 Feb 2022 15:46:27 +0100 Subject: [PATCH 1/2] Adds a method to_onnx to easily retrieve the onnx graph from numpy onnx function --- _unittests/ut_npy/test_onnx_variable.py | 383 ++++++++++-------- _unittests/ut_npy/test_onnx_variable_ort.py | 310 +++++++------- _unittests/ut_npy/test_onnx_variable_tuple.py | 18 +- _unittests/ut_npy/test_wrappers.py | 2 +- mlprodict/npy/onnx_numpy_compiler.py | 17 + mlprodict/npy/onnx_numpy_wrapper.py | 48 +++ mlprodict/npy/onnx_version.py | 2 +- 7 files changed, 441 insertions(+), 339 deletions(-) diff --git a/_unittests/ut_npy/test_onnx_variable.py b/_unittests/ut_npy/test_onnx_variable.py index 852f518ee..1c885a843 100644 --- a/_unittests/ut_npy/test_onnx_variable.py +++ b/_unittests/ut_npy/test_onnx_variable.py @@ -8,6 +8,7 @@ from pyquickhelper.pycode import ExtTestCase, ignore_warnings from mlprodict.npy import onnxnumpy, onnxnumpy_default, onnxnumpy_np import mlprodict.npy.numpy_onnx_impl as nxnp +from mlprodict.npy.onnx_version import FctVersion from mlprodict.npy import ( OnnxNumpyCompiler as ONC, NDArray, NDArraySameTypeSameShape) @@ -24,331 +25,331 @@ def get_bool(unused): @onnxnumpy_default -def test_abs(x: NDArray[Any, numpy.float32], - ) -> NDArray[Any, numpy.float32]: +def otest_abs(x: NDArray[Any, numpy.float32], + ) -> NDArray[Any, numpy.float32]: "onnx numpy abs" return nxnp.abs(x) @onnxnumpy_default -def test_abs_abs(x: NDArray[Any, numpy.float32], - ) -> NDArray[Any, numpy.float32]: +def otest_abs_abs(x: NDArray[Any, numpy.float32], + ) -> NDArray[Any, numpy.float32]: "onnx numpy abs abs" return nxnp.abs(nxnp.abs(x)) @onnxnumpy_default -def test_abs_add(x: NDArray[Any, numpy.float32], - ) -> NDArray[Any, numpy.float32]: +def otest_abs_add(x: NDArray[Any, numpy.float32], + ) -> NDArray[Any, numpy.float32]: "onnx numpy addition" return nxnp.abs(x) + x @onnxnumpy_default -def test_abs_add4(x: NDArray[Any, numpy.float32], - ) -> NDArray[Any, numpy.float32]: +def otest_abs_add4(x: NDArray[Any, numpy.float32], + ) -> NDArray[Any, numpy.float32]: "onnx numpy addition" x2 = x + x return x2 + x2 @onnxnumpy_default -def test_abs_addm(x1: NDArray[Any, numpy.float32], - x2: NDArray[Any, numpy.float32] - ) -> NDArray[Any, numpy.float32]: +def otest_abs_addm(x1: NDArray[Any, numpy.float32], + x2: NDArray[Any, numpy.float32] + ) -> NDArray[Any, numpy.float32]: "onnx numpy addition" return nxnp.abs(x1) + x2 @onnxnumpy_default -def test_abs_add2(x: NDArray[Any, numpy.float32], - ) -> NDArray[Any, numpy.float32]: +def otest_abs_add2(x: NDArray[Any, numpy.float32], + ) -> NDArray[Any, numpy.float32]: "onnx numpy addition" return nxnp.abs(x) + numpy.float32(2) @onnxnumpy_default -def test_abs_sub(x: NDArray[Any, numpy.float32], - ) -> NDArray[Any, numpy.float32]: +def otest_abs_sub(x: NDArray[Any, numpy.float32], + ) -> NDArray[Any, numpy.float32]: "onnx numpy addition" return nxnp.abs(x) - x @onnxnumpy_default -def test_abs_mul(x: NDArray[Any, numpy.float32], - ) -> NDArray[Any, numpy.float32]: +def otest_abs_mul(x: NDArray[Any, numpy.float32], + ) -> NDArray[Any, numpy.float32]: "onnx numpy addition" return nxnp.abs(x) * x @onnxnumpy_default -def test_abs_pow(x: NDArray[Any, numpy.float32], - ) -> NDArray[Any, numpy.float32]: +def otest_abs_pow(x: NDArray[Any, numpy.float32], + ) -> NDArray[Any, numpy.float32]: "onnx numpy power" return nxnp.abs(x) ** numpy.float32(2) @onnxnumpy_default -def test_abs_mod(x: NDArray[Any, numpy.float32], - ) -> NDArray[Any, numpy.float32]: +def otest_abs_mod(x: NDArray[Any, numpy.float32], + ) -> NDArray[Any, numpy.float32]: "onnx numpy modulo" return nxnp.abs(x) % numpy.float32(2) @onnxnumpy_default -def test_abs_matmul(x: NDArray[Any, numpy.float32], - ) -> NDArray[Any, numpy.float32]: +def otest_abs_matmul(x: NDArray[Any, numpy.float32], + ) -> NDArray[Any, numpy.float32]: "onnx numpy addition" return nxnp.abs(x) @ x @onnxnumpy_default -def test_abs_matmul2(x: NDArray[Any, numpy.float32], - ) -> NDArray[Any, numpy.float32]: +def otest_abs_matmul2(x: NDArray[Any, numpy.float32], + ) -> NDArray[Any, numpy.float32]: "onnx numpy addition" return nxnp.matmul(nxnp.abs(x), x) @onnxnumpy_default -def test_abs_div(x: NDArray[Any, numpy.float32], - ) -> NDArray[Any, numpy.float32]: +def otest_abs_div(x: NDArray[Any, numpy.float32], + ) -> NDArray[Any, numpy.float32]: "onnx numpy division" return nxnp.abs(x) / x @onnxnumpy_default -def test_abs_idiv(x: NDArray[Any, numpy.float32], - ) -> NDArray[Any, numpy.int64]: +def otest_abs_idiv(x: NDArray[Any, numpy.float32], + ) -> NDArray[Any, numpy.int64]: "onnx numpy int division" return nxnp.abs(x).astype(numpy.int64) // x.astype(numpy.int64) @onnxnumpy_default -def test_abs_equal(x: NDArray[Any, numpy.float32], - ) -> NDArray[Any, numpy_bool]: +def otest_abs_equal(x: NDArray[Any, numpy.float32], + ) -> NDArray[Any, numpy_bool]: "onnx numpy equality" return nxnp.abs(x) == x @onnxnumpy_default -def test_abs_not_equal(x: NDArray[Any, numpy.float32], - ) -> NDArray[Any, numpy_bool]: +def otest_abs_not_equal(x: NDArray[Any, numpy.float32], + ) -> NDArray[Any, numpy_bool]: "onnx numpy inequality" return nxnp.abs(x) != x @onnxnumpy_default -def test_abs_greater(x: NDArray[Any, numpy.float32], - ) -> NDArray[Any, numpy_bool]: +def otest_abs_greater(x: NDArray[Any, numpy.float32], + ) -> NDArray[Any, numpy_bool]: "onnx numpy greater" return nxnp.abs(x) > x @onnxnumpy_default -def test_abs_greater_or_equal(x: NDArray[Any, numpy.float32], - ) -> NDArray[Any, numpy_bool]: +def otest_abs_greater_or_equal(x: NDArray[Any, numpy.float32], + ) -> NDArray[Any, numpy_bool]: "onnx numpy greater or equal" return nxnp.abs(x) >= x @onnxnumpy_default -def test_abs_less(x: NDArray[Any, numpy.float32], - ) -> NDArray[Any, numpy_bool]: +def otest_abs_less(x: NDArray[Any, numpy.float32], + ) -> NDArray[Any, numpy_bool]: "onnx numpy less" return nxnp.abs(x) < x @onnxnumpy_default -def test_abs_less_or_equal(x: NDArray[Any, numpy.float32], - ) -> NDArray[Any, numpy_bool]: +def otest_abs_less_or_equal(x: NDArray[Any, numpy.float32], + ) -> NDArray[Any, numpy_bool]: "onnx numpy less or equal" return nxnp.abs(x) <= x @onnxnumpy_default -def test_abs_and(x: NDArray[Any, numpy.float32], - ) -> NDArray[Any, numpy_bool]: +def otest_abs_and(x: NDArray[Any, numpy.float32], + ) -> NDArray[Any, numpy_bool]: "onnx numpy and" return (nxnp.abs(x) < x) and (nxnp.abs(x) < numpy.float32(0)) @onnxnumpy_default -def test_abs_and2(x: NDArray[Any, numpy.float32], - ) -> NDArray[Any, numpy_bool]: +def otest_abs_and2(x: NDArray[Any, numpy.float32], + ) -> NDArray[Any, numpy_bool]: "onnx numpy and" return (nxnp.abs(x) < x) & (nxnp.abs(x) < numpy.float32(0)) @onnxnumpy_default -def test_abs_or(x: NDArray[Any, numpy.float32], - ) -> NDArray[Any, numpy_bool]: +def otest_abs_or(x: NDArray[Any, numpy.float32], + ) -> NDArray[Any, numpy_bool]: "onnx numpy or" return (nxnp.abs(x) < x) or (nxnp.abs(x) < numpy.float32(0)) @onnxnumpy_default -def test_abs_or2(x: NDArray[Any, numpy.float32], - ) -> NDArray[Any, numpy_bool]: +def otest_abs_or2(x: NDArray[Any, numpy.float32], + ) -> NDArray[Any, numpy_bool]: "onnx numpy or" return (nxnp.abs(x) < x) | (nxnp.abs(x) < numpy.float32(0)) @onnxnumpy_default -def test_abs_sum1(x: NDArray[Any, numpy.float32], - ) -> NDArray[Any, numpy.float32]: +def otest_abs_sum1(x: NDArray[Any, numpy.float32], + ) -> NDArray[Any, numpy.float32]: "onnx numpy sum" return nxnp.sum(nxnp.abs(x), axis=0) @onnxnumpy_default -def test_abs_sum2(x: NDArray[Any, numpy.float32], - ) -> NDArray[Any, numpy.float32]: +def otest_abs_sum2(x: NDArray[Any, numpy.float32], + ) -> NDArray[Any, numpy.float32]: "onnx numpy sum" return nxnp.sum(nxnp.abs(x), axis=1, keepdims=1) @onnxnumpy_default -def test_abs_transpose_t(x: NDArray[Any, numpy.float32], - ) -> NDArray[Any, numpy.float32]: +def otest_abs_transpose_t(x: NDArray[Any, numpy.float32], + ) -> NDArray[Any, numpy.float32]: "onnx numpy transpose T" return nxnp.abs(x).T @onnxnumpy_default -def test_abs_cast(x: NDArray[Any, numpy.float32], - ) -> NDArray[Any, numpy.int64]: +def otest_abs_cast(x: NDArray[Any, numpy.float32], + ) -> NDArray[Any, numpy.int64]: "onnx numpy cast" return nxnp.abs(x).astype(numpy.int64) @onnxnumpy_default -def test_abs_reshape(x: NDArray[Any, numpy.float32], - ) -> NDArray[Any, numpy.float32]: +def otest_abs_reshape(x: NDArray[Any, numpy.float32], + ) -> NDArray[Any, numpy.float32]: "onnx numpy reshape" return nxnp.abs(x).reshape((-1, 1)) @onnxnumpy(op_version=11) -def test_abs_reshape_11(x: NDArray[Any, numpy.float32], - ) -> NDArray[Any, numpy.float32]: +def otest_abs_reshape_11(x: NDArray[Any, numpy.float32], + ) -> NDArray[Any, numpy.float32]: "onnx numpy reshape with opset 11" return nxnp.abs(x).reshape((-1, 1)) @onnxnumpy_default -def test_abs_slice(x: NDArray[Any, numpy.float32], - ) -> NDArray[Any, numpy.float32]: +def otest_abs_slice(x: NDArray[Any, numpy.float32], + ) -> NDArray[Any, numpy.float32]: "onnx numpy slice 1" return nxnp.abs(x)[:, 1] @onnxnumpy_default -def test_abs_slice2(x: NDArray[Any, numpy.float32], - ) -> NDArray[Any, numpy.float32]: +def otest_abs_slice2(x: NDArray[Any, numpy.float32], + ) -> NDArray[Any, numpy.float32]: "onnx numpy slice 2" return nxnp.abs(x)[:1, 1] @onnxnumpy_default -def test_abs_slice23(x: NDArray[Any, numpy.float32], - ) -> NDArray[Any, numpy.float32]: +def otest_abs_slice23(x: NDArray[Any, numpy.float32], + ) -> NDArray[Any, numpy.float32]: "onnx numpy slice 23" return nxnp.abs(x)[::2, ::3] @onnxnumpy_default -def test_abs_slice_end(x: NDArray[Any, numpy.float32], - ) -> NDArray[Any, numpy.float32]: +def otest_abs_slice_end(x: NDArray[Any, numpy.float32], + ) -> NDArray[Any, numpy.float32]: "onnx numpy slice end" return nxnp.abs(x)[1:, :3] @onnxnumpy_default -def test_abs_gather(x: NDArray[Any, numpy.float32], - ) -> NDArray[Any, numpy.float32]: +def otest_abs_gather(x: NDArray[Any, numpy.float32], + ) -> NDArray[Any, numpy.float32]: "onnx numpy gather" return nxnp.abs(x)[1] @onnxnumpy_default -def test_abs_gather2(x: NDArray[Any, numpy.float32], - ) -> NDArray[Any, numpy.float32]: +def otest_abs_gather2(x: NDArray[Any, numpy.float32], + ) -> NDArray[Any, numpy.float32]: "onnx numpy gather" return nxnp.abs(x)[:, 1] @onnxnumpy_default -def test_abs_neg(x: NDArray[Any, numpy.float32], - ) -> NDArray[Any, numpy.float32]: +def otest_abs_neg(x: NDArray[Any, numpy.float32], + ) -> NDArray[Any, numpy.float32]: "onnx numpy neg" return - nxnp.abs(x) @onnxnumpy_default -def test_abs_not(x: NDArray[Any, numpy.float32], - ) -> NDArray[Any, numpy.bool_]: +def otest_abs_not(x: NDArray[Any, numpy.float32], + ) -> NDArray[Any, numpy.bool_]: "onnx numpy not" temp = nxnp.abs(x) > numpy.float32(0) return temp.not_() @onnxnumpy_default -def test_abs_filter(x: NDArray[Any, numpy.float32], - ) -> NDArray[Any, numpy.float32]: +def otest_abs_filter(x: NDArray[Any, numpy.float32], + ) -> NDArray[Any, numpy.float32]: "onnx numpy filter" return nxnp.abs(x)[x[:, 0] > numpy.float32(15)] @onnxnumpy_default -def test_log(x: NDArray[Any, numpy.float32], - ) -> NDArray[Any, numpy.float32]: +def otest_log(x: NDArray[Any, numpy.float32], + ) -> NDArray[Any, numpy.float32]: "onnx numpy log" return nxnp.log(x) @onnxnumpy_np(signature=NDArraySameTypeSameShape("floats")) -def test_abs_log_multi(x): +def otest_abs_log_multi(x): "onnx numpy log multiple type" return nxnp.log(nxnp.abs(x)) @onnxnumpy_np(signature=NDArraySameTypeSameShape("floats")) -def test_abs_log_multi_dtype(x): +def otest_abs_log_multi_dtype(x): "onnx numpy log multiple type" return nxnp.log(nxnp.abs(x) + x.dtype(1)) @onnxnumpy_default -def test_abs_shape(x: NDArray[Any, numpy.float32], - ) -> NDArray[Any, numpy.int64]: +def otest_abs_shape(x: NDArray[Any, numpy.float32], + ) -> NDArray[Any, numpy.int64]: "onnx numpy shape" return nxnp.abs(x).shape @onnxnumpy_default -def test_abs_size(x: NDArray[Any, numpy.float32], - ) -> NDArray[Any, numpy.int64]: +def otest_abs_size(x: NDArray[Any, numpy.float32], + ) -> NDArray[Any, numpy.int64]: "onnx numpy size" return nxnp.abs(x).size @onnxnumpy_default -def test_abs_flatten(x: NDArray[Any, numpy.float32], - ) -> NDArray[Any, numpy.int64]: +def otest_abs_flatten(x: NDArray[Any, numpy.float32], + ) -> NDArray[Any, numpy.int64]: "onnx numpy flatten" return nxnp.abs(x).flatten() @onnxnumpy_default -def test_abs_flatten2(x: NDArray[Any, numpy.float32], - ) -> NDArray[Any, numpy.int64]: +def otest_abs_flatten2(x: NDArray[Any, numpy.float32], + ) -> NDArray[Any, numpy.int64]: "onnx numpy flatten" return nxnp.abs(x).flatten(axis=1) @onnxnumpy_default -def test_abs_set1a(x: NDArray[Any, numpy.float32], - ) -> NDArray[Any, numpy.float32]: +def otest_abs_set1a(x: NDArray[Any, numpy.float32], + ) -> NDArray[Any, numpy.float32]: "onnx numpy set" temp = nxnp.abs(x).copy() temp[2] = numpy.float32(-1.5) @@ -356,8 +357,8 @@ def test_abs_set1a(x: NDArray[Any, numpy.float32], @onnxnumpy_default -def test_abs_set1b(x: NDArray[Any, numpy.float32], - ) -> NDArray[Any, numpy.float32]: +def otest_abs_set1b(x: NDArray[Any, numpy.float32], + ) -> NDArray[Any, numpy.float32]: "onnx numpy set" temp = nxnp.abs(x).copy() temp[:4] = numpy.float32(-1.5) @@ -365,8 +366,8 @@ def test_abs_set1b(x: NDArray[Any, numpy.float32], @onnxnumpy_default -def test_abs_set1c(x: NDArray[Any, numpy.float32], - ) -> NDArray[Any, numpy.float32]: +def otest_abs_set1c(x: NDArray[Any, numpy.float32], + ) -> NDArray[Any, numpy.float32]: "onnx numpy set" temp = nxnp.abs(x).copy() temp[:4:2] = numpy.float32(-1.5) @@ -374,8 +375,8 @@ def test_abs_set1c(x: NDArray[Any, numpy.float32], @onnxnumpy_default -def test_abs_set1d(x: NDArray[Any, numpy.float32], - ) -> NDArray[Any, numpy.float32]: +def otest_abs_set1d(x: NDArray[Any, numpy.float32], + ) -> NDArray[Any, numpy.float32]: "onnx numpy set" temp = nxnp.abs(x).copy() temp[:4:2] = numpy.array([-1.5, -1.6], dtype=numpy.float32) @@ -383,8 +384,8 @@ def test_abs_set1d(x: NDArray[Any, numpy.float32], @onnxnumpy_default -def test_abs_set1e(x: NDArray[Any, numpy.float32], - ) -> NDArray[Any, numpy.float32]: +def otest_abs_set1e(x: NDArray[Any, numpy.float32], + ) -> NDArray[Any, numpy.float32]: "onnx numpy set" temp = nxnp.abs(x).copy() temp[2:] = numpy.float32(-1.5) @@ -392,8 +393,8 @@ def test_abs_set1e(x: NDArray[Any, numpy.float32], @onnxnumpy_default -def test_abs_set1f(x: NDArray[Any, numpy.float32], - ) -> NDArray[Any, numpy.float32]: +def otest_abs_set1f(x: NDArray[Any, numpy.float32], + ) -> NDArray[Any, numpy.float32]: "onnx numpy set" temp = nxnp.abs(x).copy() temp[3:5] = numpy.float32(-1.5) @@ -401,8 +402,8 @@ def test_abs_set1f(x: NDArray[Any, numpy.float32], @onnxnumpy_default -def test_abs_set1g(x: NDArray[Any, numpy.float32], - ) -> NDArray[Any, numpy.float32]: +def otest_abs_set1g(x: NDArray[Any, numpy.float32], + ) -> NDArray[Any, numpy.float32]: "onnx numpy set" temp = nxnp.abs(x).copy() temp[3:] = numpy.array([-1.5] * 4, dtype=numpy.float32) @@ -410,8 +411,8 @@ def test_abs_set1g(x: NDArray[Any, numpy.float32], @onnxnumpy_default -def test_abs_set1h(x: NDArray[Any, numpy.float32], - ) -> NDArray[Any, numpy.float32]: +def otest_abs_set1h(x: NDArray[Any, numpy.float32], + ) -> NDArray[Any, numpy.float32]: "onnx numpy set" cp = x.copy() cp[x < numpy.float32(0)] = numpy.array([-1], dtype=numpy.float32) @@ -419,8 +420,8 @@ def test_abs_set1h(x: NDArray[Any, numpy.float32], @onnxnumpy_default -def test_abs_set1i(x: NDArray[Any, numpy.float32], - ) -> NDArray[Any, numpy.float32]: +def otest_abs_set1i(x: NDArray[Any, numpy.float32], + ) -> NDArray[Any, numpy.float32]: "onnx numpy set" cp = x.copy() z = x < numpy.float32(0) @@ -467,283 +468,283 @@ class TestOnnxVariable(ExtTestCase): def test_py_abs(self): x = numpy.array([[6.1, -5], [3.5, -7.8]], dtype=numpy.float32) - y = test_abs(x) + y = otest_abs(x) self.assertEqualArray(y, numpy.abs(x)) - self.assertEqual(test_abs.__doc__, "onnx numpy abs") - self.assertTrue(hasattr(test_abs, 'compiled')) - self.assertIsInstance(test_abs.compiled, ONC) - rep = repr(test_abs.compiled) + self.assertEqual(otest_abs.__doc__, "onnx numpy abs") + self.assertTrue(hasattr(otest_abs, 'compiled')) + self.assertIsInstance(otest_abs.compiled, ONC) + rep = repr(otest_abs.compiled) self.assertStartsWith("OnnxNumpyCompiler(", rep) def test_py_abs_add(self): x = numpy.array([[6.1, -5], [3.5, -7.8]], dtype=numpy.float32) - y = test_abs_add(x) + y = otest_abs_add(x) self.assertEqualArray(y, numpy.abs(x) + x) def test_py_abs_addm(self): x = numpy.array([[6.1, -5], [3.5, -7.8]], dtype=numpy.float32) - y = test_abs_addm(x, x) + y = otest_abs_addm(x, x) self.assertEqualArray(y, numpy.abs(x) + x) def test_py_abs_add_cst(self): x = numpy.array([[6.1, -5], [3.5, -7.8]], dtype=numpy.float32) - y = test_abs_add2(x) + y = otest_abs_add2(x) self.assertEqualArray(y, numpy.abs(x) + 2) def test_py_abs_add4(self): x = numpy.array([[6.1, -5], [3.5, -7.8]], dtype=numpy.float32) - y = test_abs_add4(x) - text = str(test_abs_add4.compiled.onnx_).split('op_type: "Add"') + y = otest_abs_add4(x) + text = str(otest_abs_add4.compiled.onnx_).split('op_type: "Add"') self.assertEqual(len(text), 3) self.assertEqualArray(y, (x + x) + (x + x)) def test_py_abs_sub(self): x = numpy.array([[6.1, -5], [3.5, -7.8]], dtype=numpy.float32) - y = test_abs_sub(x) + y = otest_abs_sub(x) self.assertEqualArray(y, numpy.abs(x) - x) def test_py_abs_mul(self): x = numpy.array([[6.1, -5], [3.5, -7.8]], dtype=numpy.float32) - y = test_abs_mul(x) + y = otest_abs_mul(x) self.assertEqualArray(y, numpy.abs(x) * x) def test_py_abs_mod(self): x = numpy.array([[6.1, -5], [3.5, -7.8]], dtype=numpy.float32) - y = test_abs_mod(x) + y = otest_abs_mod(x) self.assertEqualArray(y, numpy.abs(x) % 2) def test_py_abs_pox(self): x = numpy.array([[6.1, -5], [3.5, -7.8]], dtype=numpy.float32) - y = test_abs_pow(x) + y = otest_abs_pow(x) self.assertEqualArray(y, numpy.abs(x) ** 2) def test_py_abs_matmul(self): x = numpy.array([[6.1, -5], [3.5, -7.8]], dtype=numpy.float32) - y = test_abs_matmul(x) + y = otest_abs_matmul(x) self.assertEqualArray(y, numpy.abs(x) @ x) def test_py_abs_matmul2(self): x = numpy.array([[6.1, -5], [3.5, -7.8]], dtype=numpy.float32) - y = test_abs_matmul2(x) + y = otest_abs_matmul2(x) self.assertEqualArray(y, numpy.abs(x) @ x) def test_py_abs_div(self): x = numpy.array([[6.1, -5], [3.5, -7.8]], dtype=numpy.float32) - y = test_abs_div(x) + y = otest_abs_div(x) self.assertEqualArray(y, numpy.abs(x) / x) x = numpy.array([[6.1, -5], [3.5, -7.8]], dtype=numpy.int64) - y = test_abs_div(x) + y = otest_abs_div(x) self.assertEqualArray(y, numpy.abs(x) / x) def test_py_abs_idiv(self): x = numpy.array([[6.1, -5], [3.5, -7.8]], dtype=numpy.float32) - y = test_abs_idiv(x) + y = otest_abs_idiv(x) self.assertEqualArray(y, numpy.abs(x) // x) x = numpy.array([[6.1, -5], [3.5, -7.8]], dtype=numpy.int64) - y = test_abs_idiv(x) + y = otest_abs_idiv(x) self.assertEqualArray(y, numpy.abs(x) // x) @ignore_warnings(DeprecationWarning) def test_py_abs_equal(self): x = numpy.array([[6.1, -5], [3.5, -7.8]], dtype=numpy.float32) - y = test_abs_equal(x) + y = otest_abs_equal(x) self.assertEqualArray(y, numpy.abs(x) == x) @ignore_warnings(DeprecationWarning) def test_py_abs_not_equal(self): x = numpy.array([[6.1, -5], [3.5, -7.8]], dtype=numpy.float32) - y = test_abs_not_equal(x) + y = otest_abs_not_equal(x) self.assertEqualArray(y, numpy.abs(x) != x) @ignore_warnings(DeprecationWarning) def test_py_abs_greater(self): x = numpy.array([[6.1, -5], [3.5, -7.8]], dtype=numpy.float32) - y = test_abs_greater(x) + y = otest_abs_greater(x) self.assertEqualArray(y, numpy.abs(x) > x) @ignore_warnings(DeprecationWarning) def test_py_abs_greater_or_equal(self): x = numpy.array([[6.1, -5], [3.5, -7.8]], dtype=numpy.float32) - y = test_abs_greater_or_equal(x) + y = otest_abs_greater_or_equal(x) self.assertEqualArray(y, numpy.abs(x) >= x) @ignore_warnings(DeprecationWarning) def test_py_abs_less(self): x = numpy.array([[6.1, -5], [3.5, -7.8]], dtype=numpy.float32) - y = test_abs_less(x) + y = otest_abs_less(x) self.assertEqualArray(y, numpy.abs(x) < x) @ignore_warnings(DeprecationWarning) def test_py_abs_less_or_equal(self): x = numpy.array([[6.1, -5], [3.5, -7.8]], dtype=numpy.float32) - y = test_abs_less_or_equal(x) + y = otest_abs_less_or_equal(x) self.assertEqualArray(y, numpy.abs(x) <= x) @ignore_warnings(DeprecationWarning) def test_py_abs_and(self): x = numpy.array([[6.1, -5], [3.5, -7.8]], dtype=numpy.float32) - y = test_abs_and(x) + y = otest_abs_and(x) self.assertEqualArray( y, (numpy.abs(x) < x) & (numpy.abs(x) < 0)) @ignore_warnings(DeprecationWarning) def test_py_abs_and2(self): x = numpy.array([[6.1, -5], [3.5, -7.8]], dtype=numpy.float32) - y = test_abs_and2(x) + y = otest_abs_and2(x) self.assertEqualArray( y, (numpy.abs(x) < x) & (numpy.abs(x) < 0)) @ignore_warnings(DeprecationWarning) def test_py_abs_or(self): x = numpy.array([[6.1, -5], [3.5, -7.8]], dtype=numpy.float32) - y = test_abs_or(x) + y = otest_abs_or(x) self.assertEqualArray( y, (numpy.abs(x) < x) | (numpy.abs(x) < 0)) @ignore_warnings(DeprecationWarning) def test_py_abs_or2(self): x = numpy.array([[6.1, -5], [3.5, -7.8]], dtype=numpy.float32) - y = test_abs_or2(x) + y = otest_abs_or2(x) self.assertEqualArray( y, (numpy.abs(x) < x) | (numpy.abs(x) < 0)) @ignore_warnings(DeprecationWarning) def test_py_abs_sum1(self): x = numpy.array([[6.1, -5], [3.5, -7.8]], dtype=numpy.float32) - y = test_abs_sum1(x) + y = otest_abs_sum1(x) self.assertEqualArray(y, numpy.sum(numpy.abs(x), axis=0)) @ignore_warnings(DeprecationWarning) def test_py_abs_sum2(self): x = numpy.array([[6.1, -5], [3.5, -7.8]], dtype=numpy.float32) - y = test_abs_sum2(x) + y = otest_abs_sum2(x) self.assertEqualArray(y, numpy.sum(numpy.abs(x), axis=1, keepdims=1)) @ignore_warnings(DeprecationWarning) def test_py_transpose_t(self): x = numpy.array([[6.1, -5], [3.5, -7.8]], dtype=numpy.float32) - y = test_abs_transpose_t(x) + y = otest_abs_transpose_t(x) self.assertEqualArray(y, numpy.abs(x).T) @ignore_warnings(DeprecationWarning) def test_py_abs_cast(self): x = numpy.array([[6.1, -5], [3.5, -7.8]], dtype=numpy.float32) - y = test_abs_cast(x) + y = otest_abs_cast(x) self.assertEqualArray(y, numpy.abs(x).astype(numpy.int64)) @ignore_warnings(DeprecationWarning) def test_py_abs_reshape(self): x = numpy.array([[6.1, -5], [3.5, -7.8]], dtype=numpy.float32) - y = test_abs_reshape(x) + y = otest_abs_reshape(x) self.assertEqualArray(y, numpy.abs(x).reshape((-1, 1))) @ignore_warnings(DeprecationWarning) def test_py_abs_reshape_11(self): x = numpy.array([[6.1, -5], [3.5, -7.8]], dtype=numpy.float32) - y = test_abs_reshape(x) + y = otest_abs_reshape(x) self.assertEqualArray(y, numpy.abs(x).reshape((-1, 1))) - compiled = test_abs_reshape.compiled + compiled = otest_abs_reshape.compiled self.assertNotIn("version: 11", str(compiled.onnx_)) - y = test_abs_reshape_11(x) + y = otest_abs_reshape_11(x) self.assertEqualArray(y, numpy.abs(x).reshape((-1, 1))) - compiled = test_abs_reshape_11.compiled + compiled = otest_abs_reshape_11.compiled self.assertIn("version: 11", str(compiled.onnx_)) @ignore_warnings(DeprecationWarning) def test_py_abs_slice(self): x = numpy.array([[6.1, -5], [3.5, -7.8]], dtype=numpy.float32) - y = test_abs_slice(x) + y = otest_abs_slice(x) self.assertEqualArray(y, numpy.abs(x)[:, 1]) @ignore_warnings(DeprecationWarning) def test_py_abs_slice23(self): x = numpy.arange(0, 36).reshape((6, 6)).astype(numpy.float32) - y = test_abs_slice23(x) + y = otest_abs_slice23(x) self.assertEqualArray(y, numpy.abs(x)[::2, ::3]) @ignore_warnings(DeprecationWarning) def test_py_abs_slice_end(self): x = numpy.arange(0, 36).reshape((6, 6)).astype(numpy.float32) - y = test_abs_slice_end(x) + y = otest_abs_slice_end(x) self.assertEqualArray(y, numpy.abs(x)[1:, :3]) @ignore_warnings(DeprecationWarning) def test_py_abs_gather(self): x = numpy.arange(0, 36).reshape((6, 6)).astype(numpy.float32) - y = test_abs_gather(x) + y = otest_abs_gather(x) self.assertEqualArray(y, numpy.abs(x)[1]) @ignore_warnings(DeprecationWarning) def test_py_abs_gather2(self): x = numpy.arange(0, 36).reshape((6, 6)).astype(numpy.float32) - y = test_abs_gather2(x) + y = otest_abs_gather2(x) self.assertEqualArray(y, numpy.abs(x)[:, 1]) @ignore_warnings(DeprecationWarning) def test_py_abs_neg(self): x = numpy.arange(0, 36).reshape((6, 6)).astype(numpy.float32) - y = test_abs_neg(x) + y = otest_abs_neg(x) self.assertEqualArray(y, -numpy.abs(x)) @ignore_warnings(DeprecationWarning) def test_py_abs_not(self): x = numpy.arange(0, 36).reshape((6, 6)).astype(numpy.float32) - y = test_abs_not(x) + y = otest_abs_not(x) self.assertEqualArray(y, numpy.abs(x) <= 0) @ignore_warnings(DeprecationWarning) def test_py_abs_filter(self): x = numpy.arange(0, 36).reshape((6, 6)).astype(numpy.float32) - y = test_abs_filter(x) + y = otest_abs_filter(x) self.assertEqualArray(y, numpy.abs(x)[x[:, 0] > 15]) @ignore_warnings(DeprecationWarning) def test_py_log(self): x = numpy.array([[6.1, 5], [3.5, 7.8]], dtype=numpy.float32) - y = test_log(x) + y = otest_log(x) self.assertEqualArray(y, numpy.log(x)) @ignore_warnings(DeprecationWarning) def test_py_abs_log_multi(self): x = numpy.array([[6.1, -5], [-3.5, 7.8]], dtype=numpy.float32) - y = test_abs_log_multi(x) + y = otest_abs_log_multi(x) self.assertEqualArray(y, numpy.log(numpy.abs(x))) @ignore_warnings(DeprecationWarning) def test_py_abs_log_multi_dtype(self): x = numpy.array([[6.1, -5], [-3.5, 7.8]], dtype=numpy.float32) - y = test_abs_log_multi_dtype(x) + y = otest_abs_log_multi_dtype(x) self.assertEqualArray(y, numpy.log(numpy.abs(x) + 1)) @ignore_warnings(DeprecationWarning) def test_py_abs_shape(self): x = numpy.array([[6.1, -5], [3.5, -7.8]], dtype=numpy.float32) - y = test_abs_shape(x) + y = otest_abs_shape(x) self.assertEqualArray(y, numpy.abs(x).shape) @ignore_warnings(DeprecationWarning) def test_py_abs_size(self): x = numpy.array([[6.1, -5], [3.5, -7.8]], dtype=numpy.float32) - y = test_abs_size(x) + y = otest_abs_size(x) self.assertEqualArray(y, numpy.abs(x).size) @ignore_warnings(DeprecationWarning) def test_py_abs_flatten(self): x = numpy.array([[6.1, -5], [3.5, -7.8]], dtype=numpy.float32) - y = test_abs_flatten(x) + y = otest_abs_flatten(x) self.assertEqualArray(y, numpy.abs(x).flatten()) @ignore_warnings(DeprecationWarning) def test_py_abs_flatten2(self): x = numpy.array([[[6.11, -51], [3.51, -7.81]], [[6.1, -5], [3.5, -7.8]]], dtype=numpy.float32) - y = test_abs_flatten2(x) + y = otest_abs_flatten2(x) self.assertEqualArray(y, numpy.abs(x).flatten().reshape((2, -1))) @ignore_warnings(DeprecationWarning) def test_py_abs_set1a(self): x = numpy.array([6.1, -5, 3.5, -7.8, 6.7, -5.0], dtype=numpy.float32) - y = test_abs_set1a(x) + y = otest_abs_set1a(x) temp = numpy.abs(x) temp[2] = -1.5 self.assertEqualArray(y, temp) @@ -751,7 +752,7 @@ def test_py_abs_set1a(self): @ignore_warnings(DeprecationWarning) def test_py_abs_set1b(self): x = numpy.array([6.1, -5, 3.5, -7.8, 6.7, -5.0], dtype=numpy.float32) - y = test_abs_set1b(x) + y = otest_abs_set1b(x) temp = numpy.abs(x) temp[:4] = -1.5 self.assertEqualArray(y, temp) @@ -759,7 +760,7 @@ def test_py_abs_set1b(self): @ignore_warnings(DeprecationWarning) def test_py_abs_set1c(self): x = numpy.array([6.1, -5, 3.5, -7.8, 6.7, -5.0], dtype=numpy.float32) - y = test_abs_set1c(x) + y = otest_abs_set1c(x) temp = numpy.abs(x) temp[:4:2] = -1.5 self.assertEqualArray(y, temp) @@ -767,17 +768,17 @@ def test_py_abs_set1c(self): @ignore_warnings(DeprecationWarning) def test_py_abs_set1d(self): x = numpy.array([6.1, -5, 3.5, -7.8, 6.7, -5.0], dtype=numpy.float32) - y = test_abs_set1d(x) + y = otest_abs_set1d(x) temp = numpy.abs(x) temp[:4:2] = [-1.5, -1.6] self.assertEqualArray(y, temp) @ignore_warnings(DeprecationWarning) def test_py_abs_set1e(self): - self.assertIn('op_type: "Shape"', str(test_abs_set1e.compiled.onnx_)) + self.assertIn('op_type: "Shape"', str(otest_abs_set1e.compiled.onnx_)) x = numpy.array([6.1, -5, 3.5, -7.8, 6.7, -5.0, -6., -7.], dtype=numpy.float32) - y = test_abs_set1e(x) + y = otest_abs_set1e(x) temp = numpy.abs(x) temp[2:] = -1.5 self.assertEqualArray(y, temp) @@ -786,7 +787,7 @@ def test_py_abs_set1e(self): def test_py_abs_set1f(self): x = numpy.array([6.1, -5, 3.5, -7.8, 6.7, -5.0, -6.], dtype=numpy.float32) - y = test_abs_set1f(x) + y = otest_abs_set1f(x) temp = numpy.abs(x) temp[3:5] = -1.5 self.assertEqualArray(y, temp) @@ -795,7 +796,7 @@ def test_py_abs_set1f(self): def test_py_abs_set1g(self): x = numpy.array([6.1, -5, 3.5, -7.8, 6.7, -5.0, -6.], dtype=numpy.float32) - y = test_abs_set1g(x) + y = otest_abs_set1g(x) temp = numpy.abs(x) temp[3:] = -1.5 self.assertEqualArray(y, temp) @@ -804,7 +805,7 @@ def test_py_abs_set1g(self): def test_py_abs_set1h(self): x = numpy.array([6.1, -5, 3.5, -7.8, 6.7, -5.0, -6.], dtype=numpy.float32) - y = test_abs_set1h(x) + y = otest_abs_set1h(x) temp = x.copy() temp[x < 0] = -1 self.assertEqualArray(temp, y) @@ -813,7 +814,7 @@ def test_py_abs_set1h(self): def test_py_abs_set1i(self): x = numpy.array([6.1, -5, 3.5, -7.8, 6.7, -5.0, -6.], dtype=numpy.float32) - y = test_abs_set1i(x) + y = otest_abs_set1i(x) temp = numpy.abs(x) self.assertEqualArray(temp, y) @@ -887,6 +888,42 @@ def test_py_exp_1r_mul3(self): temp = numpy.log(2 * x) self.assertEqualArray(temp, y) + def test_get_onnx_graph(self): + self.assertEqual( + otest_abs_reshape.to_onnx().SerializeToString(), + otest_abs_reshape.compiled.onnx_.SerializeToString()) + self.assertEqual( + otest_abs_reshape_11.to_onnx().SerializeToString(), + otest_abs_reshape_11.compiled.onnx_.SerializeToString()) + + x = numpy.array([[6.1, -5], [-3.5, 7.8]], dtype=numpy.float32) + otest_abs_log_multi(x) + sigs = list(otest_abs_log_multi.signed_compiled.values())[0] + self.assertEqual( + otest_abs_log_multi.to_onnx().SerializeToString(), + sigs.compiled.onnx_.SerializeToString()) + + x = numpy.array([[6.1, -5], [-3.5, 7.8]], dtype=numpy.float32) + otest_abs_log_multi_dtype(x) + otest_abs_log_multi_dtype(x.astype(numpy.float64)) + self.assertRaise(lambda: otest_abs_log_multi_dtype.to_onnx(), + ValueError) + self.assertRaise( + lambda: otest_abs_log_multi_dtype.to_onnx(blabla=None), + ValueError) + self.assertRaise( + lambda: otest_abs_log_multi_dtype.to_onnx(key="?"), + ValueError) + key = FctVersion((numpy.float64,), None) + sigs = otest_abs_log_multi_dtype.signed_compiled[key] + self.assertEqual( + otest_abs_log_multi_dtype.to_onnx(key=key).SerializeToString(), + sigs.compiled.onnx_.SerializeToString()) + self.assertEqual( + otest_abs_log_multi_dtype.to_onnx( + key=numpy.float64).SerializeToString(), + sigs.compiled.onnx_.SerializeToString()) + if __name__ == "__main__": unittest.main() diff --git a/_unittests/ut_npy/test_onnx_variable_ort.py b/_unittests/ut_npy/test_onnx_variable_ort.py index daf4b76de..b4622b103 100644 --- a/_unittests/ut_npy/test_onnx_variable_ort.py +++ b/_unittests/ut_npy/test_onnx_variable_ort.py @@ -25,305 +25,305 @@ def get_bool(unused): @onnxnumpy(runtime='onnxruntime1') -def test_abs(x: NDArray[Any, numpy.float32], - ) -> NDArray[Any, numpy.float32]: +def otest_abs(x: NDArray[Any, numpy.float32], + ) -> NDArray[Any, numpy.float32]: "onnx numpy abs" return nxnp.abs(x) @onnxnumpy(runtime='onnxruntime1') -def test_abs_abs(x: NDArray[Any, numpy.float32], - ) -> NDArray[Any, numpy.float32]: +def otest_abs_abs(x: NDArray[Any, numpy.float32], + ) -> NDArray[Any, numpy.float32]: "onnx numpy abs abs" return nxnp.abs(nxnp.abs(x)) @onnxnumpy(runtime='onnxruntime1') -def test_abs_add(x: NDArray[Any, numpy.float32], - ) -> NDArray[Any, numpy.float32]: +def otest_abs_add(x: NDArray[Any, numpy.float32], + ) -> NDArray[Any, numpy.float32]: "onnx numpy addition" return nxnp.abs(x) + x @onnxnumpy(runtime='onnxruntime1') -def test_abs_add4(x: NDArray[Any, numpy.float32], - ) -> NDArray[Any, numpy.float32]: +def otest_abs_add4(x: NDArray[Any, numpy.float32], + ) -> NDArray[Any, numpy.float32]: "onnx numpy addition" x2 = x * x return x2 * x2 @onnxnumpy(runtime='onnxruntime1') -def test_abs_addm(x1: NDArray[Any, numpy.float32], - x2: NDArray[Any, numpy.float32] - ) -> NDArray[Any, numpy.float32]: +def otest_abs_addm(x1: NDArray[Any, numpy.float32], + x2: NDArray[Any, numpy.float32] + ) -> NDArray[Any, numpy.float32]: "onnx numpy addition" return nxnp.abs(x1) + x2 @onnxnumpy(runtime='onnxruntime1') -def test_abs_add2(x: NDArray[Any, numpy.float32], - ) -> NDArray[Any, numpy.float32]: +def otest_abs_add2(x: NDArray[Any, numpy.float32], + ) -> NDArray[Any, numpy.float32]: "onnx numpy addition" return nxnp.abs(x) + numpy.float32(2) @onnxnumpy(runtime='onnxruntime1') -def test_abs_sub(x: NDArray[Any, numpy.float32], - ) -> NDArray[Any, numpy.float32]: +def otest_abs_sub(x: NDArray[Any, numpy.float32], + ) -> NDArray[Any, numpy.float32]: "onnx numpy addition" return nxnp.abs(x) - x @onnxnumpy(runtime='onnxruntime1') -def test_abs_mul(x: NDArray[Any, numpy.float32], - ) -> NDArray[Any, numpy.float32]: +def otest_abs_mul(x: NDArray[Any, numpy.float32], + ) -> NDArray[Any, numpy.float32]: "onnx numpy addition" return nxnp.abs(x) * x @onnxnumpy(runtime='onnxruntime1') -def test_abs_pow(x: NDArray[Any, numpy.float32], - ) -> NDArray[Any, numpy.float32]: +def otest_abs_pow(x: NDArray[Any, numpy.float32], + ) -> NDArray[Any, numpy.float32]: "onnx numpy power" return nxnp.abs(x) ** numpy.float32(2) @onnxnumpy(runtime='onnxruntime1') -def test_abs_mod(x: NDArray[Any, numpy.float32], - ) -> NDArray[Any, numpy.int64]: +def otest_abs_mod(x: NDArray[Any, numpy.float32], + ) -> NDArray[Any, numpy.int64]: "onnx numpy modulo" return nxnp.abs(x).astype(numpy.int64) % numpy.int64(2) @onnxnumpy(runtime='onnxruntime1') -def test_abs_matmul(x: NDArray[Any, numpy.float32], - ) -> NDArray[Any, numpy.float32]: +def otest_abs_matmul(x: NDArray[Any, numpy.float32], + ) -> NDArray[Any, numpy.float32]: "onnx numpy addition" return nxnp.abs(x) @ x @onnxnumpy(runtime='onnxruntime1') -def test_abs_div(x: NDArray[Any, numpy.float32], - ) -> NDArray[Any, numpy.float32]: +def otest_abs_div(x: NDArray[Any, numpy.float32], + ) -> NDArray[Any, numpy.float32]: "onnx numpy division" return nxnp.abs(x) / x @onnxnumpy(runtime='onnxruntime1') -def test_abs_idiv(x: NDArray[Any, numpy.float32], - ) -> NDArray[Any, numpy.int64]: +def otest_abs_idiv(x: NDArray[Any, numpy.float32], + ) -> NDArray[Any, numpy.int64]: "onnx numpy int division" return nxnp.abs(x).astype(numpy.int64) // x.astype(numpy.int64) @onnxnumpy(runtime='onnxruntime1') -def test_abs_equal(x: NDArray[Any, numpy.float32], - ) -> NDArray[Any, numpy_bool]: +def otest_abs_equal(x: NDArray[Any, numpy.float32], + ) -> NDArray[Any, numpy_bool]: "onnx numpy equality" return nxnp.abs(x) == x @onnxnumpy(runtime='onnxruntime1') -def test_abs_not_equal(x: NDArray[Any, numpy.float32], - ) -> NDArray[Any, numpy_bool]: +def otest_abs_not_equal(x: NDArray[Any, numpy.float32], + ) -> NDArray[Any, numpy_bool]: "onnx numpy inequality" return nxnp.abs(x) != x @onnxnumpy(runtime='onnxruntime1') -def test_abs_greater(x: NDArray[Any, numpy.float32], - ) -> NDArray[Any, numpy_bool]: +def otest_abs_greater(x: NDArray[Any, numpy.float32], + ) -> NDArray[Any, numpy_bool]: "onnx numpy greater" return nxnp.abs(x) > x @onnxnumpy(runtime='onnxruntime1') -def test_abs_greater_or_equal(x: NDArray[Any, numpy.float32], - ) -> NDArray[Any, numpy_bool]: +def otest_abs_greater_or_equal(x: NDArray[Any, numpy.float32], + ) -> NDArray[Any, numpy_bool]: "onnx numpy greater or equal" return nxnp.abs(x) >= x @onnxnumpy(runtime='onnxruntime1') -def test_abs_less(x: NDArray[Any, numpy.float32], - ) -> NDArray[Any, numpy_bool]: +def otest_abs_less(x: NDArray[Any, numpy.float32], + ) -> NDArray[Any, numpy_bool]: "onnx numpy less" return nxnp.abs(x) < x @onnxnumpy(runtime='onnxruntime1') -def test_abs_less_or_equal(x: NDArray[Any, numpy.float32], - ) -> NDArray[Any, numpy_bool]: +def otest_abs_less_or_equal(x: NDArray[Any, numpy.float32], + ) -> NDArray[Any, numpy_bool]: "onnx numpy less or equal" return nxnp.abs(x) <= x @onnxnumpy(runtime='onnxruntime1') -def test_abs_and(x: NDArray[Any, numpy.float32], - ) -> NDArray[Any, numpy_bool]: +def otest_abs_and(x: NDArray[Any, numpy.float32], + ) -> NDArray[Any, numpy_bool]: "onnx numpy and" return (nxnp.abs(x) < x) and (nxnp.abs(x) < numpy.float32(0)) @onnxnumpy(runtime='onnxruntime1') -def test_abs_or(x: NDArray[Any, numpy.float32], - ) -> NDArray[Any, numpy_bool]: +def otest_abs_or(x: NDArray[Any, numpy.float32], + ) -> NDArray[Any, numpy_bool]: "onnx numpy or" return (nxnp.abs(x) < x) or (nxnp.abs(x) < numpy.float32(0)) @onnxnumpy(runtime='onnxruntime1') -def test_abs_sum1(x: NDArray[Any, numpy.float32], - ) -> NDArray[Any, numpy.float32]: +def otest_abs_sum1(x: NDArray[Any, numpy.float32], + ) -> NDArray[Any, numpy.float32]: "onnx numpy sum" return nxnp.sum(nxnp.abs(x), axis=0) @onnxnumpy(runtime='onnxruntime1') -def test_abs_sum2(x: NDArray[Any, numpy.float32], - ) -> NDArray[Any, numpy.float32]: +def otest_abs_sum2(x: NDArray[Any, numpy.float32], + ) -> NDArray[Any, numpy.float32]: "onnx numpy sum" return nxnp.sum(nxnp.abs(x), axis=1, keepdims=1) @onnxnumpy(runtime='onnxruntime1') -def test_abs_transpose_t(x: NDArray[Any, numpy.float32], - ) -> NDArray[Any, numpy.float32]: +def otest_abs_transpose_t(x: NDArray[Any, numpy.float32], + ) -> NDArray[Any, numpy.float32]: "onnx numpy transpose T" return nxnp.abs(x).T @onnxnumpy(runtime='onnxruntime1') -def test_abs_cast(x: NDArray[Any, numpy.float32], - ) -> NDArray[Any, numpy.int64]: +def otest_abs_cast(x: NDArray[Any, numpy.float32], + ) -> NDArray[Any, numpy.int64]: "onnx numpy cast" return nxnp.abs(x).astype(numpy.int64) @onnxnumpy(runtime='onnxruntime1') -def test_abs_reshape(x: NDArray[Any, numpy.float32], - ) -> NDArray[Any, numpy.float32]: +def otest_abs_reshape(x: NDArray[Any, numpy.float32], + ) -> NDArray[Any, numpy.float32]: "onnx numpy reshape" return nxnp.abs(x).reshape((-1, 1)) @onnxnumpy(op_version=11, runtime='onnxruntime1') -def test_abs_reshape_11(x: NDArray[Any, numpy.float32], - ) -> NDArray[Any, numpy.float32]: +def otest_abs_reshape_11(x: NDArray[Any, numpy.float32], + ) -> NDArray[Any, numpy.float32]: "onnx numpy reshape with opset 11" return nxnp.abs(x).reshape((-1, 1)) @onnxnumpy(runtime='onnxruntime1') -def test_abs_slice(x: NDArray[Any, numpy.float32], - ) -> NDArray[Any, numpy.float32]: +def otest_abs_slice(x: NDArray[Any, numpy.float32], + ) -> NDArray[Any, numpy.float32]: "onnx numpy slice 1" return nxnp.abs(x)[:, 1] @onnxnumpy(runtime='onnxruntime1') -def test_abs_slice2(x: NDArray[Any, numpy.float32], - ) -> NDArray[Any, numpy.float32]: +def otest_abs_slice2(x: NDArray[Any, numpy.float32], + ) -> NDArray[Any, numpy.float32]: "onnx numpy slice 2" return nxnp.abs(x)[:1, 1] @onnxnumpy(runtime='onnxruntime1') -def test_abs_slice23(x: NDArray[Any, numpy.float32], - ) -> NDArray[Any, numpy.float32]: +def otest_abs_slice23(x: NDArray[Any, numpy.float32], + ) -> NDArray[Any, numpy.float32]: "onnx numpy slice 23" return nxnp.abs(x)[::2, ::3] @onnxnumpy(runtime='onnxruntime1') -def test_abs_slice_end(x: NDArray[Any, numpy.float32], - ) -> NDArray[Any, numpy.float32]: +def otest_abs_slice_end(x: NDArray[Any, numpy.float32], + ) -> NDArray[Any, numpy.float32]: "onnx numpy slice end" return nxnp.abs(x)[1:, :3] @onnxnumpy(runtime='onnxruntime1') -def test_abs_gather(x: NDArray[Any, numpy.float32], - ) -> NDArray[Any, numpy.float32]: +def otest_abs_gather(x: NDArray[Any, numpy.float32], + ) -> NDArray[Any, numpy.float32]: "onnx numpy gather" return nxnp.abs(x)[1] @onnxnumpy(runtime='onnxruntime1') -def test_abs_gather2(x: NDArray[Any, numpy.float32], - ) -> NDArray[Any, numpy.float32]: +def otest_abs_gather2(x: NDArray[Any, numpy.float32], + ) -> NDArray[Any, numpy.float32]: "onnx numpy gather" return nxnp.abs(x)[:, 1] @onnxnumpy(runtime='onnxruntime1') -def test_abs_neg(x: NDArray[Any, numpy.float32], - ) -> NDArray[Any, numpy.float32]: +def otest_abs_neg(x: NDArray[Any, numpy.float32], + ) -> NDArray[Any, numpy.float32]: "onnx numpy neg" return - nxnp.abs(x) @onnxnumpy(runtime='onnxruntime1') -def test_abs_not(x: NDArray[Any, numpy.float32], - ) -> NDArray[Any, numpy.bool_]: +def otest_abs_not(x: NDArray[Any, numpy.float32], + ) -> NDArray[Any, numpy.bool_]: "onnx numpy not" temp = nxnp.abs(x) > numpy.float32(0) return temp.not_() @onnxnumpy(runtime='onnxruntime1') -def test_abs_filter(x: NDArray[Any, numpy.float32], - ) -> NDArray[Any, numpy.float32]: +def otest_abs_filter(x: NDArray[Any, numpy.float32], + ) -> NDArray[Any, numpy.float32]: "onnx numpy filter" return nxnp.abs(x)[x[:, 0] > numpy.float32(15)] @onnxnumpy(runtime='onnxruntime1') -def test_log(x: NDArray[Any, numpy.float32], - ) -> NDArray[Any, numpy.float32]: +def otest_log(x: NDArray[Any, numpy.float32], + ) -> NDArray[Any, numpy.float32]: "onnx numpy log" return nxnp.log(x) @onnxnumpy_np(signature=NDArraySameTypeSameShape("floats"), runtime='onnxruntime1') -def test_abs_log_multi(x): +def otest_abs_log_multi(x): "onnx numpy log multiple type" return nxnp.log(nxnp.abs(x)) @onnxnumpy(runtime='onnxruntime1') -def test_abs_shape(x: NDArray[Any, numpy.float32], - ) -> NDArray[Any, numpy.int64]: +def otest_abs_shape(x: NDArray[Any, numpy.float32], + ) -> NDArray[Any, numpy.int64]: "onnx numpy shape" return nxnp.abs(x).shape @onnxnumpy(runtime='onnxruntime1') -def test_abs_size(x: NDArray[Any, numpy.float32], - ) -> NDArray[Any, numpy.int64]: +def otest_abs_size(x: NDArray[Any, numpy.float32], + ) -> NDArray[Any, numpy.int64]: "onnx numpy size" return nxnp.abs(x).size @onnxnumpy(runtime='onnxruntime1') -def test_abs_flatten(x: NDArray[Any, numpy.float32], - ) -> NDArray[Any, numpy.float32]: +def otest_abs_flatten(x: NDArray[Any, numpy.float32], + ) -> NDArray[Any, numpy.float32]: "onnx numpy flatten" return nxnp.abs(x).flatten() @onnxnumpy(runtime='onnxruntime1') -def test_abs_flatten2(x: NDArray[Any, numpy.float32], - ) -> NDArray[Any, numpy.float32]: +def otest_abs_flatten2(x: NDArray[Any, numpy.float32], + ) -> NDArray[Any, numpy.float32]: "onnx numpy flatten" return nxnp.abs(x).flatten(axis=1) @onnxnumpy(runtime='onnxruntime1') -def test_abs_set1a(x: NDArray[Any, numpy.float32], - ) -> NDArray[Any, numpy.float32]: +def otest_abs_set1a(x: NDArray[Any, numpy.float32], + ) -> NDArray[Any, numpy.float32]: "onnx numpy set" temp = nxnp.abs(x).copy() temp[2] = numpy.float32(-1.5) @@ -331,8 +331,8 @@ def test_abs_set1a(x: NDArray[Any, numpy.float32], @onnxnumpy(runtime='onnxruntime1') -def test_abs_set1b(x: NDArray[Any, numpy.float32], - ) -> NDArray[Any, numpy.float32]: +def otest_abs_set1b(x: NDArray[Any, numpy.float32], + ) -> NDArray[Any, numpy.float32]: "onnx numpy set" temp = nxnp.abs(x).copy() temp[:4] = numpy.float32(-1.5) @@ -340,8 +340,8 @@ def test_abs_set1b(x: NDArray[Any, numpy.float32], @onnxnumpy(runtime='onnxruntime1') -def test_abs_set1c(x: NDArray[Any, numpy.float32], - ) -> NDArray[Any, numpy.float32]: +def otest_abs_set1c(x: NDArray[Any, numpy.float32], + ) -> NDArray[Any, numpy.float32]: "onnx numpy set" temp = nxnp.abs(x).copy() temp[:4:2] = numpy.float32(-1.5) @@ -349,8 +349,8 @@ def test_abs_set1c(x: NDArray[Any, numpy.float32], @onnxnumpy(runtime='onnxruntime1') -def test_abs_set1d(x: NDArray[Any, numpy.float32], - ) -> NDArray[Any, numpy.float32]: +def otest_abs_set1d(x: NDArray[Any, numpy.float32], + ) -> NDArray[Any, numpy.float32]: "onnx numpy set" temp = nxnp.abs(x).copy() temp[:4:2] = numpy.array([-1.5, -1.6], dtype=numpy.float32) @@ -358,8 +358,8 @@ def test_abs_set1d(x: NDArray[Any, numpy.float32], @onnxnumpy(runtime='onnxruntime1') -def test_abs_set1e(x: NDArray[Any, numpy.float32], - ) -> NDArray[Any, numpy.float32]: +def otest_abs_set1e(x: NDArray[Any, numpy.float32], + ) -> NDArray[Any, numpy.float32]: "onnx numpy set" temp = nxnp.abs(x).copy() temp[2:] = numpy.float32(-1.5) @@ -367,8 +367,8 @@ def test_abs_set1e(x: NDArray[Any, numpy.float32], @onnxnumpy(runtime='onnxruntime1') -def test_abs_set1f(x: NDArray[Any, numpy.float32], - ) -> NDArray[Any, numpy.float32]: +def otest_abs_set1f(x: NDArray[Any, numpy.float32], + ) -> NDArray[Any, numpy.float32]: "onnx numpy set" temp = nxnp.abs(x).copy() temp[3:5] = numpy.float32(-1.5) @@ -376,8 +376,8 @@ def test_abs_set1f(x: NDArray[Any, numpy.float32], @onnxnumpy(runtime='onnxruntime1') -def test_abs_set1g(x: NDArray[Any, numpy.float32], - ) -> NDArray[Any, numpy.float32]: +def otest_abs_set1g(x: NDArray[Any, numpy.float32], + ) -> NDArray[Any, numpy.float32]: "onnx numpy set" temp = nxnp.abs(x).copy() temp[3:] = numpy.array([-1.5] * 4, dtype=numpy.float32) @@ -388,234 +388,234 @@ class TestOnnxVariableOrt(ExtTestCase): def test_ort_abs(self): x = numpy.array([[6.1, -5], [3.5, -7.8]], dtype=numpy.float32) - y = test_abs(x) + y = otest_abs(x) self.assertEqualArray(y, numpy.abs(x)) - self.assertEqual(test_abs.__doc__, "onnx numpy abs") - self.assertTrue(hasattr(test_abs, 'compiled')) - self.assertIsInstance(test_abs.compiled, ONC) + self.assertEqual(otest_abs.__doc__, "onnx numpy abs") + self.assertTrue(hasattr(otest_abs, 'compiled')) + self.assertIsInstance(otest_abs.compiled, ONC) def test_ort_abs_add(self): x = numpy.array([[6.1, -5], [3.5, -7.8]], dtype=numpy.float32) - y = test_abs_add(x) + y = otest_abs_add(x) self.assertEqualArray(y, numpy.abs(x) + x) def test_ort_abs_addm(self): x = numpy.array([[6.1, -5], [3.5, -7.8]], dtype=numpy.float32) - y = test_abs_addm(x, x) + y = otest_abs_addm(x, x) self.assertEqualArray(y, numpy.abs(x) + x) def test_ort_abs_add_cst(self): x = numpy.array([[6.1, -5], [3.5, -7.8]], dtype=numpy.float32) - y = test_abs_add2(x) + y = otest_abs_add2(x) self.assertEqualArray(y, numpy.abs(x) + 2) def test_ort_abs_add4(self): x = numpy.array([[6.1, -5], [3.5, -7.8]], dtype=numpy.float32) - y = test_abs_add4(x) - text = str(test_abs_add4.compiled.onnx_).split('op_type: "Mul"') + y = otest_abs_add4(x) + text = str(otest_abs_add4.compiled.onnx_).split('op_type: "Mul"') self.assertEqual(len(text), 3) self.assertEqualArray(y, (x * x) * (x * x)) def test_ort_abs_sub(self): x = numpy.array([[6.1, -5], [3.5, -7.8]], dtype=numpy.float32) - y = test_abs_sub(x) + y = otest_abs_sub(x) self.assertEqualArray(y, numpy.abs(x) - x) def test_ort_abs_mul(self): x = numpy.array([[6.1, -5], [3.5, -7.8]], dtype=numpy.float32) - y = test_abs_mul(x) + y = otest_abs_mul(x) self.assertEqualArray(y, numpy.abs(x) * x) def test_ort_abs_mod(self): x = numpy.array([[6.1, -5], [3.5, -7.8]], dtype=numpy.float32) - y = test_abs_mod(x) + y = otest_abs_mod(x) self.assertEqualArray(y, numpy.abs(x).astype(numpy.int64) % 2) def test_ort_abs_pox(self): x = numpy.array([[6.1, -5], [3.5, -7.8]], dtype=numpy.float32) - y = test_abs_pow(x) + y = otest_abs_pow(x) self.assertEqualArray(y, numpy.abs(x) ** 2) def test_ort_abs_matmul(self): x = numpy.array([[6.1, -5], [3.5, -7.8]], dtype=numpy.float32) - y = test_abs_matmul(x) + y = otest_abs_matmul(x) self.assertEqualArray(y, numpy.abs(x) @ x) def test_ort_abs_div(self): x = numpy.array([[6.1, -5], [3.5, -7.8]], dtype=numpy.float32) - y = test_abs_div(x) + y = otest_abs_div(x) self.assertEqualArray(y, numpy.abs(x) / x) x = numpy.array([[6.1, -5], [3.5, -7.8]], dtype=numpy.int64) - self.assertRaise(lambda: test_abs_div(x), OrtInvalidArgument) + self.assertRaise(lambda: otest_abs_div(x), OrtInvalidArgument) def test_ort_abs_idiv(self): x = numpy.array([[6.1, -5], [3.5, -7.8]], dtype=numpy.float32) - y = test_abs_idiv(x) + y = otest_abs_idiv(x) self.assertEqualArray(y, numpy.abs(x) // x) x = numpy.array([[6.1, -5], [3.5, -7.8]], dtype=numpy.int64) - self.assertRaise(lambda: test_abs_idiv(x), OrtInvalidArgument) + self.assertRaise(lambda: otest_abs_idiv(x), OrtInvalidArgument) @ignore_warnings(DeprecationWarning) def test_ort_abs_equal(self): x = numpy.array([[6.1, -5], [3.5, -7.8]], dtype=numpy.float32) - y = test_abs_equal(x) + y = otest_abs_equal(x) self.assertEqualArray(y, numpy.abs(x) == x) @ignore_warnings(DeprecationWarning) def test_ort_abs_not_equal(self): x = numpy.array([[6.1, -5], [3.5, -7.8]], dtype=numpy.float32) - y = test_abs_not_equal(x) + y = otest_abs_not_equal(x) self.assertEqualArray(y, numpy.abs(x) != x) @ignore_warnings(DeprecationWarning) def test_ort_abs_greater(self): x = numpy.array([[6.1, -5], [3.5, -7.8]], dtype=numpy.float32) - y = test_abs_greater(x) + y = otest_abs_greater(x) self.assertEqualArray(y, numpy.abs(x) > x) @ignore_warnings(DeprecationWarning) def test_ort_abs_greater_or_equal(self): x = numpy.array([[6.1, -5], [3.5, -7.8]], dtype=numpy.float32) - y = test_abs_greater_or_equal(x) + y = otest_abs_greater_or_equal(x) self.assertEqualArray(y, numpy.abs(x) >= x) @ignore_warnings(DeprecationWarning) def test_ort_abs_less(self): x = numpy.array([[6.1, -5], [3.5, -7.8]], dtype=numpy.float32) - y = test_abs_less(x) + y = otest_abs_less(x) self.assertEqualArray(y, numpy.abs(x) < x) @ignore_warnings(DeprecationWarning) def test_ort_abs_less_or_equal(self): x = numpy.array([[6.1, -5], [3.5, -7.8]], dtype=numpy.float32) - y = test_abs_less_or_equal(x) + y = otest_abs_less_or_equal(x) self.assertEqualArray(y, numpy.abs(x) <= x) @ignore_warnings(DeprecationWarning) def test_ort_abs_and(self): x = numpy.array([[6.1, -5], [3.5, -7.8]], dtype=numpy.float32) - y = test_abs_and(x) + y = otest_abs_and(x) self.assertEqualArray( y, (numpy.abs(x) < x) & (numpy.abs(x) < 0)) @ignore_warnings(DeprecationWarning) def test_ort_abs_or(self): x = numpy.array([[6.1, -5], [3.5, -7.8]], dtype=numpy.float32) - y = test_abs_or(x) + y = otest_abs_or(x) self.assertEqualArray( y, (numpy.abs(x) < x) | (numpy.abs(x) < 0)) def test_ort_abs_sum1(self): x = numpy.array([[6.1, -5], [3.5, -7.8]], dtype=numpy.float32) - y = test_abs_sum1(x) + y = otest_abs_sum1(x) self.assertEqualArray(y, numpy.sum(numpy.abs(x), axis=0)) def test_ort_abs_sum2(self): x = numpy.array([[6.1, -5], [3.5, -7.8]], dtype=numpy.float32) - y = test_abs_sum2(x) + y = otest_abs_sum2(x) self.assertEqualArray(y, numpy.sum(numpy.abs(x), axis=1, keepdims=1)) def test_ort_transpose_t(self): x = numpy.array([[6.1, -5], [3.5, -7.8]], dtype=numpy.float32) - y = test_abs_transpose_t(x) + y = otest_abs_transpose_t(x) self.assertEqualArray(y, numpy.abs(x).T) def test_ort_abs_cast(self): x = numpy.array([[6.1, -5], [3.5, -7.8]], dtype=numpy.float32) - y = test_abs_cast(x) + y = otest_abs_cast(x) self.assertEqualArray(y, numpy.abs(x).astype(numpy.int64)) def test_ort_abs_reshape(self): x = numpy.array([[6.1, -5], [3.5, -7.8]], dtype=numpy.float32) - y = test_abs_reshape(x) + y = otest_abs_reshape(x) self.assertEqualArray(y, numpy.abs(x).reshape((-1, 1))) def test_ort_abs_reshape_11(self): x = numpy.array([[6.1, -5], [3.5, -7.8]], dtype=numpy.float32) - y = test_abs_reshape(x) + y = otest_abs_reshape(x) self.assertEqualArray(y, numpy.abs(x).reshape((-1, 1))) - compiled = test_abs_reshape.compiled + compiled = otest_abs_reshape.compiled self.assertNotIn("version: 11", str(compiled.onnx_)) - y = test_abs_reshape_11(x) + y = otest_abs_reshape_11(x) self.assertEqualArray(y, numpy.abs(x).reshape((-1, 1))) - compiled = test_abs_reshape_11.compiled + compiled = otest_abs_reshape_11.compiled self.assertIn("version: 11", str(compiled.onnx_)) def test_ort_abs_slice(self): x = numpy.array([[6.1, -5], [3.5, -7.8]], dtype=numpy.float32) - y = test_abs_slice(x) + y = otest_abs_slice(x) self.assertEqualArray(y, numpy.abs(x)[:, 1]) def test_ort_abs_slice23(self): x = numpy.arange(0, 36).reshape((6, 6)).astype(numpy.float32) - y = test_abs_slice23(x) + y = otest_abs_slice23(x) self.assertEqualArray(y, numpy.abs(x)[::2, ::3]) def test_ort_abs_slice_end(self): x = numpy.arange(0, 36).reshape((6, 6)).astype(numpy.float32) - y = test_abs_slice_end(x) + y = otest_abs_slice_end(x) self.assertEqualArray(y, numpy.abs(x)[1:, :3]) def test_ort_abs_gather(self): x = numpy.arange(0, 36).reshape((6, 6)).astype(numpy.float32) - y = test_abs_gather(x) + y = otest_abs_gather(x) self.assertEqualArray(y, numpy.abs(x)[1]) def test_ort_abs_gather2(self): x = numpy.arange(0, 36).reshape((6, 6)).astype(numpy.float32) - y = test_abs_gather2(x) + y = otest_abs_gather2(x) self.assertEqualArray(y, numpy.abs(x)[:, 1]) def test_ort_abs_neg(self): x = numpy.arange(0, 36).reshape((6, 6)).astype(numpy.float32) - y = test_abs_neg(x) + y = otest_abs_neg(x) self.assertEqualArray(y, -numpy.abs(x)) def test_ort_abs_not(self): x = numpy.arange(0, 36).reshape((6, 6)).astype(numpy.float32) - y = test_abs_not(x) + y = otest_abs_not(x) self.assertEqualArray(y, numpy.abs(x) <= 0) def test_ort_abs_filter(self): x = numpy.arange(0, 36).reshape((6, 6)).astype(numpy.float32) - y = test_abs_filter(x) + y = otest_abs_filter(x) self.assertEqualArray(y, numpy.abs(x)[x[:, 0] > 15]) def test_ort_log(self): x = numpy.array([[6.1, 5], [3.5, 7.8]], dtype=numpy.float32) - y = test_log(x) + y = otest_log(x) self.assertEqualArray(y, numpy.log(x), decimal=6) def test_ort_abs_log_multi(self): x = numpy.array([[6.1, -5], [-3.5, 7.8]], dtype=numpy.float32) - y = test_abs_log_multi(x) + y = otest_abs_log_multi(x) self.assertEqualArray(y, numpy.log(numpy.abs(x)), decimal=6) def test_ort_abs_shape(self): x = numpy.array([[6.1, -5], [3.5, -7.8]], dtype=numpy.float32) - y = test_abs_shape(x) + y = otest_abs_shape(x) self.assertEqualArray(y, numpy.abs(x).shape) def test_ort_abs_size(self): x = numpy.array([[6.1, -5], [3.5, -7.8]], dtype=numpy.float32) - y = test_abs_size(x) + y = otest_abs_size(x) self.assertEqualArray(y, numpy.abs(x).size) def test_py_abs_flatten(self): x = numpy.array([[6.1, -5], [3.5, -7.8]], dtype=numpy.float32) - y = test_abs_flatten(x) + y = otest_abs_flatten(x) self.assertEqualArray(y, numpy.abs(x).flatten()) def test_py_abs_flatten2(self): x = numpy.array([[[6.11, -51], [3.51, -7.81]], [[6.1, -5], [3.5, -7.8]]], dtype=numpy.float32) - y = test_abs_flatten2(x) + y = otest_abs_flatten2(x) self.assertEqualArray(y, numpy.abs(x).flatten().reshape((2, -1))) @ignore_warnings(DeprecationWarning) def test_py_abs_set1a(self): x = numpy.array([6.1, -5, 3.5, -7.8, 6.7, -5.0], dtype=numpy.float32) - y = test_abs_set1a(x) + y = otest_abs_set1a(x) temp = numpy.abs(x) temp[2] = -1.5 self.assertEqualArray(y, temp) @@ -623,7 +623,7 @@ def test_py_abs_set1a(self): @ignore_warnings(DeprecationWarning) def test_py_abs_set1b(self): x = numpy.array([6.1, -5, 3.5, -7.8, 6.7, -5.0], dtype=numpy.float32) - y = test_abs_set1b(x) + y = otest_abs_set1b(x) temp = numpy.abs(x) temp[:4] = -1.5 self.assertEqualArray(y, temp) @@ -631,7 +631,7 @@ def test_py_abs_set1b(self): @ignore_warnings(DeprecationWarning) def test_py_abs_set1c(self): x = numpy.array([6.1, -5, 3.5, -7.8, 6.7, -5.0], dtype=numpy.float32) - y = test_abs_set1c(x) + y = otest_abs_set1c(x) temp = numpy.abs(x) temp[:4:2] = -1.5 self.assertEqualArray(y, temp) @@ -639,17 +639,17 @@ def test_py_abs_set1c(self): @ignore_warnings(DeprecationWarning) def test_py_abs_set1d(self): x = numpy.array([6.1, -5, 3.5, -7.8, 6.7, -5.0], dtype=numpy.float32) - y = test_abs_set1d(x) + y = otest_abs_set1d(x) temp = numpy.abs(x) temp[:4:2] = [-1.5, -1.6] self.assertEqualArray(y, temp) @ignore_warnings(DeprecationWarning) def test_py_abs_set1e(self): - self.assertIn('op_type: "Shape"', str(test_abs_set1e.compiled.onnx_)) + self.assertIn('op_type: "Shape"', str(otest_abs_set1e.compiled.onnx_)) x = numpy.array([6.1, -5, 3.5, -7.8, 6.7, -5.0, -6.], dtype=numpy.float32) - y = test_abs_set1e(x) + y = otest_abs_set1e(x) temp = numpy.abs(x) temp[2:] = -1.5 self.assertEqualArray(y, temp) @@ -658,7 +658,7 @@ def test_py_abs_set1e(self): def test_py_abs_set1f(self): x = numpy.array([6.1, -5, 3.5, -7.8, 6.7, -5.0, -6.], dtype=numpy.float32) - y = test_abs_set1f(x) + y = otest_abs_set1f(x) temp = numpy.abs(x) temp[3:5] = -1.5 self.assertEqualArray(y, temp) @@ -667,7 +667,7 @@ def test_py_abs_set1f(self): def test_py_abs_set1g(self): x = numpy.array([6.1, -5, 3.5, -7.8, 6.7, -5.0, -6.], dtype=numpy.float32) - y = test_abs_set1g(x) + y = otest_abs_set1g(x) temp = numpy.abs(x) temp[3:] = -1.5 self.assertEqualArray(y, temp) diff --git a/_unittests/ut_npy/test_onnx_variable_tuple.py b/_unittests/ut_npy/test_onnx_variable_tuple.py index f2e0bd426..4b48468e0 100644 --- a/_unittests/ut_npy/test_onnx_variable_tuple.py +++ b/_unittests/ut_npy/test_onnx_variable_tuple.py @@ -30,17 +30,17 @@ def common_test_abs_topk(x): @onnxnumpy_default -def test_abs_topk(x: NDArray[Any, numpy.float32], - ) -> (NDArray[Any, numpy.float32], - NDArray[Any, numpy.int64]): +def otest_abs_topk(x: NDArray[Any, numpy.float32], + ) -> (NDArray[Any, numpy.float32], + NDArray[Any, numpy.int64]): "onnx topk" return common_test_abs_topk(x) @onnxnumpy(runtime='onnxruntime1') -def test_abs_topk_ort(x: NDArray[Any, numpy.float32], - ) -> (NDArray[Any, numpy.float32], - NDArray[Any, numpy.int64]): +def otest_abs_topk_ort(x: NDArray[Any, numpy.float32], + ) -> (NDArray[Any, numpy.float32], + NDArray[Any, numpy.int64]): "onnx topk" return common_test_abs_topk(x) @@ -51,8 +51,8 @@ class TestOnnxVariableTuple(ExtTestCase): def test_py_abs_topk(self): x = numpy.array([6.1, -5, 3.5, -7.8, 6.7, -5.0], dtype=numpy.float32).reshape((-1, 2)) - y, yi = test_abs_topk(x) # pylint: disable=E0633 - self.assertIn('output: "y"', str(test_abs_topk.compiled.onnx_)) + y, yi = otest_abs_topk(x) # pylint: disable=E0633 + self.assertIn('output: "y"', str(otest_abs_topk.compiled.onnx_)) exp_y = numpy.array([[6.1, 7.8, 6.7]], dtype=numpy.float32).T exp_yi = numpy.array([[0, 1, 0]], dtype=numpy.float32).T self.assertEqualArray(exp_y, y) @@ -62,7 +62,7 @@ def test_py_abs_topk(self): def test_py_abs_topk_ort(self): x = numpy.array([6.1, -5, 3.5, -7.8, 6.7, -5.0], dtype=numpy.float32).reshape((-1, 2)) - y, yi = test_abs_topk_ort(x) # pylint: disable=E0633 + y, yi = otest_abs_topk_ort(x) # pylint: disable=E0633 exp_y = numpy.array([[6.1, 7.8, 6.7]], dtype=numpy.float32).T exp_yi = numpy.array([[0, 1, 0]], dtype=numpy.float32).T self.assertEqualArray(exp_y, y) diff --git a/_unittests/ut_npy/test_wrappers.py b/_unittests/ut_npy/test_wrappers.py index 4a53e0985..2f06cd026 100644 --- a/_unittests/ut_npy/test_wrappers.py +++ b/_unittests/ut_npy/test_wrappers.py @@ -375,5 +375,5 @@ def test_signature_optional3_kwargs_more(self): if __name__ == "__main__": - TestWrappers().test_signature_optional_errors_runtime() + # TestWrappers().test_signature_optional_errors_runtime() unittest.main() diff --git a/mlprodict/npy/onnx_numpy_compiler.py b/mlprodict/npy/onnx_numpy_compiler.py index f3c206c0a..0e588bcc8 100644 --- a/mlprodict/npy/onnx_numpy_compiler.py +++ b/mlprodict/npy/onnx_numpy_compiler.py @@ -403,6 +403,23 @@ def _to_onnx(self, op_version=None, signature=None, version=None): type(self), self.fct_)) return self.onnx_ + def to_onnx(self, **kwargs): + """ + Returns the ONNX graph for the wrapped function. + It takes additional arguments to distinguish between multiple graphs. + This happens when a function needs to support multiple type. + + :return: ONNX graph + """ + if len(kwargs) > 0: + raise NotImplementedError( # pragma: no cover + "kwargs is not empty, this case is not implemented. " + "kwargs=%r." % kwargs) + if hasattr(self, 'onnx_'): + return self.onnx_ + raise NotImplementedError( # pragma: no cover + "Attribute 'onnx_' is missing.") + def _build_runtime(self, op_version=None, runtime=None, signature=None, version=None): """ diff --git a/mlprodict/npy/onnx_numpy_wrapper.py b/mlprodict/npy/onnx_numpy_wrapper.py index acf21db0e..b5fa3fcc0 100644 --- a/mlprodict/npy/onnx_numpy_wrapper.py +++ b/mlprodict/npy/onnx_numpy_wrapper.py @@ -68,6 +68,16 @@ def __setstate__(self, state): """ self.compiled = state['compiled'] + def to_onnx(self, **kwargs): + """ + Returns the ONNX graph for the wrapped function. + It takes additional arguments to distinguish between multiple graphs. + This happens when a function needs to support multiple type. + + :return: ONNX graph + """ + return self.compiled.to_onnx(**kwargs) + def onnxnumpy(op_version=None, runtime=None, signature=None): """ @@ -202,6 +212,44 @@ def _populate(self, version): def _validate_onnx_data(self, X): return X + def to_onnx(self, **kwargs): + """ + Returns the ONNX graph for the wrapped function. + It takes additional arguments to distinguish between multiple graphs. + This happens when a function needs to support multiple type. + + :return: ONNX graph + """ + if len(self.signed_compiled) == 0: + raise RuntimeError( # pragma: no cover + "No ONNX graph was compiled.") + if len(kwargs) == 0 and len(self.signed_compiled) == 1: + # We take the only one. + key = list(self.signed_compiled)[0] + cpl = self.signed_compiled[key] + return cpl.to_onnx() + if len(kwargs) == 0: + raise ValueError( + "There are multiple compiled ONNX graphs associated " + "with keys %r (add key=...)." % list(self.signed_compiled)) + if list(kwargs) != ['key']: + raise ValueError( + "kwargs should contain one parameter key=... but " + "it is %r." % kwargs) + key = kwargs['key'] + if key in self.signed_compiled: + return self.signed_compiled[key].compiled.onnx_ + found = [] + for k, v in self.signed_compiled.items(): + if k.args == key or ( + not isinstance(key, tuple) and k.args == (key, )): + found.append((k, v)) + if len(found) == 1: + return found[0][1].compiled.onnx_ + raise ValueError( + "Unable to find signature with key=%r among %r." % ( + key, list(self.signed_compiled))) + def onnxnumpy_np(op_version=None, runtime=None, signature=None): """ diff --git a/mlprodict/npy/onnx_version.py b/mlprodict/npy/onnx_version.py index 26155edda..c4a00aa80 100644 --- a/mlprodict/npy/onnx_version.py +++ b/mlprodict/npy/onnx_version.py @@ -50,7 +50,7 @@ def as_tuple_with_sep(self, sep): (tuple() if self.kwargs is None else self.kwargs)) def as_string(self): - "Returns a single stirng identifier." + "Returns a single string identifier." val = "_".join(map(str, self.as_tuple_with_sep("_"))) val = val.replace("", "").replace(" ", "") From 6c0ded047550278ba70bcb8d6435543efc1e8177 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?xavier=20dupr=C3=A9?= Date: Thu, 3 Feb 2022 18:06:20 +0100 Subject: [PATCH 2/2] update notebooks --- _doc/notebooks/numpy_api_onnx_ftr.ipynb | 223 +++++++++---------- _doc/notebooks/onnx_fft.ipynb | 272 ++++++++++++------------ 2 files changed, 244 insertions(+), 251 deletions(-) diff --git a/_doc/notebooks/numpy_api_onnx_ftr.ipynb b/_doc/notebooks/numpy_api_onnx_ftr.ipynb index 33c97adb2..c31918175 100644 --- a/_doc/notebooks/numpy_api_onnx_ftr.ipynb +++ b/_doc/notebooks/numpy_api_onnx_ftr.ipynb @@ -229,6 +229,7 @@ "name": "stdout", "output_type": "stream", "text": [ + "No CUDA runtime is found, using CUDA_HOME='C:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v11.5'\n", "FunctionTransformer is not supported unless the transform function is None (= identity). You may raise an issue at https://github.com/onnx/sklearn-onnx/issues.\n" ] } @@ -259,7 +260,7 @@ "data": { "text/plain": [ "Pipeline(steps=[('functiontransformer',\n", - " FunctionTransformer(func=)),\n", + " FunctionTransformer(func=)),\n", " ('standardscaler', StandardScaler()),\n", " ('logisticregression', LogisticRegression())])" ] @@ -283,7 +284,16 @@ "cell_type": "code", "execution_count": 7, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "C:\\Python395_x64\\lib\\site-packages\\xgboost\\compat.py:36: FutureWarning: pandas.Int64Index is deprecated and will be removed from pandas in a future version. Use pandas.Index with the appropriate dtype instead.\n", + " from pandas import MultiIndex, Int64Index\n" + ] + } + ], "source": [ "onx = to_onnx(pipe, X_train.astype(numpy.float64), rewrite_ops=True)" ] @@ -296,16 +306,16 @@ { "data": { "text/html": [ - "
\n", + "
\n", "" ], "text/plain": [ - "" + "" ] }, "execution_count": 9, @@ -333,7 +343,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "4.61 \u00b5s \u00b1 821 ns per loop (mean \u00b1 std. dev. of 7 runs, 100000 loops each)\n" + "8.84 \u00b5s \u00b1 747 ns per loop (mean \u00b1 std. dev. of 7 runs, 100,000 loops each)\n" ] } ], @@ -350,7 +360,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "15.5 \u00b5s \u00b1 723 ns per loop (mean \u00b1 std. dev. of 7 runs, 100000 loops each)\n" + "33.8 \u00b5s \u00b1 4.01 \u00b5s per loop (mean \u00b1 std. dev. of 7 runs, 10,000 loops each)\n" ] } ], @@ -376,7 +386,7 @@ "data": { "text/plain": [ "Pipeline(steps=[('functiontransformer',\n", - " FunctionTransformer(func=)),\n", + " FunctionTransformer(func=)),\n", " ('standardscaler', StandardScaler()),\n", " ('logisticregression', LogisticRegression())])" ] @@ -435,7 +445,7 @@ "data": { "text/plain": [ "Pipeline(steps=[('functiontransformer',\n", - " FunctionTransformer(func=)),\n", + " FunctionTransformer(func=)),\n", " ('standardscaler', StandardScaler()),\n", " ('logisticregression', LogisticRegression())])" ] @@ -469,16 +479,16 @@ { "data": { "text/html": [ - "
\n", + "
\n", "" ], "text/plain": [ - "" + "" ] }, "execution_count": 15, @@ -507,7 +517,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "6.15 \u00b5s \u00b1 116 ns per loop (mean \u00b1 std. dev. of 7 runs, 100000 loops each)\n" + "13.7 \u00b5s \u00b1 625 ns per loop (mean \u00b1 std. dev. of 7 runs, 100,000 loops each)\n" ] } ], @@ -527,7 +537,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "22.1 \u00b5s \u00b1 2.21 \u00b5s per loop (mean \u00b1 std. dev. of 7 runs, 10000 loops each)\n" + "46.3 \u00b5s \u00b1 6.84 \u00b5s per loop (mean \u00b1 std. dev. of 7 runs, 10,000 loops each)\n" ] } ], @@ -551,7 +561,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "433 \u00b5s \u00b1 53.7 \u00b5s per loop (mean \u00b1 std. dev. of 7 runs, 1000 loops each)\n" + "722 \u00b5s \u00b1 46.8 \u00b5s per loop (mean \u00b1 std. dev. of 7 runs, 1,000 loops each)\n" ] } ], @@ -569,7 +579,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "357 \u00b5s \u00b1 13.6 \u00b5s per loop (mean \u00b1 std. dev. of 7 runs, 1000 loops each)\n" + "400 \u00b5s \u00b1 80.7 \u00b5s per loop (mean \u00b1 std. dev. of 7 runs, 1,000 loops each)\n" ] } ], @@ -601,9 +611,9 @@ { "data": { "text/plain": [ - "array([[2.2948687 , 1.0178018 , 0.14858188, 1.0178018 ],\n", - " [2.4203196 , 2.2417266 , 1.7303984 , 2.2417266 ],\n", - " [3.0329118 , 1.2578778 , 0.75200284, 1.2578778 ]], dtype=float32)" + "array([[3.1185195 , 0.68828994, 2.553703 , 0.68828994],\n", + " [2.9688716 , 1.1822908 , 0.22248763, 1.1822908 ],\n", + " [3.0031753 , 2.3098822 , 3.0584362 , 2.3098822 ]], dtype=float32)" ] }, "execution_count": 20, @@ -653,12 +663,20 @@ "execution_count": 20, "metadata": {}, "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "C:\\xadupre\\github\\mlprodict\\mlprodict\\npy\\numpy_onnx_impl.py:267: UserWarning: npnx.dot is equivalent to npnx.matmul == numpy.matmul != numpy.dot with arrays with more than 3D dimensions.\n", + " warnings.warn(\n" + ] + }, { "data": { "text/plain": [ - "array([[2.2948687 , 1.0178018 , 0.14858188, 1.0178018 ],\n", - " [2.4203196 , 2.2417266 , 1.7303984 , 2.2417266 ],\n", - " [3.0329118 , 1.257878 , 0.75200284, 1.2578778 ]], dtype=float32)" + "array([[3.1185198, 0.6882898, 2.5537028, 0.68829 ],\n", + " [2.9688714, 1.1822908, 0.2224876, 1.1822908],\n", + " [3.0031753, 2.3098822, 3.058436 , 2.3098824]], dtype=float32)" ] }, "execution_count": 21, @@ -713,16 +731,16 @@ { "data": { "text/html": [ - "
\n", + "
\n", "" ], "text/plain": [ - "" + "" ] }, "execution_count": 22, @@ -731,7 +749,8 @@ } ], "source": [ - "%onnxview custom_fft_abs.compiled.onnx_" + "fonx = custom_fft_abs.to_onnx()\n", + "%onnxview fonx" ] }, { @@ -750,93 +769,67 @@ "name": "stdout", "output_type": "stream", "text": [ - "-- OnnxInference: run 39 nodes\n", - "Onnx-Shape(x) -> Sh_shape0\n", + "-- OnnxInference: run 26 nodes\n", + "Onnx-Shape(x) -> Sh_shape0 (name='Sh_Shape')\n", "+kr='Sh_shape0': (2,) (dtype=int64 min=3 max=4)\n", - "Onnx-Slice(Sh_shape0, Sl_Slicecst, Sl_Slicecst1, Sl_Slicecst2) -> Sl_output01\n", - "+kr='Sl_output01': (1,) (dtype=int64 min=4 max=4)\n", - "Onnx-Identity(Sl_Slicecst2) -> Sq_Squeezecst\n", - "+kr='Sq_Squeezecst': (1,) (dtype=int64 min=0 max=0)\n", - "Onnx-Squeeze(Sl_output01, Sq_Squeezecst) -> Sq_squeezed01\n", - "+kr='Sq_squeezed01': () (dtype=int64 min=4 max=4)\n", - "Onnx-Identity(Sl_Slicecst2) -> Su_Subcst\n", - "+kr='Su_Subcst': (1,) (dtype=int64 min=0 max=0)\n", - "Onnx-Sub(Sq_squeezed01, Su_Subcst) -> Su_C0\n", - "+kr='Su_C0': (1,) (dtype=int64 min=4 max=4)\n", - "Onnx-ConstantOfShape(Su_C0) -> Co_output01\n", + "Onnx-Transpose(x) -> Tr_transposed0 (name='Tr_Transpose')\n", + "+kr='Tr_transposed0': (4, 3) (dtype=float32 min=-1.7609916925430298 max=1.1423430442810059)\n", + "Onnx-Gather(Sh_shape0, Ga_Gathercst) -> Ga_output0 (name='Ga_Gather')\n", + "+kr='Ga_output0': () (dtype=int64 min=4 max=4)\n", + "Onnx-Reshape(Ga_output0, Re_Reshapecst) -> Re_reshaped01 (name='Re_Reshape')\n", + "+kr='Re_reshaped01': (1,) (dtype=int64 min=4 max=4)\n", + "Onnx-Cast(Ga_output0) -> Ca_output02 (name='Ca_Cast1')\n", + "+kr='Ca_output02': () (dtype=float32 min=4.0 max=4.0)\n", + "Onnx-ConstantOfShape(Re_reshaped01) -> Co_output01 (name='Co_ConstantOfShape')\n", "+kr='Co_output01': (4,) (dtype=int64 min=1 max=1)\n", - "Onnx-Identity(Sl_Slicecst2) -> Cu_CumSumcst\n", - "+kr='Cu_CumSumcst': (1,) (dtype=int64 min=0 max=0)\n", - "Onnx-CumSum(Co_output01, Cu_CumSumcst) -> Cu_y0\n", + "Onnx-CumSum(Co_output01, Cu_CumSumcst) -> Cu_y0 (name='Cu_CumSum')\n", "+kr='Cu_y0': (4,) (dtype=int64 min=1 max=4)\n", - "Onnx-Add(Cu_y0, Ad_Addcst) -> Ad_C01\n", + "Onnx-Add(Cu_y0, Re_Reshapecst) -> Ad_C01 (name='Ad_Add')\n", "+kr='Ad_C01': (4,) (dtype=int64 min=0 max=3)\n", - "Onnx-Cast(Ad_C01) -> Ca_output0\n", + "Onnx-Cast(Ad_C01) -> Ca_output0 (name='Ca_Cast')\n", "+kr='Ca_output0': (4,) (dtype=float32 min=0.0 max=3.0)\n", - "Onnx-Reshape(Ca_output0, Re_Reshapecst) -> Re_reshaped0\n", + "Onnx-Reshape(Ca_output0, Re_Reshapecst1) -> Re_reshaped0 (name='Re_Reshape1')\n", "+kr='Re_reshaped0': (4, 1) (dtype=float32 min=0.0 max=3.0)\n", - "Onnx-Mul(Ca_output0, Mu_Mulcst) -> Mu_C01\n", + "Onnx-Mul(Ca_output0, Mu_Mulcst) -> Mu_C01 (name='Mu_Mul')\n", "+kr='Mu_C01': (4,) (dtype=float32 min=-18.84955596923828 max=-0.0)\n", - "Onnx-Mul(Re_reshaped0, Mu_C01) -> Mu_C0\n", + "Onnx-Mul(Re_reshaped0, Mu_C01) -> Mu_C0 (name='Mu_Mul1')\n", "+kr='Mu_C0': (4, 4) (dtype=float32 min=-56.548667907714844 max=-0.0)\n", - "Onnx-Cast(Sq_squeezed01) -> Ca_output01\n", - "+kr='Ca_output01': () (dtype=float32 min=4.0 max=4.0)\n", - "Onnx-Div(Mu_C0, Ca_output01) -> Di_C0\n", + "Onnx-Div(Mu_C0, Ca_output02) -> Di_C0 (name='Di_Div')\n", "+kr='Di_C0': (4, 4) (dtype=float32 min=-14.137166976928711 max=-0.0)\n", - "Onnx-Identity(Sl_Slicecst2) -> Un_Unsqueezecst\n", - "+kr='Un_Unsqueezecst': (1,) (dtype=int64 min=0 max=0)\n", - "Onnx-Unsqueeze(Di_C0, Un_Unsqueezecst) -> Un_expanded0\n", + "Onnx-Unsqueeze(Di_C0, Cu_CumSumcst) -> Un_expanded0 (name='Un_Unsqueeze')\n", "+kr='Un_expanded0': (1, 4, 4) (dtype=float32 min=-14.137166976928711 max=-0.0)\n", - "Onnx-Cos(Un_expanded0) -> Co_output0\n", + "Onnx-Cos(Un_expanded0) -> Co_output0 (name='Co_Cos')\n", "+kr='Co_output0': (1, 4, 4) (dtype=float32 min=-1.0 max=1.0)\n", - "Onnx-Sin(Un_expanded0) -> Si_output0\n", + "Onnx-Sin(Un_expanded0) -> Si_output0 (name='Si_Sin')\n", "+kr='Si_output0': (1, 4, 4) (dtype=float32 min=-1.0 max=1.0)\n", - "Onnx-Concat(Co_output0, Si_output0) -> Co_concat_result0\n", + "Onnx-Concat(Co_output0, Si_output0) -> Co_concat_result0 (name='Co_Concat')\n", "+kr='Co_concat_result0': (2, 4, 4) (dtype=float32 min=-1.0 max=1.0)\n", - "Onnx-Transpose(x) -> Tr_transposed0\n", - "+kr='Tr_transposed0': (4, 3) (dtype=float32 min=-2.0982813835144043 max=1.0294874906539917)\n", - "Onnx-MatMul(Co_concat_result0, Tr_transposed0) -> Ma_Y0\n", - "+kr='Ma_Y0': (2, 4, 3) (dtype=float32 min=-3.032911777496338 max=2.2948687076568604)\n", - "Onnx-Pow(Ma_Y0, Po_Powcst) -> Po_Z0\n", - "+kr='Po_Z0': (2, 4, 3) (dtype=float32 min=0.0 max=9.198554039001465)\n", - "Onnx-Identity(Sl_Slicecst2) -> Sl_Slicecst3\n", - "+kr='Sl_Slicecst3': (1,) (dtype=int64 min=0 max=0)\n", - "Onnx-Identity(Sl_Slicecst) -> Sl_Slicecst4\n", - "+kr='Sl_Slicecst4': (1,) (dtype=int64 min=1 max=1)\n", - "Onnx-Identity(Sl_Slicecst2) -> Sl_Slicecst5\n", - "+kr='Sl_Slicecst5': (1,) (dtype=int64 min=0 max=0)\n", - "Onnx-Slice(Po_Z0, Sl_Slicecst3, Sl_Slicecst4, Sl_Slicecst5) -> Sl_output0\n", - "+kr='Sl_output0': (1, 4, 3) (dtype=float32 min=0.020312773063778877 max=9.198554039001465)\n", - "Onnx-Identity(Sl_Slicecst2) -> Sq_Squeezecst1\n", - "+kr='Sq_Squeezecst1': (1,) (dtype=int64 min=0 max=0)\n", - "Onnx-Squeeze(Sl_output0, Sq_Squeezecst1) -> Sq_squeezed0\n", - "+kr='Sq_squeezed0': (4, 3) (dtype=float32 min=0.020312773063778877 max=9.198554039001465)\n", - "Onnx-Identity(Sl_Slicecst) -> Sl_Slicecst6\n", - "+kr='Sl_Slicecst6': (1,) (dtype=int64 min=1 max=1)\n", - "Onnx-Identity(Sl_Slicecst1) -> Sl_Slicecst7\n", - "+kr='Sl_Slicecst7': (1,) (dtype=int64 min=2 max=2)\n", - "Onnx-Identity(Sl_Slicecst2) -> Sl_Slicecst8\n", - "+kr='Sl_Slicecst8': (1,) (dtype=int64 min=0 max=0)\n", - "Onnx-Slice(Po_Z0, Sl_Slicecst6, Sl_Slicecst7, Sl_Slicecst8) -> Sl_output02\n", - "+kr='Sl_output02': (1, 4, 3) (dtype=float32 min=0.0 max=4.499505996704102)\n", - "Onnx-Identity(Sl_Slicecst2) -> Sq_Squeezecst2\n", - "+kr='Sq_Squeezecst2': (1,) (dtype=int64 min=0 max=0)\n", - "Onnx-Squeeze(Sl_output02, Sq_Squeezecst2) -> Sq_squeezed02\n", - "+kr='Sq_squeezed02': (4, 3) (dtype=float32 min=0.0 max=4.499505996704102)\n", - "Onnx-Add(Sq_squeezed0, Sq_squeezed02) -> Ad_C0\n", - "+kr='Ad_C0': (4, 3) (dtype=float32 min=0.022076575085520744 max=9.198554039001465)\n", - "Onnx-Sqrt(Ad_C0) -> Sq_Y0\n", - "+kr='Sq_Y0': (4, 3) (dtype=float32 min=0.1485818773508072 max=3.032911777496338)\n", - "Onnx-Transpose(Sq_Y0) -> y\n", - "+kr='y': (3, 4) (dtype=float32 min=0.1485818773508072 max=3.032911777496338)\n" + "Onnx-MatMul(Co_concat_result0, Tr_transposed0) -> Ma_Y0 (name='Ma_MatMul')\n", + "+kr='Ma_Y0': (2, 4, 3) (dtype=float32 min=-3.1185197830200195 max=2.2570557594299316)\n", + "Onnx-Pow(Ma_Y0, Po_Powcst) -> Po_Z0 (name='Po_Pow')\n", + "+kr='Po_Z0': (2, 4, 3) (dtype=float32 min=0.0 max=9.725165367126465)\n", + "Onnx-Slice(Po_Z0, Cu_CumSumcst, Sl_Slicecst1, Cu_CumSumcst) -> Sl_output0 (name='Sl_Slice')\n", + "+kr='Sl_output0': (1, 4, 3) (dtype=float32 min=0.0495007298886776 max=9.725165367126465)\n", + "Onnx-Slice(Po_Z0, Sl_Slicecst1, Po_Powcst, Cu_CumSumcst) -> Sl_output02 (name='Sl_Slice1')\n", + "+kr='Sl_output02': (1, 4, 3) (dtype=float32 min=0.0 max=5.094300746917725)\n", + "Onnx-Squeeze(Sl_output0, Cu_CumSumcst) -> Sq_squeezed0 (name='Sq_Squeeze')\n", + "+kr='Sq_squeezed0': (4, 3) (dtype=float32 min=0.0495007298886776 max=9.725165367126465)\n", + "Onnx-Squeeze(Sl_output02, Cu_CumSumcst) -> Sq_squeezed02 (name='Sq_Squeeze1')\n", + "+kr='Sq_squeezed02': (4, 3) (dtype=float32 min=0.0 max=5.094300746917725)\n", + "Onnx-Add(Sq_squeezed0, Sq_squeezed02) -> Ad_C0 (name='Ad_Add1')\n", + "+kr='Ad_C0': (4, 3) (dtype=float32 min=0.0495007298886776 max=9.725165367126465)\n", + "Onnx-Sqrt(Ad_C0) -> Sq_Y0 (name='Sq_Sqrt')\n", + "+kr='Sq_Y0': (4, 3) (dtype=float32 min=0.22248759865760803 max=3.1185197830200195)\n", + "Onnx-Transpose(Sq_Y0) -> y (name='Tr_Transpose1')\n", + "+kr='y': (3, 4) (dtype=float32 min=0.22248759865760803 max=3.1185197830200195)\n" ] }, { "data": { "text/plain": [ - "array([[2.2948687 , 1.0178018 , 0.14858188, 1.0178018 ],\n", - " [2.4203196 , 2.2417266 , 1.7303984 , 2.2417266 ],\n", - " [3.0329118 , 1.257878 , 0.75200284, 1.2578778 ]], dtype=float32)" + "array([[3.1185198, 0.6882898, 2.5537028, 0.68829 ],\n", + " [2.9688714, 1.1822908, 0.2224876, 1.1822908],\n", + " [3.0031753, 2.3098822, 3.058436 , 2.3098824]], dtype=float32)" ] }, "execution_count": 23, @@ -857,7 +850,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "25.3 \u00b5s \u00b1 5.76 \u00b5s per loop (mean \u00b1 std. dev. of 7 runs, 10000 loops each)\n" + "24.1 \u00b5s \u00b1 2.45 \u00b5s per loop (mean \u00b1 std. dev. of 7 runs, 10,000 loops each)\n" ] } ], @@ -874,7 +867,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "288 \u00b5s \u00b1 12.7 \u00b5s per loop (mean \u00b1 std. dev. of 7 runs, 1000 loops each)\n" + "309 \u00b5s \u00b1 65.8 \u00b5s per loop (mean \u00b1 std. dev. of 7 runs, 1,000 loops each)\n" ] } ], @@ -898,7 +891,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "1.72 ms \u00b1 32.3 \u00b5s per loop (mean \u00b1 std. dev. of 7 runs, 1000 loops each)\n" + "1.53 ms \u00b1 150 \u00b5s per loop (mean \u00b1 std. dev. of 7 runs, 1,000 loops each)\n" ] } ], @@ -916,7 +909,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "5.32 ms \u00b1 206 \u00b5s per loop (mean \u00b1 std. dev. of 7 runs, 100 loops each)\n" + "4.51 ms \u00b1 455 \u00b5s per loop (mean \u00b1 std. dev. of 7 runs, 100 loops each)\n" ] } ], @@ -942,9 +935,9 @@ { "data": { "text/plain": [ - "array([[2.2948687 , 1.0178018 , 0.14858188, 1.0178018 ],\n", - " [2.4203196 , 2.2417266 , 1.7303984 , 2.2417266 ],\n", - " [3.0329118 , 1.257878 , 0.75200284, 1.2578778 ]], dtype=float32)" + "array([[3.1185198, 0.6882898, 2.5537028, 0.68829 ],\n", + " [2.9688714, 1.1822908, 0.2224876, 1.1822908],\n", + " [3.0031753, 2.3098822, 3.058436 , 2.3098824]], dtype=float32)" ] }, "execution_count": 28, @@ -968,11 +961,19 @@ "execution_count": 28, "metadata": {}, "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "C:\\xadupre\\github\\mlprodict\\mlprodict\\npy\\numpy_onnx_impl.py:267: UserWarning: npnx.dot is equivalent to npnx.matmul == numpy.matmul != numpy.dot with arrays with more than 3D dimensions.\n", + " warnings.warn(\n" + ] + }, { "name": "stdout", "output_type": "stream", "text": [ - "149 \u00b5s \u00b1 54 \u00b5s per loop (mean \u00b1 std. dev. of 7 runs, 1 loop each)\n" + "114 \u00b5s \u00b1 37.1 \u00b5s per loop (mean \u00b1 std. dev. of 7 runs, 1 loop each)\n" ] } ], @@ -996,7 +997,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "217 \u00b5s \u00b1 18.9 \u00b5s per loop (mean \u00b1 std. dev. of 7 runs, 1000 loops each)\n" + "256 \u00b5s \u00b1 20.2 \u00b5s per loop (mean \u00b1 std. dev. of 7 runs, 1,000 loops each)\n" ] } ], @@ -1065,9 +1066,9 @@ { "data": { "text/plain": [ - "array([[2.2948687 , 1.0178018 , 0.14858188, 1.0178018 ],\n", - " [2.4203196 , 2.2417266 , 1.7303984 , 2.2417266 ],\n", - " [3.0329118 , 1.257878 , 0.75200284, 1.2578778 ]], dtype=float32)" + "array([[3.1185198, 0.6882898, 2.5537028, 0.68829 ],\n", + " [2.9688714, 1.1822908, 0.2224876, 1.1822908],\n", + " [3.0031753, 2.3098822, 3.058436 , 2.3098824]], dtype=float32)" ] }, "execution_count": 33, @@ -1107,7 +1108,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.8.7" + "version": "3.9.5" } }, "nbformat": 4, diff --git a/_doc/notebooks/onnx_fft.ipynb b/_doc/notebooks/onnx_fft.ipynb index ce4072f68..613f09946 100644 --- a/_doc/notebooks/onnx_fft.ipynb +++ b/_doc/notebooks/onnx_fft.ipynb @@ -173,7 +173,7 @@ { "data": { "text/plain": [ - "'1.21.0'" + "'1.22.1'" ] }, "execution_count": 4, @@ -205,16 +205,16 @@ { "data": { "text/plain": [ - "array([[-1.36418152+0.j , 2.3512614 -1.47772773j,\n", - " -3.4774066 +3.40257902j, -1.73059963+1.64505308j],\n", - " [ 0.6441313 +0.j , -0.87221646-1.87952026j,\n", - " 1.0705215 -1.186307j , 1.31619296+5.60515407j],\n", - " [ 1.38915221+0.j , -1.11980049+2.87742877j,\n", - " -0.25900143+0.17339344j, -1.45116622+1.24798734j],\n", - " [-1.86380783+0.j , 2.37798625+1.72008612j,\n", - " 1.42540207+1.57713781j, 0.18057206+1.32039835j],\n", - " [ 4.1150526 +0.j , -3.35634771-0.41940018j,\n", - " -0.38524887-1.39453991j, -0.31538136+1.7538376j ]])" + "array([[-0.75051495+0.j , 1.33475465+3.13179737j,\n", + " -1.87604383+0.49239622j, 0.73039102+1.11186655j],\n", + " [-0.76200065+0.j , 0.03706497+0.76383572j,\n", + " 2.22939392-1.13904508j, -3.81884915+0.45814935j],\n", + " [ 1.2141826 +0.j , 0.50065353-2.12543076j,\n", + " -3.10769194+0.43760207j, -0.91013869+0.88561919j],\n", + " [-2.93666464+0.j , 1.07270369-2.56275325j,\n", + " -1.42040003+0.10802866j, -1.65220639-2.11547056j],\n", + " [ 2.98258114+0.j , -1.71955059-1.29732326j,\n", + " 1.22977031+0.34286838j, -0.76048649+1.50560422j]])" ] }, "execution_count": 5, @@ -323,11 +323,11 @@ { "data": { "text/plain": [ - "array([[ 0.50121731+0.j , -1.76725248+1.19033269j],\n", - " [ 1.84486783+0.j , -0.13533521+1.86170961j],\n", - " [-1.49032012+0.j , -0.17000796+0.02887427j],\n", - " [-0.8358376 +0.j , 1.725943 +0.19581766j],\n", - " [ 0.9690519 +0.j , -1.34143379+0.70979425j]])" + "array([[-1.10793678+0.j , 0.4741874 +0.66750763j],\n", + " [-1.34050566+0.j , -0.15834314-2.11824309j],\n", + " [ 1.72974443+0.j , -2.11205184+0.59408175j],\n", + " [-0.06082912+0.j , -1.45597189-1.08558287j],\n", + " [ 1.1374151 +0.j , -0.46541163+0.50106358j]])" ] }, "execution_count": 7, @@ -369,20 +369,27 @@ "scrolled": false }, "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "No CUDA runtime is found, using CUDA_HOME='C:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v11.5'\n" + ] + }, { "data": { "text/plain": [ - "array([[[-1.3641814 , 2.3512614 , -3.4774065 , -1.7305996 ],\n", - " [ 0.6441313 , -0.87221646, 1.0705215 , 1.3161929 ],\n", - " [ 1.3891523 , -1.1198004 , -0.25900146, -1.4511662 ],\n", - " [-1.8638077 , 2.3779864 , 1.425402 , 0.18057205],\n", - " [ 4.1150527 , -3.3563478 , -0.38524887, -0.31538135]],\n", + "array([[[-0.75051486, 1.3347546 , -1.8760438 , 0.730391 ],\n", + " [-0.7620005 , 0.03706497, 2.2293937 , -3.8188488 ],\n", + " [ 1.2141826 , 0.50065356, -3.107692 , -0.9101387 ],\n", + " [-2.9366646 , 1.0727037 , -1.4204 , -1.6522063 ],\n", + " [ 2.9825811 , -1.7195507 , 1.2297703 , -0.7604865 ]],\n", "\n", - " [[ 0. , -1.4777277 , 3.402579 , 1.6450533 ],\n", - " [ 0. , -1.8795203 , -1.1863071 , 5.605154 ],\n", - " [ 0. , 2.8774288 , 0.17339343, 1.2479873 ],\n", - " [ 0. , 1.7200862 , 1.5771378 , 1.3203983 ],\n", - " [ 0. , -0.41940016, -1.39454 , 1.7538376 ]]],\n", + " [[ 0. , 3.1317973 , 0.49239618, 1.1118665 ],\n", + " [ 0. , 0.7638357 , -1.1390451 , 0.4581493 ],\n", + " [ 0. , -2.1254308 , 0.437602 , 0.88561916],\n", + " [ 0. , -2.5627534 , 0.10802869, -2.1154706 ],\n", + " [ 0. , -1.2973232 , 0.34286833, 1.5056041 ]]],\n", " dtype=float32)" ] }, @@ -440,16 +447,16 @@ { "data": { "text/html": [ - "
\n", + "
\n", "" ], "text/plain": [ - "" + "" ] }, "execution_count": 11, @@ -458,8 +465,7 @@ } ], "source": [ - "key = list(onnx_rfft.signed_compiled)[0]\n", - "%onnxview onnx_rfft.signed_compiled[key].compiled.onnx_" + "%onnxview onnx_rfft.to_onnx()" ] }, { @@ -492,16 +498,16 @@ { "data": { "text/plain": [ - "array([[ 5.56511808+0.j , 2.40434541-6.58876113j,\n", - " -2.99787318+6.09018702j, 2.95547828-4.78324036j],\n", - " [-1.46413093-9.60314657j, -1.66675694+0.60494258j,\n", - " -2.49781725+0.06244585j, -4.22491665-2.62906297j],\n", - " [-1.06488187-4.9975721j , -7.53624925+2.11727626j,\n", - " -2.93212515+2.35814643j, -1.32906648-6.29456206j],\n", - " [-1.06488187+4.9975721j , 1.28429404-3.79395468j,\n", - " -4.70865157+7.14245256j, 4.69409373-0.6235566j ],\n", - " [-1.46413093+9.60314657j, -3.6701756 -3.08301071j,\n", - " -0.67943963-5.20582724j, 5.05462128+3.35367375j]])" + "array([[10.14779193+0.j , -1.55134743-1.67220211j,\n", + " 3.23984394-7.15630184j, -8.55688343-3.86255514j],\n", + " [-5.47836537-7.29111075j, -1.44693655-4.16582164j,\n", + " -0.15482528-2.91009629j, -5.74598895+0.4286478j ],\n", + " [ 0.37482297-4.60517198j, -3.39913789+3.28850098j,\n", + " -4.56144176+9.89934275j, 5.52501083-1.01792048j],\n", + " [ 0.37482297+4.60517198j, -4.16542648-0.19354436j,\n", + " 1.59761181-7.05603298j, 0.02120182+6.56731064j],\n", + " [-5.47836537+7.29111075j, 2.29746565+7.31672206j,\n", + " 1.93122673+1.08542613j, -2.22944407+2.13972051j]])" ] }, "execution_count": 13, @@ -601,16 +607,16 @@ { "data": { "text/plain": [ - "array([[ 5.56511808+0.j , 2.40434541-6.58876113j,\n", - " -2.99787318+6.09018702j, 2.95547828-4.78324036j],\n", - " [-1.46413093-9.60314657j, -1.66675694+0.60494258j,\n", - " -2.49781725+0.06244585j, -4.22491665-2.62906297j],\n", - " [-1.06488187-4.9975721j , -7.53624925+2.11727626j,\n", - " -2.93212515+2.35814643j, -1.32906648-6.29456206j],\n", - " [-1.06488187+4.9975721j , 1.28429404-3.79395468j,\n", - " -4.70865157+7.14245256j, 4.69409373-0.6235566j ],\n", - " [-1.46413093+9.60314657j, -3.6701756 -3.08301071j,\n", - " -0.67943963-5.20582724j, 5.05462128+3.35367375j]])" + "array([[10.14779193+0.j , -1.55134743-1.67220211j,\n", + " 3.23984394-7.15630184j, -8.55688343-3.86255514j],\n", + " [-5.47836537-7.29111075j, -1.44693655-4.16582164j,\n", + " -0.15482528-2.91009629j, -5.74598895+0.4286478j ],\n", + " [ 0.37482297-4.60517198j, -3.39913789+3.28850098j,\n", + " -4.56144176+9.89934275j, 5.52501083-1.01792048j],\n", + " [ 0.37482297+4.60517198j, -4.16542648-0.19354436j,\n", + " 1.59761181-7.05603298j, 0.02120182+6.56731064j],\n", + " [-5.47836537+7.29111075j, 2.29746565+7.31672206j,\n", + " 1.93122673+1.08542613j, -2.22944407+2.13972051j]])" ] }, "execution_count": 16, @@ -631,17 +637,17 @@ { "data": { "text/plain": [ - "array([[[ 5.56511808, 2.40434541, -2.99787318, 2.95547828],\n", - " [-1.46413093, -1.66675694, -2.49781725, -4.22491665],\n", - " [-1.06488187, -7.53624925, -2.93212515, -1.32906648],\n", - " [-1.06488187, 1.28429404, -4.70865157, 4.69409373],\n", - " [-1.46413093, -3.6701756 , -0.67943963, 5.05462128]],\n", + "array([[[10.14779193, -1.55134743, 3.23984394, -8.55688343],\n", + " [-5.47836537, -1.44693655, -0.15482528, -5.74598895],\n", + " [ 0.37482297, -3.39913789, -4.56144176, 5.52501083],\n", + " [ 0.37482297, -4.16542648, 1.59761181, 0.02120182],\n", + " [-5.47836537, 2.29746565, 1.93122673, -2.22944407]],\n", "\n", - " [[ 0. , -6.58876113, 6.09018702, -4.78324036],\n", - " [-9.60314657, 0.60494258, 0.06244585, -2.62906297],\n", - " [-4.9975721 , 2.11727626, 2.35814643, -6.29456206],\n", - " [ 4.9975721 , -3.79395468, 7.14245256, -0.6235566 ],\n", - " [ 9.60314657, -3.08301071, -5.20582724, 3.35367375]]])" + " [[ 0. , -1.67220211, -7.15630184, -3.86255514],\n", + " [-7.29111075, -4.16582164, -2.91009629, 0.4286478 ],\n", + " [-4.60517198, 3.28850098, 9.89934275, -1.01792048],\n", + " [ 4.60517198, -0.19354436, -7.05603298, 6.56731064],\n", + " [ 7.29111075, 7.31672206, 1.08542613, 2.13972051]]])" ] }, "execution_count": 17, @@ -744,16 +750,16 @@ { "data": { "text/html": [ - "
\n", + "
\n", "" ], "text/plain": [ - "" + "" ] }, "execution_count": 20, @@ -762,8 +768,7 @@ } ], "source": [ - "key = list(onnx_rfft_2d.signed_compiled)[0]\n", - "%onnxview onnx_rfft_2d.signed_compiled[key].compiled.onnx_" + "%onnxview onnx_rfft_2d.to_onnx()" ] }, { @@ -774,8 +779,7 @@ "outputs": [], "source": [ "with open(\"fft2d.onnx\", \"wb\") as f:\n", - " key = list(onnx_rfft_2d.signed_compiled)[0]\n", - " f.write(onnx_rfft_2d.signed_compiled[key].compiled.onnx_.SerializeToString())" + " f.write(onnx_rfft_2d.to_onnx().SerializeToString())" ] }, { @@ -850,14 +854,14 @@ { "data": { "text/plain": [ - "array([[[ 1.62552961+0.j , -2.33151346-0.26713149j,\n", - " 1.52621416+0.j , -2.33151346+0.26713149j]],\n", + "array([[[ 1.34545542+0.j , -0.35498468-0.77279791j,\n", + " -1.72351556+0.j , -0.35498468+0.77279791j]],\n", "\n", - " [[ 1.56267625+0.j , -2.11182106+0.97715026j,\n", - " -1.59615904+0.j , -2.11182106-0.97715026j]],\n", + " [[-1.13275981+0.j , -2.43033203+0.77264115j,\n", + " -2.97744519+0.j , -2.43033203-0.77264115j]],\n", "\n", - " [[-2.11940277+0.j , 2.92459655+2.19828379j,\n", - " -1.98709261+0.j , 2.92459655-2.19828379j]]])" + " [[-0.06647013+0.j , 0.20555305+1.91183175j,\n", + " 2.91867135+0.j , 0.20555305-1.91183175j]]])" ] }, "execution_count": 24, @@ -1115,7 +1119,7 @@ "name": "stderr", "output_type": "stream", "text": [ - "100%|\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588| 24/24 [00:00<00:00, 776.23it/s]\n" + "100%|\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588| 24/24 [00:00<00:00, 292.18it/s]\n" ] }, { @@ -1179,7 +1183,7 @@ "name": "stderr", "output_type": "stream", "text": [ - "100%|\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588| 15/15 [00:00<00:00, 1156.92it/s]\n" + "100%|\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588| 15/15 [00:00<00:00, 357.70it/s]\n" ] }, { @@ -1225,19 +1229,7 @@ "metadata": { "scrolled": false }, - "outputs": [ - { - "name": "stderr", - "output_type": "stream", - "text": [ - "C:\\xavierdupre\\__home_\\GitHub\\mlprodict\\mlprodict\\npy\\onnx_numpy_wrapper.py:27: RuntimeWarning: Class 'onnxnumpy_nb_onnx_rfft_2d_any_None_None' overwritten in\n", - "'onnxnumpy_nb_onnx_rfft_2d_None_None, onnxnumpy_nb_onnx_rfft_2d_any_None_None, onnxnumpy_nb_onnx_rfft_None_None'\n", - "---\n", - "\n", - " warnings.warn( # pragma: no cover\n" - ] - } - ], + "outputs": [], "source": [ "def onnx_rfft_3d_1d(x, fft_length=None, transpose=True):\n", " if fft_length is None:\n", @@ -1319,7 +1311,7 @@ "OK x.shape=(3, 1, 4) length=(1, 4) output shape=(3, 4) or (2, 3, 1, 3)\n", "OK x.shape=(3, 1, 4) length=(1, 4) output shape=(3, 4) or (2, 3, 1, 3)\n", "OK x.shape=(3, 1, 4) length=(1, 2) output shape=(3, 4) or (2, 3, 1, 2)\n", - "DIS x.shape=(3, 1, 4) length=(1, 1) error=AssertionError('Mismatch max diff=2.9777344341736463e+35 > 1e-05.') output shape=(3, 4) or (2, 3, 1, 1)\n", + "DIS x.shape=(3, 1, 4) length=(1, 1) error=AssertionError('Mismatch max diff=1.0 > 1e-05.') output shape=(3, 4) or (2, 3, 1, 1)\n", "OK x.shape=(5, 7) length=(5, 7) output shape=(3, 4) or (2, 5, 4)\n", "OK x.shape=(5, 7) length=(1, 7) output shape=(3, 4) or (2, 1, 4)\n", "OK x.shape=(5, 7) length=(2, 7) output shape=(3, 4) or (2, 2, 4)\n", @@ -1392,16 +1384,16 @@ { "data": { "text/html": [ - "
\n", + "
\n", "" ], "text/plain": [ - "" + "" ] }, "execution_count": 35, @@ -1487,10 +1479,12 @@ "-- OnnxInference: run 38 nodes\n", "Onnx-Unsqueeze(Un_Unsqueezecst, Un_Unsqueezecst1) -> Un_expanded0 (name='Un_Unsqueeze')\n", "+kr='Un_expanded0': (1, 2, 1, 1) (dtype=float32 min=0.0 max=1.0)\n", - "Onnx-Unsqueeze(Un_Unsqueezecst2, Un_Unsqueezecst1) -> Un_expanded03 (name='Un_Unsqueeze1')\n", - "+kr='Un_expanded03': (1, 2, 4, 4) (dtype=float32 min=-1.0 max=1.0)\n", "Onnx-Shape(x) -> Sh_shape0 (name='Sh_Shape')\n", "+kr='Sh_shape0': (3,) (dtype=int64 min=1 max=4)\n", + "Onnx-Unsqueeze(Un_Unsqueezecst2, Un_Unsqueezecst1) -> Un_expanded03 (name='Un_Unsqueeze1')\n", + "+kr='Un_expanded03': (1, 2, 4, 4) (dtype=float32 min=-1.0 max=1.0)\n", + "Onnx-Slice(Sh_shape0, Un_Unsqueezecst1, Sl_Slicecst, Un_Unsqueezecst1) -> Sl_output010 (name='Sl_Slice9')\n", + "+kr='Sl_output010': (1,) (dtype=int64 min=3 max=3)\n", "Onnx-Shape(Sh_shape0) -> Sh_shape01 (name='Sh_Shape1')\n", "+kr='Sh_shape01': (1,) (dtype=int64 min=3 max=3)\n", "Onnx-Gather(Sh_shape01, Un_Unsqueezecst1) -> Ga_output01 (name='Ga_Gather')\n", @@ -1500,84 +1494,82 @@ "Onnx-Concat(Co_Concatcst, Sl_output05) -> Co_concat_result0 (name='Co_Concat')\n", "+kr='Co_concat_result0': (3,) (dtype=int64 min=-1 max=4)\n", "Onnx-Reshape(x, Co_concat_result0) -> Re_reshaped0 (name='Re_Reshape')\n", - "+kr='Re_reshaped0': (3, 1, 4) (dtype=float32 min=-1.5941405296325684 max=1.1006875038146973)\n", + "+kr='Re_reshaped0': (3, 1, 4) (dtype=float32 min=-2.1212947368621826 max=1.6622426509857178)\n", "Onnx-Slice(Re_reshaped0, Sl_Slicecst2, Sl_Slicecst3, Sl_Slicecst4) -> Sl_output04 (name='Sl_Slice1')\n", - "+kr='Sl_output04': (3, 1, 4) (dtype=float32 min=-1.5941405296325684 max=1.1006875038146973)\n", + "+kr='Sl_output04': (3, 1, 4) (dtype=float32 min=-2.1212947368621826 max=1.6622426509857178)\n", "Onnx-Transpose(Sl_output04) -> Tr_transposed02 (name='Tr_Transpose')\n", - "+kr='Tr_transposed02': (3, 4, 1) (dtype=float32 min=-1.5941405296325684 max=1.1006875038146973)\n", + "+kr='Tr_transposed02': (3, 4, 1) (dtype=float32 min=-2.1212947368621826 max=1.6622426509857178)\n", "Onnx-Slice(Tr_transposed02, Un_Unsqueezecst1, Sl_Slicecst6, Sl_Slicecst7) -> Sl_output03 (name='Sl_Slice2')\n", - "+kr='Sl_output03': (3, 4, 1) (dtype=float32 min=-1.5941405296325684 max=1.1006875038146973)\n", + "+kr='Sl_output03': (3, 4, 1) (dtype=float32 min=-2.1212947368621826 max=1.6622426509857178)\n", "Onnx-Unsqueeze(Sl_output03, Sl_Slicecst7) -> Un_expanded04 (name='Un_Unsqueeze2')\n", - "+kr='Un_expanded04': (3, 1, 4, 1) (dtype=float32 min=-1.5941405296325684 max=1.1006875038146973)\n", + "+kr='Un_expanded04': (3, 1, 4, 1) (dtype=float32 min=-2.1212947368621826 max=1.6622426509857178)\n", "Onnx-MatMul(Un_expanded03, Un_expanded04) -> Ma_Y01 (name='Ma_MatMul')\n", - "+kr='Ma_Y01': (3, 2, 4, 1) (dtype=float32 min=-2.508474588394165 max=3.18086314201355)\n", + "+kr='Ma_Y01': (3, 2, 4, 1) (dtype=float32 min=-3.5156421661376953 max=2.6367990970611572)\n", "Onnx-Slice(Ma_Y01, Un_Unsqueezecst1, Sl_Slicecst9, Sl_Slicecst7) -> Sl_output02 (name='Sl_Slice3')\n", - "+kr='Sl_output02': (3, 2, 4, 1) (dtype=float32 min=-2.508474588394165 max=3.18086314201355)\n", + "+kr='Sl_output02': (3, 2, 4, 1) (dtype=float32 min=-3.5156421661376953 max=2.6367990970611572)\n", "Onnx-Transpose(Sl_output02) -> Tr_transposed01 (name='Tr_Transpose1')\n", - "+kr='Tr_transposed01': (2, 3, 1, 4) (dtype=float32 min=-2.508474588394165 max=3.18086314201355)\n", + "+kr='Tr_transposed01': (2, 3, 1, 4) (dtype=float32 min=-3.5156421661376953 max=2.6367990970611572)\n", "Onnx-Gather(Tr_transposed01, Ga_Gathercst1) -> Ga_output0 (name='Ga_Gather1')\n", - "+kr='Ga_output0': (3, 1, 4) (dtype=float32 min=-2.508474588394165 max=3.18086314201355)\n", - "Onnx-Slice(Ga_output0, Un_Unsqueezecst1, Sl_Slicecst7, Sl_Slicecst7) -> Sl_output01 (name='Sl_Slice4')\n", - "+kr='Sl_output01': (3, 1, 4) (dtype=float32 min=-2.508474588394165 max=3.18086314201355)\n", - "Onnx-Unsqueeze(Sl_output01, Sl_Slicecst7) -> Un_expanded02 (name='Un_Unsqueeze3')\n", - "+kr='Un_expanded02': (3, 1, 1, 4) (dtype=float32 min=-2.508474588394165 max=3.18086314201355)\n", - "Onnx-MatMul(Un_expanded0, Un_expanded02) -> Ma_Y0 (name='Ma_MatMul1')\n", - "+kr='Ma_Y0': (3, 2, 1, 4) (dtype=float32 min=-2.508474588394165 max=3.18086314201355)\n", - "Onnx-Transpose(Ma_Y0) -> Tr_transposed0 (name='Tr_Transpose2')\n", - "+kr='Tr_transposed0': (2, 3, 1, 4) (dtype=float32 min=-2.508474588394165 max=3.18086314201355)\n", + "+kr='Ga_output0': (3, 1, 4) (dtype=float32 min=-3.5156421661376953 max=2.6367990970611572)\n", "Onnx-Gather(Tr_transposed01, Ga_Gathercst2) -> Ga_output03 (name='Ga_Gather2')\n", - "+kr='Ga_output03': (3, 1, 4) (dtype=float32 min=-2.1299846172332764 max=2.1299846172332764)\n", + "+kr='Ga_output03': (3, 1, 4) (dtype=float32 min=-1.5755668878555298 max=1.5755668878555298)\n", + "Onnx-Slice(Ga_output0, Un_Unsqueezecst1, Sl_Slicecst7, Sl_Slicecst7) -> Sl_output01 (name='Sl_Slice4')\n", + "+kr='Sl_output01': (3, 1, 4) (dtype=float32 min=-3.5156421661376953 max=2.6367990970611572)\n", "Onnx-Slice(Ga_output03, Un_Unsqueezecst1, Sl_Slicecst7, Sl_Slicecst7) -> Sl_output07 (name='Sl_Slice5')\n", - "+kr='Sl_output07': (3, 1, 4) (dtype=float32 min=-2.1299846172332764 max=2.1299846172332764)\n", + "+kr='Sl_output07': (3, 1, 4) (dtype=float32 min=-1.5755668878555298 max=1.5755668878555298)\n", "Onnx-Unsqueeze(Sl_output07, Sl_Slicecst7) -> Un_expanded06 (name='Un_Unsqueeze5')\n", - "+kr='Un_expanded06': (3, 1, 1, 4) (dtype=float32 min=-2.1299846172332764 max=2.1299846172332764)\n", + "+kr='Un_expanded06': (3, 1, 1, 4) (dtype=float32 min=-1.5755668878555298 max=1.5755668878555298)\n", + "Onnx-Unsqueeze(Sl_output01, Sl_Slicecst7) -> Un_expanded02 (name='Un_Unsqueeze3')\n", + "+kr='Un_expanded02': (3, 1, 1, 4) (dtype=float32 min=-3.5156421661376953 max=2.6367990970611572)\n", "Onnx-MatMul(Un_expanded0, Un_expanded06) -> Ma_Y03 (name='Ma_MatMul2')\n", - "+kr='Ma_Y03': (3, 2, 1, 4) (dtype=float32 min=-2.1299846172332764 max=2.1299846172332764)\n", + "+kr='Ma_Y03': (3, 2, 1, 4) (dtype=float32 min=-1.5755668878555298 max=1.5755668878555298)\n", + "Onnx-MatMul(Un_expanded0, Un_expanded02) -> Ma_Y0 (name='Ma_MatMul1')\n", + "+kr='Ma_Y0': (3, 2, 1, 4) (dtype=float32 min=-3.5156421661376953 max=2.6367990970611572)\n", "Onnx-Transpose(Ma_Y03) -> Tr_transposed04 (name='Tr_Transpose3')\n", - "+kr='Tr_transposed04': (2, 3, 1, 4) (dtype=float32 min=-2.1299846172332764 max=2.1299846172332764)\n", + "+kr='Tr_transposed04': (2, 3, 1, 4) (dtype=float32 min=-1.5755668878555298 max=1.5755668878555298)\n", + "Onnx-Transpose(Ma_Y0) -> Tr_transposed0 (name='Tr_Transpose2')\n", + "+kr='Tr_transposed0': (2, 3, 1, 4) (dtype=float32 min=-3.5156421661376953 max=2.6367990970611572)\n", "Onnx-Slice(Tr_transposed04, Sl_Slicecst7, Sl_Slicecst18, Un_Unsqueezecst1) -> Sl_output06 (name='Sl_Slice6')\n", "+kr='Sl_output06': (1, 3, 1, 4) (dtype=float32 min=0.0 max=0.0)\n", + "Onnx-Slice(Tr_transposed04, Un_Unsqueezecst1, Sl_Slicecst7, Un_Unsqueezecst1) -> Sl_output08 (name='Sl_Slice7')\n", + "+kr='Sl_output08': (1, 3, 1, 4) (dtype=float32 min=-1.5755668878555298 max=1.5755668878555298)\n", "Onnx-Neg(Sl_output06) -> Ne_Y0 (name='Ne_Neg')\n", "+kr='Ne_Y0': (1, 3, 1, 4) (dtype=float32 min=-0.0 max=-0.0)\n", - "Onnx-Slice(Tr_transposed04, Un_Unsqueezecst1, Sl_Slicecst7, Un_Unsqueezecst1) -> Sl_output08 (name='Sl_Slice7')\n", - "+kr='Sl_output08': (1, 3, 1, 4) (dtype=float32 min=-2.1299846172332764 max=2.1299846172332764)\n", "Onnx-Concat(Ne_Y0, Sl_output08) -> Co_concat_result02 (name='Co_Concat1')\n", - "+kr='Co_concat_result02': (2, 3, 1, 4) (dtype=float32 min=-2.1299846172332764 max=2.1299846172332764)\n", + "+kr='Co_concat_result02': (2, 3, 1, 4) (dtype=float32 min=-1.5755668878555298 max=1.5755668878555298)\n", "Onnx-Add(Tr_transposed0, Co_concat_result02) -> Ad_C0 (name='Ad_Add')\n", - "+kr='Ad_C0': (2, 3, 1, 4) (dtype=float32 min=-2.508474588394165 max=3.18086314201355)\n", + "+kr='Ad_C0': (2, 3, 1, 4) (dtype=float32 min=-3.5156421661376953 max=2.6367990970611572)\n", "Onnx-Slice(Ad_C0, Sl_Slicecst2, Sl_Slicecst24, Sl_Slicecst25) -> Sl_output0 (name='Sl_Slice8')\n", - "+kr='Sl_output0': (2, 3, 1, 3) (dtype=float32 min=-2.508474588394165 max=3.18086314201355)\n", - "Onnx-Slice(Sh_shape0, Un_Unsqueezecst1, Sl_Slicecst, Un_Unsqueezecst1) -> Sl_output010 (name='Sl_Slice9')\n", - "+kr='Sl_output010': (1,) (dtype=int64 min=3 max=3)\n", - "Onnx-Shape(Sl_output0) -> Sh_shape03 (name='Sh_Shape3')\n", - "+kr='Sh_shape03': (4,) (dtype=int64 min=1 max=3)\n", - "Onnx-Shape(Sh_shape03) -> Sh_shape04 (name='Sh_Shape4')\n", - "+kr='Sh_shape04': (1,) (dtype=int64 min=4 max=4)\n", - "Onnx-Gather(Sh_shape04, Un_Unsqueezecst1) -> Ga_output04 (name='Ga_Gather3')\n", + "+kr='Sl_output0': (2, 3, 1, 3) (dtype=float32 min=-3.5156421661376953 max=2.6367990970611572)\n", + "Onnx-Shape(Sl_output0) -> Sh_shape04 (name='Sh_Shape3')\n", + "+kr='Sh_shape04': (4,) (dtype=int64 min=1 max=3)\n", + "Onnx-Shape(Sh_shape04) -> Sh_shape05 (name='Sh_Shape4')\n", + "+kr='Sh_shape05': (1,) (dtype=int64 min=4 max=4)\n", + "Onnx-Gather(Sh_shape05, Un_Unsqueezecst1) -> Ga_output04 (name='Ga_Gather3')\n", "+kr='Ga_output04': (1,) (dtype=int64 min=4 max=4)\n", - "Onnx-Slice(Sh_shape03, Sl_Slicecst, Ga_output04, Un_Unsqueezecst1) -> Sl_output012 (name='Sl_Slice10')\n", + "Onnx-Slice(Sh_shape04, Sl_Slicecst, Ga_output04, Un_Unsqueezecst1) -> Sl_output012 (name='Sl_Slice10')\n", "+kr='Sl_output012': (2,) (dtype=int64 min=1 max=3)\n", "Onnx-Concat(Sl_Slicecst18, Sl_output010, Sl_output012) -> Co_concat_result03 (name='Co_Concat2')\n", "+kr='Co_concat_result03': (4,) (dtype=int64 min=1 max=3)\n", "Onnx-Reshape(Sl_output0, Co_concat_result03) -> y (name='Re_Reshape1')\n", - "+kr='y': (2, 3, 1, 3) (dtype=float32 min=-2.508474588394165 max=3.18086314201355)\n" + "+kr='y': (2, 3, 1, 3) (dtype=float32 min=-3.5156421661376953 max=2.6367990970611572)\n" ] }, { "data": { "text/plain": [ - "{'y': array([[[[ 1.0642704e+00, 7.8808188e-02, 3.1808631e+00]],\n", + "{'y': array([[[[ 1.9479027e+00, -7.0837361e-01, -3.1971555e+00]],\n", " \n", - " [[-1.7878022e+00, -2.5084746e+00, 5.4854429e-01]],\n", + " [[-2.4413235e+00, -1.2641068e+00, -3.5156422e+00]],\n", " \n", - " [[-2.2876425e+00, 8.1763226e-01, 4.4160408e-01]]],\n", + " [[ 1.9243780e-01, 6.0331464e-01, 2.6367991e+00]]],\n", " \n", " \n", - " [[[ 0.0000000e+00, -2.1299846e+00, 7.7034396e-16]],\n", + " [[[ 0.0000000e+00, 7.5195622e-01, -7.1191992e-16]],\n", " \n", - " [[ 0.0000000e+00, 1.2344277e-01, 5.0231944e-16]],\n", + " [[ 0.0000000e+00, 1.5755669e+00, -5.3446789e-16]],\n", " \n", - " [[ 0.0000000e+00, 1.0373981e+00, -5.9766380e-18]]]],\n", + " [[ 0.0000000e+00, 5.3400773e-01, 3.3330694e-16]]]],\n", " dtype=float32)}" ] },