Skip to content

Commit

Permalink
[SYSTEMML-2130] Extended sparse block validation for COO format
Browse files Browse the repository at this point in the history
Closes apache#735.
  • Loading branch information
j143 authored and mboehm7 committed Mar 4, 2018
1 parent 2ddc848 commit 162a5b0
Showing 1 changed file with 44 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,50 @@ public boolean isAllocated(int r) {

@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;
}

Expand Down

0 comments on commit 162a5b0

Please sign in to comment.