<s> """<STR_LIT>""" <EOL> import unittest <EOL> import numpy <EOL> from theano . compat import six <EOL> from pylearn2 . datasets . norb import SmallNORB <EOL> from pylearn2 . datasets . norb_small import FoveatedNORB <EOL> from pylearn2 . datasets . new_norb import NORB <EOL> from pylearn2 . utils import safe_zip <EOL> from pylearn2 . testing . skip import skip_if_no_data <EOL> class TestNORB ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> skip_if_no_data ( ) <EOL> def test_foveated_norb ( self ) : <EOL> norb_train = FoveatedNORB ( which_set = "<STR_LIT:train>" , <EOL> scale = <NUM_LIT:1> , restrict_instances = [ <NUM_LIT:4> , <NUM_LIT:6> , <NUM_LIT:7> , <NUM_LIT:8> ] ) <EOL> def test_get_topological_view ( self ) : <EOL> def test_impl ( norb ) : <EOL> topo_tensor = norb . get_topological_view ( single_tensor = True ) <EOL> shape = ( ( norb . X . shape [ <NUM_LIT:0> ] , <NUM_LIT:2> ) + <EOL> SmallNORB . original_image_shape + <EOL> ( <NUM_LIT:1> , ) ) <EOL> expected_topo_tensor = norb . X . reshape ( shape ) <EOL> for i in range ( topo_tensor . shape [ <NUM_LIT:0> ] ) : <EOL> assert numpy . all ( topo_tensor [ i ] == expected_topo_tensor [ i ] ) <EOL> topo_tensors = norb . get_topological_view ( single_tensor = False ) <EOL> expected_topo_tensors = tuple ( expected_topo_tensor [ : , i , ... ] <EOL> for i in range ( <NUM_LIT:2> ) ) <EOL> for topo_tensor , expected_topo_tensor in safe_zip ( <EOL> topo_tensors , expected_topo_tensors ) : <EOL> assert numpy . all ( topo_tensor == expected_topo_tensor ) <EOL> for norb in ( SmallNORB ( '<STR_LIT:train>' , stop = <NUM_LIT:1000> ) , <EOL> NORB ( which_norb = '<STR_LIT>' , which_set = '<STR_LIT:train>' ) ) : <EOL> test_impl ( norb ) <EOL> def test_label_to_value_funcs ( self ) : <EOL> def test_impl ( norb ) : <EOL> label_to_value_maps = ( <EOL> { <NUM_LIT:0> : '<STR_LIT>' , <EOL> <NUM_LIT:1> : '<STR_LIT>' , <EOL> <NUM_LIT:2> : '<STR_LIT>' , <EOL> <NUM_LIT:3> : '<STR_LIT>' , <EOL> <NUM_LIT:4> : '<STR_LIT>' , <EOL> <NUM_LIT:5> : '<STR_LIT:blank>' } , <EOL> dict ( safe_zip ( range ( <NUM_LIT:10> ) , range ( <NUM_LIT:10> ) ) ) , <EOL> dict ( safe_zip ( range ( <NUM_LIT:9> ) , numpy . arange ( <NUM_LIT:9> ) * <NUM_LIT:5> + <NUM_LIT:30> ) ) , <EOL> dict ( safe_zip ( range ( <NUM_LIT:0> , <NUM_LIT> , <NUM_LIT:2> ) , numpy . arange ( <NUM_LIT:0> , <NUM_LIT> , <NUM_LIT:20> ) ) ) , <EOL> dict ( safe_zip ( range ( <NUM_LIT:5> ) , range ( <NUM_LIT:5> ) ) ) , <EOL> dict ( safe_zip ( range ( - <NUM_LIT:5> , <NUM_LIT:6> ) , range ( - <NUM_LIT:5> , <NUM_LIT:6> ) ) ) , <EOL> dict ( safe_zip ( range ( - <NUM_LIT:5> , <NUM_LIT:6> ) , range ( - <NUM_LIT:5> , <NUM_LIT:6> ) ) ) , <EOL> dict ( safe_zip ( range ( - <NUM_LIT> , <NUM_LIT:20> ) , range ( - <NUM_LIT> , <NUM_LIT:20> ) ) ) , <EOL> dict ( safe_zip ( range ( <NUM_LIT:2> ) , ( <NUM_LIT> , <NUM_LIT> ) ) ) ) <EOL> for ( label_to_value_map , <EOL> label_to_value_func ) in zip ( label_to_value_maps , <EOL> norb . label_to_value_funcs ) : <EOL> for label , expected_value in six . iteritems ( label_to_value_map ) : <EOL> actual_value = label_to_value_func ( label ) <EOL> assert expected_value == actual_value <EOL> test_impl ( NORB ( which_set = '<STR_LIT:test>' , which_norb = '<STR_LIT>' ) ) <EOL> test_impl ( NORB ( which_set = '<STR_LIT:test>' , which_norb = '<STR_LIT>' ) ) <EOL> def test_image_dtype ( self ) : <EOL> expected_dtypes = ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> norbs = ( NORB ( which_set = '<STR_LIT:train>' , <EOL> which_norb = '<STR_LIT>' ) , <EOL> NORB ( which_set = '<STR_LIT:train>' , <EOL> which_norb = '<STR_LIT>' , <EOL> image_dtype = '<STR_LIT>' ) ) <EOL> for norb , expected_dtype in safe_zip ( norbs , expected_dtypes ) : <EOL> assert str ( norb . X . dtype ) == expected_dtype </s>
