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
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

@ -5,104 +5,114 @@ applying the function to every element in the array. This is typically
much more efficient than expressing the same operation as a Python loop."""
def acos():
"""Computes the inverse cosine function"""
...
"""Computes the inverse cosine function"""
...
def acosh():
"""Computes the inverse hyperbolic cosine function"""
...
"""Computes the inverse hyperbolic cosine function"""
...
def asin():
"""Computes the inverse sine function"""
...
"""Computes the inverse sine function"""
...
def asinh():
"""Computes the inverse hyperbolic sine function"""
...
"""Computes the inverse hyperbolic sine function"""
...
def around(a, *, decimals):
"""Returns a new float array in which each element is rounded to
``decimals`` places."""
...
"""Returns a new float array in which each element is rounded to
``decimals`` places."""
...
def atan():
"""Computes the inverse tangent function; the return values are in the
range [-pi/2,pi/2]."""
...
"""Computes the inverse tangent function; the return values are in the
range [-pi/2,pi/2]."""
...
def atan2(y,x):
"""Computes the inverse tangent function of y/x; the return values are in
the range [-pi, pi]."""
...
"""Computes the inverse tangent function of y/x; the return values are in
the range [-pi, pi]."""
...
def atanh():
"""Computes the inverse hyperbolic tangent function"""
...
"""Computes the inverse hyperbolic tangent function"""
...
def ceil():
"""Rounds numbers up to the next whole number"""
...
"""Rounds numbers up to the next whole number"""
...
def cos():
"""Computes the cosine function"""
...
"""Computes the cosine function"""
...
def erf():
"""Computes the error function, which has applications in statistics"""
...
"""Computes the error function, which has applications in statistics"""
...
def erfc():
"""Computes the complementary error function, which has applications in statistics"""
...
"""Computes the complementary error function, which has applications in statistics"""
...
def exp():
"""Computes the exponent function."""
...
"""Computes the exponent function."""
...
def expm1():
"""Computes $e^x-1$. In certain applications, using this function preserves numeric accuracy better than the `exp` function."""
...
"""Computes $e^x-1$. In certain applications, using this function preserves numeric accuracy better than the `exp` function."""
...
def floor():
"""Rounds numbers up to the next whole number"""
...
"""Rounds numbers up to the next whole number"""
...
def gamma():
"""Computes the gamma function"""
...
"""Computes the gamma function"""
...
def lgamma():
"""Computes the natural log of the gamma function"""
...
"""Computes the natural log of the gamma function"""
...
def log():
"""Computes the natural log"""
...
"""Computes the natural log"""
...
def log10():
"""Computes the log base 10"""
...
"""Computes the log base 10"""
...
def log2():
"""Computes the log base 2"""
...
"""Computes the log base 2"""
...
def sin():
"""Computes the sine"""
...
"""Computes the sine"""
...
def sinh():
"""Computes the hyperbolic sine"""
...
"""Computes the hyperbolic sine"""
...
def sqrt():
"""Computes the square root"""
...
"""Computes the square root"""
...
def tan():
"""Computes the tangent"""
...
"""Computes the tangent"""
...
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."""
...