Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ FillArraysStatisticsExt = "Statistics"

[compat]
Aqua = "0.8"
Base64 = "1"
Documenter = "1"
Infinities = "0.1"
LinearAlgebra = "1.6"
Expand All @@ -35,6 +36,7 @@ julia = "1.6"

[extras]
Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"
Base64 = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
Infinities = "e1ba4f0e-776d-440f-acd9-e1d2e9742647"
PDMats = "90014a1f-27ba-587c-ab20-58faa44d9150"
Expand All @@ -47,4 +49,5 @@ Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
test = ["Aqua", "Test", "Infinities", "PDMats", "ReverseDiff", "SparseArrays", "StaticArrays", "Statistics", "Quaternions", "Documenter", "Random"]
test = ["Aqua", "Base64", "Test", "Infinities", "PDMats", "ReverseDiff", "SparseArrays", "StaticArrays", "Statistics", "Quaternions", "Documenter", "Random"]

15 changes: 10 additions & 5 deletions src/fillalgebra.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,19 @@ for OP in (:transpose, :adjoint)
end
end

permutedims(a::AbstractFillVector) = fillsimilar(a, (1, length(a)))
permutedims(a::AbstractFillMatrix) = fillsimilar(a, reverse(axes(a)))

function permutedims(B::AbstractFill, perm)
dimsB = size(B)
ndimsB = length(dimsB)
@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"))
dimsP = ntuple(i->dimsB[perm[i]], ndimsB)::typeof(dimsB)
dimsP = ntuple(i->dimsB[perm[i]], ndimsB)
fillsimilar(B, dimsP)
end

Expand Down
38 changes: 27 additions & 11 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1488,17 +1488,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)

@testset "recursive" begin
S = SMatrix{2,3}(1:6)
Expand All @@ -1512,6 +1512,22 @@ end
@test F' == G'
@test transpose(F) == transpose(G)
end

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)))

# 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))
else
(F -> permutedims(F, (3,1,2)))(F)
end
@test H === Fill(2, (SOneTo(1), SOneTo(2), SOneTo(3)))
end

@testset "reverse" begin
Expand Down
Loading