[QP Solver] In-place LDLT decomposition of KKT matrix
The most significant memory cost of the dense QP solver come form storing the KKT matrix and its decomposition. Eigen allows for in-place LDLT decomposition that reuses the coefficient matrix and to save memory. The in-place decomposition requires a reference to the coefficient matrix at construction, which is not available at that point. However, construction can be delayed using a placement new, which is illustrated below.
using linear_solver_t = Eigen::LDLT<Eigen::Ref<kkt_mat_t>>;
char linear_solver_buf[sizeof(linear_solver_t)]; // enforce some alignment somehow?
linear_solver_t* linear_solver;
//...
p = (void*) linear_solver_buf;
linear_solver = new(p) linear_solver_t(kkt_mat);
Note: Another option would be to construct the linear solver as a local object on the stack.
std::shared_pointer<linear_solver_t> linear_solver; linear_solver = make_shared<linear_solver_t>(kit_mat)
?
I need to learn how to properly insert the code. =)