To Cache or not to Cache
At the initialization of the interpolation objects exposed by this package, a lot of data is precomputed and cached, see for instance the example below.
using CachedInterpolations
u = rand(10)
t = cumsum(rand(10))
itp = CSmoothedLinearInterpolation(u, t)
itp.cache
CachedInterpolations.CSmoothedLinearInterpolationCache{Vector{Float64}, Vector{Float64}, Float64, Float64}
Note: t, u stand for the inputs and outputs respectively of the original interpolation, not the inversion.
┌──────────┬──────────┐
│ u_tilde │ t_tilde │
├──────────┼──────────┤
│ 0.898901 │ 0.570199 │
│ 0.8768 │ 0.635296 │
│ 0.744194 │ 1.02588 │
│ 0.675897 │ 1.12226 │
│ 0.398718 │ 1.30997 │
│ 0.337268 │ 1.36183 │
│ 0.245747 │ 1.48526 │
│ 0.246634 │ 1.51286 │
│ ⋮ │ ⋮ │
│ 0.591577 │ 2.13674 │
│ 0.588507 │ 2.23931 │
│ 0.820185 │ 2.57131 │
│ 0.816453 │ 2.72944 │
│ 0.562388 │ 3.34626 │
│ 0.564525 │ 3.49222 │
│ 0.831417 │ 3.75116 │
│ 0.875899 │ 3.79432 │
└──────────┴──────────┘
4 rows omitted
┌───────────┬───────────┬──────────────┐
│ Δu │ Δt │ linear_slope │
├───────────┼───────────┼──────────────┤
│ -0.176808 │ 0.520776 │ -0.339509 │
│ -0.176808 │ 0.520776 │ -0.339509 │
│ -0.369572 │ 0.250284 │ -1.47661 │
│ -0.122029 │ 0.164577 │ -0.741467 │
│ 0.129129 │ 0.0561658 │ 2.29907 │
│ 0.523732 │ 0.24402 │ 2.14627 │
│ -0.33346 │ 0.37796 │ -0.882261 │
│ 0.308904 │ 0.442657 │ 0.69784 │
│ -0.338754 │ 0.822419 │ -0.4119 │
│ 0.355856 │ 0.345264 │ 1.03068 │
│ 0.355856 │ 0.345264 │ 1.03068 │
└───────────┴───────────┴──────────────┘
┌──────────┬──────────┬───────────┬────────────┬────────────────┐
│ u │ t │ ΔΔu │ ΔΔt │ degenerate_ΔΔt │
├──────────┼──────────┼───────────┼────────────┼────────────────┤
│ 0.898901 │ 0.570199 │ 0.0 │ 0.0 │ 1.0 │
│ 0.722093 │ 1.09097 │ -0.192764 │ -0.270492 │ 0.0 │
│ 0.352522 │ 1.34126 │ 0.247543 │ -0.0857064 │ 0.0 │
│ 0.230493 │ 1.50584 │ 0.251157 │ -0.108411 │ 0.0 │
│ 0.359622 │ 1.562 │ 0.394603 │ 0.187854 │ 0.0 │
│ 0.883354 │ 1.80602 │ -0.857192 │ 0.13394 │ 0.0 │
│ 0.549894 │ 2.18398 │ 0.642363 │ 0.0646962 │ 0.0 │
│ 0.858798 │ 2.62664 │ -0.647658 │ 0.379763 │ 0.0 │
│ 0.520043 │ 3.44906 │ 0.69461 │ -0.477155 │ 0.0 │
│ 0.875899 │ 3.79432 │ 0.0 │ 0.0 │ 1.0 │
└──────────┴──────────┴───────────┴────────────┴────────────────┘
This means that evaluation of the interpolation is faster, at the cost of more memory allocation at initialization. This is in contrast to the interpolation in DataInterpolations.jl
, where very little to no memory is allocated at the initialization of interpolation objects. What is better depends on the application.
If you want to use the interpolation objects exposed by this package without pre-allocation, please let me know in this issue.