There is a lot of work already done on sparse matrix computer math.

See for example

http://www-users.cs.umn.edu/~saad/software/SPARSKIT/sparskit.html

That code could be translated to Ruby, or, to retain speed, the
'C' or Fortran code could be wrapped with a Ruby interface.

Whatever works.

BobG


On Wed, 19 Nov 2003 02:02:29 -0500, Austin Ziegler wrote:
>On Wed, 19 Nov 2003 14:21:19 +0900, Charles Hixson wrote:
>> Does anyone have an implementation of a multi-dimensioned sparse
>> array?
>
>What about using hashes?
>
>  msa = Hash.new { |h, k| h[k] = Hash.new }
>
>If you just use Numeric keys, there's little difference for your
>needs. You can subclass Hash to make it act a bit more like an Array
>under certain circumstances (e.g., #each would return values in
>key-order instead of a key-value pair; you could also do an ordered
>hash per [ruby-talk:20551] to potentially save sort times).
>
>For multi-dimensional auto-vivifying, you could do:
>
>  hash_maker = proc { |h, k| h[k] = Hash.new(&hash_maker) }
>  msa = Hash.new(&hash_maker)
>
>http://www.rubygarden.org/ruby?HashOfHashes
>
>-austin
>--
>austin ziegler    * austin / halostatue.ca * Toronto, ON, Canada
>software designer * pragmatic programmer * 2003.11.19
>                                         * 01.34.12