commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Luc Maisonobe (JIRA)" <j...@apache.org>
Subject [jira] Commented: (MATH-230) Implement Sparse Matrix Support
Date Sat, 13 Dec 2008 22:08:44 GMT

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

Luc Maisonobe commented on MATH-230:
------------------------------------

I've started applying the patch with slight changes (like curly braces, javadoc).
The most important change was to extract the map class and put it into the util packages,
adding the containsKey() and keys() methods as suggested.

I have random test failures occurring in testRemove2(). The failures are triggered by the
assertEquals(mapSize, map.size()) in the assertPutAndGet mathod called at the end of testRemove2().
mapSize was 2009 while map.size was 2010. I have succeded once (and only once) to trigger
the failure under debugger. In that case, the key was -1035761067. It appeared in the map
both at index 627 with status FULL and value 0.9939107277401076 and at index 1363 with status
FREE and value 0.0. In the javaMap it was associated with value 0.21972202724338397. The load
factor was 0.5 so array size was 4096 I think.

Trying to reuse the values above in a dedicated new test with various combinations of put
and remove didn't reproduce the bug.

I don't understand what happens yet and since it appears randomly (due to the use of java.util.Random
within the test), it is quite difficult to analyze.


> 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: math-230.diff, patch-2.txt, RealMatrixImplPerformanceTest.java,
SparseRealMatrix.java, SparseRealMatrixTest.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