xtensor-stack / xtensor-r

R bindings for xtensor
BSD 3-Clause "New" or "Revised" License
87 stars 15 forks source link

Minimal working examples for xtensor-r #51

Open deanbodenham opened 6 years ago

deanbodenham commented 6 years ago

Dear xtensor maintainers,

I recently discovered your xtensor library, and it looks great. I have been trying to get started with it either in C++ or with the associated R package, but unfortunately have not had any success in getting minimal examples to work. I was wondering if you could suggest where I might be missing a step, or if you could provide some minimal working examples.

I have some experience using Rcpp and RcppArmadillo, and my first goal was to use xtensor with R.

However, after installing the 'xtensor' R package, the example on your GitHub page

library('xtensor')
xtensor::rcpp_hello_xtensor(4:12)

failed to work and resulted in the error: Error: 'rcpp_hello_xtensor' is not an exported object from 'namespace:xtensor'

I looked at your xtensor_r_example() in the documentation for version 0.6.1-0 on CRAN, but could not get that to work without knowing how to define the tensor.

I then tried the sum_of_sines example on your page (within a package framework): http://xtensor-r.readthedocs.io/en/latest/basic_usage.html

but this resulted in the errors:

clang++ -std=gnu++14 -I"/usr/local/Cellar/r/3.5.0_1/lib/R/include" -DNDEBUG  -I"/Users/dean/build/rpackages/Rcpp/include" -I/usr/local/opt/gettext/include -I/usr/local/opt/readline/include -I/usr/local/include   -fPIC  -g -O2 -c RcppExports.cpp -o RcppExports.o
RcppExports.cpp:9:21: error: use of undeclared identifier 'xt'
double sum_of_sines(xt::rarray<double>& m);
                    ^
RcppExports.cpp:9:38: error: expected '(' for function-style cast or type construction
double sum_of_sines(xt::rarray<double>& m);
                               ~~~~~~^
RcppExports.cpp:9:41: error: use of undeclared identifier 'm'
double sum_of_sines(xt::rarray<double>& m);
                                        ^
RcppExports.cpp:14:36: error: use of undeclared identifier 'xt'
    Rcpp::traits::input_parameter< xt::rarray<double>& >::type m(mSEXP);
                                   ^
RcppExports.cpp:14:53: error: expected '(' for function-style cast or type construction
    Rcpp::traits::input_parameter< xt::rarray<double>& >::type m(mSEXP);
                                              ~~~~~~^
RcppExports.cpp:14:56: error: expected unqualified-id
    Rcpp::traits::input_parameter< xt::rarray<double>& >::type m(mSEXP);
                                                       ^
RcppExports.cpp:15:47: error: use of undeclared identifier 'm'
    rcpp_result_gen = Rcpp::wrap(sum_of_sines(m));
                                              ^
7 errors generated.
make: *** [RcppExports.o] Error 1
ERROR: compilation failed for package ‘tryxtensor’
* removing ‘/private/var/folders/5z/g039vypd3d78dm1hr5bwmsk00000gn/T/RtmpGnd8U7/devtools_install_12e97786f506d/tryxtensor’
Error: Command failed (1)

Before I had tried including the line

SystemRequirements: C++14

in the description file, but this did not change the error messages. The above output is after creating a Makevars file containing CXX1XSTD = -std=gnu++14

I am using Rcpp v0.12.7 (latest release).

After this, I tried to simply get a pure C++ example to work (no R). I am using OSX, and then tried installing xtensor with 'conda', as suggested on your page. I then tried the first example (after enclosing in a main) on http://xtensor.readthedocs.io/en/latest/basic_usage.html

however, this resulted in numerous error messages. I tried compiling with the standard gcc/g++ compilers on OSX, as well as with the gcc-4.9/g++-4.9 compilers.

After the conda version of xtensor was installed, I tried the xtensor-r examples again, but still received the same error messages.

I apologise for the long post, but I wanted to detail the steps I tried. It seems that R/gcc is not finding the xtensor header files. Any suggestions for fixing this issue, or any minimal working examples for R, would be greatly appreciated.

wolfv commented 5 years ago

Hi!

Sorry for the super-late reply. This is a pretty helpful gist:

https://gist.github.com/DavisVaughan/6597eac027303443bd69809b74646372

We're going to improve the docs at some point in the future but for now we're quite swamped with work.