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 others. Unless you have some 
particular reason to constrain the inputs in some way, I wouldn't add all 
the type declarations, but just leave the function generic.


On Friday, October 14, 2016 at 9:55:21 AM UTC+2, DNF wrote:
>
> 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 function for Matrix and Vector?
>> - 
>> f_scaleRestore(a::Float64, b::Float64, c::Float64) = a * b + c;
>> -  
>> - # version 1
>> - function scaleRestore(Z::Matrix{Float64}, shift::Vector{Float64}, 
>> stretch::Vector{Float64})
>> -   broadcast(f_scaleRestore, Z, stretch', shift')
>> - end
>> -  
>> - # version 2
>> - function scaleRestore(Z::Vector{Float64}, shift::Float64, stretch::
>> Float64)
>> -   broadcast(f_scaleRestore, Z, stretch, shift)
>> - end
>>
>>
>> Thanks in advance,
>> Martin
>>
>

Reply via email to