johnmchambers / XRJulia

XR-style Interface to Julia (from "Extending R")
33 stars 2 forks source link

Long arrays wrongly converted from Julia to R #20

Open oliviaAB opened 5 years ago

oliviaAB commented 5 years ago

Hi,

I noticed a strange problem when playing with long arrays and passing them from R to Julia. When creating arrays of length <1000, no problem:

m = juliaEval("[i for i in 1:999]")
juliaGet(m)

returns:

  [1]   1   2   3   4   5   6   7   8   9  10  11  12  13  14  15  16  17  18  19  20  21  22  23  24  25  26  27  28  29  30  31  32  33
 [34]  34  35  36  37  38  39  40  41  42  43  44  45  46  47  48  49  50  51  52  53  54  55  56  57  58  59  60  61  62  63  64  65  66
... 
[991] 991 992 993 994 995 996 997 998 999

However, if the array length exceeds 1001, the value returned to R is as follow:

m = juliaEval("[i for i in 1:1001]")
juliaGet(m)
  [1]   1   0   2   0   3   0   4   0   5   0   6   0   7   0   8   0   9   0  10   0  11   0  12   0  13   0  14   0  15   0  16   0  17
  [34]   0  18   0  19   0  20   0  21   0  22   0  23   0  24   0  25   0  26   0  27   0  28   0  29   0  30   0  31   0  32   0  33   0
  ...
 [991] 496   0 497   0 498   0 499   0 500   0 501

Zeros are inserted between the values of the array that Julia returns. Is there any way to correct that?

Thank you very much!

Olivia

johnmchambers commented 5 years ago

Works OK for me with the CRAN version of the package, running under MacOSX 10.12:

x2 = juliaEval("[i for i in 1:1001]") juliaGet(x2) [1] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 [16] 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 ...

oliviaAB commented 5 years ago

From sessionInfo() I have the version XRJulia_0.7.9. I used the Github version rather than the CRAN version to avoid the problem caused by RJulia() when you specify the port ID to use. I'll try to re-install it.

EDIT: I re-installed the version 0.7.8 (the CRAN version being 0.7.7 if I'm not wrong), and the problem was solved! Thank you for answering so quickly.

johnmchambers commented 5 years ago

You're right though. It's a bug introduced in the modifications for 0.7.9. I'll try to track it down, but not for a few days.

Thanks for the report.

johnmchambers commented 5 years ago

Turned out to be an easy fix; for the new fast transfer of data, the Julia side needs to convert Int64 arrays to Int32 before writing.

Also incremented the version number and added a draft vignette on data transfer.

Anyone reading this, please try out transferring long(er) arrays, which should now be much faster.