1 /** 2 * Copyright 2020 Huawei Technologies Co., Ltd 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 #ifndef MINDSPORE_CCSRC_PYBIND_API_IR_BASE_REF_PY_H_ 17 #define MINDSPORE_CCSRC_PYBIND_API_IR_BASE_REF_PY_H_ 18 19 #include <memory> 20 #include <string> 21 #include <utility> 22 23 #include "pybind11/pybind11.h" 24 #include "base/base_ref.h" 25 26 namespace py = pybind11; 27 28 namespace mindspore { 29 30 class PyObjectRef : public BaseRef { 31 public: PyObjectRef(const py::object & py_object)32 explicit PyObjectRef(const py::object &py_object) : BaseRef(), object_(py_object) {} PyObjectRef(const py::tuple & tuple_obj)33 explicit PyObjectRef(const py::tuple &tuple_obj) : BaseRef(), object_(tuple_obj) {} 34 35 ~PyObjectRef() override = default; 36 copy()37 std::shared_ptr<Base> copy() const override { return std::make_shared<PyObjectRef>(object_); } MS_DECLARE_PARENT(PyObjectRef,BaseRef)38 MS_DECLARE_PARENT(PyObjectRef, BaseRef) 39 40 uint32_t type() const override { return tid(); } ToString()41 std::string ToString() const override { return py::str(object_); } 42 bool operator==(const BaseRef &other) const override; 43 bool operator==(const PyObjectRef &other) const; 44 45 py::object object_; 46 }; 47 } // namespace mindspore 48 49 #endif // MINDSPORE_CCSRC_PYBIND_API_IR_BASE_REF_PY_H_ 50