Merged
Conversation
wsmoses
reviewed
Oct 31, 2025
src/internal_rules.jl
Outdated
| end | ||
| end | ||
| @inbounds cofA[i, j] = (-1)^(i - 1 + j - 1) * det(minorAij) | ||
| minorAij .= zero(eltype(A)) |
Member
There was a problem hiding this comment.
use fill!(minorAij, zero) instead?
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2725 +/- ##
==========================================
- Coverage 72.61% 69.87% -2.75%
==========================================
Files 58 58
Lines 18746 19369 +623
==========================================
- Hits 13613 13534 -79
- Misses 5133 5835 +702 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Contributor
|
Your PR requires formatting changes to meet the project's style guidelines. Click here to view the suggested changes.diff --git a/lib/EnzymeTestUtils/src/test_utils.jl b/lib/EnzymeTestUtils/src/test_utils.jl
index d111f537..820306bf 100644
--- a/lib/EnzymeTestUtils/src/test_utils.jl
+++ b/lib/EnzymeTestUtils/src/test_utils.jl
@@ -4,7 +4,7 @@ struct CallWithKWargs{KW}
end
function (c::CallWithKWargs)(f, xs...)
- f(xs...; c.kwargs...)
+ return f(xs...; c.kwargs...)
end
struct CallWithCopyKWargs{KW}
@@ -12,9 +12,9 @@ struct CallWithCopyKWargs{KW}
end
function (c::CallWithCopyKWargs)(f, xs...)
- deepcopy(f)(deepcopy(xs)...; deepcopy(c.kwargs)...)
+ return deepcopy(f)(deepcopy(xs)...; deepcopy(c.kwargs)...)
end
@inline function get_primal(x::Annotation)
- x.val
-end
\ No newline at end of file
+ return x.val
+end
diff --git a/src/internal_rules.jl b/src/internal_rules.jl
index b359c670..a02d0e79 100644
--- a/src/internal_rules.jl
+++ b/src/internal_rules.jl
@@ -923,7 +923,7 @@ function EnzymeRules.reverse(
end
function cofactor(A)
- cofA = similar(A)
+ cofA = similar(A)
minorAij = similar(A, size(A, 1) - 1, size(A, 2) - 1)
for i in 1:size(A, 1), j in 1:size(A, 2)
fill!(minorAij, zero(eltype(A)))
diff --git a/src/rules/customrules.jl b/src/rules/customrules.jl
index 415affb2..e83d73af 100644
--- a/src/rules/customrules.jl
+++ b/src/rules/customrules.jl
@@ -51,7 +51,7 @@ import LinearAlgebra
elseif partial <: AbstractVector
:(LinearAlgebra.dot(adjoint(partial),dx))
else
- :(LinearAlgebra.dot(conj(partial),dx))
+ :(LinearAlgebra.dot(conj(partial), dx))
end
return quote
Base.@_inline_meta
@@ -109,27 +109,27 @@ import LinearAlgebra
end
@inline function EnzymeCore.EnzymeRules.multiply_rev_into(prev, partial::Real, dx)
- EnzymeCore.EnzymeRules.multiply_fwd_into(prev, partial, dx)
+ return EnzymeCore.EnzymeRules.multiply_fwd_into(prev, partial, dx)
end
@inline function EnzymeCore.EnzymeRules.multiply_rev_into(prev, partial::Complex, dx)
- EnzymeCore.EnzymeRules.multiply_fwd_into(prev, conj(partial), dx)
+ return EnzymeCore.EnzymeRules.multiply_fwd_into(prev, conj(partial), dx)
end
@inline function EnzymeCore.EnzymeRules.multiply_rev_into(prev, partial::AbstractArray{<:Real}, dx::Number)
- EnzymeCore.EnzymeRules.multiply_fwd_into(prev, partial, dx)
+ return EnzymeCore.EnzymeRules.multiply_fwd_into(prev, partial, dx)
end
@inline function EnzymeCore.EnzymeRules.multiply_rev_into(prev, partial::AbstractArray{<:Complex}, dx::Number)
- EnzymeCore.EnzymeRules.multiply_fwd_into(prev, conj(partial), dx)
+ return EnzymeCore.EnzymeRules.multiply_fwd_into(prev, conj(partial), dx)
end
-@inline function EnzymeCore.EnzymeRules.multiply_rev_into(prev, partial::AbstractArray{<:Real, N}, dx::AbstractArray{<:Any, N}) where N
- EnzymeCore.EnzymeRules.multiply_fwd_into(prev, partial, dx)
+@inline function EnzymeCore.EnzymeRules.multiply_rev_into(prev, partial::AbstractArray{<:Real, N}, dx::AbstractArray{<:Any, N}) where {N}
+ return EnzymeCore.EnzymeRules.multiply_fwd_into(prev, partial, dx)
end
-@inline function EnzymeCore.EnzymeRules.multiply_rev_into(prev, partial::AbstractArray{<:Complex, N}, dx::AbstractArray{<:Any, N}) where N
- EnzymeCore.EnzymeRules.multiply_fwd_into(prev, conj(partial), dx)
+@inline function EnzymeCore.EnzymeRules.multiply_rev_into(prev, partial::AbstractArray{<:Complex, N}, dx::AbstractArray{<:Any, N}) where {N}
+ return EnzymeCore.EnzymeRules.multiply_fwd_into(prev, conj(partial), dx)
end
@inline function EnzymeCore.EnzymeRules.multiply_rev_into(prev, partial::AbstractVector{<:Complex}, dx::AbstractVector{<:Any})
@@ -137,21 +137,21 @@ end
end
@inline function EnzymeCore.EnzymeRules.multiply_rev_into(prev, partial::AbstractMatrix{<:Real}, dx::AbstractVector)
- EnzymeCore.EnzymeRules.multiply_fwd_into(prev, transpose(partial), dx)
+ return EnzymeCore.EnzymeRules.multiply_fwd_into(prev, transpose(partial), dx)
end
@inline function EnzymeCore.EnzymeRules.multiply_rev_into(prev, partial::AbstractMatrix{<:Complex}, dx::AbstractVector)
- EnzymeCore.EnzymeRules.multiply_fwd_into(prev, adjoint(partial), dx)
+ return EnzymeCore.EnzymeRules.multiply_fwd_into(prev, adjoint(partial), dx)
end
@inline function EnzymeCore.EnzymeRules.multiply_rev_into(prev, partial::AbstractArray{<:Real}, dx::AbstractArray)
- EnzymeCore.EnzymeRules.multiply_fwd_into(prev, Base.permutedims(partial, (((ndims(dx)+1):ndims(partial))..., Base.OneTo(ndims(dx))...)), dx)
+ return EnzymeCore.EnzymeRules.multiply_fwd_into(prev, Base.permutedims(partial, (((ndims(dx) + 1):ndims(partial))..., Base.OneTo(ndims(dx))...)), dx)
end
@inline function EnzymeCore.EnzymeRules.multiply_rev_into(prev, partial::AbstractArray{<:Complex}, dx::AbstractArray)
- pd = Base.permutedims(partial, (((ndims(dx)+1):ndims(partial))..., Base.OneTo(ndims(dx))...))
+ pd = Base.permutedims(partial, (((ndims(dx) + 1):ndims(partial))..., Base.OneTo(ndims(dx))...))
Base.conj!(pd)
- EnzymeCore.EnzymeRules.multiply_fwd_into(prev, pd, dx)
+ return EnzymeCore.EnzymeRules.multiply_fwd_into(prev, pd, dx)
end
function enzyme_custom_setup_args(
diff --git a/test/rules/internal_rules.jl b/test/rules/internal_rules.jl
index d9a60656..8ae1b8c2 100644
--- a/test/rules/internal_rules.jl
+++ b/test/rules/internal_rules.jl
@@ -210,17 +210,17 @@ end
@testset "(matrix) det" begin
@testset "forward" begin
- @testset for RT in (Const,DuplicatedNoNeed,Duplicated,),
- Tx in (Const,Duplicated,)
+ @testset for RT in (Const, DuplicatedNoNeed, Duplicated),
+ Tx in (Const, Duplicated)
xr = [4.0 3.0; 2.0 1.0]
test_forward(LinearAlgebra.det, RT, (xr, Tx))
- xc = [4.0+0.0im 3.0; 2.0-0.0im 1.0]
+ xc = [4.0 + 0.0im 3.0; 2.0 - 0.0im 1.0]
test_forward(LinearAlgebra.det, RT, (xc, Tx))
end
end
@testset "reverse" begin
- @testset for RT in (Const, Active,), Tx in (Const, Duplicated,)
+ @testset for RT in (Const, Active), Tx in (Const, Duplicated)
# TODO see https://github.com/EnzymeAD/Enzyme/issues/2537
if RT <: Const
@@ -230,7 +230,7 @@ end
x = [4.0 3.0; 2.0 1.0]
test_reverse(LinearAlgebra.det, RT, (x, Tx))
- x = [4.0+0.0im 3.0; 2.0-0.0im 1.0]
+ x = [4.0 + 0.0im 3.0; 2.0 - 0.0im 1.0]
test_reverse(LinearAlgebra.det, RT, (x, Tx))
end
end |
Member
So in this case it was actually testing complex [e.g. the random seeds had imag components], now fixed the complex failures from internal side
so you were acidentally doing for x in [...] because of a trailing comma |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Something very odd going on with some of this.
test_forwardfails for theMatrix{ComplexF64}even though it's (secretly) all real valuedtest_reverseseems to be running the rule on each element of the matrix argument individually @sethaxen any ideas why?