!9527 Add data_sync in Tensor.__repr__

From: @irmo
Reviewed-by: @liangchenghui,@zh_qh
Signed-off-by: @zh_qh
This commit is contained in:
mindspore-ci-bot 2020-12-07 12:46:24 +08:00 committed by Gitee
commit c8f9e5d82a
2 changed files with 2 additions and 4 deletions

View File

@ -461,6 +461,7 @@ REGISTER_PYBIND_DEFINE(Tensor, ([](const py::module *m) {
mindspore.int32
)mydelimiter")
.def("set_cast_dtype", &Tensor::set_cast_dtype, py::arg("dtype") = nullptr)
.def("data_sync", &Tensor::data_sync)
.def("__str__", &Tensor::ToString)
.def("__repr__", &Tensor::ToStringRepr)
.def(py::pickle(

View File

@ -88,6 +88,7 @@ class Tensor(Tensor_):
self._virtual_flag = False
def __repr__(self):
Tensor_.data_sync(self, False)
return Tensor_.__repr__(self)
def __add__(self, other):
@ -293,7 +294,6 @@ class Tensor(Tensor_):
axis = ()
return tensor_operator_registry.get('any')(keep_dims)(self, axis)
def view(self, *shape):
r"""
Reshape the tensor according to the input shape.
@ -312,7 +312,6 @@ class Tensor(Tensor_):
shape = shape[0]
return tensor_operator_registry.get('reshape')()(self, shape)
def expand_as(self, x):
"""
Expand the dimension of target tensor to the dimension of input tensor.
@ -326,7 +325,6 @@ class Tensor(Tensor_):
"""
return tensor_operator_registry.get('broadcast_to')(x.shape)(self)
def abs(self):
"""
Return absolute value element-wisely.
@ -336,7 +334,6 @@ class Tensor(Tensor_):
"""
return tensor_operator_registry.get('abs')()(self)
def mean(self, axis=(), keep_dims=False):
"""
Reduce a dimension of a tensor by averaging all elements in the dimension.