1 /** 2 * Copyright 2022 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 17 #ifndef MINDSPORE_CCSRC_UTILS_MAP_TENSOR_PY_H_ 18 #define MINDSPORE_CCSRC_UTILS_MAP_TENSOR_PY_H_ 19 20 #include <tuple> 21 #include "pybind11/numpy.h" 22 #include "ir/map_tensor.h" 23 24 namespace py = pybind11; 25 26 namespace mindspore { 27 using tensor::MapTensor; 28 using tensor::MapTensorPtr; 29 // 30 // MapTensor python adapter class. 31 // 32 class MapTensorPy { 33 public: 34 static void UpdateFromNumpy(const MapTensorPtr &map_tensor, 35 const std::tuple<py::array, py::array, py::array> &numpy_data); 36 37 static std::tuple<py::array, py::array, py::array> ExportAsNumpy(const MapTensorPtr &map_tensor, 38 bool incremental = false); 39 40 static std::tuple<py::bytes, py::bytes, py::bytes> ExportBytes(const MapTensorPtr &map_tensor, 41 bool incremental = false); 42 43 static std::tuple<py::array, py::array, py::array, bool> ExportSliceAsNumpy(const MapTensorPtr &map_tensor, 44 bool incremental = false); 45 46 static std::tuple<py::array, py::array, py::array, bool> ExportPersistentSliceAsNumpy(const MapTensorPtr &map_tensor, 47 int32_t param_key, 48 bool incremental = false); 49 }; 50 } // namespace mindspore 51 #endif // MINDSPORE_CCSRC_UTILS_MAP_TENSOR_PY_H_ 52