Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "TensorAlgebra"
uuid = "68bd88dc-f39d-4e12-b2ca-f046b68fcc6a"
authors = ["ITensor developers <[email protected]> and contributors"]
version = "0.3.9"
version = "0.3.10"

[deps]
ArrayLayouts = "4c555306-a7a7-4459-81d9-ec55ddd5c99a"
Expand Down
31 changes: 6 additions & 25 deletions src/matricize.jl
Original file line number Diff line number Diff line change
Expand Up @@ -74,56 +74,37 @@ function matricize(a::AbstractArray, permblock1::Tuple, permblock2::Tuple)
end

# ==================================== unmatricize =======================================
function unmatricize(
m::AbstractMatrix,
axes::Tuple{Vararg{AbstractUnitRange}},
biperm::AbstractBlockPermutation{2},
)
function unmatricize(m, axes, biperm::AbstractBlockPermutation{2})
length(axes) == length(biperm) || throw(ArgumentError("axes do not match permutation"))
return unmatricize(FusionStyle(m), m, axes, biperm)
end

function unmatricize(
::FusionStyle,
m::AbstractMatrix,
axes::Tuple{Vararg{AbstractUnitRange}},
biperm::AbstractBlockPermutation{2},
)
function unmatricize(::FusionStyle, m, axes, biperm::AbstractBlockPermutation{2})
blocked_axes = axes[biperm]
a_perm = unmatricize(m, blocked_axes)
return permuteblockeddims(a_perm, invperm(biperm))
end

function unmatricize(::ReshapeFusion, m::AbstractMatrix, axes::AbstractUnitRange...)
return reshape(m, axes...)
end

function unmatricize(
::ReshapeFusion,
m::AbstractMatrix,
blocked_axes::BlockedTuple{2,<:Any,<:Tuple{Vararg{AbstractUnitRange}}},
::ReshapeFusion, m, blocked_axes::BlockedTuple{2,<:Any,<:Tuple{Vararg{AbstractUnitRange}}}
)
return reshape(m, Tuple(blocked_axes)...)
end

function unmatricize(
m::AbstractMatrix, blocked_axes::BlockedTuple{2,<:Any,<:Tuple{Vararg{AbstractUnitRange}}}
)
function unmatricize(m, blocked_axes)
return unmatricize(FusionStyle(m), m, blocked_axes)
end

function unmatricize(
m::AbstractMatrix,
m,
codomain_axes::Tuple{Vararg{AbstractUnitRange}},
domain_axes::Tuple{Vararg{AbstractUnitRange}},
)
blocked_axes = tuplemortar((codomain_axes, domain_axes))
return unmatricize(m, blocked_axes)
end

function unmatricize!(
a::AbstractArray, m::AbstractMatrix, biperm::AbstractBlockPermutation{2}
)
function unmatricize!(a, m, biperm::AbstractBlockPermutation{2})
ndims(a) == length(biperm) ||
throw(ArgumentError("destination does not match permutation"))
blocked_axes = axes(a)[biperm]
Expand Down
Loading