From 7e739b656351117573fc9466b14b2cfecce1c1c0 Mon Sep 17 00:00:00 2001 From: Daniel Karrasch Date: Tue, 14 Dec 2021 21:35:24 +0100 Subject: [PATCH] compat changes for Julia v1.8 (#6) --- Project.toml | 2 +- src/NiceLinAlg.jl | 20 ++++++++++++++------ test/runtests.jl | 11 +++++++++-- 3 files changed, 24 insertions(+), 9 deletions(-) diff --git a/Project.toml b/Project.toml index 8798788..377903e 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "NiceNumbers" uuid = "fd372b59-0929-42ec-9982-92b7b2350263" authors = ["Felix Kastner "] -version = "0.2.2" +version = "0.2.3" [deps] LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" diff --git a/src/NiceLinAlg.jl b/src/NiceLinAlg.jl index 411a029..a7cae85 100644 --- a/src/NiceLinAlg.jl +++ b/src/NiceLinAlg.jl @@ -2,9 +2,17 @@ using LinearAlgebra: Hermitian, Symmetric, UpperTriangular, LowerTriangular using LinearAlgebra: _chol!, Cholesky, checkpositivedefinite import LinearAlgebra: cholesky! - -function cholesky!(A::Union{Hermitian{NiceNumber,S}, Symmetric{NiceNumber,S}} where S, ::Val{false}=Val(false); check::Bool = true) - C, info = _chol!(A.data, A.uplo == 'U' ? UpperTriangular : LowerTriangular) - check && checkpositivedefinite(info) - return Cholesky(C.data, A.uplo, info) -end \ No newline at end of file +@static if VERSION < v"1.8.0-DEV.1139" + function cholesky!(A::Union{Hermitian{NiceNumber}, Symmetric{NiceNumber}}, ::Val{false}=Val(false); check::Bool = true) + C, info = _chol!(A.data, A.uplo == 'U' ? UpperTriangular : LowerTriangular) + check && checkpositivedefinite(info) + return Cholesky(C.data, A.uplo, info) + end +else + using LinearAlgebra: NoPivot + function cholesky!(A::Union{Hermitian{NiceNumber}, Symmetric{NiceNumber}}, ::NoPivot=NoPivot(); check::Bool = true) + C, info = _chol!(A.data, A.uplo == 'U' ? UpperTriangular : LowerTriangular) + check && checkpositivedefinite(info) + return Cholesky(C.data, A.uplo, info) + end +end diff --git a/test/runtests.jl b/test/runtests.jl index 1e84117..80dd59d 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,6 +1,13 @@ using NiceNumbers using Test, LinearAlgebra +@static if VERSION < v"1.7" + nopivot = Val(false) + pivot = Val(true) +else + nopivot = NoPivot() + pivot = RowMaximum() +end @testset "NiceNumbers" begin @testset "Constructors" begin @@ -136,12 +143,12 @@ using Test, LinearAlgebra @testset "LU" begin @nice L = [1 0 0;im 1 0; 1/2 -3im 1] @nice U = [1 1 1;0 1 1; 0 0 1] - LUL, LUU = lu(L*U, Val(false)) + LUL, LUU = lu(L*U, nopivot) @test LUL == L @test LUU == U @nice A = [2 2 0;2 2 1; 2 3 5] - L, U, p = lu(A, Val(true)) + L, U, p = lu(A, pivot) @test L == @nice [1 0 0;1 1 0;1 0 1] @test U == @nice [2 2 0;0 1 5;0 0 1] @test p == [1,3,2]