def test_ngraph_function_api(): shape = [2, 2] parameter_a = ops.parameter(shape, dtype=np.float32, name="A") parameter_b = ops.parameter(shape, dtype=np.float32, name="B") parameter_c = ops.parameter(shape, dtype=np.float32, name="C") model = (parameter_a + parameter_b) * parameter_c function = Function(model, [parameter_a, parameter_b, parameter_c], "TestFunction") function.get_parameters()[1].set_partial_shape(PartialShape([3, 4, 5])) ordered_ops = function.get_ordered_ops() op_types = [op.get_type_name() for op in ordered_ops] assert op_types == [ "Parameter", "Parameter", "Parameter", "Add", "Multiply", "Result" ] assert len(function.get_ops()) == 6 assert function.get_output_size() == 1 assert function.get_output_op(0).get_type_name() == "Result" assert function.get_output_element_type( 0) == parameter_a.get_element_type() assert list(function.get_output_shape(0)) == [2, 2] assert (function.get_parameters()[1].get_partial_shape()) == PartialShape( [3, 4, 5]) assert len(function.get_parameters()) == 3 assert len(function.get_results()) == 1 assert function.get_friendly_name() == "TestFunction"
def test_sink_function_ctor(): input_data = ops.parameter([2, 2], name="input_data", dtype=np.float32) rv = ops.read_value(input_data, "var_id_667") add = ops.add(rv, input_data, name="MemoryAdd") node = ops.assign(add, "var_id_667") res = ops.result(add, "res") function = Function(results=[res], sinks=[node], parameters=[input_data], name="TestFunction") ordered_ops = function.get_ordered_ops() op_types = [op.get_type_name() for op in ordered_ops] assert op_types == ["Parameter", "ReadValue", "Add", "Assign", "Result"] assert len(function.get_ops()) == 5 assert function.get_output_size() == 1 assert function.get_output_op(0).get_type_name() == "Result" assert function.get_output_element_type(0) == input_data.get_element_type() assert list(function.get_output_shape(0)) == [2, 2] assert (function.get_parameters()[0].get_partial_shape()) == PartialShape([2, 2]) assert len(function.get_parameters()) == 1 assert len(function.get_results()) == 1 assert function.get_friendly_name() == "TestFunction"
def test_ngraph_function_api(): shape = [2, 2] parameter_a = ops.parameter(shape, dtype=np.float32, name="A") parameter_b = ops.parameter(shape, dtype=np.float32, name="B") parameter_c = ops.parameter(shape, dtype=np.float32, name="C") model = (parameter_a + parameter_b) * parameter_c assert parameter_a.element_type == Type.f32 assert parameter_a.partial_shape == PartialShape([2, 2]) parameter_a.layout = ov.Layout("NCWH") assert parameter_a.layout == ov.Layout("NCWH") function = Function(model, [parameter_a, parameter_b, parameter_c], "TestFunction") function.get_parameters()[1].set_partial_shape(PartialShape([3, 4, 5])) ordered_ops = function.get_ordered_ops() op_types = [op.get_type_name() for op in ordered_ops] assert op_types == ["Parameter", "Parameter", "Parameter", "Add", "Multiply", "Result"] assert len(function.get_ops()) == 6 assert function.get_output_size() == 1 assert ["A", "B", "C"] == [input.get_node().friendly_name for input in function.inputs] assert ["Result"] == [output.get_node().get_type_name() for output in function.outputs] assert function.input(0).get_node().friendly_name == "A" assert function.output(0).get_node().get_type_name() == "Result" assert function.input(tensor_name="A").get_node().friendly_name == "A" assert function.output().get_node().get_type_name() == "Result" assert function.get_output_op(0).get_type_name() == "Result" assert function.get_output_element_type(0) == parameter_a.get_element_type() assert list(function.get_output_shape(0)) == [2, 2] assert (function.get_parameters()[1].get_partial_shape()) == PartialShape([3, 4, 5]) assert len(function.get_parameters()) == 3 results = function.get_results() assert len(results) == 1 assert results[0].get_output_element_type(0) == Type.f32 assert results[0].get_output_partial_shape(0) == PartialShape([2, 2]) results[0].layout = ov.Layout("NC") assert results[0].layout.to_string() == ov.Layout("NC") assert function.get_friendly_name() == "TestFunction"
def __init__(self, runtime: Runtime, ng_function: Function) -> None: self.runtime = runtime self.function = ng_function self.parameters = ng_function.get_parameters() self.results = ng_function.get_results() self.network_cache = {}