Repository: systemml
Updated Branches:
  refs/heads/master 111b29787 -> 563b8926b


[MINOR] Internal primitive for tracking matrices w/ NaNs

This patch introduces a useful primitive for tracking and reporting
matrices with NaNs. When applied after each executed instruction it
allows to easily find the first instruction that introduced a NaN
(before they often spread uncontrollably over many intermediates).


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

Branch: refs/heads/master
Commit: 563b8926b2edb26ac0b852f4ad593985f0cedadf
Parents: 111b297
Author: Matthias Boehm <mboe...@gmail.com>
Authored: Tue Jun 12 00:09:10 2018 -0700
Committer: Matthias Boehm <mboe...@gmail.com>
Committed: Tue Jun 12 00:09:10 2018 -0700

----------------------------------------------------------------------
 .../sysml/runtime/matrix/data/MatrixBlock.java  | 33 ++++++++++++++++++++
 1 file changed, 33 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/systemml/blob/563b8926/src/main/java/org/apache/sysml/runtime/matrix/data/MatrixBlock.java
----------------------------------------------------------------------
diff --git 
a/src/main/java/org/apache/sysml/runtime/matrix/data/MatrixBlock.java 
b/src/main/java/org/apache/sysml/runtime/matrix/data/MatrixBlock.java
index 393f8c7..5bd7d72 100644
--- a/src/main/java/org/apache/sysml/runtime/matrix/data/MatrixBlock.java
+++ b/src/main/java/org/apache/sysml/runtime/matrix/data/MatrixBlock.java
@@ -5573,6 +5573,39 @@ public class MatrixBlock extends MatrixValue implements 
CacheBlock, Externalizab
                return !sparse || DEFAULT_SPARSEBLOCK == SparseBlock.Type.MCSR; 
//only MCSR thread-safe 
        } 
        
+       /**
+        * Checks for existing NaN values in the matrix block.
+        * @throws DMLRuntimeException if the blocks contains at least one NaN.
+        */
+       public void checkNaN() {
+               if( isEmptyBlock(false) )
+                       return;
+               if( sparse ) {
+                       SparseBlock sblock = sparseBlock;
+                       for(int i=0; i<rlen; i++) {
+                               if( sblock.isEmpty(i) ) continue;
+                               int alen = sblock.size(i);
+                               int apos = sblock.pos(i);
+                               int[] aix = sblock.indexes(i);
+                               double[] avals = sblock.values(i);
+                               for(int k=apos; k<apos+alen; k++) {
+                                       if( Double.isNaN(avals[k]) )
+                                               throw new 
DMLRuntimeException("NaN encountered at position ["+i+","+aix[k]+"].");
+                               }
+                       }
+               }
+               else {
+                       DenseBlock dblock = denseBlock;
+                       for(int i=0; i<rlen; i++) {
+                               int aix = dblock.pos(i);
+                               double[] avals = dblock.values(i);
+                               for(int j=0; j<clen; j++)
+                                       if( Double.isNaN(avals[aix+j]) )
+                                               throw new 
DMLRuntimeException("NaN encountered at position ["+i+","+j+"].");
+                       }
+               }
+       }
+       
        @Override
        public int compareTo(Object arg0) {
                throw new RuntimeException("CompareTo should never be called 
for matrix blocks.");

Reply via email to