Re: [Rd] a question about optim.R and optim.c in R

2014-07-07 Thread Michael Weylandt


> On Jul 7, 2014, at 4:34 PM, Zhiyuan Dong  wrote:
> 
> Hi, I am learning R by reading R source code. Here is one question I have
> about the optim function in R.
> 
> The context : In the optim.R, after all the prep steps, the main function
> call call is made via :
> 
> .External2(C_optim, par, fn1, gr1, method, con, lower, upper).
> 
> So, it seems to me, to follow what is going on from here, that I should
> read the optim function in \src\library\stats\src\optim.c
> 
> where it has this signature :
> 
> SEXP optim(SEXP call, SEXP op, SEXP args, SEXP rho)
> 
> I am not sure I follow here : In the .External2 call, we have 7 parameters
> :  par, fn1, gr1, method, con, lower, upper; This does not seem to match
> the signature of
> 
> SEXP optim(SEXP call, SEXP op, SEXP args, SEXP rho)
> 
> However, it seems (from the source code) that the 7 parameters are somehow
> embedded in the 'args' parameter. I am not sure what is going on...Am I
> missing something?
> 

IIRC, args is a pairlist object. If the analogy helps, it's something like the 
OO pattern of sticking all your function parameters in an argument and passing 
that instead of passing them all as formals. One advantage of this is sane(er) 
handling of variadic functions at the C level. 

Michael


> Thanks much!!!
> 
> Best,
> 
> Zhiyuan
> 
>[[alternative HTML version deleted]]
> 
> __
> 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


Re: [Rd] a question about optim.R and optim.c in R

2014-07-07 Thread Sarah Goslee
Hi,

On Mon, Jul 7, 2014 at 4:34 PM, Zhiyuan Dong  wrote:
> Hi, I am learning R by reading R source code.

That's very brave of you.

You might also try reading some of the documentation and contributed
documentation, like:
http://adv-r.had.co.nz/C-interface.html
and
http://cran.r-project.org/doc/manuals/r-devel/R-exts.html

Sarah


Here is one question I have
> about the optim function in R.
>
> The context : In the optim.R, after all the prep steps, the main function
> call call is made via :
>
> .External2(C_optim, par, fn1, gr1, method, con, lower, upper).
>
> So, it seems to me, to follow what is going on from here, that I should
> read the optim function in \src\library\stats\src\optim.c
>
> where it has this signature :
>
> SEXP optim(SEXP call, SEXP op, SEXP args, SEXP rho)
>
> I am not sure I follow here : In the .External2 call, we have 7 parameters
> :  par, fn1, gr1, method, con, lower, upper; This does not seem to match
> the signature of
>
> SEXP optim(SEXP call, SEXP op, SEXP args, SEXP rho)
>
> However, it seems (from the source code) that the 7 parameters are somehow
> embedded in the 'args' parameter. I am not sure what is going on...Am I
> missing something?
>
> Thanks much!!!
>
> Best,
>
> Zhiyuan
>

-- 
Sarah Goslee
http://www.functionaldiversity.org

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


[Rd] a question about optim.R and optim.c in R

2014-07-07 Thread Zhiyuan Dong
Hi, I am learning R by reading R source code. Here is one question I have
about the optim function in R.

The context : In the optim.R, after all the prep steps, the main function
call call is made via :

.External2(C_optim, par, fn1, gr1, method, con, lower, upper).

So, it seems to me, to follow what is going on from here, that I should
read the optim function in \src\library\stats\src\optim.c

where it has this signature :

SEXP optim(SEXP call, SEXP op, SEXP args, SEXP rho)

I am not sure I follow here : In the .External2 call, we have 7 parameters
:  par, fn1, gr1, method, con, lower, upper; This does not seem to match
the signature of

SEXP optim(SEXP call, SEXP op, SEXP args, SEXP rho)

However, it seems (from the source code) that the 7 parameters are somehow
embedded in the 'args' parameter. I am not sure what is going on...Am I
missing something?

Thanks much!!!

Best,

Zhiyuan

[[alternative HTML version deleted]]

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


Re: [Rd] blas test problem

2014-07-07 Thread Martyn Plummer
I can reproduce this. It is a bug in reference BLAS.

With the R 3.1.0 release, Fedora changed from using the internal BLAS
that comes with R to using external BLAS. But reference BLAS does not
handle missing values correctly.  I expect this has been true since at
least 2010, when Brian patched the R copy of BLAS, but the bug has only
been revealed by the Fedora policy change.

I am taking this over to R-SIG-Fedora where we can discuss the issue
with Tom Callaway from Red Hat.

Martyn

On Fri, 2014-07-04 at 12:13 +0100, lejeczek wrote:
> later I tried plain-vanilla, well.. redhats' and derivatives 
> default packages and they all fail:
> 
>  > ## PR#4582 %*% with NAs
>  > stopifnot(is.na(NA %*% 0), is.na(0 %*% NA))
>  > ## depended on the BLAS in use.
>  >
>  >
>  > ## found from fallback test in slam 0.1-15
>  > ## most likely indicates an inaedquate BLAS.
>  > x <- matrix(c(1, 0, NA, 1), 2, 2)
>  > y <- matrix(c(1, 0, 0, 2, 1, 0), 3, 2)
>  > (z <- tcrossprod(x, y))
>   [,1] [,2] [,3]
> [1,]   NA   NA0
> [2,]210
>  > stopifnot(identical(z, x %*% t(y)))
> Error: identical(z, x %*% t(y)) is not TRUE
> Execution halted
> 
> 
> I've tried scientificLinux, Centos, Oracle
> all versions of R => 3.0 these linux distribution provide
> hardware are AMD various CPU based platform
> 
> 
> On 30/06/14 10:45, peter dalgaard wrote:
> > It is not clear what you mean:
> >
> > The quoted page lists particular AMD BLAS versions that fail R's regression 
> > test.
> >
> > Other builds of R would run the regression test during building and you can 
> > run them yourself if you get the source code (for good measure, use the 
> > current version, not one from a 2011 web posting, i.e., fetch say 
> > https://svn.r-project.org/R/branches/R-3-1-branch/tests/reg-BLAS.R).
> >
> > E.g., for me
> >
> > Peters-iMac:R pd$ ../BUILD/bin/R --vanilla < tests/reg-BLAS.R
> > ... normal output, no errors ...
> >
> > There is some risk that binary builds of R on one machine will fail on 
> > another. If this happens, it could be quite serious, so developers would 
> > want to know. However "most...seem to fail" is not enough to act upon. What 
> > exactly did you do, on which computing platform, and what happened that 
> > makes you believe that it had failed?
> >
> > -pd
> >
> > On 27 Jun 2014, at 13:38 , lejeczek  wrote:
> >
> >> dear developers
> >>
> >> I myself am not a prog-devel, I found this
> >>
> >> http://devgurus.amd.com/message/1255852#1255852
> >>
> >> Most R compilations/installations I use seem to fail this test, is this a 
> >> problem and if yes then how serious is it?
> >>
> >> regards
> >>
> >> __
> >> 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

---
This message and its attachments are strictly confidenti...{{dropped:8}}

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