From 9a5f394d1eba2f7d8177153367813d6b685fcfe0 Mon Sep 17 00:00:00 2001 From: Gregor Lichtner Date: Mon, 7 Aug 2023 16:34:40 +0200 Subject: [PATCH 1/5] releasing GIL before c function calls --- .pre-commit-config.yaml | 12 ++++++------ pystackreg/__init__.py | 4 ++-- src/pymain.cpp | 4 ++++ 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index d5e43d6..8e1374d 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,7 +1,7 @@ exclude: '^docs/' repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.3.0 + rev: v4.4.0 hooks: - id: trailing-whitespace exclude: '^.bumpversion.cfg$' @@ -10,19 +10,19 @@ repos: - id: pretty-format-json args: ['--autofix', '--no-sort-keys'] - repo: https://github.com/ambv/black - rev: 22.6.0 + rev: 23.7.0 hooks: - id: black -- repo: https://gitlab.com/pycqa/flake8 - rev: 4.0.1 +- repo: https://github.com/PyCQA/flake8 + rev: '6.1.0' hooks: - id: flake8 - repo: https://github.com/pre-commit/mirrors-mypy - rev: v0.961 + rev: v1.4.1 hooks: - id: mypy - repo: https://github.com/codespell-project/codespell - rev: 'v2.1.0' + rev: 'v2.2.5' hooks: - id: codespell name: codespell diff --git a/pystackreg/__init__.py b/pystackreg/__init__.py index 880a8dd..9d60142 100644 --- a/pystackreg/__init__.py +++ b/pystackreg/__init__.py @@ -1,3 +1,3 @@ # -*- coding: utf-8 -*- -from .pystackreg import StackReg -from .version import __version__ +from pystackreg.pystackreg import StackReg +from pystackreg.version import __version__ diff --git a/src/pymain.cpp b/src/pymain.cpp index 7f2e2ea..98d8f93 100644 --- a/src/pymain.cpp +++ b/src/pymain.cpp @@ -184,8 +184,10 @@ PyObject *turbogreg_register(PyObject *self, PyObject *args) { double *img_ref = (double *)PyArray_DATA(ref_array); double *img_mov = (double *)PyArray_DATA(mov_array); + Py_BEGIN_ALLOW_THREADS registerImg(img_ref, img_mov, (Transformation)tf, Ny_ref, Nx_ref, rm); // width and height (Nx/Ny) have to be swapped! + Py_END_ALLOW_THREADS /* clean up */ Py_XDECREF(ref_array); @@ -265,9 +267,11 @@ PyObject *turbogreg_transform(PyObject *self, PyObject *args) { matrix m(Nx_mat, Ny_mat); memcpy(m.begin(), tmat, (Nx_mat * Ny_mat * sizeof(double))); + Py_BEGIN_ALLOW_THREADS std::vector imgout = transformImg(m, img_mov, Ny_mov, Nx_mov); // width and height (Nx/Ny) have to be swapped! + Py_END_ALLOW_THREADS /* clean up */ Py_XDECREF(mat_array); From d2c1c7d889424169903f0aabbe0e5a2220155efa Mon Sep 17 00:00:00 2001 From: Lint Action Date: Mon, 7 Aug 2023 14:35:58 +0000 Subject: [PATCH 2/5] Fix code style issues with Black --- pystackreg/pystackreg.py | 1 - tests/test_pystackreg.py | 1 - 2 files changed, 2 deletions(-) diff --git a/pystackreg/pystackreg.py b/pystackreg/pystackreg.py index 957ed08..79d2cb9 100644 --- a/pystackreg/pystackreg.py +++ b/pystackreg/pystackreg.py @@ -363,7 +363,6 @@ def register_stack( iterable = tqdm(iterable) for i in iterable: - slc = [slice(None)] * len(img.shape) slc[axis] = i diff --git a/tests/test_pystackreg.py b/tests/test_pystackreg.py index d7ad56b..1d8471b 100644 --- a/tests/test_pystackreg.py +++ b/tests/test_pystackreg.py @@ -62,7 +62,6 @@ def stack_bilinear(): def load_file(transformation): - if transformation == "unregistered": fname = prefix + "-unreg" else: From 921d974cdc055686aa7a8a555babd15eb101b5b2 Mon Sep 17 00:00:00 2001 From: Gregor Lichtner Date: Mon, 7 Aug 2023 16:37:13 +0200 Subject: [PATCH 3/5] updated instance check --- pystackreg/util/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pystackreg/util/__init__.py b/pystackreg/util/__init__.py index 43c9760..b2644f3 100644 --- a/pystackreg/util/__init__.py +++ b/pystackreg/util/__init__.py @@ -44,7 +44,7 @@ def to_int_dtype(arr: np.ndarray, dtype: type): :rtype: ndarray(Ni..., Nj..., Nk...) :return: Input array clipped & rounded to integer dtype """ - assert type(arr) == np.ndarray, "Input must be a numpy array" + assert isinstance(arr, np.ndarray), "Input must be a numpy array" if not np.issubdtype(dtype, np.integer): return arr From 4ffe0c45c9c9ef06d94628e4b5e5469cb98354f7 Mon Sep 17 00:00:00 2001 From: Gregor Lichtner Date: Mon, 7 Aug 2023 16:41:53 +0200 Subject: [PATCH 4/5] fixed c error --- src/pymain.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/pymain.cpp b/src/pymain.cpp index 98d8f93..535ae2e 100644 --- a/src/pymain.cpp +++ b/src/pymain.cpp @@ -267,8 +267,10 @@ PyObject *turbogreg_transform(PyObject *self, PyObject *args) { matrix m(Nx_mat, Ny_mat); memcpy(m.begin(), tmat, (Nx_mat * Ny_mat * sizeof(double))); + std::vector imgout; + Py_BEGIN_ALLOW_THREADS - std::vector imgout = + imgout = transformImg(m, img_mov, Ny_mov, Nx_mov); // width and height (Nx/Ny) have to be swapped! Py_END_ALLOW_THREADS From 357c4bc26eb8617bdf73bafe3a3f7f94eada7225 Mon Sep 17 00:00:00 2001 From: Gregor Lichtner Date: Mon, 7 Aug 2023 16:56:59 +0200 Subject: [PATCH 5/5] updated tox commands --- tox.ini | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tox.ini b/tox.ini index 1314cde..7ec9e97 100644 --- a/tox.ini +++ b/tox.ini @@ -8,8 +8,8 @@ deps= -rrequirements.txt tifffile pytest + build commands= - python setup.py build_ext --inplace - python setup.py install + pip install --editable . pytest {posargs:}