That's a great feature Andreas!

Do you mean like this:

a = rand(5)
b = zeros(5,5)
b += Diagonal(a)

Because I get a no method +(Array{Float64,2},Diagonal{Float64}) ...

I'm on 0.2 and a fairly old commit right now, so that might be the reason.
Julia Version 0.2.0
Commit 05c6461 (2013-11-16 23:44 UTC)
Platform Info:
  System: Darwin (x86_64-apple-darwin12.5.0)
  WORD_SIZE: 64
  BLAS: libgfortblas
  LAPACK: liblapack
  LIBM: libopenlibm

-- Oliver

Den onsdag den 21. maj 2014 07.33.01 UTC+2 skrev Andreas Noack Jensen:
>
> Please consider b += Diagonal(c) instead of diagm. Diagonal(c) only stores 
> the diagonal elements but works like diagm(c) for matrix arithmetic
>
> Vectorized code is always easier to understand
>
>
> That is a strong statement. I have vectorised MATLAB code with repmat and 
> meshgrids that is completely unreadable, but would be fairly easy to follow 
> if written as loops. I really enjoy that I can just write a loop in Julia 
> without slow execution.
>
>
> 2014-05-21 5:15 GMT+02:00 Joey Huchette <joehu...@gmail.com <javascript:>>
> :
>
>> Perhaps a setdiag!(b,a) function would be handy.
>>
>>
>> On Tuesday, May 20, 2014 10:46:28 PM UTC-4, gael....@gmail.com wrote:
>>>
>>> While I cannot not agree with this ;), I'd like to state that:
>>> 1) High level functions might leverage clever algorithms faster than 
>>> plain loops (best example comming to mind: dot).
>>> 2) Vectorized code is always easier to understand, write, fix and 
>>> maintain because the intent is clear from the start. You equation is 
>>> written just as it was on paper and not burried within nested loops among 
>>> many explicit indices.
>>> Moreover, Julia will get better at devectorizing and at avoiding 
>>> temporaries.
>>>
>>> Therefore I would recommand using explicit loops only when *proved* to 
>>> provide a necessary speedup or a memory gain.
>>>
>>> In this case diagm is working just as intended and saving 20ns on matrix 
>>> construction just seem silly. I perfectly understand your point though but 
>>> explicit loops have downsides too.
>>>
>>> Profile first, optimize later... Comment now!  ;)
>>>
>>>
>
>
> -- 
> Med venlig hilsen
>
> Andreas Noack Jensen
>  

Reply via email to