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

@inbounds in copyto! for structured broadcasting #48437

Merged
merged 4 commits into from
Feb 19, 2023
Merged

Commits on Jan 28, 2023

  1. @inbounds in diagonal broadcasting

    This seems to cut down the runtime of `D .* D` by half for `5000x5000` diagonal matrices.
    Using nightly `v"1.10.0-DEV.450"`
    ```julia
    julia> using LinearAlgebra, BenchmarkTools
    
    julia> D = Diagonal(rand(5000));
    
    julia> @Btime $D * $D;
      3.648 μs (2 allocations: 39.11 KiB)
    
    julia> @Btime $D .* $D;
      8.729 μs (2 allocations: 39.11 KiB)
    
    julia> B = Broadcast.instantiate(Broadcast.Broadcasted(*, (D, D)));
    
    julia> @Btime Base.copyto!($(copy(D)), $B);
      8.390 μs (0 allocations: 0 bytes)
    
    julia> function copyto2!(dest::Diagonal, bc::Broadcast.Broadcasted{<:LinearAlgebra.StructuredMatrixStyle})
               !LinearAlgebra.isstructurepreserving(bc) && !LinearAlgebra.fzeropreserving(bc) && return copyto!(dest, convert(Broadcast.Broadcasted{Nothing}, bc))
               axs = axes(dest)
               axes(bc) == axs || Broadcast.throwdm(axes(bc), axs)
               @inbounds for i in axs[1]
                   dest.diag[i] = Broadcast._broadcast_getindex(bc, CartesianIndex(i, i))
               end
               return dest
           end
    copyto2! (generic function with 1 method)
    
    julia> @Btime copyto2!($(copy(D)), $B);
      4.207 μs (0 allocations: 0 bytes)
    ```
    jishnub committed Jan 28, 2023
    Configuration menu
    Copy the full SHA
    ea0b163 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    83e5c93 View commit details
    Browse the repository at this point in the history

Commits on Jan 29, 2023

  1. Configuration menu
    Copy the full SHA
    f7f69e8 View commit details
    Browse the repository at this point in the history

Commits on Feb 18, 2023

  1. Configuration menu
    Copy the full SHA
    fc0c7c5 View commit details
    Browse the repository at this point in the history