Skip to content

Commit 6628ee9

Browse files
Merge pull request #72 from huanglangwen/oop
fix error when x is a ndarray
2 parents 08ffdde + a89c672 commit 6628ee9

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

src/differentiation/compute_jacobian_ad.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ function forwarddiff_color_jacobian(f,x::AbstractArray{<:Number},jac_cache::Forw
8888

8989
vecx = vec(x)
9090

91-
J = jac_prototype isa Nothing ? (sparsity isa Nothing ? false .* dx .* x' : zeros(eltype(x),size(sparsity))) : zero(jac_prototype)
91+
J = jac_prototype isa Nothing ? (sparsity isa Nothing ? false .* vec(dx) .* vecx' : zeros(eltype(x),size(sparsity))) : zero(jac_prototype)
9292
nrows,ncols = size(J)
9393

9494
if !(sparsity isa Nothing)

test/test_ad.jl

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,4 +208,14 @@ Jsparse = sparse(J)
208208
colors = matrix_colors(J)
209209
forwarddiff_color_jacobian!(J, f, x, colorvec=colors)
210210
forwarddiff_color_jacobian!(Jsparse, f, x, colorvec=colors)
211-
@test J Jsparse
211+
@test J Jsparse
212+
213+
# Non vector input
214+
x = rand(2,2)
215+
oopf(x) = x
216+
iipf(fx,x) = (fx.=x)
217+
J = forwarddiff_color_jacobian(oopf,x)
218+
@test J Matrix(I,4,4)
219+
J = zero(J)
220+
forwarddiff_color_jacobian!(J,iipf,x,dx=similar(x))
221+
@test J Matrix(I,4,4)

0 commit comments

Comments
 (0)