[Rcpp-devel] binding, combining vectors

2012-12-13 Thread Romain Francois

Hello,

I'd like to add a functionality to "bind" vectors of the same type (well 
sugar expressions really, but let's say it is vectors for the sake of 
this email).


So essentially I'd like something similar to what "c" does in R :

> c( letters, letters )
 [1] "a" "b" "c" "d" "e" "f" "g" "h" "i" "j" "k" "l" "m" "n" "o" "p" 
"q" "r" "s"
[20] "t" "u" "v" "w" "x" "y" "z" "a" "b" "c" "d" "e" "f" "g" "h" "i" "j" 
"k" "l"

[39] "m" "n" "o" "p" "q" "r" "s" "t" "u" "v" "w" "x" "y" "z"


I don't want to call it "c", and I'd like suggestions : combine, bind ?

The idea is to avoid writing code like this:

CharacterVector x, y ;
CharacterVector z( x.size() + y.size() ) ;
int i=0;
for( ; iI know it is not a big deal for people to write this code, but for 
example this does not handle the names of the elements, ... and 
internally I can use more efficient code


Romain

--
Romain Francois
Professional R Enthusiast
+33(0) 6 28 91 30 30

R Graph Gallery: http://gallery.r-enthusiasts.com

blog:http://romainfrancois.blog.free.fr
|- http://bit.ly/RE6sYH : OOP with Rcpp modules
`- http://bit.ly/Thw7IK : Rcpp modules more flexible

___
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] binding, combining vectors

2012-12-13 Thread Andreas Alfons
Hi Romain,

"bind" may be confusing to R users, because "cbind" and "rbind" exist
in R and return matrices. In my opinion, "combine" is a better option.

- Andreas


On Thu, Dec 13, 2012 at 10:01 AM, Romain Francois
 wrote:
> Hello,
>
> I'd like to add a functionality to "bind" vectors of the same type (well
> sugar expressions really, but let's say it is vectors for the sake of
> this email).
>
> So essentially I'd like something similar to what "c" does in R :
>
>  > c( letters, letters )
>   [1] "a" "b" "c" "d" "e" "f" "g" "h" "i" "j" "k" "l" "m" "n" "o" "p"
> "q" "r" "s"
> [20] "t" "u" "v" "w" "x" "y" "z" "a" "b" "c" "d" "e" "f" "g" "h" "i" "j"
> "k" "l"
> [39] "m" "n" "o" "p" "q" "r" "s" "t" "u" "v" "w" "x" "y" "z"
>
>
> I don't want to call it "c", and I'd like suggestions : combine, bind ?
>
> The idea is to avoid writing code like this:
>
> CharacterVector x, y ;
> CharacterVector z( x.size() + y.size() ) ;
> int i=0;
> for( ; i for( int j=0; j
> I know it is not a big deal for people to write this code, but for
> example this does not handle the names of the elements, ... and
> internally I can use more efficient code
>
> Romain
>
> --
> Romain Francois
> Professional R Enthusiast
> +33(0) 6 28 91 30 30
>
> R Graph Gallery: http://gallery.r-enthusiasts.com
>
> blog:http://romainfrancois.blog.free.fr
> |- http://bit.ly/RE6sYH : OOP with Rcpp modules
> `- http://bit.ly/Thw7IK : Rcpp modules more flexible
>
> ___
> 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



-- 
Andreas Alfons
Faculty of Business and Economics, KU Leuven
www.econ.kuleuven.be/andreas.alfons/public/
___
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] binding, combining vectors

2012-12-13 Thread Walter Mascarenhas
Romain,

   what about "join"?

   walter.

On Thu, Dec 13, 2012 at 1:15 PM, Andreas Alfons
wrote:

