-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
LinAlg.fillslots! -> LinAlg.fillstored! #25030
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
Changes from 3 commits
bc28fbf
197ada2
893281d
69369a7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -310,58 +310,56 @@ end | |
| @test promote(C,A) isa Tuple{Tridiagonal, Tridiagonal} | ||
| end | ||
|
|
||
| import Base.LinAlg: fillslots!, UnitLowerTriangular | ||
| @testset "fill! and fillslots!" begin | ||
| let #fill! | ||
| let # fillslots! | ||
| A = Tridiagonal(randn(2), randn(3), randn(2)) | ||
| @test fillslots!(A, 3) == Tridiagonal([3, 3.], [3, 3, 3.], [3, 3.]) | ||
| B = Bidiagonal(randn(3), randn(2), :U) | ||
| @test fillslots!(B, 2) == Bidiagonal([2.,2,2], [2,2.], :U) | ||
| S = SymTridiagonal(randn(3), randn(2)) | ||
| @test fillslots!(S, 1) == SymTridiagonal([1,1,1.], [1,1.]) | ||
| Ult = UnitLowerTriangular(randn(3,3)) | ||
| @test fillslots!(Ult, 3) == UnitLowerTriangular([1 0 0; 3 1 0; 3 3 1]) | ||
| end | ||
| let # fill!(exotic, 0) | ||
| exotic_arrays = Any[Tridiagonal(randn(3), randn(4), randn(3)), | ||
| Bidiagonal(randn(3), randn(2), rand([:U,:L])), | ||
| SymTridiagonal(randn(3), randn(2)), | ||
| sparse(randn(3,4)), | ||
| # Diagonal(randn(5)), # Diagonal fill! deprecated, see below | ||
| sparse(rand(3)), | ||
| # LowerTriangular(randn(3,3)), # AbstractTriangular fill! deprecated, see below | ||
| # UpperTriangular(randn(3,3)) # AbstractTriangular fill! deprecated, see below | ||
| ] | ||
| for A in exotic_arrays | ||
| fill!(A, 0) | ||
| for a in A | ||
| @test a == 0 | ||
| end | ||
| using Base.LinAlg: fillstored!, UnitLowerTriangular | ||
| @testset "fill! and fillstored!" begin | ||
| let # fillstored! | ||
| A = Tridiagonal(randn(2), randn(3), randn(2)) | ||
| @test fillstored!(A, 3) == Tridiagonal([3, 3.], [3, 3, 3.], [3, 3.]) | ||
|
||
| B = Bidiagonal(randn(3), randn(2), :U) | ||
| @test fillstored!(B, 2) == Bidiagonal([2.,2,2], [2,2.], :U) | ||
| S = SymTridiagonal(randn(3), randn(2)) | ||
| @test fillstored!(S, 1) == SymTridiagonal([1,1,1.], [1,1.]) | ||
| Ult = UnitLowerTriangular(randn(3,3)) | ||
| @test fillstored!(Ult, 3) == UnitLowerTriangular([1 0 0; 3 1 0; 3 3 1]) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perhaps the other triangular types are worth testing as well? |
||
| end | ||
| let # fill!(exotic, 0) | ||
| exotic_arrays = Any[Tridiagonal(randn(3), randn(4), randn(3)), | ||
| Bidiagonal(randn(3), randn(2), rand([:U,:L])), | ||
| SymTridiagonal(randn(3), randn(2)), | ||
| sparse(randn(3,4)), | ||
| # Diagonal(randn(5)), # Diagonal fill! deprecated, see below | ||
| sparse(rand(3)), | ||
| # LowerTriangular(randn(3,3)), # AbstractTriangular fill! deprecated, see below | ||
| # UpperTriangular(randn(3,3)) # AbstractTriangular fill! deprecated, see below | ||
| ] | ||
| for A in exotic_arrays | ||
| fill!(A, 0) | ||
| for a in A | ||
|
||
| @test a == 0 | ||
| end | ||
| # Diagonal and AbstractTriangular fill! were defined as fillslots!, | ||
| # not matching the general behavior of fill!, and so have been deprecated. | ||
| # In a future dev cycle, these fill! methods should probably be reintroduced | ||
| # with behavior matching that of fill! for other structured matrix types. | ||
| # In the interm, equivalently test fillslots! below | ||
| @test iszero(fillslots!(Diagonal(fill(1, 3)), 0)) | ||
| @test iszero(fillslots!(LowerTriangular(fill(1, 3, 3)), 0)) | ||
| @test iszero(fillslots!(UpperTriangular(fill(1, 3, 3)), 0)) | ||
| end | ||
| let # fill!(small, x) | ||
| val = randn() | ||
| b = Bidiagonal(randn(1,1), :U) | ||
| st = SymTridiagonal(randn(1,1)) | ||
| for x in (b, st) | ||
| @test Array(fill!(x, val)) == fill!(Array(x), val) | ||
| end | ||
| b = Bidiagonal(randn(2,2), :U) | ||
| st = SymTridiagonal(randn(3), randn(2)) | ||
| t = Tridiagonal(randn(3,3)) | ||
| for x in (b, t, st) | ||
| @test_throws ArgumentError fill!(x, val) | ||
| @test Array(fill!(x, 0)) == fill!(Array(x), 0) | ||
| end | ||
| # Diagonal and AbstractTriangular fill! were defined as fillstored!, | ||
| # not matching the general behavior of fill!, and so have been deprecated. | ||
| # In a future dev cycle, these fill! methods should probably be reintroduced | ||
| # with behavior matching that of fill! for other structured matrix types. | ||
| # In the interm, equivalently test fillstored! below | ||
| @test iszero(fillstored!(Diagonal(fill(1, 3)), 0)) | ||
| @test iszero(fillstored!(LowerTriangular(fill(1, 3, 3)), 0)) | ||
| @test iszero(fillstored!(UpperTriangular(fill(1, 3, 3)), 0)) | ||
| end | ||
| let # fill!(small, x) | ||
| val = randn() | ||
| b = Bidiagonal(randn(1,1), :U) | ||
| st = SymTridiagonal(randn(1,1)) | ||
| for x in (b, st) | ||
| @test Array(fill!(x, val)) == fill!(Array(x), val) | ||
| end | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perhaps simplify to the following? @test fill!(Bidiagonal(fill(0, 1, 1), :U), 2) == fill(2, 1, 1)
@test fill!(SymTridiagonal(fill(0, 1, 1)), 2) == fill(2, 1, 1) |
||
| b = Bidiagonal(randn(2,2), :U) | ||
| st = SymTridiagonal(randn(3), randn(2)) | ||
| t = Tridiagonal(randn(3,3)) | ||
| for x in (b, t, st) | ||
| @test_throws ArgumentError fill!(x, val) | ||
| @test Array(fill!(x, 0)) == fill!(Array(x), 0) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perhaps simplify to |
||
| end | ||
| end | ||
| end | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps nix the
x=, given that whatxrefers to is not user-visible?