Skip to content

Commit

Permalink
Avoid synchronize in array function
Browse files Browse the repository at this point in the history
  • Loading branch information
okuta committed Jun 18, 2017
1 parent 320fad3 commit d3384da
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions cupy/core/core.pyx
Expand Up @@ -1900,17 +1900,17 @@ cpdef ndarray array(obj, dtype=None, bint copy=True, Py_ssize_t ndmin=0):
a.shape = (1,) * (ndmin - ndim) + a.shape
return a
else:
a_cpu = numpy.array(obj, dtype=dtype, copy=False, ndmin=ndmin)
if a_cpu.dtype.char not in '?bhilqBHILQefd':
raise ValueError('Unsupported dtype %s' % a_cpu.dtype)
if a_cpu.ndim > 0:
a_cpu = numpy.ascontiguousarray(a_cpu)
a = ndarray(a_cpu.shape, dtype=a_cpu.dtype)
a.data.copy_from_host(a_cpu.ctypes.get_as_parameter(), a.nbytes)
if a_cpu.dtype == a.dtype:
a_cpu = numpy.array(obj, dtype=dtype, copy=False, order='C',
ndmin=ndmin)
a_dtype = a_cpu.dtype
if a_dtype.char not in '?bhilqBHILQefd':
raise ValueError('Unsupported dtype %s' % a_dtype)
a = ndarray(a_cpu.shape, dtype=a_dtype)
if a_cpu.ndim == 0:
a.fill(a_cpu[()])
return a
else:
return a.view(dtype=a_cpu.dtype)
a.data.copy_from_host(a_cpu.ctypes.get_as_parameter(), a.nbytes)
return a


cpdef ndarray ascontiguousarray(ndarray a, dtype=None):
Expand Down

0 comments on commit d3384da

Please sign in to comment.