Skip to content

Commit df9c13a

Browse files
authored
Merge pull request #7485 from lcy-seso/wrapper_for_elementwise_math_op
add wrapper for element-wise math operator.
2 parents db65f49 + 8ac744f commit df9c13a

File tree

16 files changed

+304
-65
lines changed

16 files changed

+304
-65
lines changed

doc/api/v2/fluid/layers.rst

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,3 +358,132 @@ reduce_min
358358
.. autofunction:: paddle.v2.fluid.layers.reduce_min
359359
:noindex:
360360

361+
logsigmoid
362+
----------
363+
.. autofunction:: paddle.v2.fluid.layers.logsigmoid
364+
:noindex:
365+
366+
exp
367+
---
368+
.. autofunction:: paddle.v2.fluid.layers.exp
369+
:noindex:
370+
371+
relu
372+
----
373+
.. autofunction:: paddle.v2.fluid.layers.relu
374+
:noindex:
375+
376+
tanh
377+
----
378+
.. autofunction:: paddle.v2.fluid.layers.tanh
379+
:noindex:
380+
381+
tanh_shrink
382+
-----------
383+
.. autofunction:: paddle.v2.fluid.layers.tanh_shrink
384+
:noindex:
385+
386+
softshrink
387+
----------
388+
.. autofunction:: paddle.v2.fluid.layers.softshrink
389+
:noindex:
390+
391+
sqrt
392+
----
393+
.. autofunction:: paddle.v2.fluid.layers.sqrt
394+
:noindex:
395+
396+
abs
397+
----
398+
.. autofunction:: paddle.v2.fluid.layers.abs
399+
:noindex:
400+
401+
ceil
402+
----
403+
.. autofunction:: paddle.v2.fluid.layers.ceil
404+
:noindex:
405+
406+
floor
407+
-----
408+
.. autofunction:: paddle.v2.fluid.layers.floor
409+
:noindex:
410+
411+
round
412+
-----
413+
.. autofunction:: paddle.v2.fluid.layers.round
414+
:noindex:
415+
416+
reciprocal
417+
----------
418+
.. autofunction:: paddle.v2.fluid.layers.reciprocal
419+
:noindex:
420+
421+
log
422+
---
423+
.. autofunction:: paddle.v2.fluid.layers.log
424+
:noindex:
425+
426+
square
427+
------
428+
.. autofunction:: paddle.v2.fluid.layers.square
429+
:noindex:
430+
431+
softplus
432+
--------
433+
.. autofunction:: paddle.v2.fluid.layers.softplus
434+
:noindex:
435+
436+
softsign
437+
---------
438+
.. autofunction:: paddle.v2.fluid.layers.softsign
439+
:noindex:
440+
441+
brelu
442+
-----
443+
.. autofunction:: paddle.v2.fluid.layers.brelu
444+
:noindex:
445+
446+
leaky_relu
447+
----------
448+
.. autofunction:: paddle.v2.fluid.layers.leaky_relu
449+
:noindex:
450+
451+
soft_relu
452+
---------
453+
.. autofunction:: paddle.v2.fluid.layers.soft_relu
454+
:noindex:
455+
456+
elu
457+
----
458+
.. autofunction:: paddle.v2.fluid.layers.elu
459+
:noindex:
460+
461+
relu6
462+
-----
463+
.. autofunction:: paddle.v2.fluid.layers.relu6
464+
:noindex:
465+
466+
pow
467+
----
468+
.. autofunction:: paddle.v2.fluid.layers.pow
469+
:noindex:
470+
471+
hard_shrink
472+
-----------
473+
.. autofunction:: paddle.v2.fluid.layers.hard_shrink
474+
:noindex:
475+
476+
thresholded_relu
477+
----------------
478+
.. autofunction:: paddle.v2.fluid.layers.thresholded_relu
479+
:noindex:
480+
481+
hard_sigmoid
482+
-------------
483+
.. autofunction:: paddle.v2.fluid.layers.hard_sigmoid
484+
:noindex:
485+
486+
swish
487+
------
488+
.. autofunction:: paddle.v2.fluid.layers.swish
489+
:noindex:

