Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
polakowo
GitHub Repository: polakowo/vectorbt
Path: blob/master/tests/utils.py
1071 views
1
import hashlib
2
3
import numpy as np
4
5
# non-randomized hash function
6
hash = lambda s: int(hashlib.sha512(s.encode('utf-8')).hexdigest()[:16], 16)
7
8
9
def isclose(a, b, rel_tol=1e-06, abs_tol=0.0):
10
if np.isnan(a) == np.isnan(b):
11
return True
12
if np.isinf(a) == np.isinf(b):
13
return True
14
if a == b:
15
return True
16
return abs(a - b) <= max(rel_tol * max(abs(a), abs(b)), abs_tol)
17
18
19
def record_arrays_close(x, y):
20
for field in x.dtype.names:
21
np.testing.assert_allclose(x[field], y[field], rtol=1e-06)
22
23