Usage Guide
Functions are grouped by category. Each entry links to the full docstring in the API Reference.
Index/Time Conversion
Convert between 1-based sample indices and time values for regularly sampled data.
ndx_to_t converts an index (or array of indices) to time:
fs = 30_000.0
ndx_to_t(15001, fs) # 0.5
ndx_to_t(15001, fs, 1.0) # 1.5 (with start_t offset)t_to_ndx converts a time to the first sample index at or after that time. t_to_last_ndx returns the last sample at or before the time. t_sup_to_ndx returns the last sample strictly before the time.
t_to_ndx(0.5, fs) # 15001
t_to_last_ndx(0.5, fs) # 15001
t_sup_to_ndx(0.5, fs) # 15000n_ndx counts the number of indices in a range. ndx_offset computes the end index for a given start and number of points. ndx_wrap wraps an index using modular arithmetic.
clip_ndx clamps an index to 1:length. clip_ndx_deviance also returns how far the index was clipped.
clip_ndx(0, 100) # 1
clip_ndx(150, 100) # 100
clip_ndx_deviance(150, 100) # (100, -50)duration and time_interval compute timing information for a signal:
duration(30001, fs) # 1.0 (seconds)
time_interval(30001, fs, 0.0) # (0.0, 1.0)Bin and Window Operations
bin_bounds returns the (start, stop) indices for a bin number and bin size. bin_center returns the center index.
bin_bounds(2, 10) # (11, 20)
bin_center(2, 10) # 15.5expand_selection widens an index range by a given amount, clamped to [1, imax]:
expand_selection(5, 10, 100, 3) # (2, 13)make_slice_idx and make_expand_idx construct index tuples for programmatic slicing and broadcasting along arbitrary dimensions.
view_trailing_slice returns a view sliced along the last dimension:
A = rand(3, 4, 5)
v = view_trailing_slice(A, 2) # equivalent to view(A, :, :, 2)Signal Processing
moving_sum / moving_sum! compute a sliding window sum without zero-padding:
moving_sum([1, 2, 3, 4, 5], 3) # [6, 9, 12]local_extrema finds indices of local maxima (default) or minima:
local_extrema([1, 3, 2, 4, 1]) # [2] (local max at index 2)
local_extrema([1, 3, 2, 4, 1], <) # [3] (local min at index 3)find_local_extrema hill-climbs from a starting index to the nearest extremum.
find_all_edge_triggers / find_first_edge_trigger detect threshold crossings (rising edges):
find_all_edge_triggers([0, 0, 1, 1, 0, 1], 1) # [3, 6]
find_first_edge_trigger([0, 0, 1, 1, 0, 1], 1) # 3thresh_cross finds where a signal crosses upward through a threshold. indices_above_thresh returns contiguous ranges where the signal exceeds a threshold.
filter_no_collisions removes elements from one sorted array that are within a collision radius of elements in another:
filter_no_collisions([1, 5, 10, 15], [4, 14], 2) # [1, 10]window_counts counts the number of events within a sliding time window.
uniformhist / uniformhist! compute fast histograms for regularly-spaced bins, using reciprocal multiplication for speed:
uniformhist([0.1, 0.5, 1.2, 2.9], 0.0:1.0:3.0) # [2, 1, 1]centered_basis returns a range of points centered around zero. stepsize extracts the step size from a range or regularly sampled vector.
Array Utilities
weighted_mean and weighted_mean_dim compute weighted averages:
weighted_mean([1.0, 2.0, 3.0], [0.5, 0.3, 0.2]) # 1.7simple_summary_stats returns (mean, std, sem) in one call.
find_closest returns the index of the nearest value:
find_closest([1.0, 3.0, 5.0], 2.8) # 2find_subseq finds all starting indices where a subsequence occurs.
subselect extracts sub-vectors using (start, stop) index tuples.
rev_view returns a reversed view without copying.
trailing_zeros_idx finds the last non-zero index.
clipsize! resizes a vector and releases excess memory.
copy_length_check and copy_length_dest_check validate that a destination has room for a copy operation.
invert_perm returns the inverse of a permutation vector.
Pairwise Operations
pairwise_idxs generates all unique (i, j) pairs where i > j:
pairwise_idxs(3) # [(2,1), (3,1), (3,2)]pairwise_idx converts a pair back to its linear index.
map_pairwise applies a function to all unique pairs from a vector:
map_pairwise(-, [10, 20, 30]) # [10, 20, 10]imap_product lazily maps a function over the Cartesian product of two collections.
Filtering and Comparison
filtermap combines filter and map in a single pass.
find_not_unique returns indices of all duplicate elements.
skipoftype / skipnothing return iterators that skip elements of a given type:
sum(skipnothing([1, nothing, 2, nothing, 3])) # 6allsame checks whether all elements (or mapped values) are equal:
allsame([1, 1, 1]) # true
allsame(length, [1,2], [3,4]) # trueanyeq checks whether an element exists in a collection.
absdiff computes the absolute difference, with branch-free unsigned integer support.
Type Utilities
div_type determines the appropriate floating-point result type for division. Float types are preserved; integer types promote to Float64.
div_type(Int) # Float64
div_type(Float32) # Float32