Skip to content

Fix issue of inconsistent size #74

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/differentiation/compute_jacobian_ad.jl
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@ function forwarddiff_color_jacobian(f,x::AbstractArray{<:Number},jac_cache::Forw
for j in 1:chunksize
col_index = (i-1)*chunksize + j
(col_index > ncols) && return J
J = J + mapreduce(i -> i==col_index ? partials.(vec(fx), j) : zeros(nrows), hcat, 1:ncols)
Ji = mapreduce(i -> i==col_index ? partials.(vec(fx), j) : zeros(nrows), hcat, 1:ncols)
J = J + (size(Ji)!=size(J) ? reshape(Ji,size(J)) : Ji) #branch when size(dx) == (1,) => size(Ji) == (1,) while size(J) == (1,1)
end
end
end
Expand Down
8 changes: 7 additions & 1 deletion test/test_ad.jl
Original file line number Diff line number Diff line change
Expand Up @@ -218,4 +218,10 @@ J = forwarddiff_color_jacobian(oopf,x)
@test J ≈ Matrix(I,4,4)
J = zero(J)
forwarddiff_color_jacobian!(J,iipf,x,dx=similar(x))
@test J ≈ Matrix(I,4,4)
@test J ≈ Matrix(I,4,4)

#1x1 SVector test
x = SVector{1}([1.])
f(x) = x
J = forwarddiff_color_jacobian(f,x)
@test J ≈ SMatrix{1,1}([1.])