Skip to content

Commit 1065f56

Browse files
Make setindex! work for LazyArrays. Fixes #144
1 parent 9c5eddd commit 1065f56

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

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)