Skip to content

Commit

Permalink
Merge pull request #7485 from lcy-seso/wrapper_for_elementwise_math_op
Browse files Browse the repository at this point in the history
add wrapper for element-wise math operator.
  • Loading branch information
lcy-seso authored Jan 13, 2018
2 parents db65f49 + 8ac744f commit df9c13a
Show file tree
Hide file tree
Showing 16 changed files with 304 additions and 65 deletions.
129 changes: 129 additions & 0 deletions doc/api/v2/fluid/layers.rst
Original file line number Diff line number Diff line change
Expand Up @@ -358,3 +358,132 @@ reduce_min
.. autofunction:: paddle.v2.fluid.layers.reduce_min
:noindex:

logsigmoid
----------
.. autofunction:: paddle.v2.fluid.layers.logsigmoid
:noindex:

exp
---
.. autofunction:: paddle.v2.fluid.layers.exp
:noindex:

relu
----
.. autofunction:: paddle.v2.fluid.layers.relu
:noindex:

tanh
----
.. autofunction:: paddle.v2.fluid.layers.tanh
:noindex:

tanh_shrink
-----------
.. autofunction:: paddle.v2.fluid.layers.tanh_shrink
:noindex:

softshrink
----------
.. autofunction:: paddle.v2.fluid.layers.softshrink
:noindex:

sqrt
----
.. autofunction:: paddle.v2.fluid.layers.sqrt
:noindex:

abs
----
.. autofunction:: paddle.v2.fluid.layers.abs
:noindex:

ceil
----
.. autofunction:: paddle.v2.fluid.layers.ceil
:noindex:

floor
-----
.. autofunction:: paddle.v2.fluid.layers.floor
:noindex:

round
-----
.. autofunction:: paddle.v2.fluid.layers.round
:noindex:

reciprocal
----------
.. autofunction:: paddle.v2.fluid.layers.reciprocal
:noindex:

log
---
.. autofunction:: paddle.v2.fluid.layers.log
:noindex:

square
------
.. autofunction:: paddle.v2.fluid.layers.square
:noindex:

softplus
--------
.. autofunction:: paddle.v2.fluid.layers.softplus
:noindex:

softsign
---------
.. autofunction:: paddle.v2.fluid.layers.softsign
:noindex:

brelu
-----
.. autofunction:: paddle.v2.fluid.layers.brelu
:noindex:

leaky_relu
----------
.. autofunction:: paddle.v2.fluid.layers.leaky_relu
:noindex:

soft_relu
---------
.. autofunction:: paddle.v2.fluid.layers.soft_relu
:noindex:

elu
----
.. autofunction:: paddle.v2.fluid.layers.elu
:noindex:

relu6
-----
.. autofunction:: paddle.v2.fluid.layers.relu6
:noindex:

pow
----
.. autofunction:: paddle.v2.fluid.layers.pow
:noindex:

hard_shrink
-----------
.. autofunction:: paddle.v2.fluid.layers.hard_shrink
:noindex:

thresholded_relu
----------------
.. autofunction:: paddle.v2.fluid.layers.thresholded_relu
:noindex:

hard_sigmoid
-------------
.. autofunction:: paddle.v2.fluid.layers.hard_sigmoid
:noindex:

swish
------
.. autofunction:: paddle.v2.fluid.layers.swish
:noindex:
19 changes: 16 additions & 3 deletions python/paddle/v2/fluid/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,22 @@

Tensor = LoDTensor
__all__ = framework.__all__ + executor.__all__ + [
'io', 'initializer', 'layers', 'nets', 'optimizer', 'backward',
'regularizer', 'LoDTensor', 'CPUPlace', 'CUDAPlace', 'Tensor', 'ParamAttr'
'DataFeeder', 'clip', 'DistributeTranspiler', 'memory_optimize'
'io',
'initializer',
'layers',
'nets',
'optimizer',
'backward',
'regularizer',
'LoDTensor',
'CPUPlace',
'CUDAPlace',
'Tensor',
'ParamAttr'
'DataFeeder',
'clip',
'DistributeTranspiler',
'memory_optimize',
]


Expand Down
5 changes: 4 additions & 1 deletion python/paddle/v2/fluid/backward.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
import collections
import copy

__all__ = ['append_backward', 'calc_gradient']
__all__ = [
'append_backward',
'calc_gradient',
]


def _rename_arg_(op_descs, old_name, new_name, begin_idx=None, end_idx=None):
Expand Down
4 changes: 3 additions & 1 deletion python/paddle/v2/fluid/clip.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
from . import core

__all__ = [
'GradientClipByValue', 'append_gradient_clip_ops', 'error_clip_callback'
'GradientClipByValue',
'append_gradient_clip_ops',
'error_clip_callback',
]


