Skip to content

Commit 079418b

Browse files
authored
BlockArrays multiplication with non-Array base types and CI fixes
1 parent ee0152d commit 079418b

2 files changed

Lines changed: 12 additions & 18 deletions

File tree

‎src/linalg/factorizations.jl‎

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -74,22 +74,16 @@ for f in [
7474
MAK.$f!(t, out, MAK.select_algorithm(MAK.$f!, t, nothing; alg.kwargs...))
7575
end
7676

77-
# specializations until fixes in base package
78-
function MAK.is_left_isometric(A::BlockMatrix; atol::Real = 0, rtol::Real = MAK.defaulttol(A), norm = LinearAlgebra.norm)
79-
P = A' * A
80-
nP = norm(P) # isapprox would use `rtol * max(norm(P), norm(I))`
81-
for I in MAK.diagind(P)
82-
P[I] -= 1
83-
end
84-
return norm(P) <= max(atol, rtol * nP) # assume that the norm of I is `sqrt(n)`
85-
end
86-
function MAK.is_right_isometric(A::BlockMatrix; atol::Real = 0, rtol::Real = MAK.defaulttol(A), norm = LinearAlgebra.norm)
87-
P = A * A'
88-
nP = norm(P) # isapprox would use `rtol * max(norm(P), norm(I))`
89-
for I in MAK.diagind(P)
90-
P[I] -= 1
91-
end
92-
return norm(P) <= max(atol, rtol * nP) # assume that the norm of I is `sqrt(n)`
77+
# specializations until fixes in base packages:
78+
# - `similar(::MulAdd{<:AbstractBlockLayout,...})` hardcodes `Array` blocks, so `A' * A` on
79+
# non-CPU blocks mixes host and device storage (JuliaArrays/BlockArrays.jl#215).
80+
# - `MAK.diagview` silently does not alias into a `BlockMatrix`, so subtracting the identity there is a no-op.
81+
# Densifying sidesteps both, and preserves the storage type of the blocks.
82+
function MAK.is_left_isometric(A::BlockMatrix; kwargs...)
83+
return MAK.is_left_isometric(copy_dense!(similar_dense(A), A); kwargs...)
84+
end
85+
function MAK.is_right_isometric(A::BlockMatrix; kwargs...)
86+
return MAK.is_right_isometric(copy_dense!(similar_dense(A), A); kwargs...)
9387
end
9488

9589
# Make sure sparse blocktensormaps have dense outputs

‎test/abstracttensor/braidingtensor.jl‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@ end
3939
@testset "Issue #68" begin
4040
x = randn(ComplexF64, (⊞(ℙ^1) ⊗ ⊞(ℙ^1)) ← ⊞(ℙ^1))
4141
O = randn(ComplexF64, ((ℙ^1 ⊞ ℙ^4 ⊞ ℙ^16 ⊞ ℙ^4) ⊗ ⊞(ℙ^2)) ← (⊞(ℙ^2) ⊗ ⊞(ℙ^1)))
42-
A = randn(ComplexF64, (ℙ^4 ⊗ F^2 ⊗ (ℙ^2)') ← ℙ^1)
42+
A = randn(ComplexF64, (ℙ^4 ⊗ ℙ^2 ⊗ (ℙ^2)') ← ℙ^1)
4343
Ab = randn(ComplexF64, (ℙ^4 ⊗ ℙ^2 ⊗ (ℙ^2)') ← ℙ^1)
4444

4545
@plansor y[-1 -2; -3] ≔ A[-1 4 2; 1] * O[-2 6; 4 5] * τ[5 7; 2 3] *
4646
conj(Ab[-3 6 7; 8]) * x[1 3; 8]
47-
@test space(y) == (⊞(ℙ^4) ⊗ ⊞(ℙ^1)) ← ⊞(ℙ^4)
47+
@test space(y) == ((⊞(ℙ^4) ⊗ (ℙ^1 ⊞ ℙ^4 ⊞ ℙ^16 ⊞ ℙ^4)) ← ⊞(ℙ^4))
4848
end

0 commit comments

Comments
 (0)