Skip to content

Commit c9fe25e

Browse files
github-actions[bot]CompatHelper Juliamtfishman
authored
CompatHelper: bump compat for MatrixAlgebraKit to 0.6, (keep existing compat) (#184)
Co-authored-by: CompatHelper Julia <[email protected]> Co-authored-by: Matt Fishman <[email protected]> Co-authored-by: mtfishman <[email protected]>
1 parent e489457 commit c9fe25e

File tree

8 files changed

+130
-125
lines changed

8 files changed

+130
-125
lines changed

Project.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "BlockSparseArrays"
22
uuid = "2c9a651f-6452-4ace-a6ac-809f4280fbb4"
3+
version = "0.10.11"
34
authors = ["ITensor developers <[email protected]> and contributors"]
4-
version = "0.10.10"
55

66
[deps]
77
Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"
@@ -41,7 +41,7 @@ GPUArraysCore = "0.1, 0.2"
4141
LinearAlgebra = "1.10"
4242
MacroTools = "0.5.13"
4343
MapBroadcast = "0.1.5"
44-
MatrixAlgebraKit = "0.5"
44+
MatrixAlgebraKit = "0.6"
4545
SparseArraysBase = "0.7.1"
4646
SplitApplyCombine = "1.2.3"
4747
TensorAlgebra = "0.3, 0.4"

src/factorizations/orthnull.jl

Lines changed: 76 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,21 @@
1-
using MatrixAlgebraKit:
2-
MatrixAlgebraKit,
3-
default_svd_algorithm,
4-
left_null!,
5-
left_null_svd!,
6-
left_orth!,
7-
left_polar!,
8-
lq_compact!,
9-
null_truncation_strategy,
10-
qr_compact!,
11-
right_null!,
12-
right_null_svd!,
13-
right_orth!,
14-
right_polar!,
15-
select_algorithm,
16-
svd_compact!
1+
using MatrixAlgebraKit: MatrixAlgebraKit, AbstractAlgorithm, default_svd_algorithm,
2+
left_null!, left_orth!, left_polar!, lq_compact!, null_truncation_strategy, qr_compact!,
3+
right_null!, right_orth!, right_polar!, select_algorithm, svd_compact!
174

18-
function MatrixAlgebraKit.initialize_output(
19-
::typeof(left_orth!), A::AbstractBlockSparseMatrix
20-
)
21-
return nothing
5+
using MatrixAlgebraKit: LeftOrthAlgorithm
6+
for kind in ("polar", "qr", "svd")
7+
@eval begin
8+
function MatrixAlgebraKit.initialize_output(
9+
::typeof(left_orth!), A::AbstractBlockSparseMatrix,
10+
alg::LeftOrthAlgorithm{Symbol($kind)},
11+
)
12+
return nothing
13+
end
14+
end
2215
end
23-
function MatrixAlgebraKit.check_input(::typeof(left_orth!), A::AbstractBlockSparseMatrix, F)
16+
function MatrixAlgebraKit.check_input(
17+
::typeof(left_orth!), A::AbstractBlockSparseMatrix, F, alg::AbstractAlgorithm
18+
)
2419
!isnothing(F) && throw(
2520
ArgumentError(
2621
"`left_orth!` on block sparse matrices does not support specifying the output"
@@ -29,55 +24,60 @@ function MatrixAlgebraKit.check_input(::typeof(left_orth!), A::AbstractBlockSpar
2924
return nothing
3025
end
3126

32-
function MatrixAlgebraKit.left_orth_qr!(A::AbstractBlockSparseMatrix, F, alg)
27+
using MatrixAlgebraKit: LeftOrthViaQR
28+
function MatrixAlgebraKit.left_orth!(A::AbstractBlockSparseMatrix, F, alg::LeftOrthViaQR)
3329
!isnothing(F) && throw(
3430
ArgumentError(
3531
"`left_orth!` on block sparse matrices does not support specifying the output"
3632
),
3733
)
38-
alg′ = select_algorithm(qr_compact!, A, alg)
34+
alg′ = select_algorithm(qr_compact!, A, alg.alg)
3935
return qr_compact!(A, alg′)
4036
end
41-
function MatrixAlgebraKit.left_orth_polar!(A::AbstractBlockSparseMatrix, F, alg)
37+
using MatrixAlgebraKit: LeftOrthViaPolar
38+
function MatrixAlgebraKit.left_orth!(A::AbstractBlockSparseMatrix, F, alg::LeftOrthViaPolar)
4239
!isnothing(F) && throw(
4340
ArgumentError(
4441
"`left_orth!` on block sparse matrices does not support specifying the output"
4542
),
4643
)
47-
alg′ = select_algorithm(left_polar!, A, alg)
44+
alg′ = select_algorithm(left_polar!, A, alg.alg)
4845
return left_polar!(A, alg′)
4946
end
50-
function MatrixAlgebraKit.left_orth_svd!(
51-
A::AbstractBlockSparseMatrix, F, alg, trunc::Nothing = nothing
47+
using MatrixAlgebraKit: LeftOrthViaSVD, does_truncate
48+
function MatrixAlgebraKit.left_orth!(
49+
A::AbstractBlockSparseMatrix, F, alg::LeftOrthViaSVD
5250
)
5351
!isnothing(F) && throw(
5452
ArgumentError(
5553
"`left_orth!` on block sparse matrices does not support specifying the output"
5654
),
5755
)
58-
alg′ = select_algorithm(svd_compact!, A, alg)
59-
U, S, Vᴴ = svd_compact!(A, alg′)
60-
return U, S * Vᴴ
61-
end
62-
function MatrixAlgebraKit.left_orth_svd!(A::AbstractBlockSparseMatrix, F, alg, trunc)
63-
!isnothing(F) && throw(
64-
ArgumentError(
65-
"`left_orth!` on block sparse matrices does not support specifying the output"
66-
),
67-
)
68-
alg′ = select_algorithm(svd_compact!, A, alg)
69-
alg_trunc = select_algorithm(svd_trunc!, A, alg′; trunc)
70-
U, S, Vᴴ = svd_trunc!(A, alg_trunc)
56+
U, S, Vᴴ = if !does_truncate(alg.alg)
57+
alg′ = select_algorithm(svd_compact!, A, alg.alg)
58+
svd_compact!(A, alg′)
59+
else
60+
alg′ = select_algorithm(svd_compact!, A, alg.alg)
61+
alg_trunc = select_algorithm(svd_trunc!, A, alg′)
62+
svd_trunc!(A, alg_trunc)
63+
end
7164
return U, S * Vᴴ
7265
end
7366

74-
function MatrixAlgebraKit.initialize_output(
75-
::typeof(right_orth!), A::AbstractBlockSparseMatrix
76-
)
77-
return nothing
67+
using MatrixAlgebraKit: RightOrthAlgorithm
68+
for kind in ("lq", "polar", "svd")
69+
@eval begin
70+
function MatrixAlgebraKit.initialize_output(
71+
::typeof(right_orth!), A::AbstractBlockSparseMatrix,
72+
alg::RightOrthAlgorithm{Symbol($kind)},
73+
)
74+
return nothing
75+
end
76+
end
7877
end
7978
function MatrixAlgebraKit.check_input(
80-
::typeof(right_orth!), A::AbstractBlockSparseMatrix, F::Nothing
79+
::typeof(right_orth!), A::AbstractBlockSparseMatrix, F::Nothing,
80+
alg::AbstractAlgorithm,
8181
)
8282
!isnothing(F) && throw(
8383
ArgumentError(
@@ -87,65 +87,63 @@ function MatrixAlgebraKit.check_input(
8787
return nothing
8888
end
8989

90-
function MatrixAlgebraKit.right_orth_lq!(A::AbstractBlockSparseMatrix, F, alg)
90+
using MatrixAlgebraKit: RightOrthViaLQ
91+
function MatrixAlgebraKit.right_orth!(A::AbstractBlockSparseMatrix, F, alg::RightOrthViaLQ)
9192
!isnothing(F) && throw(
9293
ArgumentError(
9394
"`right_orth!` on block sparse matrices does not support specifying the output"
9495
),
9596
)
96-
alg′ = select_algorithm(lq_compact!, A, alg)
97+
alg′ = select_algorithm(lq_compact!, A, alg.alg)
9798
return lq_compact!(A, alg′)
9899
end
99-
function MatrixAlgebraKit.right_orth_polar!(A::AbstractBlockSparseMatrix, F, alg)
100+
using MatrixAlgebraKit: RightOrthViaPolar
101+
function MatrixAlgebraKit.right_orth!(
102+
A::AbstractBlockSparseMatrix, F, alg::RightOrthViaPolar
103+
)
100104
!isnothing(F) && throw(
101105
ArgumentError(
102106
"`right_orth!` on block sparse matrices does not support specifying the output"
103107
),
104108
)
105-
alg′ = select_algorithm(right_polar!, A, alg)
109+
alg′ = select_algorithm(right_polar!, A, alg.alg)
106110
return right_polar!(A, alg′)
107111
end
108-
function MatrixAlgebraKit.right_orth_svd!(
109-
A::AbstractBlockSparseMatrix, F, alg, trunc::Nothing = nothing
112+
using MatrixAlgebraKit: RightOrthViaSVD
113+
function MatrixAlgebraKit.right_orth!(
114+
A::AbstractBlockSparseMatrix, F, alg::RightOrthViaSVD
110115
)
111116
!isnothing(F) && throw(
112117
ArgumentError(
113118
"`right_orth!` on block sparse matrices does not support specifying the output"
114119
),
115120
)
116-
alg′ = select_algorithm(svd_compact!, A, alg)
117-
U, S, Vᴴ = svd_compact!(A, alg′)
118-
return U * S, Vᴴ
119-
end
120-
function MatrixAlgebraKit.right_orth_svd!(A::AbstractBlockSparseMatrix, F, alg, trunc)
121-
!isnothing(F) && throw(
122-
ArgumentError(
123-
"`right_orth!` on block sparse matrices does not support specifying the output"
124-
),
125-
)
126-
alg′ = select_algorithm(svd_compact!, A, alg)
127-
alg_trunc = select_algorithm(svd_trunc!, A, alg′; trunc)
128-
U, S, Vᴴ = svd_trunc!(A, alg_trunc)
121+
U, S, Vᴴ = if !does_truncate(alg.alg)
122+
alg′ = select_algorithm(svd_compact!, A, alg.alg)
123+
svd_compact!(A, alg′)
124+
else
125+
alg′ = select_algorithm(svd_compact!, A, alg.alg)
126+
alg_trunc = select_algorithm(svd_trunc!, A, alg′)
127+
svd_trunc!(A, alg_trunc)
128+
end
129129
return U * S, Vᴴ
130130
end
131131

132132
function MatrixAlgebraKit.initialize_output(
133-
::typeof(left_null!), A::AbstractBlockSparseMatrix
133+
::typeof(left_null!), A::AbstractBlockSparseMatrix, alg::AbstractAlgorithm
134134
)
135135
return nothing
136136
end
137137
function MatrixAlgebraKit.check_input(
138-
::typeof(left_null!), A::AbstractBlockSparseMatrix, N::Nothing
138+
::typeof(left_null!), A::AbstractBlockSparseMatrix, N::Nothing,
139+
alg::AbstractAlgorithm,
139140
)
140141
return nothing
141142
end
142-
function MatrixAlgebraKit.left_null_qr!(A::AbstractBlockSparseMatrix, N, alg)
143-
return left_null_svd!(A, N, default_svd_algorithm(A))
144-
end
145-
function MatrixAlgebraKit.left_null_svd!(
146-
A::AbstractBlockSparseMatrix, N, alg, trunc::Nothing
143+
function MatrixAlgebraKit.left_null!(
144+
A::AbstractBlockSparseMatrix, N, alg::AbstractAlgorithm
147145
)
148-
return left_null_svd!(A, N, alg, null_truncation_strategy(; atol = 0, rtol = 0))
146+
return error("Not implemented.")
149147
end
150148
function MatrixAlgebraKit.truncate(
151149
::typeof(left_null!),
@@ -156,16 +154,19 @@ function MatrixAlgebraKit.truncate(
156154
end
157155

158156
function MatrixAlgebraKit.initialize_output(
159-
::typeof(right_null!), A::AbstractBlockSparseMatrix
157+
::typeof(right_null!), A::AbstractBlockSparseMatrix, alg::AbstractAlgorithm
160158
)
161159
return nothing
162160
end
163161
function MatrixAlgebraKit.check_input(
164-
::typeof(right_null!), A::AbstractBlockSparseMatrix, N::Nothing
162+
::typeof(right_null!), A::AbstractBlockSparseMatrix, N::Nothing,
163+
alg::AbstractAlgorithm,
165164
)
166165
return nothing
167166
end
168-
function MatrixAlgebraKit.right_null_lq!(A::AbstractBlockSparseMatrix, N, alg)
167+
function MatrixAlgebraKit.right_null!(
168+
A::AbstractBlockSparseMatrix, N, alg::AbstractAlgorithm
169+
)
169170
return error("Not implement.")
170171
end
171172
function MatrixAlgebraKit.truncate(

src/factorizations/polar.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ end
2727
function MatrixAlgebraKit.left_polar!(A::AbstractBlockSparseMatrix, alg::PolarViaSVD)
2828
check_input(left_polar!, A)
2929
# TODO: Use more in-place operations here, avoid `copy`.
30-
U, S, Vᴴ = svd_compact!(A, alg.svdalg)
30+
U, S, Vᴴ = svd_compact!(A, alg.svd_alg)
3131
W = U * Vᴴ
3232
# TODO: `copy` is required for now because of:
3333
# https://github.com/ITensor/BlockSparseArrays.jl/issues/24
@@ -38,7 +38,7 @@ end
3838
function MatrixAlgebraKit.right_polar!(A::AbstractBlockSparseMatrix, alg::PolarViaSVD)
3939
check_input(right_polar!, A)
4040
# TODO: Use more in-place operations here, avoid `copy`.
41-
U, S, Vᴴ = svd_compact!(A, alg.svdalg)
41+
U, S, Vᴴ = svd_compact!(A, alg.svd_alg)
4242
Wᴴ = U * Vᴴ
4343
# TODO: `copy` is required for now because of:
4444
# https://github.com/ITensor/BlockSparseArrays.jl/issues/24

src/factorizations/svd.jl

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using DiagonalArrays: diagonaltype
2-
using MatrixAlgebraKit:
3-
MatrixAlgebraKit, check_input, default_svd_algorithm, svd_compact!, svd_full!, svd_vals!
2+
using MatrixAlgebraKit: MatrixAlgebraKit, check_input, default_svd_algorithm, svd_compact!,
3+
svd_full!, svd_vals!
44
using TypeParameterAccessors: realtype
55

66
function MatrixAlgebraKit.default_svd_algorithm(
@@ -239,3 +239,14 @@ function MatrixAlgebraKit.svd_vals!(
239239
end
240240
return S
241241
end
242+
243+
# Computing truncation errors. Currently not supported for block sparse matrices,
244+
# needs to be implemented.
245+
struct BlockSparseDiagView{T, A <: AbstractBlockSparseMatrix{T}} <:
246+
AbstractBlockSparseVector{T}
247+
a::A
248+
end
249+
MatrixAlgebraKit.diagview(a::AbstractBlockSparseMatrix) = BlockSparseDiagView(a)
250+
# TODO: Implement this, and/or develop `BlockSparseDiagView` so that the generic
251+
# version in MatrixAlgebraKit works.
252+
MatrixAlgebraKit.truncation_error!(a::BlockSparseDiagView, ind) = nothing

src/factorizations/utility.jl

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,22 @@
1+
using LinearAlgebra: LinearAlgebra
12
using MatrixAlgebraKit: MatrixAlgebraKit
23

4+
# Friendlier definitions for block sparse matrices. MatrixAlgebraKit.jl v0.6
5+
# defines them in terms of `diagview`:
6+
# https://github.com/QuantumKitHub/MatrixAlgebraKit.jl/blob/v0.6.0/src/common/matrixproperties.jl#L40-L64
7+
# which isn't well supported right now for block sparse matrices.
8+
# TODO: Improve `diagview` for block sparse matrices and remove these definitions.
9+
function MatrixAlgebraKit.is_left_isometric(
10+
A::AnyAbstractBlockSparseMatrix; isapprox_kwargs...
11+
)
12+
return isapprox(A' * A, LinearAlgebra.I; isapprox_kwargs...)
13+
end
14+
function MatrixAlgebraKit.is_right_isometric(
15+
A::AnyAbstractBlockSparseMatrix; isapprox_kwargs...
16+
)
17+
return MatrixAlgebraKit.is_left_isometric(A'; isapprox_kwargs...)
18+
end
19+
320
function infimum(r1::AbstractUnitRange, r2::AbstractUnitRange)
421
(isone(first(r1)) && isone(first(r2))) ||
522
throw(ArgumentError("infimum only defined for ranges starting at 1"))

test/Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ DiagonalArrays = "0.3"
3131
GPUArraysCore = "0.2"
3232
JLArrays = "0.2, 0.3"
3333
LinearAlgebra = "1"
34-
MatrixAlgebraKit = "0.5"
34+
MatrixAlgebraKit = "0.6"
3535
Random = "1"
3636
SafeTestsets = "0.1"
3737
SparseArraysBase = "0.7"

0 commit comments

Comments
 (0)