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

Fix LU factorization in-place operations #22774

Merged
merged 4 commits into from
Aug 24, 2017
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Add tests for in-place operations of A_ldiv_B!(y, LU, x) for LU facto…
…rizations
  • Loading branch information
haampie committed Aug 23, 2017
commit 8775d66a0aa372d155d50a9e4110986b54470cbb
21 changes: 21 additions & 0 deletions test/linalg/lu.jl
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,27 @@ dimg = randn(n)/2
@test norm(a.'*(lua.'\c) - c,1) < ε*κ*n
end
end

# Test whether Ax_ldiv_B!(y, LU, x) indeed overwrites y
resultT = typeof(oneunit(eltyb) / oneunit(eltya))

b_dest = similar(b, resultT)
c_dest = similar(c, resultT)

A_ldiv_B!(b_dest, lua, b)
A_ldiv_B!(c_dest, lua, c)
@test norm(b_dest - lua \ b, 1) < ε*κ*2n
@test norm(c_dest - lua \ c, 1) < ε*κ*n

At_ldiv_B!(b_dest, lua, b)
At_ldiv_B!(c_dest, lua, c)
@test norm(b_dest - lua.' \ b, 1) < ε*κ*2n
@test norm(c_dest - lua.' \ c, 1) < ε*κ*n

Ac_ldiv_B!(b_dest, lua, b)
Ac_ldiv_B!(c_dest, lua, c)
@test norm(b_dest - lua' \ b, 1) < ε*κ*2n
@test norm(c_dest - lua' \ c, 1) < ε*κ*n
Copy link
Member

@Sacha0 Sacha0 Jul 15, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps DRY out these tests? For example, something along the lines of

for (Aq_ldiv_B!, q) in (
        (A_ldiv_B!, identity),
        (At_ldiv_B!, transpose),
        (Ac_ldiv_B!, ctranspose) )
    Aq_ldiv_B!(b_dest, lua, b)
    Aq_ldiv_B!(c_dest, lua, c)
    @test norm(b_dest - q(lua) \ b, 1) < ε*κ*2n
    @test norm(c_dest - q(lua) \ c, 1) < ε*κ*n
end

might serve? (Edit: Missed the secondary op the first time around! :) )

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've tried it, but it doesn't seem to work :(

> transpose(lufact(rand(3, 3))) \ rand(3)
ERROR: transpose not implemented for Base.LinAlg.LU{Float64,Array{Float64,2}}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is because A.' \ B becomes At_ldiv_B(A, B) (not transpose(A) \ B). Perhaps this will do?

for (Aq_ldiv_B!, f) in (
        (A_ldiv_B!, \),
        (At_ldiv_B!, At_ldiv_B),
        (Ac_ldiv_B!, Ac_ldiv_B) )
    Aq_ldiv_B!(b_dest, lua, b)
    Aq_ldiv_B!(c_dest, lua, c)
    @test norm(b_dest - f(lua, b), 1) < ε*κ*2n
    @test norm(c_dest - f(lua, c), 1) < ε*κ*n
end

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thx, so is .' \ parsed as a single operator or something?

Copy link
Member

@fredrikekre fredrikekre Aug 23, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes,

julia> expand(Main, :(A.'\B))
:(At_ldiv_B(A, B))

and similarly for * as well.

Copy link
Sponsor Member

@StefanKarpinski StefanKarpinski Aug 23, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is definitely a hack and we want to get rid of it, but we're not quite there yet.

end
if eltya <: BlasFloat && eltyb <: BlasFloat
e = rand(eltyb,n,n)
Expand Down