Browse Source

!31723 code_check_clean

Merge pull request !31723 from liuyang/tensor_ms
r1.7
i-robot Gitee 4 years ago
parent
commit
9680aa073d
No known key found for this signature in database GPG Key ID: 173E9B9CA92EEF8F
8 changed files with 24 additions and 13 deletions
  1. +1
    -1
      docs/api/api_python/ops/mindspore.ops.func_arange.rst
  2. +5
    -2
      mindspore/ccsrc/transform/express_ir/onnx_exporter.cc
  3. +2
    -2
      mindspore/ccsrc/transform/graph_ir/convert.cc
  4. +7
    -3
      mindspore/python/mindspore/common/tensor.py
  5. +3
    -3
      mindspore/python/mindspore/numpy/array_creations.py
  6. +1
    -0
      mindspore/python/mindspore/train/callback/_history.py
  7. +1
    -0
      mindspore/python/mindspore/train/callback/_lambda_callback.py
  8. +4
    -2
      mindspore/python/mindspore/train/dataset_helper.py

+ 1
- 1
docs/api/api_python/ops/mindspore.ops.func_arange.rst View File

@@ -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.dtypestr]) - 指定返回数据的类型,如果不指定,则会根据 `start` 、 `stop` 、 `step` 的值推断类型。
- **rtype** (Union[mindspore.dtype, str]) - 指定返回数据的类型,如果不指定,则会根据 `start` 、 `stop` 、 `step` 的值推断类型。

**返回:**



+ 5
- 2
mindspore/ccsrc/transform/express_ir/onnx_exporter.cc View File

@@ -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<std::byte *>(&fp32_bits), sizeof(fp32_bits), reinterpret_cast<std::byte *>(&value),
sizeof(value));
auto ret = memcpy_s(reinterpret_cast<std::byte *>(&fp32_bits), sizeof(fp32_bits),
reinterpret_cast<std::byte *>(&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);


+ 2
- 2
mindspore/ccsrc/transform/graph_ir/convert.cc View File

@@ -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<uint32_t>(vars_.size() - count_size));
(void)save_op.create_dynamic_input_tensors(static_cast<uint32_t>(vars_.size() - static_cast<size_t>(count_size)));

// for each "parameter" in anf graph excluding "input"
for (const auto &it : vars_) {


+ 7
- 3
mindspore/python/mindspore/common/tensor.py View File

@@ -1028,8 +1028,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.
@@ -1998,9 +1998,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__')


+ 3
- 3
mindspore/python/mindspore/numpy/array_creations.py View File

@@ -430,7 +430,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.
@@ -470,7 +470,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.
@@ -501,7 +501,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`


+ 1
- 0
mindspore/python/mindspore/train/callback/_history.py View File

@@ -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.


+ 1
- 0
mindspore/python/mindspore/train/callback/_lambda_callback.py View File

@@ -16,6 +16,7 @@

from ._callback import Callback


class LambdaCallback(Callback):
"""
Callback for creating simple, custom callbacks.


+ 4
- 2
mindspore/python/mindspore/train/dataset_helper.py View File

@@ -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):


Loading…
Cancel
Save