I believe at the moment that matrix addition, subtraction and scalar multiplication is implemented in Ruby space. This results in a huge bottleneck in HPC applications. I implemented a neural network in NMatrix and 50% of the computation time is spent adding up matrices.
Would it be possible to implement a c type iterator that takes as arguments 2 dense matrices and then applies an arbitrary function on each element pair?
Something like mat1.zip(mat2).map!{|el el[0] + el[1] } would be equivalent to mat1 + mat2, but you can provide any function in the block, and this will be executed in c.
I have been going over the code to see if I can implement it myself but the code is a bit overwhelming as I do not know c or c++.
Do you guys have any pointers for me to get started on this to try and implement this function?
Also, are there other people that need this type functionality or am I missing something obvious?
Thanks,
Henry