Skip to content

Commit 3a171df

Browse files
committed
STY: Fix many pylint warnings, add good names and remove local disables
1 parent 71d8f83 commit 3a171df

38 files changed

+470
-388
lines changed

.pylintrc

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,16 +47,19 @@ disable=redefined-builtin,
4747
no-member,
4848
missing-super-argument,
4949
abstract-method,
50-
protected-access
50+
protected-access,
51+
not-callable
5152

52-
# redefined-builtin: 'object', 'range', 'str', 'super' are redefined,
53+
# redefined-builtin: 'object', 'range', 'str', 'super' are redefined,
5354
# that's okay
5455
# no-name-in-module, no-member: triggered by scipy and numpy, let's ignore them
5556
# missing-super-argument: importing new super, pylint doesn't get it
5657
# abstract-method: some classes are intended as intermediate, where it's okay not to override
5758
# abstract methods. This warning does not really prevent bugs, so we're disabling it.
5859
# protected-access: We use private attributes of "internalized" objects. Since this check is not really
5960
# a bug catcher, we're disabling it.
61+
# not-callable: pylint tries to determine if a class attribute (e.g. element_type) is
62+
# callable or not - and fails to do so
6063

6164
[REPORTS]
6265

@@ -131,10 +134,10 @@ indent-after-paren=4
131134
bad-functions=map,filter,apply,input
132135

133136
# Good variable names which should always be accepted, separated by a comma
134-
good-names=i,j,k,ex,Run,_,a,b,x,y,z,xp,yp,zp,s,q,p,I,T,dx,dy,x1,x2,xi,yi,n,m,ax
137+
good-names=a,b,c,d,f,g,h,i,j,k,m,n,p,q,r,s,t,u,v,w,x,y,z,xp,yp,zp,dx,dy,dz,x0,x1,x2,y0,y1,y2,z0,z1,z2,xi,yi,zi,ax,rn,cn,op,ex,_,I,T,nx,ny,nz,fx
135138

136139
# Bad variable names which should always be refused, separated by a comma
137-
bad-names=foo,bar,baz,toto,tutu,tata
140+
bad-names=foo,baz,toto,tutu,tata,l
138141

139142
# Colon-delimited sets of names that determine each other's naming style when
140143
# the name regexes allow several styles.

examples/convolution_test.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ def opnorm(self):
5959
cont_space = odl.FunctionSpace(odl.Interval(0, 10))
6060

6161
# Complicated functions to check performance
62-
cont_kernel = cont_space.element(lambda x: np.exp(x/2) * np.cos(x*1.172))
63-
cont_phantom = cont_space.element(lambda x: x**2 * np.sin(x)**2*(x > 5))
62+
cont_kernel = cont_space.element(lambda x: np.exp(x / 2) * np.cos(x * 1.172))
63+
cont_phantom = cont_space.element(lambda x: x ** 2 * np.sin(x) ** 2 * (x > 5))
6464

6565
# Discretization
6666
discr_space = odl.uniform_discr_fromspace(cont_space, 500, impl='numpy')
@@ -72,7 +72,7 @@ def opnorm(self):
7272

7373
# Dampening parameter for landweber
7474
iterations = 100
75-
omega = 1/conv.opnorm()**2
75+
omega = 1 / conv.opnorm() ** 2
7676

7777
# Display partial
7878
partial = solvers.util.ForEachPartial(lambda result: plt.plot(conv(result)))

examples/convolution_test_cuda.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ def opnorm(self): # An upper limit estimate of the operator norm
6464
cont_space = odl.FunctionSpace(odl.Interval(0, 10))
6565

6666
# Complicated functions to check performance
67-
cont_kernel = cont_space.element(lambda x: np.exp(x/2) * np.cos(x*1.172))
68-
cont_data = cont_space.element(lambda x: x**2 * np.sin(x)**2*(x > 5))
67+
cont_kernel = cont_space.element(lambda x: np.exp(x / 2) * np.cos(x * 1.172))
68+
cont_data = cont_space.element(lambda x: x ** 2 * np.sin(x) ** 2 * (x > 5))
6969

7070
# Discretization
7171
discr_space = odl.uniform_discr_fromspace(cont_space, 5000, impl='cuda')
@@ -77,7 +77,7 @@ def opnorm(self): # An upper limit estimate of the operator norm
7777

7878
# Dampening parameter for landweber
7979
iterations = 100
80-
omega = 1.0/conv.opnorm()**2
80+
omega = 1.0 / conv.opnorm() ** 2
8181

