function.cpp 2.64 KB
Newer Older
1
//*****************************************************************************
2
// Copyright 2017-2019 Intel Corporation
3 4 5 6 7 8 9 10 11 12 13 14 15
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//*****************************************************************************
16 17 18

#include <pybind11/pybind11.h>
#include <pybind11/stl.h>
19

20 21
#include "ngraph/function.hpp"     // ngraph::Function
#include "ngraph/op/parameter.hpp" // ngraph::op::Parameter
22 23 24 25 26 27 28
#include "pyngraph/function.hpp"

namespace py = pybind11;

void regclass_pyngraph_Function(py::module m)
{
    py::class_<ngraph::Function, std::shared_ptr<ngraph::Function>> function(m, "Function");
29
    function.doc() = "ngraph.impl.Function wraps ngraph::Function";
30
    function.def(py::init<const std::vector<std::shared_ptr<ngraph::Node>>&,
31 32 33 34 35 36 37 38 39 40 41 42
                          const std::vector<std::shared_ptr<ngraph::op::Parameter>>&,
                          const std::string&>());
    function.def(py::init<const std::shared_ptr<ngraph::Node>&,
                          const std::vector<std::shared_ptr<ngraph::op::Parameter>>&,
                          const std::string&>());
    function.def("get_output_size", &ngraph::Function::get_output_size);
    function.def("get_output_op", &ngraph::Function::get_output_op);
    function.def("get_output_element_type", &ngraph::Function::get_output_element_type);
    function.def("get_output_shape", &ngraph::Function::get_output_shape);
    function.def("get_parameters", &ngraph::Function::get_parameters);
    function.def("get_results", &ngraph::Function::get_results);
    function.def("get_result", &ngraph::Function::get_result);
43 44
    function.def("get_unique_name", &ngraph::Function::get_name);
    function.def("get_name", &ngraph::Function::get_friendly_name);
45
    function.def("set_friendly_name", &ngraph::Function::set_friendly_name);
46 47 48 49 50 51
    function.def("__repr__", [](const ngraph::Function& self) {
        std::string class_name = py::cast(self).get_type().attr("__name__").cast<std::string>();
        std::string shape =
            py::cast(self.get_output_shape(0)).attr("__str__")().cast<std::string>();
        return "<" + class_name + ": '" + self.get_friendly_name() + "' (" + shape + ")>";
    });
52
}