Hello,
I’m working with AbstractArray
s, and I would like to execute a method foo
that takes two AbstractArray
s when the number of dimensions of the first arrays is twice that of the first’s. An error should be thrown otherwise.
The only way I could achieve this is with @eval
but with a finite number of dimensions. A MWE follows.
const ndimmax = 10
for n in 1:ndimmax
@eval foo(::AbstractArray{S, $(2n)}, ::AbstractArray{T, $n}) where {S, T} = println("do something...")
end
This does the job as long as the number of dimensions remains small:
julia> foo(rand(10, 10), rand(10))
do something...
However I was wondering if there is another way I could achieve this ? It wouldn’t make sense to use @generated
functions since the value type parameters would be outside the quote…
Thanks!
V.