def _check_fun(fun, d, *args, **kwargs):
 want_shape = d.shape
 d = fun(d, *args, **kwargs)
 if (not isinstance(d, np.ndarray)):
  raise TypeError('Return value must be an ndarray')
 if (d.shape != want_shape):
  raise ValueError(('Return data must have shape %s not %s' % (want_shape, d.shape)))
 return d

def _check_fun ( fun , d , * args , ** kwargs ) : want_shape = d . shape d = fun ( d , * args , ** kwargs ) if ( not isinstance ( d , np . ndarray ) ) : raise TypeError ( 'Return value must be an ndarray' ) if ( d . shape != want_shape ) : raise ValueError ( ( 'Return data must have shape %s not %s' % ( want_shape , d . shape ) ) ) return d
check shapes .