nk
1.0.0
C++ Numerical Computing Runtime
Toggle main menu visibility
Loading...
Searching...
No Matches
conv.hpp
1
// ops/include/nk/ops/conv.hpp
2
//
3
// Direct (time-domain) linear convolution of two real double sequences — the
4
// numerical FIR kernel behind signal's conv()/xcorr(). Raw-buffer, core-free;
5
// lives in the kernel layer so the VM/codegen can lower a conv() call to it and
6
// a SIMD backend can replace the inner loop without touching the toolbox.
7
//
8
// The FFT-based path (convFFT) stays in the signal toolbox for now: it is built
9
// on the signal-local radix-2 FFT helpers, not ops::fft, so it is not a verbatim
10
// move.
11
12
#pragma once
13
14
#include <nk/value/scratch.hpp>
15
16
#include <cstddef>
17
#include <memory_resource>
18
19
namespace
nk::ops {
20
21
// Full linear convolution: out[k] = Σ_{i+j=k} a[i]·b[j], length na+nb-1.
22
// Both inputs are real double buffers; the result is returned on the arena `mr`.
23
// O(na·nb) — the caller (conv/xcorr) picks direct vs FFT by cost.
24
ScratchVec<double> convDirect(
const
double
*a, std::size_t na,
25
const
double
*b, std::size_t nb,
26
std::pmr::memory_resource *mr);
27
28
// Direct 2-D "full" convolution into a caller-allocated buffer. A is M×N
29
// (column-major), B is P×Q (column-major); `out` must be sized (M+P-1)×(N+Q-1)
30
// column-major and is zeroed then accumulated by the kernel. O(M·N·P·Q) — the
31
// time-domain core of signal conv2/filter2/convn. No allocation, no mr.
32
void
conv2Direct(
const
double
*A, std::size_t M, std::size_t N,
33
const
double
*B, std::size_t P, std::size_t Q,
34
double
*out);
35
36
}
// namespace nk::ops
src
ops
include
nk
ops
conv.hpp
Generated by
1.17.0