@numpyonly
def test_clustering_tree_maxdist():
    with util_numpy.test_uses_numpy() as np:
        s = np.array([[0.0, 0, 1, 2, 1, 0, 1, 0, 0], [0.0, 1, 2, 0, 0, 0, 0, 0, 0], [1.0, 2, 0, 0, 0, 0, 0, 1, 1], [0.0, 0, 1, 2, 1, 0, 1, 0, 0], [0.0, 1, 2, 0, 0, 0, 0, 0, 0], [1.0, 2, 0, 0, 0, 0, 0, 1, 1], [1.0, 2, 0, 0, 0, 0, 0, 1, 1]])

        def test_hook(from_idx, to_idx, distance):
            assert ((from_idx, to_idx) in [(3, 0), (4, 1), (5, 2), (6, 2), (1, 0), (2, 0)])
        model = clustering.Hierarchical(dtw.distance_matrix_fast, {}, merge_hook=test_hook, show_progress=False, max_dist=0.1)
        modelw = clustering.HierarchicalTree(model)
        cluster_idx = modelw.fit(s)
        assert (cluster_idx[0] == {0, 1, 2, 3, 4, 5, 6})
        if directory:
            hierarchy_fn = os.path.join(directory, 'hierarchy.png')
            graphviz_fn = os.path.join(directory, 'hierarchy.dot')
        else:
            file = tempfile.NamedTemporaryFile()
            hierarchy_fn = (file.name + '_hierarchy.png')
            graphviz_fn = (file.name + '_hierarchy.dot')
        if (not dtwvis.test_without_visualization()):
            modelw.plot(hierarchy_fn)
            print('Figure saved to', hierarchy_fn)
        with open(graphviz_fn, 'w') as ofile:
            print(modelw.to_dot(), file=ofile)
        print('Dot saved to', graphviz_fn)
@numpyonly
def test_clustering_tree_maxdist():
    with util_numpy.test_uses_numpy() as np:
        s = np.array([[0.0, 0, 1, 2, 1, 0, 1, 0, 0], [0.0, 1, 2, 0, 0, 0, 0, 0, 0], [1.0, 2, 0, 0, 0, 0, 0, 1, 1], [0.0, 0, 1, 2, 1, 0, 1, 0, 0], [0.0, 1, 2, 0, 0, 0, 0, 0, 0], [1.0, 2, 0, 0, 0, 0, 0, 1, 1], [1.0, 2, 0, 0, 0, 0, 0, 1, 1]])

        def test_hook(from_idx, to_idx, distance):
            assert ((from_idx, to_idx) in [(3, 0), (4, 1), (5, 2), (6, 2), (1, 0), (2, 0)])
        model = clustering.Hierarchical(dtw.distance_matrix_fast, {}, merge_hook=test_hook, show_progress=False, max_dist=0.1)
        modelw = clustering.HierarchicalTree(model)
        cluster_idx = modelw.fit(s)
        assert (cluster_idx[0] == {0, 1, 2, 3, 4, 5, 6})
        if directory:
            hierarchy_fn = os.path.join(directory, 'hierarchy.png')
            graphviz_fn = os.path.join(directory, 'hierarchy.dot')
        else:
            file = tempfile.NamedTemporaryFile()
            hierarchy_fn = (file.name + '_hierarchy.png')
            graphviz_fn = (file.name + '_hierarchy.dot')
        if (not dtwvis.test_without_visualization()):
            modelw.plot(hierarchy_fn)
            print('Figure saved to', hierarchy_fn)
        with open(graphviz_fn, 'w') as ofile:
            print(modelw.to_dot(), file=ofile)
        print('Dot saved to', graphviz_fn)