Hi there, I need to create a multidimensional array. I tried arma::cube. It is very good for 3d array, but I need to create 4d/5d array and cube seems not the answer. I found a c++ library 'ndarray' that depends on eigen. I am not sure how I can make a multidimensional array by using rcppeigen and ndarray. Does anyone know how to do it? Thank you. Aileen Lin View my profile: au.linkedin.com/in/aileen2 -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20130313/80b4c840/attachment.html>
[Rcpp-devel] ndarray + eigen
6 messages · Aileen Lin, Dirk Eddelbuettel, Suresh Easwar
How does one invoke class methods via XPtr<T> objects in R? I get this error: Error in aptr$f : object of type 'externalptr' is not subsettable:
cpp file:
#include <Rcpp.h>
struct A {
void f() {}
};
typedef Rcpp::XPtr<A> APtr;
APtr getAPtr()
{
return APtr(new A);
}
struct B {
B(APtr) { }
};
RCPP_MODULE(mytest)
{
Rcpp::function("get_aptr", &getAPtr);
Rcpp::class_<A>("A")
.constructor()
.method("f", &A::f)
;
Rcpp::class_<B>("B")
.constructor<APtr>()
;
}
R session:
R version 2.15.3 (2013-03-01) -- "Security Blanket"
Copyright (C) 2013 The R Foundation for Statistical Computing
ISBN 3-900051-07-0
Platform: x86_64-unknown-linux-gnu (64-bit)
library(mytest)
Loading required package: Rcpp
a <- new(A) aptr <- get_aptr() b <- new(B, aptr) a$f() aptr$f() <- not sure how to invoke f() via aptr
Error in aptr$f : object of type 'externalptr' is not subsettable
Thanks Suresh
On 13 March 2013 at 10:15, Suresh Easwar wrote:
| How does one invoke class methods via XPtr<T> objects in R? I get this error: Error in aptr$f : object of type 'externalptr' is not subsettable:
I don't understand what you are trying to do below, and do not have time to
understand and debug it for you.
Your example is also complicated as you mix XPtr and Modules. Maybe you will
have more success walking in smaller steps --- and a working example of XPtr
via Rcpp is in the RcppDE package where I use XPtr to pass external
(user-given) C interface functions around to the optimiser.
Dirk
|
| cpp file:
| #include <Rcpp.h>
| struct A {
| void f() {}
| };
| typedef Rcpp::XPtr<A> APtr;
| APtr getAPtr()
| {
| return APtr(new A);
| }
| struct B {
| B(APtr) { }
| };
| RCPP_MODULE(mytest)
| {
| Rcpp::function("get_aptr", &getAPtr);
| Rcpp::class_<A>("A")
| .constructor()
| .method("f", &A::f)
| ;
| Rcpp::class_<B>("B")
| .constructor<APtr>()
| ;
| }
|
| R session:
| R version 2.15.3 (2013-03-01) -- "Security Blanket"
| Copyright (C) 2013 The R Foundation for Statistical Computing
| ISBN 3-900051-07-0
| Platform: x86_64-unknown-linux-gnu (64-bit)
| > library(mytest)
| Loading required package: Rcpp
| > a <- new(A)
| > aptr <- get_aptr()
| > b <- new(B, aptr)
| > a$f()
| > aptr$f() <- not sure how to invoke f() via aptr
| Error in aptr$f : object of type 'externalptr' is not subsettable
| >
|
| Thanks
|
| Suresh
| _______________________________________________
| 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
Dirk Eddelbuettel | edd at debian.org | http://dirk.eddelbuettel.com
On 13 March 2013 at 14:49, Aileen Lin wrote:
| Hi there, | | I need to create a multidimensional array. I tried arma::cube. It is very good | for 3d array, but I need to create 4d/5d array and cube seems not the answer. I | found a c++ library 'ndarray' that depends on eigen. I am not sure how I can | make a multidimensional array by using rcppeigen and ndarray. Does anyone know | how to do it? Thank you. I think we just discussed that the other day on this list: use a standard NumericVector, and set a dimension attribute. Dirk | | Aileen Lin | | View my profile: au.linkedin.com/in/aileen2 | | | ---------------------------------------------------------------------- | _______________________________________________ | 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
Dirk Eddelbuettel | edd at debian.org | http://dirk.eddelbuettel.com
All I want to do is obtain a shared-pointer equivalent in R to a C++ object and be able to do two things with it - 1. Invoke methods of the object via the shared-pointer and 2. pass the shared-pointer to the methods of other C++ class objects. In Python, I am able to do this like so (Boost shared-ptrs are easily passed back and forth across the Python-C++ boundary using Boost-Python):
aptr = mytest.get_aptr() # obtain a shared-pointer to an instance of class A aptr.f() # invoke method f() of class A via the pointer b = mytest.B(aptr) # construct object of class B invoking constructor that accepts a shared-pointer to object of class A.
I am looking for the equivalent in R (or at least a close enough idiom). Thanks suresh
From: Dirk Eddelbuettel <edd at debian.org>
To: Suresh Easwar <seaswar at yahoo.com>
Cc: "rcpp-devel at lists.r-forge.r-project.org" <rcpp-devel at lists.r-forge.r-project.org>
Sent: Wednesday, March 13, 2013 5:56 PM
Subject: Re: [Rcpp-devel] Invoking class methods via XPtr<> objects in R
To: Suresh Easwar <seaswar at yahoo.com>
Cc: "rcpp-devel at lists.r-forge.r-project.org" <rcpp-devel at lists.r-forge.r-project.org>
Sent: Wednesday, March 13, 2013 5:56 PM
Subject: Re: [Rcpp-devel] Invoking class methods via XPtr<> objects in R
On 13 March 2013 at 10:15, Suresh Easwar wrote:
| How does one invoke class methods via XPtr<T> objects in R? I get this error: Error in aptr$f : object of type 'externalptr' is not subsettable:
I don't understand what you are trying to do below, and do not have time to
understand and debug it for you.
Your example is also complicated as you mix XPtr and Modules.? Maybe you will
have more success walking in smaller steps --- and a working example of XPtr
via Rcpp is in the RcppDE package where I use XPtr to pass external
(user-given) C interface functions around to the optimiser.
Dirk
|?
| cpp file:
| #include <Rcpp.h>
| struct A {
| void f() {}
| };
| typedef Rcpp::XPtr<A> APtr;
| APtr getAPtr()
| {
| return APtr(new A);
| }
| struct B {
| B(APtr) { }
| };
| RCPP_MODULE(mytest)
| {
|? ? ? ? ? ? ? ? Rcpp::function("get_aptr", &getAPtr);
|? ? ? ? ? ? ? ? Rcpp::class_<A>("A")
|? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? .constructor()
|? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? .method("f", &A::f)
|? ? ? ? ? ? ? ? ;
|? ? ? ? ? ? ? ? Rcpp::class_<B>("B")
|? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? .constructor<APtr>()
|? ? ? ? ? ? ? ? ;
| }
|?
| R session:
| R version 2.15.3 (2013-03-01) -- "Security Blanket"
| Copyright (C) 2013 The R Foundation for Statistical Computing
| ISBN 3-900051-07-0
| Platform: x86_64-unknown-linux-gnu (64-bit)
| > library(mytest)
| Loading required package: Rcpp
| > a <- new(A)
| > aptr <- get_aptr()
| > b <- new(B, aptr)
| > a$f()
| > aptr$f()? ? ? <- not sure how to invoke f() via aptr
| Error in aptr$f : object of type 'externalptr' is not subsettable
| >
|?
| Thanks
|?
| Suresh
| _______________________________________________
| 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
Dirk Eddelbuettel | edd at debian.org | http://dirk.eddelbuettel.com -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20130313/322980d2/attachment.html>
On 13 March 2013 at 18:27, Suresh Easwar wrote:
| All I want to do is obtain a shared-pointer equivalent in R to a C++ object and | be able to do two things with it - 1. Invoke methods of the object via the | shared-pointer and 2. pass the shared-pointer to the methods of other C++ class | objects. | | In Python, I am able to do this like so (Boost shared-ptrs are easily passed | back and forth across the Python-C++ boundary using Boost-Python): | >>> aptr = mytest.get_aptr() # obtain a shared-pointer to an instance of class | A | >>> aptr.f() # invoke method f() of class A via the pointer | >>> b = mytest.B(aptr) # construct object of class B invoking constructor that | accepts a shared-pointer to object of class A. | | I am looking for the equivalent in R (or at least a close enough idiom). Thinking by analogy is not always the best way. In essence, Rcpp modules already give you that pointer. It is not clear to me why you can't use it as is. Dirk | Thanks | suresh | | | ------------------------------------------------------------------------------- | From: Dirk Eddelbuettel <edd at debian.org> | To: Suresh Easwar <seaswar at yahoo.com> | Cc: "rcpp-devel at lists.r-forge.r-project.org" | <rcpp-devel at lists.r-forge.r-project.org> | Sent: Wednesday, March 13, 2013 5:56 PM | Subject: Re: [Rcpp-devel] Invoking class methods via XPtr<> objects in R | |
| On 13 March 2013 at 10:15, Suresh Easwar wrote:
| | How does one invoke class methods via XPtr<T> objects in R? I get this error:
| Error in aptr$f : object of type 'externalptr' is not subsettable:
|
| I don't understand what you are trying to do below, and do not have time to
| understand and debug it for you.
|
| Your example is also complicated as you mix XPtr and Modules. Maybe you will
| have more success walking in smaller steps --- and a working example of XPtr
| via Rcpp is in the RcppDE package where I use XPtr to pass external
| (user-given) C interface functions around to the optimiser.
|
| Dirk
|
| |
| | cpp file:
| | #include <Rcpp.h>
| | struct A {
| | void f() {}
| | };
| | typedef Rcpp::XPtr<A> APtr;
| | APtr getAPtr()
| | {
| | return APtr(new A);
| | }
| | struct B {
| | B(APtr) { }
| | };
| | RCPP_MODULE(mytest)
| | {
| | Rcpp::function("get_aptr", &getAPtr);
| | Rcpp::class_<A>("A")
| | .constructor()
| | .method("f", &A::f)
| | ;
| | Rcpp::class_<B>("B")
| | .constructor<APtr>()
| | ;
| | }
| |
| | R session:
| | R version 2.15.3 (2013-03-01) -- "Security Blanket"
| | Copyright (C) 2013 The R Foundation for Statistical Computing
| | ISBN 3-900051-07-0
| | Platform: x86_64-unknown-linux-gnu (64-bit)
| | > library(mytest)
| | Loading required package: Rcpp
| | > a <- new(A)
| | > aptr <- get_aptr()
| | > b <- new(B, aptr)
| | > a$f()
| | > aptr$f() <- not sure how to invoke f() via aptr
| | Error in aptr$f : object of type 'externalptr' is not subsettable
| | >
| |
| | Thanks
| |
| | Suresh
| | _______________________________________________
| | 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
|
| --
| Dirk Eddelbuettel | edd at debian.org | http://dirk.eddelbuettel.com
|
|
Dirk Eddelbuettel | edd at debian.org | http://dirk.eddelbuettel.com