Skip to content

Commit bf0405d

Browse files
committed
Add copy(::UnivPoly)
1 parent f69ac97 commit bf0405d

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

src/generic/UnivPoly.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,8 @@ function deepcopy_internal(p::UnivPoly{T}, dict::IdDict) where {T}
321321
return UnivPoly{T}(deepcopy_internal(data(p), dict), parent(p))
322322
end
323323

324+
Base.copy(f::UnivPoly{T}) where {T} = UnivPoly{T}(copy(data(f)), parent(f))
325+
324326
###############################################################################
325327
#
326328
# Multivariate coefficients

test/generic/UnivPoly-test.jl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1144,26 +1144,38 @@ end
11441144
f1 = add!(f1, g, h)
11451145

11461146
@test f1 == g + h
1147+
@test f == 3x^3 + 2x^2 + x + 4
11471148

11481149
f2 = deepcopy(f)
11491150
f2 = add!(f2, g)
11501151

11511152
@test f2 == f + g
1153+
@test f == 3x^3 + 2x^2 + x + 4
11521154

11531155
f3 = deepcopy(f)
11541156
f3 = mul!(f3, g, h)
11551157

11561158
@test f3 == g*h
1159+
@test f == 3x^3 + 2x^2 + x + 4
11571160

11581161
f4 = deepcopy(f)
11591162
f4 = addmul!(f4, g, h)
11601163

11611164
@test f4 == f + g*h
1165+
@test f == 3x^3 + 2x^2 + x + 4
11621166

11631167
f5 = deepcopy(f)
11641168
f5 = zero!(f5)
11651169

11661170
@test f5 == 0
1171+
@test f == 3x^3 + 2x^2 + x + 4
1172+
1173+
# also verify `copy` works as intended
1174+
f6 = copy(f)
1175+
f6 = zero!(f6)
1176+
1177+
@test f6 == 0
1178+
@test f == 3x^3 + 2x^2 + x + 4
11671179
end
11681180
end
11691181

0 commit comments

Comments
 (0)