Skip to content

Commit

Permalink
Merge pull request #182 from magerton/pull-request/61d75528
Browse files Browse the repository at this point in the history
Fix gradients for ScaledInterpolation with NoInterp
  • Loading branch information
timholy authored Oct 30, 2017
2 parents 62dd04b + 61d7552 commit 3d433df
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/scaling/scaling.jl
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,12 @@ gradient(sitp::ScaledInterpolation{T,N,ITPT,IT,GT}, xs...) where {T,N,ITPT,IT<:D
quote
length(g) == $(count_interp_dims(IT, N)) || throw(ArgumentError(string("The length of the provided gradient vector (", length(g), ") did not match the number of interpolating dimensions (", $(count_interp_dims(IT, N)), ")")))
gradient!(g, sitp.itp, $(interp_indices...))
for i in eachindex(g)
g[i] = rescale_gradient(sitp.ranges[i], g[i])
cntr = 0
for i = 1:N
if $(interp_dimens)[i]
cntr += 1
g[cntr] = rescale_gradient(sitp.ranges[i], g[cntr])
end
end
g
end
Expand Down
13 changes: 13 additions & 0 deletions test/scaling/nointerp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,18 @@ end

@test length(gradient(sitp, pi/3, 2)) == 1

# check for case where initial/middle indices are NoInterp but later ones are <:BSpline
srand(1234)
z0 = rand(10,10)
za = copy(z0)
zb = copy(z0')

itpa = interpolate(za, (BSpline(Linear()), NoInterp()), OnGrid())
itpb = interpolate(zb, (NoInterp(), BSpline(Linear())), OnGrid())

rng = linspace(1.0, 19.0, 10)
sitpa = scale(itpa, rng, 1:10)
sitpb = scale(itpb, 1:10, rng)
@test gradient(sitpa, 3.0, 3) == gradient(sitpb, 3, 3.0)

end

0 comments on commit 3d433df

Please sign in to comment.