From 4974495954c6f01c4bace55588dd56e395d442bf Mon Sep 17 00:00:00 2001 From: mtfishman Date: Thu, 29 May 2025 19:26:27 -0400 Subject: [PATCH 1/2] Begin implementation of null --- Project.toml | 2 +- src/factorizations/orthnull.jl | 53 ++++++++++++++++++++++++++++++++++ src/factorizations/qr.jl | 9 +++--- src/factorizations/svd.jl | 8 ++--- 4 files changed, 63 insertions(+), 9 deletions(-) diff --git a/Project.toml b/Project.toml index 826dd156..c15f9724 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "BlockSparseArrays" uuid = "2c9a651f-6452-4ace-a6ac-809f4280fbb4" authors = ["ITensor developers and contributors"] -version = "0.6.7" +version = "0.6.8" [deps] Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e" diff --git a/src/factorizations/orthnull.jl b/src/factorizations/orthnull.jl index b06af8e3..cbcffd7a 100644 --- a/src/factorizations/orthnull.jl +++ b/src/factorizations/orthnull.jl @@ -1,9 +1,15 @@ using MatrixAlgebraKit: MatrixAlgebraKit, + default_svd_algorithm, + left_null!, + left_null_svd!, left_orth!, left_polar!, lq_compact!, + null_truncation_strategy, qr_compact!, + right_null!, + right_null_svd!, right_orth!, right_polar!, select_algorithm, @@ -122,3 +128,50 @@ function MatrixAlgebraKit.right_orth_svd!(A::AbstractBlockSparseMatrix, F, alg, U, S, Vᴴ = svd_trunc!(A, alg_trunc) return U * S, Vᴴ end + +function MatrixAlgebraKit.initialize_output( + ::typeof(left_null!), A::AbstractBlockSparseMatrix +) + return nothing +end +function MatrixAlgebraKit.check_input( + ::typeof(left_null!), A::AbstractBlockSparseMatrix, N::Nothing +) + return nothing +end +function MatrixAlgebraKit.left_null_qr!(A::AbstractBlockSparseMatrix, N, alg) + return left_null_svd!(A, N, default_svd_algorithm(A)) +end +function MatrixAlgebraKit.left_null_svd!( + A::AbstractBlockSparseMatrix, N, alg, trunc::Nothing +) + return left_null_svd!(A, N, alg, null_truncation_strategy(; atol=0, rtol=0)) +end +function MatrixAlgebraKit.truncate!( + ::typeof(left_null!), + (U, S)::Tuple{AbstractBlockSparseMatrix,AbstractBlockSparseMatrix}, + strategy::TruncationStrategy, +) + return error("Not implemented.") +end + +function MatrixAlgebraKit.initialize_output( + ::typeof(right_null!), A::AbstractBlockSparseMatrix +) + return nothing +end +function MatrixAlgebraKit.check_input( + ::typeof(right_null!), A::AbstractBlockSparseMatrix, N::Nothing +) + return nothing +end +function MatrixAlgebraKit.right_null_lq!(A::AbstractBlockSparseMatrix, N, alg) + return error("Not implement.") +end +function MatrixAlgebraKit.truncate!( + ::typeof(right_null!), + (U, S)::Tuple{AbstractBlockSparseMatrix,AbstractBlockSparseMatrix}, + strategy::TruncationStrategy, +) + return error("Not implemented.") +end diff --git a/src/factorizations/qr.jl b/src/factorizations/qr.jl index 8ec1ccdf..55a0b93e 100644 --- a/src/factorizations/qr.jl +++ b/src/factorizations/qr.jl @@ -1,8 +1,9 @@ -using MatrixAlgebraKit: MatrixAlgebraKit, lq_compact!, lq_full!, qr_compact!, qr_full! +using MatrixAlgebraKit: + MatrixAlgebraKit, default_qr_algorithm, lq_compact!, lq_full!, qr_compact!, qr_full! # TODO: this is a hardcoded for now to get around this function not being defined in the # type domain -function default_blocksparse_qr_algorithm(A::AbstractMatrix; kwargs...) +function MatrixAlgebraKit.default_qr_algorithm(A::AbstractBlockSparseMatrix; kwargs...) blocktype(A) <: StridedMatrix{<:LinearAlgebra.BLAS.BlasFloat} || error("unsupported type: $(blocktype(A))") alg = MatrixAlgebraKit.LAPACK_HouseholderQR(; kwargs...) @@ -11,12 +12,12 @@ end function MatrixAlgebraKit.default_algorithm( ::typeof(qr_compact!), A::AbstractBlockSparseMatrix; kwargs... ) - return default_blocksparse_qr_algorithm(A; kwargs...) + return default_qr_algorithm(A; kwargs...) end function MatrixAlgebraKit.default_algorithm( ::typeof(qr_full!), A::AbstractBlockSparseMatrix; kwargs... ) - return default_blocksparse_qr_algorithm(A; kwargs...) + return default_qr_algorithm(A; kwargs...) end function similar_output( diff --git a/src/factorizations/svd.jl b/src/factorizations/svd.jl index fbaae498..187795ea 100644 --- a/src/factorizations/svd.jl +++ b/src/factorizations/svd.jl @@ -1,4 +1,4 @@ -using MatrixAlgebraKit: MatrixAlgebraKit, svd_compact!, svd_full! +using MatrixAlgebraKit: MatrixAlgebraKit, default_svd_algorithm, svd_compact!, svd_full! """ BlockPermutedDiagonalAlgorithm(A::MatrixAlgebraKit.AbstractAlgorithm) @@ -12,7 +12,7 @@ struct BlockPermutedDiagonalAlgorithm{A<:MatrixAlgebraKit.AbstractAlgorithm} <: alg::A end -function default_blocksparse_svd_algorithm(f, A; kwargs...) +function MatrixAlgebraKit.default_svd_algorithm(A; kwargs...) blocktype(A) <: StridedMatrix{<:LinearAlgebra.BLAS.BlasFloat} || error("unsupported type: $(blocktype(A))") # TODO: this is a hardcoded for now to get around this function not being defined in the @@ -25,12 +25,12 @@ end function MatrixAlgebraKit.default_algorithm( f::typeof(svd_compact!), A::AbstractBlockSparseMatrix; kwargs... ) - return default_blocksparse_svd_algorithm(f, A; kwargs...) + return default_svd_algorithm(A; kwargs...) end function MatrixAlgebraKit.default_algorithm( f::typeof(svd_full!), A::AbstractBlockSparseMatrix; kwargs... ) - return default_blocksparse_svd_algorithm(f, A; kwargs...) + return default_svd_algorithm(A; kwargs...) end function similar_output( From 013e0c261ba940a28664e497f73e3f0ce93048d9 Mon Sep 17 00:00:00 2001 From: mtfishman Date: Thu, 29 May 2025 19:27:02 -0400 Subject: [PATCH 2/2] Better arg name --- src/factorizations/orthnull.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/factorizations/orthnull.jl b/src/factorizations/orthnull.jl index cbcffd7a..dc8b1d86 100644 --- a/src/factorizations/orthnull.jl +++ b/src/factorizations/orthnull.jl @@ -170,7 +170,7 @@ function MatrixAlgebraKit.right_null_lq!(A::AbstractBlockSparseMatrix, N, alg) end function MatrixAlgebraKit.truncate!( ::typeof(right_null!), - (U, S)::Tuple{AbstractBlockSparseMatrix,AbstractBlockSparseMatrix}, + (S, Vᴴ)::Tuple{AbstractBlockSparseMatrix,AbstractBlockSparseMatrix}, strategy::TruncationStrategy, ) return error("Not implemented.")