[Rcpp-devel] list of matrices to Eigen matrices

2013-03-20 Thread M A
I have a list of matrices in R which I want to turn into a bunch of
Eigen matrices using RcppEigen. I found a way to do this, but it seems
unnecessarily tortured. Here's what I have:


// [[Rcpp::export]]
void listMat(Rcpp::List mat_list) {
int n_mats = mat_list.size();
std::vector vec_of_mats(n_mats);

for (int i=0; i < n_mats; i++) {
Rcpp::NumericMatrix tmpcv = mat_list[i];
double *pcv = &tmpcv(0,0);

Eigen::Map tmpmapd(pcv, tmpcv.nrow(), tmpcv.ncol());
vec_of_mats[i] = Eigen::MatrixXf(tmpmapd.cast());
}
std::cout << vec_of_mats[0] << std::endl; // Sanity check.
return;
}

Note that I'm putting each matrix in my R list into a std::vector
where each element is a float matrix (ie MatrixXf). This does assume
that Rcpp::NumericMatrix stores the matrix data contiguously and in
column-major order, which is true, but will it always necessarily be
so? (I get a little bit nervous about reaching into a class like this
and just pulling out an address). Is there a more direct way of doing
this?

Thanks,
Mark
___
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


Re: [Rcpp-devel] list of matrices to Eigen matrices

2013-03-20 Thread Dirk Eddelbuettel

Mark,

On 20 March 2013 at 13:03, M A wrote:
| I have a list of matrices in R which I want to turn into a bunch of
| Eigen matrices using RcppEigen. I found a way to do this, but it seems
| unnecessarily tortured. Here's what I have:

Nope, that is fine. (Apart from maybe doing with *pcv and sticking that into
the ctor directly).  Someone somewhere needs to fill the vector; we don't
have a function for it so you had to fill this in.
 
| // [[Rcpp::export]]
| void listMat(Rcpp::List mat_list) {
| int n_mats = mat_list.size();
| std::vector vec_of_mats(n_mats);
| 
| for (int i=0; i < n_mats; i++) {
| Rcpp::NumericMatrix tmpcv = mat_list[i];
| double *pcv = &tmpcv(0,0);
| 
| Eigen::Map tmpmapd(pcv, tmpcv.nrow(), tmpcv.ncol());
| vec_of_mats[i] = Eigen::MatrixXf(tmpmapd.cast());
| }
| std::cout << vec_of_mats[0] << std::endl; // Sanity check.
| return;
| }
| 
| Note that I'm putting each matrix in my R list into a std::vector
| where each element is a float matrix (ie MatrixXf). This does assume
| that Rcpp::NumericMatrix stores the matrix data contiguously and in
| column-major order, which is true, but will it always necessarily be
| so? (I get a little bit nervous about reaching into a class like this

No need to be nervous as we get the matrix from R which (presumably) won't
change these internals anytime soo.

| and just pulling out an address). Is there a more direct way of doing
| this?

It looks fine to me.  I'd write very similar code.

Dirk

-- 
Dirk Eddelbuettel | e...@debian.org | http://dirk.eddelbuettel.com  
___
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


[Rcpp-devel] Installing my own package in the system directory

2013-03-20 Thread Mario Bourgoin
Hi,
I use an Intel desktop under Ubuntu 11.04, and I have super-user
privileges. I wrote a utility i/o function to use in R. I am able to
install it in my account's R/site-library, and it works fine.  I
cannot install it on the system R/site-library using either R CMD
INSTALL or install.packages; I get an "invalid package" warning
followed by an "Error: ERROR: no package specified", etc. All of that
goes away if I specify to install in my account's site library. I read
about setting up a local repository, but before I plunge into setting
something like that for little things, I'd like to know I haven't
missed something obvious.  Is there something else I may do?
Best,
Mario
___
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


Re: [Rcpp-devel] Installing my own package in the system directory

2013-03-20 Thread Dirk Eddelbuettel

Mario,

That email had nothing to do with Rcpp and is there unsuitable for this
mailing list.  Please do not abuse the list.

Dirk

-- 
Dirk Eddelbuettel | e...@debian.org | http://dirk.eddelbuettel.com  
___
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


Re: [Rcpp-devel] Installing my own package in the system directory

2013-03-20 Thread Mario Bourgoin
Sorry.

Sent from my iPhone

On Mar 20, 2013, at 5:43 PM, Dirk Eddelbuettel  wrote:

>
> Mario,
>
> That email had nothing to do with Rcpp and is there unsuitable for this
> mailing list.  Please do not abuse the list.
>
> Dirk
>
> --
> Dirk Eddelbuettel | e...@debian.org | http://dirk.eddelbuettel.com
___
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


Re: [Rcpp-devel] Rcpp Google summer of code 2013?

2013-03-20 Thread Berry Kriesels

On 03/18/2013 12:50 AM, Dirk Eddelbuettel wrote:

On 17 March 2013 at 22:34, Michael Weylandt wrote:
| There's an active R-GSOC bunch and I'm sure a good Rcpp project would get
| support that way. Dirk has sponsored GSOC projects in the past so I bet you
| wouldn't have too much trouble finding a mentor. ;-)

Yep, I was quite involved for three years and even acted as admin one year,
but I stopped mentoring after GSoC 2011. For one I don't have the bandwidth
for it (but come to think about, I think I offered to be a back-up mentor for
some thing using Rcpp but being primairly BioC) and Google also encourages
rotation of personel so that things don't get stuck in the same rut.

So if someone wants to have a go at a Rcpp-based GSoC project: by all means,
go for it.

Thank you for your reply Dirk.
If someone would feel tempted to mentor the project I would be more then 
willing to show interest as a student!


Berry
  
| http://rwiki.sciviews.org/doku.php?id=developers:projects:gsoc2013

| And a mailing list off google groups.

Yup.

And there are of course other organizations too (eg I mentored for R as well
as within Debian).

Dirk



___
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


[Rcpp-devel] Simple project segfaults

2013-03-20 Thread Berry Kriesels

Hi everybody,

Just now I was playing around with Rcpp in combination with Qt (I have 
found an excellent example on this). And decided to have a go(small 
dummyproject) at this myself.  Problem is that the application segfaults 
when I run it.


QtR.h
http://pastebin.com/AXT144SK

QtR.cpp
http://pastebin.com/JUUuCFN2

main.cpp
http://pastebin.com/yWUmDL17

mainwindow.cpp
http://pastebin.com/gE84ZtxH

I create an instance of my QtR class called qtr which creates an RInside 
session in the constructor. In my mainwindow.cpp I reference to my 
instance of qtr and then invoke the loadData method. In the loadData 
method I try to use 
m_R.parseEvalQ("cat("+fname_no_ext+"',file='outfile.txt',sep='\n')");


This results in a segfault.

However when I remove this line from the loadData method and add the 
m_R.parseEvalQ("cat("+fname_no_ext+"',file='outfile.txt',sep='\n')"); 
line to the constructor of QtR which is invoked in main.cpp it runs 
without trouble.


I probably am making a very obvious mistake. But I seem unable to see 
the issue at this point myself.


Berry

PS

I have used pastebin for readability, or would everybody prefer the code 
within the e-mail?





___
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