From c7c34aa3c1ebb5ca35e335ed4d420596279469ca Mon Sep 17 00:00:00 2001 From: Jishnu Bhattacharya Date: Tue, 12 Dec 2023 18:02:23 +0530 Subject: [PATCH] Specalize `istriu`/`istril` (#326) * Specalize isdiag and istriu/istril * Remove isdiag specialization --- Project.toml | 2 +- src/fillalgebra.jl | 8 ++++++++ test/runtests.jl | 13 +++++++++++++ 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index fa5e2996..06ba0f13 100644 --- a/Project.toml +++ b/Project.toml @@ -1,6 +1,6 @@ name = "FillArrays" uuid = "1a297f60-69ca-5386-bcde-b61e274b549b" -version = "1.9.3" +version = "1.10.0" [deps] LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" diff --git a/src/fillalgebra.jl b/src/fillalgebra.jl index c4331f9d..0fef9a97 100644 --- a/src/fillalgebra.jl +++ b/src/fillalgebra.jl @@ -516,3 +516,11 @@ function kron(f::AbstractFillVecOrMat, g::AbstractFillVecOrMat) sz = _kronsize(f, g) return _kron(f, g, sz) end + +# bandedness +function LinearAlgebra.istriu(A::AbstractFillMatrix, k::Integer = 0) + iszero(A) || k <= -(size(A,1)-1) +end +function LinearAlgebra.istril(A::AbstractFillMatrix, k::Integer = 0) + iszero(A) || k >= size(A,2)-1 +end diff --git a/test/runtests.jl b/test/runtests.jl index 2e132622..0de16a98 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -2370,3 +2370,16 @@ end @test a.value == first(diag) end end + +@testset "isbanded/isdiag" begin + @testset for A in Any[Zeros(2,3), Zeros(0,1), Zeros(1,1), Zeros(1,2), + Ones(0,1), Ones(1,1), Ones(3,4), Ones(0,4), Ones(7,0), Ones(7,2), Ones(2,7), + Fill(3, 0,1), Fill(3, 1,1), Fill(3, 2,4), Fill(0, 3, 4), Fill(2, 0, 4), Fill(2, 6, 0), Fill(0, 8, 8)] + B = Array(A) + @test isdiag(A) == isdiag(B) + for k in -5:5 + @test istriu(A, k) == istriu(B, k) + @test istril(A, k) == istril(B, k) + end + end +end