I’m working on this project for sparse automatic differentiation:
The structs involved are defined like this:
const StaticTuple{T,S,N} = NamedTuple{S, NTuple{N,T}}
struct DiffCheck{T<:ReComp, S, N} <: Number
value::T
der::StaticTuple{T,S,N} # maybe not the fastest structure
function DiffCheck{T, S}(x::T, der::StaticTuple{T,S,N}) where {T<:ReComp, S, N}
return new{T,S,N}(x, der)
end
end
where S is a tuple of Symbols, N is the size of the Tuple.
The symbols are a part of the parameters so that a lot of things are static and work is done at compile time.
I’m currently trying to implement function calls
I would like the following to work (in alternative I will generate a source file and the include it)
(funsym, der) = (:(sin), :(cos))
@eval function Base.$funsym(x::DiffCheck{T,S,N}) where {T, S, N}
return DiffCheck{T, S}($funsym(value(x)), StaticTuple{T,S,N}(($der(value(x)) .* values(derivatives(x)))))
end