Skip to content

Commit 18c6597

Browse files
committed
ulab: update
.. add new modules and functions to our shared-bindings stubs
1 parent f211a09 commit 18c6597

File tree

4 files changed

+124
-54
lines changed

4 files changed

+124
-54
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
"""Numerical approximation methods"""
2+
3+
def bisect(fun, a, b, *, xtol=2.4e-7, maxiter=100) -> float:
4+
"""
5+
:param callable f: The function to bisect
6+
:param float a: The left side of the interval
7+
:param float b: The right side of the interval
8+
:param float xtol: The tolerance value
9+
:param float maxiter: The maximum number of iterations to perform
10+
11+
Find a solution (zero) of the function ``f(x)`` on the interval
12+
(``a``..``b``) using the bisection method. The result is accurate to within
13+
``xtol`` unless more than ``maxiter`` steps are required."""
14+
...
15+
16+
def newton(fun, x0, *, xtol=2.4e-7, rtol=0.0, maxiter=50) -> float:
17+
"""
18+
:param callable f: The function to bisect
19+
:param float x0: The initial x value
20+
:param float xtol: The absolute tolerance value
21+
:param float rtol: The relative tolerance value
22+
:param float maxiter: The maximum number of iterations to perform
23+
24+
Find a solution (zero) of the function ``f(x)`` using Newton's Method.
25+
The result is accurate to within ``xtol * rtol * |f(x)|`` unless more than
26+
``maxiter`` steps are requried."""
27+
...
28+
29+
def fmin(fun, x0, *, xatol=2.4e-7, fatol=2.4e-7, maxiter=200) -> float:
30+
"""
31+
:param callable f: The function to bisect
32+
:param float x0: The initial x value
33+
:param float xatol: The absolute tolerance value
34+
:param float fatol: The relative tolerance value
35+
36+
Find a minimum of the function ``f(x)`` using the downhill simplex method.
37+
The located ``x`` is within ``fxtol`` of the actual minimum, and ``f(x)``
38+
is within ``fatol`` of the actual minimum unless more than ``maxiter``
39+
steps are requried."""
40+
...
41+
42+
def interp(x: ulab.array, xp:ulab.array, fp:ulab.array, *, left=None, right=None) -> ulab.array:
43+
"""
44+
:param ulab.array x: The x-coordinates at which to evaluate the interpolated values.
45+
:param ulab.array xp: The x-coordinates of the data points, must be increasing
46+
:param ulab.array fp: The y-coordinates of the data points, same length as xp
47+
:param left: Value to return for ``x < xp[0]``, default is ``fp[0]``.
48+
:param right: Value to return for ``x > xp[-1]``, default is ``fp[-1]``.
49+
50+
Returns the one-dimensional piecewise linear interpolant to a function with given discrete data points (xp, fp), evaluated at x."""
51+
...
52+

shared-bindings/ulab/compare/__init__.pyi

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,11 @@ def minimum(x1, x2):
2828
must be the same size. If the inputs are both scalars, a number is
2929
returned"""
3030
...
31+
32+
def equal(x1, x2):
33+
"""Return an array of bool which is true where x1[i] == x2[i] and false elsewhere"""
34+
...
35+
36+
def not_equal(x1, x2):
37+
"""Return an array of bool which is false where x1[i] == x2[i] and true elsewhere"""
38+
...

shared-bindings/ulab/vector/__init__.pyi

Lines changed: 63 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -5,104 +5,114 @@ applying the function to every element in the array. This is typically
55
much more efficient than expressing the same operation as a Python loop."""
66

77
def acos():
8-
"""Computes the inverse cosine function"""
9-
...
8+
"""Computes the inverse cosine function"""
9+
...
1010

1111
def acosh():
12-
"""Computes the inverse hyperbolic cosine function"""
13-
...
12+
"""Computes the inverse hyperbolic cosine function"""
13+
...
1414

1515
def asin():
16-
"""Computes the inverse sine function"""
17-
...
16+
"""Computes the inverse sine function"""
17+
...
1818

1919
def asinh():
20-
"""Computes the inverse hyperbolic sine function"""
21-
...
20+
"""Computes the inverse hyperbolic sine function"""
21+
...
2222

