24
24
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25
25
26
26
import warnings
27
+ import operator
27
28
28
29
import numpy as np
29
30
import scipy
@@ -52,9 +53,10 @@ class AAA:
52
53
rtol : float, optional
53
54
Relative tolerance, defaults to ``eps**0.75``. If a small subset of the entries
54
55
in `values` are much larger than the rest the default tolerance may be too
55
- loose.
56
+ loose.
56
57
max_terms : int, optional
57
58
Maximum number of terms in the barycentric representation, defaults to ``100``.
59
+ Must be greater than or equal to one.
58
60
59
61
Attributes
60
62
----------
@@ -69,7 +71,7 @@ class AAA:
69
71
errors : array
70
72
Error :math:`|f(z) - r(z)|_\infty` over `points` in the successive iterations
71
73
of AAA.
72
-
74
+
73
75
Warns
74
76
-----
75
77
RuntimeWarning
@@ -93,7 +95,7 @@ class AAA:
93
95
where :math:`z_1,\dots,z_m` are real or complex support points selected from
94
96
`points`, :math:`f_1,\dots,f_m` are the corresponding real or complex data values
95
97
from `values`, and :math:`w_1,\dots,w_m` are real or complex weights.
96
-
98
+
97
99
Each iteration of the algorithm has two parts: the greedy selection the next support
98
100
point and the computation of the weights. The first part of each iteration is to
99
101
select the next support point to be added :math:`z_{m+1}` from the remaining
@@ -102,7 +104,7 @@ class AAA:
102
104
when this maximum is less than ``rtol * np.linalg.norm(f, ord=np.inf)``. This means
103
105
the interpolation property is only satisfied up to a tolerance, except at the
104
106
support points where approximation exactly interpolates the supplied data.
105
-
107
+
106
108
In the second part of each iteration, the weights :math:`w_j` are selected to solve
107
109
the least-squares problem
108
110
@@ -195,10 +197,15 @@ def __init__(self, points, values, *, rtol=None, max_terms=100):
195
197
196
198
if f .size != z .size :
197
199
raise ValueError ("`points` and `values` must be the same size." )
198
-
200
+
199
201
if not np .all (np .isfinite (z )):
200
202
raise ValueError ("`points` must be finite." )
201
203
204
+ max_terms = operator .index (max_terms )
205
+ if max_terms < 1 :
206
+ raise ValueError ("`max_terms` must be an integer value greater than or "
207
+ "equal to one." )
208
+
202
209
# Remove infinite or NaN function values and repeated entries
203
210
to_keep = (np .isfinite (f )) & (~ np .isnan (f ))
204
211
f = f [to_keep ]
0 commit comments