systemml-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] [systemml] raymondtay opened a new pull request #868: [SYSTEMML-2537] Improve the consistency of predicates in "if-then-else" expressions
Date Wed, 25 Mar 2020 01:12:28 GMT
raymondtay opened a new pull request #868: [SYSTEMML-2537] Improve the consistency of predicates
in "if-then-else" expressions
URL: https://github.com/apache/systemml/pull/868
 
 
   The original issue i noticed was when the conditional predicate in the if-expression didn't
seem what i was used to as in the C-programming language (where negative values were interpreted
as _false_ while the converse values were interpreted as _true_) and that caused some discomfort.
   
   Below is an example of the issue
   ```
   // This is a session i ran from running SystemML
   scala> import org.apache.sysml.api.mlcontext._
   scala> import org.apache.sysml.api.mlcontext.ScriptFactory._
   scala> val ml = new MLContext(spark)
   scala> val s = dml(""" if(-42) print("Yes!") else print("No!") """)
   scala> ml.execute(s)
   Yes!
   ```
   In the Scala programming language, this would be a type-error
   ```
   scala> if (-31) println("yes") else println("no")
              ^
          error: type mismatch;
           found   : Int(-31)
           required: Boolean
   ```
   
   So i started mucking around _Antlr4_ and start poking around and discovered a potential
fix for it. Running this fix after a build on my local machine, here's the desired result:
   ```
   Using Scala version 2.11.12 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_202)
   Type in expressions to have them evaluated.
   Type :help for more information.
   
   scala> import org.apache.sysml.api.mlcontext._
   import org.apache.sysml.api.mlcontext._
   
   scala> import org.apache.sysml.api.mlcontext.ScriptFactory._
   import org.apache.sysml.api.mlcontext.ScriptFactory._
   
   scala> val ml = new MLContext(spark)
   
   Welcome to Apache SystemML!
   Version 1.3.0-SNAPSHOT
   ml: org.apache.sysml.api.mlcontext.MLContext = org.apache.sysml.api.mlcontext.MLContext@380cd266
   
   scala> val s = dml(""" if(-42) print("Yes!") else print("No!") """)
   s: org.apache.sysml.api.mlcontext.Script =
   Inputs:
   None
   
   Outputs:
   None
   
   scala> ml.execute(s)
   ANTLR Tool version 4.5.3 used for code generation does not match the current runtime version
4.7ANTLR Runtime version 4.5.3 used for parser compilation does not match the current runtime
version 4.7ANTLR Tool version 4.5.3 used for code generation does not match the current runtime
version 4.7ANTLR Runtime version 4.5.3 used for parser compilation does not match the current
runtime version 4.720/03/25 09:10:54 WARN DMLTranslator: WARNING: [line 1:4] -> -42 --
Numerical value '-42' (!= 0/1) is converted to boolean FALSE by DML
   No!
   SystemML Statistics:
   Total execution time:		0.010 sec.
   Number of executed Spark inst:	0.
   
   res0: org.apache.sysml.api.mlcontext.MLResults =
   None
   
   ```

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

Mime
View raw message