Skip to content

Commit 1dc02fd

Browse files
authored
Merge pull request #66 from neveritt/pull-request/ad6198c3
Fixed unnecessary copy in convert
2 parents 0d5fa8a + ad6198c commit 1dc02fd

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

src/Polynomials.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ poly(A::Matrix, var::Char) = poly(eig(A)[1], @compat Symbol(var))
108108

109109
include("show.jl") # display polynomials.
110110

111+
convert{T}(::Type{Poly{T}}, p::Poly{T}) = p
111112
convert{T}(::Type{Poly{T}}, p::Poly) = Poly(convert(Vector{T}, p.a), p.var)
112113
convert{T, S<:Number}(::Type{Poly{T}}, x::S) = Poly(promote_type(T, S)[x])
113114
convert{T, S<:Number,n}(::Type{Poly{T}}, x::Array{S,n}) = map(el->convert(Poly{promote_type(T,S)},el),x)

test/runtests.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,3 +193,9 @@ as = [im, 1, 2]
193193
bs = [1, 1, 2]
194194
@test conj(Poly(as)) == Poly(conj(as))
195195
@test conj(Poly(bs)) == Poly(conj(bs))
196+
197+
## unnecessary copy in convert #65
198+
p1 = Poly([1,2])
199+
p2 = convert(Poly{Int64}, p1)
200+
p2[3] = 3
201+
@test p1[3] == 3

0 commit comments

Comments
 (0)