Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scaled interpolation does not automatically extrapolate when called with a vector #158

Closed
BenjaminBorn opened this issue May 13, 2017 · 2 comments · Fixed by #226
Closed

Comments

@BenjaminBorn
Copy link

BenjaminBorn commented May 13, 2017

The following example is taken from the readme

A_x = 1.:2.:40.
A = [log(x) for x in A_x]
itp = interpolate(A, BSpline(Cubic(Line())), OnGrid())
sitp = scale(itp, A_x)
sitp[3.]
sitp[3.5]

This can also be called in one go by passing a vector to be evaluated

sitp[[3.0, 3.5]]
2-element Array{Float64,1}:
 1.09861
 1.22632

If evaluated outside the grid range (e.g. at 42), it seems to automatically extrapolate

sitp[42.0]
3.7425272463577794

However, that doesn't work for a vector

sitp[[42.0,3.5]]

BoundsError: attempt to access 20-element scale(interpolate(::Array{Float64,1}, BSpline(Linear()), OnGrid()), (1.0:2.0:39.0,)) with element type Float64 at index [[42.0,3.5]]
 in throw_boundserror(::Interpolations.ScaledInterpolation{Float64,1,Interpolations.BSplineInterpolation{Float64,1,Array{Float64,1},Interpolations.BSpline{Interpolations.Linear},Interpolations.OnGrid,0},Interpolations.BSpline{Interpolations.Linear},Interpolations.OnGrid,Tuple{FloatRange{Float64}}}, ::Tuple{Array{Float64,1}}) at abstractarray.jl:363
 in checkbounds at abstractarray.jl:292 [inlined]
 in _getindex at multidimensional.jl:272 [inlined]
 in getindex(::Interpolations.ScaledInterpolation{Float64,1,Interpolations.BSplineInterpolation{Float64,1,Array{Float64,1},Interpolations.BSpline{Interpolations.Linear},Interpolations.OnGrid,0},Interpolations.BSpline{Interpolations.Linear},Interpolations.OnGrid,Tuple{FloatRange{Float64}}}, ::Array{Float64,1}) at abstractarray.jl:760
 in include_string(::String, ::String) at loading.jl:441
 in include_string(::String, ::String) at sys.dylib:?
 in eval(::Module, ::Any) at boot.jl:234
 in eval(::Module, ::Any) at sys.dylib:?
 in (::Atom.##65#68)() at eval.jl:102
 in withpath(::Atom.##65#68, ::Void) at utils.jl:30
 in withpath(::Function, ::Void) at eval.jl:38
 in macro expansion at eval.jl:101 [inlined]
 in (::Atom.##64#67{Dict{String,Any}})() at task.jl:60

What works is to set the extrapolation explicitely

esitp = extrapolate(sitp,Linear())
esitp[[42.0,3.5]]
2-element Array{Float64,1}:
 3.74253
 1.22632

This seems a bit inconsistent. Would it make sense to also automatically extrapolate when the input is a vector of points? Possibly related is issue #129.

General information

Pkg.status("Interpolations")
- Interpolations                0.6.1

Julia Version 0.5.3-pre+0
Commit 42f8035ccc (2017-05-06 16:34 UTC)
Platform Info:
  OS: macOS (x86_64-apple-darwin16.5.0)
  CPU: Intel(R) Core(TM) i7-6700K CPU @ 4.00GHz
  WORD_SIZE: 64
  BLAS: libopenblas (USE64BITINT NO_AFFINITY NEHALEM)
  LAPACK: libopenblas64_
  LIBM: libopenlibm
  LLVM: libLLVM-3.7.1 (ORCJIT, broadwell)
@timholy
Copy link
Member

timholy commented May 19, 2017

I suspect all AbstractInterpolation types should turn on bounds checking. (I think Interpolations was written before @blakejohnson added the wonderful @boundscheck mechanism.)

@tomasaschan
Copy link
Contributor

Noticed this today too, when writing up a workaround for #192. It seems it's not only for extrapolation it fails; even when evaluating inside the scaled bounds it can fail. For example, this throws the same error:

A = rand(4,4)
itp = interpolate(A, BSpline(Linear()), OnGrid())
sitp = scale(itp, 1:4, 3:6)
sitp[:,3:6]

@timholy timholy mentioned this issue Sep 10, 2018
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants