Skip to content

Commit

Permalink
Merge pull request #645 from Smit-create/i633
Browse files Browse the repository at this point in the history
CI: Fix time errors on windows and numpy warnings
  • Loading branch information
Smit-create committed Nov 3, 2022
2 parents 89a7012 + 4d6b4d2 commit 31a1bf8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 18 deletions.
16 changes: 9 additions & 7 deletions quantecon/tests/test_lqnash.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])

Expand Down
21 changes: 10 additions & 11 deletions quantecon/util/tests/test_timing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -15,9 +14,6 @@ def setup_method(self):
self.digits = 10

def test_timer(self):
if platform == 'darwin':
# skip for darwin
return

tic()

Expand All @@ -30,15 +26,14 @@ def test_timer(self):
time.sleep(self.h)
tm3 = toc()

rtol = 0.1
rtol = 2
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)
Expand All @@ -50,10 +45,14 @@ 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)

rtol = 2
atol = 0.05

for tm in test_one_arg:
assert(abs(tm - self.h) < 0.01), tm
assert_allclose(tm, self.h, atol=atol, rtol=rtol)
for tm in test_two_arg:
assert(abs(tm - self.h) < 0.01), tm
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)

0 comments on commit 31a1bf8

Please sign in to comment.