提交 2ff7ea33 编写于 作者: Z zhoukunsheng 提交者: Tao Luo

Expose sign op (#17117)

* test=develop
add sign op

* Update nn.py

test=develop
delete stop_gradient assignment
上级 f0acc366
......@@ -236,6 +236,7 @@ paddle.fluid.layers.pixel_shuffle (ArgSpec(args=['x', 'upscale_factor'], varargs
paddle.fluid.layers.fsp_matrix (ArgSpec(args=['x', 'y'], varargs=None, keywords=None, defaults=None), ('document', 'b76ccca3735bea4a58a0dbf0d77c5393'))
paddle.fluid.layers.continuous_value_model (ArgSpec(args=['input', 'cvm', 'use_cvm'], varargs=None, keywords=None, defaults=(True,)), ('document', 'a07a44c2bacdcd09c1f5f35a96a0514e'))
paddle.fluid.layers.where (ArgSpec(args=['condition'], varargs=None, keywords=None, defaults=None), ('document', '3126e3039e752ce26077f1efaca355c6'))
paddle.fluid.layers.sign (ArgSpec(args=['x'], varargs=None, keywords=None, defaults=None), ('document', 'ccf6bb7912afd2818d24bc45461e807a'))
paddle.fluid.layers.data (ArgSpec(args=['name', 'shape', 'append_batch_size', 'dtype', 'lod_level', 'type', 'stop_gradient'], varargs=None, keywords=None, defaults=(True, 'float32', 0, VarType.LOD_TENSOR, True)), ('document', 'adf285346e23316097f7789b572491e9'))
paddle.fluid.layers.open_files (ArgSpec(args=['filenames', 'shapes', 'lod_levels', 'dtypes', 'thread_num', 'buffer_size', 'pass_num', 'is_test'], varargs=None, keywords=None, defaults=(None, None, 1, None)), ('document', 'cf12066a3139026119f97f9d4381a1bd'))
paddle.fluid.layers.read_file (ArgSpec(args=['reader'], varargs=None, keywords=None, defaults=None), ('document', 'b0a1c2fc51c27a106da28f3308c41f5e'))
......
......@@ -201,6 +201,7 @@ __all__ = [
'fsp_matrix',
'continuous_value_model',
'where',
'sign',
]
kIgnoreIndex = -100
......@@ -11396,3 +11397,34 @@ def where(condition):
helper.append_op(
type='where', inputs={'Condition': condition}, outputs={'Out': [out]})
return out
def sign(x):
"""
**sign**
This function returns sign of every element in `x`: 1 for positive, -1 for negative and 0 for zero.
Args:
x(Variable|numpy.ndarray): The input tensor.
Returns:
Variable: The output sign tensor with identical shape and dtype to `x`.
Examples:
.. code-block:: python
# [1, 0, -1]
data = fluid.layers.sign(np.array([3, 0, -2]))
"""
helper = LayerHelper("sign", **locals())
if not isinstance(x, Variable):
x = assign(x)
out = helper.create_variable_for_type_inference(dtype=x.dtype)
helper.append_op(type='sign', inputs={'X': [x]}, outputs={'Out': [out]})
return out
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册