diff --git a/.github/workflows/python_package.yml b/.github/workflows/python_package.yml index 8291657..a611ffc 100644 --- a/.github/workflows/python_package.yml +++ b/.github/workflows/python_package.yml @@ -34,11 +34,11 @@ jobs: # stop the build if there are Python syntax errors or undefined names flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics --exclude=src # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide - flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics --ignore=E231,E226,E302,E301,E225 --exclude=src + flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics --ignore=E501,E252,E226,E741,E402,E231,E302,W504,E303,E123,W391,E306,E305 - name: Lint with Ruff run: | pip install ruff - ruff check --output-format=github --exclude=src . + ruff check --output-format=github --ignore E741,E402 . continue-on-error: true - name: Test with pytest run: | diff --git a/diffeopt/group/ddmatch/action/density.py b/diffeopt/group/ddmatch/action/density.py index ed46b29..8703f8e 100644 --- a/diffeopt/group/ddmatch/action/density.py +++ b/diffeopt/group/ddmatch/action/density.py @@ -39,7 +39,7 @@ def forward(ctx: Any, x: torch.Tensor, g: Union[torch.Tensor, ForwardDiffeo]) -> gy_y[0,:] += shape[1]/2 gy_y[-1,:] += shape[1]/2 - jac = gx_x*gy_y - gx_y*gy_x # Jacobian + jac = gx_x*gy_y - gx_y*gy_x # Jacobian pb = np.zeros(np.shape(x)) compute_pullback(x.detach().numpy(), g_[0], g_[1], pb) diff --git a/diffeopt/group/ddmatch/action/function.py b/diffeopt/group/ddmatch/action/function.py index 0504496..4c4fed7 100644 --- a/diffeopt/group/ddmatch/action/function.py +++ b/diffeopt/group/ddmatch/action/function.py @@ -2,7 +2,7 @@ import torch import numpy as np -from ...base import Diffeo, ForwardDiffeo +from ...base import Diffeo from ddmatch.core import generate_optimized_image_gradient, generate_optimized_image_composition # type: ignore @@ -63,7 +63,7 @@ def backward(ctx: Any, grad_output: torch.Tensor) -> tuple[torch.Tensor, Optiona q_ = q.detach().numpy() gxout, gyout = np.zeros_like(q_), np.zeros_like(q_) image_gradient(q_, gxout, gyout) - grad = torch.tensor([gxout, gyout]) + grad = torch.tensor(np.array([gxout, gyout])) result = grad*grad_output return (grad_output, result) else: diff --git a/diffeopt/optim.py b/diffeopt/optim.py index ac56f7f..3e45037 100644 --- a/diffeopt/optim.py +++ b/diffeopt/optim.py @@ -1,4 +1,4 @@ -from typing import Callable, Any, Optional, Union +from typing import Callable, Any, Optional from abc import ABC, abstractmethod import torch from .group.representation import Perturbation diff --git a/diffeopt/utils.py b/diffeopt/utils.py index f09fa56..9d42fc6 100644 --- a/diffeopt/utils.py +++ b/diffeopt/utils.py @@ -22,7 +22,6 @@ def get_random_diffeo(group: BaseDiffeoGroup, nb_steps:int=10, scale:float=1., g cometric = laplace.get_laplace_cometric(group, s=2) rm = torch.randn(*group.zero().shape, generator=generator) rv = cometric(rm) - vmx = rv.abs().max() shape_scale = (group.shape[0] + group.shape[1])/2 rv_ = rv/nb_steps/shape_scale**2*scale*32 current = group.identity() diff --git a/tests/test_distance.py b/tests/test_distance.py index e8f429b..69242b4 100644 --- a/tests/test_distance.py +++ b/tests/test_distance.py @@ -6,7 +6,7 @@ def test_zero_dist(): """ Information distance from image to itself is zero. """ - I = 1 + torch.rand(8,8) # make sure it is positive + I = 1 + torch.rand(8,8) # make sure it is positive assert information_distance(I,I) == 0 def test_information_derivative(): diff --git a/tests/test_grad.py b/tests/test_grad.py index c6dedde..28751b1 100644 --- a/tests/test_grad.py +++ b/tests/test_grad.py @@ -1,4 +1,3 @@ -import numpy as np import torch from diffeopt.group.ddmatch.action.function import get_composition_action from diffeopt.group.ddmatch.action.density import get_density_action @@ -72,7 +71,6 @@ def test_one_jacobian(): shape = [16]*2 group = DiffeoGroup(shape) act = get_density_action(shape) - idall = group.identity() vel = group.zero() vel[0] += 3 trans = group.exponential(vel)