Skip to content

Commit d4fea28

Browse files
authored
make multiplication of polynomials type stable (#387)
1 parent 8f0512f commit d4fea28

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

src/contrib.jl

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,11 @@ using Base.Cartesian
44

55

66
# direct version (do not check if threshold is satisfied)
7-
@generated function fastconv(E::Array{T,N}, k::Array{T,N}) where {T,N}
8-
quote
9-
retsize = [size(E)...] + [size(k)...] .- 1
10-
retsize = tuple(retsize...)
11-
ret = zeros(T, retsize)
12-
convn!(ret, E, k)
13-
return ret
14-
end
7+
function fastconv(E::Array{T,N}, k::Array{T,N}) where {T,N}
8+
retsize = ntuple(n -> size(E, n) + size(k, n) - 1, Val{N}())
9+
ret = zeros(T, retsize)
10+
convn!(ret, E, k)
11+
return ret
1512
end
1613

1714
# in place helper operation to speedup memory allocations

test/StandardBasis.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,14 @@ end
408408
@test pNULL^3 == pNULL
409409
@test pNULL * pNULL == pNULL
410410

411+
if P === Polynomial
412+
# type stability of multiplication
413+
@inferred 10 * pNULL
414+
@inferred 10 * p0
415+
@inferred p2 * p2
416+
@inferred p2 * p2
417+
end
418+
411419
@test pNULL + 2 == p0 + 2 == 2 + p0 == P([2])
412420
@test p2 - 2 == -2 + p2 == P([-1,1])
413421
@test 2 - p2 == P([1,-1])

0 commit comments

Comments
 (0)