Skip to content

Commit adfb8bf

Browse files
committed
Speedup the cython implementation of setitem.
1 parent e115f25 commit adfb8bf

2 files changed

Lines changed: 11 additions & 3 deletions

File tree

pygpu/gpuarray.pxd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,7 @@ cdef api class GpuArray [type PyGpuArrayType, object PyGpuArrayObject]:
337337

338338
cdef __index_helper(self, key, unsigned int i, ssize_t *start,
339339
ssize_t *stop, ssize_t *step)
340+
cdef __cgetitem__(self, idx)
340341

341342
cdef api class GpuKernel [type PyGpuKernelType, object PyGpuKernelObject]:
342343
cdef _GpuKernel k

pygpu/gpuarray.pyx

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -907,6 +907,10 @@ def array(proto, dtype=None, copy=True, order=None, unsigned int ndmin=0,
907907
This function is similar to :meth:`numpy.array` except that it returns
908908
GpuArrays.
909909
"""
910+
return carray(proto, dtype, copy, order, ndmin, context, cls)
911+
912+
cdef carray(proto, dtype, copy, order, unsigned int ndmin,
913+
GpuContext context, cls):
910914
cdef GpuArray res
911915
cdef GpuArray arg
912916
cdef GpuArray tmp
@@ -1823,6 +1827,9 @@ cdef class GpuArray:
18231827
raise TypeError, "len() of unsized object"
18241828

18251829
def __getitem__(self, key):
1830+
return self.__cgetitem__(key)
1831+
1832+
cdef __cgetitem__(self, key):
18261833
cdef ssize_t *starts
18271834
cdef ssize_t *stops
18281835
cdef ssize_t *steps
@@ -1886,9 +1893,9 @@ cdef class GpuArray:
18861893
free(steps)
18871894

18881895
def __setitem__(self, idx, v):
1889-
cdef GpuArray tmp = self.__getitem__(idx)
1890-
cdef GpuArray gv = asarray(v, dtype=self.dtype,
1891-
context=self.context)
1896+
cdef GpuArray tmp = self.__cgetitem__(idx)
1897+
cdef GpuArray gv = carray(v, self.ga.typecode, False, 'A', 0,
1898+
self.context, GpuArray)
18921899

18931900
array_setarray(tmp, gv)
18941901

0 commit comments

Comments
 (0)