From 070aa3c7ddfd165f38f7fae5c4c192c5af8525ea Mon Sep 17 00:00:00 2001 From: Jishnu Bhattacharya Date: Thu, 8 Dec 2022 00:31:36 +0400 Subject: [PATCH 1/6] specialize reverse --- src/FillArrays.jl | 2 +- src/fillalgebra.jl | 3 +++ test/runtests.jl | 9 +++++++++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/FillArrays.jl b/src/FillArrays.jl index 22320d3c..759708de 100644 --- a/src/FillArrays.jl +++ b/src/FillArrays.jl @@ -6,7 +6,7 @@ import Base: size, getindex, setindex!, IndexStyle, checkbounds, convert, +, -, *, /, \, diff, sum, cumsum, maximum, minimum, sort, sort!, any, all, axes, isone, iterate, unique, allunique, permutedims, inv, copy, vec, setindex!, count, ==, reshape, _throw_dmrs, map, zero, - show, view, in, mapreduce, one + show, view, in, mapreduce, one, reverse import LinearAlgebra: rank, svdvals!, tril, triu, tril!, triu!, diag, transpose, adjoint, fill!, dot, norm2, norm1, normInf, normMinusInf, normp, lmul!, rmul!, diagzero, AbstractTriangular, AdjointAbsVec, TransposeAbsVec, diff --git a/src/fillalgebra.jl b/src/fillalgebra.jl index 86a70a99..07ace4a9 100644 --- a/src/fillalgebra.jl +++ b/src/fillalgebra.jl @@ -26,6 +26,9 @@ function permutedims(B::AbstractFill, perm) fillsimilar(B, dimsP) end +reverse(A::AbstractFill, start::Integer=firstindex(A), stop::Integer=lastindex(A)) = A +reverse(A::AbstractFill; dims=:) = A + ## Algebraic identities diff --git a/test/runtests.jl b/test/runtests.jl index b690a390..d30c17bc 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1113,6 +1113,15 @@ end @test permutedims(Fill(2.0,2,4,5), [3,2,1]) ≡ Fill(2.0,5,4,2) end +@testset "reverse" begin + for A in (Zeros{Int}(6), Ones(2,3), Fill("abc", 2, 3, 4)) + @test reverse(A) == reverse(Array(A)) + @test reverse(A, dims=1) == reverse(Array(A), dims=1) + end + A = Ones{Int}(6) + @test reverse(A, 2, 4) == reverse(Array(A), 2, 4) +end + @testset "setindex!/fill!" begin F = Fill(1,10) @test (F[1] = 1) == 1 From 28e9cc10717643d00fc869c966249f8ff5ee8b71 Mon Sep 17 00:00:00 2001 From: Jishnu Bhattacharya Date: Thu, 8 Dec 2022 00:36:18 +0400 Subject: [PATCH 2/6] Add bounds checks --- src/fillalgebra.jl | 6 +++++- test/runtests.jl | 1 + 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/fillalgebra.jl b/src/fillalgebra.jl index 07ace4a9..e43d2411 100644 --- a/src/fillalgebra.jl +++ b/src/fillalgebra.jl @@ -26,7 +26,11 @@ function permutedims(B::AbstractFill, perm) fillsimilar(B, dimsP) end -reverse(A::AbstractFill, start::Integer=firstindex(A), stop::Integer=lastindex(A)) = A +function reverse(A::AbstractFill, start::Integer=firstindex(A), stop::Integer=lastindex(A)) + checkbounds(A, start) + checkbounds(A, stop) + A +end reverse(A::AbstractFill; dims=:) = A ## Algebraic identities diff --git a/test/runtests.jl b/test/runtests.jl index d30c17bc..2ec0d025 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1120,6 +1120,7 @@ end end A = Ones{Int}(6) @test reverse(A, 2, 4) == reverse(Array(A), 2, 4) + @test_throws BoundsError reverse(A, 1, 10) end @testset "setindex!/fill!" begin From fc43c4abcbefa1d6f39f20e75c07a2cfc4fdcd36 Mon Sep 17 00:00:00 2001 From: Jishnu Bhattacharya Date: Thu, 8 Dec 2022 00:37:03 +0400 Subject: [PATCH 3/6] version bump to v0.13.6 --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index de927e29..245580c7 100644 --- a/Project.toml +++ b/Project.toml @@ -1,6 +1,6 @@ name = "FillArrays" uuid = "1a297f60-69ca-5386-bcde-b61e274b549b" -version = "0.13.5" +version = "0.13.6" [deps] LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" From bae95f7e38c74cb7beae0360c625057b43d8db14 Mon Sep 17 00:00:00 2001 From: Jishnu Bhattacharya Date: Thu, 8 Dec 2022 00:58:30 +0400 Subject: [PATCH 4/6] skip bounds-checking with inbounds --- src/fillalgebra.jl | 6 +++--- test/runtests.jl | 2 ++ 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/fillalgebra.jl b/src/fillalgebra.jl index e43d2411..adb393e5 100644 --- a/src/fillalgebra.jl +++ b/src/fillalgebra.jl @@ -26,9 +26,9 @@ function permutedims(B::AbstractFill, perm) fillsimilar(B, dimsP) end -function reverse(A::AbstractFill, start::Integer=firstindex(A), stop::Integer=lastindex(A)) - checkbounds(A, start) - checkbounds(A, stop) +Base.@propagate_inbounds function reverse(A::AbstractFill, start::Integer, stop::Integer=lastindex(A)) + @boundscheck checkbounds(A, start) + @boundscheck checkbounds(A, stop) A end reverse(A::AbstractFill; dims=:) = A diff --git a/test/runtests.jl b/test/runtests.jl index 2ec0d025..d36eb7be 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1120,6 +1120,8 @@ end end A = Ones{Int}(6) @test reverse(A, 2, 4) == reverse(Array(A), 2, 4) + #test inlining + @test (A -> @inbounds reverse(A, 2, 10))(A) == A @test_throws BoundsError reverse(A, 1, 10) end From 03fb80c9ebb01c9a35ad18a94e469882c6ee0707 Mon Sep 17 00:00:00 2001 From: Jishnu Bhattacharya Date: Thu, 8 Dec 2022 00:58:50 +0400 Subject: [PATCH 5/6] Add test for bounds check --- test/runtests.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/runtests.jl b/test/runtests.jl index d36eb7be..f14268db 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1120,7 +1120,7 @@ end end A = Ones{Int}(6) @test reverse(A, 2, 4) == reverse(Array(A), 2, 4) - #test inlining + #test bounds-cheking elision @test (A -> @inbounds reverse(A, 2, 10))(A) == A @test_throws BoundsError reverse(A, 1, 10) end From 982011b998042ff4758319e5f8707ff3ca02fb36 Mon Sep 17 00:00:00 2001 From: Jishnu Bhattacharya Date: Thu, 8 Dec 2022 08:54:40 +0400 Subject: [PATCH 6/6] remove inbounds check --- test/runtests.jl | 2 -- 1 file changed, 2 deletions(-) diff --git a/test/runtests.jl b/test/runtests.jl index f14268db..2ec0d025 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1120,8 +1120,6 @@ end end A = Ones{Int}(6) @test reverse(A, 2, 4) == reverse(Array(A), 2, 4) - #test bounds-cheking elision - @test (A -> @inbounds reverse(A, 2, 10))(A) == A @test_throws BoundsError reverse(A, 1, 10) end