> Hi Romain,
>
> "bind" may be confusing to R users, because "cbind" and "rbind" exist
> in R and return matrices. In my opinion, "combine" is a better option.
>
> - Andreas
>
>
> On Thu, Dec 13, 2012 at 10:01 AM, Romain Francois
>  wrote:
> > Hello,
> >
> > I'd like to add a functionality to "bind" vectors of the same type (well
> > sugar expressions really, but let's say it is vectors for the sake of
> > this email).
> >
> > So essentially I'd like something similar to what "c" does in R :
> >
> >  > c( letters, letters )
> >   [1] "a" "b" "c" "d" "e" "f" "g" "h" "i" "j" "k" "l" "m" "n" "o" "p"
> > "q" "r" "s"
> > [20] "t" "u" "v" "w" "x" "y" "z" "a" "b" "c" "d" "e" "f" "g" "h" "i" "j"
> > "k" "l"
> > [39] "m" "n" "o" "p" "q" "r" "s" "t" "u" "v" "w" "x" "y" "z"
> >
> >
> > I don't want to call it "c", and I'd like suggestions : combine, bind ?
> >
> > The idea is to avoid writing code like this:
> >
> > CharacterVector x, y ;
> > CharacterVector z( x.size() + y.size() ) ;
> > int i=0;
> > for( ; i > for( int j=0; j >
> > I know it is not a big deal for people to write this code, but for
> > example this does not handle the names of the elements, ... and
> > internally I can use more efficient code
> >
> > Romain
> >
> > --
> > Romain Francois
> > Professional R Enthusiast
> > +33(0) 6 28 91 30 30
> >
> > R Graph Gallery: http://gallery.r-enthusiasts.com
> >
> > blog:http://romainfrancois.blog.free.fr
> > |- http://bit.ly/RE6sYH : OOP with Rcpp modules
> > `- http://bit.ly/Thw7IK : Rcpp modules more flexible
> >
> > ___
> > 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
>
>
>
> --
> Andreas Alfons
> Faculty of Business and Economics, KU Leuven
> www.econ.kuleuven.be/andreas.alfons/public/
> ___
> 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 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] binding, combining vectors

2012-12-13 Thread John Merrill
What about 'concat', 'cat', or 'concatenate'?  The function concatenates
vectors, and 'concat' and 'cat' are well-known short forms of the word.
 (The Unix program 'cat' is so-named because it concatenates text files.)


On Thu, Dec 13, 2012 at 7:20 AM, Walter Mascarenhas <
walter.mascaren...@gmail.com> wrote:

> Romain,
>
>what about "join"?
>
>walter.
>
>
> On Thu, Dec 13, 2012 at 1:15 PM, Andreas Alfons <
> andreas.alf...@kuleuven.be> wrote:
>
>> Hi Romain,
>>
>> "bind" may be confusing to R users, because "cbind" and "rbind" exist
>> in R and return matrices. In my opinion, "combine" is a better option.
>>
>> - Andreas
>>
>>
>> On Thu, Dec 13, 2012 at 10:01 AM, Romain Francois
>>  wrote:
>> > Hello,
>> >
>> > I'd like to add a functionality to "bind" vectors of the same type (well
>> > sugar expressions really, but let's say it is vectors for the sake of
>> > this email).
>> >
>> > So essentially I'd like something similar to what "c" does in R :
>> >
>> >  > c( letters, letters )
>> >   [1] "a" "b" "c" "d" "e" "f" "g" "h" "i" "j" "k" "l" "m" "n" "o" "p"
>> > "q" "r" "s"
>> > [20] "t" "u" "v" "w" "x" "y" "z" "a" "b" "c" "d" "e" "f" "g" "h" "i" "j"
>> > "k" "l"
>> > [39] "m" "n" "o" "p" "q" "r" "s" "t" "u" "v" "w" "x" "y" "z"
>> >
>> >
>> > I don't want to call it "c", and I'd like suggestions : combine, bind ?
>> >
>> > The idea is to avoid writing code like this:
>> >
>> > CharacterVector x, y ;
>> > CharacterVector z( x.size() + y.size() ) ;
>> > int i=0;
>> > for( ; i> > for( int j=0; j> >
>> > I know it is not a big deal for people to write this code, but for
>> > example this does not handle the names of the elements, ... and
>> > internally I can use more efficient code
>> >
>> > Romain
>> >
>> > --
>> > Romain Francois
>> > Professional R Enthusiast
>> > +33(0) 6 28 91 30 30
>> >
>> > R Graph Gallery: http://gallery.r-enthusiasts.com
>> >
>> > blog:http://romainfrancois.blog.free.fr
>> > |- http://bit.ly/RE6sYH : OOP with Rcpp modules
>> > `- http://bit.ly/Thw7IK : Rcpp modules more flexible
>> >
>> > ___
>> > 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
>>
>>
>>
>> --
>> Andreas Alfons
>> Faculty of Business and Economics, KU Leuven
>> www.econ.kuleuven.be/andreas.alfons/public/
>> ___
>> 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 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 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] iak problem -- dyn.load unable to load shared object

2012-12-13 Thread Glenn Lawyer
The problem seems to be file privileges. When I run R as 
superuser, it works. When I run as a normal user, I continue getting


Error in dyn.load(libLFile) :
  unable to load shared object 
'/tmp/RtmpTFHtzm/file1d365e7eaf51.so':
  /tmp/RtmpTFHtzm/file1d365e7eaf51.so: undefined symbol: 
_ZN4Rcpp8internal14r_vector_startILi14EdEEPT0_P7SEXPREC


Note that the names of the undefined symbol is the same for all of 
the ways and examples I have tested, which include:

cxxfunction (following the vignette)
cppFunction (following Hadley's tutorial)
R CMD INSTALL -l foo mypackage
where "mypackage" is created by Rcpp.package.skeleton("mypackage")
R CMD INSTALL -l foo somepackage.tar.gz
where "somepackage" is a package downloaded from CRAN which uses Rcpp.

I would very much appreciate a hint/suggestion as to which 
folders/directories/paths I may need to check to get the file 
permissions correct.


Does the name of the undefined symbol tell you anything? If you 
ignore some characters, it reads

...Rccp.internal..r_vector_start...SEXPR..

+glenn



On 12/12/2012 05:15 PM, Dirk Eddelbuettel wrote:

Works for me:

R>  require(Rcpp)
R>  require(inline)
Loading required package: inline
R>  inc<- '
+using namespace Rcpp;
+double norm( double x, double y ) {
+return sqrt( x*x + y*y );
+}
+RCPP_MODULE(mod) {
+function( "norm",&norm );
+}
+ '
R>  fx<- cxxfunction(signature(), plugin="Rcpp", include=inc)
R>
R>  mod<- Module( "mod", getDynLib(fx) )
R>
R>  mod$norm( 3, 4 )
[1] 5
R>
R>  sessionInfo()
R version 2.15.2 (2012-10-26)
Platform: x86_64-pc-linux-gnu (64-bit)

locale:
  [1] LC_CTYPE=en_US.UTF-8   LC_NUMERIC=C   LC_TIME=en_US.UTF-8 
   LC_COLLATE=en_US.UTF-8 LC_MONETARY=en_US.UTF-8
  [6] LC_MESSAGES=en_US.UTF-8LC_PAPER=C LC_NAME=C   
   LC_ADDRESS=C   LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C

attached base packages:
[1] stats graphics  grDevices utils datasets  methods   base

other attached packages:
[1] inline_0.3.10   RQuantLib_0.3.9 Rcpp_0.10.1.5

loaded via a namespace (and not attached):
[1] compiler_2.15.2 tools_2.15.2
R>

That is with Rcpp from SVN but that shouldn't matter.

Dirk



--
--
Pirating science, because open access isn't always open enough
www.scipirate.com@piratesci

 Dr. Glenn Lawyer
 +352 661 967 244
 Max-Planck-Institut für Informatik
 Computational Biology and Applied Algorithmics
 Campus E1 4
 66123 Saarbrücken, Germany
 http://bioinf.mpi-inf.mpg.de/~lawyer

___
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] iak problem -- dyn.load unable to load shared object

2012-12-13 Thread Romain Francois

Do you have the same version of Rcpp as root and as non root ?

You can use c++filt to demangle the name, e.g. what does this give you:

$ c++filt _ZN4Rcpp8internal14r_vector_startILi14EdEEPT0_P7SEXPREC

r_vector_start has changed in 0.10.1, i.e. it lost a template parameter, 
which is likely to be the case here. I suppose you have two versions of 
Rcpp installed;


Romain

Le 13/12/12 17:08, Glenn Lawyer a écrit :

The problem seems to be file privileges. When I run R as superuser, it
works. When I run as a normal user, I continue getting

Error in dyn.load(libLFile) :
   unable to load shared object '/tmp/RtmpTFHtzm/file1d365e7eaf51.so':
   /tmp/RtmpTFHtzm/file1d365e7eaf51.so: undefined symbol:
_ZN4Rcpp8internal14r_vector_startILi14EdEEPT0_P7SEXPREC

Note that the names of the undefined symbol is the same for all of the
ways and examples I have tested, which include:
cxxfunction (following the vignette)
cppFunction (following Hadley's tutorial)
R CMD INSTALL -l foo mypackage
where "mypackage" is created by Rcpp.package.skeleton("mypackage")
R CMD INSTALL -l foo somepackage.tar.gz
where "somepackage" is a package downloaded from CRAN which uses Rcpp.

I would very much appreciate a hint/suggestion as to which
folders/directories/paths I may need to check to get the file
permissions correct.

Does the name of the undefined symbol tell you anything? If you ignore
some characters, it reads
...Rccp.internal..r_vector_start...SEXPR..

+glenn



On 12/12/2012 05:15 PM, Dirk Eddelbuettel wrote:

Works for me:

R> require(Rcpp)
R> require(inline)
Loading required package: inline
R> inc <- '
+using namespace Rcpp;
+double norm( double x, double y ) {
+return sqrt( x*x + y*y );
+}
+RCPP_MODULE(mod) {
+function( "norm", &norm );
+}
+ '
R> fx <- cxxfunction(signature(), plugin="Rcpp", include=inc)
R>
R> mod <- Module( "mod", getDynLib(fx) )
R>
R> mod$norm( 3, 4 )
[1] 5
R>
R> sessionInfo()
R version 2.15.2 (2012-10-26)
Platform: x86_64-pc-linux-gnu (64-bit)

locale:
  [1] LC_CTYPE=en_US.UTF-8   LC_NUMERIC=C   LC_TIME=en_US.UTF-8 
   LC_COLLATE=en_US.UTF-8 LC_MONETARY=en_US.UTF-8
  [6] LC_MESSAGES=en_US.UTF-8LC_PAPER=C LC_NAME=C   
   LC_ADDRESS=C   LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C

attached base packages:
[1] stats graphics  grDevices utils datasets  methods   base

other attached packages:
[1] inline_0.3.10   RQuantLib_0.3.9 Rcpp_0.10.1.5

loaded via a namespace (and not attached):
[1] compiler_2.15.2 tools_2.15.2
R>

That is with Rcpp from SVN but that shouldn't matter.

Dirk



--
--
Pirating science, because open access isn't always open enough
www.scipirate.com@piratesci

  Dr. Glenn Lawyer
  +352 661 967 244
  Max-Planck-Institut für Informatik
  Computational Biology and Applied Algorithmics
  Campus E1 4
  66123 Saarbrücken, Germany
  http://bioinf.mpi-inf.mpg.de/~lawyer



___
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




--
Romain Francois
Professional R Enthusiast
+33(0) 6 28 91 30 30

R Graph Gallery: http://gallery.r-enthusiasts.com

blog:http://romainfrancois.blog.free.fr
|- http://bit.ly/RE6sYH : OOP with Rcpp modules
`- http://bit.ly/Thw7IK : Rcpp modules more flexible

___
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] binding, combining vectors

2012-12-13 Thread Dirk Eddelbuettel

On 13 December 2012 at 10:01, Romain Francois wrote:
| Hello,
| 
| I'd like to add a functionality to "bind" vectors of the same type (well 
| sugar expressions really, but let's say it is vectors for the sake of 
| this email).
| 
| So essentially I'd like something similar to what "c" does in R :
| 
|  > c( letters, letters )
|   [1] "a" "b" "c" "d" "e" "f" "g" "h" "i" "j" "k" "l" "m" "n" "o" "p" 
| "q" "r" "s"
| [20] "t" "u" "v" "w" "x" "y" "z" "a" "b" "c" "d" "e" "f" "g" "h" "i" "j" 
| "k" "l"
| [39] "m" "n" "o" "p" "q" "r" "s" "t" "u" "v" "w" "x" "y" "z"
| 
| 
| I don't want to call it "c", and I'd like suggestions : combine, bind ?
| 
| The idea is to avoid writing code like this:
| 
| CharacterVector x, y ;
| CharacterVector z( x.size() + y.size() ) ;
| int i=0;
| for( ; i

// [[Rcpp::export]] 
std::vector concat(std::vector x,
std::vector y) {

  std::vector z(x.size() + y.size());

  std::copy(x.begin(), x.end(), z.begin());
  std::copy(y.begin(), y.end(), z.begin() + x.size());

  return(z);
}


/*** R
concat(letters[1:5], letters[1:4])
***/
-


R> sourceCpp("/tmp/concat.cpp")

R> concat(letters[1:5], letters[1:4])
[1] "a" "b" "c" "d" "e" "a" "b" "c" "d"
R> 


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] iak problem -- dyn.load unable to load shared object

2012-12-13 Thread Dirk Eddelbuettel

On 13 December 2012 at 17:08, Glenn Lawyer wrote:
| The problem seems to be file privileges. When I run R as superuser, it works.
| When I run as a normal user, I continue getting
[...]
| I would very much appreciate a hint/suggestion as to which 
folders/directories/
| paths I may need to check to get the file permissions correct.

That is clearly a sysadmin issue, not a Rcpp issue.  Do the following as root
and a Glenn:

   .libPaths() # and look in all directories listed

   IP <- installed.packages() 
   IP[ IP[,"Package"]=="Rcpp", ]

which should give it away.

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] binding, combining vectors

2012-12-13 Thread Romain Francois

Le 13/12/12 17:29, Dirk Eddelbuettel a écrit :


On 13 December 2012 at 10:01, Romain Francois wrote:
| Hello,
|
| I'd like to add a functionality to "bind" vectors of the same type (well
| sugar expressions really, but let's say it is vectors for the sake of
| this email).
|
| So essentially I'd like something similar to what "c" does in R :
|
|  > c( letters, letters )
|   [1] "a" "b" "c" "d" "e" "f" "g" "h" "i" "j" "k" "l" "m" "n" "o" "p"
| "q" "r" "s"
| [20] "t" "u" "v" "w" "x" "y" "z" "a" "b" "c" "d" "e" "f" "g" "h" "i" "j"
| "k" "l"
| [39] "m" "n" "o" "p" "q" "r" "s" "t" "u" "v" "w" "x" "y" "z"
|
|
| I don't want to call it "c", and I'd like suggestions : combine, bind ?
|
| The idea is to avoid writing code like this:
|
| CharacterVector x, y ;
| CharacterVector z( x.size() + y.size() ) ;
| int i=0;
| for( ; i

// [[Rcpp::export]]
std::vector concat(std::vector x,
std::vector y) {

   std::vector z(x.size() + y.size());

   std::copy(x.begin(), x.end(), z.begin());
   std::copy(y.begin(), y.end(), z.begin() + x.size());

   return(z);
}


/*** R
concat(letters[1:5], letters[1:4])
***/
-


R> sourceCpp("/tmp/concat.cpp")

R> concat(letters[1:5], letters[1:4])
[1] "a" "b" "c" "d" "e" "a" "b" "c" "d"
R>


Dirk


I'm not asking how to implement it, I have a fairly good understanding 
of std::copy.


I was just asking how to name this.

I'd like to have, e.g. the possibility to do:

CharacterVector x, y ; // from somewhere

CharacterVector z1 = concat(x, y ) ;
CharacterVector z1 = concat(x, "foo", y ) ;

Or perhaps dealing with sugar exprs;

CharacterVector z1 = concat( rep(x, 2), rep_each(y, 3) ) ;


... anyway. I think I like "concat"


Romain

--
Romain Francois
Professional R Enthusiast
+33(0) 6 28 91 30 30

R Graph Gallery: http://gallery.r-enthusiasts.com

blog:http://romainfrancois.blog.free.fr
|- http://bit.ly/RE6sYH : OOP with Rcpp modules
`- http://bit.ly/Thw7IK : Rcpp modules more flexible

___
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] How to free memory in Rcpp

2012-12-13 Thread Honglang Wang
Dear All,
How to free memory in Rcpp? What's the command? Thanks.

Best wishes!

Honglang Wang

Office C402 Wells Hall
Department of Statistics and Probability
Michigan State University
1579 I Spartan Village, East Lansing, MI 48823
wangh...@msu.edu
___
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] How to free memory in Rcpp

