The devectorize package https://github.com/lindahua/Devectorize.jl can deal 
with this:
f(x) = @devec x[:]=2.*x

'f' won't allocate any new memory.

On Wednesday, February 19, 2014 12:11:02 PM UTC-8, Tim Holy wrote:
>
> Unfortunately, I'm pretty sure you can't do what you're hoping for. 
> Consider: 
>
> julia> A = rand(2,2) 
> 2x2 Array{Float64,2}: 
>  0.63259   0.109017 
>  0.667425  0.112597 
>
> julia> pointer(A) 
> Ptr{Float64} @0x000000000446f6a0 
>
> julia> A *= 2 
> 2x2 Array{Float64,2}: 
>  1.26518  0.218033 
>  1.33485  0.225195 
>
> julia> pointer(A) 
> Ptr{Float64} @0x0000000005696650 
>
> I think A *= 2 gets translated by the parser into A = A*2. There are some 
> old 
> posts that can do a better job than I explaining why this is important. 
>
> So I think your only bet is to do something like this: 
>
> for i = 1:length(A) 
>     A[i] *= 2 
> end 
>
> which does work in-place. 
>
> --Tim 
>
> On Wednesday, February 19, 2014 11:26:48 AM Madeleine Udell wrote: 
> > Currently in-place arithmetic operations turn shared arrays into normal 
> > ones: eg 
> > 
> > b = Base.shmem_randn(10) 
> > b *= 2 
> > 
> > results in b becoming a (not-shared) array. I'd like to overload these 
> > in-place arithmetic operations so that instead of writing 
> > 
> > typeof(b)==SharedArray? b.s *= 2 : b *= 2 
> > 
> > I can just write 
> > 
> > b *= 2 
> > 
> > and know that the shared status of my array will be preserved. How might 
> > one overload these operations? 
> > 
> > (Note: I don't want c = b + b to automatically create a shared array c, 
> > since that allocates new shared memory.) 
>

Reply via email to