numo-narray icon indicating copy to clipboard operation
numo-narray copied to clipboard

[Propose] Stop making a view of NArray at #aref (or Stop using idx)

Open sonots opened this issue 7 years ago • 1 comments

In Numo, advanced indexing returns a view of a Numo NArray.

irb(main):007:0> a = Numo::Int32.new(3,4).seq
=> Numo::Int32#shape=[3,4]
[[0, 1, 2, 3],
 [4, 5, 6, 7],
 [8, 9, 10, 11]]
irb(main):012:0> a[a > 5]
=> Numo::Int32(view)#shape=[6]
[6, 7, 8, 9, 10, 11]

In Numpy, advanced indexing returns a new ndarray.

>>> a = numpy.arange(12).reshape(3,4)
>>> b = a[a > 5]
>>> b
array([ 6,  7,  8,  9, 10, 11])
>>> a
array([[ 0,  1,  2,  3],
       [ 4,  5,  6,  7],
       [ 8,  9, 10, 11]])
>>> b[0] = 1
>>> b
array([ 1,  7,  8,  9, 10, 11])
>>> a
array([[ 0,  1,  2,  3],
       [ 4,  5,  6,  7],
       [ 8,  9, 10, 11]])

I propose Numo to work similarly with NumPy.

By stopping to make a view of NArray at #[], we can remove NDF_INDEX_LOOP, or all of codes using idx internally, and results in making very simple implementation.


This is a kind of feedback from Cumo. In Cumo, idx C array must be transferred from CPU to GPU when we want to use it in CUDA Kernel. Also, we have to copy back from GPU to CPU when we want to use it in CPU side.

It made implementation of Cumo very complex. I want to stop using idx.

sonots avatar Jul 07 '18 13:07 sonots

I talked with @masa16, and we agreed that making the behavior same with NumPy ndarray.

sonots avatar Jul 07 '18 13:07 sonots