From 9524f62d0e8b1d4f70504d9b8419aaf04c8f4cc8 Mon Sep 17 00:00:00 2001 From: Charles Kawczynski Date: Sat, 31 Oct 2020 08:21:00 -0700 Subject: [PATCH 01/12] Add DiffResult for MArray --- src/DiffResults.jl | 1 + 1 file changed, 1 insertion(+) diff --git a/src/DiffResults.jl b/src/DiffResults.jl index d689185..8d9ec4a 100644 --- a/src/DiffResults.jl +++ b/src/DiffResults.jl @@ -47,6 +47,7 @@ DiffResult DiffResult(value::Number, derivs::Tuple{Vararg{Number}}) = ImmutableDiffResult(value, derivs) DiffResult(value::Number, derivs::Tuple{Vararg{StaticArray}}) = ImmutableDiffResult(value, derivs) DiffResult(value::StaticArray, derivs::Tuple{Vararg{StaticArray}}) = ImmutableDiffResult(value, derivs) +DiffResult(value::MArray, derivs::Tuple{Vararg{StaticArray}}) = MutableDiffResult(value, derivs) DiffResult(value::Number, derivs::Tuple{Vararg{AbstractArray}}) = MutableDiffResult(value, derivs) DiffResult(value::AbstractArray, derivs::Tuple{Vararg{AbstractArray}}) = MutableDiffResult(value, derivs) DiffResult(value::Union{Number,AbstractArray}, derivs::Union{Number,AbstractArray}...) = DiffResult(value, derivs) From f7c8877e215cffe9184d859127824c07703896cf Mon Sep 17 00:00:00 2001 From: Charles Kawczynski Date: Tue, 10 Nov 2020 14:34:18 -0800 Subject: [PATCH 02/12] Add DiffResult for SizedArray --- src/DiffResults.jl | 1 + 1 file changed, 1 insertion(+) diff --git a/src/DiffResults.jl b/src/DiffResults.jl index 8d9ec4a..0bd8cdf 100644 --- a/src/DiffResults.jl +++ b/src/DiffResults.jl @@ -48,6 +48,7 @@ DiffResult(value::Number, derivs::Tuple{Vararg{Number}}) = ImmutableDiffResult(v DiffResult(value::Number, derivs::Tuple{Vararg{StaticArray}}) = ImmutableDiffResult(value, derivs) DiffResult(value::StaticArray, derivs::Tuple{Vararg{StaticArray}}) = ImmutableDiffResult(value, derivs) DiffResult(value::MArray, derivs::Tuple{Vararg{StaticArray}}) = MutableDiffResult(value, derivs) +DiffResult(value::SizedArray, derivs::Tuple{Vararg{StaticArray}}) = MutableDiffResult(value, derivs) DiffResult(value::Number, derivs::Tuple{Vararg{AbstractArray}}) = MutableDiffResult(value, derivs) DiffResult(value::AbstractArray, derivs::Tuple{Vararg{AbstractArray}}) = MutableDiffResult(value, derivs) DiffResult(value::Union{Number,AbstractArray}, derivs::Union{Number,AbstractArray}...) = DiffResult(value, derivs) From 2b16fe95cabf79467397e0a514d7fc89538c83e2 Mon Sep 17 00:00:00 2001 From: Guillaume Dalle <22795598+gdalle@users.noreply.github.com> Date: Tue, 19 Mar 2024 07:04:48 +0100 Subject: [PATCH 03/12] Update src/DiffResults.jl --- src/DiffResults.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/DiffResults.jl b/src/DiffResults.jl index 0bd8cdf..c8c4537 100644 --- a/src/DiffResults.jl +++ b/src/DiffResults.jl @@ -47,7 +47,7 @@ DiffResult DiffResult(value::Number, derivs::Tuple{Vararg{Number}}) = ImmutableDiffResult(value, derivs) DiffResult(value::Number, derivs::Tuple{Vararg{StaticArray}}) = ImmutableDiffResult(value, derivs) DiffResult(value::StaticArray, derivs::Tuple{Vararg{StaticArray}}) = ImmutableDiffResult(value, derivs) -DiffResult(value::MArray, derivs::Tuple{Vararg{StaticArray}}) = MutableDiffResult(value, derivs) +DiffResult(value::MArray, derivs::Tuple{Vararg{MArray}}) = MutableDiffResult(value, derivs) DiffResult(value::SizedArray, derivs::Tuple{Vararg{StaticArray}}) = MutableDiffResult(value, derivs) DiffResult(value::Number, derivs::Tuple{Vararg{AbstractArray}}) = MutableDiffResult(value, derivs) DiffResult(value::AbstractArray, derivs::Tuple{Vararg{AbstractArray}}) = MutableDiffResult(value, derivs) From c25b292299e983ef7a003f5c34f03867bca6b9c2 Mon Sep 17 00:00:00 2001 From: Guillaume Dalle <22795598+gdalle@users.noreply.github.com> Date: Tue, 19 Mar 2024 07:04:55 +0100 Subject: [PATCH 04/12] Update src/DiffResults.jl --- src/DiffResults.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/DiffResults.jl b/src/DiffResults.jl index c8c4537..a46a595 100644 --- a/src/DiffResults.jl +++ b/src/DiffResults.jl @@ -48,7 +48,7 @@ DiffResult(value::Number, derivs::Tuple{Vararg{Number}}) = ImmutableDiffResult(v DiffResult(value::Number, derivs::Tuple{Vararg{StaticArray}}) = ImmutableDiffResult(value, derivs) DiffResult(value::StaticArray, derivs::Tuple{Vararg{StaticArray}}) = ImmutableDiffResult(value, derivs) DiffResult(value::MArray, derivs::Tuple{Vararg{MArray}}) = MutableDiffResult(value, derivs) -DiffResult(value::SizedArray, derivs::Tuple{Vararg{StaticArray}}) = MutableDiffResult(value, derivs) +DiffResult(value::SizedArray, derivs::Tuple{Vararg{SizedArray}}) = MutableDiffResult(value, derivs) DiffResult(value::Number, derivs::Tuple{Vararg{AbstractArray}}) = MutableDiffResult(value, derivs) DiffResult(value::AbstractArray, derivs::Tuple{Vararg{AbstractArray}}) = MutableDiffResult(value, derivs) DiffResult(value::Union{Number,AbstractArray}, derivs::Union{Number,AbstractArray}...) = DiffResult(value, derivs) From 51603968d7940fdd2bdec54ee655aff0b052ae63 Mon Sep 17 00:00:00 2001 From: Guillaume Dalle <22795598+gdalle@users.noreply.github.com> Date: Tue, 19 Mar 2024 07:08:00 +0100 Subject: [PATCH 05/12] Merge master --- src/DiffResults.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/DiffResults.jl b/src/DiffResults.jl index d5b1c8e..bfad8df 100644 --- a/src/DiffResults.jl +++ b/src/DiffResults.jl @@ -1,6 +1,6 @@ module DiffResults -using StaticArraysCore: StaticArray, similar_type, Size +using StaticArraysCore: StaticArray, similar_type, Size, MArray, SizedArray ######### # Types # From 061a09c411432fec08a92867dcefaaaf3b8f42ba Mon Sep 17 00:00:00 2001 From: Guillaume Dalle <22795598+gdalle@users.noreply.github.com> Date: Tue, 19 Mar 2024 07:39:07 +0100 Subject: [PATCH 06/12] Add tests --- Manifest.toml | 10 +++++ src/DiffResults.jl | 10 ++--- test/runtests.jl | 93 ++++++++++++++++++++++++++++++++++++++++------ 3 files changed, 95 insertions(+), 18 deletions(-) create mode 100644 Manifest.toml diff --git a/Manifest.toml b/Manifest.toml new file mode 100644 index 0000000..dad4f31 --- /dev/null +++ b/Manifest.toml @@ -0,0 +1,10 @@ +# This file is machine-generated - editing it directly is not advised + +julia_version = "1.10.2" +manifest_format = "2.0" +project_hash = "b991d1a0321e0a74caa38487cb8a73b177987329" + +[[deps.StaticArraysCore]] +git-tree-sha1 = "36b3d696ce6366023a0ea192b4cd442268995a0d" +uuid = "1e83bf80-4336-4d27-bf5d-d5a4f845583c" +version = "1.4.2" diff --git a/src/DiffResults.jl b/src/DiffResults.jl index bfad8df..db0023a 100644 --- a/src/DiffResults.jl +++ b/src/DiffResults.jl @@ -1,6 +1,6 @@ module DiffResults -using StaticArraysCore: StaticArray, similar_type, Size, MArray, SizedArray +using StaticArraysCore: StaticArray, similar_type, Size, SArray ######### # Types # @@ -36,7 +36,7 @@ Return `r::DiffResult`, with output value storage provided by `value` and output storage provided by `derivs`. In reality, `DiffResult` is an abstract supertype of two concrete types, `MutableDiffResult` -and `ImmutableDiffResult`. If all `value`/`derivs` are all `Number`s or `StaticArray`s, +and `ImmutableDiffResult`. If all `value`/`derivs` are all `Number`s or `StaticArrays.SArray`s, then `r` will be immutable (i.e. `r::ImmutableDiffResult`). Otherwise, `r` will be mutable (i.e. `r::MutableDiffResult`). @@ -45,10 +45,8 @@ Note that `derivs` can be provide in splatted form, i.e. `DiffResult(value, deri DiffResult DiffResult(value::Number, derivs::Tuple{Vararg{Number}}) = ImmutableDiffResult(value, derivs) -DiffResult(value::Number, derivs::Tuple{Vararg{StaticArray}}) = ImmutableDiffResult(value, derivs) -DiffResult(value::StaticArray, derivs::Tuple{Vararg{StaticArray}}) = ImmutableDiffResult(value, derivs) -DiffResult(value::MArray, derivs::Tuple{Vararg{MArray}}) = MutableDiffResult(value, derivs) -DiffResult(value::SizedArray, derivs::Tuple{Vararg{SizedArray}}) = MutableDiffResult(value, derivs) +DiffResult(value::Number, derivs::Tuple{Vararg{SArray}}) = ImmutableDiffResult(value, derivs) +DiffResult(value::SArray, derivs::Tuple{Vararg{SArray}}) = ImmutableDiffResult(value, derivs) DiffResult(value::Number, derivs::Tuple{Vararg{AbstractArray}}) = MutableDiffResult(value, derivs) DiffResult(value::AbstractArray, derivs::Tuple{Vararg{AbstractArray}}) = MutableDiffResult(value, derivs) DiffResult(value::Union{Number,AbstractArray}, derivs::Union{Number,AbstractArray}...) = DiffResult(value, derivs) diff --git a/test/runtests.jl b/test/runtests.jl index 41affbe..b4d12bd 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,8 +1,8 @@ using DiffResults, StaticArrays, Test using DiffResults: DiffResult, GradientResult, JacobianResult, HessianResult, - value, value!, derivative, derivative!, gradient, gradient!, - jacobian, jacobian!, hessian, hessian! + value, value!, derivative, derivative!, gradient, gradient!, + jacobian, jacobian!, hessian, hessian! @testset "DiffResult" begin @@ -10,9 +10,13 @@ using DiffResults: DiffResult, GradientResult, JacobianResult, HessianResult, n0, n1, n2 = rand(), rand(), rand() x0, x1, x2 = rand(k), rand(k, k), rand(k, k, k) s0, s1, s2 = SVector{k}(rand(k)), SMatrix{k,k}(rand(k, k)), SArray{Tuple{k,k,k}}(rand(k, k, k)) + m0, m1, m2 = MVector{k}(rand(k)), MMatrix{k,k}(rand(k, k)), MArray{Tuple{k,k,k}}(rand(k, k, k)) + y0, y1, y2 = SizedVector{k}(rand(k)), SizedMatrix{k,k}(rand(k, k)), SizedArray{Tuple{k,k,k}}(rand(k, k, k)) + rn = DiffResult(n0, n1, n2) rx = DiffResult(x0, x1, x2) rs = DiffResult(s0, s1, s2) + rm = DiffResult(m0, m1, m2) rsmix = DiffResult(n0, s0, s1) issimilar(x, y) = typeof(x) == typeof(y) && size(x) == size(y) @@ -22,6 +26,7 @@ using DiffResults: DiffResult, GradientResult, JacobianResult, HessianResult, @test rn === DiffResult(n0, n1, n2) @test rx == DiffResult(x0, x1, x2) @test rs === DiffResult(s0, s1, s2) + @test rm == DiffResult(m0, m1, m2) @test rsmix === DiffResult(n0, s0, s1) @test issimilar(GradientResult(x0), DiffResult(first(x0), x0)) @@ -31,12 +36,18 @@ using DiffResults: DiffResult, GradientResult, JacobianResult, HessianResult, @test GradientResult(s0) === DiffResult(first(s0), s0) @test JacobianResult(s0) === DiffResult(s0, zeros(SMatrix{k,k,Float64})) - @test JacobianResult(SVector{k+1}(vcat(s0, 0.0)), s0) === DiffResult(SVector{k+1}(vcat(s0, 0.0)), zeros(SMatrix{k+1,k,Float64})) + @test JacobianResult(SVector{k + 1}(vcat(s0, 0.0)), s0) === DiffResult(SVector{k + 1}(vcat(s0, 0.0)), zeros(SMatrix{k + 1,k,Float64})) @test HessianResult(s0) === DiffResult(first(s0), s0, zeros(SMatrix{k,k,Float64})) + @test issimilar(GradientResult(m0), DiffResult(first(m0), m0)) + @test issimilar(JacobianResult(m0), DiffResult(m0, zeros(MMatrix{k,k,Float64}))) + @test issimilar(JacobianResult(MVector{k + 1}(vcat(m0, 0.0)), m0), DiffResult(MVector{k + 1}(vcat(m0, 0.0)), zeros(MMatrix{k + 1,k,Float64}))) + @test issimilar(HessianResult(m0), DiffResult(first(m0), m0, zeros(MMatrix{k,k,Float64}))) + @test eltype(rn) === typeof(n0) @test eltype(rx) === eltype(x0) @test eltype(rs) === eltype(s0) + @test eltype(rm) === eltype(m0) rn_copy = copy(rn) @test rn == rn_copy @@ -50,6 +61,10 @@ using DiffResults: DiffResult, GradientResult, JacobianResult, HessianResult, @test rs == rs_copy @test rs === rs_copy + rm_copy = copy(rm) + @test rm == rm_copy + @test rm !== rm_copy + rsmix_copy = copy(rsmix) @test rsmix == rsmix_copy @test rsmix === rsmix_copy @@ -59,6 +74,7 @@ using DiffResults: DiffResult, GradientResult, JacobianResult, HessianResult, @test value(rn) === n0 @test value(rx) === x0 @test value(rs) === s0 + @test value(rm) === m0 @test value(rsmix) === n0 rn = value!(rn, n1) @@ -76,6 +92,11 @@ using DiffResults: DiffResult, GradientResult, JacobianResult, HessianResult, @test typeof(value(rs)) === typeof(s0) rs = value!(rs, s0) + m0_new, m0_copy = rand(k), copy(m0) + rm = value!(rm, m0_new) + @test value(rm) === m0 == m0_new + rm = value!(rm, m0_copy) + rsmix = value!(rsmix, n1) @test value(rsmix) === n1 rsmix = value!(rsmix, n0) @@ -95,12 +116,17 @@ using DiffResults: DiffResult, GradientResult, JacobianResult, HessianResult, @test typeof(value(rs)) === typeof(s0) rs = value!(rs, s0) + m0_new, m0_copy = rand(k), copy(m0) + rm = value!(exp, rm, m0_new) + @test value(rm) === m0 == exp.(m0_new) + rm = value!(rm, m0_copy) + rsmix = value!(exp, rsmix, n1) @test value(rsmix) === exp(n1) rsmix = value!(rsmix, n0) ksqrt = Int(sqrt(k)) - T = typeof(SMatrix{ksqrt,ksqrt}(rand(ksqrt,ksqrt))) + T = typeof(SMatrix{ksqrt,ksqrt}(rand(ksqrt, ksqrt))) rs_new = value!(rs, convert(T, value(rs))) @test rs_new === rs end @@ -116,6 +142,9 @@ using DiffResults: DiffResult, GradientResult, JacobianResult, HessianResult, @test derivative(rs) === s1 @test derivative(rs, Val{2}) === s2 + @test derivative(rm) === m1 + @test derivative(rm, Val{2}) === m2 + @test derivative(rsmix) === s0 @test derivative(rsmix, Val{2}) === s1 @@ -140,6 +169,11 @@ using DiffResults: DiffResult, GradientResult, JacobianResult, HessianResult, @test typeof(derivative(rsmix)) === typeof(s0) rsmix = derivative!(rsmix, s0) + m1_new, m1_copy = rand(k, k), copy(m1) + rm = derivative!(rm, m1_new) + @test derivative(rm) === m1 == m1_new + rm = derivative!(rm, m1_copy) + rn = derivative!(rn, n1, Val{2}) @test derivative(rn, Val{2}) === n1 rn = derivative!(rn, n2, Val{2}) @@ -161,6 +195,11 @@ using DiffResults: DiffResult, GradientResult, JacobianResult, HessianResult, @test typeof(derivative(rsmix, Val{2})) === typeof(s1) rsmix = derivative!(rsmix, s1, Val{2}) + m2_new, m2_copy = rand(k, k, k), copy(m2) + rm = derivative!(rm, m2_new, Val{2}) + @test derivative(rm, Val{2}) === m2 == m2_new + rm = derivative!(rm, m2_copy, Val{2}) + rn = derivative!(exp, rn, n0) @test derivative(rn) === exp(n0) rn = derivative!(rn, n1) @@ -182,6 +221,11 @@ using DiffResults: DiffResult, GradientResult, JacobianResult, HessianResult, @test typeof(derivative(rsmix)) === typeof(s0) rsmix = derivative!(exp, rsmix, s0) + m1_new, m1_copy = rand(k, k), copy(m1) + rm = derivative!(exp, rm, m1_new) + @test derivative(rm) === m1 == exp.(m1_new) + rm = derivative!(exp, rm, m1_copy) + rn = derivative!(exp, rn, n1, Val{2}) @test derivative(rn, Val{2}) === exp(n1) rn = derivative!(rn, n2, Val{2}) @@ -202,6 +246,11 @@ using DiffResults: DiffResult, GradientResult, JacobianResult, HessianResult, @test derivative(rsmix, Val{2}) == exp.(s1_new) @test typeof(derivative(rsmix, Val{2})) === typeof(s1) rsmix = derivative!(exp, rsmix, s1, Val{2}) + + m2_new, m2_copy = rand(k, k, k), copy(m2) + rm = derivative!(exp, rm, m2_new, Val{2}) + @test derivative(rm, Val{2}) === m2 == exp.(m2_new) + rm = derivative!(exp, rm, m2_copy, Val{2}) end @testset "gradient/gradient!" begin @@ -217,10 +266,10 @@ using DiffResults: DiffResult, GradientResult, JacobianResult, HessianResult, @test typeof(gradient(rs)) === typeof(s1) rs = gradient!(rs, s1) - x1_new, x1_copy = rand(k, k), copy(x1) - rx = gradient!(exp, rx, x1_new) - @test gradient(rx) === x1 == exp.(x1_new) - rx = gradient!(exp, rx, x1_copy) + m1_new, m1_copy = rand(k, k), copy(m1) + rm = gradient!(rm, m1_new) + @test gradient(rm) === m1 == m1_new + rm = gradient!(rm, m1_copy) s0_new = rand(k) rsmix = gradient!(exp, rsmix, s0_new) @@ -228,12 +277,12 @@ using DiffResults: DiffResult, GradientResult, JacobianResult, HessianResult, @test typeof(gradient(rsmix)) === typeof(s0) rsmix = gradient!(exp, rsmix, s0) - T = typeof(SVector{k*k}(rand(k*k))) + T = typeof(SVector{k * k}(rand(k * k))) rs_new = gradient!(rs, convert(T, gradient(rs))) @test rs_new === rs end - @testset "jacobian/jacobian!" begin + @testset "jacobian/jacobian!" begin x1_new, x1_copy = rand(k, k), copy(x1) rx = jacobian!(rx, x1_new) @@ -246,6 +295,11 @@ using DiffResults: DiffResult, GradientResult, JacobianResult, HessianResult, @test typeof(jacobian(rs)) === typeof(s1) rs = jacobian!(rs, s1) + m1_new, m1_copy = rand(k, k), copy(m1) + rm = jacobian!(rm, m1_new) + @test jacobian(rm) === m1 == m1_new + rm = jacobian!(rm, m1_copy) + x1_new, x1_copy = rand(k, k), copy(x1) rx = jacobian!(exp, rx, x1_new) @test jacobian(rx) === x1 == exp.(x1_new) @@ -257,7 +311,12 @@ using DiffResults: DiffResult, GradientResult, JacobianResult, HessianResult, @test typeof(jacobian(rsmix)) === typeof(s0) rsmix = jacobian!(exp, rsmix, s0) - T = typeof(SVector{k*k}(rand(k*k))) + m1_new, m1_copy = rand(k, k), copy(m1) + rm = jacobian!(exp, rm, m1_new) + @test jacobian(rm) === m1 == exp.(m1_new) + rm = jacobian!(exp, rm, m1_copy) + + T = typeof(SVector{k * k}(rand(k * k))) rs_new = jacobian!(rs, convert(T, jacobian(rs))) @test rs_new === rs end @@ -275,6 +334,11 @@ using DiffResults: DiffResult, GradientResult, JacobianResult, HessianResult, @test typeof(hessian(rs)) === typeof(s2) rs = hessian!(rs, s2) + m2_new, m2_copy = rand(k, k, k), copy(m2) + rm = hessian!(rm, m2_new) + @test hessian(rm) === m2 == m2_new + rm = hessian!(rm, m2_copy) + x2_new, x2_copy = rand(k, k, k), copy(x2) rx = hessian!(exp, rx, x2_new) @test hessian(rx) === x2 == exp.(x2_new) @@ -286,7 +350,12 @@ using DiffResults: DiffResult, GradientResult, JacobianResult, HessianResult, @test typeof(hessian(rsmix)) === typeof(s1) rsmix = hessian!(exp, rsmix, s1) - T = typeof(SVector{k*k*k}(rand(k*k*k))) + m2_new, m2_copy = rand(k, k, k), copy(m2) + rm = hessian!(exp, rm, m2_new) + @test hessian(rm) === m2 == exp.(m2_new) + rm = hessian!(exp, rm, m2_copy) + + T = typeof(SVector{k * k * k}(rand(k * k * k))) rs_new = hessian!(rs, convert(T, hessian(rs))) @test rs_new === rs From 4670f89d3be05819bf91cf2cc80eef20e3476e92 Mon Sep 17 00:00:00 2001 From: Guillaume Dalle <22795598+gdalle@users.noreply.github.com> Date: Tue, 19 Mar 2024 07:40:14 +0100 Subject: [PATCH 07/12] Ignore Manifest --- .gitignore | 1 + Manifest.toml | 10 ---------- 2 files changed, 1 insertion(+), 10 deletions(-) delete mode 100644 Manifest.toml diff --git a/.gitignore b/.gitignore index 8c960ec..0ee3d17 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ *.jl.cov *.jl.*.cov *.jl.mem +Manifest.toml \ No newline at end of file diff --git a/Manifest.toml b/Manifest.toml deleted file mode 100644 index dad4f31..0000000 --- a/Manifest.toml +++ /dev/null @@ -1,10 +0,0 @@ -# This file is machine-generated - editing it directly is not advised - -julia_version = "1.10.2" -manifest_format = "2.0" -project_hash = "b991d1a0321e0a74caa38487cb8a73b177987329" - -[[deps.StaticArraysCore]] -git-tree-sha1 = "36b3d696ce6366023a0ea192b4cd442268995a0d" -uuid = "1e83bf80-4336-4d27-bf5d-d5a4f845583c" -version = "1.4.2" From 356773b005dbc9b971e42a21607f2cf991faf033 Mon Sep 17 00:00:00 2001 From: Guillaume Dalle <22795598+gdalle@users.noreply.github.com> Date: Tue, 19 Mar 2024 07:40:52 +0100 Subject: [PATCH 08/12] Undo gitignore --- .gitignore | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 0ee3d17..8b6869d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,3 @@ *.jl.cov *.jl.*.cov -*.jl.mem -Manifest.toml \ No newline at end of file +*.jl.mem \ No newline at end of file From 141adbcdf8f7831a0563ef9e376fc1dcf4432879 Mon Sep 17 00:00:00 2001 From: Guillaume Dalle <22795598+gdalle@users.noreply.github.com> Date: Tue, 19 Mar 2024 07:41:10 +0100 Subject: [PATCH 09/12] Noise in changes --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 8b6869d..8c960ec 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,3 @@ *.jl.cov *.jl.*.cov -*.jl.mem \ No newline at end of file +*.jl.mem From 5ba9c6b4fc72b3689bbd134dee500987f513d57a Mon Sep 17 00:00:00 2001 From: Guillaume Dalle <22795598+gdalle@users.noreply.github.com> Date: Tue, 19 Mar 2024 07:42:17 +0100 Subject: [PATCH 10/12] Remove noise --- test/runtests.jl | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/test/runtests.jl b/test/runtests.jl index b4d12bd..474cde1 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,8 +1,8 @@ using DiffResults, StaticArrays, Test using DiffResults: DiffResult, GradientResult, JacobianResult, HessianResult, - value, value!, derivative, derivative!, gradient, gradient!, - jacobian, jacobian!, hessian, hessian! + value, value!, derivative, derivative!, gradient, gradient!, + jacobian, jacobian!, hessian, hessian! @testset "DiffResult" begin @@ -11,7 +11,6 @@ using DiffResults: DiffResult, GradientResult, JacobianResult, HessianResult, x0, x1, x2 = rand(k), rand(k, k), rand(k, k, k) s0, s1, s2 = SVector{k}(rand(k)), SMatrix{k,k}(rand(k, k)), SArray{Tuple{k,k,k}}(rand(k, k, k)) m0, m1, m2 = MVector{k}(rand(k)), MMatrix{k,k}(rand(k, k)), MArray{Tuple{k,k,k}}(rand(k, k, k)) - y0, y1, y2 = SizedVector{k}(rand(k)), SizedMatrix{k,k}(rand(k, k)), SizedArray{Tuple{k,k,k}}(rand(k, k, k)) rn = DiffResult(n0, n1, n2) rx = DiffResult(x0, x1, x2) From d3fecde124b70e740777e5e5253c2ce1eb3c1e3e Mon Sep 17 00:00:00 2001 From: Guillaume Dalle <22795598+gdalle@users.noreply.github.com> Date: Tue, 19 Mar 2024 07:44:19 +0100 Subject: [PATCH 11/12] Remove more noise --- test/runtests.jl | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/test/runtests.jl b/test/runtests.jl index 474cde1..29104d9 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -35,7 +35,7 @@ using DiffResults: DiffResult, GradientResult, JacobianResult, HessianResult, @test GradientResult(s0) === DiffResult(first(s0), s0) @test JacobianResult(s0) === DiffResult(s0, zeros(SMatrix{k,k,Float64})) - @test JacobianResult(SVector{k + 1}(vcat(s0, 0.0)), s0) === DiffResult(SVector{k + 1}(vcat(s0, 0.0)), zeros(SMatrix{k + 1,k,Float64})) + @test JacobianResult(SVector{k+1}(vcat(s0, 0.0)), s0) === DiffResult(SVector{k+1}(vcat(s0, 0.0)), zeros(SMatrix{k+1,k,Float64})) @test HessianResult(s0) === DiffResult(first(s0), s0, zeros(SMatrix{k,k,Float64})) @test issimilar(GradientResult(m0), DiffResult(first(m0), m0)) @@ -125,7 +125,7 @@ using DiffResults: DiffResult, GradientResult, JacobianResult, HessianResult, rsmix = value!(rsmix, n0) ksqrt = Int(sqrt(k)) - T = typeof(SMatrix{ksqrt,ksqrt}(rand(ksqrt, ksqrt))) + T = typeof(SMatrix{ksqrt,ksqrt}(rand(ksqrt,ksqrt))) rs_new = value!(rs, convert(T, value(rs))) @test rs_new === rs end @@ -270,18 +270,28 @@ using DiffResults: DiffResult, GradientResult, JacobianResult, HessianResult, @test gradient(rm) === m1 == m1_new rm = gradient!(rm, m1_copy) + x1_new, x1_copy = rand(k, k), copy(x1) + rx = gradient!(exp, rx, x1_new) + @test gradient(rx) === x1 == exp.(x1_new) + rx = gradient!(exp, rx, x1_copy) + s0_new = rand(k) rsmix = gradient!(exp, rsmix, s0_new) @test gradient(rsmix) == exp.(s0_new) @test typeof(gradient(rsmix)) === typeof(s0) rsmix = gradient!(exp, rsmix, s0) - T = typeof(SVector{k * k}(rand(k * k))) + m1_new, m1_copy = rand(k, k), copy(m1) + rm = gradient!(exp, rm, m1_new) + @test gradient(rm) === m1 == exp.(m1_new) + rm = gradient!(exp, rm, m1_copy) + + T = typeof(SVector{k*k}(rand(k*k))) rs_new = gradient!(rs, convert(T, gradient(rs))) @test rs_new === rs end - @testset "jacobian/jacobian!" begin + @testset "jacobian/jacobian!" begin x1_new, x1_copy = rand(k, k), copy(x1) rx = jacobian!(rx, x1_new) @@ -315,7 +325,7 @@ using DiffResults: DiffResult, GradientResult, JacobianResult, HessianResult, @test jacobian(rm) === m1 == exp.(m1_new) rm = jacobian!(exp, rm, m1_copy) - T = typeof(SVector{k * k}(rand(k * k))) + T = typeof(SVector{k*k}(rand(k*k))) rs_new = jacobian!(rs, convert(T, jacobian(rs))) @test rs_new === rs end @@ -354,7 +364,7 @@ using DiffResults: DiffResult, GradientResult, JacobianResult, HessianResult, @test hessian(rm) === m2 == exp.(m2_new) rm = hessian!(exp, rm, m2_copy) - T = typeof(SVector{k * k * k}(rand(k * k * k))) + T = typeof(SVector{k*k*k}(rand(k*k*k))) rs_new = hessian!(rs, convert(T, hessian(rs))) @test rs_new === rs From 38cbfb15784b324bc2e662eac3f28decc786e8cd Mon Sep 17 00:00:00 2001 From: Guillaume Dalle <22795598+gdalle@users.noreply.github.com> Date: Tue, 19 Mar 2024 10:15:29 +0100 Subject: [PATCH 12/12] Bump version to 1.2 --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index 0831a68..7fe648c 100644 --- a/Project.toml +++ b/Project.toml @@ -1,6 +1,6 @@ name = "DiffResults" uuid = "163ba53b-c6d8-5494-b064-1a9d43ac40c5" -version = "1.1.0" +version = "1.2.0" [deps] StaticArraysCore = "1e83bf80-4336-4d27-bf5d-d5a4f845583c"