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_SOURCE_SAMPLERS_SUBSET_SAMPLER_IR_H_ 18 #define MINDSPORE_CCSRC_MINDDATA_DATASET_ENGINE_IR_DATASETOPS_SOURCE_SAMPLERS_SUBSET_SAMPLER_IR_H_ 19 20 #include <limits> 21 #include <memory> 22 #include <string> 23 #include <utility> 24 #include <vector> 25 #include <nlohmann/json.hpp> 26 27 #include "minddata/dataset/engine/ir/datasetops/source/samplers/samplers_ir.h" 28 #include "include/api/status.h" 29 #ifndef ENABLE_ANDROID 30 #include "minddata/mindrecord/include/shard_operator.h" 31 #endif 32 33 namespace mindspore { 34 namespace dataset { 35 36 // Internal Sampler class forward declaration 37 class SamplerRT; 38 39 class SubsetSamplerObj : public SamplerObj { 40 public: 41 SubsetSamplerObj(std::vector<int64_t> indices, int64_t num_samples); 42 43 ~SubsetSamplerObj(); 44 45 Status SamplerBuild(std::shared_ptr<SamplerRT> *sampler) override; 46 47 std::shared_ptr<SamplerObj> SamplerCopy() override; 48 49 #ifndef ENABLE_ANDROID 50 std::shared_ptr<mindrecord::ShardOperator> BuildForMindDataset() override; 51 #endif 52 53 /// \brief Get the arguments of node 54 /// \param[out] out_json JSON string of all attributes 55 /// \return Status of the function 56 Status to_json(nlohmann::json *const out_json) override; 57 58 #ifndef ENABLE_ANDROID 59 /// \brief Function for read sampler from JSON object 60 /// \param[in] json_obj JSON object to be read 61 /// \param[in] num_samples number of sample in the sampler 62 /// \param[out] sampler Sampler constructed from parameters in JSON object 63 /// \return Status of the function 64 static Status from_json(nlohmann::json json_obj, int64_t num_samples, std::shared_ptr<SamplerObj> *sampler); 65 #endif 66 67 Status ValidateParams() override; 68 69 protected: 70 const std::vector<int64_t> indices_; 71 int64_t num_samples_; 72 }; 73 74 } // namespace dataset 75 } // namespace mindspore 76 #endif // MINDSPORE_CCSRC_MINDDATA_DATASET_ENGINE_IR_DATASETOPS_SOURCE_SAMPLERS_SUBSET_SAMPLER_IR_H_ 77