def constant_or_value(x, rtype, name=None, ndim=None, dtype=None):
 x_ = scal.convert(x, dtype=dtype)
 bcastable = [(d == 1) for d in x_.shape]
 if (ndim is not None):
  if (len(bcastable) < ndim):
   bcastable = (([True] * (ndim - len(bcastable))) + bcastable)
  elif (len(bcastable) > ndim):
   raise ValueError(('ndarray could not be cast to constant with %i dimensions' % ndim))
  assert (len(bcastable) == ndim)
 try:
  if (rtype is TensorConstant):
   rval = rtype(TensorType(dtype=x_.dtype, broadcastable=bcastable), x_.copy(), name=name)
   return rval
  else:
   return rtype(TensorType(dtype=x_.dtype, broadcastable=bcastable), x_, name=name)
 except Exception:
  raise TypeError(('Could not convert %s to TensorType' % x), type(x))

def constant_or_value ( x , rtype , name = None , ndim = None , dtype = None ) : x_ = scal . convert ( x , dtype = dtype ) bcastable = [ ( d == 1 ) for d in x_ . shape ] if ( ndim is not None ) : if ( len ( bcastable ) < ndim ) : bcastable = ( ( [ True ] * ( ndim - len ( bcastable ) ) ) + bcastable ) elif ( len ( bcastable ) > ndim ) : raise ValueError ( ( 'ndarray could not be cast to constant with %i dimensions' % ndim ) ) assert ( len ( bcastable ) == ndim ) try : if ( rtype is TensorConstant ) : rval = rtype ( TensorType ( dtype = x_ . dtype , broadcastable = bcastable ) , x_ . copy ( ) , name = name ) return rval else : return rtype ( TensorType ( dtype = x_ . dtype , broadcastable = bcastable ) , x_ , name = name ) except Exception : raise TypeError ( ( 'Could not convert %s to TensorType' % x ) , type ( x ) )
return a symbolic constant with value x .