Hey! This is the third blog-post in my series of GSoC experience. Phase-1 has come to its end. I’ll be sharing my experiences of third and fourth week of GSoC.
Third week
In third week of my coding, I did many minor fixes and improvements. It includes _RecursiveAttr.__repr__
, better error handling and other changes suggested by my mentor. Thanks to Imanishi-san, he provided ideas to make existing code cleaner. So, there was some re-implementation of _Recursiveattr.__getattr__
and data transfer methods. fallback_mode
now supports direct retrieval of NumPy scalars. I also implemented some tests for fallback_mode
.
Fourth week
In this week, I again did some minor fixes, moved fallback_mode
to cupyx/fallback_mode
and implemented a test decorator for testing fallback methods. PR #2229 got merged and fallback_mode
is added for release in cupy v7.0.0b1
. I am super happy, as this was my first true opensource contribution.
Now, I am currently working on next goal, that is to implement fallback_mode.ndarray
. It’s needed in order to apply fallback on ndarrays. Supporting methods such as ndarray.min()
, ndarray.reshape()
is easy. But, supporting magic methods such as __add__
, __neg__
won’t work, as they bypasses __getattr__
in new-style classes. So, for the last couple of days, I was researching about all this and found out, that this could be overcame by proxying magic methods of cupy.ndarray
to fallback_mode.ndarray
. So, for now, working on it.
Summary
fallback_mode
now has __repr__
and basic tests are done. It now supports methods of following types:
result = numpy.func(*args, **kwargs)
result = numpy.module.func(*args, **kwargs)
where, execution steps are performed onargs
,kwargs
and result is returned.
Following is how the fallback_mode
currently works.
>>> from cupyx.fallback_mode import numpy
>>> numpy.ones
<numpy = <function ones at 0x000002AC4E0AC598>, cupy = <function ones at 0x000002AC4EB977B8>>
>>> numpy.nanargmin
<numpy = <function nanargmin at 0x000002AC4E1FA7B8>, cupy = None>
>>> numpy.pi
3.141592653589793
>>> numpy.nan
nan
>>> a = numpy.array([[1,numpy.nan,2],[3,4,numpy.nan]])
>>> type(a)
<class cupy.core.core.ndarray>
>>> res = numpy.nanargmin(a, axis=0)
>>> res
array([0, 1, 0], dtype=int64)
>>> type(res)
<class cupy.core.core.ndarray>
>>> numpy.linalg
<numpy = module numpy.linalg, cupy = module cupy.linalg>
>>> numpy.matrixlib
<numpy = module numpy.matrixlib, cupy = module None>
Future work
Future work will include:
- Support fallback for
fallback_mode.ndarray
. - Notification mechanism, similar to that of
numpy.seterr
. - Supporting methods such as
ndarray.resize()
where nothing is returned, but references are modified.