There are the codes:
struct A{T}
n::T
end
(a::A{Int})(x::Vector) = begin
res = similar
for i = 1 : size(x, 1)
res[i] = x[i]
end
res
end
(a::A{Float64})(x::Vector) = begin
res = similar
@threads for i = 1 : size(x, 1)
res[i] = x[i]
end
res
end
When a.n isa Int, I need the loop block runs on main thread,and when a.n isa Float64, I need that runs on multi threads. But the two methods isa all same except only the @threads. Is there a way I can combine the two dispatched methods? Like:
(a::A{T})(x::Vector) where {T} = begin
res = similar
func(a) for i = 1 : size(x, 1)
res[i] = x[i]
end
res
end
func(a::A{Int}) = @inbounds
func(a::A{Float64) = @threads