Skip to content
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,6 +1,6 @@
name = "TensorAlgebra"
uuid = "68bd88dc-f39d-4e12-b2ca-f046b68fcc6a"
version = "0.18.0"
version = "0.19.0"
authors = ["ITensor developers <support@itensor.org> and contributors"]

[workspace]
Expand Down
2 changes: 1 addition & 1 deletion docs/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ path = ".."
Documenter = "1.8.1"
ITensorFormatter = "0.2.27"
Literate = "2.20.1"
TensorAlgebra = "0.18"
TensorAlgebra = "0.19"
2 changes: 1 addition & 1 deletion examples/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ TensorAlgebra = "68bd88dc-f39d-4e12-b2ca-f046b68fcc6a"
path = ".."

[compat]
TensorAlgebra = "0.18"
TensorAlgebra = "0.19"
10 changes: 5 additions & 5 deletions ext/TensorAlgebraTensorKitExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -240,11 +240,11 @@ end
# A `TensorMap` is already a linear map codomain ← domain, so "matricizing" is just regrouping
# its indices into the requested codomain/domain bipartition (`permute`). No fusion or copy of
# the array vocabulary is needed: MatrixAlgebraKit factorizes the regrouped `TensorMap` directly.
struct TensorKitFusion <: TensorAlgebra.FusionStyle end
TensorAlgebra.FusionStyle(::Type{<:AbstractTensorMap}) = TensorKitFusion()
struct TensorKitMatricize <: TensorAlgebra.MatricizeStyle end
TensorAlgebra.MatricizeStyle(::Type{<:AbstractTensorMap}) = TensorKitMatricize()

function TensorAlgebra.matricize(
::TensorKitFusion, t::AbstractTensorMap, ndims_codomain::Val{K}
::TensorKitMatricize, t::AbstractTensorMap, ndims_codomain::Val{K}
) where {K}
N = numind(t)
return permute(t, (ntuple(identity, Val(K)), ntuple(i -> K + i, Val(N - K))))
Expand All @@ -253,7 +253,7 @@ end
# The identity fill on the regrouped map is TensorKit's own `one!` (MatrixAlgebraKit's
# `one!` speaks `AbstractMatrix` only).
function TensorAlgebra.one!!(
style::TensorKitFusion, A::AbstractTensorMap, ndims_codomain::Val; kwargs...
style::TensorKitMatricize, A::AbstractTensorMap, ndims_codomain::Val; kwargs...
)
return TensorKit.one!(TensorAlgebra.matricize(style, A, ndims_codomain))
end
Expand All @@ -264,7 +264,7 @@ end
# codomain-facing (un-dualized), which is exactly TensorKit's domain convention, so they build the
# domain `ProductSpace` directly.
function TensorAlgebra.unmatricize(
::TensorKitFusion, m::AbstractTensorMap, codomain_axes, domain_axes
::TensorKitMatricize, m::AbstractTensorMap, codomain_axes, domain_axes
)
S = spacetype(m)
dest = ProductSpace{S}(codomain_axes...) ← ProductSpace{S}(domain_axes...)
Expand Down
6 changes: 3 additions & 3 deletions src/contract/contract_matricize.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ function contractopadd!(
a2, biperm2_codomain, biperm2_domain
)
a1_mat = matricizeopperm(
algorithm.left_fusion_style, op1, a1, biperm1_codomain, biperm1_domain
algorithm.left_matricize_style, op1, a1, biperm1_codomain, biperm1_domain
)
a2_mat = matricizeopperm(
algorithm.right_fusion_style, op2, a2, biperm2_codomain, biperm2_domain
algorithm.right_matricize_style, op2, a2, biperm2_codomain, biperm2_domain
)
output_style = algorithm.output_fusion_style
output_style = algorithm.output_matricize_style
if iszero(β) && !matricizepermaliases(output_style, invperm_codomain, invperm_domain)
# `β` is a strong zero and matricizing `a_dest` would only build a detached copy that
# `mul!` immediately overwrites, so skip that gather: let the matmul allocate its matrix
Expand Down
12 changes: 6 additions & 6 deletions src/contract/contractalgorithm.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ ContractAlgorithm(algorithm::ContractAlgorithm) = algorithm
struct DefaultContractAlgorithm <: ContractAlgorithm end

struct Matricize{LeftStyle, RightStyle, OutputStyle} <: ContractAlgorithm
left_fusion_style::LeftStyle
right_fusion_style::RightStyle
output_fusion_style::OutputStyle
left_matricize_style::LeftStyle
right_matricize_style::RightStyle
output_matricize_style::OutputStyle
end
Matricize(fusion_style) = Matricize(fusion_style, fusion_style, fusion_style)
Matricize() = Matricize(ReshapeFusion())
Matricize(matricize_style) = Matricize(matricize_style, matricize_style, matricize_style)
Matricize() = Matricize(ReshapeMatricize())

"""
TensorOperationsAlgorithm(; backend = nothing, allocator = nothing)
Expand All @@ -36,5 +36,5 @@ function default_contract_algorithm(a1, a2)
return default_contract_algorithm(typeof(a1), typeof(a2))
end
function default_contract_algorithm(A1::Type{<:AbstractArray}, A2::Type{<:AbstractArray})
return Matricize(FusionStyle(FusionStyle(A1), FusionStyle(A2)))
return Matricize(MatricizeStyle(MatricizeStyle(A1), MatricizeStyle(A2)))
end
6 changes: 3 additions & 3 deletions src/diagonal.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using LinearAlgebra: Diagonal

# `Diagonal` participates in the `ReshapeFusion` interface like a dense matrix (it fuses with
# `Diagonal` participates in the `ReshapeMatricize` interface like a dense matrix (it fuses with
# the same row/column reshape order), but its structure is preserved wherever the result of
# an operation is still diagonal. These methods hook the lowest-level primitives, so the
# convenience wrappers built on them (`bipermutedims`, `permutedimsadd!`, `add!`, and the
Expand Down Expand Up @@ -44,9 +44,9 @@ end

# A `Diagonal` is already a matrix; the `(1 codomain, 1 domain)` matricization is the identity
# reshape, so return it directly (maybe-alias, matching `matricize`'s general contract).
matricize(::ReshapeFusion, a::Diagonal, ::Val{1}) = a
matricize(::ReshapeMatricize, a::Diagonal, ::Val{1}) = a
function unmatricize(
::ReshapeFusion, m::Diagonal,
::ReshapeMatricize, m::Diagonal,
::Tuple{<:AbstractUnitRange}, ::Tuple{<:AbstractUnitRange}
)
return m
Expand Down
2 changes: 1 addition & 1 deletion src/directsum.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# `directsum` is a plain concatenation for now, kept as its own entry point so a fusing/rotating
# variant can later be selected by style, the way `matricize` takes a `FusionStyle`.
# variant can later be selected by style, the way `matricize` takes a `MatricizeStyle`.
directsum(dims, as...) = concatenate(dims, as...)
Loading