commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Sujit Pal (JIRA)" <j...@apache.org>
Subject [jira] Commented: (MATH-230) Implement Sparse Matrix Support
Date Fri, 05 Dec 2008 03:40:48 GMT

    [ https://issues.apache.org/jira/browse/MATH-230?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12653609#action_12653609
] 

Sujit Pal commented on MATH-230:
--------------------------------

Thanks for the pointer to TObjectDoubleHashMap. So basically what you
are suggesting is for the incoming (x,y) object, whatever that is, to be
hashed to a single int object which is modded against the internal
one-dimensional array length. Finally the hash/mod result needs to be
checked against the internal double array to see if it is already
occupied, and if so, another location should be found.

Here are the relevant links:
http://trove4j.cvs.sourceforge.net/viewvc/trove4j/trove/src/gnu/trove/TObjectDoubleHashMap.java?hideattic=0&revision=1.16&view=markup
http://trove4j.cvs.sourceforge.net/viewvc/trove4j/trove/src/gnu/trove/TObjectHash.java?hideattic=0&revision=1.26&view=markup

That /would/ definitely decrease the size of the matrix, but would make
the get/set code quite complex, unless one could use (something like)
trove4j as a dependency.

Rather than add this impl, then, it may be better to open the door for
extension (via the suggestion in MATH-231) and let the client (who will
probably find it easier to add different jars as dependencies) do the
extension as he desires?




> Implement Sparse Matrix Support
> -------------------------------
>
>                 Key: MATH-230
>                 URL: https://issues.apache.org/jira/browse/MATH-230
>             Project: Commons Math
>          Issue Type: Improvement
>    Affects Versions: 2.0
>         Environment: N/A
>            Reporter: Sujit Pal
>            Assignee: Luc Maisonobe
>            Priority: Minor
>             Fix For: 2.0
>
>         Attachments: patch.txt, RealMatrixImplPerformanceTest.java, SparseRealMatrixImpl.java,
SparseRealMatrixImplTest.java
>
>
> I needed a way to deal with large sparse matrices using commons-math RealMatrix, so I
implemented it. The SparseRealMatrixImpl is a subclass of RealMatrixImpl, and the backing
data structure is a Map<Point,Double>, where Point is a struct like inner-class which
exposes two int parameters row and column. I had to make some changes to the existing components
to keep the code for SparseRealMatrixImpl clean. Here are the details.
> 1) RealMatrix.java:
>    - added a new method setEntry(int, int, double) to set data into a matrix
> 2) RealMatrixImpl.java:
>    - changed all internal calls to data[i][j] to getEntry(i,j).
>    - for some methods such as add(), subtract(), premultiply(), etc, there
>      was code that checked for ClassCastException and had two versions,
>      one for a generic RealMatrix and one for a RealMatrixImpl. This has
>      been changed to have only one that operates on a RealMatrix. The 
>      result is something like auto-type casting. So if:
>        RealMatrixImpl.add(RealMatrix) returns a RealMatrixImpl
>        SparseRealMatrixImpl.add(RealMatrix) returns a SparseRealMatrixImpl
> 3) SparseRealMatrixImpl added as a subclass of RealMatrixImpl.
> 4) LUDecompositionImpl changed to use a clone of the passed in RealMatrix
>    instead of its data[][] block, and now it uses clone.getEntry(row,col)
>    calls instead of data[row][col] calls.
> 5) LUDecompositionImpl returned RealMatrixImpl for getL(), getU(), getP()
>    and solve(). It now returns the same RealMatrix impl that is passed 
>    in through its constructor for these methods.
> 6) New test for SparseRealMatrixImpl, mimics the tests in RealMatrixImplTest,
> 7) New static method to create SparseRealMatrixImpl out of a double[][] in
>    MatrixUtils.createSparseRealMatrix().
>    but using SparseRealMatrixImpl.
> 8) Verified that all JUnit tests pass.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


Mime
View raw message