cogpy.utils.sliding_core

Core sliding-window utilities for NumPy arrays. TAG: v1.0.0

This module provides: - a low-level, non-copying sliding window view constructor (sliding_window) - a slow reference implementation (sliding_window_naive) for testing - mid-level helpers for applying functions over windows:

  • running_reduce – reduces over window samples

  • running_blockwise – applies a function to the full core block per window

All functions are NumPy-only; higher-level xarray wrappers live elsewhere.

Examples

>>> import numpy as np
>>> from cogpy.utils.sliding_core import sliding_window, running_reduce
>>> x = np.arange(100)
>>> xwin = sliding_window(x, window_size=10, window_step=5)
>>> xwin.shape
(19, 10)
>>> xmulti = np.arange(16*100).reshape(16, 100)
>>> xmulti_win = sliding_window(xmulti, window_size=10, window_step=5, axis=1)
>>> xmulti_win.shape
(16, 19, 10)

Functions

benchmark_sliding()

Simple timing and correctness checks for sliding_window vs sliding_window_naive.

running_blockwise(x, window_size, ...[, ...])

Apply func to the full core block of each window (gufunc-like helper).

running_blockwise_xr(xsig, window_size, ...)

xarray wrapper for running_blockwise().

running_reduce(x, window_size, window_step, ...)

Apply reducer independently to each sliding window along axis.

running_reduce_xr(xsig, window_size, ...[, ...])

xarray wrapper for running_reduce().

sliding_window(x, window_size[, ...])

Construct a non-copying sliding-window view along axis.

sliding_window_naive(x, window_size[, ...])

Copy-based reference implementation of sliding_window for validation/testing.

window_centers_idx(n_samples, window_size, ...)

Return window center indices as floats.

window_centers_time(t, window_size, ...[, ...])

Return window center times from a 1D time vector t.

window_ends(n_samples, window_size, window_step)

Return window end indices (inclusive) for a 1D axis of length n_samples.

window_onsets(n_samples, window_size, ...)

Return window onset indices for a 1D axis of length n_samples.