def _cast(arg, dtype):
 if (dtype is None):
  return arg
 assert (dtype in tuple((t.dtype for t in theano.scalar.all_types)))
 if isinstance(arg, tuple):
  return tuple((_cast(a, dtype) for a in arg))
 elif isinstance(arg, np.ndarray):
  return theano._asarray(arg, dtype=dtype)
 elif (str(type(arg)) == "<type 'CudaNdarray'>"):
  if (str(dtype) != 'float32'):
   raise TypeError(('Can only cast a numeric CudaNdarray to float32, not %s' % dtype))
  else:
   return arg
 elif (isinstance(arg, theano.gof.Variable) and isinstance(arg.type, CudaNdarrayType)):
  if (str(dtype) != 'float32'):
   raise TypeError(('Can only cast a theano CudaNdArrayType to float32, not %s' % dtype))
  else:
   return arg
 elif scipy.sparse.issparse(arg):
  return arg.astype(dtype)
 elif isinstance(arg, theano.tensor.TensorVariable):
  return theano.tensor.cast(arg, dtype)
 elif isinstance(arg, theano.sparse.SparseVariable):
  return theano.sparse.cast(arg, dtype)
 elif isinstance(arg, theano.sandbox.cuda.var.CudaNdarrayVariable):
  return arg
 else:
  raise TypeError(("Unsupported arg type '%s'" % str(type(arg))))

def _cast ( arg , dtype ) : if ( dtype is None ) : return arg assert ( dtype in tuple ( ( t . dtype for t in theano . scalar . all_types ) ) ) if isinstance ( arg , tuple ) : return tuple ( ( _cast ( a , dtype ) for a in arg ) ) elif isinstance ( arg , np . ndarray ) : return theano . _asarray ( arg , dtype = dtype ) elif ( str ( type ( arg ) ) == "<type 'CudaNdarray'>" ) : if ( str ( dtype ) != 'float32' ) : raise TypeError ( ( 'Can only cast a numeric CudaNdarray to float32, not %s' % dtype ) ) else : return arg elif ( isinstance ( arg , theano . gof . Variable ) and isinstance ( arg . type , CudaNdarrayType ) ) : if ( str ( dtype ) != 'float32' ) : raise TypeError ( ( 'Can only cast a theano CudaNdArrayType to float32, not %s' % dtype ) ) else : return arg elif scipy . sparse . issparse ( arg ) : return arg . astype ( dtype ) elif isinstance ( arg , theano . tensor . TensorVariable ) : return theano . tensor . cast ( arg , dtype ) elif isinstance ( arg , theano . sparse . SparseVariable ) : return theano . sparse . cast ( arg , dtype ) elif isinstance ( arg , theano . sandbox . cuda . var . CudaNdarrayVariable ) : return arg else : raise TypeError ( ( "Unsupported arg type '%s'" % str ( type ( arg ) ) ) )
convert value to a string based on json schema type .