• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
17 #ifndef MINDSPORE_CCSRC_MINDDATA_DATASET_ENGINE_IR_DATASETOPS_SKIP_NODE_H_
18 #define MINDSPORE_CCSRC_MINDDATA_DATASET_ENGINE_IR_DATASETOPS_SKIP_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 SkipNode : public DatasetNode {
30  public:
31   /// \brief Constructor
32   explicit SkipNode(std::shared_ptr<DatasetNode> child, int32_t count);
33 
34   /// \brief Destructor
35   ~SkipNode() = default;
36 
37   /// \brief Node name getter
38   /// \return Name of the current node
Name()39   std::string Name() const override { return kSkipNode; }
40 
41   /// \brief Print the description
42   /// \param out - The output stream to write output to
43   void Print(std::ostream &out) const override;
44 
45   /// \brief Copy the node to a new object
46   /// \return A shared pointer to the new copy
47   std::shared_ptr<DatasetNode> Copy() override;
48 
49   /// \brief a base class override function to create the required runtime dataset op objects for this class
50   /// \param node_ops - A vector containing shared pointer to the Dataset Ops that this object will create
51   /// \return Status Status::OK() if build successfully
52   Status Build(std::vector<std::shared_ptr<DatasetOp>> *const node_ops) override;
53 
54   /// \brief Parameters validation
55   /// \return Status Status::OK() if all the parameters are valid
56   Status ValidateParams() override;
57 
58   /// \brief Getter
59   /// \return Number of rows to skip
Count()60   const int32_t Count() const { return skip_count_; }
61 
62   /// \brief Base-class override for GetDatasetSize
63   /// \param[in] size_getter Shared pointer to DatasetSizeGetter
64   /// \param[in] estimate This is only supported by some of the ops and it's used to speed up the process of getting
65   ///     dataset size at the expense of accuracy.
66   /// \param[out] dataset_size the size of the dataset
67   /// \return Status of the function
68   Status GetDatasetSize(const std::shared_ptr<DatasetSizeGetter> &size_getter, bool estimate,
69                         int64_t *dataset_size) override;
70 
71   /// \brief Base-class override for accepting IRNodePass visitor
72   /// \param[in] p The node to visit
73   /// \param[out] modified Indicator if the node was modified
74   /// \return Status of the node visit
75   Status Accept(IRNodePass *const p, bool *const modified) override;
76 
77   /// \brief Base-class override for accepting IRNodePass visitor
78   /// \param[in] p The node to visit
79   /// \param[out] modified Indicator if the node was modified
80   /// \return Status of the node visit
81   Status AcceptAfter(IRNodePass *const p, bool *const modified) override;
82 
83   /// \brief Getter functions
SkipCount()84   int32_t SkipCount() const { return skip_count_; }
85 
86   /// \brief Get the arguments of node
87   /// \param[out] out_json JSON string of all attributes
88   /// \return Status of the function
89   Status to_json(nlohmann::json *out_json) override;
90 
91   /// \brief Function for read dataset operation from json
92   /// \param[in] json_obj The JSON object to be deserialized
93   /// \param[in] ds dataset node constructed
94   /// \param[out] result Deserialized dataset after the operation
95   /// \return Status The status code returned
96   static Status from_json(nlohmann::json json_obj, std::shared_ptr<DatasetNode> ds,
97                           std::shared_ptr<DatasetNode> *result);
98 
99  private:
100   int32_t skip_count_;
101 };
102 
103 }  // namespace dataset
104 }  // namespace mindspore
105 #endif  // MINDSPORE_CCSRC_MINDDATA_DATASET_ENGINE_IR_DATASETOPS_SKIP_NODE_H_
106