Skip to content

Commit

Permalink
Added -agg change
Browse files Browse the repository at this point in the history
This computes the difference between the last and the first element
  • Loading branch information
tnipen committed May 12, 2024
1 parent ee38c04 commit 710c367
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions verif/aggregator.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,3 +145,25 @@ def __call__(self, array, axis=None):

def __eq__(self, other):
return (self.__class__ == other.__class__) and (self.quantile == other.quantile)


class Change(Aggregator):
"""Difference between the last and the first element. Is most useful
when used with -Tagg since it implies an array representing a sequence
such as time.
"""
def __call__(self, array, axis=None):
if axis is None:
return array.flatten()[-1] - array.flatten()[0]
elif axis == 0:
return array[-1, ...] - array[0, ...]
elif axis == 1:
return array[:, -1, ...] - array[:, 0, ...]
elif axis == 2:
return array[:, :, -1, ...] - array[:, :, 0, ...]
elif axis == 3:
return array[:, :, :, -1, ...] - array[:, :, :, 0, ...]
elif axis == 4:
return array[:, :, :, :, -1, ...] - array[:, :, :, :, 0, ...]
else:
raise NotImplementedError(f"This function not implemented for axis {axis}")

0 comments on commit 710c367

Please sign in to comment.