def test_not_implemented_elemwise_grad():
 class TestOp(scalar.ScalarOp, ):
  def __init__(self):
   self.output_types_preference = scalar.upgrade_to_float
  def impl(self, n, x):
   return (x * n)
  def grad(self, inputs, gout):
   (n, x) = inputs
   (gz,) = gout
   dy_dx = n
   return [theano.gradient.grad_not_implemented(self, 0, n), (gz * dy_dx)]
 test_op = tensor.Elemwise(TestOp())
 x = tensor.scalar()
 tensor.grad(test_op(2, x), x)
 try:
  tensor.grad(test_op(x, 2), x)
  assert False
 except theano.gradient.NullTypeGradError:
  pass

def test_not_implemented_elemwise_grad ( ) : class TestOp ( scalar . ScalarOp , ) : def __init__ ( self ) : self . output_types_preference = scalar . upgrade_to_float def impl ( self , n , x ) : return ( x * n ) def grad ( self , inputs , gout ) : ( n , x ) = inputs ( gz , ) = gout dy_dx = n return [ theano . gradient . grad_not_implemented ( self , 0 , n ) , ( gz * dy_dx ) ] test_op = tensor . Elemwise ( TestOp ( ) ) x = tensor . scalar ( ) tensor . grad ( test_op ( 2 , x ) , x ) try : tensor . grad ( test_op ( x , 2 ) , x ) assert False except theano . gradient . NullTypeGradError : pass
regression test for unimplemented gradient in an elemwise op .