Skip to content

Commit

Permalink
Allow trailing 1s for gridded & scaled (fixes #301) (#318)
Browse files Browse the repository at this point in the history
  • Loading branch information
timholy authored May 8, 2019
1 parent 06f9fc6 commit d1ad2a1
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/gridded/indexing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,16 @@
wis = weightedindexes((value_weights,), itpinfo(itp)..., x)
coefficients(itp)[wis...]
end
@propagate_inbounds function (itp::GriddedInterpolation{T,N})(x::Vararg{Number,M}) where {T,M,N}
inds, trailing = split_trailing(itp, x)
@boundscheck (check1(trailing) || Base.throw_boundserror(itp, x))
@assert length(inds) == N
itp(inds...)
end
@inline function (itp::GriddedInterpolation)(x::Vararg{UnexpandedIndexTypes})
itp(to_indices(itp, x)...)
xis = to_indices(itp, x)
xis == x && error("evaluation not supported for GriddedInterpolation at positions $x")
itp(xis...)
end

@inline function gradient(itp::GriddedInterpolation{T,N}, x::Vararg{Number,N}) where {T,N}
Expand Down
6 changes: 6 additions & 0 deletions src/scaling/scaling.jl
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@ ubound(ax::AbstractRange, ::DegreeBC, ::OnGrid) = last(ax)
xl = maybe_clamp(sitp.itp, coordslookup(itpflag(sitp.itp), sitp.ranges, xs))
@inbounds sitp.itp(xl...)
end
@propagate_inbounds function (itp::ScaledInterpolation{T,N})(x::Vararg{Number,M}) where {T,M,N}
inds, trailing = split_trailing(itp, x)
@boundscheck (check1(trailing) || Base.throw_boundserror(itp, x))
@assert length(inds) == N
itp(inds...)
end
@inline function (sitp::ScaledInterpolation)(x::Vararg{UnexpandedIndexTypes})
xis = to_indices(sitp, x)
xis == x && error("evaluation not supported for ScaledInterpolation at positions $x")
Expand Down
3 changes: 3 additions & 0 deletions test/gridded/gridded.jl
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,7 @@ using Interpolations, Test
@test itp(2) === 2.0f0
@test itp(2.0) === 2.0
@test itp(2.0f0) === 2.0f0

# trailing 1s, issue #301
@test itp(1.8, 1) == itp(1.8)
end
3 changes: 3 additions & 0 deletions test/scaling/scaling.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ using Test, LinearAlgebra, StaticArrays
for (x,y) in zip(-3:.05:1.5, 1:.1:10,)
@test sitp(x) y
end
# trailing 1s, issue #301
@test sitp(0.8, 1) == sitp(0.8)


@test_throws ArgumentError scale(itp, reverse(-3:.5:1.5))

Expand Down

2 comments on commit d1ad2a1

@timholy
Copy link
Member Author

@timholy timholy commented on d1ad2a1 May 8, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator register()

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/616

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if Julia TagBot is installed, or can be done manually through the github interface, or via:

git tag -a v0.12.0 -m "<description of version>" d1ad2a1409ce6cea96cd304a540c485d2b393f5d
git push origin v0.12.0

Please sign in to comment.