def test_badoptimization_opt_err():
 @gof.local_optimizer([theano.tensor.add])
 def insert_bigger_b_add(node):
  if (node.op == theano.tensor.add):
   inputs = list(node.inputs)
   if (inputs[(-1)].owner is None):
    inputs[(-1)] = theano.tensor.concatenate((inputs[(-1)], inputs[(-1)]))
    return [node.op(*inputs)]
  return False
 edb = gof.EquilibriumDB()
 edb.register('insert_bigger_b_add', insert_bigger_b_add, 'all')
 opt = edb.query('+all')
 a = theano.tensor.dvector()
 b = theano.tensor.dvector()
 f = theano.function([a, b], (a + b), mode=debugmode.DebugMode(optimizer=opt))
 try:
  f([1.0, 2.0, 3.0], [2, 3, 4])
 except Exception as e:
  assert ('insert_bigger_b_add' in exc_message(e))
  return
 assert False

def test_badoptimization_opt_err ( ) : @ gof . local_optimizer ( [ theano . tensor . add ] ) def insert_bigger_b_add ( node ) : if ( node . op == theano . tensor . add ) : inputs = list ( node . inputs ) if ( inputs [ ( - 1 ) ] . owner is None ) : inputs [ ( - 1 ) ] = theano . tensor . concatenate ( ( inputs [ ( - 1 ) ] , inputs [ ( - 1 ) ] ) ) return [ node . op ( * inputs ) ] return False edb = gof . EquilibriumDB ( ) edb . register ( 'insert_bigger_b_add' , insert_bigger_b_add , 'all' ) opt = edb . query ( '+all' ) a = theano . tensor . dvector ( ) b = theano . tensor . dvector ( ) f = theano . function ( [ a , b ] , ( a + b ) , mode = debugmode . DebugMode ( optimizer = opt ) ) try : f ( [ 1.0 , 2.0 , 3.0 ] , [ 2 , 3 , 4 ] ) except Exception as e : assert ( 'insert_bigger_b_add' in exc_message ( e ) ) return assert False
this variant of test_badoptimization() replace the working code with a new apply node that will raise an error .