Skip to content

Commit 19dcfb1

Browse files
authored
Merge pull request #145 from jonniediegelman/lazyarray-setindex
Make `setindex!` work for `LazyArray`s. Fixes #144
2 parents 1a69191 + 84c0c10 commit 19dcfb1

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "ComponentArrays"
22
uuid = "b0b7db55-cfe3-40fc-9ded-d10e2dbeff66"
33
authors = ["Jonnie Diegelman <47193959+jonniedie@users.noreply.github.com>"]
4-
version = "0.12.1"
4+
version = "0.12.2"
55

66
[deps]
77
ArrayInterface = "4fba245c-0d91-5ea0-9b3e-6abc04ee57a9"

src/lazyarray.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ const LazyMatrix{T,G} = LazyArray{T,2,G}
1515

1616
Base.getindex(a::LazyArray, i...) = _un_iter(getfield(a, :gen), i)
1717

18+
function Base.setindex!(a::LazyArray, val, i...)
19+
a[i...] .= val
20+
end
21+
1822
_un_iter(iter, idxs) = _un_iter(iter.f, iter.iter, idxs)
1923
_un_iter(f, iter::Base.Generator, idxs) = f(_un_iter(iter.f, iter.iter, idxs))
2024
_un_iter(f, iter::Base.Iterators.ProductIterator, idxs) = f(getindex.(iter.iterators, idxs))

test/runtests.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,10 @@ end
266266
@test tempmat["b", "b"][1, 1]["a", :a][:a, :a] == 100000
267267
@test tempmat[:b, :a][2].b == 1000
268268

269+
temp_b = deepcopy(temp.b)
270+
temp.b .= temp.b .* 100
271+
@test temp.b[1] == temp_b[1] .* 100
272+
269273
temp2 = deepcopy(ca)
270274
temp3 = deepcopy(ca_MVector)
271275
@test (temp2 .= ca .* 1) isa ComponentArray

0 commit comments

Comments
 (0)