Skip to content

Commit a921e23

Browse files
authored
Merge pull request #538 from jcarpent/devel
Fix issue for sparse matrix conversions
2 parents 660d2ab + 58cda91 commit a921e23

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
66

77
## [Unreleased]
88

9+
### Fixed
10+
11+
- Fix handling of non sorted sparse matrix ([#538](https://github.com/stack-of-tasks/eigenpy/pull/538))
12+
913
## [3.10.3] - 2025-02-11
1014

1115
### Added

include/eigenpy/sparse/eigen-from-python.hpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//
2-
// Copyright (c) 2024 INRIA
2+
// Copyright (c) 2024-2025 INRIA
33
//
44

55
#ifndef __eigenpy_sparse_eigen_from_python_hpp__
@@ -156,6 +156,10 @@ void eigen_sparse_matrix_from_py_construct(
156156
}
157157
MapMatOrRefType sparse_map(m, n, nnz, indptr.data(), indices_ptr, data_ptr);
158158

159+
#if EIGEN_VERSION_AT_LEAST(3, 4, 90)
160+
sparse_map.sortInnerIndices();
161+
#endif
162+
159163
new (raw_ptr) MatOrRefType(sparse_map);
160164
}
161165

unittest/python/decompositions/sparse/test_SimplicialLLT.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import numpy as np
2+
import scipy
23
from scipy.sparse import csc_matrix
34

45
import eigenpy
@@ -30,3 +31,14 @@
3031
llt.analyzePattern(A)
3132
llt.factorize(A)
3233
permutation = llt.permutationP()
34+
35+
X_sparse = scipy.sparse.random(dim, 10)
36+
B_sparse = A.dot(X_sparse)
37+
B_sparse = B_sparse.tocsc(True)
38+
39+
if not B_sparse.has_sorted_indices:
40+
B_sparse.sort_indices()
41+
42+
X_est = llt.solve(B_sparse)
43+
assert eigenpy.is_approx(X_est.toarray(), X_sparse.toarray())
44+
assert eigenpy.is_approx(A.dot(X_est.toarray()), B_sparse.toarray())

0 commit comments

Comments
 (0)