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
|
Simple timing and correctness checks for sliding_window vs sliding_window_naive. |
|
Apply func to the full core block of each window (gufunc-like helper). |
|
xarray wrapper for |
|
Apply reducer independently to each sliding window along axis. |
|
xarray wrapper for |
|
Construct a non-copying sliding-window view along axis. |
|
Copy-based reference implementation of sliding_window for validation/testing. |
|
Return window center indices as floats. |
|
Return window center times from a 1D time vector |
|
Return window end indices (inclusive) for a 1D axis of length |
|
Return window onset indices for a 1D axis of length |