See also a slide about NArray: http://www.slideshare.net/masa16tanaka/narray-and-scientific-computing-with-ruby
it looks like there are only a few extensions over the array
No, it is completely different from an array. NArray has many numerical functions and multidimensional functions. NArray, on the other hand, is static; it does not have push / pop methods, etc. NArray Method List http://narray.rubyforge.org/SPEC.en
_one. Why not just use Array?
The array contains Ruby objects. This is inefficient for storing numerical values.
_2. Is there a huge speed advantage?
Yes. p. 36 of the above slide shows that NArray is 50 times faster.
Note that Array is faster than NArray if the loop is written in Ruby.
_3. Is there a huge memory advantage?
Yes. As for the Float values, Array consumes about 4 times as much memory as NArray on my 64-bit Linux machine.
_4. Any other advantages over using the regular Ruby Array class?
- Multidimensional array support
- Numeric Function Support
- There is no need for garbage collection in Array elements. GC takes a lot of time for large arrays.
- and etc.
masa16
source share