Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for NTuple inputs and outputs #208

Open
heltonmc opened this issue Feb 16, 2022 · 0 comments
Open

Support for NTuple inputs and outputs #208

heltonmc opened this issue Feb 16, 2022 · 0 comments

Comments

@heltonmc
Copy link

It would be nice if the example function could also work for NTuple types such as

@. model(x, p) = p[1]*exp(-x*p[2])
xdata = (0.5, 1.5, 2.5, 4.5, 6.5)
ydata = model(xdata, (1.0, 2.0))
p0 = (1.5, 0.5)
julia> fit = curve_fit(model, xdata, ydata, p0)
ERROR: MethodError: no method matching curve_fit(::typeof(model), ::NTuple{5, Float64}, ::NTuple{5, Float64}, ::Tuple{Float64, Float64})

I've found that I'm starting to use Tuples significantly more in math models for speed/allocations when considering small number of parameters.

My current workaround has been to do...

@. f(x::Tuple, p) = p[1]*exp(-x*p[2])
xdata = (0.5, 1.5, 2.5, 4.5, 6.5)
ydata = f(xdata, (1.0, 2.0))

model(x, p) = [f(Tuple(x for x in x), p)...]
p0 = [1.5, 0.5]
fit = curve_fit(model, [xdata...], [ydata...], p0)

Which works but obviously allocates a lot more. Is there perhaps a better workaround for this if f must accept a tuple? Possibly just use the inplace version?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant