Updating a function in a type, where the function is a parameter

Did you decide how to continue yet? (stated differently: is your question answered or is there anything else to consider?)

Eh, the stated differently question has a different answer from the first one :smile:

I think I have an answer to the question, that the idea I had is not possible the way I had in mind. So there is nothing else to consider.

In the point of how to continue, I am not yet sure, because I think my MyStruct (or Problem) has to either be minimised (to just have functions in there) - then I could even to a copy and stay with structs (since I would end up having about 4 different structs for functions, maybe 5 or 6).
But that would be so much work for the package, since this struct is such a central thing, that for now I might just not do this feature and maybe think about another way to do iterative optimisation where the sub solver changes. I do not know yet.

So no; I do not know hot to continue yet.

And for the other questions whether this is answered: Yes, it is. It‘s not possible.

1 Like

I have seen two approaches for typing functions in the past: MethodWrappers or (with even more black magic) FunctionWrappers. Could one of these help?

1 Like

That looks interesting, Wrapping the function was one Idea I mentioned above but I am not yet sure how to get that to work. But I will take a look how it is done there.

My first approach I might try is to model the function itself as a functor

mutable struct MyFun{F}
   f::F
   lambda:Float664
end

(f::MyFun)(x) = lambda * x

well something along those lines since the things I want to change are not arbitrary but structured with parameters. That way I do not have to replace the function but can modify it (or its parameters to be precise) still.

Sounds good, that’s kind of what my first suggestion was aiming at IIUC.
Small thing, in:

The stored function f is not actually used. The (f::MyFun)(x) = ... makes instances of the MyFun type callable, to use the stored f you still have to f.f(...) in this case.

1 Like

…the main reason that it is not used is; Me being too fast in typing the example :wink:

Sure what I meant was more like

(F::MyFun)(x) = (1-lambda) * F.f(x) - lambda