From 8a833d9fa4c0569039a142862d45a596e3702091 Mon Sep 17 00:00:00 2001 From: Christopher Rackauckas Date: Sat, 5 Mar 2022 10:07:55 -0500 Subject: [PATCH] Overload lu_instance to it generates LU{ComponentMatrix} The fallback of `similar(A,0,0)` gives a `Matrix` instead of a ComponentMatrix. This fixes that to make the types correct for LU-factorization returns. --- src/array_interface.jl | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/array_interface.jl b/src/array_interface.jl index 0c2012d9..087dafed 100644 --- a/src/array_interface.jl +++ b/src/array_interface.jl @@ -2,6 +2,16 @@ Base.parent(x::ComponentArray) = getfield(x, :data) Base.size(x::ComponentArray) = size(getdata(x)) ArrayInterface.size(A::ComponentArray) = ArrayInterface.size(parent(A)) + +## https://github.com/SciML/DifferentialEquations.jl/issues/849 +function ArrayInterface.lu_instance(x::ComponentMatrix) + T = eltype(x) + noUnitT = typeof(zero(T)) + luT = LinearAlgebra.lutype(noUnitT) + ipiv = Vector{LinearAlgebra.BlasInt}(undef, 0) + info = zero(LinearAlgebra.BlasInt) + return LU{luT}(similar(x), ipiv, info) +end Base.elsize(x::Type{<:ComponentArray{T,N,A,Axes}}) where {T,N,A,Axes} = Base.elsize(A) @@ -246,4 +256,4 @@ end # Base.$f(x::Adjoint{T,<:AbstractVector{T}}, y::ComponentVector{T,A,Axes}) where {T<:Real,A,Axes} = $f(getdata(x), getdata(y)) # Base.$f(x::Transpose{T,<:AbstractVector{T}}, y::ComponentVector{T,A,Axes}) where {T<:Real,A,Axes} = $f(getdata(x), getdata(y)) # end -# end \ No newline at end of file +# end