Re: [Rd] ifelse() woes ... can we agree on a ifelse2() ?

2016-08-08 Thread Martin Maechler
> Uwe Ligges 
> on Sun, 7 Aug 2016 09:51:58 +0200 writes:

> On 06.08.2016 17:30, Duncan Murdoch wrote:
>> On 06/08/2016 10:18 AM, Martin Maechler wrote:

   [.]

>>> Of course, an ifelse2()  should also be more efficient than
>>> ifelse() in typical "atomic" cases.
>> 
>> I don't think it is obvious how to make it more efficient.  ifelse()
>> already skips evaluation of yes or no if not needed.  (An argument could
>> be made that it would be better to guarantee evaluation of both, but
>> it's usually easy enough to do this explicitly, so I don't see a need.)

> Same from here: I do not see how this can easily be made more efficient, 
> since evaluating ony parts causes a lot of copies of objects whichs 
> slows stuff down, hence you need some complexity in yes and no to make 
> evaluations of parts of them more efficient on R level.

Yes, Duncan and Uwe are right, and my comment "wish" above was
mostly misleading.  Some of the many small changes to ifelse()
since its initial [1998, R version 0.63.3] simple

ifelseR0633 <- function (test, yes, no)
{
ans <- test
test <- as.logical(test)
nas <- is.na(test)
ans[ test] <- rep(yes, length = length(ans))[ test]
ans[!test] <- rep(no,  length = length(ans))[!test]
ans[nas] <- NA
ans
}

were exactly for adding speed in some of these cases.

> Anyway, to solve the problem, we may want an add argument to ifelse2() 
> that allows for specification of the type of the result (as vapply does)?

A good idea, probably only needed / desirable if we'd consider a
C based version {as vapply} but for the moment I did not want to
go there.

The current ifelse() is nice with "pre-S3" objects, such as
as atomic (named) vectors and (dimnamed) arrays, including matrices,
by keeping most attributes for those... and does that relatively
efficiently.

What I really meant, not above, but earlier when talking about
ifelse()'s inefficiency should really *not* have been related to
this thread, I'm sorry for that confusion.

I mean the fact that many many usages of ifelse() are of the
form
ifelse(logiFn(x), f1(x), f2(x))

  {with f1() or f2() often even being constant}

and e.g.,  in the case where logiFn(x) gives few TRUEs and f1(.)
is expensive and f2(.) very cheap (say "constant" NA), it is
much more efficient to use

 ans <- x
 Y <- logiFn(x)
 ans[ Y] <- f1(x[ Y])
 ans[!Y] <- f2(x[!Y])

as the expensive function is only called on a small subset of
the full x.

I'm working at the main topic and *am* thanking Duncan
for his conceptual analysis and the (few) proposals.

Martin

> Best,
> Uwe

>> Duncan Murdoch
>> 
>>> 
>>> 
>>> Thank you for your ideas and suggestions.
>>> Again, there's no promise of implementation coming along with this
>>> e-mail.
>>> 
>>> Martin Maechler
>>> ETH Zurich

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


[Rd] Is it intentional that the Fortran optimization flags changefrom O3 to O2 on Windows?

2016-08-08 Thread Avraham Adler
When compiling R-devel (2016-08-07) on Windows (64bit) using Rtools
(3.4.0), the C++ optimization flags are manually changed to -O2 from
-O3. This has been the situation for years, and I believe this is to
prevent certain optimizations which may cause downstream problems. In
R_HOME/src/gnuwin32/fixed/etc/Makeconf, this is seen by the -O2
entries in the CXXFLAGS and CXX1XFLAGS variables. The FFLAGS and
FCFLAGS entries in Makeconf still show -O3.

When looking at R_HOME/etc/x64/Makeconf, however, the entries for
FCFLAGS and FFLAGS are -O2. My hunch is that in
R_HOME/src/gnuwin32/fixed/Makefile, line 29 is changing ALL O3 to O2,
and not just those relating to C++:


  ifeq "$(WIN)" "64"
$(SED) -e 's/WIN = 32/WIN = 64/' \
  -e "s/-O3/-O2/" \
  ...


Is this intentional? If not, is there a way to keep O3 optimization
with FORTRAN outside of quickly editing Makeconf before R's
compilation gets to using it?

Thank you,

Avi

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


[Rd] Setting Gnu++11 when compiling R-devel on Windows

2016-08-08 Thread Avraham Adler
Recently, there have been changes to R-devel to make it more
compatible with GCC 6.x, which is great. Unfortunately, Windows still
uses a toolset based on GCC 4.9.3.

When compiling R release or R-patched, one can have GCC called with
-std=gnu++11 by having it in the CXXFLAGS in one's HOME/.R/Makevars as
well as by overwriting CXX1XSTD in
R_HOME/src/gnuwin32/fixed/etc/Makeconf.

When trying the same procedure for R-devel (08-04 and 08-07) I see
that g++ is called without -std=gnu++11. I tried adding the call to
the CXX1YSTD flag as well (although that should be reserved for C++14)
and it did not help.

I can probably force it by adding it to the CXXFLAGS and CXX1XFLAGS in
Makeconf, but that seems to be somewhat overkill and may have
downstream effects of which I am unaware.

Am I correct in my assumption that the new CXXSTD macro as discussed
in the changelogs is automatically setting GCC 4.9.3 to C++98, and if
so, is there a similar way to R-3.3 to have GCC default to gnu++11
outside of forcing it in the general flags? If I am incorrect, I would
appreciate being pointed in the proper direction.

Thank you,

Avi

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