Pad
ShippingpadExtend a Signal or Vector at its ends with constant / edge / reflect / wrap fill (numpy np.pad)
Signature
Inputs
signalSignal|Vectorrequired— The signal or vector to extend at both ends.
Outputs
resultSignal|Vector— The padded value, same variant as the input, longer by `before + after` samples.
Parameters
| Key | Type | Default | Notes |
|---|---|---|---|
mode | enum | constant | one of: constant, edge, reflect, wrap |
before | int | 0 | Number of samples to prepend to the START of the signal. The time axis is extrapolated backwards on the uniform dt; timestamps and σ² are reindexed in lock-step with the values. |
after | int | 0 | Number of samples to append to the END of the signal. The time axis is extrapolated forwards on the uniform dt; timestamps and σ² are reindexed in lock-step. |
value | float | 0.0 | The constant fill value for the added samples when Mode = Constant. Expressed in the input's unit. An injected constant is exact, so padded positions get σ² = 0. (Active only when Mode = Constant.) |
Description
Pad grows the data by before samples on the left and after samples on the right, filling the new positions according to mode (numpy np.pad):
| mode | new sample value | |------|------------------| | constant | the fixed value parameter (an injected constant) | | edge | the nearest edge sample (clamp / replicate) | | reflect | mirror about the edge without repeating it | | wrap | periodic — the signal tiles |
The edge/reflect/wrap fetches reuse the same canonical boundary machinery as smoothing/envelope/derivative, so their boundary semantics are bit-identical across the app.
A pad is a pure permutation/injection of indices, so metadata propagation is EXACT. Values come from sample_at(i) for every virtual index . Variances (σ²) are carried from the SAME source sample the value came from; a constant pad injects an exact constant so its σ² is , and a None σ² stays None (no fabrication). Timestamps are extrapolated linearly on the input's uniform before/after, keeping the interior verbatim so the padded signal stays a valid, strictly-increasing time axis. Unit is preserved (a shape op never changes dimension). A Vector input takes a simpler path: values reindexed, unit preserved, no time axis or σ².
Mathematics
Examples
Constant pad
np.pad([1,2,3], (2,1), 'constant', constant_values=9) → values [9, 9, 1, 2, 3, 9]. With before=2, after=1, value=9. Timestamps extrapolate backwards to and forwards to on , interior preserved.
Edge (clamp) pad
before=2, after=2, mode=edge on [1,2,3] replicates the end samples → [1, 1, 1, 2, 3, 3, 3]. Each replicated end sample carries its source σ².
Reflect pad
before=2, after=2, mode=reflect on [1,2,3,4] mirrors about each edge without repeating it → [3, 2, 1, 2, 3, 4, 3, 2].
Wrap (periodic) pad
before=2, after=2, mode=wrap on [1,2,3] tiles periodically → [2, 3, 1, 2, 3, 1, 2].
Applications
- Zero-padding a frame before an FFT to a convenient length (constant, value 0).
- Extending a signal with edge/reflect padding to suppress boundary artifacts before smoothing, filtering, or convolution.
- Building a periodic extension (wrap) for loopable buffers or circular processing.
- Prepending/appending a fixed run of samples to align two signals to a common length.
Neat
A single index map drives values, σ² AND timestamps simultaneously, so the three parallel arrays can never diverge — the same guarantee slicing and gathering give.
The σ² of a constant-filled position is exactly 0 (the fill is a certain constant), while a mirrored/clamped/wrapped position carries the real source sample's σ² — uncertainty is neither fabricated nor lost.
numpy's `edge` mode maps onto Captyse's `Nearest` boundary vocabulary; the doc keeps the numpy names on the UI so prototypes transfer directly.
Known issues
A `reflect` pad wider than the interior can require mirroring past the far edge; behaviour follows the shared boundary machinery rather than numpy's exact multi-bounce for very large pad widths.
Padding a Vector produces a plain Vector with no time axis — only the Signal path extrapolates timestamps.