Skip to content

Commit

Permalink
fluent methods for missed ops (apache#8329)
Browse files Browse the repository at this point in the history
  • Loading branch information
szha authored and Olivier committed Oct 19, 2017
1 parent 8609303 commit 660734b
Show file tree
Hide file tree
Showing 6 changed files with 228 additions and 10 deletions.
37 changes: 36 additions & 1 deletion docs/api/python/ndarray/ndarray.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ The `ndarray` package provides several classes:
NDArray.T
NDArray.reshape
NDArray.reshape_like
NDArray.flatten
NDArray.expand_dims
NDArray.split
Expand Down Expand Up @@ -194,6 +195,7 @@ The `ndarray` package provides several classes:
NDArray.topk
NDArray.argmax
NDArray.argmin
NDArray.argmax_channel
```

### Arithmetic operations
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -358,6 +375,7 @@ The `ndarray` package provides several classes:
cast
reshape
reshape_like
flatten
expand_dims
```
Expand Down Expand Up @@ -394,6 +412,7 @@ The `ndarray` package provides several classes:
concat
split
stack
```

### Indexing routines
Expand Down Expand Up @@ -514,11 +533,13 @@ The `ndarray` package provides several classes:
power
sqrt
rsqrt
cbrt
rcbrt
square
reciprocal
```

### Logic functions
### Comparison

```eval_rst
.. autosummary::
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -592,6 +625,8 @@ The `ndarray` package provides several classes:
SoftmaxOutput
softmax
log_softmax
relu
sigmoid
```

### More
Expand Down
38 changes: 35 additions & 3 deletions docs/api/python/symbol/symbol.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
```
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -355,6 +371,7 @@ Composite multiple symbols into a new one by an operator.
cast
reshape
reshape_like
flatten
expand_dims
```
Expand Down Expand Up @@ -391,6 +408,7 @@ Composite multiple symbols into a new one by an operator.
concat
split
stack
```

### Indexing routines
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -492,7 +509,6 @@ Composite multiple symbols into a new one by an operator.
trunc
```


### Exponents and logarithms

```eval_rst
Expand All @@ -519,9 +535,10 @@ Composite multiple symbols into a new one by an operator.
cbrt
rcbrt
square
reciprocal
```

### Logic functions
### Comparison

```eval_rst
.. autosummary::
Expand All @@ -534,6 +551,7 @@ Composite multiple symbols into a new one by an operator.
broadcast_lesser
broadcast_lesser_equal
```

### Random sampling

```eval_rst
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -596,6 +626,8 @@ Composite multiple symbols into a new one by an operator.
SoftmaxOutput
softmax
log_softmax
relu
sigmoid
```

### More
Expand Down
72 changes: 72 additions & 0 deletions python/mxnet/ndarray/ndarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -736,6 +736,14 @@ def reshape(self, shape):
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`.
Expand Down Expand Up @@ -864,6 +872,14 @@ def argmax(self, *args, **kwargs):
"""
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`.
Expand Down Expand Up @@ -1224,6 +1240,22 @@ def rsqrt(self, *args, **kwargs):
"""
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`.
Expand All @@ -1232,6 +1264,46 @@ def square(self, *args, **kwargs):
"""
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.
Expand Down
Loading

0 comments on commit 660734b

Please sign in to comment.