-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Issues with mk_function Typeable trait and blocks #18
Comments
The second one looks like it's an issue with using oop_ex = :(function func(u, p, t)
X = let (x, y, z, σ, ρ, β) = (u[1], u[2], u[3], p[1], p[2], p[3])
((*)(σ, (-)(y, x)), (-)((*)(x, (-)(ρ, z)), y), (-)((*)(x, y), (*)(β, z)))
end
T = promote_type(map(typeof, X)...)
convert.(T, X)
construct = if u isa (ModelingToolkit.StaticArrays).StaticArray
(ModelingToolkit.StaticArrays).similar_type(typeof(u), eltype(X))
else
x->begin
du = similar(u, T, 3)
vec(du) .= x
du
end
end
construct(X)
end
)
iip_ex = :(function (A, u, p, t)
let (x, y, z, σ, ρ, β) = (u[1], u[2], u[3], p[1], p[2], p[3])
A[1] = (*)(σ, (-)(y, x))
A[2] = (-)((*)(x, (-)(ρ, z)), y)
A[3] = (-)((*)(x, y), (*)(β, z))
end
nothing
end
) is fine. Maybe it needs to check if |
Okay, that's simply due to a purposeful design. Currently |
For reference I'm getting: Not implemented trait GeneralizedGenerated.Typeable for (typeof(typeof)).
error(::String) at error.jl:33
GeneralizedGenerated.Typeable(::Type) at Typeclasses.jl:144
to_type(::typeof(typeof)) at Typeclasses.jl:45
(::getfield(GeneralizedGenerated, Symbol("##7#8")){DataType})(::Function, ::Type) at typeable.jl:43
mapfoldr_impl(::typeof(identity), ::getfield(GeneralizedGenerated, Symbol("##7#8")){DataType}, ::NamedTuple{(:init,),Tuple{DataType}}, ::Array{Any,1}, ::Int64) at reduce.jl:105
#mapfoldr#189 at reduce.jl:125 [inlined]
#mapfoldr at none:0 [inlined]
#foldr#190 at reduce.jl:144 [inlined]
#foldr at none:0 [inlined]
to_typelist(::Array{Any,1}) at typeable.jl:42
##GeneralizedGenerated 19#389 at typeable.jl:64 [inlined]
(::getfield(GeneralizedGenerated, Symbol("###to_type#383#12")))(::Expr) at typeable.jl:63
to_type(::Expr) at Typeclasses.jl:45
(::getfield(GeneralizedGenerated, Symbol("##7#8")){DataType})(::Expr, ::Type) at typeable.jl:43
mapfoldr_impl(::typeof(identity), ::getfield(GeneralizedGenerated, Symbol("##7#8")){DataType}, ::NamedTuple{(:init,),Tuple{DataType}}, ::Array{Any,1}, ::Int64) at reduce.jl:102
#mapfoldr#189 at reduce.jl:125 [inlined]
#mapfoldr at none:0 [inlined]
#foldr#190 at reduce.jl:144 [inlined]
#foldr at none:0 [inlined]
to_typelist(::Array{Any,1}) at typeable.jl:42
##GeneralizedGenerated 19#389 at typeable.jl:64 [inlined]
(::getfield(GeneralizedGenerated, Symbol("###to_type#383#12")))(::Expr) at typeable.jl:63
to_type(::Expr) at Typeclasses.jl:45
(::getfield(GeneralizedGenerated, Symbol("##7#8")){DataType})(::Expr, ::Type) at typeable.jl:43
mapfoldr_impl(::typeof(identity), ::getfield(GeneralizedGenerated, Symbol("##7#8")){DataType}, ::NamedTuple{(:init,),Tuple{DataType}}, ::Array{Any,1}, ::Int64) at reduce.jl:105
#mapfoldr#189 at reduce.jl:125 [inlined]
#mapfoldr at none:0 [inlined]
#foldr#190 at reduce.jl:144 [inlined]
#foldr at none:0 [inlined]
to_typelist(::Array{Any,1}) at typeable.jl:42
##GeneralizedGenerated 19#389 at typeable.jl:64 [inlined]
(::getfield(GeneralizedGenerated, Symbol("###to_type#383#12")))(::Expr) at typeable.jl:63
to_type(::Expr) at Typeclasses.jl:45
(::getfield(GeneralizedGenerated, Symbol("##7#8")){DataType})(::Expr, ::Type) at typeable.jl:43
mapfoldr_impl(::typeof(identity), ::getfield(GeneralizedGenerated, Symbol("##7#8")){DataType}, ::NamedTuple{(:init,),Tuple{DataType}}, ::Array{Any,1}, ::Int64) at reduce.jl:102
#mapfoldr#189 at reduce.jl:125 [inlined]
#mapfoldr at none:0 [inlined]
#foldr#190 at reduce.jl:144 [inlined]
#foldr at none:0 [inlined]
to_typelist(::Array{Any,1}) at typeable.jl:42
##GeneralizedGenerated 19#389 at typeable.jl:64 [inlined]
(::getfield(GeneralizedGenerated, Symbol("###to_type#383#12")))(::Expr) at typeable.jl:63
to_type(::Expr) at Typeclasses.jl:45
(::getfield(GeneralizedGenerated, Symbol("##7#8")){DataType})(::Expr, ::Type) at typeable.jl:43
mapfoldr_impl(::typeof(identity), ::getfield(GeneralizedGenerated, Symbol("##7#8")){DataType}, ::NamedTuple{(:init,),Tuple{DataType}}, ::Array{Any,1}, ::Int64) at reduce.jl:102
#mapfoldr#189 at reduce.jl:125 [inlined]
#mapfoldr at none:0 [inlined]
#foldr#190 at reduce.jl:144 [inlined]
#foldr at none:0 [inlined]
to_typelist(::Array{Any,1}) at typeable.jl:42
##GeneralizedGenerated 19#389 at typeable.jl:64 [inlined]
(::getfield(GeneralizedGenerated, Symbol("###to_type#383#12")))(::Expr) at typeable.jl:63
to_type(::Expr) at Typeclasses.jl:45
(::getfield(GeneralizedGenerated, Symbol("##7#8")){DataType})(::Expr, ::Type) at typeable.jl:43
mapfoldr_impl(::typeof(identity), ::getfield(GeneralizedGenerated, Symbol("##7#8")){DataType}, ::NamedTuple{(:init,),Tuple{DataType}}, ::Array{Any,1}, ::Int64) at reduce.jl:102
#mapfoldr#189 at reduce.jl:125 [inlined]
#mapfoldr at none:0 [inlined]
#foldr#190 at reduce.jl:144 [inlined]
#foldr at none:0 [inlined]
to_typelist(::Array{Any,1}) at typeable.jl:42
##GeneralizedGenerated 19#389 at typeable.jl:64 [inlined]
(::getfield(GeneralizedGenerated, Symbol("###to_type#383#12")))(::Expr) at typeable.jl:63
to_type(::Expr) at Typeclasses.jl:45
(::getfield(GeneralizedGenerated, Symbol("##7#8")){DataType})(::Expr, ::Type) at typeable.jl:43
mapfoldr_impl(::typeof(identity), ::getfield(GeneralizedGenerated, Symbol("##7#8")){DataType}, ::NamedTuple{(:init,),Tuple{DataType}}, ::Array{Any,1}, ::Int64) at reduce.jl:102
#mapfoldr#189 at reduce.jl:125 [inlined]
#mapfoldr at none:0 [inlined]
#foldr#190 at reduce.jl:144 [inlined]
#foldr at none:0 [inlined]
(::getfield(GeneralizedGenerated, Symbol("###to_type#383#12")))(::Expr) at typeable.jl:63
to_type(::Expr) at Typeclasses.jl:45
(::getfield(GeneralizedGenerated, Symbol("##7#8")){DataType})(::Expr, ::Type) at typeable.jl:43
mapfoldr_impl(::typeof(identity), ::getfield(GeneralizedGenerated, Symbol("##7#8")){DataType}, ::NamedTuple{(:init,),Tuple{DataType}}, ::Array{Any,1}, ::Int64) at reduce.jl:105
#mapfoldr#189 at reduce.jl:125 [inlined]
#mapfoldr at none:0 [inlined]
#foldr#190 at reduce.jl:144 [inlined]
#foldr at none:0 [inlined... I think it's due to GeneralizedGenerated.@implement GeneralizedGenerated.Typeable{T} where T <: Function begin
function to_type(x::Function)
wrapped = Symbol(x)
GeneralizedGenerated.TVal{Symbol, wrapped}
end
end and crashed some things 🤷♂ |
Hi, in fact, the default implementation is okay: GeneralizedGenerated.@implement GeneralizedGenerated.Typeable{T} where T <: Function There're special protocols for type encoding so it's okay that your tried one didn't work. However after correcting this, still some problems are remained. Working on this. |
Now it complains correctly @ChrisRackauckas julia> mk_function(oop_ex)
ERROR: Expect a function expression Besides, instead of expecting julia> runtime_eval(1)
1
julia> runtime_eval(Main, :(
a + 1))
ERROR: UndefVarError: a not defined
julia> runtime_eval(Main, :(
a + 1))
3
julia> runtime_eval(oop_ex)
RuntimeFn{list(GeneralizedGenerated.Argument(:u, nothing, GeneralizedGenerated.Unset()), GeneralizedGenerated.Argument(:p, nothing, GeneralizedGenerated.Unset()), GeneralizedGenerated.Argument(:t, nothing, GeneralizedGenerated.Unset())),nil(GeneralizedGenerated.Argument),let
#= REPL[4]:3 =#
X = let (x, y, z, σ, ρ, β) = (u[1], u[2], u[3], p[1], p[2], p[3])
....
|
Cool. I meant for it to be a long-form anonymous function: using GeneralizedGenerated
oop_ex = :(function (u, p, t)
X = let (x, y, z, σ, ρ, β) = (u[1], u[2], u[3], p[1], p[2], p[3])
((*)(σ, (-)(y, x)), (-)((*)(x, (-)(ρ, z)), y), (-)((*)(x, y), (*)(β, z)))
end
T = promote_type(map(typeof, X)...)
convert.(T, X)
construct = if u isa (ModelingToolkit.StaticArrays).StaticArray
(ModelingToolkit.StaticArrays).similar_type(typeof(u), eltype(X))
else
x->begin
du = similar(u, T, 3)
vec(du) .= x
du
end
end
construct(X)
end
)
mk_function(oop_ex) This works! |
These were working with the older
mk_function
before the registration occurred:The text was updated successfully, but these errors were encountered: