SciRuby / nmatrix

Dense and sparse linear algebra library for Ruby via SciRuby
Other
470 stars 133 forks source link

Broadcasting support for nmatrix #589

Open v0dro opened 7 years ago

v0dro commented 7 years ago

Performing arithmetic operations by broadcasting elements in C level instead of looping over them in Ruby would be a nice way to speed up things in nmatrix. Take for example the numpy way of doing this.

Numo::NArray also supports broadcasting.

translunar commented 7 years ago

I tend to feel like broadcasting creates confusing bugs in code. For example, if I add x and x-transpose together with Numpy, I expect an error — but actually I get an nxn matrix.

Maybe there's a way to have it be a feature that is turned on and off according to user preference?

v0dro commented 7 years ago

Yes maybe we can have it with support to turn it off and on. I think most of the problems with nmatrix speed involving things like multiplication and math operations can be overcome if we use broadcasting.

Having a switch would be helpful. If this is done, nmatrix can be internally used in daru for a massive increase in efficiency. I'm a bit skeptical about using Numo::NArray in daru because that will mean dropping support for JRuby.