2012-12-13 Thread romain


Hello,

What memory do you want to free ? Can you give an example of code where 
there is memory you'd like to "free" ?


Romain

Le 2012-12-13 22:52, Honglang Wang a écrit :

Dear All,
How to free memory in Rcpp? What's the command? Thanks.

Best wishes!
 
Honglang Wang
 
Office C402 Wells Hall
Department of Statistics and Probability
Michigan State University
1579 I Spartan Village, East Lansing, MI 48823
wangh...@msu.edu [1]


Links:
--
[1] mailto:wangh...@msu.edu


___
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] Is 10.1 intentionally stricter than 9.15?

2012-12-13 Thread John Merrill
I just built a source package on a 0.10.1 box for the first time;
previously, I'd always built it on 0.9.15 boxes.  I was surprised to see
that I now need to do string comparisons to character SEXP's using the
CHAR() macro; previously, I'd been able to use the SEXP from a StringVector
directly.

I'm not complaining about this -- the code before was at least technically
wrong.  I just don't remember an announcement that this change was
happening, and I'd like to know if it was intentional.
___
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] Is 10.1 intentionally stricter than 9.15?

2012-12-13 Thread romain

Le 2012-12-13 23:09, John Merrill a écrit :

I just built a source package on a 0.10.1 box for the first time;
previously, I'd always built it on 0.9.15 boxes.  I was surprised to
see that I now need to do string comparisons to character SEXP's 
using

