Before diving into RcppCNPy, I played with 'int64' package for a while
and find some interesting things:
date file:
== test.csv====
"id", "value"
1,9223372036854775807
2,9223372036854775806
-----------------------------
You can see that these two values, one the maximum of int64, another is
the maximum -1
=== In R ==========
R> library(int64)
R> dat1 <- read.csv("test.csv")
Warning message:
In read.table(file = file, header = header, sep = sep, quote = quote, :
incomplete final line found by readTableHeader on 'test.csv'
R> dat1
id value
1 1 9.223372037e+18
2 2 9.223372037e+18
R> dat1$value
[1] 9.223372037e+18 9.223372037e+18
R> as.character(dat1$value)
[1] "9223372036854775808" "9223372036854775808"
R> as.int64(as.character(dat1$value))
[1] NA NA
-------------------------------------------------------
I don't know why R convert the number to "9223372036854775808" (and of
course 'as.int64' will give us 'NA's)
Gong.
On 02/20/2013 08:20 AM, Dirk Eddelbuettel wrote:
Good. Love that can help test, which is why I didn't upload.
On 20 February 2013 at 07:49, Gong-Yi Liao wrote:
| I have build the updated RppCNPy package (0.2.0.1) and load it in R
| 3.0.0 (which supports long double and may be long long int) and R 2.15.2
I have an r-devel build here too.
But you misunderstand: R 3.0.0 uses double for indices, hence "larger". R
still only knows "integer" and "numeric", effectively int and double.
I am just about to head to work and cannot look at this all that closely. I
think we need to proceed in stages
i) save data from Python (you're there)
ii) read it in RcppCNPy at the C++ level, make sure values are correct
iii) make sure dim + orientation is correct (col major vs row major,
sometimes we need to transpose
iv) cast as needed to get values to R
The case may mean a lossy cast to integer, or a promotion to numeric. We
have to think about this.
Likewise we have to test i) to iv) the other way around from R to Python.
Thanks!
Dirk
| , npyLoad now can load data without the 'BigEndian' problem but with
| another even weirder problem:
|
| ## Case 1:
| === In Python =====
| [1]: save('test.npy', pylab.poisson(lam=5.6, size=10))
|
| == In R 3.0.0. ======
| R> npyLoad('test.npy')
| [1] 1.976262583e-323 1.482196938e-323 1.482196938e-323
| 9.881312917e-324 0.000000000e+00 1.482196938e-323 4.940656458e-324
| 2.964393875e-323 1.482196938e-323
|
| ## Case 2:
| === In Python =========
| In [12]: save('test.npy', [numpy.int(x) for x in poisson(3.5, 10)])
|
| == In R 3.0.0 ==========
| R> npyLoad('test.npy')
| [1] 9.881312917e-324 1.976262583e-323 2.470328229e-323
| 1.482196938e-323 3.458459521e-323 1.482196938e-323 9.881312917e-324
| 2.964393875e-323 1.976262583e-323
| [10] 9.881312917e-324
|
| Case 3:
| == In Python ========
| In [13]: save('test.npy', [double(x) for x in poisson(3.5, 10)])
|
| == In R ===========
| R> npyLoad('test.npy')
| [1] 4 8 4 4 5 2 3 5 5 3
|
| It seems that something needs to be modified in R that we can load some
| int64 type data. I am not sure if the orphaned 'int64' package can help,
| because in the first case, I have tested:
|
| R> as.int64(npyLoad('test.npy')[1])
| [1] 0
|
| Gong.
|
|
|
|
|
|
|
| On 02/19/2013 08:15 PM, Dirk Eddelbuettel wrote:
| > Good news, got to look at this on train commute home. It is plainly my
| > error. And a fix (of just adding #define R_NO_REMAP before #include'ing
| > Rinternals.h) will be forthcoming. The "length" gave it away.
| >
| > You can also simply not #include<iomanip> and the error is also avoided.
| >
| > I'll commit a fix in a bit.
| >
| > Dirk
| >
|
|
| --
| Gong-Yi Liao
| Department of Statistics
| University of Connecticut
|
--
Gong-Yi Liao
Department of Statistics
University of Connecticut
--
Gong-Yi Liao
Department of Statistics
University of Connecticut
_______________________________________________
Rcpp-devel mailing list
Rcpp-devel@lists.r-forge.r-project.org
https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel