question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Consistency] Default axes in `linalg.diagonal` and `linalg.trace`.

See original GitHub issue

The functions linalg.trace and linalg.diagonal have as default axis1=0, axis2=1.

This goes against the rest of the documentation, in which a batch of matrices is defined as a tensor with shape (..., M, N).

It would be more consistent with the rest of the API to have axis1=-2, axis2=-1 to handle batches of matrices correctly by default.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:2
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
rgommerscommented, Aug 19, 2021

Fixed by gh-241, which removes the keywords. Thanks @Lezcano and @leofang

1reaction
leofangcommented, Jul 26, 2021

Wouldn’t it be better to just remove axis1 and axis2 entirely and always use the last two axes? This makes it more consistent with other linalg APIs, and is mathematically more intuitive. Users who need to compute trace/diagonal along arbitrary two axes can always swap the axes (related: #228) first before calling the API.

Read more comments on GitHub >

github_iconTop Results From Across the Web

numpy.trace — NumPy v1.24 Manual
Axes to be used as the first and second axis of the 2-D sub-arrays from which the diagonals should be taken. Defaults are...
Read more >
Lecture 1: Intro/refresher in Matrix Algebra
I is a square diagonal matrix, with all diagonal elements being one, all off-diagonal elements zero. I ij. = 1 for i =...
Read more >
Geometric interpretation of trace - linear algebra
-when a matrix A is in diagonal form, the trace is really the integral of its eigenvalues with the counting measure. -you can...
Read more >
Linear Algebra (scipy.linalg) — SciPy v1.9.3 Manual
This function takes a rank-1 (vectors) or a rank-2 (matrices) array and an optional order argument (default is 2). Based on these inputs,...
Read more >
What is the definition of a trace of a tensor?
We are aware of the trace of a two-dimensional tensor i.e. matrix. It is defined as the sum of the diagonal elements of...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found