From 5cba05d5c04f29020b0df60da68a5cc15cd75e07 Mon Sep 17 00:00:00 2001 From: Matthew Fishman Date: Tue, 30 Jun 2026 14:50:12 -0400 Subject: [PATCH 1/3] Add a sparse bipermutedimsopadd! for TensorAlgebra 0.14 Adds a `bipermutedimsopadd!` method for sparse destinations, so permutation and accumulation keep working after TensorAlgebra's `bipermutedimsopadd!` switched to a `StridedView`-based permute path that a sparse array cannot wrap. The accumulation reuses TensorAlgebra's logic over a lazily permuted source. Co-authored-by: Claude --- Project.toml | 8 +++-- .../SparseArraysBaseTensorAlgebraExt.jl | 34 ++++++++++++++++++- test/Project.toml | 2 +- 3 files changed, 40 insertions(+), 4 deletions(-) diff --git a/Project.toml b/Project.toml index dc5bf29..3cbd422 100644 --- a/Project.toml +++ b/Project.toml @@ -1,6 +1,6 @@ name = "SparseArraysBase" uuid = "0d5efcca-f356-4864-8770-e1ed8d78f208" -version = "0.10.3" +version = "0.10.4" authors = ["ITensor developers and contributors"] [workspace] @@ -21,6 +21,10 @@ SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf" [weakdeps] TensorAlgebra = "68bd88dc-f39d-4e12-b2ca-f046b68fcc6a" +[sources.TensorAlgebra] +rev = "mf/inline-strided-permute" +url = "https://github.com/ITensor/TensorAlgebra.jl" + [extensions] SparseArraysBaseTensorAlgebraExt = ["TensorAlgebra", "SparseArrays"] @@ -35,5 +39,5 @@ LinearAlgebra = "1.10" MapBroadcast = "0.1.5" Random = "1.10" SparseArrays = "1.10" -TensorAlgebra = "0.11, 0.12, 0.13" +TensorAlgebra = "0.14" julia = "1.10" diff --git a/ext/SparseArraysBaseTensorAlgebraExt/SparseArraysBaseTensorAlgebraExt.jl b/ext/SparseArraysBaseTensorAlgebraExt/SparseArraysBaseTensorAlgebraExt.jl index afe9bc0..7808033 100644 --- a/ext/SparseArraysBaseTensorAlgebraExt/SparseArraysBaseTensorAlgebraExt.jl +++ b/ext/SparseArraysBaseTensorAlgebraExt/SparseArraysBaseTensorAlgebraExt.jl @@ -2,7 +2,8 @@ module SparseArraysBaseTensorAlgebraExt using SparseArrays: SparseMatrixCSC using SparseArraysBase: AnyAbstractSparseArray, AnyAbstractSparseMatrix, SparseArrayDOK -using TensorAlgebra: TensorAlgebra, FusionStyle, ReshapeFusion, matricize, unmatricize +using TensorAlgebra: + TensorAlgebra, FusionStyle, ReshapeFusion, bipermutedimsopadd!, matricize, unmatricize struct SparseArrayFusion <: FusionStyle end TensorAlgebra.FusionStyle(::Type{<:AnyAbstractSparseArray}) = SparseArrayFusion() @@ -24,4 +25,35 @@ function TensorAlgebra.unmatricize( return convert(SparseArrayDOK, a) end +# A sparse array can't be wrapped in a `StridedView`, so the generic +# `bipermutedimsopadd!` doesn't apply. Accumulate over a lazily permuted source via +# broadcasting, which dispatches to the sparse broadcast path. `_opadd!` mirrors the +# accumulation in TensorAlgebra's generic method. +function TensorAlgebra.bipermutedimsopadd!( + dest::AnyAbstractSparseArray, op, src::AbstractArray, + perm_codomain, perm_domain, + α::Number, β::Number + ) + perm = (perm_codomain..., perm_domain...) + _opadd!(dest, op, PermutedDimsArray(src, perm), α, β) + return dest +end + +function _opadd!(dest::AbstractArray, op, src::AbstractArray, α, β) + if op === identity + if iszero(β) + dest .= α .* src + else + dest .= β .* dest .+ α .* src + end + else + if iszero(β) + dest .= α .* op.(src) + else + dest .= β .* dest .+ α .* op.(src) + end + end + return dest +end + end diff --git a/test/Project.toml b/test/Project.toml index 58332f4..252666c 100644 --- a/test/Project.toml +++ b/test/Project.toml @@ -34,5 +34,5 @@ SparseArrays = "1.10" SparseArraysBase = "0.10" StableRNGs = "1.0.2" Suppressor = "0.2.8" -TensorAlgebra = "0.11, 0.12, 0.13" +TensorAlgebra = "0.14" Test = "<0.0.1, 1" From 1aa6c2f59e67e73d0fe0a1ae3a1e2089701930e6 Mon Sep 17 00:00:00 2001 From: Matthew Fishman Date: Tue, 30 Jun 2026 15:35:32 -0400 Subject: [PATCH 2/3] Move the TensorAlgebra source pin to the test project `TensorAlgebra` is a weak dependency of SparseArraysBase, so Pkg rejects a `[sources]` entry for it in the root `Project.toml` (a source must reference a package in `[deps]` or `[extras]`). Move the branch pin to `test/Project.toml`, where `TensorAlgebra` is a regular test dependency and which is the only environment that needs the unreleased branch. --- Project.toml | 4 ---- test/Project.toml | 4 ++++ 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Project.toml b/Project.toml index 3cbd422..617c54b 100644 --- a/Project.toml +++ b/Project.toml @@ -21,10 +21,6 @@ SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf" [weakdeps] TensorAlgebra = "68bd88dc-f39d-4e12-b2ca-f046b68fcc6a" -[sources.TensorAlgebra] -rev = "mf/inline-strided-permute" -url = "https://github.com/ITensor/TensorAlgebra.jl" - [extensions] SparseArraysBaseTensorAlgebraExt = ["TensorAlgebra", "SparseArrays"] diff --git a/test/Project.toml b/test/Project.toml index 252666c..0738dce 100644 --- a/test/Project.toml +++ b/test/Project.toml @@ -19,6 +19,10 @@ Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" [sources.SparseArraysBase] path = ".." +[sources.TensorAlgebra] +rev = "mf/inline-strided-permute" +url = "https://github.com/ITensor/TensorAlgebra.jl" + [compat] Adapt = "4.2" Aqua = "0.8.11" From 89f2aa78ba05e267fd1595774cd6163377bee016 Mon Sep 17 00:00:00 2001 From: Matthew Fishman Date: Tue, 30 Jun 2026 22:39:27 -0400 Subject: [PATCH 3/3] Drop the TensorAlgebra source pin now that 0.14 is registered TensorAlgebra 0.14 is registered, so the `[compat]` bound resolves against the release and the branch pin is no longer needed. --- test/Project.toml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/test/Project.toml b/test/Project.toml index 0738dce..252666c 100644 --- a/test/Project.toml +++ b/test/Project.toml @@ -19,10 +19,6 @@ Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" [sources.SparseArraysBase] path = ".." -[sources.TensorAlgebra] -rev = "mf/inline-strided-permute" -url = "https://github.com/ITensor/TensorAlgebra.jl" - [compat] Adapt = "4.2" Aqua = "0.8.11"