Skip to content

Commit 0075f99

Browse files
committed
Added resize function for OffsetVector
1 parent e814c7a commit 0075f99

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
@@ -147,6 +147,8 @@ Base.fill(x, inds::Tuple{UnitRange,Vararg{UnitRange}}) =
147147
fill!(OffsetArray{typeof(x)}(undef, inds), x)
148148
@inline Base.fill(x, ind1::UnitRange, inds::UnitRange...) = fill(x, (ind1, inds...))
149149

150+
Base.resize!(A::OffsetVector, nl::Integer) = (resize!(A.parent, nl); A)
151+
150152
### Low-level utilities ###
151153

152154
# Computing a shifted index (subtracting the offset)

test/runtests.jl

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

379+
@testset "Resizing OffsetVectors" begin
380+
local a = OffsetVector(rand(5),-3)
381+
axes(a,1) == -2:2
382+
length(a) == 5
383+
resize!(a,3)
384+
length(a) == 3
385+
axes(a,1) == -2:0
386+
@test_throws ArgumentError resize!(a,-3)
387+
end
388+
379389
@testset "OffsetVector constructors" begin
380390
local v = rand(5)
381391
@test OffsetVector(v, -2) == OffsetArray(v, -2)

0 commit comments

Comments
 (0)