python/paddle/v2/fluid/__init__.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,22 @@
2323

2424
Tensor = LoDTensor
2525
__all__ = framework.__all__ + executor.__all__ + [
26-
'io', 'initializer', 'layers', 'nets', 'optimizer', 'backward',
27-
'regularizer', 'LoDTensor', 'CPUPlace', 'CUDAPlace', 'Tensor', 'ParamAttr'
28-
'DataFeeder', 'clip', 'DistributeTranspiler', 'memory_optimize'
26+
'io',
27+
'initializer',
28+
'layers',
29+
'nets',
30+
'optimizer',
31+
'backward',
32+
'regularizer',
33+
'LoDTensor',
34+
'CPUPlace',
35+
'CUDAPlace',
36+
'Tensor',
37+
'ParamAttr'
38+
'DataFeeder',
39+
'clip',
40+
'DistributeTranspiler',
41+
'memory_optimize',
2942
]
3043

3144

python/paddle/v2/fluid/backward.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@
33
import collections
44
import copy
55

6-
__all__ = ['append_backward', 'calc_gradient']
6+
__all__ = [
7+
'append_backward',
8+
'calc_gradient',
9+
]
710

811

912
def _rename_arg_(op_descs, old_name, new_name, begin_idx=None, end_idx=None):

python/paddle/v2/fluid/clip.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
from . import core
44

55
__all__ = [
6-
'GradientClipByValue', 'append_gradient_clip_ops', 'error_clip_callback'
6+
'GradientClipByValue',
7+
'append_gradient_clip_ops',
8+
'error_clip_callback',
79
]
810

911

python/paddle/v2/fluid/default_scope_funcs.py

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
"""
22
Default scope function.
33
4-
`Paddle` manages Scope as programming language's scope. It just a
5-
thread-local stack of Scope. Top of that stack is current scope, the bottom
6-
of that stack is all scopes' parent.
4+
`Paddle` manages Scope as programming language's scope. It just a
5+
thread-local stack of Scope. Top of that stack is current scope, the bottom
6+
of that stack is all scopes' parent.
77
8-
Invoking `var/find_var` can `new/find` variable in current scope.
9-
Invoking `enter_local_scope/leave_local_scope` can create or destroy local
10-
scope.
8+
Invoking `var/find_var` can `new/find` variable in current scope.
9+
Invoking `enter_local_scope/leave_local_scope` can create or destroy local
10+
scope.
1111
12-
A `scoped_function` will take a `function` as input. That function will be
13-
invoked in a new local scope.
12+
A `scoped_function` will take a `function` as input. That function will be
13+
invoked in a new local scope.
1414
"""
1515

1616
import paddle.v2.fluid.core
@@ -19,8 +19,12 @@
1919
__tl_scope__ = threading.local()
2020

2121
__all__ = [
22-
'get_cur_scope', 'enter_local_scope', 'leave_local_scope', 'var',
23-
'find_var', 'scoped_function'
22+
'get_cur_scope',
23+
'enter_local_scope',
24+
'leave_local_scope',
25+
'var',
26+
'find_var',
27+
'scoped_function',
2428
]
2529

2630

@@ -71,7 +75,7 @@ def find_var(name):
7175
def scoped_function(func):
7276
"""
7377
invoke `func` in new scope.
74-
78+
7579
:param func: a callable function that will be run in new scope.
7680
:type func: callable
7781
"""

python/paddle/v2/fluid/evaluator.py

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@
44
from framework import Program, unique_name, Variable, program_guard
55
from layer_helper import LayerHelper
66

7-
__all__ = ['Accuracy', 'ChunkEvaluator']
7+
__all__ = [
8+
'Accuracy',
9+
'ChunkEvaluator',
10+
]
811

