From 3c61e3b7c76702bfcb4133ea826bab18025f0a33 Mon Sep 17 00:00:00 2001 From: Cathy Wong Date: Fri, 28 May 2021 14:53:02 -0400 Subject: [PATCH] MD CI code warning fixes --- .../engine/ir/datasetops/source/bindings.cc | 8 ++++---- .../dataset/api/python/pybind_conversion.cc | 2 +- .../dataset/api/python/pybind_conversion.h | 2 +- .../ccsrc/minddata/dataset/api/transforms.cc | 2 +- mindspore/ccsrc/minddata/dataset/api/vision.cc | 15 ++++++++------- .../engine/datasetops/source/image_folder_op.h | 2 +- .../minddata/dataset/kernels/ir/validators.cc | 2 +- .../minddata/dataset/kernels/ir/validators.h | 2 +- mindspore/dataset/core/validator_helpers.py | 1 + mindspore/dataset/transforms/c_transforms.py | 4 +++- mindspore/dataset/transforms/validators.py | 10 ++++++---- 11 files changed, 28 insertions(+), 22 deletions(-) diff --git a/mindspore/ccsrc/minddata/dataset/api/python/bindings/dataset/engine/ir/datasetops/source/bindings.cc b/mindspore/ccsrc/minddata/dataset/api/python/bindings/dataset/engine/ir/datasetops/source/bindings.cc index 2579236b688..fc38dc16537 100644 --- a/mindspore/ccsrc/minddata/dataset/api/python/bindings/dataset/engine/ir/datasetops/source/bindings.cc +++ b/mindspore/ccsrc/minddata/dataset/api/python/bindings/dataset/engine/ir/datasetops/source/bindings.cc @@ -241,16 +241,16 @@ PYBIND_REGISTER(TextFileNode, 2, ([](const py::module *m) { PYBIND_REGISTER(TFRecordNode, 2, ([](const py::module *m) { (void)py::class_>(*m, "TFRecordNode", "to create a TFRecordNode") - .def(py::init([](py::list dataset_files, std::shared_ptr schema, py::list columns_list, - int64_t num_samples, int32_t shuffle, int32_t num_shards, int32_t shard_id, - bool shard_equal_rows) { + .def(py::init([](const py::list dataset_files, std::shared_ptr schema, + const py::list columns_list, int64_t num_samples, int32_t shuffle, + int32_t num_shards, int32_t shard_id, bool shard_equal_rows) { std::shared_ptr tfrecord = std::make_shared( toStringVector(dataset_files), schema, toStringVector(columns_list), num_samples, toShuffleMode(shuffle), num_shards, shard_id, shard_equal_rows, nullptr); THROW_IF_ERROR(tfrecord->ValidateParams()); return tfrecord; })) - .def(py::init([](py::list dataset_files, std::string schema, py::list columns_list, + .def(py::init([](const py::list dataset_files, std::string schema, py::list columns_list, int64_t num_samples, int32_t shuffle, int32_t num_shards, int32_t shard_id, bool shard_equal_rows) { std::shared_ptr tfrecord = std::make_shared( diff --git a/mindspore/ccsrc/minddata/dataset/api/python/pybind_conversion.cc b/mindspore/ccsrc/minddata/dataset/api/python/pybind_conversion.cc index 96051b1db2b..c09c574d8fb 100644 --- a/mindspore/ccsrc/minddata/dataset/api/python/pybind_conversion.cc +++ b/mindspore/ccsrc/minddata/dataset/api/python/pybind_conversion.cc @@ -160,7 +160,7 @@ std::vector> toDatasetNode(std::shared_ptr toSamplerObj(py::handle py_sampler, bool isMindDataset) { +std::shared_ptr toSamplerObj(const py::handle py_sampler, bool isMindDataset) { if (py_sampler.is_none()) { return nullptr; } diff --git a/mindspore/ccsrc/minddata/dataset/api/python/pybind_conversion.h b/mindspore/ccsrc/minddata/dataset/api/python/pybind_conversion.h index 199549bcbbb..5fbf6bd09a1 100644 --- a/mindspore/ccsrc/minddata/dataset/api/python/pybind_conversion.h +++ b/mindspore/ccsrc/minddata/dataset/api/python/pybind_conversion.h @@ -71,7 +71,7 @@ std::shared_ptr toTensorOperation(py::handle operation); std::vector> toDatasetNode(std::shared_ptr self, py::list datasets); -std::shared_ptr toSamplerObj(py::handle py_sampler, bool isMindDataset = false); +std::shared_ptr toSamplerObj(const py::handle py_sampler, bool isMindDataset = false); std::shared_ptr toDatasetCache(std::shared_ptr cc); diff --git a/mindspore/ccsrc/minddata/dataset/api/transforms.cc b/mindspore/ccsrc/minddata/dataset/api/transforms.cc index 431a9549bcd..2b01a08de88 100644 --- a/mindspore/ccsrc/minddata/dataset/api/transforms.cc +++ b/mindspore/ccsrc/minddata/dataset/api/transforms.cc @@ -219,7 +219,7 @@ RandomChoice::RandomChoice(const std::vector &transforms) : d RandomChoice::RandomChoice(const std::vector> &transforms) : data_(std::make_shared()) { (void)std::transform(transforms.begin(), transforms.end(), std::back_inserter(data_->transforms_), - [](std::shared_ptr op) -> std::shared_ptr { + [](const std::shared_ptr op) -> std::shared_ptr { return op != nullptr ? op->Parse() : nullptr; }); } diff --git a/mindspore/ccsrc/minddata/dataset/api/vision.cc b/mindspore/ccsrc/minddata/dataset/api/vision.cc index 1e1a258abe9..0c8006d0da5 100644 --- a/mindspore/ccsrc/minddata/dataset/api/vision.cc +++ b/mindspore/ccsrc/minddata/dataset/api/vision.cc @@ -658,10 +658,10 @@ struct RandomSelectSubpolicy::Data { RandomSelectSubpolicy::RandomSelectSubpolicy( const std::vector>> &policy) : data_(std::make_shared()) { - for (int32_t i = 0; i < policy.size(); i++) { + for (uint32_t i = 0; i < policy.size(); i++) { std::vector, double>> subpolicy; - for (int32_t j = 0; j < policy[i].size(); j++) { + for (uint32_t j = 0; j < policy[i].size(); j++) { TensorTransform *op = policy[i][j].first; std::shared_ptr operation = (op ? op->Parse() : nullptr); double prob = policy[i][j].second; @@ -674,10 +674,10 @@ RandomSelectSubpolicy::RandomSelectSubpolicy( RandomSelectSubpolicy::RandomSelectSubpolicy( const std::vector, double>>> &policy) : data_(std::make_shared()) { - for (int32_t i = 0; i < policy.size(); i++) { + for (uint32_t i = 0; i < policy.size(); i++) { std::vector, double>> subpolicy; - for (int32_t j = 0; j < policy[i].size(); j++) { + for (uint32_t j = 0; j < policy[i].size(); j++) { std::shared_ptr op = policy[i][j].first; std::shared_ptr operation = (op ? op->Parse() : nullptr); double prob = policy[i][j].second; @@ -900,9 +900,10 @@ UniformAugment::UniformAugment(const std::vector &transforms, UniformAugment::UniformAugment(const std::vector> &transforms, int32_t num_ops) : data_(std::make_shared()) { - (void)std::transform( - transforms.begin(), transforms.end(), std::back_inserter(data_->transforms_), - [](std::shared_ptr op) -> std::shared_ptr { return op ? op->Parse() : nullptr; }); + (void)std::transform(transforms.begin(), transforms.end(), std::back_inserter(data_->transforms_), + [](const std::shared_ptr op) -> std::shared_ptr { + return op ? op->Parse() : nullptr; + }); data_->num_ops_ = num_ops; } diff --git a/mindspore/ccsrc/minddata/dataset/engine/datasetops/source/image_folder_op.h b/mindspore/ccsrc/minddata/dataset/engine/datasetops/source/image_folder_op.h index ff29e7f8ad0..88ecf090165 100644 --- a/mindspore/ccsrc/minddata/dataset/engine/datasetops/source/image_folder_op.h +++ b/mindspore/ccsrc/minddata/dataset/engine/datasetops/source/image_folder_op.h @@ -229,7 +229,7 @@ class ImageFolderOp : public MappableLeafOp { std::map class_index_; std::unique_ptr data_schema_; int64_t sampler_ind_; - int64_t dirname_offset_; + uint64_t dirname_offset_; std::vector image_label_pairs_; std::unique_ptr> folder_name_queue_; std::unique_ptr> image_name_queue_; diff --git a/mindspore/ccsrc/minddata/dataset/kernels/ir/validators.cc b/mindspore/ccsrc/minddata/dataset/kernels/ir/validators.cc index 60a6dcee373..6d6f31aca93 100644 --- a/mindspore/ccsrc/minddata/dataset/kernels/ir/validators.cc +++ b/mindspore/ccsrc/minddata/dataset/kernels/ir/validators.cc @@ -18,7 +18,7 @@ namespace mindspore { namespace dataset { /* ####################################### Validator Functions ############################################ */ -Status ValidateProbability(const std::string &op_name, const float probability) { +Status ValidateProbability(const std::string &op_name, const double probability) { if (probability < 0.0 || probability > 1.0) { std::string err_msg = op_name + ": probability must be between 0.0 and 1.0, got: " + std::to_string(probability); MS_LOG(ERROR) << err_msg; diff --git a/mindspore/ccsrc/minddata/dataset/kernels/ir/validators.h b/mindspore/ccsrc/minddata/dataset/kernels/ir/validators.h index 56c5a453b12..d420377bb0e 100644 --- a/mindspore/ccsrc/minddata/dataset/kernels/ir/validators.h +++ b/mindspore/ccsrc/minddata/dataset/kernels/ir/validators.h @@ -28,7 +28,7 @@ namespace mindspore { namespace dataset { // Helper function to validate probability -Status ValidateProbability(const std::string &op_name, const float probability); +Status ValidateProbability(const std::string &op_name, const double probability); // Helper function to positive int scalar Status ValidateIntScalarPositive(const std::string &op_name, const std::string &scalar_name, int32_t scalar); diff --git a/mindspore/dataset/core/validator_helpers.py b/mindspore/dataset/core/validator_helpers.py index 0eb03b68dd0..5941ba366a1 100644 --- a/mindspore/dataset/core/validator_helpers.py +++ b/mindspore/dataset/core/validator_helpers.py @@ -476,4 +476,5 @@ def check_c_tensor_op(param, param_name): def replace_none(value, default): + """Replace None value with default""" return value if value is not None else default diff --git a/mindspore/dataset/transforms/c_transforms.py b/mindspore/dataset/transforms/c_transforms.py index 94aa0abc092..45d2eee8055 100644 --- a/mindspore/dataset/transforms/c_transforms.py +++ b/mindspore/dataset/transforms/c_transforms.py @@ -50,6 +50,7 @@ class TensorOperation: return output_tensor_list[0] if len(output_tensor_list) == 1 else tuple(output_tensor_list) def parse(self): + """parse function - not yet implemented""" raise NotImplementedError("TensorOperation has to implement parse() method.") @@ -307,7 +308,8 @@ class Concatenate(TensorOperation): Args: axis (int, optional): Concatenate the tensors along given axis (Default=0). - prepend (numpy.array, optional): NumPy array to be prepended to the already concatenated tensors (Default=None). + prepend (numpy.array, optional): NumPy array to be prepended to the already concatenated tensors + (Default=None). append (numpy.array, optional): NumPy array to be appended to the already concatenated tensors (Default=None). Examples: diff --git a/mindspore/dataset/transforms/validators.py b/mindspore/dataset/transforms/validators.py index d36378ecefb..8b2c738893a 100644 --- a/mindspore/dataset/transforms/validators.py +++ b/mindspore/dataset/transforms/validators.py @@ -271,8 +271,9 @@ def check_random_apply(method): for i, transform in enumerate(transforms): if str(transform).find("c_transform") >= 0: - raise ValueError("transforms[{}] is not a py transforms. Should not use a c transform in py transform" \ - .format(i)) + raise ValueError( + "transforms[{}] is not a py transforms. Should not use a c transform in py transform" \ + .format(i)) if prob is not None: type_check(prob, (float, int,), "prob") @@ -293,8 +294,9 @@ def check_transforms_list(method): type_check(transforms, (list,), "transforms") for i, transform in enumerate(transforms): if str(transform).find("c_transform") >= 0: - raise ValueError("transforms[{}] is not a py transforms. Should not use a c transform in py transform" \ - .format(i)) + raise ValueError( + "transforms[{}] is not a py transforms. Should not use a c transform in py transform" \ + .format(i)) return method(self, *args, **kwargs) return new_method