def grab_cpu_scalar(v, nd):
 if (v.owner is not None):
  n = v.owner
  if (isinstance(n.op, (GpuDimShuffle, DimShuffle)) and (n.op.new_order == (('x',) * nd))):
   return grab_cpu_scalar(n.inputs[0], n.inputs[0].ndim)
  elif isinstance(n.op, (GpuFromHost, HostFromGpu)):
   return grab_cpu_scalar(n.inputs[0], nd)
  else:
   return None
 elif (isinstance(v, Constant) and (v.broadcastable == ((True,) * nd))):
  return v.dimshuffle(())

def grab_cpu_scalar ( v , nd ) : if ( v . owner is not None ) : n = v . owner if ( isinstance ( n . op , ( GpuDimShuffle , DimShuffle ) ) and ( n . op . new_order == ( ( 'x' , ) * nd ) ) ) : return grab_cpu_scalar ( n . inputs [ 0 ] , n . inputs [ 0 ] . ndim ) elif isinstance ( n . op , ( GpuFromHost , HostFromGpu ) ) : return grab_cpu_scalar ( n . inputs [ 0 ] , nd ) else : return None elif ( isinstance ( v , Constant ) and ( v . broadcastable == ( ( True , ) * nd ) ) ) : return v . dimshuffle ( ( ) )
get a scalar variable value from the tree at v .