[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
## sparse 2-D lookup

**From**: |
Jeff Abrahamson |

**Subject**: |
sparse 2-D lookup |

**Date**: |
Tue, 25 Oct 2005 18:43:22 -0400 |

**User-agent**: |
Mutt/1.5.9i |

I want an array of (x,y,z) triples. The problem is that x and y come
from the same very large set, but very few (x,y) pairs will actually
be used. The z value is computed based on x and y, so this is really
a function f(x,y) = z.
Naively I'd create a sparse array, but sparse arrays seem (it's not
clear, though) to become regular arrays if I add elements to them.
Thus,
v = sparse(10000000,10000000)
v =
Compressed Column Sparse (rows=10000000, cols=10000000, nnz=0)
octave:3> v(1,1) = 1
(and memory usage jumps to near 2 GB and my machine slows to a crawl).
Any suggestions on how to do the bookkeeping?
The particular task is that I want to subdivide a triangulated surface
using midpoints of edges. So I have a 3 x n array vertices and a 3 x n
of triangles. I want to add midpoints to the vertex array, but I
don't want to add each midpoint twice, so I want an efficient lookup
mechanism so I can say "Is the midpoint of (x,y) already assigned? If
yes, what is its index in the vertex array, if no add it for me."
Thanks much for any pointers.
--
Jeff
Jeff Abrahamson <http://www.purple.com/jeff/> +1 215/837-2287
GPG fingerprint: 1A1A BA95 D082 A558 A276 63C6 16BF 8C4C 0D1D AE4B
-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.
Octave's home on the web: http://www.octave.org
How to fund new projects: http://www.octave.org/funding.html
Subscription information: http://www.octave.org/archive.html
-------------------------------------------------------------

**sparse 2-D lookup**,
*Jeff Abrahamson* **<=**