예제 #1
0
 def _allocate(self,
               where,
               obj=None,
               dtype=None,
               shape=None,
               strides=None,
               copy=True):
     if dtype:
         dtype = np.dtype(dtype)
     if where == 'host':
         if obj is not None:
             self._host = np.array(obj, dtype, copy=copy)
         else:
             self._host = np.empty(shape, dtype,
                                   _s2o(dtype, shape, strides))
     else:
         # Don't import this at module-scope as it may not be available
         # in all environments (e.g., CUDASIM)
         from numba.cuda.cudadrv import devicearray as da
         if obj is not None:
             # If 'obj' is an array-like object but not an ndarray,
             # construct an ndarray first to extract all the parameters we need.
             if not isinstance(obj, np.ndarray):
                 obj = np.array(obj, copy=False)
             self._gpu = da.from_array_like(obj)
         else:
             if strides is None:
                 strides = _o2s(dtype, shape, 'C')
             self._gpu = da.DeviceNDArray(shape, strides, dtype)
예제 #2
0
파일: smartarray.py 프로젝트: numba/numba
 def _allocate(self, where, obj=None, dtype=None, shape=None, strides=None,
               copy=True):
     if dtype:
         dtype = np.dtype(dtype)
     if where == 'host':
         if obj is not None:
             self._host = np.array(obj, dtype, copy=copy)
         else:
             self._host = np.empty(shape, dtype, _s2o(dtype, shape, strides))
     else:
         # Don't import this at module-scope as it may not be available
         # in all environments (e.g., CUDASIM)
         from numba.cuda.cudadrv import devicearray as da
         if obj is not None:
             # If 'obj' is an array-like object but not an ndarray,
             # construct an ndarray first to extract all the parameters we need.
             if not isinstance(obj, np.ndarray):
                 obj = np.array(obj, copy=False)
             self._gpu = da.from_array_like(obj)
         else:
             if strides is None:
                 strides = _o2s(dtype, shape, 'C')
             self._gpu = da.DeviceNDArray(shape, strides, dtype)