Skip to content

Commit f149661

Browse files
committed
Fix element type of gradient initialization in HessianResult
1 parent 4a440e5 commit f149661

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

src/DiffResults.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ Note that `HessianResult` allocates its own storage; `x` is only used for type a
101101
shape information. If you want to allocate storage yourself, use the `DiffResult`
102102
constructor instead.
103103
"""
104-
HessianResult(x::AbstractArray) = DiffResult(first(x), zeros(size(x)), similar(x, length(x), length(x)))
104+
HessianResult(x::AbstractArray) = DiffResult(first(x), zeros(eltype(x), size(x)), similar(x, length(x), length(x)))
105105
HessianResult(x::StaticArray) = DiffResult(first(x), x, zeros(StaticArrays.similar_type(typeof(x), Size(length(x),length(x)))))
106106

107107
#############

test/runtests.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,5 +293,7 @@ using DiffResults: DiffResult, GradientResult, JacobianResult, HessianResult,
293293
@test size(gradient(HessianResult(x0))) == size(x0)
294294
@test size(gradient(HessianResult(x1))) == size(x1)
295295
@test size(gradient(HessianResult(x2))) == size(x2)
296+
297+
@test HessianResult(Float32.(x0)).derivs[1] isa Vector{Float32}
296298
end
297299
end

0 commit comments

Comments
 (0)