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

[Propose] Return 0-dimensional array instead of Ruby numeric object

Open sonots opened this issue 7 years ago • 1 comments

This is a feedback from Cumo implementation. https://speakerdeck.com/sonots/fast-numerical-computing-and-deep-learning-in-ruby-with-cumo?slide=42

Numo:

irb(main):015: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):016:0> a.sum
=> 66

Cumo:

irb(main):002:0> a = Cumo::Int32.new(3,4).seq
=> Cumo::Int32#shape=[3,4]
[[0, 1, 2, 3],
 [4, 5, 6, 7],
 [8, 9, 10, 11]]
irb(main):003:0> a.sum
=> Cumo::Int64#shape=[]
66

The reason why Cumo returns 0-dimensional array instead of Ruby numeric object is, to avoid cudaMemcpy from GPU to CPU for performance.

For compatibility between Numo and Cumo, I propose to change behavior of Numo to return 0-dimensional NArray directly without converting it into Ruby numeric object.

sonots avatar Jul 07 '18 13:07 sonots

I second this proposition. Had a long discussion on the mathematical reasons behind it in issue #91 (which incidentally would be solved by this).

giuse avatar Jul 07 '18 13:07 giuse