[SYSTEMML-1575] DataType Change Test Fix

While working on SYSTEMML-1554, an additional bug was uncovered.
Specifically, with the new IPA scalar replacement enhancement, the
`org.apache.sysml.test.integration.functions.misc.DataTypeChangeTest#testDataTypeChangeValidate4c`
test started to fail due to attempts to cast a Matrix to a Scalar
object during IPA scalar replacement.  This was due to a bug in which
if the calling program reassigned a variable to the output of a
function, and the datatype differed between that variable and the
function output, the calling program's variable map would not be
updated to remove this variable.  Thus, a variable of the incorrect
datatype would remain in the calling program, and  when the new IPA
scalar replacement ran over the rest of the calling program, it would
attempt to replace a scalar using the value in the calling program
variable map, which would incorrectly still be a matrix type.  This
bug did not show up before since we did not previously employ IPA
scalar replacement.

This fix updates the `extractFunctionCallReturnStatistics` method
to remove the variable from the calling program's variable map if
the calling program is reassigning a variable to the output of this
function and the datatypes differ.

Closes #468.


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

Branch: refs/heads/master
Commit: a281f38c750d9fcaba2b91aba8dbd360be7037ca
Parents: 0b1dcdd
Author: Mike Dusenberry <mwdus...@us.ibm.com>
Authored: Fri May 5 13:45:18 2017 -0700
Committer: Mike Dusenberry <mwdus...@us.ibm.com>
Committed: Fri May 5 13:45:18 2017 -0700

----------------------------------------------------------------------
 .../sysml/hops/ipa/InterProceduralAnalysis.java      | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/a281f38c/src/main/java/org/apache/sysml/hops/ipa/InterProceduralAnalysis.java
----------------------------------------------------------------------
diff --git 
a/src/main/java/org/apache/sysml/hops/ipa/InterProceduralAnalysis.java 
b/src/main/java/org/apache/sysml/hops/ipa/InterProceduralAnalysis.java
index 6068ce7..37fa379 100644
--- a/src/main/java/org/apache/sysml/hops/ipa/InterProceduralAnalysis.java
+++ b/src/main/java/org/apache/sysml/hops/ipa/InterProceduralAnalysis.java
@@ -747,7 +747,20 @@ public class InterProceduralAnalysis
                                DataIdentifier di = foutputOps.get(i);
                                String fvarname = di.getName(); //name in 
function signature
                                String pvarname = outputVars[i]; //name in 
calling program
-                               
+
+                               // If the calling program is reassigning a 
variable with the output of this
+                               // function, and the datatype differs between 
that variable and this function
+                               // output, remove that variable from the 
calling program's variable map.
+                               if( callVars.keySet().contains(pvarname) ) {
+                                       DataType fdataType = di.getDataType();
+                                       DataType pdataType = 
callVars.get(pvarname).getDataType();
+                                       if( fdataType != pdataType ) {
+                                               // datatype has changed, and 
the calling program is reassigning the
+                                               // the variable, so remove it 
from the calling variable map
+                                               callVars.remove(pvarname);
+                                       }
+                               }
+                               // Update or add to the calling program's 
variable map.
                                if( di.getDataType()==DataType.MATRIX && 
tmpVars.keySet().contains(fvarname) )
                                {
                                        MatrixObject moIn = (MatrixObject) 
tmpVars.get(fvarname);

Reply via email to