Skip to content

Commit

Permalink
add functions to diff tree statistics
Browse files Browse the repository at this point in the history
  • Loading branch information
malb committed Jul 10, 2017
1 parent 7a9983d commit d2fde0e
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions src/fpylll/algorithms/bkz_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,16 @@ def __radd__(self, other):
"""
return self + other

def __sub__(self, other):
"""
Return the difference of the averages.
"""
if not isinstance(other, Statistic):
return self.avg - other
else:
return self.avg - other.avg

def __float__(self):
"""
Reduce this stats object down a float depending on strategy chosen in constructor.
Expand Down Expand Up @@ -582,6 +592,33 @@ def level(self):
node = node.parent
return level

def __sub__(self, rhs):
"""
Return tree that contains the difference of this node and the other.
The semantics are as follows:
- For all data in this node the matching data item in ``rhs`` is subtracted.
- If the data is missing in ``rhs`` it is assumed to be zero.
- For all children of this node this function is called recursively.
- If ``rhs`` does not have an immediate child node with a matching label, those children are skipped.
"""

if not isinstance(rhs, Node):
raise ValueError("Expected node but got '%s'"%type(rhs))
diff = Node(self.label)
for k in self.data:
diff.data[k] = self.data[k] - rhs.data.get(k, 0)

for lchild in self.children:
for rchild in rhs.children:
if lchild.label == rchild.label:
diff.children.append(lchild - rchild)
break
else:
print("Skipping missing node '%s'"%lchild.label)
return diff


class TimeTreeTracer(Tracer):
"""
Expand Down

0 comments on commit d2fde0e

Please sign in to comment.