Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if bkp % self.jump == 0:
if bkp - start >= self.min_size and end - bkp >= self.min_size:
bkps.append(bkp)
if len(bkps) > 0: # at least one admissible breakpoint was found
bkp = min(bkps, key=lambda x: abs(x - mid))
partition.remove((start, end))
partition.append((start, bkp))
partition.append((bkp, end))
stop = False
partition.sort()
# compute segment costs
leaves = list()
for start, end in partition:
val = self.cost.error(start, end)
leaf = Bnode(start, end, val)
leaves.append(leaf)
return leaves
def _merge(self, left, right):
"""Merge two contiguous segments."""
assert left.end == right.start, "Segments are not contiguous."
start, end = left.start, right.end
val = self.cost.error(start, end)
node = Bnode(start, end, val, left=left, right=right)
return node