Skip to content

Commit 93db239

Browse files
committed
remove W605 errors
1 parent 87930c4 commit 93db239

File tree

5 files changed

+46
-46
lines changed

5 files changed

+46
-46
lines changed

ot/bregman.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -370,9 +370,9 @@ def sinkhorn_knopp(a, b, M, reg, numItermax=1000,
370370
v = np.divide(b, KtransposeU)
371371
u = 1. / np.dot(Kp, v)
372372

373-
if (np.any(KtransposeU == 0) or
374-
np.any(np.isnan(u)) or np.any(np.isnan(v)) or
375-
np.any(np.isinf(u)) or np.any(np.isinf(v))):
373+
if (np.any(KtransposeU == 0)
374+
or np.any(np.isnan(u)) or np.any(np.isnan(v))
375+
or np.any(np.isinf(u)) or np.any(np.isinf(v))):
376376
# we have reached the machine precision
377377
# come back to previous solution and quit loop
378378
print('Warning: numerical errors at iteration', cpt)
@@ -683,13 +683,13 @@ def sinkhorn_stabilized(a, b, M, reg, numItermax=1000, tau=1e3, stopThr=1e-9,
683683

684684
def get_K(alpha, beta):
685685
"""log space computation"""
686-
return np.exp(-(M - alpha.reshape((na, 1)) -
687-
beta.reshape((1, nb))) / reg)
686+
return np.exp(-(M - alpha.reshape((na, 1))
687+
- beta.reshape((1, nb))) / reg)
688688

689689
def get_Gamma(alpha, beta, u, v):
690690
"""log space gamma computation"""
691-
return np.exp(-(M - alpha.reshape((na, 1)) - beta.reshape((1, nb))) /
692-
reg + np.log(u.reshape((na, 1))) + np.log(v.reshape((1, nb))))
691+
return np.exp(-(M - alpha.reshape((na, 1)) - beta.reshape((1, nb)))
692+
/ reg + np.log(u.reshape((na, 1))) + np.log(v.reshape((1, nb))))
693693

694694
# print(np.min(K))
695695

@@ -899,8 +899,8 @@ def sinkhorn_epsilon_scaling(a, b, M, reg, numItermax=100, epsilon0=1e4, numInne
899899

900900
def get_K(alpha, beta):
901901
"""log space computation"""
902-
return np.exp(-(M - alpha.reshape((na, 1)) -
903-
beta.reshape((1, nb))) / reg)
902+
return np.exp(-(M - alpha.reshape((na, 1))
903+
- beta.reshape((1, nb))) / reg)
904904

905905
# print(np.min(K))
906906
def get_reg(n): # exponential decreasing

ot/externals/funcsigs.py

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,8 @@ def signature(obj):
126126
new_params[arg_name] = param.replace(default=arg_value,
127127
_partial_kwarg=True)
128128

129-
elif (param.kind not in (_VAR_KEYWORD, _VAR_POSITIONAL) and
130-
not param._partial_kwarg):
129+
elif (param.kind not in (_VAR_KEYWORD, _VAR_POSITIONAL)
130+
and not param._partial_kwarg):
131131
new_params.pop(arg_name)
132132

133133
return sig.replace(parameters=new_params.values())
@@ -333,11 +333,11 @@ def __hash__(self):
333333
raise TypeError(msg)
334334

335335
def __eq__(self, other):
336-
return (issubclass(other.__class__, Parameter) and
337-
self._name == other._name and
338-
self._kind == other._kind and
339-
self._default == other._default and
340-
self._annotation == other._annotation)
336+
return (issubclass(other.__class__, Parameter)
337+
and self._name == other._name
338+
and self._kind == other._kind
339+
and self._default == other._default
340+
and self._annotation == other._annotation)
341341

342342
def __ne__(self, other):
343343
return not self.__eq__(other)
@@ -372,8 +372,8 @@ def signature(self):
372372
def args(self):
373373
args = []
374374
for param_name, param in self._signature.parameters.items():
375-
if (param.kind in (_VAR_KEYWORD, _KEYWORD_ONLY) or
376-
param._partial_kwarg):
375+
if (param.kind in (_VAR_KEYWORD, _KEYWORD_ONLY)
376+
or param._partial_kwarg):
377377
# Keyword arguments mapped by 'functools.partial'
378378
# (Parameter._partial_kwarg is True) are mapped
379379
# in 'BoundArguments.kwargs', along with VAR_KEYWORD &
@@ -402,8 +402,8 @@ def kwargs(self):
402402
kwargs_started = False
403403
for param_name, param in self._signature.parameters.items():
404404
if not kwargs_started:
405-
if (param.kind in (_VAR_KEYWORD, _KEYWORD_ONLY) or
406-
param._partial_kwarg):
405+
if (param.kind in (_VAR_KEYWORD, _KEYWORD_ONLY)
406+
or param._partial_kwarg):
407407
kwargs_started = True
408408
else:
409409
if param_name not in self.arguments:
@@ -432,9 +432,9 @@ def __hash__(self):
432432
raise TypeError(msg)
433433

434434
def __eq__(self, other):
435-
return (issubclass(other.__class__, BoundArguments) and
436-
self.signature == other.signature and
437-
self.arguments == other.arguments)
435+
return (issubclass(other.__class__, BoundArguments)
436+
and self.signature == other.signature
437+
and self.arguments == other.arguments)
438438

439439
def __ne__(self, other):
440440
return not self.__eq__(other)
@@ -612,9 +612,9 @@ def __hash__(self):
612612
raise TypeError(msg)
613613

614614
def __eq__(self, other):
615-
if (not issubclass(type(other), Signature) or
616-
self.return_annotation != other.return_annotation or
617-
len(self.parameters) != len(other.parameters)):
615+
if (not issubclass(type(other), Signature)
616+
or self.return_annotation != other.return_annotation
617+
or len(self.parameters) != len(other.parameters)):
618618
return False
619619

620620
other_positions = dict((param, idx)
@@ -635,8 +635,8 @@ def __eq__(self, other):
635635
except KeyError:
636636
return False
637637
else:
638-
if (idx != other_idx or
639-
param != other.parameters[param_name]):
638+
if (idx != other_idx
639+
or param != other.parameters[param_name]):
640640
return False
641641

642642
return True
@@ -688,8 +688,8 @@ def _bind(self, args, kwargs, partial=False):
688688
raise TypeError(msg)
689689
parameters_ex = (param,)
690690
break
691-
elif (param.kind == _VAR_KEYWORD or
692-
param.default is not _empty):
691+
elif (param.kind == _VAR_KEYWORD
692+
or param.default is not _empty):
693693
# That's fine too - we have a default value for this
694694
# parameter. So, lets start parsing `kwargs`, starting
695695
# with the current parameter
@@ -755,8 +755,8 @@ def _bind(self, args, kwargs, partial=False):
755755
# if it has a default value, or it is an '*args'-like
756756
# parameter, left alone by the processing of positional
757757
# arguments.
758-
if (not partial and param.kind != _VAR_POSITIONAL and
759-
param.default is _empty):
758+
if (not partial and param.kind != _VAR_POSITIONAL
759+
and param.default is _empty):
760760
raise TypeError('{arg!r} parameter lacking default value'.
761761
format(arg=param_name))
762762

ot/gpu/bregman.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,9 +146,9 @@ def sinkhorn_knopp(a, b, M, reg, numItermax=1000, stopThr=1e-9,
146146
v = np.divide(b, KtransposeU)
147147
u = 1. / np.dot(Kp, v)
148148

149-
if (np.any(KtransposeU == 0) or
150-
np.any(np.isnan(u)) or np.any(np.isnan(v)) or
151-
np.any(np.isinf(u)) or np.any(np.isinf(v))):
149+
if (np.any(KtransposeU == 0)
150+
or np.any(np.isnan(u)) or np.any(np.isnan(v))
151+
or np.any(np.isinf(u)) or np.any(np.isinf(v))):
152152
# we have reached the machine precision
153153
# come back to previous solution and quit loop
154154
print('Warning: numerical errors at iteration', cpt)

ot/stochastic.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -418,8 +418,8 @@ def solve_semi_dual_entropic(a, b, M, reg, method, numItermax=10000, lr=None,
418418
return None
419419

420420
opt_alpha = c_transform_entropic(b, M, reg, opt_beta)
421-
pi = (np.exp((opt_alpha[:, None] + opt_beta[None, :] - M[:, :]) / reg) *
422-
a[:, None] * b[None, :])
421+
pi = (np.exp((opt_alpha[:, None] + opt_beta[None, :] - M[:, :]) / reg)
422+
* a[:, None] * b[None, :])
423423

424424
if log:
425425
log = {}
@@ -520,15 +520,15 @@ def batch_grad_dual(a, b, M, reg, alpha, beta, batch_size, batch_alpha,
520520
arXiv preprint arxiv:1711.02283.
521521
'''
522522

523-
G = - (np.exp((alpha[batch_alpha, None] + beta[None, batch_beta] -
524-
M[batch_alpha, :][:, batch_beta]) / reg) *
523+
G = - (np.exp((alpha[batch_alpha, None] + beta[None, batch_beta]
524+
- M[batch_alpha, :][:, batch_beta]) / reg) *
525525
a[batch_alpha, None] * b[None, batch_beta])
526526
grad_beta = np.zeros(np.shape(M)[1])
527527
grad_alpha = np.zeros(np.shape(M)[0])
528-
grad_beta[batch_beta] = (b[batch_beta] * len(batch_alpha) / np.shape(M)[0] +
529-
G.sum(0))
530-
grad_alpha[batch_alpha] = (a[batch_alpha] * len(batch_beta) /
531-
np.shape(M)[1] + G.sum(1))
528+
grad_beta[batch_beta] = (b[batch_beta] * len(batch_alpha) / np.shape(M)[0]
529+
+ G.sum(0))
530+
grad_alpha[batch_alpha] = (a[batch_alpha] * len(batch_beta)
531+
/ np.shape(M)[1] + G.sum(1))
532532

533533
return grad_alpha, grad_beta
534534

@@ -702,8 +702,8 @@ def solve_dual_entropic(a, b, M, reg, batch_size, numItermax=10000, lr=1,
702702

703703
opt_alpha, opt_beta = sgd_entropic_regularization(a, b, M, reg, batch_size,
704704
numItermax, lr)
705-
pi = (np.exp((opt_alpha[:, None] + opt_beta[None, :] - M[:, :]) / reg) *
706-
a[:, None] * b[None, :])
705+
pi = (np.exp((opt_alpha[:, None] + opt_beta[None, :] - M[:, :]) / reg)
706+
* a[:, None] * b[None, :])
707707
if log:
708708
log = {}
709709
log['alpha'] = opt_alpha

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ description-file = README.md
33

44
[flake8]
55
exclude = __init__.py
6-
ignore = E265,E501
6+
ignore = E265,E501,W605

0 commit comments

Comments
 (0)