Skip to content

Conversation

@mtfishman
Copy link
Member

@mtfishman mtfishman commented Dec 8, 2025

This overloads TensorAlgebra.matricize through a package extension to return SparseArrays.SparseMatrixCSC, and defines some more converters to and from SparseArrays.jl and SparseArraysBase.jl objects.

This should make matrix multiplication faster, and will make it easier to define tensor factorizations in terms of SparseMatrixCSC matrix factorizations (though that will require adding support for sparse matrices in MatrixAlgebraKit.jl, see ITensor/TensorAlgebra.jl#21).

This also switches over to using the new [workspace] feature in the Project.toml, see https://pkgdocs.julialang.org/dev/creating-packages/#Recommended-approach:-Using-workspaces-with-test/Project.toml.

As a demonstration:

using SparseArraysBase: sparsezeros
using TensorAlgebra: contract, matricize
a = sparsezeros(2, 2, 2)
a[1, 1, 1] = 1
a[1, 2, 1] = 2
m = matricize(a, (1, 3), (2,))
b, l = contract(a, ("i", "j", "k"), a, ("j", "k", "l"))

results in:

julia> a
2×2×2 SparseArrayDOK{Float64, 3, FillArrays.Zeros{Float64, 3, Tuple{Base.OneTo{Int64}, Base.OneTo{Int64}, Base.OneTo{Int64}}}}:
[:, :, 1] =
 1.0  2.0
       

[:, :, 2] =
       
       

julia> m
4×2 SparseMatrixCSC{Float64, Int64} with 2 stored entries:
 1.0  2.0
       
       
       

julia> b
2×2 SparseMatrixDOK{Float64, FillArrays.Zeros{Float64, 2, Tuple{Base.OneTo{Int64}, Base.OneTo{Int64}}}}:
 1.0    
       

@github-actions
Copy link
Contributor

github-actions bot commented Dec 8, 2025

Your PR no longer requires formatting changes. Thank you for your contribution!

@codecov
Copy link

codecov bot commented Dec 8, 2025

Codecov Report

❌ Patch coverage is 93.33333% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 77.47%. Comparing base (78dece8) to head (840095c).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
src/sparsearrays.jl 90.47% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #75      +/-   ##
==========================================
+ Coverage   75.93%   77.47%   +1.54%     
==========================================
  Files           9       11       +2     
  Lines         698      728      +30     
==========================================
+ Hits          530      564      +34     
+ Misses        168      164       -4     
Flag Coverage Δ
docs 29.16% <0.00%> (-1.32%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@mtfishman mtfishman merged commit 033f150 into main Dec 8, 2025
16 checks passed
@mtfishman mtfishman deleted the mf/matricize branch December 8, 2025 20:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants