Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[aurelius] assigning whole number to a variable of type double #47

Open
taunometsalu opened this issue Dec 19, 2017 · 0 comments
Open

Comments

@taunometsalu
Copy link

If I try to assign a constant whole number to a variable of type double, it works with Titus:

library(aurelius)
pfaDocument = pfa_document(
  input = avro_array(avro_double),
  output = avro_array(avro_double),
  action = expression(
    out <- input,
    out[0] <- 5.0,
    out
  )
)

library(jsonlite)
engine = pfa_engine(pfaDocument)
x = 1:2
engine$action(x)

But it gives error 'Assignment conversion not possible from type "int" to type "java.lang.Double"' in Hadrian:

f = "/usr/local/src/gdrive/results/pfa/int_as_double_example_error1.pfa"
write_pfa(pfaDocument, file = f, pretty = TRUE)
library(jsonlite)
tmp1 = tempfile(fileext = ".json")
tmp2 = tempfile(fileext = ".json")
write(minify(toJSON(x, auto_unbox = TRUE)), file = tmp1)
cmd = paste0("cd /usr/local/src/gdrive/; touch ", tmp2, "; ",
             "java -jar scripts/hadrian/hadrian-standalone-0.8.1-jar-with-dependencies.jar -i json -o json ",
             f, " ", tmp1, " > ", tmp2)
system(cmd)

PFA file:

{
  "input": {
    "type": "array",
    "items": "double"
  },
  "output": {
    "type": "array",
    "items": "double"
  },
  "action": [
    {
      "let": {
        "out": "input"
      }
    },
    {
      "do": [
        {
          "let": {
            "tmp_7": 5
          }
        },
        {
          "set": {
            "out": {
              "attr": "out",
              "path": [
                0
              ],
              "to": "tmp_7"
            }
          }
        },
        "tmp_7"
      ]
    },
    "out"
  ]
}

I tried to use always_decimal parameter, but then it gives another error 'path index for an array must resolve to a long or int; item 0 is a "double"' because the path index in out[0] is also converted to double.

f = "/usr/local/src/gdrive/results/pfa/int_as_double_example_error2.pfa"
write_pfa(pfaDocument, file = f, pretty = TRUE, always_decimal = TRUE)
library(jsonlite)
tmp1 = tempfile(fileext = ".json")
tmp2 = tempfile(fileext = ".json")
write(minify(toJSON(x, auto_unbox = TRUE)), file = tmp1)
cmd = paste0("cd /usr/local/src/gdrive/; touch ", tmp2, "; ",
             "java -jar scripts/hadrian/hadrian-standalone-0.8.1-jar-with-dependencies.jar -i json -o json ",
             f, " ", tmp1, " > ", tmp2)
system(cmd)

PFA file:

{
  "input": {
    "type": "array",
    "items": "double"
  },
  "output": {
    "type": "array",
    "items": "double"
  },
  "action": [
    {
      "let": {
        "out": "input"
      }
    },
    {
      "do": [
        {
          "let": {
            "tmp_7": 5.0
          }
        },
        {
          "set": {
            "out": {
              "attr": "out",
              "path": [
                0.0
              ],
              "to": "tmp_7"
            }
          }
        },
        "tmp_7"
      ]
    },
    "out"
  ]
}

How can I force aurelius to use always_decimal only in the places where required?

The only workaround I see at the moment is to manually change the exported .pfa file (make sure that 0 is printed as 0 and 5 as 5.0).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant