Skip to content
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

Conversation

TolisChal
Copy link
Member

No description provided.

@TolisChal TolisChal requested a review from vfisikop June 24, 2024 19:24
Copy link
Contributor

@vfisikop vfisikop left a 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(),
Copy link
Contributor

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

Copy link
Member Author

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;
Copy link
Contributor

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?

Copy link
Member Author

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)
Copy link
Contributor

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

Copy link
Member Author

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
Copy link
Contributor

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?

Copy link
Contributor

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.

Copy link
Member Author

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,
Copy link
Contributor

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&?

Copy link
Member Author

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,
Copy link
Contributor

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

Copy link
Member Author

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));
Copy link
Contributor

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)

Copy link
Member Author

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,
Copy link
Contributor

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)));

Copy link
Member Author

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"
Copy link
Contributor

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

Copy link
Member Author

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
Copy link
Contributor

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?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, done

@vfisikop vfisikop merged commit 5bc28d6 into GeomScale:develop Jun 27, 2024
25 of 27 checks passed
TolisChal added a commit that referenced this pull request Jul 7, 2024
…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>
TolisChal added a commit that referenced this pull request Jul 7, 2024
…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
TolisChal added a commit to TolisChal/volume_approximation that referenced this pull request Jul 7, 2024
…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
TolisChal added a commit to TolisChal/volume_approximation that referenced this pull request Jul 7, 2024
…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
@TolisChal TolisChal deleted the generalize_rounding_loop_and_support_sparse_in_preprocessing branch July 7, 2024 03:02
TolisChal added a commit to TolisChal/volume_approximation that referenced this pull request Jul 7, 2024
…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
TolisChal added a commit to TolisChal/volume_approximation that referenced this pull request Jul 8, 2024
…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
TolisChal added a commit to TolisChal/volume_approximation that referenced this pull request Jul 8, 2024
…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
TolisChal added a commit to TolisChal/volume_approximation that referenced this pull request Jul 8, 2024
…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
TolisChal added a commit that referenced this pull request Jul 17, 2024
…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants