Uploaded image for project: 'SystemDS'
  1. SystemDS
  2. SYSTEMDS-590

Improve Namespace Handling for UDFs

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Major
    • Resolution: Fixed
    • SystemML 0.10
    • SystemML 0.10
    • Parser
    • None

    Description

      Currently, if a UDF body involves calling another UDF, the default global namespace is assumed, unless a namespace is explicitly indicated. This becomes a problem when a file contains UDFs, and is then sourced from another script.

      Imagine a file funcs.dml as follows:

      f = function(double x, int a) return (double ans) {
        x2 = g(x)
        ans = a * x2
      }
      
      g = function(double x) return (double ans) {
        ans = x * x
      }
      

      Then, let's try to call f:

      script = """
      source ("funcs.dml") as funcs
      
      ans = funcs::f(3, 1)
      print(ans)
      """
      ml.reset()
      ml.executeScript(script)
      

      This results in an error since f is in the funcs namespace, but the call to g assumes g is still in the default namespace. Clearly, the user intends to the use the g that is located in the same file.

      Currently, we would need to adjust funcs.dml as follows to explicitly assume that f and g are in a funcs namespace:

      f = function(double x, int a) return (double ans) {
        x2 = funcs::g(x)
        ans = a * x2
      }
      
      g = function(double x) return (double ans) {
        ans = x * x
      }
      

      Instead, it would be better to simply first look for g in its parent's namespace. In this case, the "parent" would be the function f, and the namespace we have selected is funcs, although that choice would be left up to the end-user. Then, namespace assumptions would not be necessary.

      Attachments

        Issue Links

          Activity

            People

              gweidner Glenn Weidner
              dusenberrymw Mike Dusenberry
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: