Skip to content

Commit

Permalink
specialize reverse for AbstractFill (#201)
Browse files Browse the repository at this point in the history
* specialize reverse

* Add bounds checks

* version bump to v0.13.6

* skip bounds-checking with inbounds

* Add test for bounds check

* remove inbounds check
  • Loading branch information
jishnub authored Dec 8, 2022
1 parent 0f12596 commit 4845062
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
2 changes: 1 addition & 1 deletion src/FillArrays.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
7 changes: 7 additions & 0 deletions src/fillalgebra.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ function permutedims(B::AbstractFill, perm)
fillsimilar(B, dimsP)
end

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

## Algebraic identities


Expand Down
10 changes: 10 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1113,6 +1113,16 @@ 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)
@test_throws BoundsError reverse(A, 1, 10)
end

@testset "setindex!/fill!" begin
F = Fill(1,10)
@test (F[1] = 1) == 1
Expand Down

3 comments on commit 4845062

@dlfivefifty
Copy link
Member

Choose a reason for hiding this comment

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

@dlfivefifty
Copy link
Member

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

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 v0.13.6 -m "<description of version>" 48450628942aceb98db17ba468cf4c3dcbc07749
git push origin v0.13.6

Please sign in to comment.