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

Add a fast method for diag of Cholesky matrices #53767

Merged
merged 12 commits into from
May 20, 2024

Conversation

dev10110
Copy link
Contributor

Normally diag(C::Cholesky) throws an error, and I was forced to do diag(Array(C)).

But its faster to just compute the diagonal elements of the matrix directly, so I thought I would contribute this code.

@longemen3000
Copy link
Contributor

longemen3000 commented Mar 18, 2024

is the docstring necessary? i would say that it isn't. otherwise, seems pretty good

@jishnub jishnub added the domain:linear algebra Linear algebra label Mar 19, 2024
stdlib/LinearAlgebra/src/cholesky.jl Outdated Show resolved Hide resolved
stdlib/LinearAlgebra/test/cholesky.jl Outdated Show resolved Hide resolved
Co-authored-by: Daniel Karrasch <daniel.karrasch@posteo.de>
@dev10110
Copy link
Contributor Author

Does anyone know why the tests are failing? It seems to be failing for unrelated reasons

https://buildkite.com/julialang/julia-master/builds/34771#018e51df-687f-4c40-b2b2-a44e7ab4b249

Co-authored-by: Daniel Karrasch <daniel.karrasch@posteo.de>
@jishnub
Copy link
Contributor

jishnub commented Mar 20, 2024

You can ignore this failure.

@jishnub
Copy link
Contributor

jishnub commented Mar 20, 2024

Should tr be defined as well if diag is defined? Perhaps there could be a generic fallback tr(A) = sum(diag(A))?

@dev10110
Copy link
Contributor Author

Actually, it seems its already defined in

function tr(A::AbstractMatrix)
checksquare(A)
sum(diag(A))
end
tr(x::Number) = x

Do you think it helps to define it the way I have done it?

@dev10110
Copy link
Contributor Author

dev10110 commented Apr 8, 2024

Can the reviewers check if this is ready?

@jishnub
Copy link
Contributor

jishnub commented Apr 8, 2024

The tr method seems to be defined for AbstractMatrix types, but a Cholesky would be a Factorization, and not an AbstractMatrix. We may probably just relax the type signature of the tr method to

-function tr(A::AbstractMatrix) 
+function tr(A) 

so that any type that defines diag would get tr for free.

@dkarrasch
Copy link
Member

@dev10110 Would you be willing and able to incorporate the comments? Afterwards, this nice contribution would be ready to go.

@dkarrasch dkarrasch added the status:merge me PR is reviewed. Merge when all tests are passing label May 20, 2024
@dkarrasch dkarrasch removed the status:merge me PR is reviewed. Merge when all tests are passing label May 20, 2024
@dkarrasch dkarrasch merged commit 98f3947 into JuliaLang:master May 20, 2024
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants