In v1.0, using the Cholesky decomposition of a sparse array to solve a linear system for the transpose results in a two-dimensional array instead of a vector:
using LinearAlgebra,SparseArrays
N = 4
A = sparse(I,N,N)
C = cholesky(A)
b = randn(N)
C'\b
returns
4脳1 Array{Float64,2}:
...
By contrast, C\b (correctly) returns
4-element Array{Float64,1}:
...
(The corresponding test for Array(I,N,N) throws a ERROR: MethodError: no method matching adjoint(::Cholesky{Float64,Array{Float64,2}}).)
@Sacha0, @andreasnoack?
This is a bug and should be fixed.
Yes, we must fix this. The culprit is probably in here:
\(adjL::Adjoint{<:Any,<:Factor}, B::Dense) = (L = adjL.parent; solve(CHOLMOD_A, L, B))
\(adjL::Adjoint{<:Any,<:Factor}, B::VecOrMat) = (L = adjL.parent; Matrix(solve(CHOLMOD_A, L, Dense(B))))
I would like to work on this if nobody is currently working on it.
Go for it.
I think the problem is explicit conversion to Matrix in \(adjL::Adjoint{<:Any,<:Factor}, B::VecOrMat) = (L = adjL.parent; Matrix(solve(CHOLMOD_A, L, Dense(B))))
Is that correct?
I believe the matrix and the vector cases need to be separated out.
\(adjL::Adjoint{<:Any,<:Factor}, B::Vector) = (L = adjL.parent; Vector(solve(CHOLMOD_A, L, Dense(B))))
\(adjL::Adjoint{<:Any,<:Factor}, B::Matrix) = (L = adjL.parent; Matrix(solve(CHOLMOD_A, L, Dense(B))))
Something like this??
Probably. It needs to be tried out and all tests should pass.
Something like this??
Yes that should work. While you are at it, please allow that B can be StridedVector/StridedMatrix. Also, it's slightly nicer to use lower case for vectors (but still upper case for matrices). Finally, please also split the function over multiple lines instead of using ;.