[julia-users] Re: Merge functions from different headers (Matrix vs. Vector)

2016-10-14 Thread DNF
On Friday, October 14, 2016 at 3:16:31 PM UTC+2, Martin Florek wrote: > > Thank you very much. This is very elegant way, I think that it solve my > problem. > You're welcome. If you are looking to improve performance further, you could add @inbounds and @simd macro calls, as seen here:

[julia-users] Re: Merge functions from different headers (Matrix vs. Vector)

2016-10-14 Thread DNF
As a proposal, this is what I would do, given you requirements: function _scaleRestore!(Z, Zout, shift, stretch) for j in 1:size(Z, 2), i in 1:size(Z, 1) Zout[i, j] = Z[i, j] * stretch[j] + shift[j] end return Zout end scaleRestore!(Z::Vector, shift::Number, stretch::Number) =

[julia-users] Re: Merge functions from different headers (Matrix vs. Vector)

2016-10-14 Thread DNF
I don't know of any way to accomplish what you want with a single method signature. I don't see how Union can help you, because you would not be able to disallow (Vector x Vector x Vector) input, for example. You normally achieve this in Julia by writing two separate methods, which is what you

[julia-users] Re: Merge functions from different headers (Matrix vs. Vector)

2016-10-14 Thread DNF
Hmm. I slightly misread the way you had set up your code. I thought you wanted your code to cover three cases: all scalar, one vector - two scalars, and one matrix - two vectors. So to be clear: defining the function: scaleRestore(a, b, c) = a .* b' .+ c' covers both your cases and then some

[julia-users] Re: Merge functions from different headers (Matrix vs. Vector)

2016-10-14 Thread DNF
This should work for the three cases you have set up: f_scaleRestore(a, b, c) = a .* b' .+ c' On Friday, October 14, 2016 at 9:12:55 AM UTC+2, Martin Florek wrote: > > Hi all, > > I have the following two functions and I want to sensibly merge them into > one. How to marge headers and body of