the CHAR() macro; previously, I'd been able to use the SEXP from a
StringVector directly.

I'm not complaining about this -- the code before was at least
technically wrong.  I just don't remember an announcement that this
change was happening, and I'd like to know if it was intentional.


I'm suspecting this is related to iterator over CharacterVector ?

I've changed the type that is returned by the 
`CharacterVector::operator[](int) const` from string_proxy to SEXP (I 
did it for performance reasons), but maybe it was not a good idea. It 
only affects you if you work on a const CharacterVector&, do you ?


Perhaps the new Rcpp::String class can help you.


Can you show some examples ? The intention is (and has always been) to 
hide the macros from the R API so this is not expected.


Romain
___
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] How to free memory in Rcpp

2012-12-13 Thread Honglang Wang
Hi,
Here is the sample code:
// [[Rcpp::export]]
List betahat(Function ker, double t0, NumericMatrix Xr, NumericMatrix yr,
NumericVector tr, double h, int m) {
  int n = Xr.nrow(), p = Xr.ncol();
  arma::mat X(Xr.begin(), n, p, false);
  arma::mat y(yr.begin(), n, 1, false);
  arma::colvec t(tr.begin(), tr.size(), false);
  arma::mat T = X;
  T.each_col() %= (t-t0)/h;
  arma::vec K =as(ker(tr-t0,h))/
m;
  double L1 = arma::accu(K%X.col(0)%X.col(0));
  double L2 = arma::accu(K%X.col(0)%X.col(1));
  double L3 = arma::accu(K%X.col(1)%X.col(1));
  double L4 = arma::accu(K%X.col(0)%T.col(0));
  double L5 = arma::accu(K%X.col(1)%T.col(0));
  double L6 = arma::accu(K%X.col(1)%T.col(1));
  double L7 = arma::accu(K%T.col(0)%T.col(0));
  double L8 = arma::accu(K%T.col(0)%T.col(1));
  double L9 = arma::accu(K%T.col(1)%T.col(1));
  double R1 = arma::accu(K%X.col(0)%y);
  double R2 = arma::accu(K%X.col(1)%y);
  double R3 = arma::accu(K%T.col(0)%y);
  double R4 = arma::accu(K%T.col(1)%y);
  arma::mat L(2*p,2*p);
  L(0,0)=L1;L(0,1)=L2;L(0,2)=L4;L(0,3)=L5;
  L(1,0)=L2;L(1,1)=L3;L(1,2)=L5;L(1,3)=L6;
  L(2,0)=L4;L(2,1)=L5;L(2,2)=L7;L(2,3)=L8;
  L(3,0)=L5;L(3,1)=L6;L(3,2)=L8;L(3,3)=L9;
  arma::mat R(2*p,1);
  R(0,0)=R1;R(1,0)=R2;R(2,0)=R3;R(3,0)=R4;
  arma::vec betahat = arma::solve(L,R);

  arma::colvec betahat0(betahat.begin(),betahat.size()/2,false);
  return List::create(Named("betahat") = betahat0);
}

