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
4 changes: 2 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "SparseArraysBase"
uuid = "0d5efcca-f356-4864-8770-e1ed8d78f208"
version = "0.10.3"
version = "0.10.4"
authors = ["ITensor developers <support@itensor.org> and contributors"]

[workspace]
Expand Down Expand Up @@ -35,5 +35,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"
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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
2 changes: 1 addition & 1 deletion test/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Loading