[Rcpp-devel] RcppArmadillo error

Douglas Bates bates at stat.wisc.edu
Wed Mar 31 15:25:14 CEST 2010


On Tue, Mar 30, 2010 at 9:12 AM, Romain Francois
<romain at r-enthusiasts.com> wrote:
> Le 30/03/10 15:36, Douglas Bates a écrit :
>> On Tue, Mar 30, 2010 at 1:15 AM, Romain Francois
>> <romain at r-enthusiasts.com>  wrote:
>>> Hi,
>>
>>> If you want to compile the code that is here
>>> http://dirk.eddelbuettel.com/code/rcpp.armadillo.html directly from R
>>> CMD SHLIB, you can do this:
>>
>>> romain at naxos /tmp $ export PKG_CXXFLAGS=`Rscript -e
>>> "RcppArmadillo:::CxxFlags()"`
>>> romain at naxos /tmp $ export PKG_LIBS=`Rscript -e "RcppArmadillo:::LdFlags()"`
>>> romain at naxos /tmp $ R CMD SHLIB armaex.cpp
>>
>> The way that RcppArmadillo:::LdFlags() is currently defined there is a
>> possibility of getting different Lapack and BLAS libraries when using
>> R or calls to RcppArmadillo.  R uses the libraries defined by the
>> macros LAPACK_LIBS, BLAS_LIBS and FLIBS in the file
>>
>> file.path(R.home("etc"), "Makeconf")  # evaluate this in R
>>
>> It is not certain that those will be the same as the libraries used by
>> Armadillo.  If they are not shared objects you run the risk of getting
>> two copies of Lapack, etc.  and possibly different BLAS, leading to
>> different performance characteristics and perhaps different results.
>
> Hmmm. Interesting. I did not think of that problem.
>
> On my machine, I have :
>
> Rscript -e "RcppArmadillo:::LdFlags()"
> /Library/Frameworks/R.framework/Resources/library/Rcpp/lib/x86_64/libRcpp.a
> -L/usr/lib -larmadillo
>
> so linking against Rcpp "user" library and armadillo... but when I
> manually set PKG_LIBS to just Rcpp user library, it still works, so we
> actually do not need to link against armadillo library. armadillo itself
> does not __need__ to get compiled into a library because it is all
> templates.

I'm pretty sure that Dirk's FastLM test would fail if you did not link
to -larmadillo library (and thence to -llapack and -lblas).  Dirk uses
things like an inv method for a matrix and that will eventually call
Lapack routines.

I haven't looked at the code for Armadillo but I did check that the
armadillo library links to the lapack and blas libraries.

$ ldd /usr/lib/libarmadillo.so
	linux-vdso.so.1 =>  (0x00007fffaf7ff000)
	libblas.so.3gf => /usr/lib/libblas.so.3gf (0x00007f01e5593000)
	liblapack.so.3gf => /usr/lib/liblapack.so.3gf (0x00007f01e49a0000)
	libstdc++.so.6 => /usr/lib/libstdc++.so.6 (0x00007f01e468f000)
	libm.so.6 => /lib/libm.so.6 (0x00007f01e440b000)
	libgcc_s.so.1 => /lib/libgcc_s.so.1 (0x00007f01e41f4000)
	libc.so.6 => /lib/libc.so.6 (0x00007f01e3e84000)
	libgfortran.so.3 => /usr/lib/libgfortran.so.3 (0x00007f01e3b98000)
	/lib64/ld-linux-x86-64.so.2 (0x00007f01e5a41000)

