Skip to content

Commit 6ebf4ca

Browse files
committed
Fix type stability bug in gradient
cc @timholy I don't know if this is the best possible solution to the problem, but it does allow us to do things like gradient(itp, dual(2,1)) and get an Array{DualNumbers{Float64},1} back. Before, that incantation would throw an InexactError because it was trying to fit a dual number with nonzero epsilon into an Array{Float64}.
1 parent ac9445a commit 6ebf4ca

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

src/b-splines/indexing.jl

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,8 @@ end
7272

7373
@generated function gradient{T,N,TCoefs,IT,GT,pad}(itp::BSplineInterpolation{T,N,TCoefs,IT,GT,pad}, xs...)
7474
n = count_interp_dims(IT, N)
75-
quote
76-
@which gradient!(Array(T, $n), itp, xs...)
77-
gradient!(Array(T,$n), itp, xs...)
78-
end
75+
Tg = promote_type(T, xs...)
76+
:(gradient!(Array($Tg,$n), itp, xs...))
7977
end
8078

8179
@generated function gradient!{T,N}(g::AbstractVector, itp::BSplineInterpolation{T,N}, xs::Number...)

0 commit comments

Comments
 (0)