MCPcopy Create free account
hub / github.com/ml-explore/mlx-data / sliding_window_impl

Function sliding_window_impl

python/mlx/data/features/audio.py:63–84  ·  view source on GitHub ↗
(x)

Source from the content-addressed store, hash-verified

61
62def sliding_window(axis, window, stride):
63 def sliding_window_impl(x):
64 if axis < 0:
65 paxis = x.ndim + axis
66 else:
67 paxis = axis
68 isz = x.shape[axis]
69 if isz < window:
70 osz = 0
71 else:
72 osz = (isz - window) // stride + 1
73 windows = (
74 x.shape[:paxis]
75 + (
76 osz,
77 window,
78 )
79 + x.shape[paxis + 1 :]
80 )
81 strides = x.strides[:paxis] + (x.strides[paxis] * stride,) + x.strides[paxis:]
82 res = np.lib.stride_tricks.as_strided(x, windows, strides)
83
84 return res
85
86 return sliding_window_impl
87

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected