Repository: incubator-systemml
Updated Branches:
  refs/heads/master 9b77782fa -> 6815cd9b7


[SYSTEMML-1222] MLContext input long to int cast

Convert MLContext long input to int since long not a supported value type.
Fix input value type error message to display input name rather than value.

Closes #370.


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

Branch: refs/heads/master
Commit: 6815cd9b7d2e9fdffeef5691102d31aa7293bef4
Parents: 9b77782
Author: Deron Eriksson <[email protected]>
Authored: Thu Feb 2 16:50:43 2017 -0800
Committer: Deron Eriksson <[email protected]>
Committed: Thu Feb 2 16:50:43 2017 -0800

----------------------------------------------------------------------
 .../sysml/api/mlcontext/MLContextUtil.java      |  2 +-
 .../org/apache/sysml/api/mlcontext/Script.java  |  7 +++++++
 .../integration/mlcontext/MLContextTest.java    | 20 ++++++++++++++++++++
 3 files changed, 28 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/6815cd9b/src/main/java/org/apache/sysml/api/mlcontext/MLContextUtil.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/sysml/api/mlcontext/MLContextUtil.java 
b/src/main/java/org/apache/sysml/api/mlcontext/MLContextUtil.java
index b4e7f01..75e9c1e 100644
--- a/src/main/java/org/apache/sysml/api/mlcontext/MLContextUtil.java
+++ b/src/main/java/org/apache/sysml/api/mlcontext/MLContextUtil.java
@@ -256,7 +256,7 @@ public final class MLContextUtil {
                        }
                }
                if (!supported) {
-                       throw new MLContextException("Input name (\"" + value + 
"\") value type not supported: " + o.getClass());
+                       throw new MLContextException("Input name (\"" + name + 
"\") value type not supported: " + o.getClass());
                }
        }
 

http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/6815cd9b/src/main/java/org/apache/sysml/api/mlcontext/Script.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/sysml/api/mlcontext/Script.java 
b/src/main/java/org/apache/sysml/api/mlcontext/Script.java
index 4f3d6ea..e96e7dd 100644
--- a/src/main/java/org/apache/sysml/api/mlcontext/Script.java
+++ b/src/main/java/org/apache/sysml/api/mlcontext/Script.java
@@ -319,6 +319,13 @@ public class Script {
         * @return {@code this} Script object to allow chaining of methods
         */
        public Script in(String name, Object value, Metadata metadata) {
+
+               if ((value != null) && (value instanceof Long)) {
+                       // convert Long to Integer since Long not a supported 
value type
+                       Long lng = (Long) value;
+                       value = lng.intValue();
+               }
+
                MLContextUtil.checkInputValueType(name, value);
                if (inputs == null) {
                        inputs = new LinkedHashMap<String, Object>();

http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/6815cd9b/src/test/java/org/apache/sysml/test/integration/mlcontext/MLContextTest.java
----------------------------------------------------------------------
diff --git 
a/src/test/java/org/apache/sysml/test/integration/mlcontext/MLContextTest.java 
b/src/test/java/org/apache/sysml/test/integration/mlcontext/MLContextTest.java
index 06e6768..89241c5 100644
--- 
a/src/test/java/org/apache/sysml/test/integration/mlcontext/MLContextTest.java
+++ 
b/src/test/java/org/apache/sysml/test/integration/mlcontext/MLContextTest.java
@@ -2507,6 +2507,26 @@ public class MLContextTest extends AutomatedTestBase {
                ml.execute(script);
        }
 
+       @Test
+       public void testInputVariablesAddLongsDML() {
+               System.out.println("MLContextTest - input variables add longs 
DML");
+
+               String s = "print('x + y = ' + (x + y));";
+               Script script = dml(s).in("x", 3L).in("y", 4L);
+               setExpectedStdOut("x + y = 7");
+               ml.execute(script);
+       }
+
+       @Test
+       public void testInputVariablesAddLongsPYDML() {
+               System.out.println("MLContextTest - input variables add longs 
PYDML");
+
+               String s = "print('x + y = ' + (x + y))";
+               Script script = pydml(s).in("x", 3L).in("y", 4L);
+               setExpectedStdOut("x + y = 7");
+               ml.execute(script);
+       }
+
        // NOTE: Uncomment these tests once they work
 
        // @SuppressWarnings({ "rawtypes", "unchecked" })

Reply via email to