I will call this function repeatedly, and at some point, it went wrong with
the following error:
Error in betahat(ker, x, X, y, t, h, m) :
  promise already under evaluation: recursive default argument reference or
earlier problems?
Calls: system.time ... apply -> FUN -> betahat -> .External -> cpp_exception
Execution halted

I have no idea what's this error. I am just wondering whether I need to
free some memory in this code. Thanks.

Best wishes!

Honglang Wang

Office C402 Wells Hall
Department of Statistics and Probability
Michigan State University
1579 I Spartan Village, East Lansing, MI 48823
wangh...@msu.edu



On Thu, Dec 13, 2012 at 4:57 PM,  wrote:

>
> Hello,
>
> What memory do you want to free ? Can you give an example of code where
> there is memory you'd like to "free" ?
>
> Romain
>
> Le 2012-12-13 22:52, Honglang Wang a écrit :
>
>> Dear All,
>> How to free memory in Rcpp? What's the command? Thanks.
>>
>> Best wishes!
>>
>> Honglang Wang
>>
>> Office C402 Wells Hall
>> Department of Statistics and Probability
>> Michigan State University
>> 1579 I Spartan Village, East Lansing, MI 48823
>> wangh...@msu.edu [1]
>>
>>
>> Links:
>> --
>> [1] mailto:wangh...@msu.edu
>>
>
> __**_
> 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 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] How to free memory in Rcpp

2012-12-13 Thread Dirk Eddelbuettel

Honglang,

You are now abusing the free facilities offered by this list.  Your examples
are not self-contained [ no sample data or simulated data ] and hence not
reproducible.  Your code is complex, and not motivated. And we have told you
REPEATEDLY to shorten your code to chunks until it works.

On 13 December 2012 at 21:15, Honglang Wang wrote:
| I have no idea what's this error. 

My best guess is that we already explained this to you, but you are not
really reading our replies all that closely.  Here is a hint: repeatedly
calling an R function is probably not the smartest thing to do in an
otherwise complex and hard to decipher program. [1]

| I am just wondering whether I need to free some memory in this code.

You are also making it pretty clear that you don't really know what you are
doing with C++, or else you would not ask this question (and the earlier
email people were to polite to reply to).

I suggest that you take a deep breath, go for a walk and once you're back,
start learning about C++.

So please stop emailing the list unless you have something more substantial
to post or ask -- and follow common courtesy and list etiquette. 

Right now you are wasting your time, as well as the time of a few hundred
list subscribers.  Stop now.

Dirk


[1] Just to be plain: Calling a function repeatedly is not per se a bad
thing.  Complete example below.

-
#include 

using namespace Rcpp;

// [[Rcpp::export]]
double foo(Function f, NumericVector x) {
  double r = 0.0;
  for (int i=0; i<100; i++)
r += as(f(x));
  return r;
}


