Skip to content

Commit 3c0db13

Browse files
authored
⬆️ Linting dependencies (#2663)
1 parent 715803b commit 3c0db13

13 files changed

+37
-40
lines changed

pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[tool.black]
2-
target-version = ['py36', 'py37', 'py38']
2+
target-version = ['py37', 'py38', 'py39', 'py310']
33
exclude = '''
44
(
55
/(

tensorflow_addons/image/filters.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -204,8 +204,8 @@ def _get_gaussian_kernel(sigma, filter_shape):
204204
"""Compute 1D Gaussian kernel."""
205205
sigma = tf.convert_to_tensor(sigma)
206206
x = tf.range(-filter_shape // 2 + 1, filter_shape // 2 + 1)
207-
x = tf.cast(x ** 2, sigma.dtype)
208-
x = tf.nn.softmax(-x / (2.0 * (sigma ** 2)))
207+
x = tf.cast(x**2, sigma.dtype)
208+
x = tf.nn.softmax(-x / (2.0 * (sigma**2)))
209209
return x
210210

211211

tensorflow_addons/losses/metric_learning.py

+6-9
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,12 @@ def pairwise_distance(feature: TensorLike, squared: bool = False):
3131
Returns:
3232
pairwise_distances: 2-D Tensor of size `[number of data, number of data]`.
3333
"""
34-
pairwise_distances_squared = (
35-
tf.math.add(
36-
tf.math.reduce_sum(tf.math.square(feature), axis=[1], keepdims=True),
37-
tf.math.reduce_sum(
38-
tf.math.square(tf.transpose(feature)), axis=[0], keepdims=True
39-
),
40-
)
41-
- 2.0 * tf.matmul(feature, tf.transpose(feature))
42-
)
34+
pairwise_distances_squared = tf.math.add(
35+
tf.math.reduce_sum(tf.math.square(feature), axis=[1], keepdims=True),
36+
tf.math.reduce_sum(
37+
tf.math.square(tf.transpose(feature)), axis=[0], keepdims=True
38+
),
39+
) - 2.0 * tf.matmul(feature, tf.transpose(feature))
4340

4441
# Deal with numerical inaccuracies. Set small negatives to zero.
4542
pairwise_distances_squared = tf.math.maximum(pairwise_distances_squared, 0.0)

tensorflow_addons/metrics/matthews_correlation_coefficient.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,9 @@ def result(self):
102102
# covariance true-pred
103103
cov_ytyp = num_correct * num_samples - tf.tensordot(true_sum, pred_sum, axes=1)
104104
# covariance pred-pred
105-
cov_ypyp = num_samples ** 2 - tf.tensordot(pred_sum, pred_sum, axes=1)
105+
cov_ypyp = num_samples**2 - tf.tensordot(pred_sum, pred_sum, axes=1)
106106
# covariance true-true
107-
cov_ytyt = num_samples ** 2 - tf.tensordot(true_sum, true_sum, axes=1)
107+
cov_ytyt = num_samples**2 - tf.tensordot(true_sum, true_sum, axes=1)
108108

109109
mcc = cov_ytyp / tf.math.sqrt(cov_ytyt * cov_ypyp)
110110

tensorflow_addons/optimizers/conditional_gradient.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ def _prepare_local(self, var_device, var_dtype, apply_state):
123123

124124
@staticmethod
125125
def _frobenius_norm(m):
126-
return tf.reduce_sum(m ** 2) ** 0.5
126+
return tf.reduce_sum(m**2) ** 0.5
127127

128128
@staticmethod
129129
def _top_singular_vector(m):

tensorflow_addons/optimizers/cyclical_learning_rate.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ def __init__(
309309
initial_learning_rate=initial_learning_rate,
310310
maximal_learning_rate=maximal_learning_rate,
311311
step_size=step_size,
312-
scale_fn=lambda x: gamma ** x,
312+
scale_fn=lambda x: gamma**x,
313313
scale_mode=scale_mode,
314314
name=name,
315315
)

tensorflow_addons/optimizers/tests/conditional_gradient_test.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ def loss():
8585
grads0_0 = 32 * 1.0 + 40 * 2.0
8686
grads0_1 = 40 * 1.0 + 50 * 2.0
8787
grads0 = tf.constant([[grads0_0, grads0_1]], dtype=dtype)
88-
norm0 = tf.math.reduce_sum(grads0 ** 2) ** 0.5
88+
norm0 = tf.math.reduce_sum(grads0**2) ** 0.5
8989

9090
learning_rate = 0.1
9191
lambda_ = 0.1
@@ -117,8 +117,8 @@ def test_basic_frobenius(dtype, use_resource):
117117
var1 = tf.Variable([3.0, 4.0], dtype=dtype[0])
118118
grads0 = tf.constant([0.1, 0.1], dtype=dtype[0])
119119
grads1 = tf.constant([0.01, 0.01], dtype=dtype[0])
120-
norm0 = tf.math.reduce_sum(grads0 ** 2) ** 0.5
121-
norm1 = tf.math.reduce_sum(grads1 ** 2) ** 0.5
120+
norm0 = tf.math.reduce_sum(grads0**2) ** 0.5
121+
norm1 = tf.math.reduce_sum(grads1**2) ** 0.5
122122

123123
def learning_rate():
124124
return 0.5
@@ -440,7 +440,7 @@ def loss():
440440

441441
# the gradient for this loss function:
442442
grads0 = tf.constant([[0, 0], [1, 1]], dtype=tf.float32)
443-
norm0 = tf.math.reduce_sum(grads0 ** 2) ** 0.5
443+
norm0 = tf.math.reduce_sum(grads0**2) ** 0.5
444444

445445
learning_rate = 0.1
446446
lambda_ = 0.1
@@ -503,8 +503,8 @@ def test_tensor_learning_rate_and_conditional_gradient_frobenius(dtype):
503503
var1 = tf.Variable([3.0, 4.0], dtype=dtype)
504504
grads0 = tf.constant([0.1, 0.1], dtype=dtype)
505505
grads1 = tf.constant([0.01, 0.01], dtype=dtype)
506-
norm0 = tf.math.reduce_sum(grads0 ** 2) ** 0.5
507-
norm1 = tf.math.reduce_sum(grads1 ** 2) ** 0.5
506+
norm0 = tf.math.reduce_sum(grads0**2) ** 0.5
507+
norm1 = tf.math.reduce_sum(grads1**2) ** 0.5
508508
ord = "fro"
509509
cg_opt = cg_lib.ConditionalGradient(
510510
learning_rate=tf.constant(0.5), lambda_=tf.constant(0.01), ord=ord
@@ -943,8 +943,8 @@ def test_sharing_frobenius(dtype):
943943
var1 = tf.Variable([3.0, 4.0], dtype=dtype)
944944
grads0 = tf.constant([0.1, 0.1], dtype=dtype)
945945
grads1 = tf.constant([0.01, 0.01], dtype=dtype)
946-
norm0 = tf.math.reduce_sum(grads0 ** 2) ** 0.5
947-
norm1 = tf.math.reduce_sum(grads1 ** 2) ** 0.5
946+
norm0 = tf.math.reduce_sum(grads0**2) ** 0.5
947+
norm1 = tf.math.reduce_sum(grads1**2) ** 0.5
948948
learning_rate = 0.1
949949
lambda_ = 0.1
950950
ord = "fro"

tensorflow_addons/optimizers/tests/cyclical_learning_rate_test.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ def test_exponential_cyclical_learning_rate(serialize):
9999
non_bounded_value = np.abs(i / 2000.0 - 2 * np.floor(1 + i / (2 * 2000)) + 1)
100100
expected = initial_learning_rate + (
101101
maximal_learning_rate - initial_learning_rate
102-
) * np.maximum(0, (1 - non_bounded_value)) * (gamma ** i)
102+
) * np.maximum(0, (1 - non_bounded_value)) * (gamma**i)
103103
computed = exponential_cyclical_lr(step).numpy()
104104
np.testing.assert_allclose(computed, expected, 1e-6)
105105
step += 1

tensorflow_addons/optimizers/tests/weight_decay_optimizers_test.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -152,9 +152,9 @@ def adamw_update_numpy(
152152
for v in (learning_rate, beta_1, beta_2, epsilon, weight_decay)
153153
)
154154
t = slot_vars.get("t", 0) + 1
155-
lr_t = lr * np.sqrt(1 - beta2 ** t) / (1 - beta1 ** t)
155+
lr_t = lr * np.sqrt(1 - beta2**t) / (1 - beta1**t)
156156
slot_vars["m"] = beta1 * slot_vars.get("m", 0) + (1 - beta1) * grad_t
157-
slot_vars["v"] = beta2 * slot_vars.get("v", 0) + (1 - beta2) * grad_t ** 2
157+
slot_vars["v"] = beta2 * slot_vars.get("v", 0) + (1 - beta2) * grad_t**2
158158
param_t = param * (1 - wd) - lr_t * slot_vars["m"] / (np.sqrt(slot_vars["v"]) + eps)
159159
slot_vars["t"] = t
160160
return param_t, slot_vars

tensorflow_addons/optimizers/tests/yogi_test.py

+9-9
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def yogi_update_numpy(
5959
beta1 = np.array(beta1, dtype=param.dtype)
6060
beta2 = np.array(beta2, dtype=param.dtype)
6161

62-
alpha_t = alpha * np.sqrt(1 - beta2 ** t) / (1 - beta1 ** t)
62+
alpha_t = alpha * np.sqrt(1 - beta2**t) / (1 - beta1**t)
6363

6464
m_t = beta1 * m + (1 - beta1) * g_t
6565
g2_t = g_t * g_t
@@ -128,8 +128,8 @@ def do_test_sparse(beta1=0.0, l1reg=0.0, l2reg=0.0):
128128
# Run 3 steps of Yogi.
129129
for t in range(1, 4):
130130
beta1_power, beta2_power = get_beta_accumulators(opt, dtype)
131-
test_utils.assert_allclose_according_to_type(beta1 ** t, beta1_power)
132-
test_utils.assert_allclose_according_to_type(0.999 ** t, beta2_power)
131+
test_utils.assert_allclose_according_to_type(beta1**t, beta1_power)
132+
test_utils.assert_allclose_according_to_type(0.999**t, beta2_power)
133133
opt.apply_gradients(zip([grads0, grads1], [var0, var1]))
134134

135135
var0_np, m0, v0 = yogi_update_numpy(
@@ -224,8 +224,8 @@ def do_test_basic(beta1=0.0, l1reg=0.0, l2reg=0.0):
224224
# Run 3 steps of Yogi.
225225
for t in range(1, 4):
226226
beta1_power, beta2_power = get_beta_accumulators(opt, dtype)
227-
test_utils.assert_allclose_according_to_type(beta1 ** t, beta1_power)
228-
test_utils.assert_allclose_according_to_type(0.999 ** t, beta2_power)
227+
test_utils.assert_allclose_according_to_type(beta1**t, beta1_power)
228+
test_utils.assert_allclose_according_to_type(0.999**t, beta2_power)
229229

230230
opt.apply_gradients(zip([grads0, grads1], [var0, var1]))
231231

@@ -284,8 +284,8 @@ def test_tensor_learning_rate():
284284
# Run 3 steps of Yogi.
285285
for t in range(1, 4):
286286
beta1_power, beta2_power = get_beta_accumulators(opt, dtype)
287-
test_utils.assert_allclose_according_to_type(0.9 ** t, beta1_power)
288-
test_utils.assert_allclose_according_to_type(0.999 ** t, beta2_power)
287+
test_utils.assert_allclose_according_to_type(0.9**t, beta1_power)
288+
test_utils.assert_allclose_according_to_type(0.999**t, beta2_power)
289289

290290
opt.apply_gradients(zip([grads0, grads1], [var0, var1]))
291291

@@ -320,8 +320,8 @@ def test_sharing():
320320
# Run 3 steps of intertwined Yogi1 and Yogi2.
321321
for t in range(1, 4):
322322
beta1_power, beta2_power = get_beta_accumulators(opt, dtype)
323-
test_utils.assert_allclose_according_to_type(0.9 ** t, beta1_power)
324-
test_utils.assert_allclose_according_to_type(0.999 ** t, beta2_power)
323+
test_utils.assert_allclose_according_to_type(0.9**t, beta1_power)
324+
test_utils.assert_allclose_according_to_type(0.999**t, beta2_power)
325325
opt.apply_gradients(zip([grads0, grads1], [var0, var1]))
326326
var0_np, m0, v0 = yogi_update_numpy(var0_np, grads0_np, t, m0, v0)
327327
var1_np, m1, v1 = yogi_update_numpy(var1_np, grads1_np, t, m1, v1)

tensorflow_addons/rnn/tests/esn_cell_test.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ def test_esn_connectivity():
9797
cell.build((3, 3))
9898
recurrent_weights = tf.constant(cell.get_weights()[0])
9999
num_non_zero = tf.math.count_nonzero(recurrent_weights)
100-
actual_connectivity = tf.divide(num_non_zero, units ** 2)
100+
actual_connectivity = tf.divide(num_non_zero, units**2)
101101
np.testing.assert_allclose(
102102
np.asarray([actual_connectivity]), np.asanyarray([connectivity]), 1e-2
103103
)

tools/install_deps/black.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
black==20.8b1
1+
black==22.1.0

tools/install_deps/flake8.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
flake8~=3.7.9
2-
pep8-naming~=0.10.0
1+
flake8~=4.0
2+
pep8-naming~=0.12.1

0 commit comments

Comments
 (0)