Re: [Rd] Result of 'seq' doesn't use compact internal representation

2018-05-31 Thread luke-tierney

This is now resolved in R-devel and R_patched.

Best,

luke

On Sun, 29 Apr 2018, Luke Tierney wrote:


Thanks -- I'll commit a fix after some testing.

Best,

luke

On 04/29/2018 06:22 AM, Duncan Murdoch wrote:

On 28/04/2018 11:11 PM, Suharto Anggono Suharto Anggono via R-devel wrote:

.Internal(inspect(1:10))

@300e4e8 13 INTSXP g0c0 [NAM(3)]  1 : 10 (compact)

.Internal(inspect(seq(1,10)))

@3b6e1f8 13 INTSXP g0c4 [] (len=10, tl=0) 1,2,3,4,5,...

system.time(1:1e7)

    user  system elapsed
   0   0   0

system.time(seq(1,1e7))

    user  system elapsed
    0.05    0.00    0.04

It seems that result of function 'seq' doesn't use compact internal 
representation. However, looking at the code of function 'seq.default', 
seq(1,n) produces 1:n. What is going on?


It looks like it is related to using compiled or interpreted code:

 > library(gtools)
 > seq2 <- unByteCode(seq.default)
 > .Internal(inspect(seq.default(1,10)))
@7fa53847dcd8 13 INTSXP g0c4 [] (len=10, tl=0) 1,2,3,4,5,...
 > .Internal(inspect(seq2(1,10)))
@7fa537fa0bf0 13 INTSXP g0c0 [NAM(3)]  1 : 10 (compact)

Duncan Murdoch




h <- seq.default
environment(h) <- .GlobalEnv
library(compiler)
enableJIT(0)

[1] 3

.Internal(inspect(h(1,10)))

@375ade8 13 INTSXP g0c0 [NAM(3)]  1 : 10 (compact)

A non-byte-compiled version of function 'seq.default' can produce object 
that uses compact internal representation.




sessionInfo()

R version 3.5.0 (2018-04-23)
Platform: i386-w64-mingw32/i386 (32-bit)
Running under: Windows XP (build 2600) Service Pack 3

Matrix products: default

locale:
[1] LC_COLLATE=English_United States.1252
[2] LC_CTYPE=English_United States.1252
[3] LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C
[5] LC_TIME=English_United States.1252

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

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel



__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel





--
Luke Tierney
Ralph E. Wareham Professor of Mathematical Sciences
University of Iowa  Phone: 319-335-3386
Department of Statistics andFax:   319-335-3017
   Actuarial Science
241 Schaeffer Hall  email:   luke-tier...@uiowa.edu
Iowa City, IA 52242 WWW:  http://www.stat.uiowa.edu
__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


[Rd] Understanding the sequence of events when calling the R dpois function

2018-05-31 Thread Jason Serviss
Hello all,

I am trying to get a better understanding of the underlying code for the 
stats::dpois function in R and, specifically, what happens under the hood when 
it is called. I finally managed to track down the C course at: 
https://github.com/wch/r-source/blob/trunk/src/nmath/dpois.c. It would seem 
that the dpois C function is taking a double for each of the x and lambda 
arguments so I am a bit confused why I can provide a vector and matrix to dpois 
in R, e.g.

dpois(1:5, matrix(runif(2*5, 1, 10), nrow = 5)))

and get a matrix back with the results. Due to this, I was expecting to see a 
loop, or similar, in the underlying C source but… to no avail. So I have to 
conclude that either a) there is a step between when I call dpois in R and the 
C code getting executed that loops over the inputs or b) that there is a 
construct in the C code (my proficiency here is limited) that is called per 
input. Any help in enlightening me on what code is responsible for iterating 
over the multiple inputs (or if someone is feeling energetic, the exact 
stepwise code that is executed when calling dpois) would be greatly 
appreciated!!

Kind Regards,
Jason Serviss


[[alternative HTML version deleted]]

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] Understanding the sequence of events when calling the R dpois function

2018-05-31 Thread Berry, Charles


> On May 31, 2018, at 8:25 AM, Jason Serviss  wrote:
> 
> Hello all,
> 
> I am trying to get a better understanding of the underlying code for the 
> stats::dpois function in R and, specifically, what happens under the hood 
> when it is called. I finally managed to track down the C course at: 
> https://github.com/wch/r-source/blob/trunk/src/nmath/dpois.c. It would seem 
> that the dpois C function is taking a double for each of the x and lambda 
> arguments so I am a bit confused why I can provide a vector and matrix to 
> dpois in R, e.g.
> 
> dpois(1:5, matrix(runif(2*5, 1, 10), nrow = 5)))
> 
> and get a matrix back with the results. Due to this, I was expecting to see a 
> loop, or similar, in the underlying C source but… to no avail. So I have to 
> conclude that either a) there is a step between when I call dpois in R and 
> the C code getting executed that loops over the inputs or b) that there is a 
> construct in the C code (my proficiency here is limited) that is called per 
> input. Any help in enlightening me on what code is responsible for iterating 
> over the multiple inputs (or if someone is feeling energetic, the exact 
> stepwise code that is executed when calling dpois) would be greatly 
> appreciated!!

Have a look at arithmetic.c. The math2 function handles calling dpois in a 
vectorized fashion.  

You need to trace how it is that the compiler knows to use dpois.c in 
constructing `C_dpois' which is what the R function dpois is calling.

If you know how to grep the sources for dpois, that will get you started. You 
will need to look over a bunch of #define's and a few C utilities to see how it 
all fits together. 

If you dig in and find the `do { ... } while(0)' construct confusing you might 
look at

https://stackoverflow.com/questions/257418/do-while-0-what-is-it-good-for

HTH,

Chuck
__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] Understanding the sequence of events when calling the R dpois function

2018-05-31 Thread Greg Minshall
Jason,

as Chuck Berry (to whom, *thanks* for 'do {...} while(0)'!) suggested,
using grep, or even grep executed from find, such as

find . -type f -exec grep -H "dpois" \{\} \; | less

(executed from the root of an R source tree), is your friend.

cheers, Greg

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel