From 6d7211036545a55ed39acb7a9565d73e1d7d5475 Mon Sep 17 00:00:00 2001 From: Mateusz Bencer Date: Wed, 14 Oct 2020 10:17:44 +0200 Subject: [PATCH] Fix using numpy scalars in Python API (#2520) * fixed numpy scalars * reverted tests changes * python style fixed --- .../python/src/openvino/inference_engine/ie_api.pyx | 2 ++ inference-engine/ie_bridges/python/tests/test_Blob.py | 9 +++++++++ ngraph/python/tests/__init__.py | 2 -- ngraph/python/tests/test_onnx/test_backend.py | 18 +++--------------- ngraph/python/tests/test_onnx/test_ops_logical.py | 8 ++++---- 5 files changed, 18 insertions(+), 21 deletions(-) diff --git a/inference-engine/ie_bridges/python/src/openvino/inference_engine/ie_api.pyx b/inference-engine/ie_bridges/python/src/openvino/inference_engine/ie_api.pyx index 4da22a3..cea04fc 100644 --- a/inference-engine/ie_bridges/python/src/openvino/inference_engine/ie_api.pyx +++ b/inference-engine/ie_bridges/python/src/openvino/inference_engine/ie_api.pyx @@ -1614,6 +1614,8 @@ cdef class BlobBuffer: cdef SizeVector shape if len(representation_shape) == 0: shape = desc.getDims() + if layout_int_to_str_map[desc.getLayout()] == 'SCALAR': + shape = [1] else: shape = representation_shape cdef Py_ssize_t itemsize = deref(ptr).element_size() diff --git a/inference-engine/ie_bridges/python/tests/test_Blob.py b/inference-engine/ie_bridges/python/tests/test_Blob.py index a70c421..4a382c5 100644 --- a/inference-engine/ie_bridges/python/tests/test_Blob.py +++ b/inference-engine/ie_bridges/python/tests/test_Blob.py @@ -110,6 +110,15 @@ def test_write_to_buffer_int64(): assert np.array_equal(blob.buffer, ones_arr) +def test_write_numpy_scalar_int64(): + tensor_desc = TensorDesc("I64", [], "SCALAR") + scalar = np.array(0, dtype=np.int64) + blob = Blob(tensor_desc, scalar) + scalar_to_write = np.array(1, dtype=np.int64) + blob.buffer[:] = scalar_to_write + assert np.array_equal(blob.buffer, np.atleast_1d(scalar_to_write)) + + def test_incompatible_array_and_td(): tensor_desc = TensorDesc("FP32", [1, 3, 127, 127], "NCHW") array = np.zeros(shape=(1, 2, 3, 4), dtype=np.float32) diff --git a/ngraph/python/tests/__init__.py b/ngraph/python/tests/__init__.py index 4c78909..d926461 100644 --- a/ngraph/python/tests/__init__.py +++ b/ngraph/python/tests/__init__.py @@ -74,8 +74,6 @@ xfail_issue_35911 = xfail_test(reason="Assertion error: Pad model mismatch error xfail_issue_35912 = xfail_test(reason="RuntimeError: Error of validate layer: B with type: " "Pad. Cannot parse parameter pads_end from IR for layer B. " "Value -1,0 cannot be casted to int.") -xfail_issue_35914 = xfail_test(reason="IndexError: too many indices for array: " - "array is 0-dimensional, but 1 were indexed") xfail_issue_35915 = xfail_test(reason="RuntimeError: Eltwise node with unsupported combination " "of input and output types") xfail_issue_35916 = xfail_test(reason="RuntimeError: Unsupported input dims count for layer Z") diff --git a/ngraph/python/tests/test_onnx/test_backend.py b/ngraph/python/tests/test_onnx/test_backend.py index e73f70a..db0fb74 100644 --- a/ngraph/python/tests/test_onnx/test_backend.py +++ b/ngraph/python/tests/test_onnx/test_backend.py @@ -34,7 +34,6 @@ from tests import (BACKEND_NAME, xfail_issue_38086, xfail_issue_38087, xfail_issue_35923, - xfail_issue_35914, xfail_issue_36483, xfail_issue_34323, xfail_issue_35915, @@ -214,19 +213,6 @@ tests_expected_to_fail = [ (xfail_issue_35923, "OnnxBackendNodeModelTest.test_prelu_broadcast_cpu", "OnnxBackendNodeModelTest.test_prelu_example_cpu"), - (xfail_issue_35914, - "OnnxBackendNodeModelTest.test_dequantizelinear_cpu", - "OnnxBackendNodeModelTest.test_pow_bcast_scalar_cpu", - "OnnxBackendNodeModelTest.test_clip_example_cpu", - "OnnxBackendNodeModelTest.test_clip_inbounds_cpu", - "OnnxBackendNodeModelTest.test_clip_outbounds_cpu", - "OnnxBackendNodeModelTest.test_clip_default_int8_min_cpu", - "OnnxBackendNodeModelTest.test_clip_default_int8_max_cpu", - "OnnxBackendNodeModelTest.test_gemm_default_scalar_bias_cpu", - "OnnxBackendNodeModelTest.test_clip_cpu", - "OnnxBackendNodeModelTest.test_clip_default_max_cpu", - "OnnxBackendNodeModelTest.test_clip_default_min_cpu", - "OnnxBackendNodeModelTest.test_clip_splitbounds_cpu"), (xfail_issue_36483, "OnnxBackendNodeModelTest.test_ceil_cpu", "OnnxBackendNodeModelTest.test_ceil_example_cpu"), @@ -347,7 +333,9 @@ tests_expected_to_fail = [ "OnnxBackendNodeModelTest.test_and_bcast4v4d_cpu", "OnnxBackendNodeModelTest.test_argmin_no_keepdims_example_cpu", "OnnxBackendNodeModelTest.test_clip_default_int8_inbounds_cpu", - "OnnxBackendNodeModelTest.test_and2d_cpu"), + "OnnxBackendNodeModelTest.test_and2d_cpu", + "OnnxBackendNodeModelTest.test_clip_default_int8_min_cpu", + "OnnxBackendNodeModelTest.test_clip_default_int8_max_cpu"), (xfail_issue_38091, "OnnxBackendNodeModelTest.test_round_cpu", "OnnxBackendNodeModelTest.test_mvn_cpu", diff --git a/ngraph/python/tests/test_onnx/test_ops_logical.py b/ngraph/python/tests/test_onnx/test_ops_logical.py index c2202cc..246b52f 100644 --- a/ngraph/python/tests/test_onnx/test_ops_logical.py +++ b/ngraph/python/tests/test_onnx/test_ops_logical.py @@ -18,15 +18,15 @@ import onnx import pytest from tests.test_onnx.utils import run_node -from tests import xfail_issue_35914, xfail_issue_35915 +from tests import xfail_issue_35915 @pytest.mark.parametrize( "onnx_op, numpy_func, data_type", [ - pytest.param("And", np.logical_and, np.bool, marks=xfail_issue_35914), - pytest.param("Or", np.logical_or, np.bool, marks=xfail_issue_35914), - pytest.param("Xor", np.logical_xor, np.bool, marks=xfail_issue_35914), + pytest.param("And", np.logical_and, np.bool), + pytest.param("Or", np.logical_or, np.bool), + pytest.param("Xor", np.logical_xor, np.bool), pytest.param("Equal", np.equal, np.int32, marks=xfail_issue_35915), pytest.param("Greater", np.greater, np.int32, marks=xfail_issue_35915), pytest.param("Less", np.less, np.int32, marks=xfail_issue_35915), -- 2.7.4