JuliaStats / PDMats.jl

Uniform Interface for positive definite matrices of various structures
Other
104 stars 43 forks source link

Improve performance of tri products for `PDiagMat` #185

Closed devmotion closed 11 months ago

devmotion commented 11 months ago

This PR removes the sqrt computations and permutedims calls from the tri product implementations for PDiagMat.

master

julia> using PDMats, BenchmarkTools

julia> a = PDiagMat(rand(10)); X = randn(10, 10);

julia> @btime Xt_A_X(a, X);
  366.343 ns (2 allocations: 1.75 KiB)

julia> @btime X_A_Xt(a, X);
  377.044 ns (4 allocations: 1.84 KiB)

julia> @btime Xt_invA_X(a, X);
  394.279 ns (2 allocations: 1.75 KiB)

julia> @btime X_invA_Xt(a, X);
  404.580 ns (4 allocations: 1.84 KiB)

julia> a = PDiagMat(rand(100)); X = randn(100, 100);

julia> @btime Xt_A_X(a, X);
  48.125 μs (4 allocations: 156.34 KiB)

julia> @btime X_A_Xt(a, X);
  46.333 μs (6 allocations: 156.44 KiB)

julia> @btime Xt_invA_X(a, X);
  52.667 μs (4 allocations: 156.34 KiB)

julia> @btime X_invA_Xt(a, X);
  49.166 μs (6 allocations: 156.44 KiB)

This PR

julia> using PDMats, BenchmarkTools

julia> a = PDiagMat(rand(10)); X = randn(10, 10);

julia> @btime Xt_A_X(a, X);
  252.231 ns (2 allocations: 1.75 KiB)

julia> @btime X_A_Xt(a, X);
  261.102 ns (2 allocations: 1.75 KiB)

julia> @btime Xt_invA_X(a, X);
  252.301 ns (2 allocations: 1.75 KiB)

julia> @btime X_invA_Xt(a, X);
  264.350 ns (2 allocations: 1.75 KiB)

julia> a = PDiagMat(rand(100)); X = randn(100, 100);

julia> @btime Xt_A_X(a, X);
  38.916 μs (4 allocations: 156.34 KiB)

julia> @btime X_A_Xt(a, X);
  41.792 μs (4 allocations: 156.34 KiB)

julia> @btime Xt_invA_X(a, X);
  40.542 μs (4 allocations: 156.34 KiB)

julia> @btime X_invA_Xt(a, X);
  40.667 μs (4 allocations: 156.34 KiB)
codecov-commenter commented 11 months ago

Codecov Report

All modified lines are covered by tests :white_check_mark:

Files Coverage Δ
src/pdiagmat.jl 97.47% <100.00%> (ø)

:loudspeaker: Thoughts on this report? Let us know!.