Repository: systemml
Updated Branches:
  refs/heads/master 2ddc84873 -> 162a5b0f6


[SYSTEMML-2130] Extended sparse block validation for COO format

Closes #735.


Project: http://git-wip-us.apache.org/repos/asf/systemml/repo
Commit: http://git-wip-us.apache.org/repos/asf/systemml/commit/162a5b0f
Tree: http://git-wip-us.apache.org/repos/asf/systemml/tree/162a5b0f
Diff: http://git-wip-us.apache.org/repos/asf/systemml/diff/162a5b0f

Branch: refs/heads/master
Commit: 162a5b0f6441942c478a8061a968fec1a85410bf
Parents: 2ddc848
Author: Janardhan Pulivarthi <[email protected]>
Authored: Sat Mar 3 20:13:38 2018 -0800
Committer: Matthias Boehm <[email protected]>
Committed: Sat Mar 3 20:13:39 2018 -0800

----------------------------------------------------------------------
 .../runtime/matrix/data/SparseBlockCOO.java     | 45 +++++++++++++++++++-
 1 file changed, 44 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/systemml/blob/162a5b0f/src/main/java/org/apache/sysml/runtime/matrix/data/SparseBlockCOO.java
----------------------------------------------------------------------
diff --git 
a/src/main/java/org/apache/sysml/runtime/matrix/data/SparseBlockCOO.java 
b/src/main/java/org/apache/sysml/runtime/matrix/data/SparseBlockCOO.java
index 3cd500a..b2a234a 100644
--- a/src/main/java/org/apache/sysml/runtime/matrix/data/SparseBlockCOO.java
+++ b/src/main/java/org/apache/sysml/runtime/matrix/data/SparseBlockCOO.java
@@ -194,7 +194,50 @@ public class SparseBlockCOO 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 && _cindexes.length < nnz && _rindexes.length < 
nnz && _values.length < nnz) {
+                       throw new RuntimeException("Incorrect array lengths.");
+               }
+
+               //3.1. sort order of row indices
+               for( int i=1; i<=nnz; i++ ) {
+                       if(_rindexes[i] < _rindexes[i-1])
+                               throw new RuntimeException("Wrong sorted order 
of row indices");
+               }
+
+               //3.2. sorted values wrt to col indexes wrt to a given row index
+               for( int i=0; i<rlen; i++ ) {
+                       int apos = pos(i);
+                       int alen = size(i);
+                       for(int k=apos+i; k<apos+alen; k++)
+                               if( _cindexes[k+1] >= _cindexes[k] )
+                                       throw new RuntimeException("Wrong 
sparse row ordering: "
+                                                       + k + " 
"+_cindexes[k-1]+" "+_cindexes[k]);
+                       for( int k=apos; k<apos+alen; k++ )
+                               if(_values[k] == 0)
+                                       throw new RuntimeException("Wrong 
sparse row: zero at "
+                                                       + k + " at col index " 
+ _cindexes[k]);
+               }
+
+               //4. non-existing zero values
+               for( int i=0; i<_size; i++ ) {
+                       if( _values[i] == 0)
+                               throw new RuntimeException("The values array 
should not contain zeros."
+                                               + " The " + i + "th value is 
"+_values[i]);
+               }
+
+               //5. a capacity that is no larger than nnz times the resize 
factor
+               int capacity = _values.length;
+               if( capacity > nnz*RESIZE_FACTOR1 ) {
+                       throw new RuntimeException("Capacity is larger than the 
nnz times a resize factor."
+                                       + " Current size: "+capacity+ ", while 
Expected size:"+nnz*RESIZE_FACTOR1);
+               }
+
                return true;
        }
 

Reply via email to