/*** R
x <- 1:10
foo(mean, x)
***/
-

Here is the result from the 100 calls:

R> sourceCpp("/tmp/fun.cpp")

R> x <- 1:10

R> foo(mean, x)
[1] 550
R> 


As expected...




-- 
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] How to free memory in Rcpp

2012-12-13 Thread Honglang Wang
I am sorry that I was abusing this list. My point is
1) First, this code works for me for some simulation cases. I repeated the
simulation 1000 times, which then called this Rcpp function 1000 times at
least. And this code worked perfectly.
2) But in some other simulation case (here what I mean by simulation case,
just change some parameters to produce the data, but the data formats are
the same.), when I repeated the simulation 1000 times, at some point, for
example, at the 298th simulation, it did not work. Then in order to see
what is the problem, I just did the 298th simulation separately (since I
set the seed, it used the same data), but it worked well in this case. Then
I really have no idea what is going on there.

Best wishes!

Honglang Wang

Office C402 Wells Hall
Department of Statistics and Probability
Michigan State University
1579 I Spartan Village, East Lansing, MI 48823
wangh...@msu.edu



On Thu, Dec 13, 2012 at 10:06 PM, Dirk Eddelbuettel  wrote:

>
> Honglang,
>
> You are now abusing the free facilities offered by this list.  Your
> examples
> are not self-contained [ no sample data or simulated data ] and hence not
> reproducible.  Your code is complex, and not motivated. And we have told
> you
> REPEATEDLY to shorten your code to chunks until it works.
>
> On 13 December 2012 at 21:15, Honglang Wang wrote:
> | I have no idea what's this error.
>
> My best guess is that we already explained this to you, but you are not
> really reading our replies all that closely.  Here is a hint: repeatedly
> calling an R function is probably not the smartest thing to do in an
> otherwise complex and hard to decipher program. [1]
>
> | I am just wondering whether I need to free some memory in this code.
>
> You are also making it pretty clear that you don't really know what you are
> doing with C++, or else you would not ask this question (and the earlier
> email people were to polite to reply to).
>
> I suggest that you take a deep breath, go for a walk and once you're back,
> start learning about C++.
>
> So please stop emailing the list unless you have something more substantial
> to post or ask -- and follow common courtesy and list etiquette.
>
> Right now you are wasting your time, as well as the time of a few hundred
> list subscribers.  Stop now.
>
> Dirk
>
>
> [1] Just to be plain: Calling a function repeatedly is not per se a bad
> thing.  Complete example below.
>
>
> -
> #include 
>
> using namespace Rcpp;
>
> // [[Rcpp::export]]
> double foo(Function f, NumericVector x) {
>   double r = 0.0;
>   for (int i=0; i<100; i++)
> r += as(f(x));
>   return r;
> }
>
>
> /*** R
> x <- 1:10
> foo(mean, x)
> ***/
>
> -
>
> Here is the result from the 100 calls:
>
> R> sourceCpp("/tmp/fun.cpp")
>
> R> x <- 1:10
>
> R> foo(mean, x)
> [1] 550
> R>
>
>
> As expected...
>
>
>
>
> --
> 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] How to free memory in Rcpp

2012-12-13 Thread Yan Zhou
You really are not reading the list as close as you should be. If you want 
advice, then take it when people give it to you or stop asking.

AFAIK, your code does not involve manually allocated memory, all memories are 
managed by RAII objects, I don't see where the question of "freeing memory" 
come from. And the error message suggests nothing about memory problems. So 
either you have no idea of C++ at all or you are just asking some random 
question and hope others to debug your code. The later is not going to happen.

On Dec 14, 2012, at 3:25 AM, Honglang Wang  wrote:

> I am sorry that I was abusing this list. My point is 
> 1) First, this code works for me for some simulation cases. I repeated the 
> simulation 1000 times, which then called this Rcpp function 1000 times at 
> least. And this code worked perfectly.
Computers don't do random things, unlike human beings. Something worked once, 
is very likely to work whatever times you repeat it as long as the input is the 
same (unless the function has side effect). So repeating it 1000 times is the 
same as once.

> 2) But in some other simulation case (here what I mean by simulation case, 
> just change some parameters to produce the data, but the data formats are the 
> same.), when I repeated the simulation 1000 times, at some point, for 
> example, at the 298th simulation, it did not work. Then in order to see what 
> is the problem, I just did the 298th simulation separately (since I set the 
> seed, it used the same data), but it worked well in this case. Then I really 
> have no idea what is going on there.
Since you already find an input that crash the program, you should go through 
the function to see where exactly the crash happens. For example, print out the 
intermediate steps in both R and C++ side to see where the execution stopped. 
Using a debugger is better. Sometime it takes a great time to trace back the 
crash site. Debugging can be exhausting. But it is supposed to be done by YOU. 
You cannot throw a bunch of code to the list, ask a non-sense question, and 
hope others to spend time to debug it for you.

Here are a few things people usually do before asking in a mailing list (not 
just Rcpp list, any such lists like R-help, StackOverflow, etc).
1. I write a program, it crashes,
2. I find out the site of crash
3. I make the program simpler and simpler until it is minimal and the crash is 
now reproducible.
4. I still cannot figure out what is wrong with that four or five lines that 
crash the minimal example
5. I ask

Ask yourself, have you go through the first 4 steps? It does not matter how 
stupid your questions are. We all asked silly questions before, that is how we 
learn. But it matters you put in effort to ask the right question. The more 
effort you put into it, the more specific question you ask and more helpful 
answers you get. I suspect you don't know how to do that at all.  So if I were 
you, I will take Dirk's advice, take a deep breath, go for a walk, and start 
learning C++.

