Remove Dict{Symbol, Any}
for type stability in FunctionOperator
#255
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The current implementation of
FunctionOperator
requires aDict{Symbol,Any}
to handle the keyword arguments. This leads to type instabilities and performance decreases, as in the following simple code:master branch
This PR branch
To manage to fix this issue, I used
NamedTuple
instead ofDict{Symbol, Any}
. For this reason, the additionalkwargs
are required whenaccepted_kwargs
is provided, in order to initialize the types inside theNamedTuple
. In principle, theaccepted_kwargs
can be directly obtained fromkwargs
keys, but I left it for consistency with the other functions.Furthermore, I've extended the methods of the
get_filtered_kwargs
, also supportingVal
types foraccepted_kwargs
. In this way, the filtering is performed at compile time, otherwise the type of theNamedTuple
cannot be inferred. Thus, all the other functions supportingaccepted_kwargs
would also supportVal
types, improving performance.