Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
机器未来
Paddle
提交
a57d63a0
P
Paddle
项目概览
机器未来
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
a57d63a0
编写于
8月 20, 2020
作者:
W
WuHaobo
提交者:
GitHub
8月 20, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix erf (#26426)
上级
7c1ff38e
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
17 addition
and
49 deletion
+17
-49
python/paddle/fluid/layers/ops.py
python/paddle/fluid/layers/ops.py
+10
-49
python/paddle/fluid/tests/unittests/test_erf_op.py
python/paddle/fluid/tests/unittests/test_erf_op.py
+7
-0
未找到文件。
python/paddle/fluid/layers/ops.py
浏览文件 @
a57d63a0
...
...
@@ -730,7 +730,7 @@ __all__ += ['erf']
_erf_
=
generate_layer_fn
(
'erf'
)
def
erf
(
x
):
def
erf
(
x
,
name
=
None
):
locals_var
=
locals
().
copy
()
kwargs
=
dict
()
for
name
,
val
in
locals_var
.
items
():
...
...
@@ -740,10 +740,6 @@ def erf(x):
erf
.
__doc__
=
"""
:alias_main: paddle.erf
:alias: paddle.erf,paddle.tensor.erf,paddle.tensor.math.erf,paddle.nn.functional.erf,paddle.nn.functional.activation.erf
:old_api: paddle.fluid.layers.erf
:strong:`Erf Operator`
For more details, see [Error function](https://en.wikipedia.org/wiki/Error_function).
...
...
@@ -753,57 +749,22 @@ Equation:
Args:
x
(Variable): The input of Erf op, Tensor or LoDTensor, dtype: float32 or
float64.
x
(Tensor): The input tensor, it's data type should be float32,
float64.
Returns:
Variable: The output of Erf op, Tensor or LoDTensor
, dtype: float32 or float64, the same as the input, shape: the same as the input.
Tensor: The output of Erf op
, dtype: float32 or float64, the same as the input, shape: the same as the input.
Examples:
.. code-block:: python
# declarative mode
import numpy as np
from paddle import fluid
x = fluid.data(name="x", shape=(-1, 3), dtype="float32")
y = fluid.layers.erf(x)
place = fluid.CPUPlace()
exe = fluid.Executor(place)
start = fluid.default_startup_program()
main = fluid.default_main_program()
data = np.random.randn(2, 3).astype("float32")
exe.run(start)
y_np, = exe.run(main, feed={"x": data}, fetch_list=[y])
data
# array([[ 0.4643714 , -1.1509596 , 1.2538221 ],
# [ 0.34369683, 0.27478245, 1.1805398 ]], dtype=float32)
y_np
# array([[ 0.48863927, -0.8964121 , 0.9237998 ],
# [ 0.37307587, 0.30242872, 0.9049887 ]], dtype=float32)
.. code-block:: python
# imperative mode
import numpy as np
from paddle import fluid
import paddle.fluid.dygraph as dg
data = np.random.randn(2, 3).astype("float32")
place = fluid.CPUPlace()
with dg.guard(place) as g:
x = dg.to_variable(data)
y = fluid.layers.erf(x)
y_np = y.numpy()
data
# array([[ 0.4643714 , -1.1509596 , 1.2538221 ],
# [ 0.34369683, 0.27478245, 1.1805398 ]], dtype=float32)
y_np
# array([[ 0.48863927, -0.8964121 , 0.9237998 ],
# [ 0.37307587, 0.30242872, 0.9049887 ]], dtype=float32)
import paddle
paddle.disable_static()
x_data = np.array([-0.4, -0.2, 0.1, 0.3])
x = paddle.to_tensor(x_data)
out = paddle.erf(x)
print(out.numpy())
# [-0.42839236 -0.22270259 0.11246292 0.32862676]
"""
python/paddle/fluid/tests/unittests/test_erf_op.py
浏览文件 @
a57d63a0
...
...
@@ -19,6 +19,7 @@ import numpy as np
from
scipy.special
import
erf
from
op_test
import
OpTest
import
paddle
import
paddle.fluid
as
fluid
import
paddle.fluid.dygraph
as
dg
...
...
@@ -58,6 +59,12 @@ class TestErfLayer(unittest.TestCase):
if
fluid
.
is_compiled_with_cuda
():
self
.
_test_case
(
fluid
.
CUDAPlace
(
0
))
def
test_name
(
self
):
with
fluid
.
program_guard
(
fluid
.
Program
()):
x
=
paddle
.
nn
.
data
(
'x'
,
[
3
,
4
])
y
=
paddle
.
erf
(
x
,
name
=
'erf'
)
self
.
assertTrue
(
'erf'
in
y
.
name
)
if
__name__
==
'__main__'
:
unittest
.
main
()
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录