<s> from __future__ import absolute_import , print_function , division <EOL> import unittest <EOL> import numpy <EOL> import theano <EOL> import theano . typed_list <EOL> from theano import tensor as T <EOL> from theano . typed_list . type import TypedListType <EOL> from theano . tests import unittest_tools as utt <EOL> def rand_ranged_matrix ( minimum , maximum , shape ) : <EOL> return numpy . asarray ( numpy . random . rand ( * shape ) * ( maximum - minimum ) + <EOL> minimum , dtype = theano . config . floatX ) <EOL> class test_typed_list_type ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> utt . seed_rng ( ) <EOL> def test_wrong_input_on_creation ( self ) : <EOL> """<STR_LIT>""" <EOL> self . assertRaises ( TypeError , TypedListType , None ) <EOL> def test_wrong_input_on_filter ( self ) : <EOL> """<STR_LIT>""" <EOL> myType = TypedListType ( T . TensorType ( theano . config . floatX , <EOL> ( False , False ) ) ) <EOL> self . assertRaises ( TypeError , myType . filter , [ <NUM_LIT:4> ] ) <EOL> def test_not_a_list_on_filter ( self ) : <EOL> """<STR_LIT>""" <EOL> myType = TypedListType ( T . TensorType ( theano . config . floatX , <EOL> ( False , False ) ) ) <EOL> self . assertRaises ( TypeError , myType . filter , <NUM_LIT:4> ) <EOL> def test_type_equality ( self ) : <EOL> """<STR_LIT>""" <EOL> myType1 = TypedListType ( T . TensorType ( theano . config . floatX , <EOL> ( False , False ) ) ) <EOL> myType2 = TypedListType ( T . TensorType ( theano . config . floatX , <EOL> ( False , False ) ) ) <EOL> myType3 = TypedListType ( T . TensorType ( theano . config . floatX , <EOL> ( ) ) ) <EOL> self . assertTrue ( myType2 == myType1 ) <EOL> self . assertFalse ( myType3 == myType1 ) <EOL> def test_filter_sanity_check ( self ) : <EOL> """<STR_LIT>""" <EOL> myType = TypedListType ( T . TensorType ( theano . config . floatX , <EOL> ( False , False ) ) ) <EOL> x = rand_ranged_matrix ( - <NUM_LIT:1000> , <NUM_LIT:1000> , [ <NUM_LIT:100> , <NUM_LIT:100> ] ) <EOL> self . assertTrue ( numpy . array_equal ( myType . filter ( [ x ] ) , [ x ] ) ) <EOL> def test_intern_filter ( self ) : <EOL> """<STR_LIT>""" <EOL> myType = TypedListType ( T . TensorType ( '<STR_LIT>' , <EOL> ( False , False ) ) ) <EOL> x = numpy . asarray ( [ [ <NUM_LIT:4> , <NUM_LIT:5> ] , [ <NUM_LIT:4> , <NUM_LIT:5> ] ] , dtype = '<STR_LIT>' ) <EOL> self . assertTrue ( numpy . array_equal ( myType . filter ( [ x ] ) , [ x ] ) ) <EOL> """<STR_LIT>""" <EOL> def test_basic_nested_list ( self ) : <EOL> """<STR_LIT>""" <EOL> myNestedType = TypedListType ( T . TensorType ( theano . config . floatX , <EOL> ( False , False ) ) ) <EOL> myType = TypedListType ( myNestedType ) <EOL> x = rand_ranged_matrix ( - <NUM_LIT:1000> , <NUM_LIT:1000> , [ <NUM_LIT:100> , <NUM_LIT:100> ] ) <EOL> self . assertTrue ( numpy . array_equal ( myType . filter ( [ [ x ] ] ) , [ [ x ] ] ) ) <EOL> def test_comparison_different_depth ( self ) : <EOL> """<STR_LIT>""" <EOL> myNestedType = TypedListType ( T . TensorType ( theano . config . floatX , <EOL> ( False , False ) ) ) <EOL> myNestedType2 = TypedListType ( myNestedType ) <EOL> myNestedType3 = TypedListType ( myNestedType2 ) <EOL> self . assertFalse ( myNestedType2 == myNestedType3 ) <EOL> def test_nested_list_arg ( self ) : <EOL> """<STR_LIT>""" <EOL> myNestedType = TypedListType ( T . TensorType ( theano . config . floatX , <EOL> ( False , False ) ) , <NUM_LIT:3> ) <EOL> myType = TypedListType ( T . TensorType ( theano . config . floatX , <EOL> ( False , False ) ) ) <EOL> myManualNestedType = TypedListType ( TypedListType ( <EOL> TypedListType ( myType ) ) ) <EOL> self . assertTrue ( myNestedType == myManualNestedType ) <EOL> def test_get_depth ( self ) : <EOL> """<STR_LIT>""" <EOL> myType = TypedListType ( T . TensorType ( theano . config . floatX , <EOL> ( False , False ) ) ) <EOL> myManualNestedType = TypedListType ( TypedListType ( <EOL> TypedListType ( myType ) ) ) <EOL> self . assertTrue ( myManualNestedType . get_depth ( ) == <NUM_LIT:3> ) <EOL> def test_comparison_uneven_nested ( self ) : <EOL> """<STR_LIT>""" <EOL> myType = TypedListType ( T . TensorType ( theano . config . floatX , <EOL> ( False , False ) ) ) <EOL> myManualNestedType1 = TypedListType ( TypedListType ( <EOL> TypedListType ( myType ) ) ) <EOL> myManualNestedType2 = TypedListType ( TypedListType ( myType ) ) <EOL> self . assertFalse ( myManualNestedType1 == myManualNestedType2 ) <EOL> self . assertFalse ( myManualNestedType2 == myManualNestedType1 ) <EOL> def test_variable_is_Typed_List_variable ( self ) : <EOL> mySymbolicVariable = TypedListType ( T . TensorType ( theano . config . floatX , <EOL> ( False , False ) ) ) ( ) <EOL> self . assertTrue ( isinstance ( mySymbolicVariable , <EOL> theano . typed_list . TypedListVariable ) ) </s>
