Skip to content

Commit

Permalink
make mutable copies in reversecholcopy
Browse files Browse the repository at this point in the history
  • Loading branch information
dlfivefifty committed Jul 14, 2023
1 parent 047efcf commit eb675a9
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "MatrixFactorizations"
uuid = "a3b82374-2e81-5b9e-98ce-41277c0e4c87"
version = "2.0"
version = "2.0.1"

[deps]
ArrayLayouts = "4c555306-a7a7-4459-81d9-ec55ddd5c99a"
Expand Down
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
cholcopy, checkpositivedefinite, char_uplo, copymutable_oftype

import Base: getindex, setindex!, *, +, -, ==, <, <=, >,
>=, /, ^, \, transpose, showerror, reindex, checkbounds, @propagate_inbounds
Expand Down
10 changes: 4 additions & 6 deletions src/reversecholesky.jl
Original file line number Diff line number Diff line change
Expand Up @@ -139,24 +139,22 @@ end
reversecholcopy(A) = cholcopy(A)
function reversecholcopy(A::SymTridiagonal)
T = LinearAlgebra.choltype(A)
Symmetric(Bidiagonal(AbstractVector{T}(A.dv), AbstractVector{T}(A.ev), :U))
Symmetric(Bidiagonal(copymutable_oftype(A.dv, T), copymutable_oftype(A.ev, T), :U))
end

function reversecholcopy(A::Symmetric{<:Any,<:Tridiagonal})
T = LinearAlgebra.choltype(A)
if A.uplo == 'U'
Symmetric(Bidiagonal(AbstractVector{T}(parent(A).d), AbstractVector{T}(parent(A).du), :U))
Symmetric(Bidiagonal(copymutable_oftype(parent(A).d, T), copymutable_oftype(parent(A).du, T), :U))
else
Symmetric(Bidiagonal(AbstractVector{T}(parent(A).d), AbstractVector{T}(parent(A).dl), :L), :L)
Symmetric(Bidiagonal(copymutable_oftype(parent(A).d, T), copymutable_oftype(parent(A).dl, T), :L), :L)
end
end

_copyifsametype(::Type{T}, A::AbstractMatrix{T}) where T = copy(A)
_copyifsametype(_, A) = A

function reversecholcopy(A::Symmetric{<:Any,<:Bidiagonal})
T = LinearAlgebra.choltype(A)
B = _copyifsametype(T, AbstractMatrix{T}(parent(A)))
B = copymutable_oftype(parent(A), T)
Symmetric{T,typeof(B)}(B, A.uplo)
end

Expand Down
8 changes: 8 additions & 0 deletions test/test_reversecholesky.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Test, LinearAlgebra, Random, MatrixFactorizations
using LinearAlgebra: BlasComplex, BlasFloat, BlasReal, QRPivoted,
PosDefException, RankDeficientException, chkfullrank
using ArrayLayouts: Fill

function unary_ops_tests(a, ca, tol; n=size(a, 1))
@test inv(ca)*a Matrix(I, n, n)
Expand Down Expand Up @@ -412,4 +413,11 @@ end
@test reversecholesky(5).U[1,1] sqrt(5)
@test propertynames(R) == (:U, :L, :UL)
end

@testset "Lazy reversecholesky" begin
A = SymTridiagonal(Fill(2,10), Fill(1,9))
@test reversecholesky(A) == reversecholesky(SymTridiagonal(fill(2.0,10), fill(1.0,9))) ==
reversecholesky(Symmetric(Bidiagonal(Fill(2,10), Fill(1,9), :U))) ==
reversecholesky(Symmetric(Tridiagonal(Fill(3,9), Fill(2,10), Fill(1,9))))
end
end

2 comments on commit eb675a9

@dlfivefifty
Copy link
Member Author

Choose a reason for hiding this comment

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

@JuliaRegistrator
Copy link

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/88400

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:

git tag -a v2.0.1 -m "<description of version>" eb675a9e5c3f9bb3443c70c78fabdef5e2130859
git push origin v2.0.1

Please sign in to comment.