ulab: update

.. add new modules and functions to our shared-bindings stubs
This commit is contained in:
Jeff Epler 2020-06-01 08:56:15 -05:00
parent f211a090e2
commit 18c659780e
4 changed files with 124 additions and 54 deletions

@ -1 +1 @@
Subproject commit cf61d728e70b9ec57e5711b40540793a89296f5d Subproject commit cbdd1295c11e9b810a2712ac5bdfd51381967bf0

View File

@ -0,0 +1,52 @@
"""Numerical approximation methods"""
def bisect(fun, a, b, *, xtol=2.4e-7, maxiter=100) -> float:
"""
:param callable f: The function to bisect
:param float a: The left side of the interval
:param float b: The right side of the interval
:param float xtol: The tolerance value
:param float maxiter: The maximum number of iterations to perform
Find a solution (zero) of the function ``f(x)`` on the interval
(``a``..``b``) using the bisection method. The result is accurate to within
``xtol`` unless more than ``maxiter`` steps are required."""
...
def newton(fun, x0, *, xtol=2.4e-7, rtol=0.0, maxiter=50) -> float:
"""
:param callable f: The function to bisect
:param float x0: The initial x value
:param float xtol: The absolute tolerance value
:param float rtol: The relative tolerance value
:param float maxiter: The maximum number of iterations to perform
Find a solution (zero) of the function ``f(x)`` using Newton's Method.
The result is accurate to within ``xtol * rtol * |f(x)|`` unless more than
``maxiter`` steps are requried."""
...
def fmin(fun, x0, *, xatol=2.4e-7, fatol=2.4e-7, maxiter=200) -> float:
"""
:param callable f: The function to bisect
:param float x0: The initial x value
:param float xatol: The absolute tolerance value
:param float fatol: The relative tolerance value
Find a minimum of the function ``f(x)`` using the downhill simplex method.
The located ``x`` is within ``fxtol`` of the actual minimum, and ``f(x)``
is within ``fatol`` of the actual minimum unless more than ``maxiter``
steps are requried."""
...
def interp(x: ulab.array, xp:ulab.array, fp:ulab.array, *, left=None, right=None) -> ulab.array:
"""
:param ulab.array x: The x-coordinates at which to evaluate the interpolated values.
:param ulab.array xp: The x-coordinates of the data points, must be increasing
:param ulab.array fp: The y-coordinates of the data points, same length as xp
:param left: Value to return for ``x < xp[0]``, default is ``fp[0]``.
:param right: Value to return for ``x > xp[-1]``, default is ``fp[-1]``.
Returns the one-dimensional piecewise linear interpolant to a function with given discrete data points (xp, fp), evaluated at x."""
...

View File

@ -28,3 +28,11 @@ def minimum(x1, x2):
must be the same size. If the inputs are both scalars, a number is must be the same size. If the inputs are both scalars, a number is
returned""" returned"""
... ...
def equal(x1, x2):
"""Return an array of bool which is true where x1[i] == x2[i] and false elsewhere"""
...
def not_equal(x1, x2):
"""Return an array of bool which is false where x1[i] == x2[i] and true elsewhere"""
...

View File

@ -106,3 +106,13 @@ def tan():
def tanh(): def tanh():
"""Computes the hyperbolic tangent""" """Computes the hyperbolic tangent"""
... ...
def vectorise(f, *, otypes=None):
"""
:param callable f: The function to wrap
:param otypes: List of array types that may be returned by the function. None is intepreted to mean the return value is float.
Wrap a Python function `f` so that it can be applied to arrays.
The callable must return only values of the types specified by otypes, or the result is undefined."""
...