Skip to content

Commit 68680ed

Browse files
committed
Update Python syntax
1 parent 78d49b7 commit 68680ed

File tree

8 files changed

+25
-25
lines changed

8 files changed

+25
-25
lines changed

examples/shared/utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def download_data(data_dir, url, unpack=True, block_size=10 * 1024):
1616
print("{} already exists. Skipping download".format(filename))
1717
return
1818

19-
print("Downloading {0} to {1}".format(url, filename))
19+
print("Downloading {} to {}".format(url, filename))
2020
response = requests.get(url, stream=True)
2121
total = int(response.headers.get("content-length", 0))
2222
progress_bar = tqdm.tqdm(total=total, unit="iB", unit_scale=True)
@@ -33,7 +33,7 @@ def download_data(data_dir, url, unpack=True, block_size=10 * 1024):
3333
with open(filename, "rb") as f:
3434
with zipfile.ZipFile(f) as zip_ref:
3535
zip_ref.extractall(data_dir)
36-
print("Unzipped {0} to {1}".format(filename, data_dir))
36+
print("Unzipped {} to {}".format(filename, data_dir))
3737

3838

3939
def load_matlab_data(key, data_dir, *folders):

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
name="tensorflow-riemopt",
66
version="0.1.2",
77
description="a library for optimization on Riemannian manifolds",
8-
long_description=open("README.md", "r").read(),
8+
long_description=open("README.md").read(),
99
long_description_content_type="text/markdown",
1010
author="Oleg Smirnov",
1111
author_email="[email protected]",

tensorflow_riemopt/manifolds/hyperboloid.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def __init__(self, k=1.0):
2424
super().__init__()
2525

