You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mxnet.apache.org by zh...@apache.org on 2017/10/18 05:57:23 UTC
[incubator-mxnet] branch master updated: fluent methods for missed
ops (#8329)
This is an automated email from the ASF dual-hosted git repository.
zhasheng pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-mxnet.git
The following commit(s) were added to refs/heads/master by this push:
new dd3853f fluent methods for missed ops (#8329)
dd3853f is described below
commit dd3853f997655c9a79b1197d94ae210808363322
Author: Sheng Zha <sz...@users.noreply.github.com>
AuthorDate: Tue Oct 17 22:57:20 2017 -0700
fluent methods for missed ops (#8329)
---
docs/api/python/ndarray/ndarray.md | 37 +++++++++++++++++-
docs/api/python/symbol/symbol.md | 38 ++++++++++++++++--
python/mxnet/ndarray/ndarray.py | 72 +++++++++++++++++++++++++++++++++++
python/mxnet/symbol/symbol.py | 72 +++++++++++++++++++++++++++++++++++
tests/python/unittest/test_ndarray.py | 10 +++--
tests/python/unittest/test_symbol.py | 9 +++--
6 files changed, 228 insertions(+), 10 deletions(-)
diff --git a/docs/api/python/ndarray/ndarray.md b/docs/api/python/ndarray/ndarray.md
index 615b9dc..09564c2 100644
--- a/docs/api/python/ndarray/ndarray.md
+++ b/docs/api/python/ndarray/ndarray.md
@@ -125,6 +125,7 @@ The `ndarray` package provides several classes:
NDArray.T
NDArray.reshape
+ NDArray.reshape_like
NDArray.flatten
NDArray.expand_dims
NDArray.split
@@ -194,6 +195,7 @@ The `ndarray` package provides several classes:
NDArray.topk
NDArray.argmax
NDArray.argmin
+ NDArray.argmax_channel
```
### Arithmetic operations
@@ -266,7 +268,22 @@ The `ndarray` package provides several classes:
NDArray.sqrt
NDArray.rsqrt
+ NDArray.cbrt
+ NDArray.rcbrt
NDArray.square
+ NDArray.reciprocal
+```
+
+## Basic neural network functions
+
+```eval_rst
+.. autosummary::
+ :nosignatures:
+
+ NDArray.relu
+ NDArray.sigmoid
+ NDArray.softmax
+ NDArray.log_softmax
```
### In-place arithmetic operations
@@ -358,6 +375,7 @@ The `ndarray` package provides several classes:
cast
reshape
+ reshape_like
flatten
expand_dims
```
@@ -394,6 +412,7 @@ The `ndarray` package provides several classes:
concat
split
+ stack
```
### Indexing routines
@@ -514,11 +533,13 @@ The `ndarray` package provides several classes:
power
sqrt
rsqrt
+ cbrt
+ rcbrt
square
reciprocal
```
-### Logic functions
+### Comparison
```eval_rst
.. autosummary::
@@ -559,6 +580,18 @@ The `ndarray` package provides several classes:
argsort
argmax
argmin
+ argmax_channel
+```
+
+### Sequence operation
+
+```eval_rst
+.. autosummary::
+ :nosignatures:
+
+ SequenceLast
+ SequenceMask
+ SequenceReverse
```
### Miscellaneous
@@ -592,6 +625,8 @@ The `ndarray` package provides several classes:
SoftmaxOutput
softmax
log_softmax
+ relu
+ sigmoid
```
### More
diff --git a/docs/api/python/symbol/symbol.md b/docs/api/python/symbol/symbol.md
index 7570e18..e93976d 100644
--- a/docs/api/python/symbol/symbol.md
+++ b/docs/api/python/symbol/symbol.md
@@ -143,9 +143,23 @@ Composite multiple symbols into a new one by an operator.
Symbol.sqrt
Symbol.rsqrt
+ Symbol.cbrt
+ Symbol.rcbrt
Symbol.square
```
+## Basic neural network functions
+
+```eval_rst
+.. autosummary::
+ :nosignatures:
+
+ Symbol.relu
+ Symbol.sigmoid
+ Symbol.softmax
+ Symbol.log_softmax
+```
+
#### Comparison operators
```eval_rst
@@ -178,6 +192,7 @@ Composite multiple symbols into a new one by an operator.
Symbol.astype
Symbol.reshape
+ Symbol.reshape_like
Symbol.flatten
Symbol.expand_dims
```
@@ -246,6 +261,7 @@ Composite multiple symbols into a new one by an operator.
Symbol.topk
Symbol.argmax
Symbol.argmin
+ Symbol.argmax_channel
```
### Query information
@@ -355,6 +371,7 @@ Composite multiple symbols into a new one by an operator.
cast
reshape
+ reshape_like
flatten
expand_dims
```
@@ -391,6 +408,7 @@ Composite multiple symbols into a new one by an operator.
concat
split
+ stack
```
### Indexing routines
@@ -424,7 +442,6 @@ Composite multiple symbols into a new one by an operator.
broadcast_div
broadcast_mod
negative
- reciprocal
dot
batch_dot
add_n
@@ -492,7 +509,6 @@ Composite multiple symbols into a new one by an operator.
trunc
```
-
### Exponents and logarithms
```eval_rst
@@ -519,9 +535,10 @@ Composite multiple symbols into a new one by an operator.
cbrt
rcbrt
square
+ reciprocal
```
-### Logic functions
+### Comparison
```eval_rst
.. autosummary::
@@ -534,6 +551,7 @@ Composite multiple symbols into a new one by an operator.
broadcast_lesser
broadcast_lesser_equal
```
+
### Random sampling
```eval_rst
@@ -561,6 +579,18 @@ Composite multiple symbols into a new one by an operator.
argsort
argmax
argmin
+ argmax_channel
+```
+
+### Sequence operation
+
+```eval_rst
+.. autosummary::
+ :nosignatures:
+
+ SequenceLast
+ SequenceMask
+ SequenceReverse
```
### Miscellaneous
@@ -596,6 +626,8 @@ Composite multiple symbols into a new one by an operator.
SoftmaxOutput
softmax
log_softmax
+ relu
+ sigmoid
```
### More
diff --git a/python/mxnet/ndarray/ndarray.py b/python/mxnet/ndarray/ndarray.py
index 2f9972b..1cd9f40 100644
--- a/python/mxnet/ndarray/ndarray.py
+++ b/python/mxnet/ndarray/ndarray.py
@@ -736,6 +736,14 @@ fixed-size items.
ctypes.byref(handle)))
return NDArray(handle=handle, writable=self.writable)
+ def reshape_like(self, *args, **kwargs):
+ """Convenience fluent method for :py:func:`reshape_like`.
+
+ The arguments are the same as for :py:func:`reshape_like`, with
+ this array as data.
+ """
+ return op.reshape_like(self, *args, **kwargs)
+
def zeros_like(self, *args, **kwargs):
"""Convenience fluent method for :py:func:`zeros_like`.
@@ -864,6 +872,14 @@ fixed-size items.
"""
return op.argmax(self, *args, **kwargs)
+ def argmax_channel(self, *args, **kwargs):
+ """Convenience fluent method for :py:func:`argmax_channel`.
+
+ The arguments are the same as for :py:func:`argmax_channel`, with
+ this array as data.
+ """
+ return op.argmax_channel(self, *args, **kwargs)
+
def argmin(self, *args, **kwargs):
"""Convenience fluent method for :py:func:`argmin`.
@@ -1224,6 +1240,22 @@ fixed-size items.
"""
return op.rsqrt(self, *args, **kwargs)
+ def cbrt(self, *args, **kwargs):
+ """Convenience fluent method for :py:func:`cbrt`.
+
+ The arguments are the same as for :py:func:`cbrt`, with
+ this array as data.
+ """
+ return op.cbrt(self, *args, **kwargs)
+
+ def rcbrt(self, *args, **kwargs):
+ """Convenience fluent method for :py:func:`rcbrt`.
+
+ The arguments are the same as for :py:func:`rcbrt`, with
+ this array as data.
+ """
+ return op.rcbrt(self, *args, **kwargs)
+
def square(self, *args, **kwargs):
"""Convenience fluent method for :py:func:`square`.
@@ -1232,6 +1264,46 @@ fixed-size items.
"""
return op.square(self, *args, **kwargs)
+ def reciprocal(self, *args, **kwargs):
+ """Convenience fluent method for :py:func:`reciprocal`.
+
+ The arguments are the same as for :py:func:`reciprocal`, with
+ this array as data.
+ """
+ return op.reciprocal(self, *args, **kwargs)
+
+ def relu(self, *args, **kwargs):
+ """Convenience fluent method for :py:func:`relu`.
+
+ The arguments are the same as for :py:func:`relu`, with
+ this array as data.
+ """
+ return op.relu(self, *args, **kwargs)
+
+ def sigmoid(self, *args, **kwargs):
+ """Convenience fluent method for :py:func:`sigmoid`.
+
+ The arguments are the same as for :py:func:`sigmoid`, with
+ this array as data.
+ """
+ return op.sigmoid(self, *args, **kwargs)
+
+ def softmax(self, *args, **kwargs):
+ """Convenience fluent method for :py:func:`softmax`.
+
+ The arguments are the same as for :py:func:`softmax`, with
+ this array as data.
+ """
+ return op.softmax(self, *args, **kwargs)
+
+ def log_softmax(self, *args, **kwargs):
+ """Convenience fluent method for :py:func:`log_softmax`.
+
+ The arguments are the same as for :py:func:`log_softmax`, with
+ this array as data.
+ """
+ return op.log_softmax(self, *args, **kwargs)
+
# pylint: disable= undefined-variable
def broadcast_to(self, shape):
"""Broadcasts the input array to a new shape.
diff --git a/python/mxnet/symbol/symbol.py b/python/mxnet/symbol/symbol.py
index 3c76826..6903db0 100644
--- a/python/mxnet/symbol/symbol.py
+++ b/python/mxnet/symbol/symbol.py
@@ -1745,6 +1745,14 @@ class Symbol(SymbolBase):
"""
return op.reshape(self, *args, **kwargs)
+ def reshape_like(self, *args, **kwargs):
+ """Convenience fluent method for :py:func:`reshape_like`.
+
+ The arguments are the same as for :py:func:`reshape_like`, with
+ this array as data.
+ """
+ return op.reshape_like(self, *args, **kwargs)
+
def astype(self, *args, **kwargs):
"""Convenience fluent method for :py:func:`cast`.
@@ -1881,6 +1889,14 @@ class Symbol(SymbolBase):
"""
return op.argmax(self, *args, **kwargs)
+ def argmax_channel(self, *args, **kwargs):
+ """Convenience fluent method for :py:func:`argmax_channel`.
+
+ The arguments are the same as for :py:func:`argmax_channel`, with
+ this array as data.
+ """
+ return op.argmax_channel(self, *args, **kwargs)
+
def argmin(self, *args, **kwargs):
"""Convenience fluent method for :py:func:`argmin`.
@@ -2249,6 +2265,22 @@ class Symbol(SymbolBase):
"""
return op.rsqrt(self, *args, **kwargs)
+ def cbrt(self, *args, **kwargs):
+ """Convenience fluent method for :py:func:`cbrt`.
+
+ The arguments are the same as for :py:func:`cbrt`, with
+ this array as data.
+ """
+ return op.cbrt(self, *args, **kwargs)
+
+ def rcbrt(self, *args, **kwargs):
+ """Convenience fluent method for :py:func:`rcbrt`.
+
+ The arguments are the same as for :py:func:`rcbrt`, with
+ this array as data.
+ """
+ return op.rcbrt(self, *args, **kwargs)
+
def square(self, *args, **kwargs):
"""Convenience fluent method for :py:func:`square`.
@@ -2257,6 +2289,46 @@ class Symbol(SymbolBase):
"""
return op.square(self, *args, **kwargs)
+ def reciprocal(self, *args, **kwargs):
+ """Convenience fluent method for :py:func:`reciprocal`.
+
+ The arguments are the same as for :py:func:`reciprocal`, with
+ this array as data.
+ """
+ return op.reciprocal(self, *args, **kwargs)
+
+ def relu(self, *args, **kwargs):
+ """Convenience fluent method for :py:func:`relu`.
+
+ The arguments are the same as for :py:func:`relu`, with
+ this array as data.
+ """
+ return op.relu(self, *args, **kwargs)
+
+ def sigmoid(self, *args, **kwargs):
+ """Convenience fluent method for :py:func:`sigmoid`.
+
+ The arguments are the same as for :py:func:`sigmoid`, with
+ this array as data.
+ """
+ return op.sigmoid(self, *args, **kwargs)
+
+ def softmax(self, *args, **kwargs):
+ """Convenience fluent method for :py:func:`softmax`.
+
+ The arguments are the same as for :py:func:`softmax`, with
+ this array as data.
+ """
+ return op.softmax(self, *args, **kwargs)
+
+ def log_softmax(self, *args, **kwargs):
+ """Convenience fluent method for :py:func:`log_softmax`.
+
+ The arguments are the same as for :py:func:`log_softmax`, with
+ this array as data.
+ """
+ return op.log_softmax(self, *args, **kwargs)
+
def wait_to_read(self):
raise NotImplementedForSymbol(self.wait_to_read, None)
diff --git a/tests/python/unittest/test_ndarray.py b/tests/python/unittest/test_ndarray.py
index e5dddeb..576d963 100644
--- a/tests/python/unittest/test_ndarray.py
+++ b/tests/python/unittest/test_ndarray.py
@@ -742,7 +742,9 @@ def test_ndarray_fluent():
'one_hot', 'pick', 'sort', 'topk', 'argsort', 'argmax', 'argmin',
'clip', 'abs', 'sign', 'sin', 'cos', 'tan', 'arcsin', 'arccos', 'arctan',
'degrees', 'radians', 'sinh', 'cosh', 'tanh', 'arcsinh', 'arccosh', 'arctanh',
- 'exp', 'expm1', 'log', 'log10', 'log2', 'log1p', 'sqrt', 'rsqrt', 'square'])
+ 'exp', 'expm1', 'log', 'log10', 'log2', 'log1p', 'sqrt', 'rsqrt', 'square',
+ 'reshape_like', 'cbrt', 'rcbrt', 'relu', 'sigmoid', 'softmax', 'log_softmax',
+ 'reciprocal'])
def check_fluent_regular(func, kwargs, shape=(5, 17, 1), equal_nan=False):
with mx.name.NameManager():
data = mx.nd.random_uniform(shape=shape, ctx=default_context())
@@ -756,11 +758,12 @@ def test_ndarray_fluent():
for func in ['flatten', 'norm', 'round', 'rint', 'fix', 'floor', 'ceil', 'trunc', 'zeros_like',
'ones_like', 'abs', 'sign', 'sin', 'cos', 'degrees', 'radians',
- 'exp', 'expm1', 'square']:
+ 'exp', 'expm1', 'square', 'reciprocal', 'argmax_channel']:
check_fluent_regular(func, {})
for func in ['arccosh', 'arcsin', 'arccos', 'arctan', 'tan', 'sinh', 'cosh', 'tanh',
- 'arcsinh', 'arctanh', 'log', 'log10', 'log2', 'log1p', 'sqrt', 'rsqrt']:
+ 'arcsinh', 'arctanh', 'log', 'log10', 'log2', 'log1p', 'sqrt', 'rsqrt',
+ 'cbrt', 'rcbrt', 'relu', 'sigmoid', 'softmax', 'log_softmax']:
check_fluent_regular(func, {}, equal_nan=True)
for func in ['expand_dims', 'flip', 'sort', 'topk', 'argsort', 'argmax', 'argmin']:
@@ -778,6 +781,7 @@ def test_ndarray_fluent():
check_fluent_regular('clip', {'a_min': 0.25, 'a_max': 0.75})
check_fluent_regular('broadcast_axes', {'axis': (2,), 'size': (5,)})
check_fluent_regular('pad', {'mode': 'constant', 'pad_width': (0,0,0,0,3,0,0,4)}, shape=(5, 17, 2, 3))
+ check_fluent_regular('reshape_like', {'rhs': mx.nd.ones((30, 17))}, shape=(5, 17, 2, 3))
for func in ['sum', 'nansum', 'prod', 'nanprod', 'mean', 'max', 'min']:
check_fluent_regular(func, {'axis': (1, 2)})
diff --git a/tests/python/unittest/test_symbol.py b/tests/python/unittest/test_symbol.py
index 2d31c60..30e76a2 100644
--- a/tests/python/unittest/test_symbol.py
+++ b/tests/python/unittest/test_symbol.py
@@ -168,7 +168,8 @@ def test_symbol_fluent():
'clip', 'abs', 'sign', 'sin', 'cos', 'tan', 'arcsin', 'arccos', 'arctan',
'degrees', 'radians', 'sinh', 'cosh', 'tanh', 'arcsinh', 'arccosh', 'arctanh',
'exp', 'expm1', 'log', 'log10', 'log2', 'log1p', 'sqrt', 'rsqrt',
- 'square'])
+ 'square', 'reciprocal' 'reshape_like', 'cbrt', 'rcbrt', 'relu', 'sigmoid',
+ 'softmax', 'log_softmax'])
def check_fluent_regular(func, kwargs, shape=(5, 17, 1), equal_nan=False):
with mx.name.NameManager():
data = mx.symbol.Variable('data')
@@ -181,11 +182,12 @@ def test_symbol_fluent():
for func in ['flatten', 'norm', 'round', 'rint', 'fix', 'floor', 'ceil', 'trunc', 'zeros_like',
'ones_like', 'abs', 'sign', 'sin', 'cos', 'degrees', 'radians',
- 'exp', 'expm1', 'square']:
+ 'exp', 'expm1', 'square', 'reciprocal', 'argmax_channel']:
check_fluent_regular(func, {})
for func in ['arccosh', 'arcsin', 'arccos', 'arctan', 'tan', 'sinh', 'cosh', 'tanh',
- 'arcsinh', 'arctanh', 'log', 'log10', 'log2', 'log1p', 'sqrt', 'rsqrt']:
+ 'arcsinh', 'arctanh', 'log', 'log10', 'log2', 'log1p', 'sqrt', 'rsqrt',
+ 'cbrt', 'rcbrt', 'relu', 'sigmoid', 'softmax', 'log_softmax']:
check_fluent_regular(func, {}, equal_nan=True)
for func in ['expand_dims', 'flip', 'sort', 'topk', 'argsort', 'argmax', 'argmin']:
@@ -201,6 +203,7 @@ def test_symbol_fluent():
check_fluent_regular('clip', {'a_min': 0.25, 'a_max': 0.75})
check_fluent_regular('broadcast_axes', {'axis': (2,), 'size': (5,)})
check_fluent_regular('pad', {'mode': 'constant', 'pad_width': (0,0,0,0,3,0,0,4)}, shape=(5, 17, 2, 3))
+ check_fluent_regular('reshape_like', {'rhs': mx.sym.ones((30, 17))}, shape=(5, 17, 2, 3))
for func in ['sum', 'nansum', 'prod', 'nanprod', 'mean', 'max', 'min']:
check_fluent_regular(func, {'axis': (1, 2)})
--
To stop receiving notification emails like this one, please contact
['"commits@mxnet.apache.org" <co...@mxnet.apache.org>'].