Yan

> 
> Best wishes!
>  
> Honglang Wang
>  
> Office C402 Wells Hall
> Department of Statistics and Probability
> Michigan State University
> 1579 I Spartan Village, East Lansing, MI 48823
> wangh...@msu.edu
> 
> 
> 
> On Thu, Dec 13, 2012 at 10:06 PM, Dirk Eddelbuettel  wrote:
> 
> Honglang,
> 
> You are now abusing the free facilities offered by this list.  Your examples
> are not self-contained [ no sample data or simulated data ] and hence not
> reproducible.  Your code is complex, and not motivated. And we have told you
> REPEATEDLY to shorten your code to chunks until it works.
> 
> On 13 December 2012 at 21:15, Honglang Wang wrote:
> | I have no idea what's this error.
> 
> My best guess is that we already explained this to you, but you are not
> really reading our replies all that closely.  Here is a hint: repeatedly
> calling an R function is probably not the smartest thing to do in an
> otherwise complex and hard to decipher program. [1]
> 
> | I am just wondering whether I need to free some memory in this code.
> 
> You are also making it pretty clear that you don't really know what you are
> doing with C++, or else you would not ask this question (and the earlier
> email people were to polite to reply to).
> 
> I suggest that you take a deep breath, go for a walk and once you're back,
> start learning about C++.
> 
> So please stop emailing the list unless you have something more substantial
> to post or ask -- and follow common courtesy and list etiquette.
> 
> Right now you are wasting your time, as well as the time of a few hundred
> list subscribers.  Stop now.
> 
> Dirk
> 
> 
> [1] Just to be plain: Calling a function repeatedly is not per se a bad
> thing.  Complete example below.
> 
> -
> #include 
> 
> using namespace Rcpp;
> 
> // [[Rcpp::export]]
> double foo(Function f, NumericVector x) {
>   double r = 0.0;
>   for (int i=0; i<100; i++)
>   

Re: [Rcpp-devel] How to free memory in Rcpp

2012-12-13 Thread Honglang Wang
Hi Yan,
Thanks a lot. Your advice is really the point for me. Have a good night.

Best wishes!

Honglang Wang

Office C402 Wells Hall
Department of Statistics and Probability
Michigan State University
1579 I Spartan Village, East Lansing, MI 48823
wangh...@msu.edu



On Thu, Dec 13, 2012 at 10:54 PM, Yan Zhou  wrote:

> You really are not reading the list as close as you should be. If you want
> advice, then take it when people give it to you or stop asking.
>
> AFAIK, your code does not involve manually allocated memory, all memories
> are managed by RAII objects, I don't see where the question of "freeing
> memory" come from. And the error message suggests nothing about memory
> problems. So either you have no idea of C++ at all or you are just asking
> some random question and hope others to debug your code. The later is not
> going to happen.
>
> On Dec 14, 2012, at 3:25 AM, Honglang Wang 
> wrote:
>
> I am sorry that I was abusing this list. My point is
> 1) First, this code works for me for some simulation cases. I repeated the
> simulation 1000 times, which then called this Rcpp function 1000 times at
> least. And this code worked perfectly.
>
> Computers don't do random things, unlike human beings. Something worked
> once, is very likely to work whatever times you repeat it as long as the
> input is the same (unless the function has side effect). So repeating it
> 1000 times is the same as once.
>
> 2) But in some other simulation case (here what I mean by simulation case,
> just change some parameters to produce the data, but the data formats are
> the same.), when I repeated the simulation 1000 times, at some point, for
> example, at the 298th simulation, it did not work. Then in order to see
> what is the problem, I just did the 298th simulation separately (since I
> set the seed, it used the same data), but it worked well in this case. Then
> I really have no idea what is going on there.
>
> Since you already find an input that crash the program, you should go
> through the function to see where exactly the crash happens. For example,
> print out the intermediate steps in both R and C++ side to see where the
> execution stopped. Using a debugger is better. Sometime it takes a great
> time to trace back the crash site. Debugging can be exhausting. But it is
> supposed to be done by YOU. You cannot throw a bunch of code to the list,
> ask a non-sense question, and hope others to spend time to debug it for you.
>
> Here are a few things people usually do before asking in a mailing list
> (not just Rcpp list, any such lists like R-help, StackOverflow, etc).
> 1. I write a program, it crashes,
> 2. I find out the site of crash
> 3. I make the program simpler and simpler until it is minimal and the
> crash is now reproducible.
> 4. I still cannot figure out what is wrong with that four or five lines
> that crash the minimal example
> 5. I ask
>
> Ask yourself, have you go through the first 4 steps? It does not matter
> how stupid your questions are. We all asked silly questions before, that is
> how we learn. But it matters you put in effort to ask the right question.
> The more effort you put into it, the more specific question you ask and
> more helpful answers you get. I suspect you don't know how to do that at
> all.  So if I were you, I will take Dirk's advice, take a deep breath, go
> for a walk, and start learning C++.
>
> Yan
>
>
> Best wishes!
>
> Honglang Wang
>
> Office C402 Wells Hall
> Department of Statistics and Probability
> Michigan State University
> 1579 I Spartan Village, East Lansing, MI 48823
> wangh...@msu.edu
>
>
>
> On Thu, Dec 13, 2012 at 10:06 PM, Dirk Eddelbuettel wrote:
>
>>
>> Honglang,
>>
>> You are now abusing the free facilities offered by this list.  Your
>> examples
>> are not self-contained [ no sample data or simulated data ] and hence not
>> reproducible.  Your code is complex, and not motivated. And we have told
>> you
>> REPEATEDLY to shorten your code to chunks until it works.
>>
>> On 13 December 2012 at 21:15, Honglang Wang wrote:
>> | I have no idea what's this error.
>>
>> My best guess is that we already explained this to you, but you are not
>> really reading our replies all that closely.  Here is a hint: repeatedly
>> calling an R function is probably not the smartest thing to do in an
>> otherwise complex and hard to decipher program. [1]
>>
>> | I am just wondering whether I need to free some memory in this code.
>>
>> You are also making it pretty clear that you don't really know what you
>> are
>> doing with C++, or else you would not ask this question (and the earlier
>> email people were to polite to reply to).
>>
>> I suggest that you take a deep breath, go for a walk and once you're back,
>> start learning about C++.
>>
>> So please stop emailing the list unless you have something more
>> substantial
>> to post or ask -- and follow common courtesy and list etiquette.
>>
>> Right now you are wasting your time, as well as the time of a few hundred

