Skip to content

Commit cc445b0

Browse files
committed
Merge branch 'mfalt-patch-1'
2 parents fc1ddc3 + 2690923 commit cc445b0

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

src/Polynomials.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ norm(q::Poly, args...) = norm(coeffs(q), args...)
193193
194194
"""
195195
getindex{T}(p::Poly{T}, i) = (i+1 > length(p.a) ? zero(T) : p.a[i+1])
196+
getindex{T}(p::Poly{T}, idx::AbstractArray) = map(i->p[i], idx)
196197
function setindex!(p::Poly, v, i)
197198
n = length(p.a)
198199
if n < i+1
@@ -202,6 +203,10 @@ function setindex!(p::Poly, v, i)
202203
p.a[i+1] = v
203204
v
204205
end
206+
function setindex!(p::Poly, vs, idx::AbstractArray)
207+
[setindex!(p, v, i) for (i,v) in zip(idx, vs)]
208+
p
209+
end
205210

206211
copy(p::Poly) = Poly(copy(p.a), p.var)
207212

test/runtests.jl

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ p1[5] = 1
163163
@test p1 == Poly([1,2,1,0,0,1])
164164

165165

166-
## elementwise operations
166+
## elementwise operations #52
167167
println("Test for element-wise operations")
168168
p1 = Poly([1, 2])
169169
p2 = Poly([3, 1.])
@@ -177,3 +177,9 @@ pmin = p-3
177177
@test isa(pprod,Vector{Poly{Float64}})
178178
@test isa(pmin, Vector{Poly{Float64}})
179179

180+
## getindex with ranges #43
181+
p1 = Poly([4,5,6])
182+
@test all(p1[0:1] .== [4,5])
183+
@test all(p1[0:end] .== [4,5,6])
184+
p1[0:1] = [7,8]
185+
@test all(p1[0:end] .== [7,8,6])

0 commit comments

Comments
 (0)