Repository: systemml Updated Branches: refs/heads/master bc4acdfab -> a26957e16
[SYSTEMML-2130] Extended sparse block validation for MCSR format Closes #738. Project: http://git-wip-us.apache.org/repos/asf/systemml/repo Commit: http://git-wip-us.apache.org/repos/asf/systemml/commit/a26957e1 Tree: http://git-wip-us.apache.org/repos/asf/systemml/tree/a26957e1 Diff: http://git-wip-us.apache.org/repos/asf/systemml/diff/a26957e1 Branch: refs/heads/master Commit: a26957e16f7e73181deea0e42b86701ee443cf96 Parents: bc4acdf Author: Janardhan Pulivarthi <[email protected]> Authored: Thu Mar 8 20:34:59 2018 -0800 Committer: Matthias Boehm <[email protected]> Committed: Thu Mar 8 20:35:00 2018 -0800 ---------------------------------------------------------------------- .../runtime/matrix/data/SparseBlockMCSR.java | 33 +++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/systemml/blob/a26957e1/src/main/java/org/apache/sysml/runtime/matrix/data/SparseBlockMCSR.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/sysml/runtime/matrix/data/SparseBlockMCSR.java b/src/main/java/org/apache/sysml/runtime/matrix/data/SparseBlockMCSR.java index 954248d..fe63f2b 100644 --- a/src/main/java/org/apache/sysml/runtime/matrix/data/SparseBlockMCSR.java +++ b/src/main/java/org/apache/sysml/runtime/matrix/data/SparseBlockMCSR.java @@ -160,7 +160,38 @@ public class SparseBlockMCSR extends SparseBlock @Override public boolean checkValidity(int rlen, int clen, long nnz, boolean strict) { - // empty implementation + + //1. Correct meta data + if( rlen < 0 || clen < 0 ) + throw new RuntimeException("Invalid block dimensions: ("+rlen+", "+clen+")."); + + //2. Correct array lengths + if( size() < nnz ) + throw new RuntimeException("Incorrect size: "+size()+" (expected: "+nnz+")."); + + //3. Sorted column indices per row + for( int i=0; i<rlen; i++ ) { + if( isEmpty(i) ) continue; + int apos = pos(i); + int alen = size(i); + int[] aix = indexes(i); + double[] avals = values(i); + for (int k = apos + 1; k < apos + alen; k++) { + if (aix[k-1] >= aix[k]) + throw new RuntimeException("Wrong sparse row ordering, at row: " + + k + "with " + aix[k-1] + ">=" + aix[k]); + if (avals[k] == 0) + throw new RuntimeException("The values are expected to be non zeros " + + "but zero at row: "+ i + ", col pos: " + k); + } + } + + //3. A capacity that is no larger than nnz times resize factor + for( int i=0; i<rlen; i++ ) + if( !isEmpty(i) && values(i).length > nnz*RESIZE_FACTOR1 ) + throw new RuntimeException("The capacity is larger than nnz times a resize factor(=2). " + + "Actual length = " + values(i).length+", should not exceed "+nnz*RESIZE_FACTOR1); + return true; }
