def expect_dimensions(__funcname=_qualified_name, **dimensions):
 if isinstance(__funcname, str):
  def get_funcname(_):
   return __funcname
 else:
  get_funcname = __funcname
 def _expect_dimension(expected_ndim):
  def _check(func, argname, argvalue):
   actual_ndim = argvalue.ndim
   if (actual_ndim != expected_ndim):
    if (actual_ndim == 0):
     actual_repr = 'scalar'
    else:
     actual_repr = ('%d-D array' % actual_ndim)
    raise ValueError('{func}() expected a {expected:d}-D array for argument {argname!r}, but got a {actual} instead.'.format(func=get_funcname(func), expected=expected_ndim, argname=argname, actual=actual_repr))
   return argvalue
  return _check
 return preprocess(**valmap(_expect_dimension, dimensions))

def expect_dimensions ( __funcname = _qualified_name , ** dimensions ) : if isinstance ( __funcname , str ) : def get_funcname ( _ ) : return __funcname else : get_funcname = __funcname def _expect_dimension ( expected_ndim ) : def _check ( func , argname , argvalue ) : actual_ndim = argvalue . ndim if ( actual_ndim != expected_ndim ) : if ( actual_ndim == 0 ) : actual_repr = 'scalar' else : actual_repr = ( '%d-D array' % actual_ndim ) raise ValueError ( '{func}() expected a {expected:d}-D array for argument {argname!r}, but got a {actual} instead.' . format ( func = get_funcname ( func ) , expected = expected_ndim , argname = argname , actual = actual_repr ) ) return argvalue return _check return preprocess ( ** valmap ( _expect_dimension , dimensions ) )
preprocessing decorator that verifies inputs are numpy arrays with a specific dimensionality .