Skip to content

Commit 2436d83

Browse files
authored
Merge pull request #55 from laborg/master
Added resize! function for OffsetVector
2 parents 98275a8 + 0075f99 commit 2436d83

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

src/OffsetArrays.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,8 @@ Base.fill(x, inds::Tuple{UnitRange,Vararg{UnitRange}}) =
151151
fill!(OffsetArray{typeof(x)}(undef, inds), x)
152152
@inline Base.fill(x, ind1::UnitRange, inds::UnitRange...) = fill(x, (ind1, inds...))
153153

154+
Base.resize!(A::OffsetVector, nl::Integer) = (resize!(A.parent, nl); A)
155+
154156
### Low-level utilities ###
155157

156158
# Computing a shifted index (subtracting the offset)

test/runtests.jl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,16 @@ a = OffsetArray([1 2; 3 4], -1:0, 5:6)
384384
a = OffsetArray(reshape([1]))
385385
@test summary(a) == "0-dimensional OffsetArray(::Array{$(Int),0}) with eltype $(Int)"
386386

387+
@testset "Resizing OffsetVectors" begin
388+
local a = OffsetVector(rand(5),-3)
389+
axes(a,1) == -2:2
390+
length(a) == 5
391+
resize!(a,3)
392+
length(a) == 3
393+
axes(a,1) == -2:0
394+
@test_throws ArgumentError resize!(a,-3)
395+
end
396+
387397
@testset "OffsetVector constructors" begin
388398
local v = rand(5)
389399
@test OffsetVector(v, -2) == OffsetArray(v, -2)

0 commit comments

Comments
 (0)