@@ -206,23 +206,37 @@ transpose(p::Poly) = p
206206* `getindex(p::Poly, i)`: If `p=a_n x^n + a_{n-1}x^{n-1} + ... + a_1 x^1 + a_0`, then `p[i]` returns `a_i`.
207207
208208"""
209- getindex {T} (p:: Poly{T} , i) = (i+ 1 > length (p. a) ? zero (T) : p. a[i+ 1 ])
210- getindex {T} (p:: Poly{T} , idx:: AbstractArray ) = map (i-> p[i], idx)
211- function setindex! (p:: Poly , v, i)
209+ getindex {T} (p:: Poly{T} , idx:: Int ) = (idx ≥ length (p. a) ? zero (T) : p. a[idx+ 1 ])
210+ getindex {T} (p:: Poly{T} , indices:: AbstractVector{Int} ) = map (idx-> p[idx], indices)
211+ getindex {T} (p:: Poly{T} , :: Colon ) = p[0 : length (p)- 1 ]
212+
213+ function setindex! (p:: Poly , value, idx:: Int )
212214 n = length (p. a)
213- if n < i + 1
214- resize! (p. a,i + 1 )
215- p. a[n+ 1 : i ] = 0
215+ if n ≤ idx
216+ resize! (p. a, idx + 1 )
217+ p. a[n+ 1 : idx ] = 0
216218 end
217- p. a[i + 1 ] = v
218- v
219+ p. a[idx + 1 ] = value
220+ return p
219221end
220- function setindex! (p:: Poly , vs, idx:: AbstractArray )
221- [setindex! (p, v, i) for (i,v) in zip (idx, vs)]
222- p
222+
223+ function setindex! (p:: Poly , values:: AbstractVector , indices:: AbstractVector{Int} )
224+ for (idx, value) in zip (indices, values)
225+ setindex! (p, value, idx)
226+ end
227+ return p
223228end
224- eachindex {T} (p:: Poly{T} ) = 0 : (length (p)- 1 )
225229
230+ function setindex! (p:: Poly , value, indices:: AbstractVector{Int} )
231+ for idx in indices
232+ setindex! (p, value, idx)
233+ end
234+ return p
235+ end
236+
237+ setindex! (p:: Poly , values, :: Colon ) = setindex! (p, values, 0 : length (p)- 1 )
238+
239+ eachindex {T} (p:: Poly{T} ) = 0 : (length (p)- 1 )
226240
227241copy (p:: Poly ) = Poly (copy (p. a), p. var)
228242
0 commit comments