From 7e322b3c42337f21f99213abb85fe5ae318da7cc Mon Sep 17 00:00:00 2001 From: yongqiangma Date: Sat, 5 Dec 2020 22:48:36 +0800 Subject: [PATCH] update unbind norm add CUDAPlace api doc information (#29322) (#29391) * enhance array_to_lod_tensor_op lod_tensor_to_array_op errors information. test=develop * fix format. test=develop * format fix. test=develop * add lod_rank_table. test=develop * fix format. test=develop * fix doc info. test=develop * fix np error * add unbind dygraph api. test=develop * fix unbind doc.test=develop --- paddle/fluid/pybind/pybind.cc | 1 - python/paddle/tensor/linalg.py | 3 --- python/paddle/tensor/manipulation.py | 24 +++++++++++++----------- 3 files changed, 13 insertions(+), 15 deletions(-) diff --git a/paddle/fluid/pybind/pybind.cc b/paddle/fluid/pybind/pybind.cc index 778b670769a..9930acff00a 100644 --- a/paddle/fluid/pybind/pybind.cc +++ b/paddle/fluid/pybind/pybind.cc @@ -1375,7 +1375,6 @@ All parameter, weight, gradient are variables in Paddle. import paddle place = paddle.CUDAPlace(0) - paddle.disable_static(place) )DOC") .def("__init__", diff --git a/python/paddle/tensor/linalg.py b/python/paddle/tensor/linalg.py index c6af97ffcac..99f5bf7ba0a 100644 --- a/python/paddle/tensor/linalg.py +++ b/python/paddle/tensor/linalg.py @@ -173,8 +173,6 @@ def matmul(x, y, transpose_x=False, transpose_y=False, name=None): def norm(x, p='fro', axis=None, keepdim=False, name=None): """ - :alias_main: paddle.norm - :alias: paddle.norm,paddle.tensor.norm,paddle.tensor.linalg.norm Returns the matrix norm (Frobenius) or vector norm (the 1-norm, the Euclidean or 2-norm, and in general the p-norm for p > 0) of a given tensor. @@ -206,7 +204,6 @@ def norm(x, p='fro', axis=None, keepdim=False, name=None): import paddle import numpy as np - paddle.disable_static() shape=[2, 3, 4] np_input = np.arange(24).astype('float32') - 12 np_input = np_input.reshape(shape) diff --git a/python/paddle/tensor/manipulation.py b/python/paddle/tensor/manipulation.py index d6f40d80a76..40a8fdb7ef0 100644 --- a/python/paddle/tensor/manipulation.py +++ b/python/paddle/tensor/manipulation.py @@ -791,29 +791,29 @@ def gather(x, index, axis=None, name=None): def unbind(input, axis=0): """ - :alias_main: paddle.tensor.unbind - :alias: paddle.tensor.unbind,paddle.tensor.manipulation.unbind Removes a tensor dimension, then split the input tensor into multiple sub-Tensors. + Args: - input (Variable): The input variable which is an N-D Tensor, data type being float32, float64, int32 or int64. - - axis (int32|int64, optional): A scalar with type ``int32|int64`` shape [1]. The dimension along which to unbind. If :math:`axis < 0`, the - dimension to unbind along is :math:`rank(input) + axis`. Default is 0. + input (Tensor): The input variable which is an N-D Tensor, data type being float32, float64, int32 or int64. + axis (int32|int64, optional): A scalar with type ``int32|int64`` shape [1]. The dimension along which to unbind. + If :math:`axis < 0`, the dimension to unbind along is :math:`rank(input) + axis`. Default is 0. Returns: - list(Variable): The list of segmented Tensor variables. + list(Tensor): The list of segmented Tensor variables. Example: .. code-block:: python + import paddle + import numpy as np # input is a variable which shape is [3, 4, 5] - input = paddle.fluid.data( - name="input", shape=[3, 4, 5], dtype="float32") - [x0, x1, x2] = paddle.tensor.unbind(input, axis=0) + np_input = np.random.rand(3, 4, 5).astype('float32') + input = paddle.to_tensor(np_input) + [x0, x1, x2] = paddle.unbind(input, axis=0) # x0.shape [4, 5] # x1.shape [4, 5] # x2.shape [4, 5] - [x0, x1, x2, x3] = paddle.tensor.unbind(input, axis=1) + [x0, x1, x2, x3] = paddle.unbind(input, axis=1) # x0.shape [3, 5] # x1.shape [3, 5] # x2.shape [3, 5] @@ -837,6 +837,8 @@ def unbind(input, axis=0): helper.create_variable_for_type_inference(dtype=helper.input_dtype()) for i in range(num) ] + if in_dygraph_mode(): + return core.ops.unbind(input, num, 'axis', axis) helper.append_op( type="unbind", -- GitLab