Skip to content

Commit

Permalink
Fix bug
Browse files Browse the repository at this point in the history
  • Loading branch information
okuta committed Jun 18, 2018
1 parent 711f035 commit 1faceab
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
10 changes: 6 additions & 4 deletions cupy/core/core.pyx
Expand Up @@ -2121,11 +2121,13 @@ cpdef ndarray array(obj, dtype=None, bint copy=True, str order='K',
a = a.view()
a.shape = (1,) * (ndmin - ndim) + a.shape
else:
if order == 'K':
order = 'A'
if order == 'K' or order == 'A':
if isinstance(obj, numpy.ndarray) and obj.flags.f_contiguous:
order = 'F'
else:
order = 'C'
a_cpu = numpy.array(obj, dtype=dtype, copy=False, order=order,
ndmin=ndmin)
order = None if a_cpu.flags.c_contiguous else 'F'
a_dtype = a_cpu.dtype
if a_dtype.char not in '?bhilqBHILQefdFD':
raise ValueError('Unsupported dtype %s' % a_dtype)
Expand All @@ -2136,7 +2138,7 @@ cpdef ndarray array(obj, dtype=None, bint copy=True, str order='K',
nbytes = a.nbytes
mem = pinned_memory.alloc_pinned_memory(nbytes)
src_cpu = numpy.frombuffer(mem, a_dtype, a_cpu.size)
src_cpu[...] = a_cpu.ravel('A')
src_cpu[:] = a_cpu.ravel(order)
stream = stream_module.get_current_stream()
a.data.copy_from_host_async(ctypes.c_void_p(mem.ptr), nbytes)
pinned_memory._add_to_watch_list(stream.record(), mem)
Expand Down
9 changes: 9 additions & 0 deletions tests/cupy_tests/creation_tests/test_from_data.py
Expand Up @@ -22,6 +22,15 @@ def test_array_from_numpy(self, xp, dtype, order):
a = testing.shaped_arange((2, 3, 4), numpy, dtype)
return xp.array(a, order=order)

@testing.for_orders('CFAK')
@testing.for_all_dtypes()
@testing.with_requires('numpy>=1.10')
@testing.numpy_cupy_array_equal()
def test_array_from_numpy_broad_cast(self, xp, dtype, order):
a = testing.shaped_arange((2, 1, 4), numpy, dtype)
a = numpy.broadcast_to(a, (2, 3, 4))
return xp.array(a, order=order)

@testing.for_orders('CFAK')
@testing.for_all_dtypes()
@testing.numpy_cupy_array_equal()
Expand Down

0 comments on commit 1faceab

Please sign in to comment.