Skip to content

Commit

Permalink
MNT: minor linting
Browse files Browse the repository at this point in the history
  • Loading branch information
olivierverdier committed Sep 30, 2024
1 parent 63b6942 commit cdbc5e8
Show file tree
Hide file tree
Showing 7 changed files with 7 additions and 10 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/python_package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down
2 changes: 1 addition & 1 deletion diffeopt/group/ddmatch/action/density.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions diffeopt/group/ddmatch/action/function.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion diffeopt/optim.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
1 change: 0 additions & 1 deletion diffeopt/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion tests/test_distance.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down
2 changes: 0 additions & 2 deletions tests/test_grad.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit cdbc5e8

Please sign in to comment.