Skip to content

Added precompilation for nonnegative least squares #809

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

Merged
merged 3 commits into from
Aug 29, 2024
Merged
Changes from 1 commit
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
30 changes: 30 additions & 0 deletions lib/OptimizationOptimJL/src/OptimizationOptimJL.jl
Original file line number Diff line number Diff line change
Expand Up @@ -453,4 +453,34 @@ function SciMLBase.__solve(cache::OptimizationCache{
stats = stats)
end


PrecompileTools.@compile_workload begin

function obj_f(x, p)
A = p[1]
b = p[2]
return sum((A * x - b) .^ 2)
end

function solve_nonnegative_least_squares(A, b, solver)

optf = Optimization.OptimizationFunction(obj_f, Optimization.AutoForwardDiff())
prob = Optimization.OptimizationProblem(optf, ones(size(A, 2)), (A, b), lb=zeros(size(A, 2)), ub=Inf * ones(size(A, 2)))
x = OptimizationOptimJL.solve(prob, solver, maxiters=5000, maxtime=100)

return x
end

solver_list = [OptimizationOptimJL.LBFGS(),
OptimizationOptimJL.ConjugateGradient(),
OptimizationOptimJL.GradientDescent(),
OptimizationOptimJL.BFGS()]

for solver in solver_list
x = solve_nonnegative_least_squares(rand(4, 4), rand(4), solver)
x = solve_nonnegative_least_squares(rand(35, 35), rand(35), solver)
x = solve_nonnegative_least_squares(rand(35, 10), rand(35), solver)
end
end

end
Loading