@@ -114,9 +114,9 @@ PennerConeMetric::PennerConeMetric(const Mesh<Scalar>& m, const VectorX& metric_
114114 // Initialize jacobian to the identity
115115 int num_edges = e2he.size ();
116116 m_transition_jacobian_lol =
117- std::vector<std::map< int , Scalar>>(num_edges, std::map< int , Scalar>());
117+ std::vector<std::vector<std::pair< int , Scalar>>> (num_edges, std::vector<std::pair< int , Scalar> >());
118118 for (int e = 0 ; e < num_edges; ++e) {
119- m_transition_jacobian_lol[e][e] = 1.0 ;
119+ m_transition_jacobian_lol[e]. push_back ( std::make_pair (e, 1.0 )) ;
120120 }
121121}
122122
@@ -207,8 +207,6 @@ std::unique_ptr<DifferentiableConeMetric> PennerConeMetric::project_to_constrain
207207
208208bool PennerConeMetric::flip_ccw (int _h, bool Ptolemy)
209209{
210- Scalar zero_threshold = 1e-15 ;
211-
212210 // Perform the flip in the base class
213211 bool success = DifferentiableConeMetric::flip_ccw (_h, Ptolemy);
214212
@@ -241,18 +239,21 @@ bool PennerConeMetric::flip_ccw(int _h, bool Ptolemy)
241239 std::vector<int > Pd_edges = {ed, ea, ebo, eao, eb};
242240 std::vector<Scalar> Pd_scalars =
243241 {-1.0 , x / (1.0 + x), x / (1.0 + x), 1.0 / (1.0 + x), 1.0 / (1.0 + x)};
242+ int num_entries = 0 ;
243+ for (int i = 0 ; i < 5 ; ++i) {
244+ int ei = Pd_edges[i];
245+ num_entries += m_transition_jacobian_lol[ei].size ();
246+ }
244247
245248 // Compute the new row of J_del corresponding to edge ed, which is the only
246249 // edge that changes
247- std::map<int , Scalar> J_del_d_new;
250+ std::vector<std::pair<int , Scalar>> J_del_d_new;
251+ J_del_d_new.reserve (num_entries);
248252 for (int i = 0 ; i < 5 ; ++i) {
249253 int ei = Pd_edges[i];
250254 Scalar Di = Pd_scalars[i];
251255 for (auto it : m_transition_jacobian_lol[ei]) {
252- J_del_d_new[it.first ] += Di * it.second ;
253-
254- // Delete the updated entry if it is near 0
255- if (abs (J_del_d_new[it.first ]) < zero_threshold) J_del_d_new.erase (it.first );
256+ J_del_d_new.push_back (std::make_pair (it.first , Di * it.second ));
256257 }
257258 }
258259
0 commit comments