8282
# Display partial
8383
partial = solvers.util.ForEachPartial(

examples/cudaspace_speedtest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,5 +78,5 @@ def run_test(function, message):
7878
run_test(lambda z, x, y: x.space.lincomb(2, z, 2, z, z), "z = (a+b)*z")
7979

8080
# Non lincomb tests
81-
run_test(lambda z, x, y: x+y, "z = x + y")
81+
run_test(lambda z, x, y: x + y, "z = x + y")
8282
run_test(lambda z, x, y: y.assign(x), "y.assign(x)")

examples/operator_test.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333

3434

3535
class Convolution(odl.Operator):
36+
3637
def __init__(self, space, kernel, adjkernel):
3738
self.kernel = kernel
3839
self.adjkernel = adjkernel
@@ -58,7 +59,7 @@ def adjoint(self):
5859
def kernel(x):
5960
mean = [0.0, 0.25]
6061
std = [0.05, 0.05]
61-
return np.exp(-(((x[0]-mean[0])/std[0])**2 + ((x[1]-mean[1])/std[1])**2))
62+
return np.exp(-(((x[0] - mean[0]) / std[0])**2 + ((x[1] - mean[1]) / std[1])**2))
6263

6364

6465
def adjkernel(x):
@@ -71,8 +72,8 @@ def adjkernel(x):
7172

7273
# Discretization parameters
7374
n = 20
74-
npoints = np.array([n+1, n+1])
75-
npoints_kernel = np.array([2*n+1, 2*n+1])
75+
npoints = np.array([n + 1, n + 1])
76+
npoints_kernel = np.array([2 * n + 1, 2 * n + 1])
7677

7778
# Discretized spaces
7879
disc_space = odl.uniform_discr_fromspace(cont_space, npoints)

examples/reals.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def _inner(self, x1, x2):
3636
return x1.__val__ * x2.__val__
3737

3838
def _lincomb(self, a, x1, b, x2, out):
39-
out.__val__ = a*x1.__val__ + b*x2.__val__
39+
out.__val__ = a * x1.__val__ + b * x2.__val__
4040

4141
def _multiply(self, x1, x2, out):
4242
out.__val__ = x1.__val__ * x2.__val__
@@ -70,7 +70,7 @@ def __str__(self):
7070

7171
print(x)
7272
print(y)
73-
print(x+y)
74-
print(x*y)
75-
print(x-y)
73+
print(x + y)
74+
print(x * y)
75+
print(x - y)
7676
print(3.14 * x)

examples/solver_examples.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
def landweber_base(operator, x, rhs, iterations=1, omega=1):
2828
"""Straightforward implementation of Landweber's iteration."""
2929
for _ in range(iterations):
30-
x = x - omega * operator.adjoint(operator(x)-rhs)
30+
x = x - omega * operator.adjoint(operator(x) - rhs)
3131

3232
return x
3333

@@ -42,8 +42,8 @@ def conjugate_gradient_base(op, x, rhs, iterations=1):
4242
q = op(p)
4343
norms2 = s.norm()**2
4444
a = norms2 / q.norm()**2
45-
x = x + a*p
46-
d = d - a*q
45+
x = x + a * p
46+
d = d - a * q
4747
s = op.adjoint(d)
48-
b = s.norm()**2/norms2
49-
p = s + b*p
48+
b = s.norm()**2 / norms2
49+
p = s + b * p

examples/visualization/show_productspace.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# You should have received a copy of the GNU General Public License
1616
# along with ODL. If not, see <http://www.gnu.org/licenses/>.
1717

18-
""" Example on using show with ProductSpace's """
18+
"""Example on using show with ProductSpace's."""
1919

2020
# Imports for common Python 2/3 codebase
2121
from __future__ import print_function, division, absolute_import
@@ -42,5 +42,5 @@
4242
title='Show every third element')
4343

4444
# Slices propagate (as in numpy)
45-
vec.show(indices=np.s_[2, :, n//2], show=True,
45+
vec.show(indices=np.s_[2, :, n // 2], show=True,
4646
title='Show second element, then slice by [:, n//2]')

examples/visualization/show_update_1d.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# You should have received a copy of the GNU General Public License
1616
# along with ODL. If not, see <http://www.gnu.org/licenses/>.
1717

18-
""" Example on using show and updating the figure in real time in 1d. """
18+
"""Example on using show and updating the figure in real time in 1d."""
1919

2020
# Imports for common Python 2/3 codebase
2121
from __future__ import print_function, division, absolute_import

examples/visualization/show_update_2d.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# You should have received a copy of the GNU General Public License
1616
# along with ODL. If not, see <http://www.gnu.org/licenses/>.
1717

18-
""" Example on using show and updating the figure in real time in 2d. """
18+
"""Example on using show and updating the figure in real time in 2d."""
1919

2020
# Imports for common Python 2/3 codebase
2121
from __future__ import print_function, division, absolute_import

0 commit comments

Comments
 (0)