1 /** 2 * Copyright 2019-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_MINDRECORD_INCLUDE_SHARD_SAMPLE_H_ 18 #define MINDSPORE_CCSRC_MINDDATA_MINDRECORD_INCLUDE_SHARD_SAMPLE_H_ 19 20 #include <memory> 21 #include <string> 22 #include <utility> 23 #include <vector> 24 #include "minddata/mindrecord/include/shard_operator.h" 25 #include "minddata/mindrecord/include/shard_shuffle.h" 26 27 namespace mindspore { 28 namespace mindrecord { 29 class __attribute__((visibility("default"))) ShardSample : public ShardOperator { 30 public: 31 explicit ShardSample(int n); 32 33 ShardSample(int num, int den); 34 35 ShardSample(int num, int den, int par, int no_of_samples = 0, int offset = -1); 36 37 ShardSample(const std::vector<int64_t> &indices); 38 39 ShardSample(const std::vector<int64_t> &indices, uint32_t seed); 40 ~ShardSample()41 ~ShardSample() override{}; 42 43 Status Execute(ShardTaskList &tasks) override; 44 45 Status UpdateTasks(ShardTaskList &tasks, int taking); 46 47 Status SufExecute(ShardTaskList &tasks) override; 48 49 int64_t GetNumSamples(int64_t dataset_size, int64_t num_classes) override; 50 51 protected: 52 int numerator_; 53 int denominator_; 54 int partition_id_; 55 int no_of_samples_; 56 std::shared_ptr<ShardShuffle> shuffle_op_; 57 std::vector<int64_t> nums_per_shard_; 58 59 private: 60 std::vector<int64_t> indices_; 61 SamplerType sampler_type_; 62 int offset_; 63 }; 64 } // namespace mindrecord 65 } // namespace mindspore 66 67 #endif // MINDSPORE_CCSRC_MINDDATA_MINDRECORD_INCLUDE_SHARD_SAMPLE_H_ 68