[Rcpp-devel] trying installing RcppCNPy with -std=c++11 (or c++0x) and failed due to incompatible number of arguments

Gong-Yi Liao gongyi.liao at gmail.com
Wed Feb 20 18:38:35 CET 2013


It seems that we still need to add "#define RCPP_HAS_LONG_LONG_TYPES " 
to cnpy.hotherwise it won't work, even the argument 'type' has been 
specified while using npyLoad

Gong.


On 02/20/2013 12:32 PM, Gong-Yi Liao wrote:
> Oh, I found it's my own fault, actually I just needed to use the 
> 'type' argument, while specify
> npyLoad('test.npy', type='integer'), the data are loaded correctly:
>
> === in R 2.15.2 ============
>
> R> npyLoad(type='integer', 'test.npy')
> loading int64 from .npy
>  [1] 103  89 114 122  81  98  89 114  88  83
>
> ========================
>
> Gong.
>
> On 02/20/2013 12:26 PM, Gong-Yi Liao wrote:
>> It seems that we have something to do with type detection, I put some 
>> console output code to see what type  of data are detected while 
>> being loaded.
>>
>> In cnpy.h, I add:
>>
>> ===== cnpy.h ===============
>>
>> + #define RCPP_HAS_LONG_LONG_TYPES
>> #ifdef RCPP_HAS_LONG_LONG_TYPES
>> #include <cstdint>        // for std::int64_t, needs c++11 switch
>> #endif
>> ============================
>>
>> in cnpyMod.cpp: I sightly modified npyLoad function: (between line 61 
>> to 71)
>>
>> === cnpyMod.cpp ===================
>>
>>     if (shape.size() == 1) {
>>         if (type == "numeric") {
>> +           std::cout << "loading numeric (double) from .npy" << 
>> std::endl;
>>             double *p = reinterpret_cast<double*>(arr.data);
>>             ret = Rcpp::NumericVector(p, p + shape[0]);
>> #ifdef RCPP_HAS_LONG_LONG_TYPES
>>         } else if (type == "integer") {
>> +           std::cout << "loading int64 from .npy" << std::endl;
>>             int64_t *p = reinterpret_cast<int64_t*>(arr.data);
>>             ret = Rcpp::IntegerVector(p, p + shape[0]);
>> #endif
>>         } else {
>>             arr.destruct();
>>             Rf_error("Unsupported type in npyLoad");
>>         }
>> ===================================
>>
>> In python, I generated the data:
>>
>> ==== in IPython 0.13 ==============
>>
>> In [3]: save('test.npy', poisson(100,10))
>>
>> ===================================
>>
>> In R, loaded data and found:
>>
>> ===== In R 2.15.2 =================
>>
>> R> library(RcppCNPy); npyLoad('test.npy');quit('yes')
>> Loading required package: Rcpp
>> loading numeric (double) from .npy
>>  [1] 5.088876152e-322 4.397184248e-322 5.632348363e-322 
>> 6.027600879e-322 4.001931731e-322 4.841843329e-322 4.397184248e-322 
>> 5.632348363e-322 4.347777683e-322
>> [10] 4.100744860e-322
>>
>> =================================
>>
>> It seems that problem is data type detection, could that be caused by 
>> R itself? I think Rcpp and RcppCNPy are constrained by R's limitation.
>>
>> Gong.
>>
>> On 02/20/2013 07:35 AM, Dirk Eddelbuettel wrote:
>>> Gong-Yi,
>>>
>>> On 19 February 2013 at 19:15, Dirk Eddelbuettel wrote:
>>> | I'll commit a fix in a bit.
>>>
>>> There is now a candidate package 0.2.0.1 at the R-Forge page (or in 
>>> SVN)
>>
>>> https://r-forge.r-project.org/R/?group_id=155
>>>
>>> Could you test that against your integer data and report back?
>>>
>>> Thanks,  Dirk
>>>
>>
>>
>
>


-- 
Gong-Yi Liao
Department of Statistics
University of Connecticut



More information about the Rcpp-devel mailing list