stan-dev / stan-dev/math

Discrete 1D convolutions [FR]

Open
#2,536 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C++
Stars
839
Forks
220
Avg merge
2d 4h
Merged PRs (30d)
14

Description

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the proposed conv1d(x, kernel) API and the existing Stan loop shown in the issue, then review the linked forum discussion for prior performance considerations. Define the supported boundary modes and establish whether the implementation is faster than direct dot products; no source file or test is named, so both the API location and validation plan must be determined.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
performance
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.