Interesting, because in many cases that would be suboptimal. (If I was doing some big computation and saving output to a variable.) Hmm, so can anyone explain what is the optimal thing to do in here? Actually I would guess that if the variable is only pointing to other variable it would be optimized away, but if some function call would be present than the compiler cannot be sure and will allocate some memory, didn’t test it though, but would make sense to me.
Thanx anyway. On Aug 6, 2014, at 2:35 PM, Ivar Nesje <[email protected]> wrote: > If you look at the compiled code, they seems to be equal > > a = test(1,1.) > > > julia> @code_native test2(a) > .section __TEXT,__text,regular,pure_instructions > Filename: none > Source line: 2 > push RBP > mov RBP, RSP > Source line: 2 > vcvtsi2sd XMM0, XMM0, QWORD PTR [RDI + 8] > vaddsd XMM0, XMM0, QWORD PTR [RDI + 16] > pop RBP > ret > > julia> @code_native test1(a) > .section __TEXT,__text,regular,pure_instructions > Filename: none > Source line: 4 > push RBP > mov RBP, RSP > Source line: 4 > vcvtsi2sd XMM0, XMM0, QWORD PTR [RDI + 8] > vaddsd XMM0, XMM0, QWORD PTR [RDI + 16] > pop RBP > ret > > Not sure how complex things get before they become different. > > kl. 14:21:24 UTC+2 onsdag 6. august 2014 skrev Tomas Krehlik følgende: > In many cases I have chunks of code that take up too much space and worsen > readability of code in Julia. For example, I have some object on input, which > has many parameters and their particular combination is often used in > subsequent code. (In particular, I have an object containing Vector > Autoregression, which has number of observations and lags, etc. and those are > often combined in specifications of degrees of freedom, etc.) Is there some > macro, which would allow me to specify some "variables" without allocating > memory to those variables. I have in mind something like this: > > type test > a::Int64 > b::Float64 > function test(c::Int64, d::Float64) > new(c, d) > end > end > > function test1(ok::test) > a = ok.a > b = ok.b > return a + b > end > > function test2(ok::test) > return ok.a + ok.b > end > where I would like some macro to make test1 equal to test2. >
