From 453a760ef10e24caa64e7b925e6f2b05a7dbd69a Mon Sep 17 00:00:00 2001 From: lkdvos Date: Fri, 24 Apr 2026 13:20:55 -0400 Subject: [PATCH] Add a rudimentary precompile workload --- Project.toml | 2 ++ src/MatrixAlgebraKit.jl | 2 ++ src/precompile.jl | 67 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 71 insertions(+) create mode 100644 src/precompile.jl diff --git a/Project.toml b/Project.toml index 0c3c002d..56042dd1 100644 --- a/Project.toml +++ b/Project.toml @@ -5,6 +5,7 @@ authors = ["Jutho Haegeman , Lukas Devos, Katharine Hya [deps] LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" +PrecompileTools = "aea7be01-6a6a-4083-8856-8a6e6704d82a" [weakdeps] AMDGPU = "21141c5a-9bdb-4563-92ae-f87d6854732e" @@ -35,6 +36,7 @@ EnzymeTestUtils = "0.2.5" GenericLinearAlgebra = "0.3.19, 0.4" GenericSchur = "0.5.6" LinearAlgebra = "1" +PrecompileTools = "1" Mooncake = "0.5.27" ParallelTestRunner = "2" Random = "1" diff --git a/src/MatrixAlgebraKit.jl b/src/MatrixAlgebraKit.jl index 8d66c441..22bf79e9 100644 --- a/src/MatrixAlgebraKit.jl +++ b/src/MatrixAlgebraKit.jl @@ -129,4 +129,6 @@ include("pullbacks/eigh.jl") include("pullbacks/svd.jl") include("pullbacks/polar.jl") +include("precompile.jl") + end diff --git a/src/precompile.jl b/src/precompile.jl new file mode 100644 index 00000000..43e3a97b --- /dev/null +++ b/src/precompile.jl @@ -0,0 +1,67 @@ +using PrecompileTools: @compile_workload + +@compile_workload begin + truncation_strategies = [ + truncrank(2), trunctol(; atol = 1.0e-2), truncrank(2) & trunctol(; atol = 1.0e-2), truncerror(; atol = 1.0e-2) | truncfilter(x -> abs(x) < 1.0e-2), + ] + for T in (Float32, Float64, ComplexF32, ComplexF64) + A = diagm(ones(T, 4)) # 4×4 Matrix{T}, Hermitian, nonsingular + Atall = rand(T, 4, 2) + Awide = rand(T, 2, 4) + + # decompositions + # -------------- + qr_compact(A) + qr_full(Atall) + qr_null(Atall) + + lq_compact(A) + lq_full(Awide) + lq_null(Awide) + + svd_compact(A) + svd_full(A) + svd_vals(A) + + schur_full(A) + schur_vals(A) + + eigh_full(A) + eigh_vals(A) + + eig_full(A) + eig_vals(A) + + gen_eig_full(A, A) + gen_eig_vals(A, A) + + left_polar(A) + right_polar(A) + + # derived decompositions + left_orth(A) + left_null(A) + right_orth(A) + right_null(A) + + # truncated decompositions + for trunc in truncation_strategies + svd_trunc(A; trunc) + eigh_trunc(A; trunc) + eig_trunc(A; trunc) + end + left_orth(A; trunc = truncrank(2)) + right_orth(A; trunc = truncrank(2)) + + # projections + project_hermitian(A) + project_antihermitian(A) + project_isometric(A) + + # properties + isisometric(A) + isunitary(A) + ishermitian(A) + isantihermitian(A) + end +end