Hey all,
I’m struggling to implement a certain problem.
My current situation is the following: Some parts of my project consist of using Tullio functions. Since my arrays can be of arbitrary dimensions and I want to apply some user specific operations on them, I was creating functions with meta programming to compose the different Tullio expressions.
This minimal working example somehow shows my use case:
# function to create a complex expression
function N_dim(dim)
if dim == 1
return Meta.parse("arr[1, 1] .+ arr[1, 2]")
else
return Meta.parse("arr[1] .+ arr[2]")
end
end
# convenient wrapper to create a function from that expression
function make_f(dim)
f = @eval arr -> $(N_dim(dim))
return f
end
# a function from which our f should be called
function foo()
f = make_f(1)
@show f([1 2; 3 4]) # fails here
return 0
end
foo()
As known, this case runs into the world age issue:
ERROR: MethodError: no method matching (::var"#21#22")(::Int64)
The applicable method may be too new: running in world age 27854, while current world is 27855.
I somehow grasped the issue of that and already read a lot of regarded posts. However, in my case I can’t really use Base.invokelatest
because I want to pass that function into Zygote.jl. Furthermore this function is performance critical and should be as fast as possible (hence the reason for using Tullio).
I would be really happy if someone could help me in solving that issue. Generating functions for different inputs at compile time is not really feasible since my real make_f
has several input parameters.
Thanks,
Felix