Skip to content

Commit

Permalink
Placate pylint by making sure the norm order is always defined.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 706728557
  • Loading branch information
agutkin committed Dec 16, 2024
1 parent 109129c commit 9e5a75b
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion protoscribe/corpus/reader/noise_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ def tf_random_lp_ball_vector(
Returns:
Sampled tensor.
Raises:
ValueError if invalid normalization order was supplied.
"""
if order not in ["INF", "1", "2"]:
raise ValueError(f"Unsupported order: {order}")
Expand All @@ -89,7 +92,7 @@ def tf_random_lp_ball_vector(
[dim], loc=1.0, scale=1.0, dtype=dtype, seed=seed
)
norm = tf.reduce_sum(tf.abs(x))
elif order == "2":
else: # Assume order of 2 (Euclidean/Frobenius).
# \mathcal{N}(0, 1).
x = tf.random.normal(shape=[dim], dtype=dtype, seed=seed)
norm = tf.sqrt(tf.reduce_sum(tf.square(x)))
Expand Down

0 comments on commit 9e5a75b

Please sign in to comment.