summaryrefslogtreecommitdiff
path: root/numpy/add_newdocs.py
diff options
context:
space:
mode:
authorrgommers <ralf.gommers@googlemail.com>2011-03-07 12:55:55 +0800
committerrgommers <ralf.gommers@googlemail.com>2011-03-07 12:59:28 +0800
commitc081ad795a70fcd0168edda6d63f3ebc7c5529a7 (patch)
tree35992784907a6163c814dd55aee137495247ca33 /numpy/add_newdocs.py
parent51b5c585890967283aa6ddcdbb9ff624f0ee4866 (diff)
downloadnumpy-c081ad795a70fcd0168edda6d63f3ebc7c5529a7.tar.gz
DOC: Revert part of previous commit, moving umath docs did not work.
If the ldexp/frexp docs belong in ufunc_docsrtings.py, they need an entry in core/code_generators/generate_umath.py. See #1759.
Diffstat (limited to 'numpy/add_newdocs.py')
-rw-r--r--numpy/add_newdocs.py247
1 files changed, 247 insertions, 0 deletions
diff --git a/numpy/add_newdocs.py b/numpy/add_newdocs.py
index 1cbf27c7d..187180c5a 100644
--- a/numpy/add_newdocs.py
+++ b/numpy/add_newdocs.py
@@ -4048,6 +4048,253 @@ add_newdoc('numpy.core.multiarray', 'ndarray', ('view',
##############################################################################
#
+# umath functions
+#
+##############################################################################
+
+add_newdoc('numpy.core.umath', 'frexp',
+ """
+ Return normalized fraction and exponent of 2 of input array, element-wise.
+
+ Returns (`out1`, `out2`) from equation ``x` = out1 * 2**out2``.
+
+ Parameters
+ ----------
+ x : array_like
+ Input array.
+
+ Returns
+ -------
+ (out1, out2) : tuple of ndarrays, (float, int)
+ `out1` is a float array with values between -1 and 1.
+ `out2` is an int array which represent the exponent of 2.
+
+ See Also
+ --------
+ ldexp : Compute ``y = x1 * 2**x2``, the inverse of `frexp`.
+
+ Notes
+ -----
+ Complex dtypes are not supported, they will raise a TypeError.
+
+ Examples
+ --------
+ >>> x = np.arange(9)
+ >>> y1, y2 = np.frexp(x)
+ >>> y1
+ array([ 0. , 0.5 , 0.5 , 0.75 , 0.5 , 0.625, 0.75 , 0.875,
+ 0.5 ])
+ >>> y2
+ array([0, 1, 2, 2, 3, 3, 3, 3, 4])
+ >>> y1 * 2**y2
+ array([ 0., 1., 2., 3., 4., 5., 6., 7., 8.])
+
+ """)
+
+add_newdoc('numpy.core.umath', 'frompyfunc',
+ """
+ frompyfunc(func, nin, nout)
+
+ Takes an arbitrary Python function and returns a Numpy ufunc.
+
+ Can be used, for example, to add broadcasting to a built-in Python
+ function (see Examples section).
+
+ Parameters
+ ----------
+ func : Python function object
+ An arbitrary Python function.
+ nin : int
+ The number of input arguments.
+ nout : int
+ The number of objects returned by `func`.
+
+ Returns
+ -------
+ out : ufunc
+ Returns a Numpy universal function (``ufunc``) object.
+
+ Notes
+ -----
+ The returned ufunc always returns PyObject arrays.
+
+ Examples
+ --------
+ Use frompyfunc to add broadcasting to the Python function ``oct``:
+
+ >>> oct_array = np.frompyfunc(oct, 1, 1)
+ >>> oct_array(np.array((10, 30, 100)))
+ array([012, 036, 0144], dtype=object)
+ >>> np.array((oct(10), oct(30), oct(100))) # for comparison
+ array(['012', '036', '0144'],
+ dtype='|S4')
+
+ """)
+
+add_newdoc('numpy.core.umath', 'ldexp',
+ """
+ Compute y = x1 * 2**x2.
+
+ Parameters
+ ----------
+ x1 : array_like
+ The array of multipliers.
+ x2 : array_like
+ The array of exponents.
+
+ Returns
+ -------
+ y : array_like
+ The output array, the result of ``x1 * 2**x2``.
+
+ See Also
+ --------
+ frexp : Return (y1, y2) from ``x = y1 * 2**y2``, the inverse of `ldexp`.
+
+ Notes
+ -----
+ Complex dtypes are not supported, they will raise a TypeError.
+
+ `ldexp` is useful as the inverse of `frexp`, if used by itself it is
+ more clear to simply use the expression ``x1 * 2**x2``.
+
+ Examples
+ --------
+ >>> np.ldexp(5, np.arange(4))
+ array([ 5., 10., 20., 40.], dtype=float32)
+
+ >>> x = np.arange(6)
+ >>> np.ldexp(*np.frexp(x))
+ array([ 0., 1., 2., 3., 4., 5.])
+
+ """)
+
+add_newdoc('numpy.core.umath', 'geterrobj',
+ """
+ geterrobj()
+
+ Return the current object that defines floating-point error handling.
+
+ The error object contains all information that defines the error handling
+ behavior in Numpy. `geterrobj` is used internally by the other
+ functions that get and set error handling behavior (`geterr`, `seterr`,
+ `geterrcall`, `seterrcall`).
+
+ Returns
+ -------
+ errobj : list
+ The error object, a list containing three elements:
+ [internal numpy buffer size, error mask, error callback function].
+
+ The error mask is a single integer that holds the treatment information
+ on all four floating point errors. The information for each error type
+ is contained in three bits of the integer. If we print it in base 8, we
+ can see what treatment is set for "invalid", "under", "over", and
+ "divide" (in that order). The printed string can be interpreted with
+
+ * 0 : 'ignore'
+ * 1 : 'warn'
+ * 2 : 'raise'
+ * 3 : 'call'
+ * 4 : 'print'
+ * 5 : 'log'
+
+ See Also
+ --------
+ seterrobj, seterr, geterr, seterrcall, geterrcall
+ getbufsize, setbufsize
+
+ Notes
+ -----
+ For complete documentation of the types of floating-point exceptions and
+ treatment options, see `seterr`.
+
+ Examples
+ --------
+ >>> np.geterrobj() # first get the defaults
+ [10000, 0, None]
+
+ >>> def err_handler(type, flag):
+ ... print "Floating point error (%s), with flag %s" % (type, flag)
+ ...
+ >>> old_bufsize = np.setbufsize(20000)
+ >>> old_err = np.seterr(divide='raise')
+ >>> old_handler = np.seterrcall(err_handler)
+ >>> np.geterrobj()
+ [20000, 2, <function err_handler at 0x91dcaac>]
+
+ >>> old_err = np.seterr(all='ignore')
+ >>> np.base_repr(np.geterrobj()[1], 8)
+ '0'
+ >>> old_err = np.seterr(divide='warn', over='log', under='call',
+ invalid='print')
+ >>> np.base_repr(np.geterrobj()[1], 8)
+ '4351'
+
+ """)
+
+add_newdoc('numpy.core.umath', 'seterrobj',
+ """
+ seterrobj(errobj)
+
+ Set the object that defines floating-point error handling.
+
+ The error object contains all information that defines the error handling
+ behavior in Numpy. `seterrobj` is used internally by the other
+ functions that set error handling behavior (`seterr`, `seterrcall`).
+
+ Parameters
+ ----------
+ errobj : list
+ The error object, a list containing three elements:
+ [internal numpy buffer size, error mask, error callback function].
+
+ The error mask is a single integer that holds the treatment information
+ on all four floating point errors. The information for each error type
+ is contained in three bits of the integer. If we print it in base 8, we
+ can see what treatment is set for "invalid", "under", "over", and
+ "divide" (in that order). The printed string can be interpreted with
+
+ * 0 : 'ignore'
+ * 1 : 'warn'
+ * 2 : 'raise'
+ * 3 : 'call'
+ * 4 : 'print'
+ * 5 : 'log'
+
+ See Also
+ --------
+ geterrobj, seterr, geterr, seterrcall, geterrcall
+ getbufsize, setbufsize
+
+ Notes
+ -----
+ For complete documentation of the types of floating-point exceptions and
+ treatment options, see `seterr`.
+
+ Examples
+ --------
+ >>> old_errobj = np.geterrobj() # first get the defaults
+ >>> old_errobj
+ [10000, 0, None]
+
+ >>> def err_handler(type, flag):
+ ... print "Floating point error (%s), with flag %s" % (type, flag)
+ ...
+ >>> new_errobj = [20000, 12, err_handler]
+ >>> np.seterrobj(new_errobj)
+ >>> np.base_repr(12, 8) # int for divide=4 ('print') and over=1 ('warn')
+ '14'
+ >>> np.geterr()
+ {'over': 'warn', 'divide': 'print', 'invalid': 'ignore', 'under': 'ignore'}
+ >>> np.geterrcall() is err_handler
+ True
+
+ """)
+
+
+##############################################################################
+#
# lib._compiled_base functions
#
##############################################################################