Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 20 additions & 10 deletions pycuda/gpuarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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):
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down