Skip to content

Commit 5e1c9c8

Browse files
Nianle-LiCopilot
andauthored
Apply suggestion from @Copilot
Co-authored-by: Copilot <[email protected]>
1 parent 99451f7 commit 5e1c9c8

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

cpp_easygraph/functions/centrality/eigenvector.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -228,22 +228,22 @@ std::vector<double> compute_eigenvector_eigen(
228228
std::vector<double> result(n);
229229

230230
try {
231-
Eigen::SelfAdjointEigenSolver<Eigen::MatrixXd> solver;
231+
Eigen::EigenSolver<Eigen::MatrixXd> solver;
232232

233233
if (n < 1000) {
234234
Eigen::MatrixXd dense_matrix(eigen_matrix);
235235
solver.compute(dense_matrix);
236236

237237
int max_idx = 0;
238-
double max_val = solver.eigenvalues()[0];
238+
double max_val = solver.eigenvalues()[0].real();
239239
for (int i = 1; i < n; i++) {
240-
if (solver.eigenvalues()[i] > max_val) {
241-
max_val = solver.eigenvalues()[i];
240+
if (solver.eigenvalues()[i].real() > max_val) {
241+
max_val = solver.eigenvalues()[i].real();
242242
max_idx = i;
243243
}
244244
}
245245

246-
Eigen::VectorXd eigen_vec = solver.eigenvectors().col(max_idx);
246+
Eigen::VectorXd eigen_vec = solver.eigenvectors().col(max_idx).real();
247247
for (int i = 0; i < n; i++) {
248248
result[i] = eigen_vec(i);
249249
}

0 commit comments

Comments
 (0)