On Tue, 19 Mar 2019, Sven Schreiber wrote:
Hi,
while looking at the example scripts I've noticed convolve.inp, and then
also the paragraph about Convolution in the guide (cheat sheet chapter,
p. 154 for me).
I wonder if this should be wrapped in a hansl function and added to the
'extra' addon, like this:
<hansl>
function void padzeros(matrix *a, matrix *b)
a = vec(a)
b = vec(b)
outrows = rows(a) + rows(b) - 1
a |= zeros(outrows - rows(a), 1)
b |= zeros(outrows - rows(b), 1)
end function
function matrix convolve(matrix p, matrix q)
padzeros(&p, &q)
return filter(p, q)
end function
# And for comparison only:
function matrix convolve_fft(matrix p, matrix q)
padzeros(&p, &q)
f = fft(p ~ q)
return ffti(cmult(f[,1:2], f[,3:4]))
end function
<hansl>
As mentioned in the guide, the filter-based variant is indeed about 30%
faster in my examples.
BTW, I think there are some typos in the notation in the Convolution
paragraph: The sum indices i should start at 0, not 1, and the upper
bound for the R(x) index should be p + q - 1 instead of pq-1.
I agree that the summation indices as stated do not seem to allow
for a constant term. One could either say
P(x) = \sum_{i=1}^p p_i x^{i-1}
for p = the degree of the polynomial + 1, or
P(x) = \sum_{i=0}^p p_i x^i
for p = the degree of the polynomial.
Not sure about the R(x) index at this point!
Allin