Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def d():
return dtw_c.distance_nogil(s1, s2)
def test_distance2_aa():
dist_opts = {'max_dist': 0.1}
s1 = np.array([0.0, 0.0, 2.0, 1.0, 1.0, 0.0, 0.0])
s2 = np.array([0.0, 1.0, 1.0, 1.0, 0.0, 0.0, 0.0])
d1 = dtw.distance(s1, s2, **dist_opts)
d2 = dtw_c.distance_nogil(s1, s2, **dist_opts)
print(d1, d2)
assert d1 == d2
assert d1 == pytest.approx(np.inf)
def test_distance3_a():
dist_opts = {"penalty": 0.005, "max_step": 0.011, "window": 3}
s = np.array([0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.005, 0.01, 0.015, 0.02, 0.01, 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.])
p = np.array([0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.005, 0.01, 0.015, 0.02, 0.01, 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.])
d1 = dtw.distance(s, p, **dist_opts)
d2 = dtw_c.distance_nogil(s, p, **dist_opts)
assert d1 == pytest.approx(d2)
def test_distance1_a():
# dist_opts = {'max_dist': 0.201, 'max_step': 0.011, 'max_length_diff': 8, 'window': 3}
dist_opts = {'window': 3}
s1 = np.array([ 0., 0.01, 0., 0.01, 0., 0., 0., 0.01, 0.01, 0.02, 0., 0.])
s2 = np.array([ 0., 0.02, 0.02, 0., 0., 0.01, 0.01, 0., 0., 0., 0.])
d1 = dtw.distance(s1, s2, **dist_opts)
d2 = dtw_c.distance_nogil(s1, s2, **dist_opts)
assert d1 == d2
assert d1 == pytest.approx(0.02)
def test_distance1_b():
dist_opts = {}
s1 = np.array([ 0., 0.01, 0., 0.01, 0., 0., 0., 0.01, 0.01, 0.02, 0., 0.])
s2 = np.array([ 0., 0.02, 0.02, 0., 0., 0.01, 0.01, 0., 0., 0., 0.])
d1 = dtw.distance(s1, s2, **dist_opts)
d2 = dtw_c.distance_nogil(s1, s2, **dist_opts)
assert d1 == d2
assert d1 == pytest.approx(0.02)
def test_distance2_bb():
dist_opts = {'max_step': 0.1}
s1 = np.array([0.0, 0.0, 2.0, 1.0, 1.0, 0.0, 0.0])
s2 = np.array([0.0, 1.0, 1.0, 1.0, 0.0, 0.0, 0.0])
d1 = dtw.distance(s1, s2, **dist_opts)
d2 = dtw_c.distance_nogil(s1, s2, **dist_opts)
print(d1, d2)
assert d1 == d2
assert d1 == pytest.approx(np.inf)
def test_distance4():
try:
import pandas as pd
except ImportError:
# If no pandas, ignore test (not a required dependency)
return
s = [[0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.],
[0.005, 0.01, 0.015, 0.02, 0.01, 0., 0., 0., 0., 0., 0., 0., 0.],
[0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.]]
p = np.array([0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.])
df = pd.DataFrame(data=s)
s = df.values
for i in range(s.shape[0]):
ss = s[i] # ss will not be C contiguous memory layout
d = dtw_c.distance_nogil(ss, p)
# print(d)