<s> from cStringIO import StringIO <EOL> from contextlib import closing <EOL> from functools import partial <EOL> import numpy as np <EOL> import cyflann <EOL> from . . typedbytes_utils import tb , register_read , register_write <EOL> def _check_all_eq ( expected , real ) : <EOL> assert np . all ( expected == real ) <EOL> def test_typedbytes_ndarray ( ) : <EOL> for ary in [ np . arange ( <NUM_LIT:30> , dtype = np . uint8 ) , <EOL> np . random . normal ( size = ( <NUM_LIT:10> , <NUM_LIT:12> , <NUM_LIT:100> ) ) , <EOL> np . linspace ( <NUM_LIT:1> , <NUM_LIT> , <NUM_LIT> ) . astype ( np . float128 ) ] : <EOL> with closing ( StringIO ( ) ) as sio : <EOL> out = tb . Output ( sio ) <EOL> register_write ( out ) <EOL> out . write ( ary ) <EOL> sio . seek ( <NUM_LIT:0> ) <EOL> inp = tb . Input ( sio ) <EOL> register_read ( inp ) <EOL> ary2 = inp . read ( ) <EOL> yield partial ( _check_all_eq , ary , ary2 ) <EOL> def _check_flann ( idx1 , idx2 ) : <EOL> assert np . all ( idx1 . data == idx2 . data ) <EOL> assert np . allclose ( idx1 . nn_index ( idx1 . data ) [ <NUM_LIT:1> ] , idx2 . nn_index ( idx1 . data ) [ <NUM_LIT:1> ] ) <EOL> def test_typedbytes_flann ( ) : <EOL> pts = np . random . normal ( size = ( <NUM_LIT:100> , <NUM_LIT:2> ) ) <EOL> for algorithm in [ '<STR_LIT>' , '<STR_LIT>' ] : <EOL> idx = cyflann . FLANNIndex ( algorithm = algorithm ) <EOL> idx . build_index ( pts ) <EOL> with closing ( StringIO ( ) ) as sio : <EOL> out = tb . Output ( sio ) <EOL> register_write ( out ) <EOL> out . write ( idx ) <EOL> sio . seek ( <NUM_LIT:0> ) <EOL> inp = tb . Input ( sio ) <EOL> register_read ( inp ) <EOL> idx2 = inp . read ( ) <EOL> fn = partial ( _check_flann , idx , idx2 ) <EOL> fn . description = "<STR_LIT>" . format ( algorithm ) <EOL> yield fn </s>
