https://github.com/wangl-cc/resizingtools.jl
Framework to create resizable arrays.
https://github.com/wangl-cc/resizingtools.jl
array julia resize
Last synced: 9 days ago
JSON representation
Framework to create resizable arrays.
- Host: GitHub
- URL: https://github.com/wangl-cc/resizingtools.jl
- Owner: wangl-cc
- License: mit
- Created: 2021-09-11T11:50:37.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2022-03-06T09:27:04.000Z (over 4 years ago)
- Last Synced: 2025-02-20T22:29:04.753Z (over 1 year ago)
- Topics: array, julia, resize
- Language: Julia
- Homepage:
- Size: 912 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ResizingTools.jl
[](https://github.com/wangl-cc/ResizingTools.jl/actions/workflows/ci.yml)
[](https://codecov.io/gh/wangl-cc/ResizingTools.jl)
[](https://github.com/wangl-cc/ResizingTools.jl/blob/master/LICENSE)
[](https://wangl-cc.github.io/ResizingTools.jl/dev/)
[](https://wangl-cc.github.io/ResizingTools.jl/stable/)
`ResizingTools` helps you create resizable `Array` types.
## Get started with `SimpleRDArray`
`SimpleRDArray` is a simple implementation of the resizable dense array, which
can be created simply:
```julia
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 == RM
true
```
Once a `SimpleRDArray` is created, you can almost do anything with which likes a
normal `Array` with similar performance:
```julia
julia> @benchmark $RM * $RM
BenchmarkTools.Trial: 10000 samples with 980 evaluations.
Range (min … max): 77.283 ns … 26.663 μs ┊ GC (min … max): 0.00% … 0.00%
Time (median): 214.530 ns ┊ GC (median): 0.00%
Time (mean ± σ): 300.628 ns ± 1.292 μs ┊ GC (mean ± σ): 6.87% ± 5.58%
█▂
▁▁▁▆██▄▂▁▁▁▁▁▁▁▁▂▂▂▃▃▃▃▃▄▄▄▄▄▄▄▄▃▃▃▃▃▃▂▂▂▂▂▂▂▂▂▂▁▁▁▁▁▁▁▁▁▁▁▁ ▂
77.3 ns Histogram: frequency by time 430 ns <
Memory estimate: 160 bytes, allocs estimate: 1.
julia> @benchmark $M * $M
BenchmarkTools.Trial: 10000 samples with 980 evaluations.
Range (min … max): 71.658 ns … 4.237 μs ┊ GC (min … max): 0.00% … 94.53%
Time (median): 144.504 ns ┊ GC (median): 0.00%
Time (mean ± σ): 161.228 ns ± 206.767 ns ┊ GC (mean ± σ): 7.40% ± 5.60%
▁▅▇█▇▅▂
▂▁▂▂▂▂▂▂▃▄▅▆███████▇▄▃▃▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂ ▃
71.7 ns Histogram: frequency by time 356 ns <
Memory estimate: 160 bytes, allocs estimate: 1.
julia> RM * RM == M * M
true
```
Besides, a `SimpleRDArray` can be resized in many ways:
```julia
julia> resize!(RM, (4, 4)) # resize RM to 4 * 4
4×4 SimpleRDArray{Int64, 2}:
1 4 7 81
2 5 8 96
3 6 9 102
4 8 66 126
julia> RM[1:3,1:3] == M
true
julia> resize!(RM, 2, 3) # resize the 2nd dimension of RM to 3
4×3 SimpleRDArray{Int64, 2}:
1 4 7
2 5 8
3 6 9
4 8 66
julia> RM[4, :] .= 0
3-element view(::SimpleRDArray{Int64, 2}, 4, :) with eltype Int64:
0
0
0
julia> resize!(RM, 1, Bool[1, 1, 0, 1]) # delete RM[3, :]
3×3 SimpleRDArray{Int64, 2}:
1 4 7
2 5 8
0 0 0
```
## Make your own array resizable
To make your own resizable array, you only need is defined some interface
methods, see
[docs](https://wangl-cc.github.io/ResizingTools.jl/dev/manual/#Interfaces) for
details.