Skip to content

Commit d68d50c

Browse files
authored
Avoid calling highly overloaded function in generated extraction functions (#469)
1 parent c91eff4 commit d68d50c

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

src/gradient.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,12 @@ end
5353
# result extraction #
5454
#####################
5555

56-
@generated function extract_gradient(::Type{T}, y::Real, x::StaticArray) where T
56+
@generated function extract_gradient(::Type{T}, y::Real, x::S) where {T,S<:StaticArray}
5757
result = Expr(:tuple, [:(partials(T, y, $i)) for i in 1:length(x)]...)
58-
V = StaticArrays.similar_type(x, valtype(y))
5958
return quote
6059
$(Expr(:meta, :inline))
61-
return $V($result)
60+
V = StaticArrays.similar_type(S, valtype($y))
61+
return V($result)
6262
end
6363
end
6464

src/jacobian.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,13 +94,13 @@ end
9494
# result extraction #
9595
#####################
9696

97-
@generated function extract_jacobian(::Type{T}, ydual::StaticArray, x::StaticArray) where T
97+
@generated function extract_jacobian(::Type{T}, ydual::StaticArray, x::S) where {T,S<:StaticArray}
9898
M, N = length(ydual), length(x)
9999
result = Expr(:tuple, [:(partials(T, ydual[$i], $j)) for i in 1:M, j in 1:N]...)
100-
V = StaticArrays.similar_type(x, valtype(eltype(ydual)), Size(M, N))
101100
return quote
102101
$(Expr(:meta, :inline))
103-
return $V($result)
102+
V = StaticArrays.similar_type(S, valtype(eltype($ydual)), Size($M, $N))
103+
return V($result)
104104
end
105105
end
106106

0 commit comments

Comments
 (0)