From 6f807e22a719397cd6d25865ae5a8f6a6cbfa963 Mon Sep 17 00:00:00 2001 From: Smit-create Date: Wed, 2 Nov 2022 19:35:01 +0530 Subject: [PATCH 1/5] Fix numpy warnings --- quantecon/tests/test_lqnash.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/quantecon/tests/test_lqnash.py b/quantecon/tests/test_lqnash.py index b748c4d35..9f224b20c 100644 --- a/quantecon/tests/test_lqnash.py +++ b/quantecon/tests/test_lqnash.py @@ -93,13 +93,15 @@ def test_nnash(self): xbar = tfi.dot(aaa[:2, 2]) # Define answers from matlab. TODO: this is ghetto - f1_ml = np.asarray(np.matrix("""\ - 0.243666582208565, 0.027236062661951, -6.827882928738190; - 0.392370733875639, 0.139696450885998, -37.734107291009138""")) - - f2_ml = np.asarray(np.matrix("""\ - 0.027236062661951, 0.243666582208565, -6.827882928738186; - 0.139696450885998, 0.392370733875639, -37.734107291009131""")) + f1_ml = np.array([ + [0.243666582208565, 0.027236062661951, -6.827882928738190], + [0.392370733875639, 0.139696450885998, -37.734107291009138] + ]) + + f2_ml = np.array([ + [0.027236062661951, 0.243666582208565, -6.827882928738186], + [0.139696450885998, 0.392370733875639, -37.734107291009131] + ]) xbar_ml = np.array([1.246871007582702, 1.246871007582685]) From 7e044175d7e0c658cdc96ff8aac91a047510b824 Mon Sep 17 00:00:00 2001 From: Smit-create Date: Wed, 2 Nov 2022 19:37:15 +0530 Subject: [PATCH 2/5] Raise the tolerance limit for windows --- quantecon/util/tests/test_timing.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/quantecon/util/tests/test_timing.py b/quantecon/util/tests/test_timing.py index 0a49d77a0..7f30bd8a5 100644 --- a/quantecon/util/tests/test_timing.py +++ b/quantecon/util/tests/test_timing.py @@ -31,6 +31,11 @@ def test_timer(self): tm3 = toc() rtol = 0.1 + + if platform == 'win32': + # pytest platform specific issue + rtol *= 2 + for actual, desired in zip([tm1, tm2, tm3], [self.h, self.h, self.h*3]): assert_allclose(actual, desired, rtol=rtol) @@ -50,10 +55,15 @@ def test_function_two_arg(n, a): loop_timer(5, test_function_one_arg, self.h, digits=10) test_two_arg = \ loop_timer(5, test_function_two_arg, [self.h, 1], digits=10) + + tol = 0.01 + if platform == 'win32': + # pytest platform specific issue + tol *= 2 for tm in test_one_arg: - assert(abs(tm - self.h) < 0.01), tm + assert(abs(tm - self.h) < tol), tm for tm in test_two_arg: - assert(abs(tm - self.h) < 0.01), tm + assert(abs(tm - self.h) < tol), tm for (average_time, average_of_best) in [test_one_arg, test_two_arg]: assert_(average_time >= average_of_best) From b3ce842b3a35cfddee3285c6ff0ae244e1d0343c Mon Sep 17 00:00:00 2001 From: Smit-create Date: Thu, 3 Nov 2022 13:04:11 +0530 Subject: [PATCH 3/5] Use assert_allclose --- quantecon/util/tests/test_timing.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/quantecon/util/tests/test_timing.py b/quantecon/util/tests/test_timing.py index 7f30bd8a5..161f92687 100644 --- a/quantecon/util/tests/test_timing.py +++ b/quantecon/util/tests/test_timing.py @@ -56,14 +56,15 @@ def test_function_two_arg(n, a): test_two_arg = \ loop_timer(5, test_function_two_arg, [self.h, 1], digits=10) - tol = 0.01 + rtol = 0.1 + if platform == 'win32': # pytest platform specific issue - tol *= 2 + rtol *= 2 for tm in test_one_arg: - assert(abs(tm - self.h) < tol), tm + assert_allclose(tm, self.h, rtol=rtol) for tm in test_two_arg: - assert(abs(tm - self.h) < tol), tm + assert_allclose(tm, self.h, rtol=rtol) for (average_time, average_of_best) in [test_one_arg, test_two_arg]: assert_(average_time >= average_of_best) From 56ff1107012ae207801c93e84f2e6ef53f407f84 Mon Sep 17 00:00:00 2001 From: Smit-create Date: Thu, 3 Nov 2022 14:36:14 +0530 Subject: [PATCH 4/5] Also test for darwin --- quantecon/util/tests/test_timing.py | 26 +++++++------------------- 1 file changed, 7 insertions(+), 19 deletions(-) diff --git a/quantecon/util/tests/test_timing.py b/quantecon/util/tests/test_timing.py index 161f92687..a869714b1 100644 --- a/quantecon/util/tests/test_timing.py +++ b/quantecon/util/tests/test_timing.py @@ -4,7 +4,6 @@ """ import time -from sys import platform from numpy.testing import assert_allclose, assert_ from quantecon.util import tic, tac, toc, loop_timer @@ -15,9 +14,6 @@ def setup_method(self): self.digits = 10 def test_timer(self): - if platform == 'darwin': - # skip for darwin - return tic() @@ -30,20 +26,14 @@ def test_timer(self): time.sleep(self.h) tm3 = toc() - rtol = 0.1 - - if platform == 'win32': - # pytest platform specific issue - rtol *= 2 + rtol = 0.5 + atol = 0.05 for actual, desired in zip([tm1, tm2, tm3], [self.h, self.h, self.h*3]): - assert_allclose(actual, desired, rtol=rtol) + assert_allclose(actual, desired, atol=atol, rtol=rtol) def test_loop(self): - if platform == 'darwin': - # skip for darwin - return def test_function_one_arg(n): return time.sleep(n) @@ -56,15 +46,13 @@ def test_function_two_arg(n, a): test_two_arg = \ loop_timer(5, test_function_two_arg, [self.h, 1], digits=10) - rtol = 0.1 + rtol = 0.5 + atol = 0.05 - if platform == 'win32': - # pytest platform specific issue - rtol *= 2 for tm in test_one_arg: - assert_allclose(tm, self.h, rtol=rtol) + assert_allclose(tm, self.h, atol=atol, rtol=rtol) for tm in test_two_arg: - assert_allclose(tm, self.h, rtol=rtol) + assert_allclose(tm, self.h, atol=atol, rtol=rtol) for (average_time, average_of_best) in [test_one_arg, test_two_arg]: assert_(average_time >= average_of_best) From 4d6b4d24dbe54b69ea431f7a094b1755de0a75e3 Mon Sep 17 00:00:00 2001 From: Smit-create Date: Thu, 3 Nov 2022 18:38:52 +0530 Subject: [PATCH 5/5] Use rtol=2 --- quantecon/util/tests/test_timing.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/quantecon/util/tests/test_timing.py b/quantecon/util/tests/test_timing.py index a869714b1..db0e1bc78 100644 --- a/quantecon/util/tests/test_timing.py +++ b/quantecon/util/tests/test_timing.py @@ -26,7 +26,7 @@ def test_timer(self): time.sleep(self.h) tm3 = toc() - rtol = 0.5 + rtol = 2 atol = 0.05 for actual, desired in zip([tm1, tm2, tm3], @@ -46,7 +46,7 @@ def test_function_two_arg(n, a): test_two_arg = \ loop_timer(5, test_function_two_arg, [self.h, 1], digits=10) - rtol = 0.5 + rtol = 2 atol = 0.05 for tm in test_one_arg: