[SYSTEMML-1265] Fix robustness quantile/iqm check for integer weights 

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

Branch: refs/heads/master
Commit: 12d79c5481838fbf31d2ec3a86c3b9c4c5af1265
Parents: 0e6411d
Author: Matthias Boehm <[email protected]>
Authored: Tue Feb 14 19:26:27 2017 -0800
Committer: Matthias Boehm <[email protected]>
Committed: Wed Feb 15 10:49:20 2017 -0800

----------------------------------------------------------------------
 .../sysml/runtime/matrix/data/MatrixBlock.java       | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/12d79c54/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 746ac17..a6de5ec 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
@@ -4843,11 +4843,18 @@ public class MatrixBlock extends MatrixValue implements 
CacheBlock, Externalizab
                throws DMLRuntimeException 
        {
                double sum_wt = 0;
-               for (int i=0; i < getNumRows(); i++ )
-                       sum_wt += quickGetValue(i, 1);
-               if ( Math.floor(sum_wt) < sum_wt ) {
-                       throw new DMLRuntimeException("Unexpected error while 
computing quantile -- weights must be integers.");
+               for (int i=0; i < getNumRows(); i++ ) {
+                       double tmp = quickGetValue(i, 1);
+                       sum_wt += tmp;          
+                       
+                       // test all values not just final sum_wt to ensure that 
non-integer weights
+                       // don't cancel each other out; integer weights are 
required by all quantiles, etc
+                       if( Math.floor(tmp) < tmp ) {
+                               throw new DMLRuntimeException("Wrong input 
data, quantile weights "
+                                               + "are expected to be integers 
but found '"+tmp+"'.");
+                       }
                }
+               
                return sum_wt;
        }
 

Reply via email to