What this is about
Reading the code for various factorizations in LinearAlgebra, I notized that each define a bunch of methods to reconstruct a factorization (ie obtain an ::AbstractMatrix
).
Eg Cholesky
has
AbstractMatrix(C::Cholesky) = C.uplo == 'U' ? C.U'C.U : C.L*C.L'
AbstractArray(C::Cholesky) = AbstractMatrix(C)
Matrix(C::Cholesky) = Array(AbstractArray(C))
Array(C::Cholesky) = Matrix(C)
while LU
has
AbstractMatrix(F::LU) = (F.L * F.U)[invperm(F.p),:]
AbstractArray(F::LU) = AbstractMatrix(F)
Matrix(F::LU) = Array(AbstractArray(F))
Array(F::LU) = Matrix(F)
I am wondering if it would make sense to add default fallbacks and document which one the user would need to define for a subtype of Factorization
.
Proposal
I would propose that the user defines the AbstractMatrix
method, and have
AbstractArray(F::Factorization) = AbstractMatrix(F)
Matrix(F::Factorization) = Array(AbstractArray(F))
Array(F::Factorization) = Matrix(F)
This would
-
remove repetitive code,
-
standardize the method for future extensions, either in standard packages or user packages.