Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
raise ValueError("Some clusters do not exist.")
# Find the new cluster number.
if to is None:
to = self.new_cluster_id()
if to < self.new_cluster_id():
raise ValueError(
"The new cluster numbers should be higher than {0}.".format(self.new_cluster_id()))
# NOTE: we could have called self.assign() here, but we don't.
# We circumvent self.assign() for performance reasons.
# assign() is a relatively costly operation, whereas merging is a much
# cheaper operation.
# Find all spikes in the specified clusters.
spike_ids = _spikes_in_clusters(self.spike_clusters, cluster_ids)
up = self._do_merge(spike_ids, cluster_ids, to)
undo_state = emit('request_undo_state', self, up)
# Add to stack.
self._undo_stack.add((spike_ids, [to], undo_state))
emit('cluster', self, up)
return up
def spikes_in_template(self, template_id):
return _spikes_in_clusters(self.spike_templates, [template_id])
def _extend_spikes(spike_ids, spike_clusters):
"""Return all spikes belonging to the clusters containing the specified
spikes."""
# We find the spikes belonging to modified clusters.
# What are the old clusters that are modified by the assignment?
old_spike_clusters = spike_clusters[spike_ids]
unique_clusters = _unique(old_spike_clusters)
# Now we take all spikes from these clusters.
changed_spike_ids = _spikes_in_clusters(spike_clusters, unique_clusters)
# These are the new spikes that need to be reassigned.
extended_spike_ids = np.setdiff1d(changed_spike_ids, spike_ids, assume_unique=True)
return extended_spike_ids
def spikes_in_clusters(self, clusters):
"""Return the array of spike ids belonging to a list of clusters."""
return _spikes_in_clusters(self.spike_clusters, clusters)