Re: [julia-users] Re: Correct way to define function and function!

2015-08-23 Thread Stefan Karpinski
Yes, this is a common way to do this. Usually to get the non-mutating behavior you need to make a copy first anyway. (Some languages just do so implicitly and don't allow anything else.) Sometimes, as Kristoffer mentions, there might be a way to construct a new object directly instead of

Re: [julia-users] Re: Correct way to define function and function!

2015-08-22 Thread Timothée Poisot
Thanks for these infos. I will definitely pre-allocate memory (in fact I do in the real code). t Le samedi 22 août 2015 à 14:24 -0700, Sisyphuss a écrit : I don't think it's much less efficient to copy` in your second example. In the second function., you should allocate memory for `y`

[julia-users] Re: Correct way to define function and function!

2015-08-22 Thread Kristoffer Carlsson
What do you mean copying the object is inefficient? Do you mean that it is cheaper to build it from scratch than to start with the copy? On Saturday, August 22, 2015 at 9:51:48 PM UTC+2, Timothée Poisot wrote: Hi, I caught myself wondering about the correct way to use function and

[julia-users] Re: Correct way to define function and function!

2015-08-22 Thread Sisyphuss
Another (maybe better) option is ``` baz!(z,x) = begin ... return z; end baz(x) = baz!(similar(x),x) ``` You can call them by ``` baz!(x,x) z = baz(x) ``` On Saturday, August 22, 2015 at 11:24:51 PM UTC+2, Sisyphuss wrote: I don't think it's much less efficient to copy` in your second