From luke-tierney at uiowa.edu  Thu Aug 31 00:01:42 2017
From: luke-tierney at uiowa.edu (luke-tierney at uiowa.edu)
Date: Wed, 30 Aug 2017 17:01:42 -0500 (CDT)
Subject: [Rd] loop compilation problem
In-Reply-To: <alpine.DEB.2.20.1708241110230.2616@luke-Latitude>
References: <8EA1A94F-EB30-4AE0-A399-C9F73BC33EB5@oracle.com>
 <alpine.DEB.2.20.1708241110230.2616@luke-Latitude>
Message-ID: <alpine.DEB.2.20.1708301701220.2616@luke-Latitude>

What is happening here is that the compiler makes a legitimate
optimization, but that runs into a long-standing issue, not related to
compilation, with certain assignment expressions in arguments. The
general issue will take some time to address; hopefully it will be
resolved in time for the next major release. In the interim, to avoid
the particular discrepancy reported here the compiler has been
adjusted to not optimize assignments within argument expressions.
This adjustment is in R-devel (r73161) and R-patched (r73162).

Best,

luke

On Thu, 24 Aug 2017, luke-tierney at uiowa.edu wrote:

> Thanks.
>
> Here is a simplified version:
>
> library(compiler)
> zero <- 0
> one <- 1
> expr <- quote((z <- zero + one) + (z <- z + 1))
> eval(compiler::compile(expr))
>
> Sill fix shortly.
>
> Best,
>
> luke
>
> On Thu, 24 Aug 2017, Lukas Stadler wrote:
>
>> Hi!
>>
>> We?ve seen a problem with the compiler in specific cases of matrix 
> updates:
>>
>>> { m <- matrix(1:4, 2) ; z <- 0; for(i in 1) { m[z <- z + 1,z <- z + 1] <- 
> 99; } ; m }
>>     [,1] [,2]
>> [1,]    1    3
>> [2,]    2   99
>>
>> Here, it modifies element [2,2], which is unexpected.
>> It behaves correct without the loop:
>>
>>> { m <- matrix(1:4, 2) ; z <- 0; m[z <- z + 1,z <- z + 1] <- 99 ; m }
>>     [,1] [,2]
>> [1,]    1   99
>> [2,]    2    4
>>
>> ? and without the jit:
>>
>>> enableJIT(0)
>> [1] 3
>>> { m <- matrix(1:4, 2) ; z <- 0; for(i in 1) { m[z <- z + 1,z <- z + 1] <- 
> 99; } ; m }
>>     [,1] [,2]
>> [1,]    1   99
>> [2,]    2    4
>>
>> I checked with "R Under development (unstable) (2017-08-23 r73116)?, and 
> the problem is still there.
>>
>> - Lukas
>> ______________________________________________
>> R-devel at 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 and        Fax:               319-335-3017
    Actuarial Science
241 Schaeffer Hall                  email:   luke-tierney at uiowa.edu
Iowa City, IA 52242                 WWW:  http://www.stat.uiowa.edu


[Rd] loop compilation problem
luke-tierney at uiowa.edu