• 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_KERNELS_IR_TENSOR_OPERATION_H_
18 #define MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IR_TENSOR_OPERATION_H_
19 
20 #include <memory>
21 #include <string>
22 
23 #include "minddata/dataset/kernels/tensor_op.h"
24 #include "minddata/dataset/util/status.h"
25 
26 namespace mindspore {
27 namespace dataset {
28 // Abstract class to represent a dataset in the data pipeline.
29 class TensorOperation : public std::enable_shared_from_this<TensorOperation> {
30  public:
31   /// \brief Constructor
TensorOperation()32   TensorOperation() : random_op_(false) {}
33 
34   /// \brief Constructor
TensorOperation(bool random)35   explicit TensorOperation(bool random) : random_op_(random) {}
36 
37   /// \brief Destructor
38   ~TensorOperation() = default;
39 
40   /// \brief Pure virtual function to convert a TensorOperation class into a runtime TensorOp object.
41   /// \return shared pointer to the newly created TensorOp.
42   virtual std::shared_ptr<TensorOp> Build() = 0;
43 
ValidateParams()44   virtual Status ValidateParams() { return Status::OK(); }
45 
46   virtual std::string Name() const = 0;
47 
48   /// \brief Check whether the operation is deterministic.
49   /// \return true if this op is a random op (returns non-deterministic result e.g. RandomCrop)
IsRandomOp()50   bool IsRandomOp() const { return random_op_; }
51 
to_json(nlohmann::json * out_json)52   virtual Status to_json(nlohmann::json *out_json) { return Status::OK(); }
53 
54  protected:
55   bool random_op_;
56 };
57 }  // namespace dataset
58 }  // namespace mindspore
59 #endif  // MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IR_TENSOR_OPERATION_H_
60