Skip to content

Commit

Permalink
Merge pull request #424 from esi-neuroscience/discrete-get-methods
Browse files Browse the repository at this point in the history
Another discrete speedup
  • Loading branch information
tensionhead authored Jan 18, 2023
2 parents ce5707c + 4ec7eac commit 040888e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ All notable changes to this project will be documented in this file.
### NEW

### CHANGED
- major performance improvements for DiscreteData #403 #418, #424

### Fixed
- fix bug #394 'Copying a spy.StructDict returns a dict'.
- serializable `.cfg` #392
- serializable `.cfg` #392

## [2022.12]

Expand Down
21 changes: 11 additions & 10 deletions syncopy/datatype/discrete_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,12 +214,15 @@ def _preview_trial(self, trialno):
syncopy.datatype.base_data.FauxTrial : class definition and further details
syncopy.shared.computational_routine.ComputationalRoutine : Syncopy compute engine
"""

trialIdx = np.where(self.trialid == trialno)[0]
trlSlice = self._trialslice[trialno]
trialIdx = np.arange(trlSlice.start, trlSlice.stop) #np.where(self.trialid == trialno)[0]
nCol = len(self.dimord)
idx = [trialIdx.tolist(), slice(0, nCol)]
idx = [[], slice(0, nCol)]
if self.selection is not None: # selections are harmonized, just take `.time`
idx[0] = trialIdx[self.selection.time[self.selection.trial_ids.index(trialno)]].tolist()
else:
idx[0] = trialIdx.tolist()

shp = [len(idx[0]), nCol]

return FauxTrial(shp, tuple(idx), self.data.dtype, self.dimord)
Expand Down Expand Up @@ -261,7 +264,7 @@ def _get_time(self, trials, toi=None, toilim=None):
if toilim is not None:
allTrials = self.trialtime
for trlno in trials:
trlTime = allTrials[self.trialid == trlno]
trlTime = allTrials[self._trialslice[trlno]]
_, selTime = best_match(trlTime, toilim, span=True)
selTime = selTime.tolist()
if len(selTime) > 1 and np.diff(trlTime).min() > 0:
Expand All @@ -272,11 +275,11 @@ def _get_time(self, trials, toi=None, toilim=None):
elif toi is not None:
allTrials = self.trialtime
for trlno in trials:
trlTime = allTrials[self.trialid == trlno]
trlTime = allTrials[self._trialslice[trlno]]
_, arrayIdx = best_match(trlTime, toi)
# squash duplicate values then readd
_, xdi = np.unique(trlTime[arrayIdx], return_index=True)
arrayIdx = arrayIdx[np.sort(xdi)]
arrayIdx = arrayIdx[xdi] # we assume sorted data
selTime = []
for t in arrayIdx:
selTime += np.where(trlTime[t] == trlTime)[0].tolist()
Expand Down Expand Up @@ -488,9 +491,8 @@ def _get_unit(self, trials, units=None):
"""
if units is not None:
indices = []
allUnits = self.data[:, self.dimord.index("unit")]
for trlno in trials:
thisTrial = allUnits[self.trialid == trlno]
thisTrial = self.data[self._trialslice[trlno], self.dimord.index("unit")]
trialUnits = []
for unit in units:
trialUnits += list(np.where(thisTrial == unit)[0])
Expand Down Expand Up @@ -633,9 +635,8 @@ def _get_eventid(self, trials, eventids=None):
"""
if eventids is not None:
indices = []
allEvents = self.data[:, self.dimord.index("eventid")]
for trlno in trials:
thisTrial = allEvents[self.trialid == trlno]
thisTrial = self.data[self._trialslice[trlno], self.dimord.index("eventid")]
trialEvents = []
for event in eventids:
trialEvents += list(np.where(thisTrial == event)[0])
Expand Down

0 comments on commit 040888e

Please sign in to comment.