>>> I would however strongly recommend you to have this in a package.
>>>
>>> Romain
>>>
>>> Le 26/03/10 19:00, Abhisek a écrit :
>>>> Hi Dirk,
>>>>
>>>> I was referring to this page:
>>>> http://dirk.eddelbuettel.com/code/rcpp.armadillo.html
>>>> i was trying to run the code there.
>>>>
>>>> here is my understanding so far (im new to linux and c++ so i apologize
>>>> for seeming rather slow!):
>>>> 1.  The Rcpp package helps C++ and R recognize each others stuff (like
>>>> variables).
>>>>
>>>> 2. The RcppArmadillo package extends this functionality to objects used
>>>> in armadillo (such as matrices and vectors e.g. colvec).
>>>>
>>>> 3. In FastLM, armadillo is being included but not RcppArmadillo.  but
>>>> that is ok because there is a loop in there which converts an vector as
>>>> defined in armadillo to one which Rcpp recognizes.  And it is this
>>>> vector which which gets passed back to R through the Rcpp interface.
>>>> also, it uses cfunction which is different from what im doing here as i
>>>> think you mentioned earlier (it worked by the way!)
>>>>
>>>> what i tried to do was as follows:
>>>> a) to run the code as in the link above and include Rcpp and
>>>> RcppArmadillo and I was getting the errors as described in my initial post.
>>>> b) then i tried the same code but only including Rcpp and armadillo.
>>>>
>>>> if my reasoning above is correct, part (b) should not run as Rcpp would
>>>> not recognize stuff like arma::colvec.  but, i get the exact same error
>>>> as above!
>>>>
>>>> so that suggests, that while compiling the code, the compiler is not
>>>> even getting to the point in procedure b when it should encounters an
>>>> type it doesnt recognize.  which means that somehow, armadillo is giving
>>>> problems.  but that is as far as i can understand.  either that or my
>>>> understanding is way off.
>>>>
>>>> appreciate your patience and help!
>>>> abhisek
>>>>
>>>>
>>>>
>>>> On Fri, Mar 26, 2010 at 4:20 PM, Dirk Eddelbuettel<edd at debian.org
>>>> <mailto:edd at debian.org>>  wrote:
>>>>
>>>>
>>>>      On 26 March 2010 at 15:32, Abhisek wrote:
>>>>      | Hi Dirk,
>>>>      |
>>>>      | Just so that I understand.  I copied the code in the RcppArmadillo
>>>>      section
>>>>      | on your website and pasted and saved it.
>>>>
>>>>      What code? What page?
>>>>
>>>>      | Are you saying I should change
>>>>      | #include<RcppArmadillo>  to #include<Rcpp>  and #include<armadillo>  ?
>>>>
>>>>      No that is not what I said.  I said
>>>>
>>>>          You can't just look at FastLM() and think your code will run
>>>>      like it.
>>>>          RcppArmadillo __does not export its classes__.  It is an
>>>>      implementation
>>>>          reference -- it gives you guidance as to how to implement C++
>>>>      packages of
>>>>          your own against other libraries.
>>>>
>>>>          If you "just" want to use Armadillo and have Rcpp help you, look
>>>>      at the
>>>>          installed example 'FastLM' in the Rcpp package.  In other words
>>>>      ignore
>>>>          RcppArmadillo for now.
>>>>
>>>>      So look at /usr/local/lib/Rcpp/examples/FastLM/ and the files there.
>>>>        Run
>>>>
>>>>          fastLMviaArmadillo.r
>>>>
>>>>      and look at it. That should work.
>>>>
>>>>      You can also look at the _entire RcppArmadillo package_ and see how the
>>>>      pieces fit together, including src/Makevars.
>>>>
>>>>      But don't just take semi-random shortcuts and expect that to work. If we
>>>>      could make it any simpler, we would.  There is a reason RcppArmadilli is
>>>>      package and not just a file.
>>>>
>>>>      Dirk
>>>>
>>>>      | best,
>>>>      | abhisek
>>>>      |
>>>>      | On Fri, Mar 26, 2010 at 1:40 PM, Dirk Eddelbuettel<edd at debian.org
>>>>      <mailto:edd at debian.org>>  wrote:
>>>>      |
>>>>      |>
>>>>      |>  Hi Abhisek,
>>>>      |>
>>>>      |>  On 26 March 2010 at 12:28, Abhisek wrote:
>>>>      |>  | I downloaded the stuff just last friday so it should be the latest
>>>>      |>  version
>>>>      |>  | of Rcpp as well as Armadillo.  I used install.packages() for
>>>>      Rcpp and
>>>>      |>  | RcppArmadillo.  Armadillo is 0.9.4.  Im using xubuntu karmic
>>>>      koala.
>>>>      |>
>>>>      |>  Ok, that is all good.  And if RcppArmadillo installed you have
>>>>      proper
>>>>      |>  libraries, Armadillo included.
>>>>      |>
>>>>      |>  I think part of your problem is a misunderstanding of an issue
>>>>      we may not
>>>>      |>  have made particularly clear:  You can't just look at FastLM()
>>>>      and think
>>>>      |>  your code will run like it.  RcppArmadillo __does not export its
>>>>      classes__.
>>>>      |>  It is an implementation reference -- it gives you guidance as to
>>>>      how to
>>>>      |>  implement C++ packages of your own against other libraries.
>>>>      |>
>>>>      |>  If you "just" want to use Armadillo and have Rcpp help you, look
>>>>      at the
>>>>      |>  installed example 'FastLM' in the Rcpp package.  In other words
>>>>      ignore
>>>>      |>  RcppArmadillo for now.
>>>>      |>
>>>>      |>  The example (in 0.7.10) uses an idiom we no longer like and I am
>>>>      about to
>>>>      |>  change that for an upcoming 0.7.11 release, but it should works
>>>>      as is and
>>>>      |>  just use inline -- so no messing with makefile etc.
>>>>      |>
>>>>      |>  Try that and see how it goes and keep us posted.
>>>>      |>
>>>>      |>  Cheers, Dirk
>>>>      |>
>>>>      |>
>>>>      |>  | i also had some problem using Armadillo which I posted on the
>>>>      Armadillo
>>>>      |>  | discussion board.  Conrad got back to me.  Here is the discussion:
>>>>      |>  | https://sourceforge.net/apps/phpbb/arma/viewtopic.php?f=1&t=4
>>>>      <https://sourceforge.net/apps/phpbb/arma/viewtopic.php?f=1&t=4>
>>>>      |>  |
>>>>      |>  | so it may be that armadillo is the problem but im really not sure.
>>>>      |>  |
>>>>      |>  | Many thanks
>>>>      |>  | Abhisek
>>>>      |>  |
>>>>      |>  | On Fri, Mar 26, 2010 at 12:17 PM, Dirk Eddelbuettel
>>>>      <edd at debian.org<mailto:edd at debian.org>>
>>>>      |>  wrote:
>>>>      |>  |
>>>>      |>  |>
>>>>      |>  |>  (resending, this time to list I omitted last time, sorry.
>>>>      --Dirk)
>>>>      |>  |>
>>>>      |>  |>  On 26 March 2010 at 11:10, Abhisek wrote:
>>>>      |>  |>  | Hi,
>>>>      |>  |>  |
>>>>      |>  |>  | Ive been trying to make RcppArmadillo work using the
>>>>      example file
>>>>      |>  |>  (fastLM).
>>>>      |>  |>  | I copied and pasted the code and saved it as
>>>>      RcppArmadilloEg.cpp (not
>>>>      |>  to
>>>>      |>  |>  use
>>>>      |>  |>  | fastLM but to figure out how to work RcppArmadillo).  Then
>>>>      i tried
>>>>      |>  using
>>>>      |>  |>  the
>>>>      |>  |>  | command R CMD SHLIB RcppArmadilloEg.cpp but an error came
>>>>      up saying
>>>>      |>  that
>>>>      |>  |>  | RcppArmadillo.h not found.
>>>>      |>  |>  |
>>>>      |>  |>  | So i tried doing a symbolic link from /usr/local/include
>>>>      to the
>>>>      |>  directory
>>>>      |>  |>  | where RcppArmadillo.h and RcppArmadilloDefines.h is
>>>>      stored.  I also
>>>>      |>  did a
>>>>      |>  |>  | symbolic link analogously for RcppArmadillo.so.  When i
>>>>      ran R CMD
>>>>      |>  SHLIB
>>>>      |>  |>  | again I got the following error:
>>>>      |>  |>  |
>>>>      |>  |>  | abhisek at shieks:~/Desktop/Personal/Test$ R CMD SHLIB
>>>>      |>  RcppArmadilloEg.cpp
>>>>      |>  |>  | g++ -I/usr/share/R/include
>>>>      |>  |>  | -I/home/abhisek/R/i486-pc-linux-gnu-library/2.10/Rcpp/lib
>>>>      -fpic  -g
>>>>      |>  -O2
>>>>      |>  |>  -c
>>>>      |>  |>  | RcppArmadilloEg.cpp -o RcppArmadilloEg.o
>>>>      |>  |>
>>>>      |>  |>  So far so good:  one -I for R as usual, one for Rcpp.
>>>>      |>  |>
>>>>      |>  |>  | In file included from
>>>>      |>  |>  |
>>>>      |>
>>>>      /home/abhisek/R/i486-pc-linux-gnu-library/2.10/Rcpp/lib/RcppCommon.h:215,
>>>>      |>  |>  |                  from
>>>>      |>  |>  |
>>>>      /home/abhisek/R/i486-pc-linux-gnu-library/2.10/Rcpp/lib/Rcpp.h:28,
>>>>      |>  |>  |                  from RcppArmadilloEg.cpp:1:
>>>>      |>  |>  |
>>>>      |>  |>
>>>>      |>
>>>>      /home/abhisek/R/i486-pc-linux-gnu-library/2.10/Rcpp/lib/Rcpp/internal/wrap.h:
>>>>      |>  |>  | In function ‘SEXPREC*
>>>>      |>  |>  Rcpp::internal::wrap_dispatch_unknown_iterable(const
>>>>      |>  |>  | T&, Rcpp::traits::false_type) [with T = arma::Col<double>]’:
>>>>      |>  |>  |
>>>>      |>  |>
>>>>      |>
>>>>      /home/abhisek/R/i486-pc-linux-gnu-library/2.10/Rcpp/lib/Rcpp/internal/wrap.h:491:
>>>>      |>  |>  | instantiated from ‘SEXPREC*
>>>>      |>  Rcpp::internal::wrap_dispatch_unknown(const
>>>>      |>  |>  T&,
>>>>      |>  |>  | Rcpp::traits::false_type) [with T = arma::Col<double>]’
>>>>      |>  |>  |
>>>>      |>  |>
>>>>      |>
>>>>      /home/abhisek/R/i486-pc-linux-gnu-library/2.10/Rcpp/lib/Rcpp/internal/wrap.h:509:
>>>>      |>  |>  | instantiated from ‘SEXPREC*
>>>>      |>  |>  | Rcpp::internal::wrap_dispatch_unknown_importable(const T&,
>>>>      |>  |>  | Rcpp::traits::false_type) [with T = arma::Col<double>]’
>>>>      |>  |>  |
>>>>      |>  |>
>>>>      |>
>>>>      /home/abhisek/R/i486-pc-linux-gnu-library/2.10/Rcpp/lib/Rcpp/internal/wrap.h:526:
>>>>      |>  |>  | instantiated from ‘SEXPREC*
>>>>      Rcpp::internal::wrap_dispatch(const T&,
>>>>      |>  |>  | Rcpp::traits::wrap_type_unknown_tag) [with T =
>>>>      arma::Col<double>]’
>>>>      |>  |>  |
>>>>      |>  |>
>>>>      |>
>>>>      /home/abhisek/R/i486-pc-linux-gnu-library/2.10/Rcpp/lib/Rcpp/internal/wrap.h:541:
>>>>      |>  |>  | instantiated from ‘SEXPREC* Rcpp::wrap(const T&) [with T =
>>>>      |>  |>  | arma::Col<double>]’
>>>>      |>  |>  |
>>>>      |>
>>>>      /home/abhisek/R/i486-pc-linux-gnu-library/2.10/Rcpp/lib/Rcpp/Named.h:54:
>>>>      |>  |>  | instantiated from ‘Rcpp::Named::Named(const std::string&,
>>>>      const T&)
>>>>      |>  [with
>>>>      |>  |>  T
>>>>      |>  |>  | = arma::colvec]’
>>>>      |>  |>  | RcppArmadilloEg.cpp:19:   instantiated from here
>>>>      |>  |>  |
>>>>      |>  |>
>>>>      |>
>>>>      /home/abhisek/R/i486-pc-linux-gnu-library/2.10/Rcpp/lib/Rcpp/internal/wrap.h:394:
>>>>      |>  |>  | error: cannot convert ‘const arma::Col<double>’ to
>>>>      ‘SEXPREC*’ in
>>>>      |>  |>  | initialization
>>>>      |>  |>  | make: *** [RcppArmadilloEg.o] Error 1
>>>>      |>  |>  |
>>>>      |>  |>  |
>>>>      |>  |>  | could someone provide some advice?
>>>>      |>  |>
>>>>      |>  |>  Which Rcpp version do you have installed?
>>>>      |>  |>
>>>>      |>  |>  Which Armadillo version do you have installed?
>>>>      |>  |>
>>>>      |>  |>  I have not tried the free-floating direct compile you try
>>>>      here.  Maybe
>>>>      |>  the
>>>>      |>  |>  defines for RcppArmadillo that we use are missing here --
>>>>      hard to say.
>>>>      |>  |>
>>>>      |>  |>  Could you try to create your own little package but copying the
>>>>      |>  |>  RcppArmadillo
>>>>      |>  |>  files, changes DESCRIPTION to what you do and changes the
>>>>      FastLM code
>>>>      |>  in
>>>>      |>  |>  C++
>>>>      |>  |>  and R?
>>>>      |>  |>
>>>>      |>  |>  Dirk
>>>>      |>  |>
>>>>      |>  |>  --
>>>>      |>  |>    Registration is open for the 2nd International conference R
>>>>      / Finance
>>>>      |>  2010
>>>>      |>  |>    See http://www.RinFinance.com for details, and see you in
>>>>      Chicago in
>>>>      |>  |>  April!
>>>>      |>  |>
>>>>      |>
>>>>      |>  --
>>>>      |>     Registration is open for the 2nd International conference R /
>>>>      Finance
>>>>      |>  2010
>>>>      |>    See http://www.RinFinance.com for details, and see you in
>>>>      Chicago in
>>>>      |>  April!
>>>>      |>
>>>>
>>>>      --
>>>>        Registration is open for the 2nd International conference R /
>>>>      Finance 2010
>>>>        See http://www.RinFinance.com for details, and see you in Chicago
>>>>      in April!
>>>>
>>>>
>>>>
>>>>
>>>> _______________________________________________
>>>> Rcpp-devel mailing list
>>>> Rcpp-devel at lists.r-forge.r-project.org
>>>> https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel
>>>
>>>
>>> --
>>> Romain Francois
>>> Professional R Enthusiast
>>> +33(0) 6 28 91 30 30
>>> http://romainfrancois.blog.free.fr
>>> |- http://tr.im/OIXN : raster images and RImageJ
>>> |- http://tr.im/OcQe : Rcpp 0.7.7
>>> `- http://tr.im/O1wO : highlight 0.1-5
>>>
>>> _______________________________________________
>>> Rcpp-devel mailing list
>>> Rcpp-devel at lists.r-forge.r-project.org
>>> https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel
>>>
>>
>
>
> --
> Romain Francois
> Professional R Enthusiast
> +33(0) 6 28 91 30 30
> http://romainfrancois.blog.free.fr
> |- http://tr.im/OIXN : raster images and RImageJ
> |- http://tr.im/OcQe : Rcpp 0.7.7
> `- http://tr.im/O1wO : highlight 0.1-5
>
> _______________________________________________
> Rcpp-devel mailing list
> Rcpp-devel at lists.r-forge.r-project.org
> https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel
>


More information about the Rcpp-devel mailing list