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
Saving and loading (anonymous) functions #258
Comments
Hi @hendri54 , thanks for this bug report! The problem was introduced in The problem is in Line 1339 in d6bd508
This was changed to make I made a PR #260 that restores the correct behavior in this case but I don't know enough about |
Thank you for the suggestion. 0.2.4 works for now. And thank you for all the work you are putting into the package. |
@JonasIsensee |
This should be fixed in |
Thanks again! |
saving functions is not really fixed, for if you quit out julia and start a fresh REPL, then you can not call that saved function. so after executing the above code in the OP, if you then immediately call the loaded function it works:
but if you quit and then re-load it doesn't:
this is with julia 1.8, JLD2 0.4.23 |
and it gets worse if you redefine that struct before loading:
|
the only hack i know of is to save the Expr corresponding to the function and eval it after loading:
and it works in a fresh REPL:
and it doesn't break if you redefine the struct:
|
I did not mean to claim that saving functions was fixed. Functions in julia are complex objects thanks to multiple dispatch / specializations / generated functions / wrapped variables / references to globals / and potentially being retrieved from a system image. The julia serializer has limited support for storing functions but is not generally compatible with JLD2. The error message you posted above does appear to be a bug. There should be a more graceful failure mode. |
by limited do you mean none? i can't get even a simple case to work:
quit and open a new REPL:
i'll also chime in with the others and thank you for your work on JLD2! |
oh, I did not know that part. Anonymous functions "work":
This looked fine, but the following still fails:
|
When saving and then loading a
struct
that contains a function I now get a MethodError. MWE:The error is:
Replacing the function with, say, and
Int
avoids the error.This is on Julia 1.5.2, JLD2 0.3.0, FileIO 1.4.4.
The text was updated successfully, but these errors were encountered: