• 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_ENGINE_IR_DATASETOPS_MAP_NODE_H_
18 #define MINDSPORE_CCSRC_MINDDATA_DATASET_ENGINE_IR_DATASETOPS_MAP_NODE_H_
19 
20 #include <memory>
21 #include <string>
22 #include <vector>
23 
24 #include "minddata/dataset/engine/ir/datasetops/dataset_node.h"
25 
26 namespace mindspore {
27 namespace dataset {
28 
29 class MapNode : public DatasetNode {
30  public:
31   /// \brief Constructor
32   MapNode(std::shared_ptr<DatasetNode> child, std::vector<std::shared_ptr<TensorOperation>> operations,
33           std::vector<std::string> input_columns = {}, std::vector<std::string> output_columns = {},
34           const std::vector<std::string> &columns = {}, std::shared_ptr<DatasetCache> cache = nullptr,
35           std::vector<std::shared_ptr<DSCallback>> callbacks = {});
36 
37   /// \brief Destructor
38   ~MapNode() = default;
39 
40   /// \brief Node name getter
41   /// \return Name of the current node
Name()42   std::string Name() const override { return kMapNode; }
43 
44   /// \brief Print the description
45   /// \param out - The output stream to write output to
46   void Print(std::ostream &out) const override;
47 
48   /// \brief Copy the node to a new object
49   /// \return A shared pointer to the new copy
50   std::shared_ptr<DatasetNode> Copy() override;
51 
52   /// \brief a base class override function to create the required runtime dataset op objects for this class
53   /// \param node_ops - A vector containing shared pointer to the Dataset Ops that this object will create
54   /// \return Status Status::OK() if build successfully
55   Status Build(std::vector<std::shared_ptr<DatasetOp>> *const node_ops) override;
56 
57   /// \brief Parameters validation
58   /// \return Status Status::OK() if all the parameters are valid
59   Status ValidateParams() override;
60 
61   /// \brief Base-class override for accepting IRNodePass visitor
62   /// \param[in] p The node to visit
63   /// \param[out] modified Indicator if the node was modified
64   /// \return Status of the node visit
65   Status Accept(IRNodePass *const p, bool *const modified) override;
66 
67   /// \brief Base-class override for accepting IRNodePass visitor
68   /// \param[in] p The node to visit
69   /// \param[out] modified Indicator if the node was modified
70   /// \return Status of the node visit
71   Status AcceptAfter(IRNodePass *const p, bool *const modified) override;
72 
73   /// \brief clear all callbacks
ClearCallbacks()74   void ClearCallbacks() { callbacks_.clear(); }
75 
76   /// \brief getter to get all tensor operations
77   std::vector<std::shared_ptr<TensorOperation>> operations();
78 
79   /// \brief setter to set all tensor operations
80   void setOperations(const std::vector<std::shared_ptr<TensorOperation>> &operations);
81 
82   /// \brief Getter functions
83   /// \brief Getter of tensor operations
84   /// \return Vector of operations the Map node will process
TensorOperations()85   const auto &TensorOperations() const { return operations_; }
InputColumns()86   const std::vector<std::string> &InputColumns() const { return input_columns_; }
OutputColumns()87   const std::vector<std::string> &OutputColumns() const { return output_columns_; }
ProjectColumns()88   const std::vector<std::string> &ProjectColumns() const { return project_columns_; }
Callbacks()89   const std::vector<std::shared_ptr<DSCallback>> &Callbacks() const { return callbacks_; }
90 
91   /// \brief Get the arguments of node
92   /// \param[out] out_json JSON string of all attributes
93   /// \return Status of the function
94   Status to_json(nlohmann::json *out_json) override;
95 
96 #ifndef ENABLE_ANDROID
97   /// \brief Function for read dataset operation from json
98   /// \param[in] json_obj The JSON object to be deserialized
99   /// \param[in] ds dataset node constructed
100   /// \param[out] result Deserialized dataset after the operation
101   /// \return Status The status code returned
102   static Status from_json(nlohmann::json json_obj, std::shared_ptr<DatasetNode> ds,
103                           std::shared_ptr<DatasetNode> *result);
104 #endif
105 
106   /// \brief Base-class override for GetDatasetSize
107   /// \param[in] size_getter Shared pointer to DatasetSizeGetter
108   /// \param[in] estimate This is only supported by some of the ops and it's used to speed up the process of getting
109   ///     dataset size at the expense of accuracy.
110   /// \param[out] dataset_size the size of the dataset
111   /// \return Status of the function
112   Status GetDatasetSize(const std::shared_ptr<DatasetSizeGetter> &size_getter, bool estimate,
113                         int64_t *dataset_size) override;
114 
115  private:
116   std::vector<std::shared_ptr<TensorOperation>> operations_;
117   std::vector<std::string> input_columns_;
118   std::vector<std::string> output_columns_;
119   std::vector<std::string> project_columns_;
120   std::vector<std::shared_ptr<DSCallback>> callbacks_;
121 };
122 
123 }  // namespace dataset
124 }  // namespace mindspore
125 #endif  // MINDSPORE_CCSRC_MINDDATA_DATASET_ENGINE_IR_DATASETOPS_MAP_NODE_H_
126