2626
def __repr__(self):
27-
return "{0} (k={1}, ndims={2}) manifold".format(
27+
return "{} (k={}, ndims={}) manifold".format(
2828
self.name, self.k, self.ndims
2929
)
3030

tensorflow_riemopt/manifolds/manifold.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class Manifold(metaclass=abc.ABCMeta):
88

99
def __repr__(self):
1010
"""Returns a string representation of the particular manifold."""
11-
return "{0} (ndims={1}) manifold".format(self.name, self.ndims)
11+
return "{} (ndims={}) manifold".format(self.name, self.ndims)
1212

1313
def check_shape(self, shape_or_tensor):
1414
"""Check if given shape is compatible with the manifold."""

tensorflow_riemopt/manifolds/poincare.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def __init__(self, k=1.0):
3131
super().__init__()
3232

3333
def __repr__(self):
34-
return "{0} (k={1}, ndims={2}) manifold".format(
34+
return "{} (k={}, ndims={}) manifold".format(
3535
self.name, self.k, self.ndims
3636
)
3737

@@ -45,10 +45,10 @@ def _check_vector_on_tangent(self, x, u, atol, rtol):
4545

4646
def _mobius_add(self, x, y):
4747
"""Compute the Möbius addition of :math:`x` and :math:`y` in
48-
:math:`\mathcal{D}^{n}_{k}`
48+
:math:`\\mathcal{D}^{n}_{k}`
4949
50-
:math:`x \oplus y = \frac{(1 + 2k\langle x, y\rangle + k||y||^2)x + (1
51-
- k||x||^2)y}{1 + 2k\langle x,y\rangle + k^2||x||^2||y||^2}`
50+
:math:`x \\oplus y = \frac{(1 + 2k\\langle x, y\rangle + k||y||^2)x + (1
51+
- k||x||^2)y}{1 + 2k\\langle x,y\rangle + k^2||x||^2||y||^2}`
5252
"""
5353
x_2 = tf.reduce_sum(tf.math.square(x), axis=-1, keepdims=True)
5454
y_2 = tf.reduce_sum(tf.math.square(y), axis=-1, keepdims=True)
@@ -59,11 +59,11 @@ def _mobius_add(self, x, y):
5959
)
6060

6161
def _mobius_scal_mul(self, x, r):
62-
"""Compute the Möbius scalar multiplication of :math:`x \in
63-
\mathcal{D}^{n}_{k} \ {0}` by :math:`r`
62+
"""Compute the Möbius scalar multiplication of :math:`x \\in
63+
\\mathcal{D}^{n}_{k} \\ {0}` by :math:`r`
6464
65-
:math:`x \otimes r = (1/\sqrt{k})\tanh(r
66-
\atanh(\sqrt{k}||x||))\frac{x}{||x||}`
65+
:math:`x \\otimes r = (1/\\sqrt{k})\tanh(r
66+
\atanh(\\sqrt{k}||x||))\frac{x}{||x||}`
6767
6868
"""
6969
sqrt_k = tf.math.sqrt(tf.cast(self.k, x.dtype))
@@ -73,7 +73,7 @@ def _mobius_scal_mul(self, x, r):
7373
return (1 / sqrt_k) * tf.math.tanh(r * tf.math.atanh(tan)) * x / norm_x
7474

7575
def _gyration(self, u, v, w):
76-
"""Compute the gyration of :math:`u`, :math:`v`, :math:`w`:
76+
r"""Compute the gyration of :math:`u`, :math:`v`, :math:`w`:
7777
7878
:math:`\operatorname{gyr}[u, v]w =
7979
\ominus (u \oplus_\kappa v) \oplus (u \oplus_\kappa (v \oplus_\kappa w))`

tensorflow_riemopt/optimizers/constrained_rmsprop.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ def __init__(
6666
allow time inverse decay of learning rate. `lr` is included for backward
6767
compatibility, recommended to use `learning_rate` instead.
6868
"""
69-
super(ConstrainedRMSprop, self).__init__(name, **kwargs)
69+
super().__init__(name, **kwargs)
7070
self._set_hyper("learning_rate", kwargs.get("lr", learning_rate))
7171
self._set_hyper("decay", self._initial_decay)
7272
self._set_hyper("rho", rho)
@@ -83,7 +83,7 @@ def _create_slots(self, var_list):
8383
self.add_slot(var, "mg")
8484

8585
def _prepare_local(self, var_device, var_dtype, apply_state):
86-
super(ConstrainedRMSprop, self)._prepare_local(
86+
super()._prepare_local(
8787
var_device, var_dtype, apply_state
8888
)
8989

@@ -197,10 +197,10 @@ def set_weights(self, weights):
197197
params = self.weights
198198
if len(params) == len(weights) + 1:
199199
weights = [np.array(0)] + weights
200-
super(ConstrainedRMSprop, self).set_weights(weights)
200+
super().set_weights(weights)
201201

202202
def get_config(self):
203-
config = super(ConstrainedRMSprop, self).get_config()
203+
config = super().get_config()
204204
config.update(
205205
{
206206
"learning_rate": self._serialize_hyperparameter(

tensorflow_riemopt/optimizers/riemannian_adam.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ def __init__(
6969
7070
"""
7171

72-
super(RiemannianAdam, self).__init__(name, **kwargs)
72+
super().__init__(name, **kwargs)
7373
self._set_hyper("learning_rate", kwargs.get("lr", learning_rate))
7474
self._set_hyper("decay", self._initial_decay)
7575
self._set_hyper("beta_1", beta_1)
@@ -88,7 +88,7 @@ def _create_slots(self, var_list):
8888
self.add_slot(var, "vhat")
8989

9090
def _prepare_local(self, var_device, var_dtype, apply_state):
91-
super(RiemannianAdam, self)._prepare_local(
91+
super()._prepare_local(
9292
var_device, var_dtype, apply_state
9393
)
9494

@@ -118,7 +118,7 @@ def set_weights(self, weights):
118118
num_vars = int((len(params) - 1) / 2)
119119
if len(weights) == 3 * num_vars + 1:
120120
weights = weights[: len(params)]
121-
super(RiemannianAdam, self).set_weights(weights)
121+
super().set_weights(weights)
122122

123123
@def_function.function(experimental_compile=True)
124124
def _resource_apply_dense(self, grad, var, apply_state=None):
@@ -215,7 +215,7 @@ def _stabilize(self, var):
215215
m.assign(manifold.proju(var, m))
216216

217217
def get_config(self):
218-
config = super(RiemannianAdam, self).get_config()
218+
config = super().get_config()
219219
config.update(
220220
{
221221
"learning_rate": self._serialize_hyperparameter(

tensorflow_riemopt/optimizers/riemannian_gradient_descent.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def __init__(
5757
5858
"""
5959

60-
super(RiemannianSGD, self).__init__(name, **kwargs)
60+
super().__init__(name, **kwargs)
6161
self._set_hyper("learning_rate", kwargs.get("lr", learning_rate))
6262
self._set_hyper("decay", self._initial_decay)
6363
self._momentum = False
@@ -81,7 +81,7 @@ def _create_slots(self, var_list):
8181
self.add_slot(var, "momentum")
8282

8383
def _prepare_local(self, var_device, var_dtype, apply_state):
84-
super(RiemannianSGD, self)._prepare_local(
84+
super()._prepare_local(
8585
var_device, var_dtype, apply_state
8686
)
8787
apply_state[(var_device, var_dtype)]["momentum"] = array_ops.identity(
@@ -168,7 +168,7 @@ def _stabilize(self, var):
168168
momentum.assign(manifold.proju(var, momentum))
169169

170170
def get_config(self):
171-
config = super(RiemannianSGD, self).get_config()
171+
config = super().get_config()
172172
config.update(
173173
{
174174
"learning_rate": self._serialize_hyperparameter(

0 commit comments

Comments
 (0)