2323
def around(a, *, decimals):
24-
"""Returns a new float array in which each element is rounded to
25-
``decimals`` places."""
26-
...
24+
"""Returns a new float array in which each element is rounded to
25+
``decimals`` places."""
26+
...
2727

2828
def atan():
29-
"""Computes the inverse tangent function; the return values are in the
30-
range [-pi/2,pi/2]."""
31-
...
29+
"""Computes the inverse tangent function; the return values are in the
30+
range [-pi/2,pi/2]."""
31+
...
3232

3333
def atan2(y,x):
34-
"""Computes the inverse tangent function of y/x; the return values are in
35-
the range [-pi, pi]."""
36-
...
34+
"""Computes the inverse tangent function of y/x; the return values are in
35+
the range [-pi, pi]."""
36+
...
3737

3838
def atanh():
39-
"""Computes the inverse hyperbolic tangent function"""
40-
...
39+
"""Computes the inverse hyperbolic tangent function"""
40+
...
4141

4242
def ceil():
43-
"""Rounds numbers up to the next whole number"""
44-
...
43+
"""Rounds numbers up to the next whole number"""
44+
...
4545

4646
def cos():
47-
"""Computes the cosine function"""
48-
...
47+
"""Computes the cosine function"""
48+
...
4949

5050
def erf():
51-
"""Computes the error function, which has applications in statistics"""
52-
...
51+
"""Computes the error function, which has applications in statistics"""
52+
...
5353

5454
def erfc():
55-
"""Computes the complementary error function, which has applications in statistics"""
56-
...
55+
"""Computes the complementary error function, which has applications in statistics"""
56+
...
5757

5858
def exp():
59-
"""Computes the exponent function."""
60-
...
59+
"""Computes the exponent function."""
60+
...
6161

6262
def expm1():
63-
"""Computes $e^x-1$. In certain applications, using this function preserves numeric accuracy better than the `exp` function."""
64-
...
63+
"""Computes $e^x-1$. In certain applications, using this function preserves numeric accuracy better than the `exp` function."""
64+
...
6565

6666
def floor():
67-
"""Rounds numbers up to the next whole number"""
68-
...
67+
"""Rounds numbers up to the next whole number"""
68+
...
6969

7070
def gamma():
71-
"""Computes the gamma function"""
72-
...
71+
"""Computes the gamma function"""
72+
...
7373

7474
def lgamma():
75-
"""Computes the natural log of the gamma function"""
76-
...
75+
"""Computes the natural log of the gamma function"""
76+
...
7777

7878
def log():
79-
"""Computes the natural log"""
80-
...
79+
"""Computes the natural log"""
80+
...
8181

8282
def log10():
83-
"""Computes the log base 10"""
84-
...
83+
"""Computes the log base 10"""
84+
...
8585

8686
def log2():
87-
"""Computes the log base 2"""
88-
...
87+
"""Computes the log base 2"""
88+
...
8989

9090
def sin():
91-
"""Computes the sine"""
92-
...
91+
"""Computes the sine"""
92+
...
9393

9494
def sinh():
95-
"""Computes the hyperbolic sine"""
96-
...
95+
"""Computes the hyperbolic sine"""
96+
...
9797

9898
def sqrt():
99-
"""Computes the square root"""
100-
...
99+
"""Computes the square root"""
100+
...
101101

102102
def tan():
103-
"""Computes the tangent"""
104-
...
103+
"""Computes the tangent"""
104+
...
105105

106106
def tanh():
107-
"""Computes the hyperbolic tangent"""
108-
...
107+
"""Computes the hyperbolic tangent"""
108+
...
109+
110+
def vectorise(f, *, otypes=None):
111+
"""
112+
:param callable f: The function to wrap
113+
:param otypes: List of array types that may be returned by the function. None is intepreted to mean the return value is float.
114+
115+
Wrap a Python function `f` so that it can be applied to arrays.
116+
117+
The callable must return only values of the types specified by otypes, or the result is undefined."""
118+
...

0 commit comments

Comments
 (0)