[Numpy-discussion] Update on sparse matrix in binary

Mark Janikas mjanikas@esri....
Thu Feb 15 12:48:39 CST 2007


I wanted to thank all of you who helped me with my making my sparse
matrix representation cross-platform in binary format!

 

I ended up writing and reading everything explicitly in little endian.
To recap, each row in the matrix is represented by three records:

 

1)       row#, nn (number of non-zero elements)

2)       col (indices of non-zero elements in row #)

3)       values (doubles corresponding to indices provided in the
previous array)

 

I created the arrays using: 

 

a = array([values], '<l or d').tostring(); f.write(a)

 

And read using: 

 

a = f.read(# of bytes, 8 for first record, nn*4 for longs, nn*8 for
doubles); 

a = fromstring(a, '<l or d')

 

The tofile() and fromfile() version work as well, but it wasn't any
faster.  So I went with what I thought was more intuitive in the context
of the algorithm.

 

So far, it has worked on the Windows, Linux, Solaris and Mac OSX boxes I
have tried.  I know it is hardware specific as opposed to platform, so I
will continue to seek out the rarer vintages of machines that can run
the software we provide.

 

Again, thanks to all; and if there are any more suggestions as to how
this process could be more optimized, please feel free to respond.  Best
wishes,

 

 

Mark Janikas

Product Engineer

ESRI, Geoprocessing

380 New York St.

Redlands, CA 92373

909-793-2853 (2563)

mjanikas@esri.com

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://projects.scipy.org/pipermail/numpy-discussion/attachments/20070215/1d00ee46/attachment.html 


More information about the Numpy-discussion mailing list