Hey! This is the sixth blog-post in the series of GSoC blog-posts. 2nd evaluations are done and this is going to be the last month of GSoC. I think, this month will be the best of all. I am going to go deeper into CuPy for creation of view
of ndarray
(ndarray
sharing same memory space with another ndarray
) and deal with core ndarray
implementation, cuda.MemoryPointer
, __cuda_array_interface__
(CuPy), __array_interface__
(NumPy) etc. for dealing with memory location and stuff. It’s going to be amazing!
Ninth week
I was on leave for about 3-4 days due to my college re-opening. Still, I was able to do some work. I implemented cupy.nanvar
and cupy.nanstd
using ReductionKernel
. It was something new so, I enjoyed it.
Then, I implemented fallback.vectorize
(a wrapper around numpy.vectorize
). I faced some difficulty for the elimination of recursion error, but it was resolved without taking too much time.
Tenth week
This week I implemented support for in-place operations. It was decided to update all args
and kwargs
as an initial solution. I created some tests to cover special cases too such as numpy.putmask
, ndarray.byteswap
etc. and it’s working as expected.
Then, I went ahead for adding support for view
. I was able to create a view
of cupy.ndarray
with desired shape[0]
. Manipulating zero-axis was quite straight forward, but it will be way much harder to support all axes. Following is the prototype:
import cupy as cp
import numpy as np
a = np.ones((3, 4))
b = a[1:]
x = cp.ones((3, 4))
# we need to create view wrt x, as b is a view wrt a
def getptr(a):
if isinstance(a, np.ndarray):
return a.__array_interface__['data'][0]
if isinstance(a, cp.ndarray):
return a.data.ptr
raise TypeError
if b.base is a:
offset = getptr(b) - getptr(a)
memptr = x.data + offset
y = cp.ndarray(b.shape, x.dtype, memptr)
y[0][0] = 0
print(x)
'''
[[1. 1. 1. 1.]
[0. 1. 1. 1.]
[1. 1. 1. 1.]]
'''
Summary
- Implemented support for in-place operations.
- PR #2350 for
fallback.vectorize
got merged. - PR #2344 for
cupy.nanvar
andcupy.nanstd
got merged.
Future work
Future work will consist of following:
- Supporting
view
ofndarray
. - Supporting of
numpy.ndarray
variants such asnumpy.ma.MaskedArray
,numpy.chararray
etc.