Skip to content

Commit c4eeb2f

Browse files
authored
Resolve kron ambiguities (#342)
1 parent afe6847 commit c4eeb2f

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

src/linalg.jl

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1380,11 +1380,21 @@ end
13801380
end
13811381
return z
13821382
end
1383-
# due to the sparse result type, there is no risk to override dense ⊗ dense here
1384-
@inline function kron!(C::SparseMatrixCSC, A::Union{_SparseKronGroup,_DenseConcatGroup}, B::Union{_SparseKronGroup,_DenseConcatGroup})
1383+
kron!(C::SparseMatrixCSC, A::_SparseKronGroup, B::_DenseConcatGroup) =
13851384
kron!(C, convert(SparseMatrixCSC, A), convert(SparseMatrixCSC, B))
1386-
end
1387-
kron!(C::SparseMatrixCSC, A::SparseVectorUnion, B::AdjOrTransSparseVectorUnion) = broadcast!(*, C, A, B)
1385+
kron!(C::SparseMatrixCSC, A::_DenseConcatGroup, B::_SparseKronGroup) =
1386+
kron!(C, convert(SparseMatrixCSC, A), convert(SparseMatrixCSC, B))
1387+
kron!(C::SparseMatrixCSC, A::_SparseKronGroup, B::_SparseKronGroup) =
1388+
kron!(C, convert(SparseMatrixCSC, A), convert(SparseMatrixCSC, B))
1389+
kron!(C::SparseMatrixCSC, A::SparseVectorUnion, B::AdjOrTransSparseVectorUnion) =
1390+
broadcast!(*, C, A, B)
1391+
# disambiguation
1392+
kron!(C::SparseMatrixCSC, A::_SparseKronGroup, B::Diagonal) =
1393+
kron!(C, convert(SparseMatrixCSC, A), convert(SparseMatrixCSC, B))
1394+
kron!(C::SparseMatrixCSC, A::Diagonal, B::_SparseKronGroup) =
1395+
kron!(C, convert(SparseMatrixCSC, A), convert(SparseMatrixCSC, B))
1396+
kron!(c::SparseMatrixCSC, a::Number, b::_SparseKronGroup) = mul!(c, a, b)
1397+
kron!(c::SparseMatrixCSC, a::_SparseKronGroup, b::Number) = mul!(c, a, b)
13881398

13891399
function kron(A::AbstractSparseMatrixCSC, B::AbstractSparseMatrixCSC)
13901400
mA, nA = size(A)
@@ -1410,6 +1420,9 @@ kron(A::_SparseKronGroup, B::_SparseKronGroup) =
14101420
kron(A::_SparseKronGroup, B::_DenseConcatGroup) = kron(A, sparse(B))
14111421
kron(A::_DenseConcatGroup, B::_SparseKronGroup) = kron(sparse(A), B)
14121422
kron(A::SparseVectorUnion, B::AdjOrTransSparseVectorUnion) = A .* B
1423+
# disambiguation
1424+
kron(a::Number, b::_SparseKronGroup) = a * b
1425+
kron(a::_SparseKronGroup, b::Number) = a * b
14131426

14141427
## det, inv, cond
14151428

src/solvers/cholmod.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1576,7 +1576,8 @@ end
15761576
(\)(L::Factor, B::Transpose{<:Any,<:SparseMatrixCSC}) = L \ copy(B)
15771577
(\)(L::Factor, B::SparseVector) = sparsevec(spsolve(CHOLMOD_A, L, Sparse(B)))
15781578

1579-
\(adjL::AdjType{<:Any,<:Factor}, B::Dense) = (L = adjL.parent; solve(CHOLMOD_A, L, B))
1579+
# the eltype restriction is necessary for disambiguation with the B::StridedMatrix below
1580+
\(adjL::AdjType{<:VTypes,<:Factor}, B::Dense) = (L = adjL.parent; solve(CHOLMOD_A, L, B))
15801581
\(adjL::AdjType{<:Any,<:Factor}, B::Sparse) = (L = adjL.parent; spsolve(CHOLMOD_A, L, B))
15811582
\(adjL::AdjType{<:Any,<:Factor}, B::SparseVecOrMat) = (L = adjL.parent; \(adjoint(L), Sparse(B)))
15821583

0 commit comments

Comments
 (0)