If you want to extend functions that only require the vectors of the arg vector, this should do this:
macro vectorize_on_2nd(S, f) S = esc(S); f = esc(f); N = esc(:N) quote ($f){$N}(a, x::AbstractArray{$S, $N}) = reshape([($f)(a, x[i]) for i in eachindex(x)], size(x)) end end
Used as follows:
@vectorize_on_2nd Int64 myfunc
This should give you the myfunc{N}(::Any, ::AbstractArray{Int64,N}) method myfunc{N}(::Any, ::AbstractArray{Int64,N}) .
source share