Skip to content
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

[Bug] pinv for Diagonal operators returns infs that should be zero #105

Open
f0uriest opened this issue Oct 7, 2024 · 0 comments
Open
Labels
bug Something isn't working

Comments

@f0uriest
Copy link

f0uriest commented Oct 7, 2024

🐛 Bug

Basically, cola.linalg.pinv(cola.ops.Diagonal) seems to just be doing an (unmasked) elementwise inverse, which gives the wrong result for rank deficient operators.

To reproduce

np.diag(cola.linalg.pinv(cola.ops.Diagonal(np.arange(5))).to_dense())
# array([       inf, 1.        , 0.5       , 0.33333333, 0.25      ])

# if we explicitly make it a dense matrix it calls np.linalg.lstsq which gives the expected result
np.diag(cola.linalg.pinv(cola.ops.Dense(np.diag(np.arange(5)))).to_dense())
# array([0.        , 1.        , 0.5       , 0.33333333, 0.25      ])

Expected Behavior

I think the "standard" behavior for this case would be to return 0 in place of inf (or anywhere abs(A[i,i]) < eps*max(A.shape), which is what happens if you actually call np.linalg.pinv

System information

Please complete the following information:

  • CoLA Version '0.0.6'
  • JAX Version '0.4.31'
@f0uriest f0uriest added the bug Something isn't working label Oct 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant