Skip to content

Commit 10030ed

Browse files
authored
linters: add ruff & isort (#441)
* sort pre-commit file * pre-commit: add ruff * pre-commit run -a * manual ruff fixes * README: add ruff badge * pre-commit: add isort * pre-commit run -a * ignore previous commit in blames * add changelog entry * replace black & isort by ruff * ruff: more linters * clean config files * pre-commit run -a * ignore previous commit in blames * fix NPY002 ref. https://numpy.org/doc/stable/reference/random/legacy.html * remove useless code * fix dtype conversion
1 parent a4bfa94 commit 10030ed

33 files changed

+160
-129
lines changed

.git-blame-ignore-revs

+6
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,8 @@
11
# pre-commit run -a (Guilhem Saurel, 2022-07-27)
22
4af05ec6781f9da65b81af8e3af8d69213f99e85
3+
4+
# pre-commit run -a (Guilhem Saurel, 2024-02-17)
5+
48fb48c83f0456de2fb612ef55df8ad789824d87
6+
7+
# pre-commit run -a (Guilhem Saurel, 2024-02-19)
8+
0bae435330ee475f8dbb11bf5e672284d294d9b3

.pre-commit-config.yaml

+27-18
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,29 @@
11
ci:
2-
autoupdate_branch: 'devel'
2+
autoupdate_branch: devel
33
repos:
4-
- repo: https://github.com/pre-commit/mirrors-clang-format
5-
rev: v17.0.6
6-
hooks:
7-
- id: clang-format
8-
args: ['--style={BasedOnStyle: Google, SortIncludes: false, Standard: Cpp03}']
9-
- repo: https://github.com/pre-commit/pre-commit-hooks
10-
rev: v4.5.0
11-
hooks:
12-
- id: trailing-whitespace
13-
- repo: https://github.com/psf/black
14-
rev: 24.2.0
15-
hooks:
16-
- id: black
17-
- repo: https://github.com/cheshirekow/cmake-format-precommit
18-
rev: v0.6.13
19-
hooks:
20-
- id: cmake-format
4+
- repo: https://github.com/astral-sh/ruff-pre-commit
5+
rev: v0.2.2
6+
hooks:
7+
- id: ruff
8+
args:
9+
- --fix
10+
- --exit-non-zero-on-fix
11+
- id: ruff-format
12+
- repo: https://github.com/cheshirekow/cmake-format-precommit
13+
rev: v0.6.13
14+
hooks:
15+
- id: cmake-format
16+
- repo: https://github.com/pappasam/toml-sort
17+
rev: v0.23.1
18+
hooks:
19+
- id: toml-sort-fix
20+
- repo: https://github.com/pre-commit/mirrors-clang-format
21+
rev: v17.0.6
22+
hooks:
23+
- id: clang-format
24+
args:
25+
- '--style={BasedOnStyle: Google, SortIncludes: false, Standard: Cpp03}'
26+
- repo: https://github.com/pre-commit/pre-commit-hooks
27+
rev: v4.5.0
28+
hooks:
29+
- id: trailing-whitespace

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
1313
- Support for `std::unique_ptr` as a return types with `StdUniquePtrCallPolicies` and `boost::python::default_call_policies` ([#433](https://github.com/stack-of-tasks/eigenpy/pull/433))
1414
- Support for `std::unique_ptr` as an internal reference with `ReturnInternalStdUniquePtr` ([#433](https://github.com/stack-of-tasks/eigenpy/pull/433))
1515
- Support for `Eigen::Simplicial{LLT,LDLT}` and `Eigen::Cholmod{Simplicial,Supernodal}{LLT,LDLT}` Cholesky de compositions ([#438](https://github.com/stack-of-tasks/eigenpy/pull/438))
16+
- Switch to ruff for lints, format, and import sort ([#441](https://github.com/stack-of-tasks/eigenpy/pull/441))
1617

1718
### Fixed
1819
- Fix the issue of missing exposition of Eigen types with __int64 scalar type ([#426](https://github.com/stack-of-tasks/eigenpy/pull/426))

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ EigenPy — Versatile and efficient Python bindings between Numpy and Eigen
88
<a href="https://anaconda.org/conda-forge/eigenpy"><img src="https://img.shields.io/conda/vn/conda-forge/eigenpy.svg" alt="Conda Version"/></a>
99
<a href="https://badge.fury.io/py/eigenpy"><img src="https://badge.fury.io/py/eigenpy.svg" alt="PyPI version"></a>
1010
<a href="https://github.com/psf/black"><img src="https://img.shields.io/badge/code%20style-black-000000.svg" alt="Code style: black"></a>
11+
<a href="https://github.com/astral-sh/ruff"><img src="https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json" alt="Linter: ruff"></a>
1112
</p>
1213

1314
**EigenPy** is an open-source framework that allows the binding of the famous [Eigen](http://eigen.tuxfamily.org) C++ library in Python via Boost.Python.

benchmarks/bench-switch.py

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
1-
from __future__ import print_function
2-
3-
import eigenpy
4-
import numpy as np
5-
61
import time # noqa
72
import timeit # noqa
83

4+
import numpy as np
95
from IPython import get_ipython
106

7+
import eigenpy
8+
119
ipython = get_ipython()
1210

1311
quat = eigenpy.Quaternion()

pyproject.toml

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[tool.ruff]
2+
extend-exclude = ["cmake"]
3+
4+
[tool.ruff.lint]
5+
extend-select = ["I", "NPY", "RUF", "UP", "W"]
6+
7+
[tool.ruff.lint.isort]
8+
known-first-party = ["eigenpy"]
9+
10+
[tool.tomlsort]
11+
all = true

python/eigenpy/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33
#
44

55
from .eigenpy_pywrap import * # noqa
6-
from .eigenpy_pywrap import __version__, __raw_version__ # noqa
6+
from .eigenpy_pywrap import __raw_version__, __version__ # noqa

unittest/python/decompositions/sparse/cholmod/test_CholmodSimplicialLDLT.py

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
1-
import eigenpy
2-
31
import numpy as np
42
from scipy.sparse import csc_matrix
53

4+
import eigenpy
5+
66
dim = 100
7-
A = np.random.rand(dim, dim)
8-
A = (A + A.T) * 0.5 + np.diag(10.0 + np.random.rand(dim))
7+
rng = np.random.default_rng()
8+
A = rng.random((dim, dim))
9+
A = (A + A.T) * 0.5 + np.diag(10.0 + rng.random(dim))
910

1011
A = csc_matrix(A)
1112

1213
llt = eigenpy.CholmodSimplicialLDLT(A)
1314

1415
assert llt.info() == eigenpy.ComputationInfo.Success
1516

16-
X = np.random.rand(dim, 20)
17+
X = rng.rand((dim, 20))
1718
B = A.dot(X)
1819
X_est = llt.solve(B)
1920
assert eigenpy.is_approx(X, X_est)

unittest/python/decompositions/sparse/cholmod/test_CholmodSimplicialLLT.py

+7-5
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
1-
import eigenpy
2-
31
import numpy as np
42
from scipy.sparse import csc_matrix
53

4+
import eigenpy
5+
66
dim = 100
7-
A = np.random.rand(dim, dim)
8-
A = (A + A.T) * 0.5 + np.diag(10.0 + np.random.rand(dim))
7+
rng = np.random.default_rng()
8+
9+
A = rng.random((dim, dim))
10+
A = (A + A.T) * 0.5 + np.diag(10.0 + rng.random(dim))
911

1012
A = csc_matrix(A)
1113

1214
llt = eigenpy.CholmodSimplicialLLT(A)
1315

1416
assert llt.info() == eigenpy.ComputationInfo.Success
1517

16-
X = np.random.rand(dim, 20)
18+
X = rng.random((dim, 20))
1719
B = A.dot(X)
1820
X_est = llt.solve(B)
1921
assert eigenpy.is_approx(X, X_est)

unittest/python/decompositions/sparse/cholmod/test_CholmodSupernodalLLT.py

+7-5
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
1-
import eigenpy
2-
31
import numpy as np
42
from scipy.sparse import csc_matrix
53

4+
import eigenpy
5+
66
dim = 100
7-
A = np.random.rand(dim, dim)
8-
A = (A + A.T) * 0.5 + np.diag(10.0 + np.random.rand(dim))
7+
rng = np.random.default_rng()
8+
9+
A = rng.random((dim, dim))
10+
A = (A + A.T) * 0.5 + np.diag(10.0 + rng.random(dim))
911

1012
A = csc_matrix(A)
1113

1214
llt = eigenpy.CholmodSupernodalLLT(A)
1315

1416
assert llt.info() == eigenpy.ComputationInfo.Success
1517

16-
X = np.random.rand(dim, 20)
18+
X = rng.random((dim, 20))
1719
B = A.dot(X)
1820
X_est = llt.solve(B)
1921
assert eigenpy.is_approx(X, X_est)

unittest/python/decompositions/sparse/test_Accelerate.py

+7-5
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,23 @@
1-
import eigenpy
2-
31
import numpy as np
42
from scipy.sparse import csc_matrix
53

4+
import eigenpy
5+
6+
rng = np.random.default_rng()
7+
68

79
def test(SolverType: type):
810
dim = 100
9-
A = np.random.rand(dim, dim)
10-
A = (A + A.T) * 0.5 + np.diag(10.0 + np.random.rand(dim))
11+
A = rng.random((dim, dim))
12+
A = (A + A.T) * 0.5 + np.diag(10.0 + rng.random(dim))
1113

1214
A = csc_matrix(A)
1315

1416
llt = SolverType(A)
1517

1618
assert llt.info() == eigenpy.ComputationInfo.Success
1719

18-
X = np.random.rand(dim, 20)
20+
X = rng.random((dim, 20))
1921
B = A.dot(X)
2022
X_est = llt.solve(B)
2123
# import pdb; pdb.set_trace()

unittest/python/decompositions/sparse/test_SimplicialLDLT.py

+7-5
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
import eigenpy
2-
31
import numpy as np
42
from scipy.sparse import csc_matrix
53

4+
import eigenpy
5+
66
dim = 100
7-
A = np.random.rand(dim, dim)
8-
A = (A + A.T) * 0.5 + np.diag(10.0 + np.random.rand(dim))
7+
rng = np.random.default_rng()
8+
9+
A = rng.random((dim, dim))
10+
A = (A + A.T) * 0.5 + np.diag(10.0 + rng.random(dim))
911

1012
A = csc_matrix(A)
1113

@@ -20,7 +22,7 @@
2022
LDU = L @ D @ U
2123
assert eigenpy.is_approx(LDU.toarray(), A.toarray())
2224

23-
X = np.random.rand(dim, 20)
25+
X = rng.random((dim, 20))
2426
B = A.dot(X)
2527
X_est = ldlt.solve(B)
2628
assert eigenpy.is_approx(X, X_est)

unittest/python/decompositions/sparse/test_SimplicialLLT.py

+7-5
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
import eigenpy
2-
31
import numpy as np
42
from scipy.sparse import csc_matrix
53

4+
import eigenpy
5+
66
dim = 100
7-
A = np.random.rand(dim, dim)
8-
A = (A + A.T) * 0.5 + np.diag(10.0 + np.random.rand(dim))
7+
rng = np.random.default_rng()
8+
9+
A = rng.random((dim, dim))
10+
A = (A + A.T) * 0.5 + np.diag(10.0 + rng.random(dim))
911

1012
A = csc_matrix(A)
1113

@@ -19,7 +21,7 @@
1921
LU = L @ U
2022
assert eigenpy.is_approx(LU.toarray(), A.toarray())
2123

22-
X = np.random.rand(dim, 20)
24+
X = rng.random((dim, 20))
2325
B = A.dot(X)
2426
X_est = llt.solve(B)
2527
assert eigenpy.is_approx(X, X_est)

unittest/python/test_LDLT.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
import eigenpy
21
import numpy as np
32

3+
import eigenpy
4+
45
dim = 100
5-
A = np.random.rand(dim, dim)
6+
rng = np.random.default_rng()
67

7-
A = (A + A.T) * 0.5 + np.diag(10.0 + np.random.rand(dim))
8+
A = rng.random((dim, dim))
9+
A = (A + A.T) * 0.5 + np.diag(10.0 + rng.random(dim))
810

911
ldlt = eigenpy.LDLT(A)
1012

@@ -16,7 +18,7 @@
1618
np.transpose(P).dot(L.dot(np.diag(D).dot(np.transpose(L).dot(P)))), A
1719
)
1820

19-
X = np.random.rand(dim, 20)
21+
X = rng.random((dim, 20))
2022
B = A.dot(X)
2123
X_est = ldlt.solve(B)
2224
assert eigenpy.is_approx(X, X_est)

unittest/python/test_LLT.py

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
1-
import eigenpy
2-
31
import numpy as np
42

3+
import eigenpy
4+
55
dim = 100
6-
A = np.random.rand(dim, dim)
6+
rng = np.random.default_rng()
77

8-
A = (A + A.T) * 0.5 + np.diag(10.0 + np.random.rand(dim))
8+
A = rng.random((dim, dim))
9+
A = (A + A.T) * 0.5 + np.diag(10.0 + rng.random(dim))
910

1011
llt = eigenpy.LLT(A)
1112

1213
L = llt.matrixL()
1314
assert eigenpy.is_approx(L.dot(np.transpose(L)), A)
1415

15-
X = np.random.rand(dim, 20)
16+
X = rng.random((dim, 20))
1617
B = A.dot(X)
1718
X_est = llt.solve(B)
1819
assert eigenpy.is_approx(X, X_est)

unittest/python/test_MINRES.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
1-
import eigenpy
21
import numpy as np
32

3+
import eigenpy
4+
45
dim = 100
6+
rng = np.random.default_rng()
57
A = np.eye(dim)
68

79
minres = eigenpy.MINRES(A)
810

9-
X = np.random.rand(dim, 20)
11+
X = rng.random((dim, 20))
1012
B = A.dot(X)
1113
X_est = minres.solve(B)
1214
print("A.dot(X_est):", A.dot(X_est))

unittest/python/test_complex.py

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
1-
from __future__ import print_function
2-
31
import numpy as np
4-
from complex import real, imag, ascomplex
2+
from complex import ascomplex, imag, real
53

64
rows = 10
75
cols = 20
6+
rng = np.random.default_rng()
87

98

109
def test(dtype):
1110
Z = np.zeros((rows, cols), dtype=dtype)
12-
Z.real = np.random.rand(rows, cols)
13-
Z.imag = np.random.rand(rows, cols)
11+
Z.real = rng.random((rows, cols))
12+
Z.imag = rng.random((rows, cols))
1413

1514
Z_real = real(Z)
1615
assert (Z_real == Z.real).all()

unittest/python/test_dimensions.py

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from __future__ import print_function
2-
31
import eigenpy
42

53
quat = eigenpy.Quaternion()

0 commit comments

Comments
 (0)