-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #250 from biaslab/dev-issue-249
Fix issue #249
- Loading branch information
Showing
9 changed files
with
129 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# This file implements various hot-fixes for external dependencies | ||
# This file can be empty, which is fine. It only means that all external dependecies released a new version | ||
# that is now fixed | ||
|
||
# Fix for 3-argument `dot` product and `ForwardDiff.hessian`, see | ||
# https://github.com/JuliaDiff/ForwardDiff.jl/issues/551 | ||
# https://github.com/JuliaDiff/ForwardDiff.jl/pull/481 | ||
# https://github.com/JuliaDiff/ForwardDiff.jl/issues/480 | ||
import LinearAlgebra: dot | ||
import ForwardDiff | ||
|
||
function dot(x::AbstractVector, A::AbstractMatrix, y::AbstractVector{D}) where {D <: ForwardDiff.Dual} | ||
(axes(x)..., axes(y)...) == axes(A) || throw(DimensionMismatch()) | ||
T = typeof(dot(first(x), first(A), first(y))) | ||
s = zero(T) | ||
i₁ = first(eachindex(x)) | ||
x₁ = first(x) | ||
@inbounds for j in eachindex(y) | ||
yj = y[j] | ||
temp = zero(adjoint(A[i₁, j]) * x₁) | ||
@simd for i in eachindex(x) | ||
temp += adjoint(A[i, j]) * x[i] | ||
end | ||
s += dot(temp, yj) | ||
end | ||
return s | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
module ForwardDiffGradTest | ||
|
||
using Test | ||
using ReactiveMP | ||
using Random | ||
using LinearAlgebra | ||
using Distributions | ||
using ForwardDiff | ||
|
||
import ReactiveMP: convert_eltype | ||
|
||
@testset "ForwardDiffGrad" begin | ||
grad = ForwardDiffGrad() | ||
|
||
for i in 1:100 | ||
@test ReactiveMP.compute_gradient(grad, (x) -> sum(x)^2, [i]) ≈ [2 * i] | ||
@test ReactiveMP.compute_hessian(grad, (x) -> sum(x)^2, [i]) ≈ [2;;] | ||
end | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters