def assert_shape(x, expected_shape, msg='Unexpected shape.'):
 if (expected_shape is None):
  return x
 shape = x.shape
 tests = []
 for i in range(x.ndim):
  if (expected_shape[i] is not None):
   tests.append(theano.tensor.eq(shape[i], expected_shape[i]))
 if tests:
  return Assert(msg)(x, *tests)
 else:
  return x

def assert_shape ( x , expected_shape , msg = 'Unexpected shape.' ) : if ( expected_shape is None ) : return x shape = x . shape tests = [ ] for i in range ( x . ndim ) : if ( expected_shape [ i ] is not None ) : tests . append ( theano . tensor . eq ( shape [ i ] , expected_shape [ i ] ) ) if tests : return Assert ( msg ) ( x , * tests ) else : return x
wraps x in an assert to check its shape .