Discrete 1D convolutions [FR]
I’m working on a project whose main bottleneck is a series of 1d discrete convolutions, basically a lot of dot products within a for loop. Similar computations also came up in the forums a couple of times (for example here).
I’m wondering if there is a way to make them more efficient. Would it be helpful to add something like a conv1d function to stan-math? Is there a way to implement conv1d(x, kernel) such that it is more efficient than:
for (i in T:n) {
y[i] = dot_product(kernel, x[(i-T+1):i]);
}
I guess there are many subtleties here that I'm not aware of (numpy convolve has 3 modes - "full", "valid" and "same" - to handle various padding and border scenarios), just curious if this is relevant/interesting.
Would the row/col-wise framework work for this? https://github.com/stan-dev/design-docs/pull/35#issuecomment-821812405