<s> from __future__ import absolute_import , print_function , division <EOL> import numpy <EOL> from theano . gof . type import Type <EOL> from theano . gof . graph import Variable , Apply , Constant <EOL> from theano . gof . op import Op <EOL> from theano . gof . opt import * <EOL> from theano . gof . fg import FunctionGraph as Env <EOL> from theano . gof . toolbox import * <EOL> import theano . tensor . basic as T <EOL> def as_variable ( x ) : <EOL> if not isinstance ( x , Variable ) : <EOL> raise TypeError ( "<STR_LIT>" , x ) <EOL> return x <EOL> class MyType ( Type ) : <EOL> def filter ( self , data ) : <EOL> return data <EOL> def __eq__ ( self , other ) : <EOL> return isinstance ( other , MyType ) <EOL> class MyOp ( Op ) : <EOL> def __init__ ( self , name , dmap = None , x = None ) : <EOL> if dmap is None : <EOL> dmap = { } <EOL> self . name = name <EOL> self . destroy_map = dmap <EOL> self . x = x <EOL> def make_node ( self , * inputs ) : <EOL> inputs = list ( map ( as_variable , inputs ) ) <EOL> for input in inputs : <EOL> if not isinstance ( input . type , MyType ) : <EOL> raise Exception ( "<STR_LIT>" ) <EOL> outputs = [ MyType ( ) ( ) ] <EOL> return Apply ( self , inputs , outputs ) <EOL> def __str__ ( self ) : <EOL> return self . name <EOL> def __repr__ ( self ) : <EOL> return self . name <EOL> def __eq__ ( self , other ) : <EOL> return ( self is other or isinstance ( other , MyOp ) and self . x is not None <EOL> and self . x == other . x ) <EOL> def __hash__ ( self ) : <EOL> if self . x is not None : <EOL> return self . x <EOL> else : return id ( self ) <EOL> op1 = MyOp ( '<STR_LIT>' ) <EOL> def test_merge_with_weird_eq ( ) : <EOL> """<STR_LIT>""" <EOL> x = T . constant ( numpy . asarray ( <NUM_LIT:1> ) , name = '<STR_LIT:x>' ) <EOL> y = T . constant ( numpy . asarray ( <NUM_LIT:1> ) , name = '<STR_LIT:y>' ) <EOL> g = Env ( [ x , y ] , [ x + y ] ) <EOL> MergeOptimizer ( ) . optimize ( g ) <EOL> assert len ( g . apply_nodes ) == <NUM_LIT:1> <EOL> node = list ( g . apply_nodes ) [ <NUM_LIT:0> ] <EOL> assert len ( node . inputs ) == <NUM_LIT:2> <EOL> assert node . inputs [ <NUM_LIT:0> ] is node . inputs [ <NUM_LIT:1> ] <EOL> x = T . constant ( numpy . ones ( <NUM_LIT:5> ) , name = '<STR_LIT:x>' ) <EOL> y = T . constant ( numpy . ones ( <NUM_LIT:5> ) , name = '<STR_LIT:y>' ) <EOL> g = Env ( [ x , y ] , [ x + y ] ) <EOL> MergeOptimizer ( ) . optimize ( g ) <EOL> assert len ( g . apply_nodes ) == <NUM_LIT:1> <EOL> node = list ( g . apply_nodes ) [ <NUM_LIT:0> ] <EOL> assert len ( node . inputs ) == <NUM_LIT:2> <EOL> assert node . inputs [ <NUM_LIT:0> ] is node . inputs [ <NUM_LIT:1> ] </s>
