Skip to content

Commit e045b91

Browse files
committed
Replaced map with vector of pairs for lol sparse matrix
1 parent e0309f3 commit e045b91

File tree

2 files changed

+13
-12
lines changed

2 files changed

+13
-12
lines changed

src/optimization/cone_metric.cpp

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -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

208208
bool 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

src/optimization/cone_metric.hh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,17 +116,17 @@ public:
116116
// Initialize jacobian to the identity
117117
int num_edges = e2he.size();
118118
m_transition_jacobian_lol =
119-
std::vector<std::map<int, Scalar>>(num_edges, std::map<int, Scalar>());
119+
std::vector<std::vector<std::pair<int, Scalar>>>(num_edges, std::vector<std::pair<int, Scalar>>());
120120
for (int e = 0; e < num_edges; ++e) {
121-
m_transition_jacobian_lol[e][e] = 1.0;
121+
m_transition_jacobian_lol[e].push_back(std::make_pair(e, 1.0));
122122
}
123123
}
124124

125125
protected:
126126
std::vector<int> m_embed;
127127
std::vector<int> m_proj;
128128
MatrixX m_projection;
129-
std::vector<std::map<int, Scalar>> m_transition_jacobian_lol;
129+
std::vector<std::vector<std::pair<int, Scalar>>> m_transition_jacobian_lol;
130130

131131
VectorX reduce_metric_coordinates(const VectorX& metric_coords) const;
132132
void expand_metric_coordinates(const VectorX& metric_coords);

0 commit comments

Comments
 (0)