Skip to content

Commit e235d04

Browse files
authored
permutedims disambiguation (#53)
1 parent 384b276 commit e235d04

File tree

3 files changed

+25
-22
lines changed

3 files changed

+25
-22
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "TensorAlgebra"
22
uuid = "68bd88dc-f39d-4e12-b2ca-f046b68fcc6a"
33
authors = ["ITensor developers <[email protected]> and contributors"]
4-
version = "0.3.0"
4+
version = "0.3.1"
55

66
[deps]
77
ArrayLayouts = "4c555306-a7a7-4459-81d9-ec55ddd5c99a"

src/matricize.jl

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -38,31 +38,16 @@ end
3838

3939
# TODO remove _permutedims once support for Julia 1.10 is dropped
4040
# define permutedims with a BlockedPermuation. Default is to flatten it.
41-
function Base.permutedims(a::AbstractArray, biperm::AbstractBlockPermutation)
41+
function permuteblockeddims(a::AbstractArray, biperm::AbstractBlockPermutation)
4242
return _permutedims(a, Tuple(biperm))
4343
end
4444

45-
# solve ambiguities
46-
function Base.permutedims(a::StridedArray, biperm::AbstractBlockPermutation)
47-
return _permutedims(a, Tuple(biperm))
48-
end
49-
function Base.permutedims(a::Diagonal, biperm::AbstractBlockPermutation)
50-
return _permutedims(a, Tuple(biperm))
51-
end
52-
53-
function Base.permutedims!(
45+
function permuteblockeddims!(
5446
a::AbstractArray, b::AbstractArray, biperm::AbstractBlockPermutation
5547
)
5648
return _permutedims!(a, b, Tuple(biperm))
5749
end
5850

59-
# solve ambiguities
60-
function Base.permutedims!(
61-
a::Array{T,N}, b::StridedArray{T,N}, biperm::AbstractBlockPermutation
62-
) where {T,N}
63-
return _permutedims!(a, b, Tuple(biperm))
64-
end
65-
6651
# ===================================== matricize ========================================
6752
# TBD settle copy/not copy convention
6853
# matrix factorizations assume copy
@@ -75,7 +60,7 @@ end
7560
function matricize(
7661
style::FusionStyle, a::AbstractArray, biperm::AbstractBlockPermutation{2}
7762
)
78-
a_perm = permutedims(a, biperm)
63+
a_perm = permuteblockeddims(a, biperm)
7964
return matricize(style, a_perm, trivialperm(biperm))
8065
end
8166

@@ -112,7 +97,7 @@ function unmatricize(
11297
)
11398
blocked_axes = axes[biperm]
11499
a_perm = unmatricize(m, blocked_axes)
115-
return permutedims(a_perm, invperm(biperm))
100+
return permuteblockeddims(a_perm, invperm(biperm))
116101
end
117102

118103
function unmatricize(::ReshapeFusion, m::AbstractMatrix, axes::AbstractUnitRange...)
@@ -147,5 +132,5 @@ function unmatricize!(
147132
)
148133
blocked_axes = axes(a)[biperm]
149134
a_perm = unmatricize(m, blocked_axes)
150-
return permutedims!(a, a_perm, invperm(biperm))
135+
return permuteblockeddims!(a, a_perm, invperm(biperm))
151136
end

test/test_basics.jl

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,30 @@ using StableRNGs: StableRNG
55
using TensorOperations: TensorOperations
66

77
using TensorAlgebra:
8-
blockedpermvcat, contract, contract!, matricize, tuplemortar, unmatricize, unmatricize!
8+
blockedpermvcat,
9+
permuteblockeddims,
10+
permuteblockeddims!,
11+
contract,
12+
contract!,
13+
matricize,
14+
tuplemortar,
15+
unmatricize,
16+
unmatricize!
917

1018
default_rtol(elt::Type) = 10^(0.75 * log10(eps(real(elt))))
1119
const elts = (Float32, Float64, Complex{Float32}, Complex{Float64})
1220

1321
@testset "TensorAlgebra" begin
22+
@testset "permuteblockeddims (eltype=$elt)" for elt in elts
23+
a = randn(elt, 2, 3, 4, 5)
24+
a_perm = permuteblockeddims(a, blockedpermvcat((3, 1), (2, 4)))
25+
@test a_perm == permutedims(a, (3, 1, 2, 4))
26+
27+
a = randn(elt, 2, 3, 4, 5)
28+
a_perm = Array{elt}(undef, (4, 2, 3, 5))
29+
permuteblockeddims!(a_perm, a, blockedpermvcat((3, 1), (2, 4)))
30+
@test a_perm == permutedims(a, (3, 1, 2, 4))
31+
end
1432
@testset "matricize (eltype=$elt)" for elt in elts
1533
a = randn(elt, 2, 3, 4, 5)
1634

0 commit comments

Comments
 (0)