I've solved a differential equation using NDSolve with a large working precision prec. The output is a few interpolating functions which, when evaluated, return values with the same working precision specified before.
I'd like to export these functions to avoid rerunning NDSolve. I landed on using
Export["fun.m", f[x]]
for exporting the function and
f[x_] = Import["fun.m"]
to import the function. However, after importing, the values returned by f[x] are always given by the MachinePrecision. Taking Precision[f[x]] also returns MachinePrecision.
I've taken a look at the exported .m files and it looks like all of the data is there, so I am not sure what the issue is.
Here is a minimal example:
f = NDSolveValue[{y'[x] == y[x], y[0] == 1}, y, {x, 0, 2}, WorkingPrecision -> 20];
Export["fun.m", f];
fExported = Import["fun.m"];
f[1] // FullForm
(* 2.7182818122020232403695791388107538970319.68219897174271 *) fExported[1] // FullForm (* 2.718281812202023*)
fExported // InputFormandFilePrint["fun.m"]show the problem is probably withImport. The values at the end of "fun.m" are at the correct precision, but they are machine precision infExported. It's either a bug or there's some option toImportyou should use (don't know what that is, though). Using"fun.mx"seems to fix the problem, if that's any help. – Goofy Jan 02 '24 at 17:17DumpSaveinstead ofExport. See also How do I save a variable or function definition to a file?. – Domen Jan 02 '24 at 17:23foo = First@Import[funFile, "HeldExpressions"]showsImportdoes its job right. ButReleaseHold[foo]shows that the evaluation ofInterpolatingFunctionconverts the values to machine precision. I'd say it's a bug and should be reported to WRI. – Goofy Jan 02 '24 at 17:29