Function with parameter: `f(x,p)` or `f(x;p)`

I have been using the call with the key argument to provide parameters f(x;p=(a=1.1,b=2.2)) taking advantage of broadcasting without Ref. However, noticed f(x,p) is a common format as well.
Any thoughts on which way is “better”, more standard, more performant?

I asked a similar question a few weeks ago. This is the thread: Performance difference between optional args and keyword args

1 Like

BTW if you are passing parameters that way, I think you’d be interested in ComponentArrays.jl.

1 Like

thanks for the reference. The performance aspect is solved!

What is about the “more standard” aspect. Which one would have a better compatibility with other packages?

I think that ML people prefer to pass parameters as arguments, but I wouldn’t call that standard. Myself, I tend to pass them as kwargs.

Really nice, I did not see it, indeed.
In AlgebraPDF, I work with NamedTuples, so everything is immutable. There are pros and cons. Here I also do not really know what is better.

I think in the announcement post of ComponentArrays.jl there is some discussion on performance of several similar structures: [RFC/ANN] ComponentArrays.jl for building composable models without a modeling language

One thing is that a ComponentArray is a subtype of AbstractArray, so you can pass it to optimizers, solvers, etc. For example Optim, NLsolve

oh, that is great. I had to reinvent it.

Depends on your use case. If you want to dispatch on p in f, you have to use a positional argument, otherwise pick what you find most convenient.