• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright 2020-2021 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_MINDDATA_DATASET_API_PYTHON_PYBIND_CONVERSION_H_
18 #define MINDSPORE_CCSRC_MINDDATA_DATASET_API_PYTHON_PYBIND_CONVERSION_H_
19 
20 #include <algorithm>
21 #include <map>
22 #include <memory>
23 #include <set>
24 #include <string>
25 #include <utility>
26 #include <unordered_map>
27 #include <vector>
28 #include "pybind11/pybind11.h"
29 #include "pybind11/stl.h"
30 #include "pybind11/stl_bind.h"
31 #include "minddata/dataset/api/python/pybind_register.h"
32 #include "minddata/dataset/core/type_id.h"
33 #include "minddata/dataset/engine/ir/cache/pre_built_dataset_cache.h"
34 #include "minddata/dataset/engine/ir/datasetops/source/csv_node.h"
35 #include "minddata/dataset/include/dataset/datasets.h"
36 #include "minddata/dataset/engine/ir/datasetops/source/samplers/samplers_ir.h"
37 #include "minddata/dataset/engine/ir/datasetops/source/samplers/prebuilt_sampler_ir.h"
38 #include "minddata/dataset/kernels/ir/data/transforms_ir.h"
39 #include "minddata/dataset/kernels/py_func_op.h"
40 namespace py = pybind11;
41 
42 namespace mindspore {
43 namespace dataset {
44 float toFloat(const py::handle &handle);
45 
46 int toInt(const py::handle &handle);
47 
48 int64_t toInt64(const py::handle &handle);
49 
50 bool toBool(const py::handle &handle);
51 
52 std::string toString(const py::handle &handle);
53 
54 std::set<std::string> toStringSet(const py::list list);
55 
56 std::map<std::string, int32_t> toStringMap(const py::dict dict);
57 
58 std::vector<std::string> toStringVector(const py::list list);
59 
60 std::vector<pid_t> toIntVector(const py::list input_list);
61 
62 std::unordered_map<int32_t, std::vector<pid_t>> toIntMap(const py::dict input_dict);
63 
64 std::pair<int64_t, int64_t> toIntPair(const py::tuple tuple);
65 
66 std::vector<std::pair<int, int>> toPairVector(const py::list list);
67 
68 std::vector<std::shared_ptr<TensorOperation>> toTensorOperations(py::list operations);
69 
70 std::shared_ptr<TensorOperation> toTensorOperation(py::handle operation);
71 
72 std::vector<std::shared_ptr<DatasetNode>> toDatasetNode(std::shared_ptr<DatasetNode> self, py::list datasets);
73 
74 std::shared_ptr<SamplerObj> toSamplerObj(const py::handle py_sampler, bool isMindDataset = false);
75 
76 std::shared_ptr<DatasetCache> toDatasetCache(std::shared_ptr<CacheClient> cc);
77 
78 ShuffleMode toShuffleMode(const int32_t shuffle);
79 
80 std::vector<std::shared_ptr<CsvBase>> toCSVBase(py::list csv_bases);
81 
82 std::shared_ptr<TensorOp> toPyFuncOp(py::object func, DataType::Type data_type);
83 
84 Status ToJson(const py::handle &padded_sample, nlohmann::json *const padded_sample_json,
85               std::map<std::string, std::string> *sample_bytes);
86 
87 Status toPadInfo(py::dict value, std::map<std::string, std::pair<TensorShape, std::shared_ptr<Tensor>>> *pad_info);
88 
89 py::list shapesToListOfShape(std::vector<TensorShape> shapes);
90 
91 py::list typesToListOfType(std::vector<DataType> types);
92 
93 }  // namespace dataset
94 }  // namespace mindspore
95 #endif  // MINDSPORE_CCSRC_MINDDATA_DATASET_API_PYTHON_PYBIND_CONVERSION_H_
96