Skip to content

Commit

Permalink
Fix code format following ruff update
Browse files Browse the repository at this point in the history
  • Loading branch information
fchollet committed Jan 13, 2025
1 parent 509c92b commit 78dda1c
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 25 deletions.
14 changes: 7 additions & 7 deletions keras/src/backend/openvino/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,9 +242,9 @@ def __getitem__(self, indices):
def __len__(self):
ov_output = self.output
ov_shape = ov_output.get_partial_shape()
assert (
ov_shape.rank.is_static and ov_shape.rank.get_length() > 0
), "rank must be static and greater than zero"
assert ov_shape.rank.is_static and ov_shape.rank.get_length() > 0, (
"rank must be static and greater than zero"
)
assert ov_shape[0].is_static, "the first dimension must be static"
return ov_shape[0].get_length()

Expand Down Expand Up @@ -425,10 +425,10 @@ def convert_to_numpy(x):
x = x.value
else:
return x.value.data
assert isinstance(
x, OpenVINOKerasTensor
), "unsupported type {} for `convert_to_numpy` in openvino backend".format(
type(x)
assert isinstance(x, OpenVINOKerasTensor), (
"unsupported type {} for `convert_to_numpy` in openvino backend".format(
type(x)
)
)
try:
ov_result = x.output
Expand Down
6 changes: 3 additions & 3 deletions keras/src/backend/openvino/nn.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,9 +325,9 @@ def depthwise_conv(
data_format = backend.standardize_data_format(data_format)
num_spatial_dims = inputs.get_partial_shape().rank.get_length() - 2

assert (
data_format == "channels_last"
), "`depthwise_conv` is supported only for channels_last data_format"
assert data_format == "channels_last", (
"`depthwise_conv` is supported only for channels_last data_format"
)

strides = _adjust_strides_dilation(strides, num_spatial_dims)
dilation_rate = _adjust_strides_dilation(dilation_rate, num_spatial_dims)
Expand Down
12 changes: 6 additions & 6 deletions keras/src/backend/openvino/numpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@ def mean(x, axis=None, keepdims=False):


def max(x, axis=None, keepdims=False, initial=None):
assert (
initial is None
), "`max` with not None initial is not supported by openvino backend"
assert initial is None, (
"`max` with not None initial is not supported by openvino backend"
)
x = get_ov_output(x)
reduce_axis = ov_opset.constant(axis, Type.i32).output(0)
return OpenVINOKerasTensor(
Expand Down Expand Up @@ -260,9 +260,9 @@ def bincount(x, weights=None, minlength=0, sparse=False):


def broadcast_to(x, shape):
assert isinstance(
shape, (tuple, list)
), "`broadcast_to` is supported only for tuple and list `shape`"
assert isinstance(shape, (tuple, list)), (
"`broadcast_to` is supported only for tuple and list `shape`"
)
target_shape = ov_opset.constant(list(shape), Type.i32).output(0)
x = get_ov_output(x)
return OpenVINOKerasTensor(ov_opset.broadcast(x, target_shape).output(0))
Expand Down
18 changes: 9 additions & 9 deletions keras/src/ops/numpy_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ def test_basic(self):
array = np.array([[1, 2], [3, 4]])
rotated = knp.rot90(array)
expected = np.array([[2, 4], [1, 3]])
assert np.array_equal(
rotated, expected
), f"Failed basic 2D test: {rotated}"
assert np.array_equal(rotated, expected), (
f"Failed basic 2D test: {rotated}"
)

def test_multiple_k(self):
array = np.array([[1, 2], [3, 4]])
Expand All @@ -50,9 +50,9 @@ def test_axes(self):
array = np.arange(8).reshape((2, 2, 2))
rotated = knp.rot90(array, k=1, axes=(1, 2))
expected = np.array([[[1, 3], [0, 2]], [[5, 7], [4, 6]]])
assert np.array_equal(
rotated, expected
), f"Failed custom axes test: {rotated}"
assert np.array_equal(rotated, expected), (
f"Failed custom axes test: {rotated}"
)

def test_single_image(self):
array = np.random.random((4, 4, 3))
Expand Down Expand Up @@ -83,9 +83,9 @@ def test_invalid_rank(self):
try:
knp.rot90(array)
except ValueError as e:
assert "Input array must have at least 2 dimensions." in str(
e
), f"Failed invalid rank test: {e}"
assert "Input array must have at least 2 dimensions." in str(e), (
f"Failed invalid rank test: {e}"
)
else:
raise AssertionError("Failed to raise error for invalid input")

Expand Down

0 comments on commit 78dda1c

Please sign in to comment.