Skip to content

Commit 22a9580

Browse files
committed
fix exception string literals in tf_numeric.py
1 parent 259e12b commit 22a9580

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

nncf/tensor/functions/tf_numeric.py

+11-6
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,8 @@ def _(a: tf.Tensor, k: int = 0) -> tf.Tensor:
388388
elif rank == 2:
389389
return tf.linalg.diag_part(a, k=k)
390390
else:
391-
raise ValueError("Input tensor must be 1D or 2D.")
391+
error_msg = "Input tensor must be 1D or 2D."
392+
raise ValueError(error_msg)
392393

393394

394395
@numeric.logical_or.register(tf.Tensor)
@@ -439,14 +440,16 @@ def _(a: tf.Tensor, axis: Union[int, Tuple[int, ...], List[int]]) -> np.ndarray:
439440
axis = (axis,)
440441

441442
if len(set(axis)) != len(axis):
442-
raise ValueError("repeated axis")
443+
error_msg = "repeated axis"
444+
raise ValueError(error_msg)
443445

444446
out_ndim = len(axis) + a.ndim
445447

446448
norm_axis = []
447449
for ax in axis:
448450
if ax < -out_ndim or ax >= out_ndim:
449-
raise ValueError(f"axis {ax} is out of bounds for array of dimension {out_ndim}")
451+
error_msg = f"axis {ax} is out of bounds for array of dimension {out_ndim}"
452+
raise ValueError(error_msg)
450453
norm_axis.append(ax + out_ndim if ax < 0 else ax)
451454

452455
shape_it = iter(a.shape)
@@ -463,9 +466,11 @@ def _(a: tf.Tensor) -> tf.Tensor:
463466
@numeric.searchsorted.register(tf.Tensor)
464467
def _(a: tf.Tensor, v: tf.Tensor, side: str = "left", sorter: Optional[tf.Tensor] = None) -> tf.Tensor:
465468
if side not in ["right", "left"]:
466-
raise ValueError(f"Invalid value for 'side': {side}. Expected 'right' or 'left'.")
469+
error_msg = f"Invalid value for 'side': {side}. Expected 'right' or 'left'."
470+
raise ValueError(error_msg)
467471
if a.ndim != 1:
468-
raise ValueError(f"Input tensor 'a' must be 1-D. Received {a.ndim}-D tensor.")
472+
error_msg = f"Input tensor 'a' must be 1-D. Received {a.ndim}-D tensor."
473+
raise ValueError(error_msg)
469474
sorted_a = tf.sort(a)
470475
return tf.searchsorted(sorted_sequence=sorted_a, values=v, side=side)
471476

@@ -542,4 +547,4 @@ def tensor(
542547
device = convert_to_tf_device(device)
543548
dtype = convert_to_tf_dtype(dtype)
544549
with tf.device(device):
545-
return tf.constant(data, dtype=dtype)
550+
return tf.constant(data, dtype=dtype)

0 commit comments

Comments
 (0)