同步操作将从 PaddlePaddle/Paddle 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
# Copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved.## Licensed under the Apache License, Version 2.0 (the "License");# you may not use this file except in compliance with the License.# You may obtain a copy of the License at## http://www.apache.org/licenses/LICENSE-2.0## Unless required by applicable law or agreed to in writing, software# distributed under the License is distributed on an "AS IS" BASIS,# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.# See the License for the specific language governing permissions and# limitations under the License.from __future__ import print_functionfrom ..framework import corefrom ..fluid.layer_helper import LayerHelperfrom ..fluid.data_feeder import check_variable_and_dtype# TODO: define functions to get tensor attributesfrom ..fluid.layers import rank # noqa: F401from ..fluid.layers import shape # noqa: F401import paddlefrom paddle import _C_opsfrom paddle.static import Variablefrom ..fluid.framework import _in_legacy_dygraph, in_dygraph_mode__all__ = []def _complex_to_real_dtype(dtype):if dtype == core.VarDesc.VarType.COMPLEX64:return core.VarDesc.VarType.FP32elif dtype == core.VarDesc.VarType.COMPLEX128:return core.VarDesc.VarType.FP64else:return dtypedef _real_to_complex_dtype(dtype):if dtype == core.VarDesc.VarType.FP32:return core.VarDesc.VarType.COMPLEX64elif dtype == core.VarDesc.VarType.FP64:return core.VarDesc.VarType.COMPLEX128else:return dtypedef is_complex(x):"""Return whether x is a tensor of complex data type(complex64 or complex128).Args:x (Tensor): The input tensor.Returns:bool: True if the data type of the input is complex data type, otherwise false.Examples:.. code-block:: pythonimport paddlex = paddle.to_tensor([1 + 2j, 3 + 4j])print(paddle.is_complex(x))# Truex = paddle.to_tensor([1.1, 1.2])print(paddle.is_complex(x))# Falsex = paddle.to_tensor([1, 2, 3])print(paddle.is_complex(x))# False"""if not isinstance(x, (paddle.Tensor, paddle.static.Variable)):raise TypeError("Expected Tensor, but received type of x: {}".format(type(x)))dtype = x.dtypeis_complex_dtype = (dtype == core.VarDesc.VarType.COMPLEX64 ordtype == core.VarDesc.VarType.COMPLEX128)return is_complex_dtypedef is_floating_point(x):"""Returns whether the dtype of `x` is one of paddle.float64, paddle.float32, paddle.float16, and paddle.bfloat16.Args:x (Tensor): The input tensor.Returns:bool: True if the dtype of `x` is floating type, otherwise false.Examples:.. code-block:: pythonimport paddlex = paddle.arange(1., 5., dtype='float32')y = paddle.arange(1, 5, dtype='int32')print(paddle.is_floating_point(x))# Trueprint(paddle.is_floating_point(y))# False"""if not isinstance(x, (paddle.Tensor, paddle.static.Variable)):raise TypeError("Expected Tensor, but received type of x: {}".format(type(x)))dtype = x.dtypeis_fp_dtype = (dtype == core.VarDesc.VarType.FP32 ordtype == core.VarDesc.VarType.FP64 ordtype == core.VarDesc.VarType.FP16 ordtype == core.VarDesc.VarType.BF16)return is_fp_dtypedef is_integer(x):"""Return whether x is a tensor of integeral data type.Args:x (Tensor): The input tensor.Returns:bool: True if the data type of the input is integer data type, otherwise false.Examples:.. code-block:: pythonimport paddlex = paddle.to_tensor([1 + 2j, 3 + 4j])print(paddle.is_integer(x))# Falsex = paddle.to_tensor([1.1, 1.2])print(paddle.is_integer(x))# Falsex = paddle.to_tensor([1, 2, 3])print(paddle.is_integer(x))# True"""if not isinstance(x, (paddle.Tensor, paddle.static.Variable)):raise TypeError("Expected Tensor, but received type of x: {}".format(type(x)))dtype = x.dtypeis_int_dtype = (dtype == core.VarDesc.VarType.UINT8 ordtype == core.VarDesc.VarType.INT8 ordtype == core.VarDesc.VarType.INT16 ordtype == core.VarDesc.VarType.INT32 ordtype == core.VarDesc.VarType.INT64)return is_int_dtypedef real(x, name=None):"""Returns a new tensor containing real values of the input tensor.Args:x (Tensor): the input tensor, its data type could be complex64 or complex128.name (str, optional): The default value is None. Normally there is no need foruser to set this property. For more information, please refer to :ref:`api_guide_Name` .Returns:Tensor: a tensor containing real values of the input tensor.Examples:.. code-block:: pythonimport paddlex = paddle.to_tensor([[1 + 6j, 2 + 5j, 3 + 4j], [4 + 3j, 5 + 2j, 6 + 1j]])# Tensor(shape=[2, 3], dtype=complex64, place=CUDAPlace(0), stop_gradient=True,# [[(1+6j), (2+5j), (3+4j)],# [(4+3j), (5+2j), (6+1j)]])real_res = paddle.real(x)# Tensor(shape=[2, 3], dtype=float32, place=CUDAPlace(0), stop_gradient=True,# [[1., 2., 3.],# [4., 5., 6.]])real_t = x.real()# Tensor(shape=[2, 3], dtype=float32, place=CUDAPlace(0), stop_gradient=True,# [[1., 2., 3.],# [4., 5., 6.]])"""if in_dygraph_mode():return _C_ops.final_state_real(x)if _in_legacy_dygraph():return _C_ops.real(x)check_variable_and_dtype(x, 'x', ['complex64', 'complex128'], 'real')helper = LayerHelper('real', **locals())out = helper.create_variable_for_type_inference(dtype=_complex_to_real_dtype(helper.input_dtype()))helper.append_op(type='real', inputs={'X': x}, outputs={'Out': out})return outdef imag(x, name=None):"""Returns a new tensor containing imaginary values of input tensor.Args:x (Tensor): the input tensor, its data type could be complex64 or complex128.name (str, optional): The default value is None. Normally there is no need foruser to set this property. For more information, please refer to :ref:`api_guide_Name` .Returns:Tensor: a tensor containing imaginary values of the input tensor.Examples:.. code-block:: pythonimport paddlex = paddle.to_tensor([[1 + 6j, 2 + 5j, 3 + 4j], [4 + 3j, 5 + 2j, 6 + 1j]])# Tensor(shape=[2, 3], dtype=complex64, place=CUDAPlace(0), stop_gradient=True,# [[(1+6j), (2+5j), (3+4j)],# [(4+3j), (5+2j), (6+1j)]])imag_res = paddle.imag(x)# Tensor(shape=[2, 3], dtype=float32, place=CUDAPlace(0), stop_gradient=True,# [[6., 5., 4.],# [3., 2., 1.]])imag_t = x.imag()# Tensor(shape=[2, 3], dtype=float32, place=CUDAPlace(0), stop_gradient=True,# [[6., 5., 4.],# [3., 2., 1.]])"""if in_dygraph_mode():return _C_ops.final_state_imag(x)if _in_legacy_dygraph():return _C_ops.imag(x)check_variable_and_dtype(x, 'x', ['complex64', 'complex128'], 'imag')helper = LayerHelper('imag', **locals())out = helper.create_variable_for_type_inference(dtype=_complex_to_real_dtype(helper.input_dtype()))helper.append_op(type='imag', inputs={'X': x}, outputs={'Out': out})return out
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。