def test_numpymatrix_transpose():
"""Passing a matrix instead of a list failed because the array is now a
view instead of the original data structure."""
s = np.matrix([
[0., 0., 1.,],
[0, 1, 2],
[1, 2, 0],
[2, 0, 0],
[1, 0, 0],
[0, 0, 0],
[1, 0, 0],
[0, 0, 1],
[0, 0, 0]
]).T
m = dtw_c.distance_matrix_nogil(s)
m2 = dtw.distance_matrix(s)
correct = np.array([
[np.inf, 1.41421356, 1.73205081],
[np.inf, np.inf, 1.41421356],
[np.inf, np.inf, np.inf]])
assert m[0, 1] == pytest.approx(math.sqrt(2))
assert m2[0, 1] == pytest.approx(math.sqrt(2))
np.testing.assert_almost_equal(correct, m, decimal=4)
np.testing.assert_almost_equal(correct, m2, decimal=4)
评论列表
文章目录