@@ -0,0 +1,1562 @@
+from cStringIO import StringIO%0Afrom contextlib import closing%0Afrom functools import partial%0A%0Aimport numpy as np%0A%0Aimport cyflann%0Afrom ..typedbytes_utils import tb, register_read, register_write%0A%0A# TODO: test with non-seekable files%0A%0A%0Adef _check_all_eq(expected, real):%0A    assert np.all(expected == real)%0A%0Adef test_typedbytes_ndarray():%0A    for ary in %5Bnp.arange(30, dtype=np.uint8),%0A                np.random.normal(size=(10, 12, 100)),%0A                np.linspace(1, 3.2, 121).astype(np.float128)%5D:%0A        with closing(StringIO()) as sio:%0A            out = tb.Output(sio)%0A            register_write(out)%0A            out.write(ary)%0A%0A            sio.seek(0)%0A            inp = tb.Input(sio)%0A            register_read(inp)%0A            ary2 = inp.read()%0A%0A            yield partial(_check_all_eq, ary, ary2)%0A%0A%0Adef _check_flann(idx1, idx2):%0A    assert np.all(idx1.data == idx2.data)%0A    assert np.allclose(idx1.nn_index(idx1.data)%5B1%5D, idx2.nn_index(idx1.data)%5B1%5D)%0A%0Adef test_typedbytes_flann():%0A    pts = np.random.normal(size=(100, 2))%0A    for algorithm in %5B'kdtree_single', 'linear'%5D:%0A        idx = cyflann.FLANNIndex(algorithm=algorithm)%0A        idx.build_index(pts)%0A%0A        with closing(StringIO()) as sio:%0A            out = tb.Output(sio)%0A            register_write(out)%0A            out.write(idx)%0A%0A            sio.seek(0)%0A            inp = tb.Input(sio)%0A            register_read(inp)%0A            idx2 = inp.read()%0A%0A            fn = partial(_check_flann, idx, idx2)%0A            fn.description = %22flann typedbytes io - %7B%7D%22.format(algorithm)%0A            yield fn%0A

add some basic tests for typedbytes i/o of ndarrays / flann indices