Chances are (as you possibly already discovered) you need something like calculate.(Ref(model), x), to only broadcast over x:
julia> model = Model1(); calculate.(model, rand(2))
ERROR: MethodError: no method matching length(::Model1)
The function `length` exists, but no method is defined for this combination of argument types.
...
julia> model = Model1(); calculate.(Ref(model), rand(2))
2-element Vector{Float64}:
0.6703962401999668
0.02555859497947358
julia> y = randn(10); outerfunction(y, Model1()) # after changing mock_objective to use calculate.(Ref(model), x)
10-element Vector{Float64}:
-2.0454384710671905
0.7536118906802644
0.02433927361845278
-0.6611984902692523
2.4331966348683114
0.32002204681925306
-0.25881730669622205
-0.2741795111891973
0.08683262936815833
0.7966843475386596
In general I would always suggest to just also post your fix, instead of deleting your post. You never know who will find it useful ![]()