Skip to content

Commit d516eb4

Browse files
committed
Fix isisometric
1 parent bbed66d commit d516eb4

File tree

2 files changed

+36
-39
lines changed

2 files changed

+36
-39
lines changed

src/factorizations/utility.jl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
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(A::AbstractBlockSparseMatrix; isapprox_kwargs...)
10+
return isapprox(A' * A, LinearAlgebra.I; isapprox_kwargs...)
11+
end
12+
function MatrixAlgebraKit.is_right_isometric(A::AbstractBlockSparseMatrix; isapprox_kwargs...)
13+
return MatrixAlgebraKit.is_left_isometric(A'; isapprox_kwargs...)
14+
end
15+
316
function infimum(r1::AbstractUnitRange, r2::AbstractUnitRange)
417
(isone(first(r1)) && isone(first(r2))) ||
518
throw(ArgumentError("infimum only defined for ranges starting at 1"))

test/test_abstract_blocktype.jl

Lines changed: 23 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,9 @@ using BlockArrays: Block
33
using BlockSparseArrays: BlockSparseMatrix, blockstoredlength
44
using JLArrays: JLArray
55
using LinearAlgebra: hermitianpart, norm
6-
using MatrixAlgebraKit:
7-
eig_full,
8-
eig_trunc,
9-
eig_vals,
10-
eigh_full,
11-
eigh_trunc,
12-
eigh_vals,
13-
isisometry,
14-
left_orth,
15-
left_polar,
16-
lq_compact,
17-
lq_full,
18-
qr_compact,
19-
qr_full,
20-
right_orth,
21-
right_polar,
22-
svd_compact,
23-
svd_full,
24-
svd_trunc
6+
using MatrixAlgebraKit: eig_full, eig_trunc, eig_vals, eigh_full, eigh_trunc, eigh_vals,
7+
isisometric, left_orth, left_polar, lq_compact, lq_full, qr_compact, qr_full,
8+
right_orth, right_polar, svd_compact, svd_full, svd_trunc
259
using SparseArraysBase: storedlength
2610
using Test: @test, @test_broken, @testset
2711

@@ -106,32 +90,32 @@ arrayts = (Array, JLArray)
10690
a = BlockSparseMatrix{elt, AbstractMatrix{elt}}(undef, [2, 3], [2, 3])
10791
a[Block(1, 1)] = dev(randn(elt, 2, 2))
10892
for f in (left_orth, left_polar, qr_compact, qr_full)
109-
if arrayt Array && f left_orth
110-
@test_broken f(a)
93+
## if arrayt ≢ Array && f ≡ left_orth
94+
## @test_broken f(a)
95+
## else
96+
u, c = f(a)
97+
@test u * c a
98+
if arrayt Array
99+
@test isisometric(u; side = :left)
111100
else
112-
u, c = f(a)
113-
@test u * c a
114-
if arrayt Array
115-
@test isisometry(u; side = :left)
116-
else
117-
# TODO: Fix comparison with UniformScaling on GPU.
118-
@test_broken isisometry(u; side = :left)
119-
end
101+
# TODO: Fix comparison with UniformScaling on GPU.
102+
@test_broken isisometric(u; side = :left)
120103
end
104+
## end
121105
end
122106
for f in (right_orth, right_polar, lq_compact, lq_full)
123-
if arrayt Array && f right_orth
124-
@test_broken f(a)
107+
## if arrayt ≢ Array && f ≡ right_orth
108+
## @test_broken f(a)
109+
## else
110+
c, u = f(a)
111+
@test c * u a
112+
if arrayt Array
113+
@test isisometric(u; side = :right)
125114
else
126-
c, u = f(a)
127-
@test c * u a
128-
if arrayt Array
129-
@test isisometry(u; side = :right)
130-
else
131-
# TODO: Fix comparison with UniformScaling on GPU.
132-
@test_broken isisometry(u; side = :right)
133-
end
115+
# TODO: Fix comparison with UniformScaling on GPU.
116+
@test_broken isisometric(u; side = :right)
134117
end
118+
## end
135119
end
136120
for f in (svd_compact, svd_full, svd_trunc)
137121
if arrayt Array && (f svd_full || f svd_trunc)

0 commit comments

Comments
 (0)