@@ -730,7 +730,7 @@ def gelu(x, approximate=False):
730730_erf_ = generate_layer_fn ('erf' )
731731
732732
733- def erf (x ):
733+ def erf (x , name = None ):
734734 locals_var = locals ().copy ()
735735 kwargs = dict ()
736736 for name , val in locals_var .items ():
@@ -740,10 +740,6 @@ def erf(x):
740740
741741
742742erf .__doc__ = """
743- :alias_main: paddle.erf
744- :alias: paddle.erf,paddle.tensor.erf,paddle.tensor.math.erf,paddle.nn.functional.erf,paddle.nn.functional.activation.erf
745- :old_api: paddle.fluid.layers.erf
746-
747743:strong:`Erf Operator`
748744For more details, see [Error function](https://en.wikipedia.org/wiki/Error_function).
749745
@@ -753,57 +749,22 @@ def erf(x):
753749
754750Args:
755751
756- x(Variable ): The input of Erf op, Tensor or LoDTensor, dtype: float32 or float64.
752+ x (Tensor ): The input tensor, it's data type should be float32, float64.
757753
758754Returns:
759755
760- Variable : The output of Erf op, Tensor or LoDTensor , dtype: float32 or float64, the same as the input, shape: the same as the input.
756+ Tensor : The output of Erf op, dtype: float32 or float64, the same as the input, shape: the same as the input.
761757
762758Examples:
763759
764760 .. code-block:: python
765761
766- # declarative mode
767762 import numpy as np
768- from paddle import fluid
769-
770- x = fluid.data(name="x", shape=(-1, 3), dtype="float32")
771- y = fluid.layers.erf(x)
772-
773- place = fluid.CPUPlace()
774- exe = fluid.Executor(place)
775- start = fluid.default_startup_program()
776- main = fluid.default_main_program()
777-
778- data = np.random.randn(2, 3).astype("float32")
779- exe.run(start)
780-
781- y_np, = exe.run(main, feed={"x": data}, fetch_list=[y])
782-
783- data
784- # array([[ 0.4643714 , -1.1509596 , 1.2538221 ],
785- # [ 0.34369683, 0.27478245, 1.1805398 ]], dtype=float32)
786- y_np
787- # array([[ 0.48863927, -0.8964121 , 0.9237998 ],
788- # [ 0.37307587, 0.30242872, 0.9049887 ]], dtype=float32)
789-
790- .. code-block:: python
791-
792- # imperative mode
793- import numpy as np
794- from paddle import fluid
795- import paddle.fluid.dygraph as dg
796-
797- data = np.random.randn(2, 3).astype("float32")
798- place = fluid.CPUPlace()
799- with dg.guard(place) as g:
800- x = dg.to_variable(data)
801- y = fluid.layers.erf(x)
802- y_np = y.numpy()
803- data
804- # array([[ 0.4643714 , -1.1509596 , 1.2538221 ],
805- # [ 0.34369683, 0.27478245, 1.1805398 ]], dtype=float32)
806- y_np
807- # array([[ 0.48863927, -0.8964121 , 0.9237998 ],
808- # [ 0.37307587, 0.30242872, 0.9049887 ]], dtype=float32)
763+ import paddle
764+ paddle.disable_static()
765+ x_data = np.array([-0.4, -0.2, 0.1, 0.3])
766+ x = paddle.to_tensor(x_data)
767+ out = paddle.erf(x)
768+ print(out.numpy())
769+ # [-0.42839236 -0.22270259 0.11246292 0.32862676]
809770"""
0 commit comments