Ruby core Matrix vs NArray's NMatrix
There seems to be three matrix modules in Ruby that I've found
- Matrix: Part of core Ruby it seems
- NArra开发者_StackOverflow社区y: NMatrix is part of the NArray library (github)
- NMatrix: Part of SciRuby
At the moment it seems NArray
's NMatrix
is faster than Matrix
, has some more helpful methods, but require a bit more setup.
Is there anyone with experience of both who can give a rough overview of why I should use one over the other?
Just stumbling on this question now... It's been 7 months since you've asked, so I'm sure you've found your answer by now.
However, please find information here.
Basically, the author of the core Matrix class did not add methods to perform run-time modifications to the array once it is instantiated. The NArray class allows for this.
As far as computation time, I'll leave that to somebody else, for I don't know.
A bit late to the ballgame, but have you seen the new NMatrix gem? It's inspired by NArray. It's also written in C/C++, whereas Ruby Matrix is written only in Ruby --- so NMatrix is definitely faster.
That's also true for NArray, which is C-only.
The advantage to using NMatrix instead of NArray::NMatrix
is that you can choose between different storage types (sparse, dense, etc.).
精彩评论