Skip to content

Commit

Permalink
Merge pull request #78 from fredrikekre/fe/push-etc
Browse files Browse the repository at this point in the history
Define some modifying functions for OffsetVector
  • Loading branch information
fredrikekre authored Jun 25, 2019
2 parents 07f33c3 + 344c1d8 commit 950bb88
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 8 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/Manifest.toml
4 changes: 0 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,3 @@ julia:

notifications:
email: false

after_success:
- julia -e 'Pkg.init(); run(`ln -s $(pwd()) $(Pkg.dir("OffsetArrays"))`); Pkg.pin("OffsetArrays"); Pkg.resolve()'
- julia -e 'using OffsetArrays; @assert isdefined(:OffsetArrays); @assert typeof(OffsetArrays) === Module'
5 changes: 1 addition & 4 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
name = "OffsetArrays"
uuid = "6fe1bfb0-de20-5000-8ca7-80f57d26f881"
version = "0.11.0"

[deps]
DelimitedFiles = "8bb1440f-4735-579b-a4ab-409b98df4dab"
version = "0.11.1"

[compat]
julia = "0.7, 1"
Expand Down
6 changes: 6 additions & 0 deletions src/OffsetArrays.jl
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,13 @@ Base.fill(x, inds::Tuple{UnitRange,Vararg{UnitRange}}) =
fill!(OffsetArray{typeof(x)}(undef, inds), x)
@inline Base.fill(x, ind1::UnitRange, inds::UnitRange...) = fill(x, (ind1, inds...))


### Some mutating functions defined only for OffsetVector ###

Base.resize!(A::OffsetVector, nl::Integer) = (resize!(A.parent, nl); A)
Base.push!(A::OffsetVector, x...) = (push!(A.parent, x...); A)
Base.pop!(A::OffsetVector) = pop!(A.parent)
Base.empty!(A::OffsetVector) = (empty!(A.parent); A)

### Low-level utilities ###

Expand Down
21 changes: 21 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -554,3 +554,24 @@ end
O2[1, 1] = x + 1 # just a sanity check
@test A[2, 2] == x + 1
end

@testset "mutating functions for OffsetVector" begin
# push!
o = OffsetVector(Int[], -1)
@test push!(o) === o
@test axes(o, 1) == 0:-1
@test push!(o, 1) === o
@test axes(o, 1) == 0:0
@test o[end] == 1
@test push!(o, 2, 3) === o
@test axes(o, 1) == 0:2
@test o[end-1:end] == [2, 3]
# pop!
o = OffsetVector([1, 2, 3], -1)
@test pop!(o) == 3
@test axes(o, 1) == 0:1
# empty!
o = OffsetVector([1, 2, 3], -1)
@test empty!(o) === o
@test axes(o, 1) == 0:-1
end

2 comments on commit 950bb88

@fredrikekre
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/1573

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 Julia TagBot is installed, or can be done manually through the github interface, or via:

git tag -a v0.11.1 -m "<description of version>" 950bb889753bfbdcd5313b6f1eb814b28f1a26c2
git push origin v0.11.1

Please sign in to comment.