From 070c9b839522e8a92d29f93ef180b458a3025e1f Mon Sep 17 00:00:00 2001 From: JoFrhwld Date: Tue, 12 Nov 2024 17:32:43 -0500 Subject: [PATCH] trying for more efficiency --- src/aligned_textgrid/sequence_list.py | 19 ++++++++++--------- src/aligned_textgrid/sequences/sequences.py | 7 +++---- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/aligned_textgrid/sequence_list.py b/src/aligned_textgrid/sequence_list.py index 0772be4..0ee810e 100644 --- a/src/aligned_textgrid/sequence_list.py +++ b/src/aligned_textgrid/sequence_list.py @@ -102,14 +102,16 @@ def __repr__(self): return self._values.__repr__() def _sort(self)->None: - if len(self._values) > 0: - if hasattr(self[0], "start"): - item_starts = np.array([x.start for x in self._values]) - if hasattr(self[0], "time"): - item_starts = np.array([x.time for x in self._values]) - item_order = np.argsort(item_starts) - self._values = [self._values[idx] for idx in item_order] - + if len(self._values) < 1: + return + + if np.all(self.starts[:-1] <= self.starts[1:]): + return + + item_order = np.argsort(self.starts) + self._values = [self._values[idx] for idx in item_order] + + @wrap(log_class.entering, log_class.exiting) def _entry_class_checker(self, value) -> None: if self.entry_class is None: self.entry_class = value.entry_class @@ -205,7 +207,6 @@ def append(self:Sequence[SeqVar], value:SeqVar, shift:bool = False, re_init = Fa return self._values.append(value) - self._sort() def concat(self:Sequence[SeqVar], intervals:Sequence[SeqVar])->None: """Concatenate two sequence lists diff --git a/src/aligned_textgrid/sequences/sequences.py b/src/aligned_textgrid/sequences/sequences.py index 20645a9..7268ced 100644 --- a/src/aligned_textgrid/sequences/sequences.py +++ b/src/aligned_textgrid/sequences/sequences.py @@ -153,11 +153,10 @@ def set_subset_list(self, subset_list:SequenceList['SequenceInterval'] = None)-> for element in subset_list: if not self is element.super_instance: element.remove_superset() - element.set_super_instance(self) + element.super_instance = self - # self.append_subset_list(element) - - self._set_within() + #self._set_within() + self.contains = self._subset_list self._set_subset_precedence() #self.validate() else: