Issue Details (XML | Word | Printable)

Key: MATH-230
Type: Improvement Improvement
Status: Closed Closed
Resolution: Fixed
Priority: Minor Minor
Assignee: Luc Maisonobe
Reporter: Sujit Pal
Votes: 1
Watchers: 2
Operations

If you were logged in you would be able to see more operations.
Commons Math

Implement Sparse Matrix Support

Created: 30/Nov/08 08:16 PM   Updated: 23/Apr/09 02:26 AM
Return to search
Component/s: None
Affects Version/s: 2.0
Fix Version/s: 2.0

Time Tracking:
Not Specified

File Attachments:
  Size
File Licensed for inclusion in ASF works math-230.diff 2008-12-08 01:11 AM Ismael Juma 49 kB
Text File Licensed for inclusion in ASF works patch-2.txt 2008-12-12 06:37 PM Sujit Pal 2 kB
Java Source File Licensed for inclusion in ASF works RealMatrixImplPerformanceTest.java 2008-12-02 08:16 PM Sujit Pal 2 kB
Java Source File Licensed for inclusion in ASF works SparseRealMatrix.java 2008-12-12 06:36 PM Sujit Pal 11 kB
Java Source File Licensed for inclusion in ASF works SparseRealMatrixTest.java 2008-12-12 06:36 PM Sujit Pal 25 kB
Environment: N/A
Issue Links:
dependent
 

Resolution Date: 14/Dec/08 03:08 PM


 Description  « Hide
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.


 All   Comments   Work Log   Change History   Subversion Commits      Sort Order: Ascending order - Click to sort in descending order