Re: Sparse arrays

From: Gordon Sande (g.sande_at_worldnet.att.net)
Date: 12/04/03


Date: Thu, 04 Dec 2003 10:09:35 -0400

In article <slrnbsuc4h.rro.tconnors@tellurium.ssi.swin.edu.au>,
TimC <tconnors@no.astro.spam.swin.accepted.edu.here.au> wrote:

>Subject: Sparse arrays
>From: TimC <tconnors@no.astro.spam.swin.accepted.edu.here.au>
>Organization: Some weird and wacky place in the superconfusing place, Swinny.
>Date: Thu, 04 Dec 2003 13:03:15 GMT
>Newsgroups: comp.lang.fortran
>
>I have a wish to store an array in RAM that if left to it's own
>devices, would take up about 10GB. Clearly, this is impossible on x86
>architecture :)
>
>I don't want to do anything at all complex to it - I just want to
>access array element (i,j), set it, sit for a bit, and read it back
>later. No disk IO, matrix multiplications or diagonalisations etc.
>
>It's going to be a darn sparse array, but it's still going to have a
>lot of elements, so I'll like both accessing and storage to be as
>efficient as possible. I don't want to imagine what cache misses will
>look like if it does some tricky hash thing - but they will all be set
>and accessed in sequential order (with the setting being incomplete
>due to the holes in the arrays).
>
>Naturally, google aint telling me much (well technically, it is
>telling me 16000 different ways to do something that doesn't seem to
>resemble what I want), even though it is telling me just where to get
>these lovely linear algebra packages. Do *you* know of any fortran
>libraries that might suit my seemingly simple requirements?
>
>
>--
>TimC -- http://astronomy.swin.edu.au/staff/tconnors/
>"Nature is pretty" -- CmdrTaco

IF, and these things depend critically on the assumptions, your
ONLY operations are STORE and RETRIEVE with no structure to the
sequence of access then the classical solution is a scatter store,
also known as a hash table. If you can tolerate a bit of inefficiency
(its OK, just don't tell anyone other than your drinking buddies)
then keep a sorted list, sorted on i then j, and do a binary
search into the list. It is pretty quick and very easy. No need
to figure out what to do if you guess the sizes wrong, no extra
programming for hash collisions, it is easy to debug, etc, etc.
This makes the additional assumption that you tend to have
more stores before the retrieves to keep the sorts/updates
within reason.

And unless you are doing an awfull lot of this your can probably
even tolerate a fair bit of inefficiency. A lot of inefficiency
might become noticable and above that you probably need to think
about decent algorithms. A bubble sort and a linear probe for
more than 1000(?) elements will get you into the lot of
inefficiency territory.

I have codes that read in some values of a multiple index array
and store them for later access. A bit of minor fiddling and then
out they go. They live in sorted lists. The minor fiddling includes
setting of the constraint matrices for serious OR which is done
with different data structures that support the computational
operations. These are custom matrix generators in the OR usage.



Relevant Pages

  • Re: Finding the nearest match without reusing results
    ... comparing an array with a value generates an array of Trues and ... Any diff with wrong State or with used Store is implicitly zeroed out. ... Each must be larger than the absolute value of the maximum Sales ... go.....it just needs to return the closest match. ...
    (microsoft.public.excel.programming)
  • Re: read keyboard input and storing in an array?
    ... > I'm trying to store user input in an array, ... You have the beginnings of that logic already since your prompt tells the ... 201st value since the array only has room for 200 values. ... This will force you to store the int values as Integer ('Integer' ...
    (comp.lang.java.help)
  • Re: Challenge: reading ascii data
    ... to store all the data before producing any output. ... would be bad practice in terms of memory consumption to use a standard ... So I use hashes to create a two-level "sparse array", ... Well the original problem definition was: ...
    (comp.lang.fortran)
  • Re: attempting an actual game...
    ... >>> and inflexible by the absurd decision to use a bit array for square ... as then one has 8 bits in which to store a color and a few flags ... Using a 2D int (or, ... > Change direction and you may eventually complete a game. ...
    (comp.games.development.programming.misc)
  • Re: Efficient Code to Copy a 1-D Array to a Worksheet Column
    ... Invoke WorksheetFunction.Transpose[I don't know how you would ... Create and populate a 2D array from the 1D array. ... but adds inefficiency due to the extra copy step. ...
    (microsoft.public.excel.programming)