def test_partial_shape_equals(): ps1 = PartialShape.dynamic() ps2 = PartialShape.dynamic() assert ps1 == ps2 ps1 = PartialShape([1, 2, 3]) ps2 = PartialShape([1, 2, 3]) assert ps1 == ps2 shape = Shape([1, 2, 3]) ps = PartialShape([1, 2, 3]) assert shape == ps
def test_all_predicates(): static_param = opset8.parameter(PartialShape([1, 3, 22, 22]), np.float32) dynamic_param = opset8.parameter(PartialShape([-1, 6]), np.long) fully_dynamic_param = opset8.parameter(PartialShape.dynamic()) assert Matcher(WrapType("opset8.Parameter", consumers_count(0)), "Test").match(static_param) assert not Matcher(WrapType("opset8.Parameter", consumers_count(1)), "Test").match(static_param) assert Matcher(WrapType("opset8.Parameter", has_static_dim(1)), "Test").match(static_param) assert not Matcher(WrapType("opset8.Parameter", has_static_dim(0)), "Test").match(dynamic_param) assert Matcher(WrapType("opset8.Parameter", has_static_dims([0, 3])), "Test").match(static_param) assert not Matcher(WrapType("opset8.Parameter", has_static_dims([0, 1])), "Test").match(dynamic_param) assert Matcher(WrapType("opset8.Parameter", has_static_shape()), "Test").match(static_param) assert not Matcher(WrapType("opset8.Parameter", has_static_shape()), "Test").match(dynamic_param) assert Matcher(WrapType("opset8.Parameter", has_static_rank()), "Test").match(dynamic_param) assert not Matcher(WrapType("opset8.Parameter", has_static_rank()), "Test").match(fully_dynamic_param) assert Matcher(WrapType("opset8.Parameter", type_matches(get_element_type(np.float32))), "Test").match(static_param) assert not Matcher(WrapType("opset8.Parameter", type_matches(get_element_type(np.float32))), "Test").match(dynamic_param) assert Matcher(WrapType("opset8.Parameter", type_matches_any([get_element_type(np.float32), get_element_type(np.long)])), "Test").match(static_param) assert Matcher(WrapType("opset8.Parameter", type_matches_any([get_element_type(np.float32), get_element_type(np.long)])), "Test").match(dynamic_param)
def test_partial_shape_same_scheme(): ps1 = PartialShape([1, 2, -1]) ps2 = PartialShape([1, 3, -1]) assert not ps1.same_scheme(ps2) ps1 = PartialShape([1, 2, -1]) ps2 = PartialShape([1, 2, -1]) assert ps1.same_scheme(ps2) ps1 = PartialShape([1, 2, 3]) ps2 = PartialShape([1, 2, 3]) assert ps1.same_scheme(ps2) ps1 = PartialShape([-1, 2, 3]) ps2 = PartialShape([1, -1, 3]) assert not ps1.same_scheme(ps2) ps1 = PartialShape.dynamic() ps2 = PartialShape.dynamic() assert ps1.same_scheme(ps2)
def test_partial_shape_compatible(): ps1 = PartialShape.dynamic() ps2 = PartialShape.dynamic() assert ps1.compatible(ps2) ps1 = PartialShape([3]) ps2 = PartialShape.dynamic() assert ps1.compatible(ps2) ps1 = PartialShape.dynamic() ps2 = PartialShape([4]) assert ps1.compatible(ps2) ps1 = PartialShape([2, -1, 3, -1, 5]) ps2 = PartialShape([2, -1, -1, 4, 5]) assert ps1.compatible(ps2) ps1 = PartialShape([2, -1, 3, -1, 5]) ps2 = PartialShape([1, -1, -1, 4, 5]) assert not ps1.compatible(ps2)
def test_partial_shape_refinement(): ps1 = PartialShape.dynamic() ps2 = PartialShape.dynamic() assert ps1.refines(ps2) assert ps1.relaxes(ps2) assert ps2.refines(ps1) assert ps2.relaxes(ps1) ps1 = PartialShape.dynamic() ps2 = PartialShape([3, -1, 7, 9]) assert not ps1.refines(ps2) assert ps1.relaxes(ps2) assert ps2.refines(ps1) assert not ps2.relaxes(ps1) ps1 = PartialShape.dynamic() ps2 = PartialShape([3, 5, 7, 9]) assert not ps1.refines(ps2) assert ps1.relaxes(ps2) assert ps2.refines(ps1) assert not ps2.relaxes(ps1)
def test_partial_shape(): ps = PartialShape([1, 2, 3, 4]) assert ps.is_static assert not ps.is_dynamic assert ps.rank == 4 assert repr(ps) == "<PartialShape: {1,2,3,4}>" assert ps.get_dimension(0) == Dimension(1) assert ps.get_dimension(1) == Dimension(2) assert ps.get_dimension(2) == Dimension(3) assert ps.get_dimension(3) == Dimension(4) shape = Shape([1, 2, 3]) ps = PartialShape(shape) assert ps.is_static assert not ps.is_dynamic assert ps.all_non_negative assert ps.rank == 3 assert list(ps.get_shape()) == [1, 2, 3] assert list(ps.get_max_shape()) == [1, 2, 3] assert list(ps.get_min_shape()) == [1, 2, 3] assert list(ps.to_shape()) == [1, 2, 3] assert repr(shape) == "<Shape: {1, 2, 3}>" assert repr(ps) == "<PartialShape: {1,2,3}>" ps = PartialShape( [Dimension(1), Dimension(2), Dimension(3), Dimension.dynamic()]) assert not ps.is_static assert ps.is_dynamic assert ps.all_non_negative assert ps.rank == 4 assert list(ps.get_min_shape()) == [1, 2, 3, 0] assert list(ps.get_max_shape())[3] > 1000000000 assert repr(ps) == "<PartialShape: {1,2,3,?}>" assert ps.get_dimension(0) == Dimension(1) assert ps.get_dimension(1) == Dimension(2) assert ps.get_dimension(2) == Dimension(3) assert ps.get_dimension(3) == Dimension.dynamic() ps = PartialShape([1, 2, 3, -1]) assert not ps.is_static assert ps.is_dynamic assert ps.all_non_negative assert ps.rank == 4 assert list(ps.get_min_shape()) == [1, 2, 3, 0] assert list(ps.get_max_shape())[3] > 1000000000 assert repr(ps) == "<PartialShape: {1,2,3,?}>" ps = PartialShape.dynamic() assert not ps.is_static assert ps.is_dynamic assert ps.rank == Dimension.dynamic() assert list(ps.get_min_shape()) == [] assert list(ps.get_max_shape()) == [] assert repr(ps) == "<PartialShape: ...>" ps = PartialShape.dynamic(rank=Dimension(2)) assert not ps.is_static assert ps.is_dynamic assert ps.rank == 2 assert 2 == ps.rank assert list(ps.get_min_shape()) == [0, 0] assert list(ps.get_max_shape())[0] > 1000000000 assert repr(ps) == "<PartialShape: {?,?}>"
def test_partial_shape(): ps = PartialShape([1, 2, 3, 4]) assert ps.is_static assert not ps.is_dynamic assert ps.rank == 4 assert repr(ps) == "<PartialShape: {1,2,3,4}>" assert ps.get_dimension(0) == Dimension(1) assert ps.get_dimension(1) == Dimension(2) assert ps.get_dimension(2) == Dimension(3) assert ps.get_dimension(3) == Dimension(4) shape = Shape([1, 2, 3]) ps = PartialShape(shape) assert ps.is_static assert not ps.is_dynamic assert ps.all_non_negative assert ps.rank == 3 assert list(ps.get_shape()) == [1, 2, 3] assert list(ps.get_max_shape()) == [1, 2, 3] assert list(ps.get_min_shape()) == [1, 2, 3] assert list(ps.to_shape()) == [1, 2, 3] assert repr(shape) == "<Shape: {1, 2, 3}>" assert repr(ps) == "<PartialShape: {1,2,3}>" ps = PartialShape( [Dimension(1), Dimension(2), Dimension(3), Dimension.dynamic()]) assert not ps.is_static assert ps.is_dynamic assert ps.all_non_negative assert ps.rank == 4 assert list(ps.get_min_shape()) == [1, 2, 3, 0] assert list(ps.get_max_shape())[3] > 1000000000 assert repr(ps) == "<PartialShape: {1,2,3,?}>" assert ps.get_dimension(0) == Dimension(1) assert ps.get_dimension(1) == Dimension(2) assert ps.get_dimension(2) == Dimension(3) assert ps.get_dimension(3) == Dimension.dynamic() ps = PartialShape([1, 2, 3, -1]) assert not ps.is_static assert ps.is_dynamic assert ps.all_non_negative assert ps.rank == 4 assert list(ps.get_min_shape()) == [1, 2, 3, 0] assert list(ps.get_max_shape())[3] > 1000000000 assert repr(ps) == "<PartialShape: {1,2,3,?}>" ps = PartialShape.dynamic() assert not ps.is_static assert ps.is_dynamic assert ps.rank == Dimension.dynamic() assert list(ps.get_min_shape()) == [] assert list(ps.get_max_shape()) == [] assert repr(ps) == "<PartialShape: ...>" ps = PartialShape.dynamic(rank=Dimension(2)) assert not ps.is_static assert ps.is_dynamic assert ps.rank == 2 assert 2 == ps.rank assert list(ps.get_min_shape()) == [0, 0] assert list(ps.get_max_shape())[0] > 1000000000 assert repr(ps) == "<PartialShape: {?,?}>" shape_list = [(1, 10), [2, 5], 4, Dimension(2), "..10"] ref_ps = PartialShape([ Dimension(1, 10), Dimension(2, 5), Dimension(4), Dimension(2), Dimension(-1, 10) ]) assert PartialShape(shape_list) == ref_ps assert PartialShape(tuple(shape_list)) == ref_ps with pytest.raises(TypeError) as e: PartialShape([(1, 2, 3)]) assert "Two elements are expected in tuple(lower, upper) " \ "for dynamic dimension, but 3 elements were given." in str(e.value) with pytest.raises(TypeError) as e: PartialShape([("?", "?")]) assert "Incorrect pair of types (<class 'str'>, <class 'str'>) " \ "for dynamic dimension, ints are expected." in str(e.value) with pytest.raises(TypeError) as e: PartialShape([range(10)]) assert "Incorrect type <class 'range'> for dimension. Expected types are: " \ "int, str, openvino.runtime.Dimension, list/tuple with lower " \ "and upper values for dynamic dimension." in str(e.value) ps = PartialShape("...") assert ps == PartialShape.dynamic() ps = PartialShape("?, 3, ..224, 28..224") assert ps == PartialShape( [Dimension(-1), Dimension(3), Dimension(-1, 224), Dimension(28, 224)]) with pytest.raises(RuntimeError) as e: ps = PartialShape("?,,3") assert 'Cannot get vector of dimensions! "?,,3" is incorrect' in str( e.value) shape = Shape() assert len(shape) == 0