Repository navigation
Conversation
Resolve conflict in correlograms.py: keep the TsdFrame dispatch from dev before the bin parameters, and combine the docstrings.
gviejo
force-pushed
the
sorted_tsgroup
branch
from
October 16, 2026 20:47
fe94306 to
257eb1a
Compare
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Sorted-array storage for
TsGroup(issue #662)Summary
This PR changes the internal storage of
TsGroup. On main, aTsGroupis a dict with oneTs/Tsdfor each unit. On this branch, it holds the spikes of all the units in one array, sorted by time:_times_clusters_data_is_tsd,_columnsSo a group operation runs once on the merged array, not once for each unit. The PR also adds a lazy TsGroup for data on disk, and it moves the process functions to the new storage.
The branch has 22 commits after
dev, including a merge ofdev. It changes 29 files: about 7,460 lines added and 1,740 removed.Main changes
1.
TsGroup(core/ts_group.py)_cluster_positions: the position of the unit of each spike_ragged_index: the spikes of each unit, in time order, for fast access to one unitcount,restrict,value_from,to_tsd,get,time_diffand the other methods work on the merged arrays, with numba kernels.tsg[k]builds the unit object on each call, from_ragged_index.group.datais now a read-only view (_TsGroupDictView).ratemetadata is now read-only.2. New public entry points
TsGroup.from_ragged_arrays(...)andTsGroup.from_sorted_arrays(...)build a group from flat arrays.utils.is_lazy_array) andlazy=True, they return a lazy group. In all other cases, they return a regularTsGroup.3. Lazy TsGroup (
core/lazy_ts_group.py, private)_LazyTsGrouphas two sources:_RaggedArraySource(NWB style) and_SortedArraySource(for example zarr).TsGroup, then calls the same method on it. The process functions usegroup._load_in_memory(ep).4. NWB (
io/interface_nwb.py)nwb['units']now returns a lazy group that reads the NWB ragged arrays.NWBFile.close()now works with pynwb objects.5. The matching kernel of
value_from(core/_jitted_functions.py)jitvaluefromis now the only matching kernel. It does one merge scan for each epoch, and bothvalue_fromandcompute_tuning_curvescall it._valuefrom_matchreproduces the rules of the old kernel, and the tests check this against a brute-force oracle.6. Process functions
_cross_correlograms. It counts with integer times, in units of the time precision.binsizebelow the time precision raises aValueError._cross_correlogramis removed.jitvaluefrommatches the spikes, then_jitcount_spikescounts them for each unit and bin.compute_tuning_curves,compute_response_per_epochandcompute_mutual_information.7. Other fixes
__getattr__recursion in the metadata mixin, when the object is not fully built.TsGroupconstructor.Performance (1000 units × 2,000 spikes, branch against main)
get(a, b)compute_tuning_curves(1D, 2D, 100 epochs)restrict/value_fromnwb['units']count/to_tsd/time_diffTsGroup(dict)tsg[5 units]_takescans all the spikes withnp.isintsg[k], loop over unitscountof a lazy NWB groupjitter_timestamps/resample_timestampsvalue_fromwith very sparse inputsTests
New test file:
test_lazy_ts_group.py. Updated test files:test_ts_group.py,test_correlograms.py,test_jitted.py,test_metadata.py,test_npz_file.py,test_nwb.py,test_perievent.py,test_randomize.py,test_restrict_routing.py,test_tuning_curves.py,test_value_from_kernel.pyandtest_warping.py. The last full run passed: 6047 passed, 280 skipped.