Expand Down
26 changes: 15 additions & 11 deletions python/paddle/v2/fluid/default_scope_funcs.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
"""
Default scope function.
`Paddle` manages Scope as programming language's scope. It just a
thread-local stack of Scope. Top of that stack is current scope, the bottom
of that stack is all scopes' parent.
`Paddle` manages Scope as programming language's scope. It just a
thread-local stack of Scope. Top of that stack is current scope, the bottom
of that stack is all scopes' parent.
Invoking `var/find_var` can `new/find` variable in current scope.
Invoking `enter_local_scope/leave_local_scope` can create or destroy local
scope.
Invoking `var/find_var` can `new/find` variable in current scope.
Invoking `enter_local_scope/leave_local_scope` can create or destroy local
scope.
A `scoped_function` will take a `function` as input. That function will be
invoked in a new local scope.
A `scoped_function` will take a `function` as input. That function will be
invoked in a new local scope.
"""

import paddle.v2.fluid.core
Expand All @@ -19,8 +19,12 @@
__tl_scope__ = threading.local()

__all__ = [
'get_cur_scope', 'enter_local_scope', 'leave_local_scope', 'var',
'find_var', 'scoped_function'
'get_cur_scope',
'enter_local_scope',
'leave_local_scope',
'var',
'find_var',
'scoped_function',
]


Expand Down Expand Up @@ -71,7 +75,7 @@ def find_var(name):
def scoped_function(func):
"""
invoke `func` in new scope.
:param func: a callable function that will be run in new scope.
:type func: callable
"""
Expand Down
35 changes: 19 additions & 16 deletions python/paddle/v2/fluid/evaluator.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
from framework import Program, unique_name, Variable, program_guard
from layer_helper import LayerHelper

__all__ = ['Accuracy', 'ChunkEvaluator']
__all__ = [
'Accuracy',
'ChunkEvaluator',
]


def _clone_var_(block, var):
Expand All @@ -21,19 +24,19 @@ def _clone_var_(block, var):
class Evaluator(object):
"""
Base Class for all evaluators
Args:
name(str): The name of evaluator. such as, "accuracy". Used for generate
name(str): The name of evaluator. such as, "accuracy". Used for generate
temporary variable name.
main_program(Program, optional): The evaluator should be added to this
main_program(Program, optional): The evaluator should be added to this
main_program. Default default_main_program()
startup_program(Program, optional):The parameter should be added to this
startup_program(Program, optional):The parameter should be added to this
startup_program. Default default_startup_program()
Attributes:
states(list): The list of state variables. states will be reset to zero
states(list): The list of state variables. states will be reset to zero
when `reset` is invoked.
metrics(list): The list of metrics variables. They will be calculate
metrics(list): The list of metrics variables. They will be calculate
every mini-batch
"""

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

def create_state(self, suffix, dtype, shape):
"""
Create state variable.
Create state variable.
NOTE: It is not a public API.
Args:
suffix(str): the state suffix.
dtype(str|core.DataType): the state data type
shape(tuple|list): the shape of state
suffix(str): the state suffix.
dtype(str|core.DataType): the state data type
shape(tuple|list): the shape of state
Returns: State variable
Expand Down Expand Up @@ -127,8 +130,8 @@ def eval(self, executor, eval_program=None):

class ChunkEvaluator(Evaluator):
"""
Accumulate counter numbers output by chunk_eval from mini-batches and
compute the precision recall and F1-score using the accumulated counter
Accumulate counter numbers output by chunk_eval from mini-batches and
compute the precision recall and F1-score using the accumulated counter
numbers.
"""

Expand Down
12 changes: 9 additions & 3 deletions python/paddle/v2/fluid/framework.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,15 @@
from . import core

__all__ = [
'Block', 'Variable', 'Program', 'Operator', 'default_startup_program',
'default_main_program', 'program_guard', 'switch_startup_program',
'switch_main_program'
'Block',
'Variable',
'Program',
'Operator',
'default_startup_program',
'default_main_program',
'program_guard',
'switch_startup_program',
'switch_main_program',
]

EMPTY_VAR_NAME = core.kEmptyVarName()
Expand Down
7 changes: 6 additions & 1 deletion python/paddle/v2/fluid/initializer.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import framework
import numpy as np

__all__ = ['Constant', 'Uniform', 'Normal', 'Xavier']
__all__ = [
'Constant',
'Uniform',
'Normal',
'Xavier',
]


class Initializer(object):
Expand Down
12 changes: 9 additions & 3 deletions python/paddle/v2/fluid/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,15 @@
from paddle.v2.fluid.framework import Program, Parameter, default_main_program, Variable

__all__ = [
'save_vars', 'save_params', 'save_persistables', 'load_vars', 'load_params',
'load_persistables', "save_inference_model", "load_inference_model",
"get_inference_program"
'save_vars',
'save_params',
'save_persistables',
'load_vars',
'load_params',
'load_persistables',
'save_inference_model',
'load_inference_model',
'get_inference_program',
]


Expand Down
Loading

0 comments on commit df9c13a

Please sign in to comment.