21 assert(in.rows() == out.rows());
22 assert(in.cols() == out.cols());
23 [[maybe_unused]]
const bool is_3x3_matrix =
24 in.rows() == 3 && in.cols() == 3;
25 [[maybe_unused]]
const bool is_9_vector =
26 in.size() == 9 && (in.rows() == 9 || in.cols() == 9);
27 assert(is_3x3_matrix || is_9_vector);
29 using so3_mat = Eigen::Matrix<real_t, 3, 3>;
30 Eigen::JacobiSVD<so3_mat> svd{
31 in.reshaped(3, 3), Eigen::ComputeFullU | Eigen::ComputeFullV};
32 so3_mat U = svd.matrixU();
33 auto &&V = svd.matrixV();
35 if (U.determinant() * V.determinant() < 0)
37 out.reshaped(3, 3).noalias() = U * V.transpose();