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

[RFC] Clean up test/tridiag #23609

Merged
merged 2 commits into from
Sep 7, 2017
Merged

[RFC] Clean up test/tridiag #23609

merged 2 commits into from
Sep 7, 2017

Conversation

kshyatt
Copy link
Contributor

@kshyatt kshyatt commented Sep 6, 2017

We had two loops doing very similar things. I tried to combine all the tests in a reasonable way. There's probably more that could be done here.

@kshyatt kshyatt added linear algebra Linear algebra test This change adds or pertains to unit tests labels Sep 6, 2017
@kshyatt kshyatt requested a review from andreasnoack September 6, 2017 20:35
Copy link
Member

@fredrikekre fredrikekre left a comment

Choose a reason for hiding this comment

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

Looks nicer, some (optional) comments 🇸🇪

end
end
ε = eps(abs2(float(one(elty))))
Copy link
Member

Choose a reason for hiding this comment

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

ε is not actually used in this file.

end
@testset "interconversion of Tridiagonal and SymTridiagonal" begin
@test Tridiagonal(dl, d, dl) == SymTridiagonal(d, dl)
@test SymTridiagonal(d, dl) == Tridiagonal(dl, d, dl)
Copy link
Member

Choose a reason for hiding this comment

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

This test is completely equivalent with the one on the line above.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

A bit of a theme in this file...

@test (A[3, 2] = A[3, 2]; A == fA) # test assignment on the subdiagonal
@test (A[2, 3] = A[2, 3]; A == fA) # test assignment on the superdiagonal
@test ((A[1, 3] = 0) == 0; A == fA) # test zero assignment off the main/sub/super diagonal
else
Copy link
Member

Choose a reason for hiding this comment

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

Add a comment else # mat_type == SymTridiagonal for clarity?

@test diag(A,0) == a
@test diag(A,n-1) == zeros(elty,1)
@test_throws ArgumentError diag(A,n+1)
@test diag(A, 1) == (mat_type == Tridiagonal ? du : dl)
Copy link
Member

Choose a reason for hiding this comment

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

This could test with ===. and likewise the next two tests.

@test ((A[3, 3] = A[3, 3]) == A[3, 3]; A == fA) # test assignment on the main diagonal
@test_throws ArgumentError A[3, 2] = 1 # test assignment on the subdiagonal
@test_throws ArgumentError A[2, 3] = 1 # test assignment on the superdiagonal
end
end
@testset "Diagonal extraction" begin
Copy link
Member

Choose a reason for hiding this comment

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

Could also be worth adding a test for diag(A), i.e. without specifying a diagonal.

@test isa(floor.(Int,A), SymTridiagonal)
for f in (round, trunc, floor, ceil)
fds = [f.(d) for d in ds]
@test f.(A) == mat_type(fds...)
Copy link
Member

Choose a reason for hiding this comment

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

Perhaps remove the isa tests here and do @test (f.(A))::mat_type == mat_type(fds...) for even more code deletion.

@test isa(ceil.(Int,A), Tridiagonal)
@test floor.(Int,A) == floor.(Int,fA)
@test isa(floor.(Int,A), Tridiagonal)
if elty <: Real
Copy link
Member

Choose a reason for hiding this comment

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

Seems like these two ifs could be collapsed to one level with if elty <: LinAlg.BlasReal

@kshyatt
Copy link
Contributor Author

kshyatt commented Sep 7, 2017

Thanks for the detailed review, @fredrikekre. These are great suggestions <3!

Copy link
Member

@fredrikekre fredrikekre left a comment

Choose a reason for hiding this comment

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

Nice!

@kshyatt kshyatt merged commit 6d1680a into master Sep 7, 2017
@kshyatt kshyatt deleted the ksh/reworktridiag branch September 7, 2017 21:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
linear algebra Linear algebra test This change adds or pertains to unit tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants