def validate_matrix_shape(name, shape, nrows, ncols, nobs):
 ndim = len(shape)
 if (ndim not in [2, 3]):
  raise ValueError(('Invalid value for %s matrix. Requires a 2- or 3-dimensional array, got %d dimensions' % (name, ndim)))
 if (not (shape[0] == nrows)):
  raise ValueError(('Invalid dimensions for %s matrix: requires %d rows, got %d' % (name, nrows, shape[0])))
 if (not (shape[1] == ncols)):
  raise ValueError(('Invalid dimensions for %s matrix: requires %d columns, got %d' % (name, ncols, shape[1])))
 if ((nobs is None) and (not ((ndim == 2) or (shape[(-1)] == 1)))):
  raise ValueError(('Invalid dimensions for %s matrix: time-varying matrices cannot be given unless `nobs` is specified (implicitly when a dataset is bound or else set explicity)' % name))
 if ((ndim == 3) and (nobs is not None) and (not (shape[(-1)] in [1, nobs]))):
  raise ValueError(('Invalid dimensions for time-varying %s matrix. Requires shape (*,*,%d), got %s' % (name, nobs, str(shape))))

def validate_matrix_shape ( name , shape , nrows , ncols , nobs ) : ndim = len ( shape ) if ( ndim not in [ 2 , 3 ] ) : raise ValueError ( ( 'Invalid value for %s matrix. Requires a 2- or 3-dimensional array, got %d dimensions' % ( name , ndim ) ) ) if ( not ( shape [ 0 ] == nrows ) ) : raise ValueError ( ( 'Invalid dimensions for %s matrix: requires %d rows, got %d' % ( name , nrows , shape [ 0 ] ) ) ) if ( not ( shape [ 1 ] == ncols ) ) : raise ValueError ( ( 'Invalid dimensions for %s matrix: requires %d columns, got %d' % ( name , ncols , shape [ 1 ] ) ) ) if ( ( nobs is None ) and ( not ( ( ndim == 2 ) or ( shape [ ( - 1 ) ] == 1 ) ) ) ) : raise ValueError ( ( 'Invalid dimensions for %s matrix: time-varying matrices cannot be given unless `nobs` is specified (implicitly when a dataset is bound or else set explicity)' % name ) ) if ( ( ndim == 3 ) and ( nobs is not None ) and ( not ( shape [ ( - 1 ) ] in [ 1 , nobs ] ) ) ) : raise ValueError ( ( 'Invalid dimensions for time-varying %s matrix. Requires shape (*,*,%d), got %s' % ( name , nobs , str ( shape ) ) ) )
validate the shape of a possibly time-varying matrix .