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

rdiv! is not working for an LU object in Julia 1.2 #40586

Closed
andreasvarga opened this issue Apr 23, 2021 · 2 comments
Closed

rdiv! is not working for an LU object in Julia 1.2 #40586

andreasvarga opened this issue Apr 23, 2021 · 2 comments

Comments

@andreasvarga
Copy link
Contributor

I am performing tests with the DescriptorSystems with versions of Julia starting with 1.2. The tests with Julia 1.2 fail with a message saying

MethodError: no method matching rdiv!(::Array{Float64,2}, ::LinearAlgebra.LU{Float64,Array{Float64,2}})

I reproduced the error message after I reinstalled version 1.2 and performed the following sequence:

using LinearAlgebra
a = rand(3,3);
b = rand(3,3);
F = lu(a);
ldiv!(F,b);
rdiv!(b,F);
ERROR: MethodError: no method matching rdiv!(::Array{Float64,2}, ::LU{Float64,Array{Float64,2}})

All other versions of Julia starting with 1.3 are working at this point. I wonder if this is an error or rdiv! is not implemented for factorizations such as LU or QR (I was able to find the code only for ldiv!, but rdiv! is documented). Compat.jl also does not provide a solution.

The missing code (taken from version 1.6) is:

function rdiv!(A::StridedVecOrMat, B::LU{<:Any,<:StridedMatrix})
    rdiv!(rdiv!(A, UpperTriangular(B.factors)), UnitLowerTriangular(B.factors))
    _apply_inverse_ipiv_cols!(B, A)
end

_apply_inverse_ipiv_cols!(A::LU, B::StridedVecOrMat) = _ipiv_cols!(A, length(A.ipiv) : -1 : 1, B)

function _ipiv_cols!(A::LU, order::OrdinalRange, B::StridedVecOrMat)
    for i = order
        if i != A.ipiv[i]
            _swap_cols!(B, i, A.ipiv[i])
        end
    end
    B
end

function _swap_cols!(B::StridedVector, i::Integer, j::Integer)
    _swap_rows!(B, i, j)
end

function _swap_cols!(B::StridedMatrix, i::Integer, j::Integer)
    for row = 1 : size(B, 1)
        B[row,i], B[row,j] = B[row,j], B[row,i]
    end
    B
end

The overloaded code for rdiv! works apparently in version 1.2 too:

julia> rdiv!(a,lu(a))
3×3 Array{Float64,2}:
 1.0  0.0  3.21456e-16
 0.0  1.0  0.0
 0.0  0.0  1.0
@mcabbott
Copy link
Contributor

This seems to have been added in #31285, which is part of 1.3 onwards. If sufficiently motivated you could add it to Compat.jl, but it's probably better to upgrade.

@andreasvarga
Copy link
Contributor Author

Thanks! I added the code to my package to be only used with Julia 1.2. See a comment in Discourse on this issue.

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