#NEWLINE# def copy_to_host( self , ary = None , stream = 0 ) : #NEWLINE# #INDENT# 'Copy ``self`` to ``ary`` or create a new Numpy ndarray\n        if ``ary`` is ``None``.\n\n        If a CUDA ``stream`` is given, then the transfer will be made\n        asynchronously as part as the given stream.  Otherwise, the transfer is\n        synchronous: the function returns after the copy is finished.\n\n        Always returns the host array.\n\n        Example::\n\n            import numpy as np\n            from numba import cuda\n\n            arr = np.arange(1000)\n            d_arr = cuda.to_device(arr)\n\n            my_kernel[100, 100](d_arr)\n\n            result_array = d_arr.copy_to_host()\n        ' #NEWLINE# stream = self . _default_stream ( stream ) #NEWLINE# if ( ary is None ) : #NEWLINE# #INDENT# hostary = np . empty ( shape = self . alloc_size , dtype = np . byte ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( ary . dtype != self . dtype ) : #NEWLINE# #INDENT# raise TypeError ( 'incompatible dtype' ) #NEWLINE# #UNINDENT# if ( ary . shape != self . shape ) : #NEWLINE# #INDENT# scalshapes = ( ( ) , ( 1 , ) ) #NEWLINE# if ( not ( ( ary . shape in scalshapes ) and ( self . shape in scalshapes ) ) ) : #NEWLINE# #INDENT# raise TypeError ( ( 'incompatible shape; device %s; host %s' % ( self . shape , ary . shape ) ) ) #NEWLINE# #UNINDENT# #UNINDENT# if ( ary . strides != self . strides ) : #NEWLINE# #INDENT# scalstrides = ( ( ) , ( self . dtype . itemsize , ) ) #NEWLINE# if ( not ( ( ary . strides in scalstrides ) and ( self . strides in scalstrides ) ) ) : #NEWLINE# #INDENT# raise TypeError ( ( 'incompatible strides; device %s; host %s' % ( self . strides , ary . strides ) ) ) #NEWLINE# #UNINDENT# #UNINDENT# hostary = ary #NEWLINE# #UNINDENT# assert ( self . alloc_size >= 0 ) , 'Negative memory size' #NEWLINE# if ( self . alloc_size != 0 ) : #NEWLINE# #INDENT# _driver . device_to_host ( hostary , self , self . alloc_size , stream = stream ) #NEWLINE# #UNINDENT# if ( ary is None ) : #NEWLINE# #INDENT# if ( self . size == 0 ) : #NEWLINE# #INDENT# hostary = np . ndarray ( shape = self . shape , dtype = self . dtype , buffer = hostary ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# hostary = np . ndarray ( shape = self . shape , dtype = self . dtype , strides = self . strides , buffer = hostary ) #NEWLINE# #UNINDENT# #UNINDENT# return hostary