From d79e516d839bf0c6ecfe848ccb2473c5d457d99a Mon Sep 17 00:00:00 2001 From: adrhill Date: Wed, 9 Oct 2024 18:49:44 +0200 Subject: [PATCH 01/10] Remove more conditionals based on package version --- test/runtests.jl | 18 ++--- test/test_arrays.jl | 158 ++++++++++++++++++++---------------------- test/test_gradient.jl | 10 ++- test/test_hessian.jl | 38 +++++----- 4 files changed, 105 insertions(+), 119 deletions(-) diff --git a/test/runtests.jl b/test/runtests.jl index 8e9fd75..91b16b9 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -18,11 +18,9 @@ GROUP = get(ENV, "JULIA_SCT_TEST_GROUP", "Core") @testset verbose = true "SparseConnectivityTracer.jl" begin if GROUP in ("Core", "All") - if VERSION >= v"1.10" - @testset verbose = true "Linting" begin - @info "Testing linting..." - include("linting.jl") - end + @testset verbose = true "Linting" begin + @info "Testing linting..." + include("linting.jl") end end if GROUP in ("Core", "All") @@ -78,12 +76,10 @@ GROUP = get(ENV, "JULIA_SCT_TEST_GROUP", "Core") end end # Some extensions are only loaded in newer Julia releases - if VERSION >= v"1.10" - for ext in (:DataInterpolations,) - @testset "$ext" begin - @info "...$ext" - include("ext/test_$ext.jl") - end + for ext in (:DataInterpolations,) + @testset "$ext" begin + @info "...$ext" + include("ext/test_$ext.jl") end end end diff --git a/test/test_arrays.jl b/test/test_arrays.jl index 095f304..0525a16 100644 --- a/test/test_arrays.jl +++ b/test/test_arrays.jl @@ -188,60 +188,58 @@ arrayname(A) = "$(typeof(A)) $(size(A))" testH0(logabsdet_last, A) end - if VERSION >= v"1.9" - @testset "`SparseMatrixCSC` (3×3)" begin - A = rand(3, 3) - v = rand(3) - - # TODO: this is a temporary solution until sparse matrix inputs are supported (#28) - @testset "det" begin - testJ1(SparsifyInput(det), A) - testH1(SparsifyInput(det), A) - testJ1(SpdiagmifyInput(det), v) - testH1(SpdiagmifyInput(det), v) - end - @testset "logdet" begin - testJ1(SparsifyInput(logdet), A) - testH1(SparsifyInput(logdet), A) - testJ1(SpdiagmifyInput(logdet), v) - testH1(SpdiagmifyInput(logdet), v) - end - @testset "norm" begin - testJ1(SparsifyInput(norm), A) - testH1(SparsifyInput(norm), A) - testJ1(SpdiagmifyInput(norm), v) - testH1(SpdiagmifyInput(norm), v) - end - @testset "eigmax" begin - testJ1(SparsifyInput(eigmax), A) - testH1(SparsifyInput(eigmax), A) - testJ1(SpdiagmifyInput(eigmax), v) - testH1(SpdiagmifyInput(eigmax), v) - end - @testset "eigmin" begin - testJ1(SparsifyInput(eigmin), A) - testH1(SparsifyInput(eigmin), A) - testJ1(SpdiagmifyInput(eigmin), v) - testH1(SpdiagmifyInput(eigmin), v) - end - @testset "opnorm(x, 1)" begin - testJ1(SparsifyInput(opnorm1), A) - testH0(SparsifyInput(opnorm1), A) - testJ1(SpdiagmifyInput(opnorm1), v) - testH0(SpdiagmifyInput(opnorm1), v) - end - @testset "first(logabsdet(x))" begin - testJ1(SparsifyInput(logabsdet_first), A) - testH1(SparsifyInput(logabsdet_first), A) - testJ1(SpdiagmifyInput(logabsdet_first), v) - testH1(SpdiagmifyInput(logabsdet_first), v) - end - @testset "last(logabsdet(x))" begin - testJ0(SparsifyInput(logabsdet_last), A) - testH0(SparsifyInput(logabsdet_last), A) - testJ0(SpdiagmifyInput(logabsdet_last), v) - testH0(SpdiagmifyInput(logabsdet_last), v) - end + @testset "`SparseMatrixCSC` (3×3)" begin + A = rand(3, 3) + v = rand(3) + + # TODO: this is a temporary solution until sparse matrix inputs are supported (#28) + @testset "det" begin + testJ1(SparsifyInput(det), A) + testH1(SparsifyInput(det), A) + testJ1(SpdiagmifyInput(det), v) + testH1(SpdiagmifyInput(det), v) + end + @testset "logdet" begin + testJ1(SparsifyInput(logdet), A) + testH1(SparsifyInput(logdet), A) + testJ1(SpdiagmifyInput(logdet), v) + testH1(SpdiagmifyInput(logdet), v) + end + @testset "norm" begin + testJ1(SparsifyInput(norm), A) + testH1(SparsifyInput(norm), A) + testJ1(SpdiagmifyInput(norm), v) + testH1(SpdiagmifyInput(norm), v) + end + @testset "eigmax" begin + testJ1(SparsifyInput(eigmax), A) + testH1(SparsifyInput(eigmax), A) + testJ1(SpdiagmifyInput(eigmax), v) + testH1(SpdiagmifyInput(eigmax), v) + end + @testset "eigmin" begin + testJ1(SparsifyInput(eigmin), A) + testH1(SparsifyInput(eigmin), A) + testJ1(SpdiagmifyInput(eigmin), v) + testH1(SpdiagmifyInput(eigmin), v) + end + @testset "opnorm(x, 1)" begin + testJ1(SparsifyInput(opnorm1), A) + testH0(SparsifyInput(opnorm1), A) + testJ1(SpdiagmifyInput(opnorm1), v) + testH0(SpdiagmifyInput(opnorm1), v) + end + @testset "first(logabsdet(x))" begin + testJ1(SparsifyInput(logabsdet_first), A) + testH1(SparsifyInput(logabsdet_first), A) + testJ1(SpdiagmifyInput(logabsdet_first), v) + testH1(SpdiagmifyInput(logabsdet_first), v) + end + @testset "last(logabsdet(x))" begin + testJ0(SparsifyInput(logabsdet_last), A) + testH0(SparsifyInput(logabsdet_last), A) + testJ0(SpdiagmifyInput(logabsdet_last), v) + testH0(SpdiagmifyInput(logabsdet_last), v) end end end @@ -292,31 +290,29 @@ end testH1(pow3, A) end - if VERSION >= v"1.9" - A = rand(3, 3) - v = rand(3) + A = rand(3, 3) + v = rand(3) - @testset "`SparseMatrixCSC` (3×3)" begin - # TODO: this is a temporary solution until sparse matrix inputs are supported (#28) + @testset "`SparseMatrixCSC` (3×3)" begin + # TODO: this is a temporary solution until sparse matrix inputs are supported (#28) - testJ1(SparsifyInput(exp), A) - testH1(SparsifyInput(exp), A) + testJ1(SparsifyInput(exp), A) + testH1(SparsifyInput(exp), A) - testJ0(SparsifyInput(pow0), A) - testH0(SparsifyInput(pow0), A) + testJ0(SparsifyInput(pow0), A) + testH0(SparsifyInput(pow0), A) - testJ1(SparsifyInput(pow3), A) - testH1(SparsifyInput(pow3), A) + testJ1(SparsifyInput(pow3), A) + testH1(SparsifyInput(pow3), A) - testJ1(SpdiagmifyInput(exp), v) - testH1(SpdiagmifyInput(exp), v) + testJ1(SpdiagmifyInput(exp), v) + testH1(SpdiagmifyInput(exp), v) - testJ0(SpdiagmifyInput(pow0), v) - testH0(SpdiagmifyInput(pow0), v) + testJ0(SpdiagmifyInput(pow0), v) + testH0(SpdiagmifyInput(pow0), v) - testJ1(SpdiagmifyInput(pow3), v) - testH1(SpdiagmifyInput(pow3), v) - end + testJ1(SpdiagmifyInput(pow3), v) + testH1(SpdiagmifyInput(pow3), v) end # Functions that work on all matrices @@ -361,15 +357,13 @@ end @test all(t -> SCT.gradient(t) == s_out, vectors) end -if VERSION >= v"1.9" - @testset "SparseMatrixCSC construction" begin - t1 = TG(P(S(1))) - t2 = TG(P(S(2))) - t3 = TG(P(S(3))) - SA = sparse([t1 t2; t3 0]) - @test length(SA.nzval) == 3 +@testset "SparseMatrixCSC construction" begin + t1 = TG(P(S(1))) + t2 = TG(P(S(2))) + t3 = TG(P(S(3))) + SA = sparse([t1 t2; t3 0]) + @test length(SA.nzval) == 3 - res = opnorm(SA, 1) - @test SCT.gradient(res) == S([1, 2, 3]) - end + res = opnorm(SA, 1) + @test SCT.gradient(res) == S([1, 2, 3]) end diff --git a/test/test_gradient.jl b/test/test_gradient.jl index 45fe991..360774d 100644 --- a/test/test_gradient.jl +++ b/test/test_gradient.jl @@ -97,12 +97,10 @@ J(f, x) = jacobian_sparsity(f, x, detector) end @testset "ifelse and comparisons" begin - if VERSION >= v"1.8" - @test J(x -> ifelse(x[2] < x[3], x[1] + x[2], x[3] * x[4]), [1 2 3 4]) == - [1 1 1 1] - @test J(x -> ifelse(x[2] < x[3], x[1] + x[2], 1.0), [1 2 3 4]) == [1 1 0 0] - @test J(x -> ifelse(x[2] < x[3], 1.0, x[3] * x[4]), [1 2 3 4]) == [0 0 1 1] - end + @test J(x -> ifelse(x[2] < x[3], x[1] + x[2], x[3] * x[4]), [1 2 3 4]) == + [1 1 1 1] + @test J(x -> ifelse(x[2] < x[3], x[1] + x[2], 1.0), [1 2 3 4]) == [1 1 0 0] + @test J(x -> ifelse(x[2] < x[3], 1.0, x[3] * x[4]), [1 2 3 4]) == [0 0 1 1] function f_ampgo07(x) return (x[1] <= 0) * convert(eltype(x), Inf) + diff --git a/test/test_hessian.jl b/test/test_hessian.jl index c628ef7..f47014f 100644 --- a/test/test_hessian.jl +++ b/test/test_hessian.jl @@ -224,28 +224,26 @@ D = Dual{Int,T} end @testset "ifelse and comparisons" begin - if VERSION >= v"1.8" - @test H(x -> ifelse(x[1], x[1]^x[2], x[3] * x[4]), rand(4)) == [ - 1 1 0 0 - 1 1 0 0 - 0 0 0 1 - 0 0 1 0 - ] + @test H(x -> ifelse(x[1], x[1]^x[2], x[3] * x[4]), rand(4)) == [ + 1 1 0 0 + 1 1 0 0 + 0 0 0 1 + 0 0 1 0 + ] - @test H(x -> ifelse(x[1], x[1]^x[2], 1.0), rand(4)) == [ - 1 1 0 0 - 1 1 0 0 - 0 0 0 0 - 0 0 0 0 - ] + @test H(x -> ifelse(x[1], x[1]^x[2], 1.0), rand(4)) == [ + 1 1 0 0 + 1 1 0 0 + 0 0 0 0 + 0 0 0 0 + ] - @test H(x -> ifelse(x[1], 1.0, x[3] * x[4]), rand(4)) == [ - 0 0 0 0 - 0 0 0 0 - 0 0 0 1 - 0 0 1 0 - ] - end + @test H(x -> ifelse(x[1], 1.0, x[3] * x[4]), rand(4)) == [ + 0 0 0 0 + 0 0 0 0 + 0 0 0 1 + 0 0 1 0 + ] function f_ampgo07(x) return (x[1] <= 0) * convert(eltype(x), Inf) + From ec960a62eb839ddf72dd9338a99c58598d59bec2 Mon Sep 17 00:00:00 2001 From: adrhill Date: Wed, 9 Oct 2024 18:50:01 +0200 Subject: [PATCH 02/10] Test `RecursiveSet` --- test/tracers_definitions.jl | 1 + 1 file changed, 1 insertion(+) diff --git a/test/tracers_definitions.jl b/test/tracers_definitions.jl index 2b28ace..f7d6803 100644 --- a/test/tracers_definitions.jl +++ b/test/tracers_definitions.jl @@ -9,6 +9,7 @@ GRADIENT_PATTERNS = ( IndexSetGradientPattern{Int,Set{Int}}, IndexSetGradientPattern{Int,DuplicateVector{Int}}, IndexSetGradientPattern{Int,SortedVector{Int}}, + IndexSetGradientPattern{Int,RecursiveSet{Int}}, ) HESSIAN_PATTERNS_SHARED = ( From 30632bffc87b6ca83408d3b6159b6123522f2c83 Mon Sep 17 00:00:00 2001 From: adrhill Date: Wed, 9 Oct 2024 18:50:17 +0200 Subject: [PATCH 03/10] Remove `name` --- src/tracers.jl | 7 ------- test/test_constructors.jl | 11 ++++++++--- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/src/tracers.jl b/src/tracers.jl index 5e33d28..8367ce9 100644 --- a/src/tracers.jl +++ b/src/tracers.jl @@ -146,10 +146,3 @@ function create_tracers( tracers = create_tracers(T, xs, indices) return D.(xs, tracers) end - -# Pretty-printing of Dual tracers -name(::Type{T}) where {T<:GradientTracer} = "GradientTracer" -name(::Type{T}) where {T<:HessianTracer} = "HessianTracer" -name(::Type{D}) where {P,T,D<:Dual{P,T}} = "Dual-$(name(T))" -name(::T) where {T<:AbstractTracer} = name(T) -name(::D) where {D<:Dual} = name(D) diff --git a/test/test_constructors.jl b/test/test_constructors.jl index 4f04727..94be19b 100644 --- a/test/test_constructors.jl +++ b/test/test_constructors.jl @@ -1,12 +1,17 @@ # Test construction and conversions of internal tracer types using SparseConnectivityTracer: AbstractTracer, GradientTracer, HessianTracer, Dual -using SparseConnectivityTracer: primal, tracer, isemptytracer, myempty, name +using SparseConnectivityTracer: primal, tracer, isemptytracer, myempty, tracer_name using SparseConnectivityTracer: IndexSetGradientPattern using Test # Load definitions of GRADIENT_TRACERS, GRADIENT_PATTERNS, HESSIAN_TRACERS and HESSIAN_PATTERNS include("tracers_definitions.jl") +# Pretty-printing of Dual tracers +tracer_name(::Type{T}) where {T<:GradientTracer} = "GradientTracer" +tracer_name(::Type{T}) where {T<:HessianTracer} = "HessianTracer" +tracer_name(::Type{D}) where {P,T,D<:Dual{P,T}} = "Dual-$(tracer_name(T))" + function test_nested_duals(::Type{T}) where {T<:AbstractTracer} # Putting Duals into Duals is prohibited t = myempty(T) @@ -65,13 +70,13 @@ end function test_type_casting(::Type{D}) where {P,T,D<:Dual{P,T}} d_in = Dual(one(P), myempty(T)) - @testset "$(name(D)) to $(name(D))" begin + @testset "$(tracer_name(D)) to $(tracer_name(D))" begin d_out = D(d_in) @test primal(d_out) == primal(d_in) @test tracer(d_out) isa T @test isemptytracer(d_out) end - @testset "$P2 to $(name(D))" for P2 in (Int, Float32, Irrational) + @testset "$P2 to $(tracer_name(D))" for P2 in (Int, Float32, Irrational) p_in = one(P2) d_out = D(p_in) @test primal(d_out) == P(p_in) From 60a86a6a4f8888b61017d279df0987b9d8eea4f5 Mon Sep 17 00:00:00 2001 From: adrhill Date: Wed, 9 Oct 2024 18:50:28 +0200 Subject: [PATCH 04/10] Remove more conditionals --- src/overloads/arrays.jl | 10 ++-- src/overloads/ifelse_global.jl | 101 ++++++++++++++++----------------- 2 files changed, 53 insertions(+), 58 deletions(-) diff --git a/src/overloads/arrays.jl b/src/overloads/arrays.jl index 85ce3bc..903f044 100644 --- a/src/overloads/arrays.jl +++ b/src/overloads/arrays.jl @@ -204,10 +204,8 @@ end # On Tracers, `iszero` and `!iszero` don't return a boolean, # but we need a function that does to handle the structure of the array. -if VERSION >= v"1.9" # _iszero was added in JuliaSparse/SparseArrays.jl#177 - SparseArrays._iszero(t::AbstractTracer) = isemptytracer(t) - SparseArrays._iszero(d::Dual) = isemptytracer(tracer(d)) && iszero(primal(d)) +SparseArrays._iszero(t::AbstractTracer) = isemptytracer(t) +SparseArrays._iszero(d::Dual) = isemptytracer(tracer(d)) && iszero(primal(d)) - SparseArrays._isnotzero(t::AbstractTracer) = !isemptytracer(t) - SparseArrays._isnotzero(d::Dual) = !isemptytracer(tracer(d)) || !iszero(primal(d)) -end +SparseArrays._isnotzero(t::AbstractTracer) = !isemptytracer(t) +SparseArrays._isnotzero(d::Dual) = !isemptytracer(tracer(d)) || !iszero(primal(d)) diff --git a/src/overloads/ifelse_global.jl b/src/overloads/ifelse_global.jl index 1d8c53a..beeed0b 100644 --- a/src/overloads/ifelse_global.jl +++ b/src/overloads/ifelse_global.jl @@ -1,58 +1,55 @@ -@static if VERSION >= v"1.8" - function Base.ifelse(::AbstractTracer, x, y) - size(x) != size(y) && throw( - DimensionMismatch( - "Output sizes of x and y in `ifelse(condition, x, y)` don't match in size.", - ), - ) - return output_union(x, y) - end +function Base.ifelse(::AbstractTracer, x, y) + size(x) != size(y) && throw( + DimensionMismatch( + "Output sizes of x and y in `ifelse(condition, x, y)` don't match in size." + ), + ) + return output_union(x, y) +end - ## output union on scalar outputs - function output_union(tx::T, ty::T) where {T<:GradientTracer} - return T(output_union(pattern(tx), pattern(ty))) # return tracer - end - function output_union(px::P, py::P) where {P<:IndexSetGradientPattern} - return P(union(gradient(px), gradient(py))) # return pattern - end +## output union on scalar outputs +function output_union(tx::T, ty::T) where {T<:GradientTracer} + return T(output_union(pattern(tx), pattern(ty))) # return tracer +end +function output_union(px::P, py::P) where {P<:IndexSetGradientPattern} + return P(union(gradient(px), gradient(py))) # return pattern +end - function output_union(tx::T, ty::T) where {T<:HessianTracer} - return T(output_union(pattern(tx), pattern(ty))) # return tracer - end - function output_union(px::P, py::P) where {P<:AbstractHessianPattern} - return output_union(px, py, shared(P)) # return pattern - end - function output_union(px::P, py::P, ::Shared) where {P<:AbstractHessianPattern} - g_out = union(gradient(px), gradient(py)) - hx, hy = hessian(px), hessian(py) - hx !== hy && error("Expected shared Hessians, got $hx, $hy.") - return P(g_out, hx) # return pattern - end +function output_union(tx::T, ty::T) where {T<:HessianTracer} + return T(output_union(pattern(tx), pattern(ty))) # return tracer +end +function output_union(px::P, py::P) where {P<:AbstractHessianPattern} + return output_union(px, py, shared(P)) # return pattern +end +function output_union(px::P, py::P, ::Shared) where {P<:AbstractHessianPattern} + g_out = union(gradient(px), gradient(py)) + hx, hy = hessian(px), hessian(py) + hx !== hy && error("Expected shared Hessians, got $hx, $hy.") + return P(g_out, hx) # return pattern +end - function output_union(px::P, py::P, ::NotShared) where {P<:IndexSetHessianPattern} - g_out = union(gradient(px), gradient(py)) - h_out = union(hessian(px), hessian(py)) - return P(g_out, h_out) # return pattern - end - function output_union(px::P, py::P, ::NotShared) where {P<:DictHessianPattern} - g_out = union(gradient(px), gradient(py)) - h_out = myunion!(deepcopy(hessian(px)), hessian(py)) - return P(g_out, h_out) # return pattern - end +function output_union(px::P, py::P, ::NotShared) where {P<:IndexSetHessianPattern} + g_out = union(gradient(px), gradient(py)) + h_out = union(hessian(px), hessian(py)) + return P(g_out, h_out) # return pattern +end +function output_union(px::P, py::P, ::NotShared) where {P<:DictHessianPattern} + g_out = union(gradient(px), gradient(py)) + h_out = myunion!(deepcopy(hessian(px)), hessian(py)) + return P(g_out, h_out) # return pattern +end - output_union(tx::AbstractTracer, y) = tx - output_union(x, ty::AbstractTracer) = ty +output_union(tx::AbstractTracer, y) = tx +output_union(x, ty::AbstractTracer) = ty - ## output union on AbstractArray outputs - function output_union( - tx::AbstractArray{T}, ty::AbstractArray{T} - ) where {T<:AbstractTracer} - return output_union.(tx, ty) - end - function output_union(tx::AbstractArray{T}, y::AbstractArray) where {T<:AbstractTracer} - return tx - end - function output_union(x::AbstractArray, ty::AbstractArray{T}) where {T<:AbstractTracer} - return ty - end +## output union on AbstractArray outputs +# TODO: add test +function output_union(tx::AbstractArray{T}, ty::AbstractArray{T}) where {T<:AbstractTracer} + return output_union.(tx, ty) +end +function output_union(tx::AbstractArray{T}, y::AbstractArray) where {T<:AbstractTracer} + return tx +end +function output_union(x::AbstractArray, ty::AbstractArray{T}) where {T<:AbstractTracer} + return ty end From 867d60d281339701c292985a19000bfc06bdcbd6 Mon Sep 17 00:00:00 2001 From: adrhill Date: Wed, 9 Oct 2024 18:50:37 +0200 Subject: [PATCH 05/10] Remove dead code --- src/tracers.jl | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/src/tracers.jl b/src/tracers.jl index 8367ce9..9d66f9a 100644 --- a/src/tracers.jl +++ b/src/tracers.jl @@ -39,7 +39,6 @@ end GradientTracer{P}(::Real) where {P} = myempty(GradientTracer{P}) GradientTracer{P}(t::GradientTracer{P}) where {P} = t -GradientTracer(t::GradientTracer) = t isemptytracer(t::GradientTracer) = t.isempty pattern(t::GradientTracer) = t.pattern @@ -70,7 +69,6 @@ end HessianTracer{P}(::Real) where {P} = myempty(HessianTracer{P}) HessianTracer{P}(t::HessianTracer{P}) where {P} = t -HessianTracer(t::HessianTracer) = t isemptytracer(t::HessianTracer) = t.isempty pattern(t::HessianTracer) = t.pattern @@ -103,11 +101,7 @@ end primal(d::Dual) = d.primal tracer(d::Dual) = d.tracer - -gradient(d::Dual{P,T}) where {P,T<:GradientTracer} = gradient(tracer(d)) -gradient(d::Dual{P,T}) where {P,T<:HessianTracer} = gradient(tracer(d)) -hessian(d::Dual{P,T}) where {P,T<:HessianTracer} = hessian(tracer(d)) -isemptytracer(d::Dual) = isemptytracer(tracer(d)) +isemptytracer(d::Dual) = isemptytracer(tracer(d)) Dual{P,T}(d::Dual{P,T}) where {P<:Real,T<:AbstractTracer} = d Dual(primal::P, tracer::T) where {P,T} = Dual{P,T}(primal, tracer) @@ -122,8 +116,6 @@ end shared(::Type{T}) where {P,T<:HessianTracer{P}} = shared(P) -myempty(::T) where {T<:AbstractTracer} = myempty(T) - myempty(::Type{GradientTracer{P}}) where {P} = GradientTracer{P}(myempty(P), true) myempty(::Type{HessianTracer{P}}) where {P} = HessianTracer{P}(myempty(P), true) From e2f7b1d3d482a0093ebefb946c9cb4bb662d0967 Mon Sep 17 00:00:00 2001 From: adrhill Date: Wed, 9 Oct 2024 18:52:32 +0200 Subject: [PATCH 06/10] Exclude test folder from codecov Lines including `@testset` don't get recognized as run, reducing coverage metric by a lot. --- .github/workflows/CI.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 5573dc2..283834b 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -43,7 +43,7 @@ jobs: JULIA_SCT_TEST_GROUP: ${{ matrix.group }} - uses: julia-actions/julia-processcoverage@v1 with: - directories: src,ext,test,benchmark + directories: src,ext,benchmark - uses: codecov/codecov-action@v4 with: token: ${{ secrets.CODECOV_TOKEN }} From d75319520e6e74a17cc2ea7da50f1fdd784b084b Mon Sep 17 00:00:00 2001 From: adrhill Date: Wed, 9 Oct 2024 18:59:08 +0200 Subject: [PATCH 07/10] Remove more dead code --- src/overloads/gradient_tracer.jl | 7 ------- 1 file changed, 7 deletions(-) diff --git a/src/overloads/gradient_tracer.jl b/src/overloads/gradient_tracer.jl index e1e9bd5..6a44198 100644 --- a/src/overloads/gradient_tracer.jl +++ b/src/overloads/gradient_tracer.jl @@ -10,14 +10,7 @@ function gradient_tracer_1_to_1(t::T, is_der1_zero::Bool) where {T<:GradientTrac end end -function gradient_tracer_1_to_1_inner( - p::P, is_der1_zero::Bool -) where {P<:IndexSetGradientPattern} - return P(gradient_tracer_1_to_1_inner(gradient(p), is_der1_zero)) # return pattern -end - # This is only required because it is called by HessianTracer with IndexSetHessianPattern -# Otherwise, we would just have the method on IndexSetGradientPattern above. function gradient_tracer_1_to_1_inner( s::S, is_der1_zero::Bool ) where {S<:AbstractSet{<:Integer}} From ac067b98d73b4f2bfdfc40175c5b7c97517b3a5f Mon Sep 17 00:00:00 2001 From: adrhill Date: Wed, 9 Oct 2024 18:59:30 +0200 Subject: [PATCH 08/10] Update DataInterpolations compat entry --- Project.toml | 2 +- test/ext/test_DataInterpolations.jl | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Project.toml b/Project.toml index 400e399..00d02c1 100644 --- a/Project.toml +++ b/Project.toml @@ -27,7 +27,7 @@ SparseConnectivityTracerSpecialFunctionsExt = "SpecialFunctions" [compat] ADTypes = "1" -DataInterpolations = "6.2" +DataInterpolations = "6.4.2" DocStringExtensions = "0.9" FillArrays = "1" LinearAlgebra = "<0.0.1, 1" diff --git a/test/ext/test_DataInterpolations.jl b/test/ext/test_DataInterpolations.jl index 277b92d..87c6ad2 100644 --- a/test/ext/test_DataInterpolations.jl +++ b/test/ext/test_DataInterpolations.jl @@ -260,7 +260,7 @@ for N in (2, 5) InterpolationTest( N, ConstantInterpolation(um, t); is_der1_zero=true, is_der2_zero=true ), - # InterpolationTest(N, LinearInterpolation(um, t); is_der2_zero=true), # TODO: include once https://github.com/SciML/DataInterpolations.jl/pull/335 is settled + InterpolationTest(N, LinearInterpolation(um, t); is_der2_zero=true), InterpolationTest(N, QuadraticInterpolation(um, t)), InterpolationTest(N, LagrangeInterpolation(um, t)), ## The following interpolations appear to not be supported on N dimensions as of DataInterpolations v6.2.0: From f93d189f92a245cb53eb983e4f70d4ef5cb10c44 Mon Sep 17 00:00:00 2001 From: adrhill Date: Wed, 9 Oct 2024 19:03:30 +0200 Subject: [PATCH 09/10] Appease JET --- src/tracers.jl | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/tracers.jl b/src/tracers.jl index 9d66f9a..74382e8 100644 --- a/src/tracers.jl +++ b/src/tracers.jl @@ -101,7 +101,11 @@ end primal(d::Dual) = d.primal tracer(d::Dual) = d.tracer -isemptytracer(d::Dual) = isemptytracer(tracer(d)) + +gradient(d::Dual{P,T}) where {P,T<:GradientTracer} = gradient(tracer(d)) +gradient(d::Dual{P,T}) where {P,T<:HessianTracer} = gradient(tracer(d)) +hessian(d::Dual{P,T}) where {P,T<:HessianTracer} = hessian(tracer(d)) +isemptytracer(d::Dual) = isemptytracer(tracer(d)) Dual{P,T}(d::Dual{P,T}) where {P<:Real,T<:AbstractTracer} = d Dual(primal::P, tracer::T) where {P,T} = Dual{P,T}(primal, tracer) From a841b8b43d3dc5b2bcecf375b748e3d58d01cbc2 Mon Sep 17 00:00:00 2001 From: adrhill Date: Wed, 9 Oct 2024 19:19:12 +0200 Subject: [PATCH 10/10] Minor fix --- test/test_constructors.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_constructors.jl b/test/test_constructors.jl index 94be19b..8e15f1b 100644 --- a/test/test_constructors.jl +++ b/test/test_constructors.jl @@ -1,6 +1,6 @@ # Test construction and conversions of internal tracer types using SparseConnectivityTracer: AbstractTracer, GradientTracer, HessianTracer, Dual -using SparseConnectivityTracer: primal, tracer, isemptytracer, myempty, tracer_name +using SparseConnectivityTracer: primal, tracer, isemptytracer, myempty using SparseConnectivityTracer: IndexSetGradientPattern using Test