mirror of
https://github.com/RustyRaptor/incubator-mxnet.git
synced 2026-12-04 08:15:21 -07:00
* changes to broadcast, linearregressionoutput, maeregressionoutput, logisticregressionoutput operators * changes to broadcast_axis * broadcast_add, broadcast_sub, broadcast_mul, broadcast_div operators doc * Regression methods doc rewrite * some formatting and added broadcasting summary * minor formatting change * Added broadcast_power,broadcast_maximum, broadcast_minimum, broadcast_hypot * changes according to review to ndarray.py file * changes according to the review * minor changes * minor grammar changed, remaining broadcast methods added * line too long error removed * minor change for parameter * Changes according to Zack's review * minor change * small changes after review * line too long removed
106 lines
2.8 KiB
Python
106 lines
2.8 KiB
Python
# coding: utf-8
|
|
# pylint: disable=unused-argument, too-many-arguments
|
|
"""Extra symbol documents"""
|
|
from __future__ import absolute_import as _abs
|
|
import re as _re
|
|
|
|
from .base import build_param_doc as _build_param_doc
|
|
|
|
class NDArrayDoc(object):
|
|
"""The basic class"""
|
|
pass
|
|
|
|
class ReshapeDoc(NDArrayDoc):
|
|
"""
|
|
Examples
|
|
--------
|
|
Reshapes the input array into a new shape.
|
|
|
|
>>> x = mx.nd.array([1, 2, 3, 4])
|
|
>>> y = mx.nd.reshape(x,shape=(2, 2))
|
|
>>> x.shape
|
|
(4L,)
|
|
>>> y.shape
|
|
(2L, 2L)
|
|
>>> y.asnumpy()
|
|
array([[ 1., 2.],
|
|
[ 3., 4.]], dtype=float32)
|
|
|
|
You can use ``0`` to copy a particular dimension from the input to the output shape
|
|
and '-1' to infer the dimensions of the output.
|
|
|
|
>>> x = mx.nd.ones((2, 3, 4))
|
|
>>> x.shape
|
|
(2L, 3L, 4L)
|
|
>>> y = mx.nd.reshape(x, shape=(4, 0, -1))
|
|
>>> y.shape
|
|
(4L, 3L, 2L)
|
|
"""
|
|
|
|
class BroadcastToDoc(NDArrayDoc):
|
|
"""
|
|
Examples
|
|
--------
|
|
Broadcasts the input array into a new shape.
|
|
>>> a = mx.nd.array(np.arange(6).reshape(6,1))
|
|
>>> b = a.broadcast_to((6,2))
|
|
>>> a.shape
|
|
(6L, 1L)
|
|
>>> b.shape
|
|
(6L, 2L)
|
|
>>> b.asnumpy()
|
|
array([[ 0., 0.],
|
|
[ 1., 1.],
|
|
[ 2., 2.],
|
|
[ 3., 3.],
|
|
[ 4., 4.],
|
|
[ 5., 5.]], dtype=float32)
|
|
Broadcasts along axes 1 and 2.
|
|
>>> c = a.reshape((2,1,1,3))
|
|
>>> d = c.broadcast_to((2,2,2,3))
|
|
>>> d.asnumpy()
|
|
array([[[[ 0., 1., 2.],
|
|
[ 0., 1., 2.]],
|
|
|
|
[[ 0., 1., 2.],
|
|
[ 0., 1., 2.]]],
|
|
|
|
|
|
[[[ 3., 4., 5.],
|
|
[ 3., 4., 5.]],
|
|
|
|
[[ 3., 4., 5.],
|
|
[ 3., 4., 5.]]]], dtype=float32)
|
|
>>> c.shape
|
|
(2L, 1L, 1L, 3L)
|
|
>>> d.shape
|
|
(2L, 2L, 2L, 3L)
|
|
"""
|
|
|
|
def _build_doc(func_name,
|
|
desc,
|
|
arg_names,
|
|
arg_types,
|
|
arg_desc,
|
|
key_var_num_args=None,
|
|
ret_type=None):
|
|
"""Build docstring for imperative functions."""
|
|
param_str = _build_param_doc(arg_names, arg_types, arg_desc)
|
|
# if key_var_num_args:
|
|
# desc += '\nThis function support variable length of positional input.'
|
|
doc_str = ('%s\n\n' +
|
|
'%s\n' +
|
|
'out : NDArray, optional\n' +
|
|
' The output NDArray to hold the result.\n\n'+
|
|
'Returns\n' +
|
|
'-------\n' +
|
|
'out : NDArray or list of NDArrays\n' +
|
|
' The output of this function.')
|
|
doc_str = doc_str % (desc, param_str)
|
|
extra_doc = "\n" + '\n'.join([x.__doc__ for x in type.__subclasses__(NDArrayDoc)
|
|
if x.__name__ == '%sDoc' % func_name])
|
|
doc_str += _re.sub(_re.compile(" "), "", extra_doc)
|
|
doc_str = _re.sub('NDArray-or-Symbol', 'NDArray', doc_str)
|
|
|
|
return doc_str
|