Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion src/MatrixFactorizations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import LinearAlgebra: cholesky, cholesky!, norm, diag, eigvals!, eigvals, eigen!
chkstride1, kron, lmul!, rmul!, factorize, StructuredMatrixStyle, det, logabsdet,
AbstractQ, _zeros, _cut_B, _ret_size, require_one_based_indexing, checksquare,
checknonsingular, ipiv2perm, copytri!, issuccess, RealHermSymComplexHerm,
cholcopy, checkpositivedefinite, char_uplo, copymutable_oftype
cholcopy, checkpositivedefinite, char_uplo, copymutable_oftype, copy_similar, choltype


using LinearAlgebra: TransposeFactorization, AdjointFactorization
Expand Down
7 changes: 6 additions & 1 deletion src/reversecholesky.jl
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,12 @@ function reversecholesky!(A::AbstractMatrix, ::NoPivot = NoPivot(); check::Bool
end
end

reversecholcopy(A) = cholcopy(A)
# can't use chol_copy in 1.12 since it makes BigFloat fill with #undef
reversecholcopy(A::Symmetric, S=choltype(A)) = Symmetric(copy_similar(A, S), LinearAlgebra.sym_uplo(A.uplo))
reversecholcopy(A::Hermitian, S=choltype(A)) = Hermitian(copy_similar(A, S), LinearAlgebra.sym_uplo(A.uplo))
reversecholcopy(A::Diagonal, S=choltype(A)) = Diagonal(copy_similar(diag(A), S))
reversecholcopy(A::RealHermSymComplexHerm{<:Any,<:Diagonal}, S=choltype(A)) = Diagonal(copy_similar(diag(A), S))
reversecholcopy(A, S=choltype(A)) = copy_similar(A, S)
function reversecholcopy(A::SymTridiagonal)
T = LinearAlgebra.choltype(A)
Symmetric(Bidiagonal(copymutable_oftype(A.dv, T), copymutable_oftype(A.ev, T), :U))
Expand Down
6 changes: 6 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,15 @@ using MatrixFactorizations, LinearAlgebra, Random, ArrayLayouts, Test
using LinearAlgebra: BlasComplex, BlasFloat, BlasReal, rmul!, lmul!, require_one_based_indexing, checksquare
using MatrixFactorizations: QRCompactWYQLayout, AbstractQtype

if VERSION < v"1.12-"
const FieldError = ErrorException
end

struct MyMatrix <: LayoutMatrix{Float64}
A::Matrix{Float64}
end

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

Base.elsize(::Type{MyVector}) = sizeof(Float64)
Base.getindex(A::MyVector, k::Int) = A.A[k]
Base.setindex!(A::MyVector, v, k::Int) = setindex!(A.A, v, k)
Base.size(A::MyVector) = size(A.A)
Expand Down
4 changes: 2 additions & 2 deletions test/test_ql.jl
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ using MatrixFactorizations, ArrayLayouts, Test
qla = @inferred ql(a)
@inferred ql(a)
q, l = qla.Q, qla.L
@test_throws ErrorException qla.Z
@test_throws FieldError qla.Z
@test q'*squareQ(q) ≈ Matrix(I, a_1, a_1)
@test q*squareQ(q)' ≈ Matrix(I, a_1, a_1)
@test q'*Matrix(1.0I, a_1, a_1)' ≈ squareQ(q)'
Expand All @@ -84,7 +84,7 @@ using MatrixFactorizations, ArrayLayouts, Test
qla = @inferred ql(a[:, 1:n1], Val(false))
@inferred ql(a[:, 1:n1], Val(false))
q,l = qla.Q, qla.L
@test_throws ErrorException qla.Z
@test_throws FieldError qla.Z
@test q'*squareQ(q) ≈ Matrix(I, a_1, a_1)
@test q'*rectangularQ(q) ≈ Matrix(I, a_1, n1)
@test q*l ≈ a[:, 1:n1]
Expand Down
4 changes: 2 additions & 2 deletions test/test_qr.jl
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ rectangularQ(Q::LinearAlgebra.AbstractQ) = Matrix(Q) # convert(Array, Q)
qra = @inferred qrunblocked(a)
@inferred qrunblocked(a)
q, r = qra.Q, qra.R
@test_throws ErrorException qra.Z
@test_throws FieldError qra.Z
@test q[1,1] ≈ Matrix(q)[1,1]
@test q[1:2,1:2] ≈ Matrix(q)[1:2,1:2]
@test q'*squareQ(q) ≈ Matrix(I, a_1, a_1)
Expand All @@ -74,7 +74,7 @@ rectangularQ(Q::LinearAlgebra.AbstractQ) = Matrix(Q) # convert(Array, Q)
qra = @inferred qrunblocked(a[:, 1:n1], Val(false))
@inferred qrunblocked(a[:, 1:n1], Val(false))
q,r = qra.Q, qra.R
@test_throws ErrorException qra.Z
@test_throws FieldError qra.Z
@test q[1,1] ≈ Matrix(q)[1,1]
@test q[1:2,1:2] ≈ Matrix(q)[1:2,1:2]
@test q'*squareQ(q) ≈ Matrix(I, a_1, a_1)
Expand Down
4 changes: 2 additions & 2 deletions test/test_reversecholesky.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ function unary_ops_tests(a, ca, tol; n=size(a, 1))
@test logabsdet_ca[1] ≈ logabsdet_a[1]
@test logabsdet_ca[2] ≈ logabsdet_a[2]
@test isposdef(ca)
@test_throws ErrorException ca.Z
@test_throws FieldError ca.Z
@test size(ca) == size(a)
@test Array(copy(ca)) ≈ a
end
Expand Down Expand Up @@ -92,7 +92,7 @@ end
if eltya != Int
@test Factorization{eltya}(capd) === capd
if eltya <: Real
@test Array(Factorization{complex(eltya)}(capd)) ≈ Array(factorize(complex(apd)))
@test Array(Factorization{complex(eltya)}(capd)) ≈ apd
@test eltype(Factorization{complex(eltya)}(capd)) == complex(eltya)
end
end
Expand Down
6 changes: 5 additions & 1 deletion test/test_rq.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ using MatrixFactorizations: RQPackedQ
using MatrixFactorizations: rq, rq!
const Our=MatrixFactorizations

if !isdefined(Base, :FieldError)
const FieldError = ErrorException
end

@testset "RQ" begin
@testset "LAPACK $elty" for elty in (Float32,Float64,ComplexF32,ComplexF64)
@testset "Compare with LAPACK (square $elty)" begin
Expand Down Expand Up @@ -91,7 +95,7 @@ const Our=MatrixFactorizations
rqa = @inferred rq(a)
@inferred rq(a)
q, r = rqa.Q, rqa.R
@test_throws ErrorException rqa.Z
@test_throws FieldError rqa.Z
@test q[1,1] ≈ Matrix(q)[1,1]
@test q[1:2,1:2] ≈ Matrix(q)[1:2,1:2]
@test q'*q ≈ Matrix(I, a_1, a_1)
Expand Down
Loading