diff --git a/pycuda/gpuarray.py b/pycuda/gpuarray.py index 896b2fca..374a3693 100644 --- a/pycuda/gpuarray.py +++ b/pycuda/gpuarray.py @@ -213,7 +213,6 @@ def __init__(self, shape, dtype, allocator=drv.mem_alloc, assert base is None else: self.gpudata = gpudata - self.base = base self._grid, self._block = splay(self.mem_size) @@ -375,7 +374,7 @@ def _div(self, other, out, stream=None): return out - def _new_like_me(self, dtype=None): + def _new_like_me(self, dtype=None, order="C"): strides = None if dtype is None: dtype = self.dtype @@ -384,7 +383,7 @@ def _new_like_me(self, dtype=None): strides = self.strides return self.__class__(self.shape, dtype, - allocator=self.allocator, strides=strides) + allocator=self.allocator, strides=strides, order=order) # operators --------------------------------------------------------------- def mul_add(self, selffac, other, otherfac, add_timer=None, stream=None): @@ -680,7 +679,7 @@ def astype(self, dtype, stream=None): return result - def reshape(self, *shape): + def reshape(self, *shape, order="C"): """Gives a new shape to an array without changing its data.""" # TODO: add more error-checking, perhaps @@ -712,7 +711,8 @@ def reshape(self, *shape): dtype=self.dtype, allocator=self.allocator, base=self, - gpudata=int(self.gpudata)) + gpudata=int(self.gpudata), + order=order) def ravel(self): return self.reshape(self.size) @@ -900,8 +900,11 @@ def real(self): if issubclass(dtype.type, np.complexfloating): from pytools import match_precision real_dtype = match_precision(np.dtype(np.float64), dtype) - - result = self._new_like_me(dtype=real_dtype) + if self.flags.f_contiguous: + order = "F" + else: + order = "C" + result = self._new_like_me(dtype=real_dtype, order=order) func = elementwise.get_real_kernel(dtype, real_dtype) func.prepared_async_call(self._grid, self._block, None, @@ -922,8 +925,11 @@ def imag(self): from pytools import match_precision real_dtype = match_precision(np.dtype(np.float64), dtype) - - result = self._new_like_me(dtype=real_dtype) + if self.flags.f_contiguous: + order = "F" + else: + order = "C" + result = self._new_like_me(dtype=real_dtype, order=order) func = elementwise.get_imag_kernel(dtype, real_dtype) func.prepared_async_call(self._grid, self._block, None, @@ -941,7 +947,11 @@ def conj(self): raise RuntimeError("only contiguous arrays may " "be used as arguments to this operation") - result = self._new_like_me() + if self.flags.f_contiguous: + order = "F" + else: + order = "C" + result = self._new_like_me(order=order) func = elementwise.get_conj_kernel(dtype) func.prepared_async_call(self._grid, self._block, None,