-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Copy parent in copy_similar for Symmetric/Hermitian #54473
Conversation
What is the timing without compilation? I had a quick look and the only difference is that Symmetric goes through julia/stdlib/LinearAlgebra/src/symmetric.jl Line 317 in 5949e0b
|
This PR is primarily about faster compilation. The difference mainly arises from the fact that julia> using LinearAlgebra
julia> A = rand(1000,1000); H = Hermitian(A); B = similar(A);
julia> @time copyto!(B, A);
0.024590 seconds (38.30 k allocations: 1.943 MiB, 81.51% compilation time) vs julia> @time copyto!(B, H);
0.122573 seconds (178.02 k allocations: 9.301 MiB, 13.93% gc time, 95.64% compilation time) Even leaving the compilation-time aside, the julia> @btime copyto!($B, $A);
475.371 μs (0 allocations: 0 bytes)
julia> @btime copyto!($B, $H);
1.737 ms (0 allocations: 0 bytes) However, in this specific context, this difference may not matter much, if at all. |
What if we specialized |
The docstring of |
BTW, should we make use of |
I went ahead and opened #54476, since it's orthogonal to this PR, but allows for more options. |
I don't think we should call |
I've timed the With eigencopy_oftype(A::Hermitian, S) = Hermitian(copytrito!(similar(parent(A), S, size(A)), A.data, A.uplo), sym_uplo(A.uplo)) we obtain julia> using LinearAlgebra
julia> A = rand(200,200); H = Hermitian(A);
julia> @time eigen(H);
0.299632 seconds (318.16 k allocations: 17.390 MiB, 97.93% compilation time)
julia> @btime eigen!($H);
5.333 ms (20 allocations: 698.94 KiB) whereas, with the julia> @time eigen(H);
0.274765 seconds (326.63 k allocations: 17.926 MiB, 98.01% compilation time)
julia> @btime eigen!($H);
5.505 ms (20 allocations: 698.94 KiB) Perhaps we should go with |
Hm, failures look real. Something about reference to undefined objects in |
Yeah, that's one potential catch with using |
I don't have time right now to work it out, but as an option, can we catch the potentially bad cases in |
The specific failing test should be fixed by #54491 |
The failing |
The failing |
Awesome, how many further improvements this has triggered through failing tests. 🤣 |
This should be equivalent to copying the `Symmetric`/`Hermitian` matrix, as only one triangular half is used. However, this reduces latency when the parent is a `Matrix` (and possibly others too, although I've not checked this). ```julia julia> using LinearAlgebra julia> A = rand(2,2); H = Hermitian(A); julia> @time eigen(H); 0.342207 seconds (440.61 k allocations: 22.926 MiB, 99.95% compilation time) # nightly 0.260913 seconds (326.62 k allocations: 16.926 MiB, 99.93% compilation time) # This PR ``` Copying the parent is also marginally faster, although this doesn't really matter in `eigen`: ```julia julia> A = rand(1000,1000); H = Hermitian(A); julia> @Btime LinearAlgebra.copy_similar($H, Float64); 1.839 ms (3 allocations: 7.63 MiB) # nightly 1.760 ms (3 allocations: 7.63 MiB) # This PR ``` --------- Co-authored-by: Daniel Karrasch <daniel.karrasch@posteo.de>
This should be equivalent to copying the
Symmetric
/Hermitian
matrix, as only one triangular half is used. However, this reduces latency when the parent is aMatrix
(and possibly others too, although I've not checked this).Copying the parent is also marginally faster, although this doesn't really matter in
eigen
: