From eb4a568ae40101f86afdb645a84922235eb52109 Mon Sep 17 00:00:00 2001 From: liuyang_655 Date: Tue, 22 Mar 2022 06:07:29 -0400 Subject: [PATCH] code check clean --- docs/api/api_python/ops/mindspore.ops.func_arange.rst | 2 +- mindspore/ccsrc/transform/express_ir/onnx_exporter.cc | 7 +++++-- mindspore/ccsrc/transform/graph_ir/convert.cc | 4 ++-- mindspore/python/mindspore/common/tensor.py | 10 +++++++--- mindspore/python/mindspore/numpy/array_creations.py | 6 +++--- mindspore/python/mindspore/train/callback/_history.py | 1 + .../mindspore/train/callback/_lambda_callback.py | 1 + mindspore/python/mindspore/train/dataset_helper.py | 6 ++++-- 8 files changed, 24 insertions(+), 13 deletions(-) diff --git a/docs/api/api_python/ops/mindspore.ops.func_arange.rst b/docs/api/api_python/ops/mindspore.ops.func_arange.rst index 3d2b08e82b..0c054dddd2 100644 --- a/docs/api/api_python/ops/mindspore.ops.func_arange.rst +++ b/docs/api/api_python/ops/mindspore.ops.func_arange.rst @@ -10,7 +10,7 @@ mindspore.ops.arange - **start** (Union[int, float]) - 指定范围的起始值,范围包含该值。类型为int或float。 - **stop** (Union[int, float]) - 指定范围的结束值,范围不包含该值。类型为int或float。 - **step** (Union[int, float]) - 指定取值的间隔。类型为int或float。 - - **rtype** (Union[mindspore.dtype,str]) - 指定返回数据的类型,如果不指定,则会根据 `start` 、 `stop` 、 `step` 的值推断类型。 + - **rtype** (Union[mindspore.dtype, str]) - 指定返回数据的类型,如果不指定,则会根据 `start` 、 `stop` 、 `step` 的值推断类型。 **返回:** diff --git a/mindspore/ccsrc/transform/express_ir/onnx_exporter.cc b/mindspore/ccsrc/transform/express_ir/onnx_exporter.cc index d000d9c38f..7e68c4adb9 100644 --- a/mindspore/ccsrc/transform/express_ir/onnx_exporter.cc +++ b/mindspore/ccsrc/transform/express_ir/onnx_exporter.cc @@ -236,8 +236,11 @@ uint32_t Fp32ToFp16(float value) { const unsigned int FP16_E = 16 - 1 - FP16_M; uint32_t fp32_bits; - memcpy_s(reinterpret_cast(&fp32_bits), sizeof(fp32_bits), reinterpret_cast(&value), - sizeof(value)); + auto ret = memcpy_s(reinterpret_cast(&fp32_bits), sizeof(fp32_bits), + reinterpret_cast(&value), sizeof(value)); + if (ret != 0) { + MS_LOG(ERROR) << "Set data memcpy_s failed, ret = " << ret; + } uint32_t mantissa = fp32_bits & FieldMask(FP32_M); uint32_t fp32_exp_mask = FieldMask(FP32_E); diff --git a/mindspore/ccsrc/transform/graph_ir/convert.cc b/mindspore/ccsrc/transform/graph_ir/convert.cc index 923cca1e17..9a759e75ab 100644 --- a/mindspore/ccsrc/transform/graph_ir/convert.cc +++ b/mindspore/ccsrc/transform/graph_ir/convert.cc @@ -432,11 +432,11 @@ void DfGraphConvertor::BuildSaveCheckpointGraph() { size_t index = 0; string name; - size_t count_size = std::count_if(vars_.begin(), vars_.end(), [](const auto &it) { + auto count_size = std::count_if(vars_.begin(), vars_.end(), [](const auto &it) { return LongToUlong(it.second == nullptr || it.first.find("/") != std::string::npos); }); - (void)save_op.create_dynamic_input_tensors(static_cast(vars_.size() - count_size)); + (void)save_op.create_dynamic_input_tensors(static_cast(vars_.size() - static_cast(count_size))); // for each "parameter" in anf graph excluding "input" for (const auto &it : vars_) { diff --git a/mindspore/python/mindspore/common/tensor.py b/mindspore/python/mindspore/common/tensor.py index 26bdf750e8..1ed9b7696a 100644 --- a/mindspore/python/mindspore/common/tensor.py +++ b/mindspore/python/mindspore/common/tensor.py @@ -1021,8 +1021,8 @@ class Tensor(Tensor_): Return a copy of the tensor, cast to a specified type. Args: - dtype (Union[:class:`mindspore.dtype`, str]): Designated tensor dtype, can be in format - of :class:`mindspore.dtype.float32` or `float32`. + dtype (Union[:class:`mindspore.dtype`, :class:`numpy.dtype`, str]): Designated tensor dtype, can be in + format of :class:`mindspore.dtype.float32` or :class:`numpy.float32` or `float32`. copy (bool, optional): By default, astype always returns a newly allocated tensor. If this is set to false, the input tensor is returned instead of a copy. Default: True. @@ -1991,9 +1991,13 @@ class Tensor(Tensor_): v = tensor_operator_registry.get('make_tensor')(v) shape = v.shape if sorter is not None: + if not isinstance(sorter, (int, float, bool, list, tuple, Tensor)): + raise TypeError("For Tensor.searchsorted, the type of the argument 'sorter' must be one of 'int', " + "'float', 'bool', 'list', 'tuple', 'Tensor', but got {}.".format(type(sorter))) + if not isinstance(sorter, Tensor): + sorter = tensor_operator_registry.get('make_tensor')(sorter) if sorter.ndim != 1 or sorter.size != a.size: raise ValueError('sorter must be 1-D array with the same size as the Tensor') - sorter = tensor_operator_registry.get('make_tensor')(sorter) sorter = sorter.reshape(sorter.shape + (1,)) a = tensor_operator_registry.get('gather_nd')(a, sorter) less_op = tensor_operator_registry.get('__le__') if side == 'left' else tensor_operator_registry.get('__lt__') diff --git a/mindspore/python/mindspore/numpy/array_creations.py b/mindspore/python/mindspore/numpy/array_creations.py index 94114e5684..f5d35749d3 100644 --- a/mindspore/python/mindspore/numpy/array_creations.py +++ b/mindspore/python/mindspore/numpy/array_creations.py @@ -432,7 +432,7 @@ def randn(*shape, dtype=mstype.float32): Returns: Tensor, with the designated shape and dtype, filled with a sample (or samples) - from the "standard normal" distribution. + from the "standard normal" distribution. Raises: TypeError: If input arguments have types not specified above. @@ -472,7 +472,7 @@ def rand(*shape, dtype=mstype.float32): Returns: Tensor, with the designated shape and dtype, filled with random numbers from the - uniform distribution on the interval :math:`[0, 1)`. + uniform distribution on the interval :math:`[0, 1)`. Raises: TypeError: If input arguments have types not specified above. @@ -503,7 +503,7 @@ def randint(minval, maxval=None, shape=None, dtype=mstype.int32): """ Return random integers from minval (inclusive) to maxval (exclusive). Return random integers from the discrete uniform distribution of the specified dtype in the “half-open” interval :math:`[minval, maxval)`. - If maxval is None (the default), then results are from [0, maxval). + If maxval is None (the default), the value range will be [0, minval), in this case, minval must be greater than 0. Args: minval(Union[int]): Start value of interval. The interval includes this value. When `maxval` diff --git a/mindspore/python/mindspore/train/callback/_history.py b/mindspore/python/mindspore/train/callback/_history.py index 8ddf91ba24..aa30f371db 100644 --- a/mindspore/python/mindspore/train/callback/_history.py +++ b/mindspore/python/mindspore/train/callback/_history.py @@ -18,6 +18,7 @@ import numpy as np from mindspore.common.tensor import Tensor from ._callback import Callback + class History(Callback): """ Records the network outputs information into a `History` object. diff --git a/mindspore/python/mindspore/train/callback/_lambda_callback.py b/mindspore/python/mindspore/train/callback/_lambda_callback.py index 8f6c68125f..25c4c3d5a7 100644 --- a/mindspore/python/mindspore/train/callback/_lambda_callback.py +++ b/mindspore/python/mindspore/train/callback/_lambda_callback.py @@ -16,6 +16,7 @@ from ._callback import Callback + class LambdaCallback(Callback): """ Callback for creating simple, custom callbacks. diff --git a/mindspore/python/mindspore/train/dataset_helper.py b/mindspore/python/mindspore/train/dataset_helper.py index a98c224f70..98623ef522 100644 --- a/mindspore/python/mindspore/train/dataset_helper.py +++ b/mindspore/python/mindspore/train/dataset_helper.py @@ -404,8 +404,10 @@ class _DatasetIter: return self.op() def types_shapes(self): - """Return the types and shapes of the dataset. The type and shape of each data in the dataset - should be consistent.""" + """ + Return the types and shapes of the dataset. The type and shape of each data in the dataset + should be consistent. + """ return self.dataset_types, self.dataset_shapes def get_sink_count(self, dataset):