Skip to content

Commit

Permalink
Merge pull request #12 from gerlero/fix-gh-11
Browse files Browse the repository at this point in the history
Make defensive copies of Interpolator input vectors
  • Loading branch information
gerlero authored Jan 28, 2022
2 parents 684b274 + e56c85d commit 3b33c3b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/PCHIPInterpolation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ struct Interpolator{Xs,Ys,Ds}
end

ds = _initial_ds_scipy(xs, ys)
new{typeof(xs),typeof(ys),typeof(ds)}(xs, ys, ds)
new{typeof(xs),typeof(ys),typeof(ds)}(deepcopy(xs), deepcopy(ys), ds)
end
end

Expand Down
9 changes: 9 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -142,3 +142,12 @@ itp = Interpolator(x, x)
x = collect(range(0, stop=1, length=1000))
itp = Interpolator(x, x)
@test itp(1) == 1

# Regression test for https://github.com/gerlero/PCHIPInterpolation.jl/issues/11
v = [1, 2, 3]
p = Interpolator(v, v)
xs = copy(p.xs)
ys = copy(p.ys)
v .= -1
@test p.xs == xs
@test p.ys == ys

0 comments on commit 3b33c3b

Please sign in to comment.