Skip to content

Commit

Permalink
support off-diagonal trace
Browse files Browse the repository at this point in the history
This patch reimplements the dispatched numpy.trace function to include support
for the off-diagonal case. An important side effect of this patch is that the
function no longer relies on the function._takediag helper function, which will
be removed in a later commit.
  • Loading branch information
gertjanvanzwieten committed Jul 28, 2023
1 parent 2621367 commit 8304029
Showing 1 changed file with 1 addition and 3 deletions.
4 changes: 1 addition & 3 deletions nutils/function.py
Original file line number Diff line number Diff line change
Expand Up @@ -4353,9 +4353,7 @@ def ravel(arg: Array):

@implements(numpy.trace)
def trace(arg: Array, offset: int = 0, axis1: int = 0, axis2: int = 1) -> Array:
if offset != 0:
raise NotImplementedError('traces over offset diagonal are not yet supported')
return numpy.sum(_takediag(arg, axis1, axis2), -1)
return numpy.sum(numpy.diagonal(arg, offset, axis1, axis2), -1)

@implements(numpy.transpose)
def transpose(array: Array, axes: Optional[Sequence[int]] = None) -> Array:
Expand Down

0 comments on commit 8304029

Please sign in to comment.