Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,30 @@ jobs:
matrix:
version:
- '1.7'
- '1.9'
- '1.10'
- '1.12'
- 'pre'
- 'nightly'
os:
- ubuntu-latest
- windows-latest
- macos-latest
arch:
- x64
- 'default'
- 'x86'
exclude:
- os: macos-latest
version: '1.7'
- os: macos-latest
arch: 'x86'
steps:
- uses: actions/checkout@v4
- uses: julia-actions/setup-julia@v1
- uses: actions/checkout@v6
- uses: julia-actions/setup-julia@v2
with:
version: ${{ matrix.version }}
arch: ${{ matrix.arch }}
show-versioninfo: true
- uses: julia-actions/cache@v1
- uses: julia-actions/cache@v2
- uses: julia-actions/julia-buildpkg@v1
- uses: julia-actions/julia-runtest@v1
with:
Expand Down
9 changes: 3 additions & 6 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
name = "MutatePlainDataArray"
uuid = "3b0f367b-da20-4531-811a-c13cc92422b5"
authors = ["Haoran Ni <[email protected]> and contributors"]
version = "0.3.0"
version = "0.4.0"

[compat]
julia = "1.7"

[extras]
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
test = ["Test"]
[workspace]
projects = ["test"]
31 changes: 13 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@

Enable mutating immutable plain data fields using `aref` wrapper, allowing mutating immutable plain data fields using the following syntax:
```julia
aref(v)[i].a.b._i._j[] = val
aref(v)[i].a.b[] = val
```

The nested fields can be accessed using either the field name, or the field index prefixed with `_`.
Except for the wrapped vector, every field in the chain must be immutable. The final type to be mutated must be bits type.
The nested fields can be accessed using either the field name, or the field index with `getproperty`.
The wrapped vector must implement the strided arrays interface and must have `isbitstype` element type.

Examples:
```julia
```julia-repl
julia> using MutatePlainDataArray

julia> a = [1, 2, 3];
Expand All @@ -25,28 +25,23 @@ julia> a
2
3

julia> b = [(tup=(1, 2.5), s="a"), (tup=(2, 4.5), s="b")];
julia> b = [(;tup=(1, 2.5), s=4), (;tup=(2, 4.5), s=5)];

julia> aref(b)[1].tup._2[] = Inf
julia> aref(b)[1].tup.:2[] = Inf
Inf

julia> b
2-element Vector{NamedTuple{(:tup, :s), Tuple{Tuple{Int64, Float64}, String}}}:
(tup = (1, Inf), s = "a")
(tup = (2, 4.5), s = "b")
2-element Vector{@NamedTuple{tup::Tuple{Int64, Float64}, s::Int64}}:
(tup = (1, Inf), s = 4)
(tup = (2, 4.5), s = 5)

julia> aref(b)[2]._1._1[] *= 100
julia> (aref(b)[2].:1).:1[] *= 100
200

julia> b
2-element Vector{NamedTuple{(:tup, :s), Tuple{Tuple{Int64, Float64}, String}}}:
(tup = (1, Inf), s = "a")
(tup = (200, 4.5), s = "b")

julia> aref(b)[1].s[] = "invalid"
ERROR: The field type String (field s in NamedTuple{(:tup, :s), Tuple{Tuple{Int64, Float64}, String}}) is not immutable.
Stacktrace:
...
2-element Vector{@NamedTuple{tup::Tuple{Int64, Float64}, s::Int64}}:
(tup = (1, Inf), s = 4)
(tup = (200, 4.5), s = 5)
```

The mutation provided by this package is
Expand Down
267 changes: 0 additions & 267 deletions benchmark/Manifest.toml

This file was deleted.

3 changes: 3 additions & 0 deletions benchmark/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@ BangBang = "198e06fe-97b7-11e9-32a5-e1d131e6ad66"
BenchmarkTools = "6e4b80f9-dd63-53aa-95a3-0cdb28fa8baf"
MutatePlainDataArray = "3b0f367b-da20-4531-811a-c13cc92422b5"
Setfield = "efcf1570-3423-57d1-acb7-fd33fddbac46"

[sources]
MutatePlainDataArray = {path = ".."}
4 changes: 2 additions & 2 deletions benchmark/runbenchmarks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ struct BAI1
c::Int
d::Int
bab::BAB
m::Matrix{Float64}
m::Float64
end
BAI1() = BAI1(0, 0, 0, 0, BAB(), zeros(100, 100))
BAI1() = BAI1(0, 0, 0, 0, BAB(), 100)


function inbounds_setinner!_mutate(v, i)
Expand Down
Loading