sgnts.base.signal
¶
Array operations not covered by the Python Array API standard.
The standard xp namespace (via array_namespace) covers creation and
manipulation ops (zeros/ones/full/concat/stack/matmul/
sum/arange …) uniformly across numpy and torch. A few operations sgn-ts
needs are not in the standard for every backend and so cannot be reached as
xp.<op>:
pad— present asnumpy.padbut absent from torch's array-API namespace (torch usestorch.nn.functional.padwith a different signature).- convolution / correlation (e.g.
scipy.signal.correlatevstorch.nn.functional.conv1d) — genuinely backend-specific kernels.
This module is the single, named home for those escape-hatch operations: namespace-dispatched helpers so element code stays backend-blind where it can. Single-backend elements may still import their library directly — this module is for the backend-agnostic call sites.
mask_runs(mask)
¶
Yield (start, stop, value) runs of a 1-D boolean mask.
Backend-agnostic replacement for numpy.ma.clump_masked /
clump_unmasked (numpy.ma has no array-API equivalent):
consecutive equal values are grouped into half-open index ranges
[start, stop), in order. Run boundaries are data-dependent, so
for device arrays this synchronizes with the host -- inherent to the
use case, since run structure is host-side metadata (e.g. buffer
boundaries).
Source code in src/sgnts/base/signal.py
pad(data, pad_width)
¶
Zero-pad the last axis of data by (before, after) samples.
Dispatches on the array's backend because pad is not uniformly available
in the Array API standard namespace (numpy has it, torch does not).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Array
|
Array, the array to pad (numpy or torch). |
required |
pad_width
|
tuple[int, int]
|
tuple[int, int], samples to pad before and after along the last axis. |
required |
Returns:
| Type | Description |
|---|---|
Array
|
Array, the padded array, same backend as |