Thanks to visit codestin.com
Credit goes to github.com

Skip to content

DOC: Update documentation of np.linalg.det() #27599

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

amitsubhashchejara
Copy link
Contributor

This update modifies the documentation in _linalg.py for the np.linalg.det() function to clarify the effects of floating-point precision limitations when calculating the determinant of a matrix.

It includes an explanation that small numerical errors (i.e. floating point rounding error) may occur, leading to very small non-zero values instead of exactly zero for singular matrices. Additionally, an example is provided using np.isclose() to check if the determinant is effectively zero.

…ating-point precision

This update modifies the documentation in _linalg.py for the np.linalg.det() function to clarify the effects of floating-point precision limitations when calculating the determinant of a matrix. 

It includes an explanation that small numerical errors (i.e. floating point rounding error) may occur, leading to very small non-zero values instead of exactly zero for singular matrices. Additionally, an example is provided using np.isclose() to check if the determinant is effectively zero.
@charris charris changed the title Update documentation in _linalg.py for np.linalg.det() to clarify floating-point precision DOC: Update documentation of np.linalg.det() Oct 20, 2024
@fancidev
Copy link

fancidev commented Oct 21, 2024

I think it is helpful to raise awareness of numerical precision by adding a paragraph to the documentation.

For the particular case of det, I find two points that might be worth discussion:

First, it might not be a great choice to use det to test singularity. Consider the determinant of an $n \times n$ diagonal matrix with $a$ along the diagonal. Its determinant is $a^n$. If $a$ is small and $n$ is large, this can get arbitrarily small, and “effectively zero” by the np.isclose test. However, the matrix is clearly not singular. (A better way to test for singularity is to call np.linalg.matrix_rank.)

Secondly, it is somewhat tricky to use np.isclose to test floating point equality, especially with the default tolerance parameters (rtol=1e-5, atol=1e-8). In fact, the doc of np.isclose contains a section to alert about the default tolerance parameters. Picking the right tolerance might be problem-specific and I’m not aware of a choice that fits all purposes.

@charris
Copy link
Member

charris commented Oct 24, 2024

close/reopen

@charris charris closed this Oct 24, 2024
@charris charris reopened this Oct 24, 2024
@mdhaber
Copy link
Contributor

mdhaber commented Nov 14, 2024

@amitsubhashchejara the suggestion by @rkern #27554 (comment) was my first thought, too. There are many other functions for which similar notes would be equally appropriate. When we are faced with the decision of whether we want to add to all of them or just add a general section in a tutorial, the tutorial is much more maintainable. I also agree that the absolute beginners tutorial would be the right place - is there a section there where this would fit (if it's not mentioned already)?

@melissawm
Copy link
Member

See also #27871

@charris
Copy link
Member

charris commented May 10, 2025

I'm going to close this. The idea for a tutorial section on floating point precision would be good to have and det could a good example. @melissawm Can you take it from here?

@charris charris closed this May 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants