Introduction

ResizingTools provide some tools to help you resize multi-dimensional arrays with a set of interface methods. Besides, there is a simple implementation of resizable dense array type named SimpleRDArray as a resizable alternative of Array.

Get started with SimpleRDArray

SimpleRDArray is a simple implementation of the resizable dense array, which can be created simply:

julia> using ResizingTools
julia> M = reshape(1:9, 3, 3)3×3 reshape(::UnitRange{Int64}, 3, 3) with eltype Int64: 1 4 7 2 5 8 3 6 9
julia> RM = SimpleRDArray(M)3×3 SimpleRDArray{Int64, 2}: 1 4 7 2 5 8 3 6 9
julia> M == RMtrue

Once a SimpleRDArray is created, you can almost do anything with which likes a normal Array with similar performance:

julia> using BenchmarkTools
julia> @benchmark $RM * $RMBenchmarkTools.Trial: 10000 samples with 986 evaluations. Range (min … max): 53.753 ns … 1.105 μs ┊ GC (min … max): 0.00% … 89.49% Time (median): 55.376 ns ┊ GC (median): 0.00% Time (mean ± σ): 60.848 ns ± 52.067 ns ┊ GC (mean ± σ): 4.30% ± 4.86% ▆█▆▃▁ ▁▁▁ ▁ █████▇████▇▇▇▇▇▇▆▆▆▆▇▆▆▆▅▃▅▃▅▃▃▁▃▃▃▃▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▅████ █ 53.8 ns Histogram: log(frequency) by time 118 ns < Memory estimate: 128 bytes, allocs estimate: 1.
julia> @benchmark $M * $MBenchmarkTools.Trial: 10000 samples with 988 evaluations. Range (min … max): 50.305 ns … 1.247 μs ┊ GC (min … max): 0.00% … 95.03% Time (median): 52.935 ns ┊ GC (median): 0.00% Time (mean ± σ): 58.675 ns ± 59.844 ns ┊ GC (mean ± σ): 5.17% ± 4.91% ▆█▆▂ ▁▁▁▁ ▁ ▆██████▇█▇██▇██▇▇▆▇▆▆▆▆▅▅▄▅▆▃▄▁▃▄▁▄▁▁▃▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▃▄████ █ 50.3 ns Histogram: log(frequency) by time 114 ns < Memory estimate: 128 bytes, allocs estimate: 1.
julia> RM * RM == M * Mtrue

Besides, a SimpleRDArray can be resized in many ways:

julia> resize!(RM, (4, 4)) # resize RM to 4 * 44×4 SimpleRDArray{Int64, 2}:
 1  4                7  140106548244496
 2  5                8  140106386814304
 3  6                9  140106548209072
 4  8  140106560798272  140106538781648
julia> RM[1:3,1:3] == Mtrue
julia> resize!(RM, 2, 3) # resize the 2nd dimension of RM to 34×3 SimpleRDArray{Int64, 2}: 1 4 7 2 5 8 3 6 9 4 8 140106560798272
julia> RM[4, :] .= 03-element view(::SimpleRDArray{Int64, 2}, 4, :) with eltype Int64: 0 0 0
julia> resize!(RM, 1, Bool[1, 1, 0, 1]) # delete at index 3 at 1st dimension3×3 SimpleRDArray{Int64, 2}: 1 4 7 2 5 8 0 0 0