From 9383c3d31631f136ca1230e26dd6ff3f532ebb77 Mon Sep 17 00:00:00 2001 From: Jishnu Bhattacharya Date: Tue, 5 Dec 2023 12:08:36 +0530 Subject: [PATCH 1/6] Remove unnecessary permutedims method --- src/fillalgebra.jl | 1 - 1 file changed, 1 deletion(-) diff --git a/src/fillalgebra.jl b/src/fillalgebra.jl index 5a5897ef..577628a4 100644 --- a/src/fillalgebra.jl +++ b/src/fillalgebra.jl @@ -11,7 +11,6 @@ adjoint(a::Union{AbstractOnesMatrix, AbstractZerosMatrix}) = fillsimilar(a, reve transpose(a::FillMatrix{T}) where T = Fill{T}(transpose(a.value), reverse(a.axes)) adjoint(a::FillMatrix{T}) where T = Fill{T}(adjoint(a.value), reverse(a.axes)) -permutedims(a::AbstractFillVector) = fillsimilar(a, (1, length(a))) permutedims(a::AbstractFillMatrix) = fillsimilar(a, reverse(a.axes)) function permutedims(B::AbstractFill, perm) From d6f575fb1a368e671ea195ab39546cf276632dc7 Mon Sep 17 00:00:00 2001 From: Jishnu Bhattacharya Date: Tue, 5 Dec 2023 12:43:49 +0530 Subject: [PATCH 2/6] Swap axes in permutedims --- src/fillalgebra.jl | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/fillalgebra.jl b/src/fillalgebra.jl index 577628a4..cff03f02 100644 --- a/src/fillalgebra.jl +++ b/src/fillalgebra.jl @@ -13,11 +13,11 @@ adjoint(a::FillMatrix{T}) where T = Fill{T}(adjoint(a.value), reverse(a.axes)) permutedims(a::AbstractFillMatrix) = fillsimilar(a, reverse(a.axes)) -function permutedims(B::AbstractFill, perm) - dimsB = size(B) - ndimsB = length(dimsB) +Base.@constprop :aggressive function permutedims(B::AbstractFill, perm) + dimsB = axes(B) + ndimsB = ndims(B) (ndimsB == length(perm) && isperm(perm)) || throw(ArgumentError("no valid permutation of dimensions")) - dimsP = ntuple(i->dimsB[perm[i]], ndimsB)::typeof(dimsB) + dimsP = ntuple(i->dimsB[perm[i]], ndimsB) fillsimilar(B, dimsP) end From a7a83d9700d101d83285b87ec90a38c27d4b4963 Mon Sep 17 00:00:00 2001 From: Jishnu Bhattacharya Date: Tue, 5 Dec 2023 12:53:53 +0530 Subject: [PATCH 3/6] Constant propagation only on recent Julia versions --- Project.toml | 2 +- src/fillalgebra.jl | 8 +++++++- test/runtests.jl | 15 +++++++++++++++ 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/Project.toml b/Project.toml index 5365dbe7..18c93182 100644 --- a/Project.toml +++ b/Project.toml @@ -1,6 +1,6 @@ name = "FillArrays" uuid = "1a297f60-69ca-5386-bcde-b61e274b549b" -version = "1.9.1" +version = "1.10.0" [deps] LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" diff --git a/src/fillalgebra.jl b/src/fillalgebra.jl index cff03f02..e941e9ca 100644 --- a/src/fillalgebra.jl +++ b/src/fillalgebra.jl @@ -13,7 +13,13 @@ adjoint(a::FillMatrix{T}) where T = Fill{T}(adjoint(a.value), reverse(a.axes)) permutedims(a::AbstractFillMatrix) = fillsimilar(a, reverse(a.axes)) -Base.@constprop :aggressive function permutedims(B::AbstractFill, perm) +@static if VERSION >= v"1.9" + Base.@constprop :aggressive permutedims(B::AbstractFill, perm) = _permutedims(B, perm) +else + permutedims(B::AbstractFill, perm) = _permutedims(B, perm) +end + +@inline function _permutedims(B::AbstractFill, perm) dimsB = axes(B) ndimsB = ndims(B) (ndimsB == length(perm) && isperm(perm)) || throw(ArgumentError("no valid permutation of dimensions")) diff --git a/test/runtests.jl b/test/runtests.jl index d7a6aca1..dfee2987 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1394,6 +1394,21 @@ end @test permutedims(Ones(2,4,5), [3,2,1]) ≡ Ones(5,4,2) @test permutedims(Zeros(2,4,5), [3,2,1]) ≡ Zeros(5,4,2) @test permutedims(Fill(2.0,2,4,5), [3,2,1]) ≡ Fill(2.0,5,4,2) + + # test for inference only if aggressive constant propagation is available + H = if VERSION >= v"1.8" + @inferred(permutedims(Fill(2, (SOneTo(2), SOneTo(3))))) + else + permutedims(Fill(2, (SOneTo(2), SOneTo(3)))) + end + @test H === Fill(2, (SOneTo(3), SOneTo(2))) + F = Fill(2, (SOneTo(2), SOneTo(3), SOneTo(1))) + H = if VERSION >= v"1.8" + @inferred((F -> permutedims(F, (3,1,2)))(F)) + else + (F -> permutedims(F, (3,1,2)))(F) + end + @test H === Fill(2, (SOneTo(1), SOneTo(2), SOneTo(3))) end @testset "reverse" begin From 81c9e94dc332357efcc99640a43cc664242d89d1 Mon Sep 17 00:00:00 2001 From: Jishnu Bhattacharya Date: Tue, 5 Dec 2023 13:03:21 +0530 Subject: [PATCH 4/6] test for inference --- test/runtests.jl | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/test/runtests.jl b/test/runtests.jl index dfee2987..acba3b81 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1383,17 +1383,17 @@ end @test Fill([1+im 2; 3 4; 5 6], 2,3)' == Fill([1+im 2; 3 4; 5 6]', 3,2) @test transpose(Fill([1+im 2; 3 4; 5 6], 2,3)) == Fill(transpose([1+im 2; 3 4; 5 6]), 3,2) - @test permutedims(Ones(10)) ≡ Ones(1,10) - @test permutedims(Zeros(10)) ≡ Zeros(1,10) - @test permutedims(Fill(2.0,10)) ≡ Fill(2.0,1,10) - @test permutedims(Ones(10,3)) ≡ Ones(3,10) - @test permutedims(Zeros(10,3)) ≡ Zeros(3,10) - @test permutedims(Fill(2.0,10,3)) ≡ Fill(2.0,3,10) - - @test permutedims(Ones(2,4,5), [3,2,1]) == permutedims(Array(Ones(2,4,5)), [3,2,1]) - @test permutedims(Ones(2,4,5), [3,2,1]) ≡ Ones(5,4,2) - @test permutedims(Zeros(2,4,5), [3,2,1]) ≡ Zeros(5,4,2) - @test permutedims(Fill(2.0,2,4,5), [3,2,1]) ≡ Fill(2.0,5,4,2) + @test @inferred(permutedims(Ones(10))) ≡ Ones(1,10) + @test @inferred(permutedims(Zeros(10))) ≡ Zeros(1,10) + @test @inferred(permutedims(Fill(2.0,10))) ≡ Fill(2.0,1,10) + @test @inferred(permutedims(Ones(10,3))) ≡ Ones(3,10) + @test @inferred(permutedims(Zeros(10,3))) ≡ Zeros(3,10) + @test @inferred(permutedims(Fill(2.0,10,3))) ≡ Fill(2.0,3,10) + + @test @inferred(permutedims(Ones(2,4,5), [3,2,1])) == permutedims(Array(Ones(2,4,5)), [3,2,1]) + @test @inferred(permutedims(Ones(2,4,5), [3,2,1])) ≡ Ones(5,4,2) + @test @inferred(permutedims(Zeros(2,4,5), [3,2,1])) ≡ Zeros(5,4,2) + @test @inferred(permutedims(Fill(2.0,2,4,5), [3,2,1])) ≡ Fill(2.0,5,4,2) # test for inference only if aggressive constant propagation is available H = if VERSION >= v"1.8" From 5b5a1cbcf2e205fc7028ecac6294f5a1e6570e11 Mon Sep 17 00:00:00 2001 From: Jishnu Bhattacharya Date: Tue, 5 Dec 2023 14:02:06 +0530 Subject: [PATCH 5/6] Update inference tests --- Project.toml | 20 ++++++++++---------- test/runtests.jl | 9 +++------ 2 files changed, 13 insertions(+), 16 deletions(-) diff --git a/Project.toml b/Project.toml index 18c93182..9b53239c 100644 --- a/Project.toml +++ b/Project.toml @@ -9,16 +9,6 @@ Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf" Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2" -[weakdeps] -PDMats = "90014a1f-27ba-587c-ab20-58faa44d9150" -SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf" -Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2" - -[extensions] -FillArraysPDMatsExt = "PDMats" -FillArraysSparseArraysExt = "SparseArrays" -FillArraysStatisticsExt = "Statistics" - [compat] Aqua = "0.8" Base64 = "1.6" @@ -33,6 +23,11 @@ Statistics = "1.6" Test = "1.6" julia = "1.6" +[extensions] +FillArraysPDMatsExt = "PDMats" +FillArraysSparseArraysExt = "SparseArrays" +FillArraysStatisticsExt = "Statistics" + [extras] Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595" Base64 = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f" @@ -46,3 +41,8 @@ Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" [targets] test = ["Aqua", "Test", "Base64", "Infinities", "PDMats", "ReverseDiff", "SparseArrays", "StaticArrays", "Statistics"] + +[weakdeps] +PDMats = "90014a1f-27ba-587c-ab20-58faa44d9150" +SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf" +Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2" diff --git a/test/runtests.jl b/test/runtests.jl index acba3b81..c1355ac9 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1395,13 +1395,10 @@ end @test @inferred(permutedims(Zeros(2,4,5), [3,2,1])) ≡ Zeros(5,4,2) @test @inferred(permutedims(Fill(2.0,2,4,5), [3,2,1])) ≡ Fill(2.0,5,4,2) - # test for inference only if aggressive constant propagation is available - H = if VERSION >= v"1.8" - @inferred(permutedims(Fill(2, (SOneTo(2), SOneTo(3))))) - else - permutedims(Fill(2, (SOneTo(2), SOneTo(3)))) - end + H = @inferred(permutedims(Fill(2, (SOneTo(2), SOneTo(3))))) @test H === Fill(2, (SOneTo(3), SOneTo(2))) + + # test for inference only if aggressive constant propagation is available F = Fill(2, (SOneTo(2), SOneTo(3), SOneTo(1))) H = if VERSION >= v"1.8" @inferred((F -> permutedims(F, (3,1,2)))(F)) From 5030c7ed8fb6a24e5982edbfdad203611bc0be9a Mon Sep 17 00:00:00 2001 From: Jishnu Bhattacharya Date: Tue, 26 Dec 2023 17:49:06 +0530 Subject: [PATCH 6/6] Fix Project.toml ordering --- Project.toml | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/Project.toml b/Project.toml index 9b53239c..18c93182 100644 --- a/Project.toml +++ b/Project.toml @@ -9,6 +9,16 @@ Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf" Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2" +[weakdeps] +PDMats = "90014a1f-27ba-587c-ab20-58faa44d9150" +SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf" +Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2" + +[extensions] +FillArraysPDMatsExt = "PDMats" +FillArraysSparseArraysExt = "SparseArrays" +FillArraysStatisticsExt = "Statistics" + [compat] Aqua = "0.8" Base64 = "1.6" @@ -23,11 +33,6 @@ Statistics = "1.6" Test = "1.6" julia = "1.6" -[extensions] -FillArraysPDMatsExt = "PDMats" -FillArraysSparseArraysExt = "SparseArrays" -FillArraysStatisticsExt = "Statistics" - [extras] Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595" Base64 = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f" @@ -41,8 +46,3 @@ Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" [targets] test = ["Aqua", "Test", "Base64", "Infinities", "PDMats", "ReverseDiff", "SparseArrays", "StaticArrays", "Statistics"] - -[weakdeps] -PDMats = "90014a1f-27ba-587c-ab20-58faa44d9150" -SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf" -Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"