Sato
Sato

Reputation: 1133

Saving interpolated function into a separate file in Julia

It is easy to save an array as files (such as .txt/.csv formats) in Julia/Python, but is there any way to save a function generated from interpolating an array? Taking a simple example:

using Interpolations

inter = Dict("constant" => BSpline(Constant()), 
    "linear" => BSpline(Linear()), 
    "quadratic" => BSpline(Quadratic(Line(OnCell()))),
    "cubic" => BSpline(Cubic(Line(OnCell())))
)

arr = rand(100, 100, 100)  # 3D array
func = interpolate(arr, inter["cubic"])

How can this function be saved for future use, such that one does not need to interpolate the function again each time when one runs the program?

Upvotes: 0

Views: 356

Answers (1)

mdavezac
mdavezac

Reputation: 515

A simple solution is to use JLD2.

using JLD2
@save "savedfunction.jld" func

And then reload with

using Interpolations, JLD2
@load "savedfunction.jld"
func

Upvotes: 1

Related Questions