Skip to content

generalize unmatricize to arbitrary axes #66

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jul 16, 2025
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
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
23 changes: 4 additions & 19 deletions src/matricize.jl
Original file line number Diff line number Diff line change
Expand Up @@ -74,30 +74,19 @@ function matricize(a::AbstractArray, permblock1::Tuple, permblock2::Tuple)
end

# ==================================== unmatricize =======================================
function unmatricize(
m::AbstractMatrix,
axes::Tuple{Vararg{AbstractUnitRange}},
biperm::AbstractBlockPermutation{2},
)
function unmatricize(m::AbstractMatrix, 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},
::FusionStyle, m::AbstractMatrix, 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,
Expand All @@ -106,9 +95,7 @@ function unmatricize(
return reshape(m, Tuple(blocked_axes)...)
end

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

Expand All @@ -121,9 +108,7 @@ function unmatricize(
return unmatricize(m, blocked_axes)
end

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