Fix get method
@@ -1635,20 +1635,26 @@ cdef class ndarray:
raise TypeError('Only numpy.ndarray can be obtained from'
'cupy.ndarray')
if self.dtype != out.dtype:
- raise TypeError('{} array cannot be obtained from {} array'.format(
+ raise TypeError(
+ '{} array cannot be obtained from {} array'.format(
out.dtype, self.dtype))
if self.shape != out.shape:
raise ValueError(
- 'Shape mismatch. Expected shape: {}, actual shape: {}'.format(
- self.shape, out.shape))
+ 'Shape mismatch. Expected shape: {}, '
+ 'actual shape: {}'.format(self.shape, out.shape))
+ if not (out.flags.c_contiguous and self._c_contiguous or
+ out.flags.f_contiguous and self._f_contiguous):
with self.device:
if out.flags.c_contiguous:
a_gpu = ascontiguousarray(self)
elif out.flags.f_contiguous:
a_gpu = asfortranarray(self)
else:
- raise RuntimeError('`out` cannot be specified when copying to '
+ raise RuntimeError(
+ '`out` cannot be specified when copying to '
'non-contiguous ndarray')
+ else:
+ a_gpu = self
a_cpu = out
else:
if self.size == 0:
@@ -1660,7 +1666,8 @@ cdef class ndarray:
order = 'F'
else:
order = 'C'
-
+ if not (order == 'C' and self._c_contiguous or
+ order == 'F' and self._f_contiguous):
with self.device:
if order == 'C':
a_gpu = ascontiguousarray(self)
@@ -1668,6 +1675,8 @@ cdef class ndarray:
a_gpu = asfortranarray(self)
else:
raise ValueError("unsupported order: {}".format(order))
+ else:
+ a_gpu = self
a_cpu = numpy.empty(self._shape, dtype=self.dtype, order=order)
ptr = a_cpu.ctypes.get_as_parameter()
if stream is not None:
