-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Don't promote to `Matrix`. * Add StaticArrays tests, fix A / B::PDiagMat * Improve `StaticArray` support and add tests * Bump version * Fix merge errors * Bump version * Add tests with BandedMatrices * Fix test error with old Julia versions Co-authored-by: chriselrod <[email protected]>
- Loading branch information
1 parent
087d59f
commit 8727724
Showing
5 changed files
with
86 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
using BandedMatrices | ||
using StaticArrays | ||
|
||
@testset "Special matrix types" begin | ||
@testset "StaticArrays" begin | ||
# Full matrix | ||
S = (x -> x * x')(@SMatrix(randn(4, 7))) | ||
PDS = PDMat(S) | ||
@test PDS isa PDMat{Float64, <:SMatrix{4, 4, Float64}} | ||
@test isbits(PDS) | ||
|
||
# Diagonal matrix | ||
D = PDiagMat(@SVector(rand(4))) | ||
@test D isa PDiagMat{Float64, <:SVector{4, Float64}} | ||
|
||
x = @SVector rand(4) | ||
X = @SMatrix rand(10, 4) | ||
Y = @SMatrix rand(4, 10) | ||
|
||
for A in (PDS, D) | ||
@test A * x isa SVector{4, Float64} | ||
@test A * x ≈ Matrix(A) * Vector(x) | ||
|
||
@test A * Y isa SMatrix{4, 10, Float64} | ||
@test A * Y ≈ Matrix(A) * Matrix(Y) | ||
|
||
@test X / A isa SMatrix{10, 4, Float64} | ||
@test X / A ≈ Matrix(X) / Matrix(A) | ||
|
||
@test A \ x isa SVector{4, Float64} | ||
@test A \ x ≈ Matrix(A) \ Vector(x) | ||
|
||
@test A \ Y isa SMatrix{4, 10, Float64} | ||
@test A \ Y ≈ Matrix(A) \ Matrix(Y) | ||
|
||
@test X_A_Xt(A, X) isa SMatrix{10, 10, Float64} | ||
@test X_A_Xt(A, X) ≈ Matrix(X) * Matrix(A) * Matrix(X)' | ||
|
||
@test X_invA_Xt(A, X) isa SMatrix{10, 10, Float64} | ||
@test X_invA_Xt(A, X) ≈ Matrix(X) * (Matrix(A) \ Matrix(X)') | ||
|
||
@test Xt_A_X(A, Y) isa SMatrix{10, 10, Float64} | ||
@test Xt_A_X(A, Y) ≈ Matrix(Y)' * Matrix(A) * Matrix(Y) | ||
|
||
@test Xt_invA_X(A, Y) isa SMatrix{10, 10, Float64} | ||
@test Xt_invA_X(A, Y) ≈ Matrix(Y)' * (Matrix(A) \ Matrix(Y)) | ||
end | ||
end | ||
|
||
@testset "BandedMatrices" begin | ||
# Full matrix | ||
A = Symmetric(BandedMatrix(Eye(5), (1, 1))) | ||
P = PDMat(A) | ||
@test P isa PDMat{Float64, <:BandedMatrix{Float64}} | ||
|
||
x = rand(5) | ||
X = rand(2, 5) | ||
Y = rand(5, 2) | ||
@test P * x ≈ A * x | ||
@test P * Y ≈ A * Y | ||
# Right division with Cholesky requires https://github.com/JuliaLang/julia/pull/32594 | ||
if VERSION >= v"1.3.0-DEV.562" | ||
@test X / P ≈ X / A | ||
end | ||
@test P \ x ≈ A \ x | ||
@test P \ Y ≈ A \ Y | ||
@test X_A_Xt(P, X) ≈ X * A * X' | ||
@test X_invA_Xt(P, X) ≈ X * (A \ X') | ||
@test Xt_A_X(P, Y) ≈ Y' * A * Y | ||
@test Xt_invA_X(P, Y) ≈ Y' * (A \ Y) | ||
end | ||
end |
8727724
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.
@JuliaRegistrator register
8727724
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.
Registration pull request created: JuliaRegistries/General/56435
After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.
This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via: