### [tests] Spacing based on max values rather than 1

```Base the comparison that two arrays are almost equal based on the
spacing of the maximum value of the array rather than one. Using one
will give incorrect resulsts when the magintude of the values is
significantly different to one.```
parent 599409bf
 ... @@ -12,10 +12,13 @@ import scipy.sparse as sp ... @@ -12,10 +12,13 @@ import scipy.sparse as sp import mdptoolbox.example import mdptoolbox.example ## example.forest def assert_equal_numpy_spacing(A, B): A = np.array(A) B = np.array(B) x = np.amax(np.maximum(np.abs(A), np.abs(B))) assert_true((np.abs(A - B) <= np.spacing(x)).all()) def assert_spacing_equal(A, B): ## example.forest return(assert_true((np.abs(A - B) <= np.spacing(1)).all())) class TestExampleForest(object): class TestExampleForest(object): P = np.array( P = np.array( ... @@ -34,8 +37,8 @@ class TestExampleForest(object): ... @@ -34,8 +37,8 @@ class TestExampleForest(object): P, R = mdptoolbox.example.forest() P, R = mdptoolbox.example.forest() assert_equal(P.shape, self.P.shape) assert_equal(P.shape, self.P.shape) assert_equal(R.shape, self.R.shape) assert_equal(R.shape, self.R.shape) assert_spacing_equal(P, self.P) assert_equal_numpy_spacing(P, self.P) assert_spacing_equal(R, self.R) assert_equal_numpy_spacing(R, self.R) def test_sparse_PR(self): def test_sparse_PR(self): P, R = mdptoolbox.example.forest(is_sparse=True) P, R = mdptoolbox.example.forest(is_sparse=True) ... @@ -97,8 +100,8 @@ class TestExampleRand(object): ... @@ -97,8 +100,8 @@ class TestExampleRand(object): P, R = mdptoolbox.example.rand(self.S, self.A) P, R = mdptoolbox.example.rand(self.S, self.A) assert_equal(P.shape, self.P.shape) assert_equal(P.shape, self.P.shape) assert_equal(R.shape, self.R.shape) assert_equal(R.shape, self.R.shape) assert_spacing_equal(P, self.P) assert_equal_numpy_spacing(P, self.P) assert_spacing_equal(R, self.R) assert_equal_numpy_spacing(R, self.R) def test_sparse_PR(self): def test_sparse_PR(self): P, R = mdptoolbox.example.rand(self.S, self.A, is_sparse=True) P, R = mdptoolbox.example.rand(self.S, self.A, is_sparse=True) ... ...
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!