def _as_scalar(res, dtype=None):
 if (dtype is None):
  dtype = config.floatX
 if numpy.all(res.type.broadcastable):
  while (res.owner and isinstance(res.owner.op, T.DimShuffle)):
   res = res.owner.inputs[0]
  if res.type.broadcastable:
   rval = res.dimshuffle()
  else:
   rval = res
  if (rval.type.dtype in theano.tensor.integer_dtypes):
   if (theano.scalar.upcast(res.dtype, dtype) == dtype):
    return T.cast(rval, dtype)
   else:
    return None
  return rval

def _as_scalar ( res , dtype = None ) : if ( dtype is None ) : dtype = config . floatX if numpy . all ( res . type . broadcastable ) : while ( res . owner and isinstance ( res . owner . op , T . DimShuffle ) ) : res = res . owner . inputs [ 0 ] if res . type . broadcastable : rval = res . dimshuffle ( ) else : rval = res if ( rval . type . dtype in theano . tensor . integer_dtypes ) : if ( theano . scalar . upcast ( res . dtype , dtype ) == dtype ) : return T . cast ( rval , dtype ) else : return None return rval
return none or a tensorvariable whose type is in t .