ezmsg.sigproc.util.sparse#

Functions

sliding_win_oneaxis(s, nwin, axis, step=1)[source]#

Generates a view-like sparse array using a sliding window of specified length along a specified axis. Sparse analog of an optimized dense as_strided-based implementation with these properties:

  • Accepts a single nwin and a single axis.

  • Inserts a new ‘win’ axis immediately BEFORE the original target axis. Output shape:

    s.shape[:axis] + (W,) + (nwin,) + s.shape[axis+1:]

    where W = s.shape[axis] - (nwin - 1).

  • If step > 1, stepping is applied by slicing along the new windows axis (same observable behavior as doing slice_along_axis(result, slice(None, None, step), axis) in the dense version).

Parameters:
  • s (SparseArray) – Input sparse array (pydata/sparse COO-compatible).

  • nwin (int) – Sliding window size (must be > 0).

  • axis (int) – Axis of s along which the window slides (supports negative indexing).

  • step (int) – Stride between windows. If > 1, applied by slicing the windows axis after construction.

Returns:

A sparse array with a new windows axis inserted before the original axis.

Return type:

SparseArray

Notes

  • Mirrors the dense function’s known edge case: when nwin == shape[axis] + 1, W becomes 0 and an empty windows axis is returned.

  • Built by coordinate arithmetic; no per-window indexing or concatenation.

sliding_win_oneaxis_old(s, nwin, axis, step=1)[source]#

Like ezmsg.util.messages.axisarray.sliding_win_oneaxis but for sparse arrays. This approach is about 4x slower than the version that uses coordinate arithmetic below.

Parameters:
  • s (SparseArray) – The input sparse array.

  • nwin (int) – The size of the sliding window.

  • axis (int) – The axis along which the sliding window will be applied.

  • step (int) – The size of the step between windows. If > 1, the strided window will be sliced with slice_along_axis.

Return type:

SparseArray

Returns:

sliding_win_oneaxis_old(s, nwin, axis, step=1)[source]#

Like ezmsg.util.messages.axisarray.sliding_win_oneaxis but for sparse arrays. This approach is about 4x slower than the version that uses coordinate arithmetic below.

Parameters:
  • s (SparseArray) – The input sparse array.

  • nwin (int) – The size of the sliding window.

  • axis (int) – The axis along which the sliding window will be applied.

  • step (int) – The size of the step between windows. If > 1, the strided window will be sliced with slice_along_axis.

Return type:

SparseArray

Returns:

sliding_win_oneaxis(s, nwin, axis, step=1)[source]#

Generates a view-like sparse array using a sliding window of specified length along a specified axis. Sparse analog of an optimized dense as_strided-based implementation with these properties:

  • Accepts a single nwin and a single axis.

  • Inserts a new ‘win’ axis immediately BEFORE the original target axis. Output shape:

    s.shape[:axis] + (W,) + (nwin,) + s.shape[axis+1:]

    where W = s.shape[axis] - (nwin - 1).

  • If step > 1, stepping is applied by slicing along the new windows axis (same observable behavior as doing slice_along_axis(result, slice(None, None, step), axis) in the dense version).

Parameters:
  • s (SparseArray) – Input sparse array (pydata/sparse COO-compatible).

  • nwin (int) – Sliding window size (must be > 0).

  • axis (int) – Axis of s along which the window slides (supports negative indexing).

  • step (int) – Stride between windows. If > 1, applied by slicing the windows axis after construction.

Returns:

A sparse array with a new windows axis inserted before the original axis.

Return type:

SparseArray

Notes

  • Mirrors the dense function’s known edge case: when nwin == shape[axis] + 1, W becomes 0 and an empty windows axis is returned.

  • Built by coordinate arithmetic; no per-window indexing or concatenation.