Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 9 additions & 68 deletions src/precompile.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,16 @@ if Base.VERSION >= v"1.9"
rng = MersenneTwister(7)
A = randn(rng, 4, 3, 2)
B = abs.(A)
A_med = randn(rng, 6, 5, 4)

model = JoinModel(A, 2; geometry = :canonical)
p0 = _solver_point(manifold(model), initial_point(model, :random; verbose = false))
model_med = JoinModel(A_med, 2; geometry = :canonical)
p0_med = _solver_point(
manifold(model_med),
initial_point(model_med, :random; verbose = false),
)

nn_model = JoinModel(B, 2; nonnegative = true, geometry = :softplus_metric)
p0_nn = _solver_point(
manifold(nn_model),
initial_point(nn_model, :random; verbose = false),
)

# The first LM call is dominated by JIT compilation in the operator-action
# path. Precompiling a minimal canonical and softplus NNCP workload moves
# that cost to package precompile time instead of first user execution.
# Keep this workload intentionally small: we want to cover the operator LM
# path and the public CP/NNCP frontends without forcing every user to pay
# a very large package precompile cost up front.
@compile_workload begin
# Direct LM solve path on an already-prepared canonical CP model.
# Direct LM solve on a canonical CP model covers the core operator
# least-squares path without routing through the public frontend.
solve(
LMSolver(),
model;
Expand All @@ -36,38 +25,8 @@ if Base.VERSION >= v"1.9"
verbose = false,
return_stats = true,
)
solve(
LMSolver(),
model_med;
init = :random,
p0 = p0_med,
maxiter = 1,
tol = 1e-6,
verbose = false,
return_stats = true,
)
cpd(
A,
2;
solver = :lm,
init = :random,
p0 = p0,
maxiter = 1,
tol = 1e-6,
verbose = false,
)
cpd(
A_med,
2;
solver = :lm,
init = :random,
p0 = p0_med,
maxiter = 1,
tol = 1e-6,
verbose = false,
)
# Frontend LM route with ALS warm start, which is the path users hit
# most often when they request cpd(...; solver=:lm).

# Warm-started CPD is the most common public LM entry point.
cpd(
A,
2;
Expand All @@ -78,26 +37,8 @@ if Base.VERSION >= v"1.9"
tol = 1e-6,
verbose = false,
)
cpd(
A_med,
2;
solver = :lm,
init = :alswarm,
warm_steps = 2,
maxiter = 1,
tol = 1e-6,
verbose = false,
)
nncpd(
B,
2;
solver = :lm,
init = :random,
p0 = p0_nn,
maxiter = 1,
tol = 1e-6,
verbose = false,
)

# Nonnegative LM still goes through a distinct parameterization path.
nncpd(
B,
2;
Expand Down
Loading