Skip to content
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

[NDTensors] BlockSparseArray contract, QR, and Hermitian eigendecomposition #1247

Merged
merged 21 commits into from
Nov 17, 2023
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Test block sparse Hermitian eigendecomposition
mtfishman committed Nov 16, 2023
commit 69e1d5a94e466c23159a88fdbc04373aed564d0d
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@ module LinearAlgebraExt
using BlockArrays: BlockArrays, blockedrange, blocks
using ..BlockSparseArrays: SparseArray, nonzero_keys # TODO: Move to `SparseArraysExtensions` module, rename `SparseArrayDOK`.
using ..BlockSparseArrays: BlockSparseArrays, BlockSparseArray, nonzero_blockkeys
using LinearAlgebra: LinearAlgebra, Hermitian, Transpose, I, qr
using LinearAlgebra: LinearAlgebra, Hermitian, Transpose, I, eigen, qr
using ...NDTensors: Algorithm, @Algorithm_str # TODO: Move to `AlgorithmSelector` module.
using SparseArrays: SparseArrays, SparseMatrixCSC, spzeros, sparse

@@ -11,4 +11,6 @@ include("hermitian.jl")
# TODO: Move to `SparseArraysExtensions`.
include("transpose.jl")
include("qr.jl")
include("eigen.jl")
include("svd.jl")
end
13 changes: 11 additions & 2 deletions NDTensors/src/BlockSparseArrays/test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Test
using BlockArrays: BlockArrays, BlockRange, blocksize
using LinearAlgebra: norm, qr
using LinearAlgebra: Diagonal, Hermitian, eigen, qr
using NDTensors: contract
using NDTensors.BlockSparseArrays:
BlockSparseArrays, BlockSparseArray, gradedrange, nonzero_blockkeys, fusedims
@@ -82,7 +82,7 @@ include("TestBlockSparseArraysUtils.jl")
a_dest_dense = contract(Array(a1), (1, -1, 2), Array(a2), (-1, 3))
@show a_dest ≈ a_dest_dense
end
@testset "qr (eltype=$elt)" for elt in (Float32, Float64)
@testset "qr (eltype=$elt)" for elt in (Float32, ComplexF32, Float64, ComplexF64)
for d in
(([3, 4], [2, 3]), ([2, 3], [3, 4]), ([2, 3], [3]), ([3, 4], [2]), ([2], [3, 4]))
a = BlockSparseArray{elt}(d)
@@ -91,4 +91,13 @@ include("TestBlockSparseArraysUtils.jl")
@test q * r ≈ a
end
end
@testset "eigen (eltype=$elt)" for elt in (Float32, ComplexF32, Float64, ComplexF64)
d1, d2 = [2, 3], [2, 3]
a = BlockSparseArray{elt}(d1, d2)
TestBlockSparseArraysUtils.set_blocks!(a, randn, b -> allequal(b.n))
d, u = eigen(Hermitian(a))
@test eltype(d) == real(elt)
@test eltype(u) == elt
@test Hermitian(Matrix(a)) * Matrix(u) ≈ Matrix(u) * Diagonal(Vector(d))
end
end
3 changes: 0 additions & 3 deletions NDTensors/src/NDTensors.jl
Original file line number Diff line number Diff line change
@@ -161,9 +161,6 @@ include("arraystorage/diagonalarray/tensor/contract.jl")
# BlockSparseArray storage
include("arraystorage/blocksparsearray/storage/unwrap.jl")
include("arraystorage/blocksparsearray/storage/contract.jl")
## include("arraystorage/blocksparsearray/storage/qr.jl")
include("arraystorage/blocksparsearray/storage/eigen.jl")
include("arraystorage/blocksparsearray/storage/svd.jl")

include("arraystorage/blocksparsearray/tensor/contract.jl")

140 changes: 0 additions & 140 deletions NDTensors/src/arraystorage/blocksparsearray/storage/qr_backup.jl

This file was deleted.