<s> """<STR_LIT>""" <EOL> import numpy <EOL> import theano <EOL> try : <EOL> import scipy . sparse <EOL> scipy_imported = True <EOL> except ImportError : <EOL> scipy_imported = False <EOL> from theano . misc . may_share_memory import may_share_memory <EOL> def test_may_share_memory ( ) : <EOL> a = numpy . random . rand ( <NUM_LIT:5> , <NUM_LIT:4> ) <EOL> b = numpy . random . rand ( <NUM_LIT:5> , <NUM_LIT:4> ) <EOL> va = a . view ( ) <EOL> vb = b . view ( ) <EOL> ra = a . reshape ( ( <NUM_LIT:4> , <NUM_LIT:5> ) ) <EOL> rb = b . reshape ( ( <NUM_LIT:4> , <NUM_LIT:5> ) ) <EOL> ta = a . T <EOL> tb = b . T <EOL> for a_ , b_ , rep in [ ( a , a , True ) , ( b , b , True ) , ( a , b , False ) , <EOL> ( a , a [ <NUM_LIT:0> ] , True ) , ( a , a [ : , <NUM_LIT:0> ] , True ) , ( a , a . T , True ) , <EOL> ( a , ( <NUM_LIT:0> , ) , False ) , ( a , <NUM_LIT:1> , False ) , ( a , None , False ) , <EOL> ( a , va , True ) , ( b , vb , True ) , ( va , b , False ) , ( a , vb , False ) , <EOL> ( a , ra , True ) , ( b , rb , True ) , ( ra , b , False ) , ( a , rb , False ) , <EOL> ( a , ta , True ) , ( b , tb , True ) , ( ta , b , False ) , ( a , tb , False ) , <EOL> ] : <EOL> assert may_share_memory ( a_ , b_ , False ) == rep <EOL> assert may_share_memory ( b_ , a_ , False ) == rep <EOL> for a_ , b_ , rep in [ ( a , ( <NUM_LIT:0> , ) , False ) , ( a , <NUM_LIT:1> , False ) , ( a , None , False ) , ] : <EOL> assert may_share_memory ( a_ , b_ , False ) == rep <EOL> assert may_share_memory ( b_ , a_ , False ) == rep <EOL> try : <EOL> may_share_memory ( a_ , b_ ) <EOL> raise Exception ( "<STR_LIT>" ) <EOL> except TypeError : <EOL> pass <EOL> try : <EOL> may_share_memory ( b_ , a_ ) <EOL> raise Exception ( "<STR_LIT>" ) <EOL> except TypeError : <EOL> pass <EOL> if scipy_imported : <EOL> def test_may_share_memory_scipy ( ) : <EOL> a = scipy . sparse . csc_matrix ( scipy . sparse . eye ( <NUM_LIT:5> , <NUM_LIT:3> ) ) <EOL> b = scipy . sparse . csc_matrix ( scipy . sparse . eye ( <NUM_LIT:4> , <NUM_LIT:3> ) ) <EOL> as_ar = lambda a : theano . _asarray ( a , dtype = '<STR_LIT>' ) <EOL> for a_ , b_ , rep in [ ( a , a , True ) , ( b , b , True ) , ( a , b , False ) , <EOL> ( a , a . data , True ) , ( a , a . indptr , True ) , ( a , a . indices , True ) , ( a , as_ar ( a . shape ) , False ) , <EOL> ( a . data , a , True ) , ( a . indptr , a , True ) , ( a . indices , a , True ) , ( as_ar ( a . shape ) , a , False ) , <EOL> ( b , b . data , True ) , ( b , b . indptr , True ) , ( b , b . indices , True ) , ( b , as_ar ( b . shape ) , False ) , <EOL> ( b . data , b , True ) , ( b . indptr , b , True ) , ( b . indices , b , True ) , ( as_ar ( b . shape ) , b , False ) , <EOL> ( b . data , a , False ) , ( b . indptr , a , False ) , ( b . indices , a , False ) , ( as_ar ( b . shape ) , a , False ) , <EOL> ] : <EOL> assert may_share_memory ( a_ , b_ ) == rep <EOL> assert may_share_memory ( b_ , a_ ) == rep <EOL> for a_ , b_ , rep in [ ( a , ( <NUM_LIT:0> , ) , False ) , ( a , <NUM_LIT:1> , False ) , ( a , None , False ) ] : <EOL> assert may_share_memory ( a_ , b_ , False ) == rep <EOL> assert may_share_memory ( b_ , a_ , False ) == rep <EOL> try : <EOL> may_share_memory ( a_ , b_ ) <EOL> raise Exception ( "<STR_LIT>" ) <EOL> except TypeError : <EOL> pass <EOL> try : <EOL> may_share_memory ( b_ , a_ ) <EOL> raise Exception ( "<STR_LIT>" ) <EOL> except TypeError : <EOL> pass </s>
