Open baggepinnen opened 2 years ago
@YingboMa would this issue be a suitable first step towards better array-variable register support? An example usecase could be a dynamics function on the form
function f(u, p, t)
# heavy computation
return du
end
where du
is an array. To register this, I imagine that you'd like to say something about the type and size of the output, e.g.,
@register f(u::Vector, p, t::Real)::Vector
but with additional size information.
The intended effect of calling f
on arrays with symbols or symbolic arrays would be to get a "symbolic function call" like
FunctionCall{typeof(f)}((u, p, t), arg_types, return_type)
that can later be extended with derivative/sparsity information etc.
FYI, there's https://github.com/JuliaSymbolics/Symbolics.jl/pull/457. But it seems to be slightly buggy.
julia> @register_symbolic oof(x::AbstractVector)
julia> @variables x[1:100]
1-element Vector{Symbolics.Arr{Num, 1}}:
x[1:100]
julia> oof(x)
ERROR: MethodError: no method matching oof(::Symbolics.Arr{Num, 1})
Closest candidates are:
oof(::SymbolicUtils.Symbolic{<:AbstractVector}) at ~/src/julia/Symbolics/src/register.jl:51
Stacktrace:
[1] top-level scope
@ REPL[313]:1
julia> oof(Symbolics.unwrap(x))
oof(x)
@shashi could you take a look?
I cannot get
@register
to work with arrays of variables.I have found one workaround, which is to define a wrapper function that accepts a symbolic dummy variable, like so
but this is of course not optimal :)
Changing
Vector{Num}
todoesn't change anything