Skip to content
Snippets Groups Projects
Unverified Commit 10030ede authored by Guilhem Saurel's avatar Guilhem Saurel Committed by GitHub
Browse files

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
parent a4bfa94c
No related branches found
No related tags found
No related merge requests found
Pipeline #36573 passed with warnings
Showing
with 125 additions and 87 deletions
# pre-commit run -a (Guilhem Saurel, 2022-07-27)
4af05ec6781f9da65b81af8e3af8d69213f99e85
# pre-commit run -a (Guilhem Saurel, 2024-02-17)
48fb48c83f0456de2fb612ef55df8ad789824d87
# pre-commit run -a (Guilhem Saurel, 2024-02-19)
0bae435330ee475f8dbb11bf5e672284d294d9b3
ci:
autoupdate_branch: 'devel'
autoupdate_branch: devel
repos:
- repo: https://github.com/pre-commit/mirrors-clang-format
rev: v17.0.6
hooks:
- id: clang-format
args: ['--style={BasedOnStyle: Google, SortIncludes: false, Standard: Cpp03}']
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
hooks:
- id: trailing-whitespace
- repo: https://github.com/psf/black
rev: 24.2.0
hooks:
- id: black
- repo: https://github.com/cheshirekow/cmake-format-precommit
rev: v0.6.13
hooks:
- id: cmake-format
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.2.2
hooks:
- id: ruff
args:
- --fix
- --exit-non-zero-on-fix
- id: ruff-format
- repo: https://github.com/cheshirekow/cmake-format-precommit
rev: v0.6.13
hooks:
- id: cmake-format
- repo: https://github.com/pappasam/toml-sort
rev: v0.23.1
hooks:
- id: toml-sort-fix
- repo: https://github.com/pre-commit/mirrors-clang-format
rev: v17.0.6
hooks:
- id: clang-format
args:
- '--style={BasedOnStyle: Google, SortIncludes: false, Standard: Cpp03}'
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
hooks:
- id: trailing-whitespace
......@@ -13,6 +13,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- 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))
- Support for `std::unique_ptr` as an internal reference with `ReturnInternalStdUniquePtr` ([#433](https://github.com/stack-of-tasks/eigenpy/pull/433))
- 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))
- Switch to ruff for lints, format, and import sort ([#441](https://github.com/stack-of-tasks/eigenpy/pull/441))
### Fixed
- Fix the issue of missing exposition of Eigen types with __int64 scalar type ([#426](https://github.com/stack-of-tasks/eigenpy/pull/426))
......
......@@ -8,6 +8,7 @@ EigenPy — Versatile and efficient Python bindings between Numpy and Eigen
<a href="https://anaconda.org/conda-forge/eigenpy"><img src="https://img.shields.io/conda/vn/conda-forge/eigenpy.svg" alt="Conda Version"/></a>
<a href="https://badge.fury.io/py/eigenpy"><img src="https://badge.fury.io/py/eigenpy.svg" alt="PyPI version"></a>
<a href="https://github.com/psf/black"><img src="https://img.shields.io/badge/code%20style-black-000000.svg" alt="Code style: black"></a>
<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>
</p>
**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.
......
from __future__ import print_function
import eigenpy
import numpy as np
import time # noqa
import timeit # noqa
import numpy as np
from IPython import get_ipython
import eigenpy
ipython = get_ipython()
quat = eigenpy.Quaternion()
......
[tool.ruff]
extend-exclude = ["cmake"]
[tool.ruff.lint]
extend-select = ["I", "NPY", "RUF", "UP", "W"]
[tool.ruff.lint.isort]
known-first-party = ["eigenpy"]
[tool.tomlsort]
all = true
......@@ -3,4 +3,4 @@
#
from .eigenpy_pywrap import * # noqa
from .eigenpy_pywrap import __version__, __raw_version__ # noqa
from .eigenpy_pywrap import __raw_version__, __version__ # noqa
import eigenpy
import numpy as np
from scipy.sparse import csc_matrix
import eigenpy
dim = 100
A = np.random.rand(dim, dim)
A = (A + A.T) * 0.5 + np.diag(10.0 + np.random.rand(dim))
rng = np.random.default_rng()
A = rng.random((dim, dim))
A = (A + A.T) * 0.5 + np.diag(10.0 + rng.random(dim))
A = csc_matrix(A)
......@@ -13,7 +14,7 @@ llt = eigenpy.CholmodSimplicialLDLT(A)
assert llt.info() == eigenpy.ComputationInfo.Success
X = np.random.rand(dim, 20)
X = rng.rand((dim, 20))
B = A.dot(X)
X_est = llt.solve(B)
assert eigenpy.is_approx(X, X_est)
......
import eigenpy
import numpy as np
from scipy.sparse import csc_matrix
import eigenpy
dim = 100
A = np.random.rand(dim, dim)
A = (A + A.T) * 0.5 + np.diag(10.0 + np.random.rand(dim))
rng = np.random.default_rng()
A = rng.random((dim, dim))
A = (A + A.T) * 0.5 + np.diag(10.0 + rng.random(dim))
A = csc_matrix(A)
......@@ -13,7 +15,7 @@ llt = eigenpy.CholmodSimplicialLLT(A)
assert llt.info() == eigenpy.ComputationInfo.Success
X = np.random.rand(dim, 20)
X = rng.random((dim, 20))
B = A.dot(X)
X_est = llt.solve(B)
assert eigenpy.is_approx(X, X_est)
......
import eigenpy
import numpy as np
from scipy.sparse import csc_matrix
import eigenpy
dim = 100
A = np.random.rand(dim, dim)
A = (A + A.T) * 0.5 + np.diag(10.0 + np.random.rand(dim))
rng = np.random.default_rng()
A = rng.random((dim, dim))
A = (A + A.T) * 0.5 + np.diag(10.0 + rng.random(dim))
A = csc_matrix(A)
......@@ -13,7 +15,7 @@ llt = eigenpy.CholmodSupernodalLLT(A)
assert llt.info() == eigenpy.ComputationInfo.Success
X = np.random.rand(dim, 20)
X = rng.random((dim, 20))
B = A.dot(X)
X_est = llt.solve(B)
assert eigenpy.is_approx(X, X_est)
......
import eigenpy
import numpy as np
from scipy.sparse import csc_matrix
import eigenpy
rng = np.random.default_rng()
def test(SolverType: type):
dim = 100
A = np.random.rand(dim, dim)
A = (A + A.T) * 0.5 + np.diag(10.0 + np.random.rand(dim))
A = rng.random((dim, dim))
A = (A + A.T) * 0.5 + np.diag(10.0 + rng.random(dim))
A = csc_matrix(A)
......@@ -15,7 +17,7 @@ def test(SolverType: type):
assert llt.info() == eigenpy.ComputationInfo.Success
X = np.random.rand(dim, 20)
X = rng.random((dim, 20))
B = A.dot(X)
X_est = llt.solve(B)
# import pdb; pdb.set_trace()
......
import eigenpy
import numpy as np
from scipy.sparse import csc_matrix
import eigenpy
dim = 100
A = np.random.rand(dim, dim)
A = (A + A.T) * 0.5 + np.diag(10.0 + np.random.rand(dim))
rng = np.random.default_rng()
A = rng.random((dim, dim))
A = (A + A.T) * 0.5 + np.diag(10.0 + rng.random(dim))
A = csc_matrix(A)
......@@ -20,7 +22,7 @@ D = csc_matrix(np.diag(ldlt.vectorD()))
LDU = L @ D @ U
assert eigenpy.is_approx(LDU.toarray(), A.toarray())
X = np.random.rand(dim, 20)
X = rng.random((dim, 20))
B = A.dot(X)
X_est = ldlt.solve(B)
assert eigenpy.is_approx(X, X_est)
......
import eigenpy
import numpy as np
from scipy.sparse import csc_matrix
import eigenpy
dim = 100
A = np.random.rand(dim, dim)
A = (A + A.T) * 0.5 + np.diag(10.0 + np.random.rand(dim))
rng = np.random.default_rng()
A = rng.random((dim, dim))
A = (A + A.T) * 0.5 + np.diag(10.0 + rng.random(dim))
A = csc_matrix(A)
......@@ -19,7 +21,7 @@ U = llt.matrixU()
LU = L @ U
assert eigenpy.is_approx(LU.toarray(), A.toarray())
X = np.random.rand(dim, 20)
X = rng.random((dim, 20))
B = A.dot(X)
X_est = llt.solve(B)
assert eigenpy.is_approx(X, X_est)
......
import eigenpy
import numpy as np
import eigenpy
dim = 100
A = np.random.rand(dim, dim)
rng = np.random.default_rng()
A = (A + A.T) * 0.5 + np.diag(10.0 + np.random.rand(dim))
A = rng.random((dim, dim))
A = (A + A.T) * 0.5 + np.diag(10.0 + rng.random(dim))
ldlt = eigenpy.LDLT(A)
......@@ -16,7 +18,7 @@ assert eigenpy.is_approx(
np.transpose(P).dot(L.dot(np.diag(D).dot(np.transpose(L).dot(P)))), A
)
X = np.random.rand(dim, 20)
X = rng.random((dim, 20))
B = A.dot(X)
X_est = ldlt.solve(B)
assert eigenpy.is_approx(X, X_est)
......
import eigenpy
import numpy as np
import eigenpy
dim = 100
A = np.random.rand(dim, dim)
rng = np.random.default_rng()
A = (A + A.T) * 0.5 + np.diag(10.0 + np.random.rand(dim))
A = rng.random((dim, dim))
A = (A + A.T) * 0.5 + np.diag(10.0 + rng.random(dim))
llt = eigenpy.LLT(A)
L = llt.matrixL()
assert eigenpy.is_approx(L.dot(np.transpose(L)), A)
X = np.random.rand(dim, 20)
X = rng.random((dim, 20))
B = A.dot(X)
X_est = llt.solve(B)
assert eigenpy.is_approx(X, X_est)
......
import eigenpy
import numpy as np
import eigenpy
dim = 100
rng = np.random.default_rng()
A = np.eye(dim)
minres = eigenpy.MINRES(A)
X = np.random.rand(dim, 20)
X = rng.random((dim, 20))
B = A.dot(X)
X_est = minres.solve(B)
print("A.dot(X_est):", A.dot(X_est))
......
from __future__ import print_function
import numpy as np
from complex import real, imag, ascomplex
from complex import ascomplex, imag, real
rows = 10
cols = 20
rng = np.random.default_rng()
def test(dtype):
Z = np.zeros((rows, cols), dtype=dtype)
Z.real = np.random.rand(rows, cols)
Z.imag = np.random.rand(rows, cols)
Z.real = rng.random((rows, cols))
Z.imag = rng.random((rows, cols))
Z_real = real(Z)
assert (Z_real == Z.real).all()
......
from __future__ import print_function
import eigenpy
quat = eigenpy.Quaternion()
......
import numpy as np
from eigen_ref import (
printMatrix,
getRefToStatic,
asRef,
asConstRef,
asRef,
copyRowVectorFromConstRef,
copyVectorFromConstRef,
editBlock,
fill,
getBlock,
editBlock,
modify_block,
getRefToStatic,
has_ref_member,
copyVectorFromConstRef,
copyRowVectorFromConstRef,
modify_block,
printMatrix,
)
......@@ -60,7 +60,7 @@ def test_read_block():
def test_create_ref(mat):
print("[asRef(mat)]")
ref = asRef(mat)
assert np.array_equal(ref, mat), "ref=\n{}\nmat=\n{}".format(ref, mat)
assert np.array_equal(ref, mat), f"ref=\n{ref}\nmat=\n{mat}"
assert not (ref.flags.owndata)
assert ref.flags.writeable
......@@ -68,7 +68,7 @@ def test_create_ref(mat):
def test_create_const_ref(mat):
print("[asConstRef]")
const_ref = asConstRef(mat)
assert np.array_equal(const_ref, mat), "ref=\n{}\nmat=\n{}".format(const_ref, mat)
assert np.array_equal(const_ref, mat), f"ref=\n{const_ref}\nmat=\n{mat}"
assert not (const_ref.flags.writeable)
assert not (const_ref.flags.owndata)
......@@ -79,11 +79,11 @@ def test_edit_block(rows, cols):
mat[:, :] = np.arange(rows * cols).reshape(rows, cols)
mat0 = mat.copy()
for i, rowsize, colsize in ([0, 3, 2], [1, 1, 2], [0, 3, 1]):
print("taking block [{}:{}, {}:{}]".format(i, rowsize + i, 0, colsize))
print(f"taking block [{i}:{rowsize + i}, {0}:{colsize}]")
B = getBlock(mat, i, 0, rowsize, colsize)
B = B.reshape(rowsize, colsize)
lhs = mat[i : rowsize + i, :colsize]
assert np.array_equal(lhs, B), "got lhs\n{}\nrhs B=\n{}".format(lhs, B)
assert np.array_equal(lhs, B), f"got lhs\n{lhs}\nrhs B=\n{B}"
B[:] = 1.0
rhs = np.ones((rowsize, colsize))
......@@ -100,9 +100,6 @@ def test_edit_block(rows, cols):
assert np.array_equal(mat, mat_copy)
class ModifyBlockImpl(modify_block):
def __init__(self):
super(ModifyBlockImpl, self).__init__()
def call(self, mat):
n, m = mat.shape
mat[:, :] = np.arange(n * m).reshape(n, m)
......
import numpy as np
import eigenpy
dim = 100
A = np.random.rand(dim, dim)
rng = np.random.default_rng()
A = rng.random((dim, dim))
es = eigenpy.EigenSolver(A)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment