Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 727b174

Browse files
committed
define isclose, to allow Python 3.4
1 parent 709e0ae commit 727b174

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

utils.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,13 @@ def sigmoid(x):
229229
def step(x):
230230
"""Return activation value of x with sign function"""
231231
return 1 if x >= 0 else 0
232+
233+
try: # math.isclose was added in Python 3.5;
234+
from math import isclose
235+
except ImportError:
236+
def isclose(a, b, rel_tol=1e-09, abs_tol=0.0):
237+
"Return true if numbers a and b are close to each other."
238+
return abs(a-b) <= max(rel_tol * max(abs(a), abs(b)), abs_tol)
232239

233240
# ______________________________________________________________________________
234241
# Misc Functions

0 commit comments

Comments
 (0)