Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

eltype of static matrix factorization is Any #1190

Closed
gdalle opened this issue Aug 4, 2023 · 2 comments
Closed

eltype of static matrix factorization is Any #1190

gdalle opened this issue Aug 4, 2023 · 2 comments

Comments

@gdalle
Copy link

gdalle commented Aug 4, 2023

julia> using StaticArrays, LinearAlgebra

julia> A = rand(2, 2);

julia> eltype(lu(A))
Float64

julia> S = SMatrix{2,2}(A);

julia> eltype(lu(S))
Any
@fredrikekre
Copy link
Member

What do you need it for? Note that neither LinearAlgebra.LU nor StaticArrays.LU are abstract arrays that you can index etc. They both iterate L, U, and p (matrix, matrix, vector) so considering this the Any eltype make more sense.

@gdalle
Copy link
Author

gdalle commented Aug 4, 2023

What do you need it for?

The following chunk of code will land in an upcoming version of ImplicitDifferentiation.jl. Basically I wanna solve a linear system with a possibly failed LU decomposition, and replace the results with NaNs if needed:

function safe_solve(A_lu, b)
    T = float(promote_type(eltype(A_lu), eltype(b)))
    x_maybenan = Vector{T}(undef, size(A_lu, 2))
    if issuccess(A_lu)
        x_maybenan .= A \ b
    else
        x_maybenan .= convert(T, NaN)
    end
    return x_maybenan
end

But this errored twice: because of float(eltype(A_lu)) and because of size(A_lu).

Note that neither LinearAlgebra.LU nor StaticArrays.LU are abstract arrays

Basically that's what confused me. Since matrix operations like * and \ are defined, I thought every matrix operation would be. But I understand why that is not the case.

For my scenario, I used the fields of the LU decomposition instead and it worked.

@gdalle gdalle closed this as completed Aug 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants