Skip to content

Commit

Permalink
prevent unnecessary copy
Browse files Browse the repository at this point in the history
  • Loading branch information
danielhrisca committed Dec 14, 2023
1 parent e6dbac3 commit 1f12c7d
Showing 1 changed file with 25 additions and 22 deletions.
47 changes: 25 additions & 22 deletions src/asammdf/signal.py
Original file line number Diff line number Diff line change
Expand Up @@ -1349,7 +1349,7 @@ def physical(self) -> Signal:
)

def validate(self, copy: bool = True) -> Signal:
"""appply invalidation bits if they are available for this signal
"""apply invalidation bits if they are available for this signal
Parameters
----------
Expand All @@ -1364,27 +1364,30 @@ def validate(self, copy: bool = True) -> Signal:

else:
idx = np.nonzero(~self.invalidation_bits)[0]
signal = Signal(
self.samples[idx],
self.timestamps[idx],
self.unit,
self.name,
self.conversion,
self.comment,
self.raw,
self.master_metadata,
self.display_names,
self.attachment,
self.source,
self.bit_count,
invalidation_bits=None,
encoding=self.encoding,
group_index=self.group_index,
channel_index=self.channel_index,
flags=self.flags,
virtual_conversion=self.virtual_conversion,
virtual_master_conversion=self.virtual_master_conversion,
)
if len(idx) == len(self.samples):
signal = self
else:
signal = Signal(
self.samples[idx],
self.timestamps[idx],
self.unit,
self.name,
self.conversion,
self.comment,
self.raw,
self.master_metadata,
self.display_names,
self.attachment,
self.source,
self.bit_count,
invalidation_bits=None,
encoding=self.encoding,
group_index=self.group_index,
channel_index=self.channel_index,
flags=self.flags,
virtual_conversion=self.virtual_conversion,
virtual_master_conversion=self.virtual_master_conversion,
)

if copy:
signal = signal.copy()
Expand Down

0 comments on commit 1f12c7d

Please sign in to comment.