Skip to content

Commit c684abe

Browse files
authored
Support Julia v1.12 (#72)
* Support Julia v1.12 * Fix some tests * Update runtests.jl * avoid Array(::BunchKaufman) * reimplement cholcopy * tests pass
1 parent 754238b commit c684abe

File tree

7 files changed

+24
-9
lines changed

7 files changed

+24
-9
lines changed

src/MatrixFactorizations.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import LinearAlgebra: cholesky, cholesky!, norm, diag, eigvals!, eigvals, eigen!
1010
chkstride1, kron, lmul!, rmul!, factorize, StructuredMatrixStyle, det, logabsdet,
1111
AbstractQ, _zeros, _cut_B, _ret_size, require_one_based_indexing, checksquare,
1212
checknonsingular, ipiv2perm, copytri!, issuccess, RealHermSymComplexHerm,
13-
cholcopy, checkpositivedefinite, char_uplo, copymutable_oftype
13+
cholcopy, checkpositivedefinite, char_uplo, copymutable_oftype, copy_similar, choltype
1414

1515

1616
using LinearAlgebra: TransposeFactorization, AdjointFactorization

src/reversecholesky.jl

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,12 @@ function reversecholesky!(A::AbstractMatrix, ::NoPivot = NoPivot(); check::Bool
136136
end
137137
end
138138

139-
reversecholcopy(A) = cholcopy(A)
139+
# can't use chol_copy in 1.12 since it makes BigFloat fill with #undef
140+
reversecholcopy(A::Symmetric, S=choltype(A)) = Symmetric(copy_similar(A, S), LinearAlgebra.sym_uplo(A.uplo))
141+
reversecholcopy(A::Hermitian, S=choltype(A)) = Hermitian(copy_similar(A, S), LinearAlgebra.sym_uplo(A.uplo))
142+
reversecholcopy(A::Diagonal, S=choltype(A)) = Diagonal(copy_similar(diag(A), S))
143+
reversecholcopy(A::RealHermSymComplexHerm{<:Any,<:Diagonal}, S=choltype(A)) = Diagonal(copy_similar(diag(A), S))
144+
reversecholcopy(A, S=choltype(A)) = copy_similar(A, S)
140145
function reversecholcopy(A::SymTridiagonal)
141146
T = LinearAlgebra.choltype(A)
142147
Symmetric(Bidiagonal(copymutable_oftype(A.dv, T), copymutable_oftype(A.ev, T), :U))

test/runtests.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,15 @@ using MatrixFactorizations, LinearAlgebra, Random, ArrayLayouts, Test
22
using LinearAlgebra: BlasComplex, BlasFloat, BlasReal, rmul!, lmul!, require_one_based_indexing, checksquare
33
using MatrixFactorizations: QRCompactWYQLayout, AbstractQtype
44

5+
if VERSION < v"1.12-"
6+
const FieldError = ErrorException
7+
end
8+
59
struct MyMatrix <: LayoutMatrix{Float64}
610
A::Matrix{Float64}
711
end
812

13+
Base.elsize(::Type{MyMatrix}) = sizeof(Float64)
914
Base.getindex(A::MyMatrix, k::Int, j::Int) = A.A[k,j]
1015
Base.setindex!(A::MyMatrix, v, k::Int, j::Int) = setindex!(A.A, v, k, j)
1116
Base.size(A::MyMatrix) = size(A.A)
@@ -17,6 +22,7 @@ struct MyVector <: LayoutVector{Float64}
1722
A::Vector{Float64}
1823
end
1924

25+
Base.elsize(::Type{MyVector}) = sizeof(Float64)
2026
Base.getindex(A::MyVector, k::Int) = A.A[k]
2127
Base.setindex!(A::MyVector, v, k::Int) = setindex!(A.A, v, k)
2228
Base.size(A::MyVector) = size(A.A)

test/test_ql.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ using MatrixFactorizations, ArrayLayouts, Test
5959
qla = @inferred ql(a)
6060
@inferred ql(a)
6161
q, l = qla.Q, qla.L
62-
@test_throws ErrorException qla.Z
62+
@test_throws FieldError qla.Z
6363
@test q'*squareQ(q) Matrix(I, a_1, a_1)
6464
@test q*squareQ(q)' Matrix(I, a_1, a_1)
6565
@test q'*Matrix(1.0I, a_1, a_1)' squareQ(q)'
@@ -84,7 +84,7 @@ using MatrixFactorizations, ArrayLayouts, Test
8484
qla = @inferred ql(a[:, 1:n1], Val(false))
8585
@inferred ql(a[:, 1:n1], Val(false))
8686
q,l = qla.Q, qla.L
87-
@test_throws ErrorException qla.Z
87+
@test_throws FieldError qla.Z
8888
@test q'*squareQ(q) Matrix(I, a_1, a_1)
8989
@test q'*rectangularQ(q) Matrix(I, a_1, n1)
9090
@test q*l a[:, 1:n1]

test/test_qr.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ rectangularQ(Q::LinearAlgebra.AbstractQ) = Matrix(Q) # convert(Array, Q)
4747
qra = @inferred qrunblocked(a)
4848
@inferred qrunblocked(a)
4949
q, r = qra.Q, qra.R
50-
@test_throws ErrorException qra.Z
50+
@test_throws FieldError qra.Z
5151
@test q[1,1] Matrix(q)[1,1]
5252
@test q[1:2,1:2] Matrix(q)[1:2,1:2]
5353
@test q'*squareQ(q) Matrix(I, a_1, a_1)
@@ -74,7 +74,7 @@ rectangularQ(Q::LinearAlgebra.AbstractQ) = Matrix(Q) # convert(Array, Q)
7474
qra = @inferred qrunblocked(a[:, 1:n1], Val(false))
7575
@inferred qrunblocked(a[:, 1:n1], Val(false))
7676
q,r = qra.Q, qra.R
77-
@test_throws ErrorException qra.Z
77+
@test_throws FieldError qra.Z
7878
@test q[1,1] Matrix(q)[1,1]
7979
@test q[1:2,1:2] Matrix(q)[1:2,1:2]
8080
@test q'*squareQ(q) Matrix(I, a_1, a_1)

test/test_reversecholesky.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ function unary_ops_tests(a, ca, tol; n=size(a, 1))
1616
@test logabsdet_ca[1] logabsdet_a[1]
1717
@test logabsdet_ca[2] logabsdet_a[2]
1818
@test isposdef(ca)
19-
@test_throws ErrorException ca.Z
19+
@test_throws FieldError ca.Z
2020
@test size(ca) == size(a)
2121
@test Array(copy(ca)) a
2222
end
@@ -92,7 +92,7 @@ end
9292
if eltya != Int
9393
@test Factorization{eltya}(capd) === capd
9494
if eltya <: Real
95-
@test Array(Factorization{complex(eltya)}(capd)) Array(factorize(complex(apd)))
95+
@test Array(Factorization{complex(eltya)}(capd)) apd
9696
@test eltype(Factorization{complex(eltya)}(capd)) == complex(eltya)
9797
end
9898
end

test/test_rq.jl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ using MatrixFactorizations: RQPackedQ
2121
using MatrixFactorizations: rq, rq!
2222
const Our=MatrixFactorizations
2323

24+
if !isdefined(Base, :FieldError)
25+
const FieldError = ErrorException
26+
end
27+
2428
@testset "RQ" begin
2529
@testset "LAPACK $elty" for elty in (Float32,Float64,ComplexF32,ComplexF64)
2630
@testset "Compare with LAPACK (square $elty)" begin
@@ -91,7 +95,7 @@ const Our=MatrixFactorizations
9195
rqa = @inferred rq(a)
9296
@inferred rq(a)
9397
q, r = rqa.Q, rqa.R
94-
@test_throws ErrorException rqa.Z
98+
@test_throws FieldError rqa.Z
9599
@test q[1,1] Matrix(q)[1,1]
96100
@test q[1:2,1:2] Matrix(q)[1:2,1:2]
97101
@test q'*q Matrix(I, a_1, a_1)

0 commit comments

Comments
 (0)