-
Notifications
You must be signed in to change notification settings - Fork 116
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
Generalize the rounding loop and support sparse computations in preprocessing routines #312
Generalize the rounding loop and support sparse computations in preprocessing routines #312
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great addition! I have a few comments.
MT E; | ||
VT center; | ||
bool converged; | ||
std::tie(E, center, converged) = max_inscribed_ellipsoid<MT>(HP.get_mat(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe better
std::tie(E, center, converged) = max_inscribed_ellipsoid<MT>(HP.get_mat(),
HP.get_vec(), x0, max_iter, tol, reg);
to consume only 2 lines
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, done
throw std::runtime_error("max_inscribed_ellipsoid not converged"); | ||
|
||
MT A_ell = inscribed_ellipsoid_res.first.first.inverse(); | ||
MT A_ell = E; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we avoid the copy here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, done
@@ -638,6 +638,12 @@ class OrderPolytope { | |||
return false; | |||
} | |||
|
|||
// Apply linear transformation, of square matrix T^{-1}, in H-polytope P:= Ax<=b | |||
// This is most of the times for testing reasons because it might destroy the sparsity | |||
void linear_transformIt(MT const& T) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should follow naming conventions here, so linear_transform_it
or something similar
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
linear_transformIt
is the name in every polytope class. This is why I used the same here.
// Licensed under GNU LGPL.3, see LICENCE file | ||
|
||
|
||
#ifndef MATRIX_COMPUTATIONAL_OPERATOR_H |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the header guard, the filename and the class is good to have the same name (to avoid confusion). Could you please change the name of the file?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am wondering if it is simpler to just have two versions for each function (one for sparse and one for dense)
e.g.
inline static auto
initialize_chol(MT const& M)
{
using DenseMT = Eigen::Matrix<NT, Eigen::Dynamic, Eigen::Dynamic>;
using SparseMT = Eigen::SparseMatrix<NT>;
if constexpr (std::is_same<MT, DenseMT>::value)
{
return std::unique_ptr<Eigen::LLT<MT>>(new Eigen::LLT<MT>());
} else if constexpr (std::is_same<MT, SparseMT>::value)
{
// avoid using new!
std::unique_ptr<Eigen::SimplicialLLT<Eigen::SparseMatrix<NT>>> llt =
std::unique_ptr<Eigen::SimplicialLLT<Eigen::SparseMatrix<NT>>>(new Eigen::SimplicialLLT<Eigen::SparseMatrix<NT>>());
llt->analyzePattern(mat);
return llt;
} else { \\...not supported\\ }
}
This way there is not need to initialize structs with types and you just call the function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I personally like more the style with structs :)
My main "concern" is that in other header files we use structs for compile time decisions so if we use if constexpr
we introduce one more style in our code. Is there any particular reason for that?
typename Point, | ||
int ellipsopid_type = EllipsoidType::MAX_ELLIPSOID | ||
> | ||
std::tuple<MT, VT, NT> inscribed_ellipsoid_rounding(Polytope &P, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does this function changes P
? Could it be a const&
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't change anything here (remind you this was previously the max_inscribed_ellipsoid_roundin()
). This function changes P as it rounds it by applying (T, shift) on it. It returns T, shift and the scalar value for the volume calculations.
It looks good to me I'd say. I don't see any reason to copy P and round it instead.
return std::unique_ptr<Spectra::DenseSymMatProd<NT>>(new Spectra::DenseSymMatProd<NT>(E)); | ||
} | ||
|
||
inline static std::unique_ptr<Spectra::SymEigsSolver<NT, Spectra::SELECT_EIGENVALUE::BOTH_ENDS, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we can use auto
as return here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks, done
|
||
inline static std::unique_ptr<Spectra::DenseSymMatProd<NT>> get_mat_prod_op(MT const& E) | ||
{ | ||
return std::unique_ptr<Spectra::DenseSymMatProd<NT>>(new Spectra::DenseSymMatProd<NT>(E)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please do not use new
;) You can use return std::make_unique<Spectra::DenseSymMatProd<NT>>(E)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks, done
Spectra::DenseSymMatProd<NT>>> get_eigs_solver(std::unique_ptr<Spectra::DenseSymMatProd<NT>> const& op, | ||
int const n) | ||
{ | ||
return std::unique_ptr<Spectra::SymEigsSolver<NT, Spectra::SELECT_EIGENVALUE::BOTH_ENDS, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is too long.
What about
using SymEigsSolver = Spectra::SymEigsSolver
<
NT,
Spectra::SELECT_EIGENVALUE::BOTH_ENDS,
Spectra::DenseSymMatProd<NT>
>;
return std::unique_ptr<SymEigsSolver>(new SymEigsSolver(op.get(), 2, std::min(std::max(10, n/5), n)));
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, done
@@ -11,6 +11,8 @@ | |||
#ifndef MAX_INNER_BALL | |||
#define MAX_INNER_BALL | |||
|
|||
#include "mat_computational_operator.h" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please use the full path
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks, done
@@ -296,6 +296,10 @@ add_test(NAME test_round_max_ellipsoid | |||
COMMAND new_rounding_test -tc=round_max_ellipsoid) | |||
add_test(NAME test_round_svd | |||
COMMAND new_rounding_test -tc=round_svd) | |||
add_test(NAME test_round_log_barrier_test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we just call it rounding_test
now?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, done
…se_in_preprocessing
…ocessing routines (#312) * generalize rounding loop * support sparse cholesky operator * complete sparse support in max_inscribed_ball * complete sparse support in preprocesing * add sparse tests * change main rounding function name * improve explaining comments * resolve PR comments * changing the dates in copyrights * use if constexpr instead of SNIFAE * update the examples to cpp17 * update to cpp17 order polytope example * fix templating in mat_computational_operators * fix templating errors and change header file to mat_computational_operators --------- Authored-by: Apostolos Chalkis (TolisChal) <tolis.chal@gmail.com>
…ocessing routines (#312) * generalize rounding loop * support sparse cholesky operator * complete sparse support in max_inscribed_ball * complete sparse support in preprocesing * add sparse tests * change main rounding function name * improve explaining comments * resolve PR comments * changing the dates in copyrights * use if constexpr instead of SNIFAE * update the examples to cpp17 * update to cpp17 order polytope example * fix templating in mat_computational_operators * fix templating errors and change header file to mat_computational_operators
…ocessing routines (GeomScale#312) * generalize rounding loop * support sparse cholesky operator * complete sparse support in max_inscribed_ball * complete sparse support in preprocesing * add sparse tests * change main rounding function name * improve explaining comments * resolve PR comments * changing the dates in copyrights * use if constexpr instead of SNIFAE * update the examples to cpp17 * update to cpp17 order polytope example * fix templating in mat_computational_operators * fix templating errors and change header file to mat_computational_operators
…ocessing routines (GeomScale#312) * generalize rounding loop * support sparse cholesky operator * complete sparse support in max_inscribed_ball * complete sparse support in preprocesing * add sparse tests * change main rounding function name * improve explaining comments * resolve PR comments * changing the dates in copyrights * use if constexpr instead of SNIFAE * update the examples to cpp17 * update to cpp17 order polytope example * fix templating in mat_computational_operators * fix templating errors and change header file to mat_computational_operators
…ocessing routines (GeomScale#312) * generalize rounding loop * support sparse cholesky operator * complete sparse support in max_inscribed_ball * complete sparse support in preprocesing * add sparse tests * change main rounding function name * improve explaining comments * resolve PR comments * changing the dates in copyrights * use if constexpr instead of SNIFAE * update the examples to cpp17 * update to cpp17 order polytope example * fix templating in mat_computational_operators * fix templating errors and change header file to mat_computational_operators
…ocessing routines (GeomScale#312) * generalize rounding loop * support sparse cholesky operator * complete sparse support in max_inscribed_ball * complete sparse support in preprocesing * add sparse tests * change main rounding function name * improve explaining comments * resolve PR comments * changing the dates in copyrights * use if constexpr instead of SNIFAE * update the examples to cpp17 * update to cpp17 order polytope example * fix templating in mat_computational_operators * fix templating errors and change header file to mat_computational_operators
…ocessing routines (GeomScale#312) * generalize rounding loop * support sparse cholesky operator * complete sparse support in max_inscribed_ball * complete sparse support in preprocesing * add sparse tests * change main rounding function name * improve explaining comments * resolve PR comments * changing the dates in copyrights * use if constexpr instead of SNIFAE * update the examples to cpp17 * update to cpp17 order polytope example * fix templating in mat_computational_operators * fix templating errors and change header file to mat_computational_operators
…ocessing routines (GeomScale#312) * generalize rounding loop * support sparse cholesky operator * complete sparse support in max_inscribed_ball * complete sparse support in preprocesing * add sparse tests * change main rounding function name * improve explaining comments * resolve PR comments * changing the dates in copyrights * use if constexpr instead of SNIFAE * update the examples to cpp17 * update to cpp17 order polytope example * fix templating in mat_computational_operators * fix templating errors and change header file to mat_computational_operators
…ocessing routines (#312) * generalize rounding loop * support sparse cholesky operator * complete sparse support in max_inscribed_ball * complete sparse support in preprocesing * add sparse tests * change main rounding function name * improve explaining comments * resolve PR comments * changing the dates in copyrights * use if constexpr instead of SNIFAE * update the examples to cpp17 * update to cpp17 order polytope example * fix templating in mat_computational_operators * fix templating errors and change header file to mat_computational_operators
No description provided.