Re: [Rcpp-devel] How to free memory in Rcpp

2012-12-13 Thread Romain Francois

Le 14/12/12 03:15, Honglang Wang a écrit :

Hi,
Here is the sample code:
// [[Rcpp::export]]
List betahat(Function ker, double t0, NumericMatrix Xr, NumericMatrix
yr, NumericVector tr, double h, int m) {
   int n = Xr.nrow(), p = Xr.ncol();
   arma::mat X(Xr.begin(), n, p, false);
   arma::mat y(yr.begin(), n, 1, false);
   arma::colvec t(tr.begin(), tr.size(), false);
   arma::mat T = X;
   T.each_col() %= (t-t0)/h;
   arma::vec K =as(ker(tr-t0,h))/
m;
   double L1 = arma::accu(K%X.col(0)%X.col(0));
   double L2 = arma::accu(K%X.col(0)%X.col(1));
   double L3 = arma::accu(K%X.col(1)%X.col(1));
   double L4 = arma::accu(K%X.col(0)%T.col(0));
   double L5 = arma::accu(K%X.col(1)%T.col(0));
   double L6 = arma::accu(K%X.col(1)%T.col(1));
   double L7 = arma::accu(K%T.col(0)%T.col(0));
   double L8 = arma::accu(K%T.col(0)%T.col(1));
   double L9 = arma::accu(K%T.col(1)%T.col(1));
   double R1 = arma::accu(K%X.col(0)%y);
   double R2 = arma::accu(K%X.col(1)%y);
   double R3 = arma::accu(K%T.col(0)%y);
   double R4 = arma::accu(K%T.col(1)%y);
   arma::mat L(2*p,2*p);
   L(0,0)=L1;L(0,1)=L2;L(0,2)=L4;L(0,3)=L5;
   L(1,0)=L2;L(1,1)=L3;L(1,2)=L5;L(1,3)=L6;
   L(2,0)=L4;L(2,1)=L5;L(2,2)=L7;L(2,3)=L8;
   L(3,0)=L5;L(3,1)=L6;L(3,2)=L8;L(3,3)=L9;
   arma::mat R(2*p,1);
   R(0,0)=R1;R(1,0)=R2;R(2,0)=R3;R(3,0)=R4;
   arma::vec betahat = arma::solve(L,R);

   arma::colvec betahat0(betahat.begin(),betahat.size()/2,false);
   return List::create(Named("betahat") = betahat0);
}

I will call this function repeatedly, and at some point, it went wrong
with the following error:
Error in betahat(ker, x, X, y, t, h, m) :
   promise already under evaluation: recursive default argument
reference or earlier problems?
Calls: system.time ... apply -> FUN -> betahat -> .External -> cpp_exception
Execution halted

I have no idea what's this error. I am just wondering whether I need to
free some memory in this code. Thanks.


You don't. The explicit constructor/destructor scheme of C++ takes care 
of this automatically for you.


So there is a chance you are victim of a well hidden bug. These are 
usually related to garbage collection and us not making enough 
precaution somewhere. This is very hard to track.


As a wild guess, I think it is because Function return you an 
unprotected SEXP. It does not matter most of the time because you 
consume it, but sometimes the GC will run and collect your object before 
as has a chance to process it.


If my guess is correct, then doing yourself some protection might do the 
trick, something like:


NumericVector result = ker(tr-t0,h) ;
arma::vec K =as(result)/m;

will do the trick since the result of the function call then gets 
protected by the "result" object.


If this does not work, then you can do some debugging as indicated by 
others.


Romain


Best wishes!
Honglang Wang
Office C402 Wells Hall
Department of Statistics and Probability
Michigan State University
1579 I Spartan Village, East Lansing, MI 48823
wangh...@msu.edu 



On Thu, Dec 13, 2012 at 4:57 PM, mailto:rom...@r-enthusiasts.com>> wrote:


Hello,

What memory do you want to free ? Can you give an example of code
where there is memory you'd like to "free" ?

Romain

Le 2012-12-13 22:52, Honglang Wang a écrit :

Dear All,
How to free memory in Rcpp? What's the command? Thanks.

Best wishes!

Honglang Wang

Office C402 Wells Hall
Department of Statistics and Probability
Michigan State University
1579 I Spartan Village, East Lansing, MI 48823
wangh...@msu.edu  [1]


Links:
--
[1] mailto:wangh...@msu.edu 



--
Romain Francois
Professional R Enthusiast
+33(0) 6 28 91 30 30

R Graph Gallery: http://gallery.r-enthusiasts.com

blog:http://romainfrancois.blog.free.fr
|- http://bit.ly/RE6sYH : OOP with Rcpp modules
`- http://bit.ly/Thw7IK : Rcpp modules more flexible

___
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