JuliaSmoothOptimizers / LinearOperators.jl

Linear Operators for Julia
Other
150 stars 32 forks source link

Efficient `get_nargs` #275

Open gdalle opened 1 year ago

gdalle commented 1 year ago

In a recent Discourse thread it surfaced that get_nargs takes up a sizeable part of the benchmark. The reason is that it allocates the whole methods table before considering the first element:

get_nargs(f) = first(methods(f)).nargs - 1

Besides it is not necessarily accurate if several methods have varying numbers of arguments. Any idea how we could overcome this?

gdalle commented 1 year ago

The workaround I found for my package: https://github.com/gdalle/ImplicitDifferentiation.jl/pull/47

dpo commented 1 year ago

Sorry for the slow reply here. The obvious workaround would be for nargs to be an input to the constructor. Or we could have two constructors, LinearOperator and LinearOperator5 (say) for products with 5 arguments.

@geoffroyleconte What do you think?

geoffroyleconte commented 1 year ago

Sorry for the slow reply here. The obvious workaround would be for nargs to be an input to the constructor. Or we could have two constructors, LinearOperator and LinearOperator5 (say) for products with 5 arguments.

@geoffroyleconte What do you think?

https://github.com/JuliaSmoothOptimizers/LinearOperators.jl/pull/282

Something like this?