creating CRSMatrix on the fly

76 views
Skip to first unread message

Ken Stephenson

unread,
Jan 28, 2014, 10:40:59 AM1/28/14
to la...@googlegroups.com
I need to solve sparse linear systems in my java program CirclePack, and I'm experimenting with la4j. 

Some newbie questions: * How does one create CCSMatrix on the fly, not reading from a file? Also, matrices may be up to 500,000 x 500,000, so I don't want to allocate a full array just to create the matrix. * I've tried 'set' methods, but does indexing start are 0 or 1? For a BasicVector, b.set(0,2.0) puts a 2 in the first entry, but for a CCSMatrix, seems that m.set(1,3,5.0) puts 5 in the (1,3) entry. * Looking at the documentation for CCSMatrix, reference is to "indices" but to column "pointers". What's the difference? * How do the sparse solvers compare to sparse solvers in C++ or fortran for performance? I'm moving code from C++ into java for cross-platform purposes. Does la4j exploit sparseness in solving or just use it to save storage?

Many thanks,
Ken

Vladimir Kostyukov

unread,
Jan 28, 2014, 11:19:35 AM1/28/14
to Ken Stephenson, la...@googlegroups.com
Hi Ken,

First of all, thanks a lot for contacting me via the la4j-email list. This is how I see an efficient collaboration between developers in contributors. Regarding your questions and issues.

* CRS matrices on-the-fly: You can easily create new sparse matrix with public constructor like this:

Matrix a = new CCSMatrix(500000, 500000);

It's not a problem having such a _big_ matrices, since la4j doesn't allocate the whole memory for sparse matrices. It will be growing on-demand. There is only one constraint: the maximum matrix you can handle with la4j is Integer.MAX_VALUE - 1 x Integer.MAX_VALUE - 1. This is a restriction from JVM - maximum array size, actually.

* Indexation: all the access operations like get/set are 0-index based. So, I don't see any issues with the examples you provided.

Documentation: You're right. The documentation is the weakest side of the la4j library. So, I'm currently trying to fix this and put as much effort into this as possible. You can also participate in this. Anyway, regarding your question. CCSMatrix implements a well-known "Compressed Column Storage" format of sparse matrices. So, in CCSMatrix, the rowIndices array contains a row-index for every value in values array. While, columnPointers array contains a value-index, starting from each, the i-th column is represented in values array. So, normally, you don't need to handle this in your application code. It's kind of tricky, but it can boost the performance of generating new sparse matrices, by using a specialised constructor. But, still, I would suggest you to avoid this approach, until you prove that this a bottleneck. 

Sparse solvers: For now, all the solvers logic is built on top of primitive set/get operations, which means there is no performance improvements of using sparse data. So, the la4j library is currently handling sparse entries for reducing memory footprint. But, that doesn't mean, sparse entries are slow. They work Ok, but should be improved for sure. I'm currently in the middle of doing this. The next la4j release will be arising this issue (as well as in-place operations). Which means, you can write you application code in terms of la4j API and get the performance boost after updating the library installation (w/o changing the code). The new version should be available this summer (or earlier, it depends on contributors' activity as well).

And the last but not least thing. I've just updated the version of la4j. The latest one is 0.4.9. Please, don't forget to update your Maven config in order to get the latest version.

Let me know, should you have any further questions!

--
Thanks,
Vladimir Kostyukov

Ken Stephenson

unread,
Jan 28, 2014, 2:11:54 PM1/28/14
to la...@googlegroups.com, Ken Stephenson
Vlad,

Thanks for quick reply. Yes, I've got 4.9 installed. I plan to use the calls without getting into the backend details, but just to be sure,
you are saying that   m.set(0,0,7.0)   will set the first row/first column of matrix m to 7.0, right? Okay, I'll see how it goes.

Ken

Vladimir Kostyukov

unread,
Jan 28, 2014, 11:05:36 PM1/28/14
to Ken Stephenson, la...@googlegroups.com
Ken,

That's corrent. Please, let me now of any other issues/questions you will face.
--
Thanks,
Vladimir Kostyukov
Reply all
Reply to author
Forward
0 new messages