MatrixXf M(MatrixXf::Zero((R + 1) * (R + 1), (R + 1) * (R + 1)));
MatrixXf r_uv_flattened(MatrixXf::Zero((R + 1) * (R + 1), 1));
for (int outer_i = 0; outer_i < 2 * R + 1; ++outer_i) {
MatrixXf M(MatrixXf::Zero((R + 1) * (R + 1), (R + 1) * (R + 1)));
MatrixXf r_uv_flattened(MatrixXf::Zero((R + 1) * (R + 1), 1));
for (int outer_i = 0; outer_i < 2 * R + 1; ++outer_i) {