Simple direct and extendable convolution library.
npm install convolutionshell
$ npm i convolution
`
Usage
$3
convolve(a: Array
Performs a convolution operation on two arrays one dimensional a and b. The function returns a new array of the same type as the input, which represents the result of the convolution.
`ts
import convolve from "convolution"
const a = [1, 2, 3]
const b = [1, 2, 3]
const result = convolve(a, b)
// result = [1, 4, 10, 12, 9]
`
$3
convolveArbitrary(convolutionStepFunction: (a: List, b: List) => T): (a: List, b: List) => List
Creates a convolution function given a custom convolution step function. A convolution step is the operation of combining two arrays of the same length into a single value. Typically this is done by $\sum_{i}^{}(a_i * b_i)$, but can be arbitrary. The function returns a new function which can be used to perform the whole convolution on two arrays.
The following example is the same as the convolve function above.
`ts
import { convolveArbitrary } from "convolution"
const convolutionStepFunction = (a, b) => {
let sum = 0
for (let i = 0; i < a.length; i++) {
sum += a[i] * b[i]
}
return sum
}
const convolve = convolveArbitrary(convolutionStepFunction)
const a = [1, 2, 3]
const b = [1, 2, 3]
const result = convolve(a, b)
// result = [1, 4, 10, 12, 9]
``