912

1013
def _clone_var_(block, var):
@@ -21,19 +24,19 @@ def _clone_var_(block, var):
2124
class Evaluator(object):
2225
"""
2326
Base Class for all evaluators
24-
27+
2528
Args:
26-
name(str): The name of evaluator. such as, "accuracy". Used for generate
29+
name(str): The name of evaluator. such as, "accuracy". Used for generate
2730
temporary variable name.
28-
main_program(Program, optional): The evaluator should be added to this
31+
main_program(Program, optional): The evaluator should be added to this
2932
main_program. Default default_main_program()
30-
startup_program(Program, optional):The parameter should be added to this
33+
startup_program(Program, optional):The parameter should be added to this
3134
startup_program. Default default_startup_program()
32-
35+
3336
Attributes:
34-
states(list): The list of state variables. states will be reset to zero
37+
states(list): The list of state variables. states will be reset to zero
3538
when `reset` is invoked.
36-
metrics(list): The list of metrics variables. They will be calculate
39+
metrics(list): The list of metrics variables. They will be calculate
3740
every mini-batch
3841
"""
3942

@@ -66,14 +69,14 @@ def eval(self, executor, eval_program=None):
6669

6770
def create_state(self, suffix, dtype, shape):
6871
"""
69-
Create state variable.
70-
72+
Create state variable.
73+
7174
NOTE: It is not a public API.
72-
75+
7376
Args:
74-
suffix(str): the state suffix.
75-
dtype(str|core.DataType): the state data type
76-
shape(tuple|list): the shape of state
77+
suffix(str): the state suffix.
78+
dtype(str|core.DataType): the state data type
79+
shape(tuple|list): the shape of state
7780
7881
Returns: State variable
7982
@@ -127,8 +130,8 @@ def eval(self, executor, eval_program=None):
127130

128131
class ChunkEvaluator(Evaluator):
129132
"""
130-
Accumulate counter numbers output by chunk_eval from mini-batches and
131-
compute the precision recall and F1-score using the accumulated counter
133+
Accumulate counter numbers output by chunk_eval from mini-batches and
134+
compute the precision recall and F1-score using the accumulated counter
132135
numbers.
133136
"""
134137

python/paddle/v2/fluid/framework.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,15 @@
77
from . import core
88

99
__all__ = [
10-
'Block', 'Variable', 'Program', 'Operator', 'default_startup_program',
11-
'default_main_program', 'program_guard', 'switch_startup_program',
12-
'switch_main_program'
10+
'Block',
11+
'Variable',
12+
'Program',
13+
'Operator',
14+
'default_startup_program',
15+
'default_main_program',
16+
'program_guard',
17+
'switch_startup_program',
18+
'switch_main_program',
1319
]
1420

1521
EMPTY_VAR_NAME = core.kEmptyVarName()

python/paddle/v2/fluid/initializer.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
import framework
22
import numpy as np
33

4-
__all__ = ['Constant', 'Uniform', 'Normal', 'Xavier']
4+
__all__ = [
5+
'Constant',
6+
'Uniform',
7+
'Normal',
8+
'Xavier',
9+
]
510

611

712
class Initializer(object):

python/paddle/v2/fluid/io.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,15 @@
44
from paddle.v2.fluid.framework import Program, Parameter, default_main_program, Variable
55

66
__all__ = [
7-
'save_vars', 'save_params', 'save_persistables', 'load_vars', 'load_params',
8-
'load_persistables', "save_inference_model", "load_inference_model",
9-
"get_inference_program"
7+
'save_vars',
8+
'save_params',
9+
'save_persistables',
10+
'load_vars',
11+
'load_params',
12+
'load_persistables',
13+
'save_inference_model',
14+
'load_inference_model',
15+
'get_inference_program',
1016
]
1117

1218

0 commit comments

Comments
 (0)