Skip to content

Commit

Permalink
auto-lint code
Browse files Browse the repository at this point in the history
  • Loading branch information
ivy-dev-bot committed Jul 20, 2024
1 parent df80243 commit f1a937f
Show file tree
Hide file tree
Showing 94 changed files with 2,929 additions and 2,483 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,11 @@ def forward(self, input):
"""
return F.batch_norm(
input,
self.running_mean
if not self.training or self.track_running_stats
else None,
(
self.running_mean
if not self.training or self.track_running_stats
else None
),
self.running_var if not self.training or self.track_running_stats else None,
self.weight,
self.bias,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,11 @@ def forward(self, input):
"""
normalized, self.running_mean, self.running_var = ivy_batch_norm_frnt(
input,
self.running_mean
if not self.training or self.track_running_stats
else None,
(
self.running_mean
if not self.training or self.track_running_stats
else None
),
self.running_var if not self.training or self.track_running_stats else None,
self.weight,
self.bias,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,16 @@ def call(self, input):
normalized, self.running_mean, self.running_var = (
tensorflow_batch_norm_frnt(
input,
self.running_mean
if not self.training or self.track_running_stats
else None,
self.running_var
if not self.training or self.track_running_stats
else None,
(
self.running_mean
if not self.training or self.track_running_stats
else None
),
(
self.running_var
if not self.training or self.track_running_stats
else None
),
self.weight,
self.bias,
bn_training,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,13 @@ def _load_from_state_dict(
state_dict = tensorflow_set_item_bknd(
state_dict,
num_batches_tracked_key,
self.num_batches_tracked
if self.num_batches_tracked is not None
and self.num_batches_tracked.device
!= tensorflow_device_frnt("meta")
else tensorflow_tensor_frnt(0, dtype=tf.int64),
(
self.num_batches_tracked
if self.num_batches_tracked is not None
and self.num_batches_tracked.device
!= tensorflow_device_frnt("meta")
else tensorflow_tensor_frnt(0, dtype=tf.int64)
),
)
super()._load_from_state_dict(
state_dict,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -470,9 +470,7 @@ def tensorflow_default_bknd(
return (
x
if tensorflow_exists_bknd(x)
else default_val()
if default_callable
else default_val
else default_val() if default_callable else default_val
)


Expand Down Expand Up @@ -905,17 +903,21 @@ def tensorflow_default_int_dtype_bknd(
elif isinstance(input, (list, tuple, dict)):
if tensorflow_nested_argwhere_bknd(
input,
lambda x: tensorflow_dtype(x) == "uint64"
if tensorflow_is_array_bknd(x)
else x > 9223372036854775807 and x != math.inf,
lambda x: (
tensorflow_dtype(x) == "uint64"
if tensorflow_is_array_bknd(x)
else x > 9223372036854775807 and x != math.inf
),
stop_after_n_found=1,
):
ret = tf.uint64
elif tensorflow_nested_argwhere_bknd(
input,
lambda x: tensorflow_dtype(x) == "int64"
if tensorflow_is_array_bknd(x)
else x > 2147483647 and x != math.inf,
lambda x: (
tensorflow_dtype(x) == "int64"
if tensorflow_is_array_bknd(x)
else x > 2147483647 and x != math.inf
),
stop_after_n_found=1,
):
ret = tf.int64
Expand Down Expand Up @@ -1300,21 +1302,27 @@ def tensorflow_nested_map_bknd(
to_ignore = to_ignore + (class_instance,)
tuple_check_fn = tensorflow_default_bknd(
_tuple_check_fn,
(lambda x_, t_: isinstance(x_, t_))
if include_derived["tuple"]
else lambda x_, t_: type(x_) is t_,
(
(lambda x_, t_: isinstance(x_, t_))
if include_derived["tuple"]
else lambda x_, t_: type(x_) is t_
),
)
list_check_fn = tensorflow_default_bknd(
_list_check_fn,
(lambda x_, t_: isinstance(x_, t_))
if include_derived["list"]
else lambda x_, t_: type(x_) is t_,
(
(lambda x_, t_: isinstance(x_, t_))
if include_derived["list"]
else lambda x_, t_: type(x_) is t_
),
)
dict_check_fn = tensorflow_default_bknd(
_dict_check_fn,
(lambda x_, t_: isinstance(x_, t_))
if include_derived["dict"]
else lambda x_, t_: type(x_) is t_,
(
(lambda x_, t_: isinstance(x_, t_))
if include_derived["dict"]
else lambda x_, t_: type(x_) is t_
),
)
if tuple_check_fn(x, tuple) and not isinstance(x, to_ignore):
ret_list = [
Expand Down Expand Up @@ -1735,9 +1743,7 @@ def tensorflow_where(
dtype = (
x1.dtype
if hasattr(x1, "dtype")
else x2.dtype
if hasattr(x2, "dtype")
else tensorflow_default_dtype_bknd()
else x2.dtype if hasattr(x2, "dtype") else tensorflow_default_dtype_bknd()
)
if not tensorflow_is_array_bknd(x1):
x1 = tensorflow_asarray(x1, dtype=dtype)
Expand Down Expand Up @@ -2149,9 +2155,7 @@ def tensorflow__parse_query_bknd(query, x_shape, scatter=False):
(
tensorflow_reshape_bknd_(arr, (-1,))
if len(arr.shape) > 1
else tensorflow_expand_dims(arr)
if not len(arr.shape)
else arr
else tensorflow_expand_dims(arr) if not len(arr.shape) else arr
)
for arr in array_queries
]
Expand Down Expand Up @@ -2265,9 +2269,11 @@ def is_native(x):

if tensorflow_nested_argwhere_bknd(
input,
lambda x: tensorflow_dtype(x) == "uint64"
if is_native(x)
else x > 9223372036854775807 and x != math.inf,
lambda x: (
tensorflow_dtype(x) == "uint64"
if is_native(x)
else x > 9223372036854775807 and x != math.inf
),
stop_after_n_found=1,
):
ret = tf.uint64
Expand Down Expand Up @@ -2475,9 +2481,7 @@ def tensorflow_multiply(
dtype = (
x1.dtype
if hasattr(x1, "dtype")
else x2.dtype
if hasattr(x2, "dtype")
else tensorflow_default_dtype_bknd()
else x2.dtype if hasattr(x2, "dtype") else tensorflow_default_dtype_bknd()
)
if not tensorflow_is_array_bknd(x1):
x1 = tensorflow_asarray(x1, dtype=dtype)
Expand Down Expand Up @@ -2641,9 +2645,11 @@ def tensorflow_scatter_nd(
dtype = tensorflow_promote_types_bknd(out.dtype, updates_dtype)
updates = tensorflow.cast(
updates,
tensorflow_as_native_dtype(dtype)
if tensorflow_exists_bknd(out)
else updates_dtype,
(
tensorflow_as_native_dtype(dtype)
if tensorflow_exists_bknd(out)
else updates_dtype
),
)
expected_shape = (
list(tensorflow.shape(indices)[:-1])
Expand Down Expand Up @@ -3022,9 +3028,7 @@ def tensorflow_add(
dtype = (
x1.dtype
if hasattr(x1, "dtype")
else x2.dtype
if hasattr(x2, "dtype")
else tensorflow_default_dtype_bknd()
else x2.dtype if hasattr(x2, "dtype") else tensorflow_default_dtype_bknd()
)
if not tensorflow_is_array_bknd(x1):
x1 = tensorflow_asarray(x1, dtype=dtype)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -475,9 +475,7 @@ def tensorflow_default_bknd(
return (
x
if tensorflow_exists_bknd(x)
else default_val()
if default_callable
else default_val
else default_val() if default_callable else default_val
)


Expand Down Expand Up @@ -912,17 +910,21 @@ def tensorflow_default_int_dtype_bknd(
elif isinstance(input, (list, tuple, dict)):
if tensorflow_nested_argwhere_bknd(
input,
lambda x: tensorflow_dtype(x) == "uint64"
if tensorflow_is_array_bknd(x)
else x > 9223372036854775807 and x != math.inf,
lambda x: (
tensorflow_dtype(x) == "uint64"
if tensorflow_is_array_bknd(x)
else x > 9223372036854775807 and x != math.inf
),
stop_after_n_found=1,
):
ret = tf.uint64
elif tensorflow_nested_argwhere_bknd(
input,
lambda x: tensorflow_dtype(x) == "int64"
if tensorflow_is_array_bknd(x)
else x > 2147483647 and x != math.inf,
lambda x: (
tensorflow_dtype(x) == "int64"
if tensorflow_is_array_bknd(x)
else x > 2147483647 and x != math.inf
),
stop_after_n_found=1,
):
ret = tf.int64
Expand Down Expand Up @@ -1308,21 +1310,27 @@ def tensorflow_nested_map_bknd(
to_ignore = to_ignore + (class_instance,)
tuple_check_fn = tensorflow_default_bknd(
_tuple_check_fn,
(lambda x_, t_: isinstance(x_, t_))
if include_derived["tuple"]
else lambda x_, t_: type(x_) is t_,
(
(lambda x_, t_: isinstance(x_, t_))
if include_derived["tuple"]
else lambda x_, t_: type(x_) is t_
),
)
list_check_fn = tensorflow_default_bknd(
_list_check_fn,
(lambda x_, t_: isinstance(x_, t_))
if include_derived["list"]
else lambda x_, t_: type(x_) is t_,
(
(lambda x_, t_: isinstance(x_, t_))
if include_derived["list"]
else lambda x_, t_: type(x_) is t_
),
)
dict_check_fn = tensorflow_default_bknd(
_dict_check_fn,
(lambda x_, t_: isinstance(x_, t_))
if include_derived["dict"]
else lambda x_, t_: type(x_) is t_,
(
(lambda x_, t_: isinstance(x_, t_))
if include_derived["dict"]
else lambda x_, t_: type(x_) is t_
),
)
if tuple_check_fn(x, tuple) and not isinstance(x, to_ignore):
ret_list = [
Expand Down Expand Up @@ -1743,9 +1751,7 @@ def tensorflow_where(
dtype = (
x1.dtype
if hasattr(x1, "dtype")
else x2.dtype
if hasattr(x2, "dtype")
else tensorflow_default_dtype_bknd()
else x2.dtype if hasattr(x2, "dtype") else tensorflow_default_dtype_bknd()
)
if not tensorflow_is_array_bknd(x1):
x1 = tensorflow_asarray(x1, dtype=dtype)
Expand Down Expand Up @@ -2157,9 +2163,7 @@ def tensorflow__parse_query_bknd(query, x_shape, scatter=False):
(
tensorflow_reshape_bknd_(arr, (-1,))
if len(arr.shape) > 1
else tensorflow_expand_dims(arr)
if not len(arr.shape)
else arr
else tensorflow_expand_dims(arr) if not len(arr.shape) else arr
)
for arr in array_queries
]
Expand Down Expand Up @@ -2307,9 +2311,11 @@ def is_native(x):

if tensorflow_nested_argwhere_bknd(
input,
lambda x: tensorflow_dtype(x) == "uint64"
if is_native(x)
else x > 9223372036854775807 and x != math.inf,
lambda x: (
tensorflow_dtype(x) == "uint64"
if is_native(x)
else x > 9223372036854775807 and x != math.inf
),
stop_after_n_found=1,
):
ret = tf.uint64
Expand Down Expand Up @@ -2517,9 +2523,7 @@ def tensorflow_multiply(
dtype = (
x1.dtype
if hasattr(x1, "dtype")
else x2.dtype
if hasattr(x2, "dtype")
else tensorflow_default_dtype_bknd()
else x2.dtype if hasattr(x2, "dtype") else tensorflow_default_dtype_bknd()
)
if not tensorflow_is_array_bknd(x1):
x1 = tensorflow_asarray(x1, dtype=dtype)
Expand Down Expand Up @@ -2683,9 +2687,11 @@ def tensorflow_scatter_nd(
dtype = tensorflow_promote_types_bknd(out.dtype, updates_dtype)
updates = tensorflow.cast(
updates,
tensorflow_as_native_dtype(dtype)
if tensorflow_exists_bknd(out)
else updates_dtype,
(
tensorflow_as_native_dtype(dtype)
if tensorflow_exists_bknd(out)
else updates_dtype
),
)
expected_shape = (
list(tensorflow.shape(indices)[:-1])
Expand Down Expand Up @@ -3090,9 +3096,7 @@ def tensorflow_add(
dtype = (
x1.dtype
if hasattr(x1, "dtype")
else x2.dtype
if hasattr(x2, "dtype")
else tensorflow_default_dtype_bknd()
else x2.dtype if hasattr(x2, "dtype") else tensorflow_default_dtype_bknd()
)
if not tensorflow_is_array_bknd(x1):
x1 = tensorflow_asarray(x1, dtype=dtype)
Expand Down
Loading

0 comments on commit f1a937f

Please sign in to comment.