Skip to content

Implement the Cholesky decomposition #232

@astrozot

Description

@astrozot

Doing the Cholesky decomposition with Tensors.jl is significantly slower than using StaticArrays.jl, presumably because there is no specific code and everything is converted into a standard Matrix:

julia> using Tensors, StaticArrays, LinearAlgebra, BenchmarkTools

julia> A = SymmetricTensor{2,2,Float64}((1.0, 2.0, 5.0))
2×2 SymmetricTensor{2, 2, Float64, 3}:
 1.0  2.0
 2.0  5.0

julia> B = SMatrix{2,2}(1.0, 2.0, 2.0, 5.0)
2×2 SMatrix{2, 2, Float64, 4} with indices SOneTo(2)×SOneTo(2):
 1.0  2.0
 2.0  5.0

julia> @benchmark cholesky($A)
BenchmarkTools.Trial: 10000 samples with 992 evaluations per sample.
 Range (min … max):  38.306 ns …  3.228 μs  ┊ GC (min … max): 0.00% … 98.18%
 Time  (median):     43.557 ns              ┊ GC (median):    0.00%
 Time  (mean ± σ):   46.372 ns ± 71.473 ns  ┊ GC (mean ± σ):  6.35% ±  4.48%

                   ▇█▆▂▂
  ▁▅█▇▇▇▅▄▃▃▃▄▃▃▃▄▅█████▆▄▃▃▃▃▃▃▂▂▂▂▃▃▃▂▂▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁ ▃
  38.3 ns         Histogram: frequency by time        55.4 ns <

 Memory estimate: 112 bytes, allocs estimate: 2.

julia> @benchmark cholesky($B)
BenchmarkTools.Trial: 10000 samples with 1000 evaluations per sample.
 Range (min … max):  1.708 ns … 13.750 ns  ┊ GC (min … max): 0.00% … 0.00%
 Time  (median):     1.792 ns              ┊ GC (median):    0.00%
 Time  (mean ± σ):   1.864 ns ±  0.199 ns  ┊ GC (mean ± σ):  0.00% ± 0.00%

       ▅     █     ▁     ▁     ▂    ▄     ▇                  ▁
  ▅▁▁▁▁█▁▁▁▁▁█▁▁▁▁▁█▁▁▁▁▁█▁▁▁▁██▁▁▁▁█▁▁▁▁▁█▁▁▁▁▁█▁▁▁▁▁█▁▁▁▁█ █
  1.71 ns      Histogram: log(frequency) by time     2.12 ns <

 Memory estimate: 0 bytes, allocs estimate: 0.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions