Skip to content
This repository was archived by the owner on Jan 8, 2026. It is now read-only.
Merged
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
@@ -1,7 +1,7 @@
name = "DerivableInterfaces"
uuid = "6c5e35bf-e59e-4898-b73c-732dcc4ba65f"
authors = ["ITensor developers <support@itensor.org> and contributors"]
version = "0.5.3"
version = "0.5.4"

[deps]
Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"
Expand All @@ -15,16 +15,19 @@ TypeParameterAccessors = "7e5a90cf-f82e-492e-a09b-e3e26432c138"

[weakdeps]
BlockArrays = "8e7c35d0-a365-5155-bbbb-fb81a777f24e"
FillArrays = "1a297f60-69ca-5386-bcde-b61e274b549b"

[extensions]
DerivableInterfacesBlockArraysExt = "BlockArrays"
DerivableInterfacesFillArraysExt = "FillArrays"

[compat]
Adapt = "4.1.1"
ArrayLayouts = "1.11"
BlockArrays = "1.4"
Compat = "3.47,4.10"
ExproniconLite = "0.10.13"
FillArrays = "1.13"
LinearAlgebra = "1.10"
MLStyle = "0.4.17"
MapBroadcast = "0.1.5"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module DerivableInterfacesFillArraysExt

using DerivableInterfaces: DerivableInterfaces
using FillArrays: RectDiagonal
function DerivableInterfaces.permuteddims(a::RectDiagonal, perm)
(ndims(a) == length(perm) && isperm(perm)) ||
throw(ArgumentError("no valid permutation of dimensions"))
return RectDiagonal(parent(a), ntuple(d -> axes(a)[perm[d]], ndims(a)))
end

end
7 changes: 7 additions & 0 deletions src/permuteddims.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,10 @@ but can be customized to output a different type of array.
"""
permuteddims(a::AbstractArray, perm) = PermutedDimsArray(a, perm)
# See: https://github.com/JuliaLang/julia/issues/53188

using LinearAlgebra: Diagonal
function permuteddims(a::Diagonal, perm)
(ndims(a) == length(perm) && isperm(perm)) ||
throw(ArgumentError("no valid permutation of dimensions"))
return a
end
2 changes: 2 additions & 0 deletions test/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"
ArrayLayouts = "4c555306-a7a7-4459-81d9-ec55ddd5c99a"
DerivableInterfaces = "6c5e35bf-e59e-4898-b73c-732dcc4ba65f"
FillArrays = "1a297f60-69ca-5386-bcde-b61e274b549b"
JLArrays = "27aeb0d3-9eb9-45fb-866b-73c2ecf80fcb"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
SafeTestsets = "1bc83da4-3b8d-516f-aca4-4fe02f6d838f"
Expand All @@ -13,6 +14,7 @@ TestExtras = "5ed8adda-3752-4e41-b88a-e8b09835ee3a"
Aqua = "0.8"
ArrayLayouts = "1"
DerivableInterfaces = "0.5"
FillArrays = "1.13"
JLArrays = "0.2"
LinearAlgebra = "1"
SafeTestsets = "0.1"
Expand Down
10 changes: 10 additions & 0 deletions test/test_permuteddims.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
using DerivableInterfaces: permuteddims
using FillArrays: RectDiagonal
using LinearAlgebra: Diagonal
using Test: @test, @testset

@testset "permuteddims" begin
a = randn(2, 3, 4)
@test permuteddims(a, (2, 1, 3)) ≡ PermutedDimsArray(a, (2, 1, 3))

a = Diagonal(randn(3))
@test permuteddims(a, (1, 2)) ≡ a
@test permuteddims(a, (2, 1)) ≡ a

a = RectDiagonal(randn(3), (3, 4))
@test permuteddims(a, (1, 2)) ≡ a
@test permuteddims(a, (2, 1)) ≡ RectDiagonal(parent(a), (4, 3))
end
Loading