Skip to content

Commit

Permalink
More tests for AAA
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffrey-hokanson committed Sep 30, 2020
1 parent 51b7cb5 commit 356377c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
3 changes: 3 additions & 0 deletions polyrat/aaa.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,9 @@ def __init__(self, degree = None, tol = None, verbose = True):
self.tol = tol
self.verbose = verbose

if self.degree is None and self.tol is None:
self.tol = 1e-12

def fit(self, X, y):
X = np.array(X)
self.y = np.array(y)
Expand Down
24 changes: 22 additions & 2 deletions tests/test_aaa.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import numpy
from polyrat.aaa import *

import pytest

def eval_aaa_slow(xeval, x, y, I, b):
reval = []
Expand Down Expand Up @@ -56,7 +56,8 @@ def test_eval_aaa():


def test_aaa():

r""" Functionality testing
"""
M = int(1e2)
x = np.linspace(-1,1, M).reshape(-1,1)
y = np.abs(x).flatten()
Expand All @@ -67,6 +68,25 @@ def test_aaa():
I, b = aaa(x, y, degree = 10)

# Use matrix valued data
Y = np.vstack([y for i in range(5)]).T
I, b = aaa(x, Y, degree = 10)


@pytest.mark.parametrize("M", [1000])
@pytest.mark.parametrize("degree", [5, 10, None])
@pytest.mark.parametrize("tol", [1e-5, 1e-10, None])
@pytest.mark.parametrize("verbose", [True, False])
def test_AAARationalApproximation(M,degree, tol, verbose):
r""" Integration tests for AAARationalApproximation
"""
X = np.random.randn(M,1)
y = np.abs(X).flatten()

aaa = AAARationalApproximation(degree= degree, tol = tol, verbose = verbose)
aaa.fit(X, y)

res_norm = np.linalg.norm(aaa(X) - y)
print(res_norm)

if __name__ == '__main__':
test_eval_aaa()
Expand Down

0 comments on commit 356377c

Please sign in to comment.