From 1c5cba7b81a994d80b14fbc6ee12dfe0c8a0290a Mon Sep 17 00:00:00 2001 From: huanghui Date: Fri, 4 Dec 2020 18:08:08 +0800 Subject: [PATCH] add data_sync in Tensor.__repr__ --- mindspore/ccsrc/pybind_api/ir/tensor_py.cc | 1 + mindspore/common/tensor.py | 5 +---- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/mindspore/ccsrc/pybind_api/ir/tensor_py.cc b/mindspore/ccsrc/pybind_api/ir/tensor_py.cc index e2f3ea834b..034cc99858 100644 --- a/mindspore/ccsrc/pybind_api/ir/tensor_py.cc +++ b/mindspore/ccsrc/pybind_api/ir/tensor_py.cc @@ -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( diff --git a/mindspore/common/tensor.py b/mindspore/common/tensor.py index 9f8de3f49d..cec002234b 100644 --- a/mindspore/common/tensor.py +++ b/mindspore/common/tensor.py @@ -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.