From a526999ab8e7116223eb3d8dc5bce7538516f53e Mon Sep 17 00:00:00 2001 From: ivy-dev-bot Date: Sun, 4 Aug 2024 15:56:37 +0000 Subject: [PATCH] Update cache files [skip ci] --- .../run_0/Translated_AdaptiveAvgPool2d.py | 4 +- .../run_0/Translated_AvgPool2d.py | 4 +- .../run_0/Translated__BatchNorm.py | 12 +- .../run_0/Translated_Conv2d.py | 24 ++-- .../run_0/Translated__ConvNd.py | 2 +- .../Translated_Conv2d_output/run_0/helpers.py | 17 ++- .../run_0/Translated_ConvTranspose2d.py | 18 +-- .../run_0/Translated__ConvTransposeNd.py | 6 +- .../run_0/helpers.py | 17 ++- .../run_0/Translated_Dropout2d.py | 4 +- .../run_0/Translated_LayerNorm.py | 5 +- .../run_0/Translated_Linear.py | 5 +- .../run_0/Translated_MaxPool2d.py | 4 +- .../run_0/Translated_ModuleDict.py | 2 +- .../run_0/Translated_Sequential.py | 11 +- .../run_0/ivy__BatchNorm.py | 8 +- .../ivy_Conv2d_output/run_0/ivy_Conv2d.py | 16 ++- .../ivy_Conv2d_output/run_0/ivy__ConvNd.py | 2 +- .../ivy_Conv2d_output/run_0/ivy__helpers.py | 17 ++- .../run_0/ivy_ConvTranspose2d.py | 14 +- .../run_0/ivy__ConvTransposeNd.py | 6 +- .../run_0/ivy__helpers.py | 17 ++- .../run_0/ivy_LayerNorm.py | 2 +- .../ivy_Linear_output/run_0/ivy_Linear.py | 2 +- .../run_0/ivy_Sequential.py | 2 +- .../run_0/tensorflow__helpers.py | 96 +++++++------- .../run_0/tensorflow_NestedSequence_bknd.py | 2 +- .../run_0/tensorflow__helpers.py | 84 ++++++------ .../run_0/tensorflow__BatchNorm.py | 17 +-- .../run_0/tensorflow__NormBase.py | 12 +- .../run_0/tensorflow__helpers.py | 83 ++++++------ .../run_0/tensorflow_Conv2d.py | 24 ++-- .../run_0/tensorflow_NestedSequence_bknd.py | 2 +- .../run_0/tensorflow__ConvNd.py | 2 +- .../run_0/tensorflow__helpers.py | 122 +++++++++--------- .../run_0/tensorflow_ConvTranspose2d.py | 21 ++- .../run_0/tensorflow_NestedSequence_bknd.py | 2 +- .../run_0/tensorflow__ConvTransposeNd.py | 8 +- .../run_0/tensorflow__helpers.py | 122 +++++++++--------- .../run_0/tensorflow_NestedSequence_bknd.py | 2 +- .../run_0/tensorflow__helpers.py | 84 ++++++------ .../run_0/tensorflow_LayerNorm.py | 2 +- .../run_0/tensorflow_NestedSequence_bknd.py | 2 +- .../run_0/tensorflow__helpers.py | 87 ++++++------- .../run_0/tensorflow_NestedSequence_bknd.py | 2 +- .../run_0/tensorflow__helpers.py | 80 ++++++------ .../run_0/tensorflow_NestedSequence_bknd.py | 2 +- .../run_0/tensorflow__helpers.py | 84 ++++++------ .../run_0/tensorflow_NestedSequence_bknd.py | 2 +- .../run_0/tensorflow__helpers.py | 84 ++++++------ .../run_0/tensorflow__helpers.py | 84 ++++++------ .../run_0/tensorflow_NestedSequence_bknd.py | 2 +- .../run_0/tensorflow_Sequential.py | 2 +- .../run_0/tensorflow__helpers.py | 84 ++++++------ .../run_0/tensorflow_NestedSequence_bknd.py | 2 +- .../run_0/tensorflow__helpers.py | 80 ++++++------ .../run_0/tensorflow_NestedSequence_bknd.py | 2 +- .../run_0/tensorflow__helpers.py | 80 ++++++------ .../run_0/tensorflow_add.py | 6 +- .../run_0/tensorflow_NestedSequence_bknd.py | 2 +- .../run_0/tensorflow__helpers.py | 80 ++++++------ .../run_0/tensorflow_all.py | 4 +- .../run_0/tensorflow__helpers.py | 80 ++++++------ .../run_0/tensorflow_NestedSequence_bknd.py | 2 +- .../run_0/tensorflow__helpers.py | 80 ++++++------ .../run_0/tensorflow__helpers.py | 80 ++++++------ .../run_0/tensorflow_asarray.py | 2 +- .../run_0/tensorflow_NestedSequence_bknd.py | 2 +- .../run_0/tensorflow__helpers.py | 80 ++++++------ .../run_0/tensorflow_batch_norm.py | 2 +- .../run_0/tensorflow_NestedSequence_bknd.py | 2 +- .../run_0/tensorflow__helpers.py | 80 ++++++------ .../run_0/tensorflow_bernoulli.py | 2 +- .../run_0/tensorflow__helpers.py | 80 ++++++------ .../run_0/tensorflow__helpers.py | 80 ++++++------ .../run_0/tensorflow__helpers.py | 80 ++++++------ .../run_0/tensorflow_clip.py | 4 +- .../run_0/tensorflow__helpers.py | 4 +- .../run_0/tensorflow_concat.py | 4 +- .../run_0/tensorflow_NestedSequence_bknd.py | 2 +- .../run_0/tensorflow__helpers.py | 80 ++++++------ .../run_0/tensorflow_conv_general_dilated.py | 2 +- .../run_0/tensorflow__helpers.py | 80 ++++++------ .../run_0/tensorflow_default_device_bknd.py | 2 +- .../run_0/tensorflow_NestedSequence_bknd.py | 2 +- .../run_0/tensorflow__helpers.py | 80 ++++++------ .../run_0/tensorflow_default_dtype_bknd.py | 2 +- .../run_0/tensorflow_NestedSequence_bknd.py | 2 +- .../run_0/tensorflow__helpers.py | 80 ++++++------ .../run_0/tensorflow_dropout.py | 2 +- .../run_0/tensorflow__helpers.py | 80 ++++++------ .../run_0/tensorflow_empty.py | 2 +- .../run_0/tensorflow_NestedSequence_bknd.py | 2 +- .../run_0/tensorflow__helpers.py | 80 ++++++------ .../run_0/tensorflow_equal.py | 4 +- .../run_0/tensorflow_NestedSequence_bknd.py | 2 +- .../run_0/tensorflow__helpers.py | 80 ++++++------ .../run_0/tensorflow_erfinv.py | 2 +- .../run_0/tensorflow__helpers.py | 80 ++++++------ .../run_0/tensorflow_exp.py | 2 +- .../run_0/tensorflow__helpers.py | 80 ++++++------ .../run_0/tensorflow__helpers.py | 80 ++++++------ .../run_0/tensorflow_floor_divide.py | 6 +- .../run_0/tensorflow__helpers.py | 80 ++++++------ .../run_0/tensorflow_NestedSequence_bknd.py | 2 +- .../run_0/tensorflow__helpers.py | 80 ++++++------ .../run_0/tensorflow__helpers.py | 84 ++++++------ .../run_0/tensorflow_interpolate.py | 12 +- .../run_0/tensorflow_NestedSequence_bknd.py | 2 +- .../run_0/tensorflow__helpers.py | 84 ++++++------ .../run_0/tensorflow_layer_norm_bknd.py | 2 +- .../run_0/tensorflow_NestedSequence_bknd.py | 2 +- .../run_0/tensorflow__helpers.py | 80 ++++++------ .../run_0/tensorflow_NestedSequence_bknd.py | 2 +- .../run_0/tensorflow__helpers.py | 80 ++++++------ .../run_0/tensorflow_linspace.py | 2 +- .../run_0/tensorflow__helpers.py | 80 ++++++------ .../run_0/tensorflow_NestedSequence_bknd.py | 2 +- .../run_0/tensorflow__helpers.py | 80 ++++++------ .../run_0/tensorflow_max_pool2d.py | 2 +- .../run_0/tensorflow_NestedSequence_bknd.py | 2 +- .../run_0/tensorflow__helpers.py | 80 ++++++------ .../run_0/tensorflow_maximum.py | 6 +- .../run_0/tensorflow_NestedSequence_bknd.py | 2 +- .../run_0/tensorflow__helpers.py | 80 ++++++------ .../run_0/tensorflow_multiply.py | 4 +- .../run_0/tensorflow__helpers.py | 80 ++++++------ .../run_0/tensorflow_nonzero.py | 2 +- .../run_0/tensorflow__helpers.py | 80 ++++++------ .../run_0/tensorflow_pad.py | 4 +- .../run_0/tensorflow__helpers.py | 80 ++++++------ .../run_0/tensorflow_permute_dims.py | 2 +- .../run_0/tensorflow__helpers.py | 80 ++++++------ .../run_0/tensorflow_NestedSequence_bknd.py | 2 +- .../run_0/tensorflow__helpers.py | 80 ++++++------ .../run_0/tensorflow_scatter_nd.py | 10 +- .../run_0/tensorflow_NestedSequence_bknd.py | 2 +- .../run_0/tensorflow__helpers.py | 80 ++++++------ .../run_0/tensorflow_set_item_bknd.py | 2 +- .../run_0/tensorflow_NestedSequence_bknd.py | 2 +- .../run_0/tensorflow__helpers.py | 80 ++++++------ .../run_0/tensorflow_sign.py | 2 +- .../run_0/tensorflow_NestedSequence_bknd.py | 2 +- .../run_0/tensorflow__helpers.py | 80 ++++++------ .../run_0/tensorflow_split.py | 2 +- .../run_0/tensorflow_NestedSequence_bknd.py | 2 +- .../run_0/tensorflow__helpers.py | 80 ++++++------ .../run_0/tensorflow_swapaxes.py | 2 +- .../run_0/tensorflow_NestedSequence_bknd.py | 2 +- .../run_0/tensorflow__helpers.py | 80 ++++++------ .../run_0/tensorflow_NestedSequence_bknd.py | 2 +- .../run_0/tensorflow__helpers.py | 80 ++++++------ .../run_0/tensorflow__helpers.py | 80 ++++++------ .../run_0/tensorflow_zeros.py | 2 +- .../ivy_to_tensorflow_translation_cache.pkl | 4 +- ...orch_frontend_to_ivy_translation_cache.pkl | 4 +- ...ch_to_torch_frontend_translation_cache.pkl | 4 +- 157 files changed, 2372 insertions(+), 2667 deletions(-) diff --git a/ivy/compiler/_cache/Translated_Outputs/Translated_AdaptiveAvgPool2d_output/run_0/Translated_AdaptiveAvgPool2d.py b/ivy/compiler/_cache/Translated_Outputs/Translated_AdaptiveAvgPool2d_output/run_0/Translated_AdaptiveAvgPool2d.py index 01546cfb3c1d0..c4ca8274ba086 100644 --- a/ivy/compiler/_cache/Translated_Outputs/Translated_AdaptiveAvgPool2d_output/run_0/Translated_AdaptiveAvgPool2d.py +++ b/ivy/compiler/_cache/Translated_Outputs/Translated_AdaptiveAvgPool2d_output/run_0/Translated_AdaptiveAvgPool2d.py @@ -1,4 +1,4 @@ -import ivy.functional.frontends.torch.nn.functional as F +import ivy.functional.frontends.torch as torch import typing @@ -9,4 +9,4 @@ class Translated_AdaptiveAvgPool2d(Translated__AdaptiveAvgPoolNd): output_size: typing.Any def forward(self, input): - return F.adaptive_avg_pool2d(input, self.output_size) + return torch.nn.functional.adaptive_avg_pool2d(input, self.output_size) diff --git a/ivy/compiler/_cache/Translated_Outputs/Translated_AvgPool2d_output/run_0/Translated_AvgPool2d.py b/ivy/compiler/_cache/Translated_Outputs/Translated_AvgPool2d_output/run_0/Translated_AvgPool2d.py index e4e21cd5a43e7..1c627a4227208 100644 --- a/ivy/compiler/_cache/Translated_Outputs/Translated_AvgPool2d_output/run_0/Translated_AvgPool2d.py +++ b/ivy/compiler/_cache/Translated_Outputs/Translated_AvgPool2d_output/run_0/Translated_AvgPool2d.py @@ -1,4 +1,4 @@ -import ivy.functional.frontends.torch.nn.functional as F +import ivy.functional.frontends.torch as torch import typing @@ -38,7 +38,7 @@ def __init__( self.divisor_override = divisor_override def forward(self, input): - return F.avg_pool2d( + return torch.nn.functional.avg_pool2d( input, self.kernel_size, self.stride, diff --git a/ivy/compiler/_cache/Translated_Outputs/Translated_BatchNorm2d_output/run_0/Translated__BatchNorm.py b/ivy/compiler/_cache/Translated_Outputs/Translated_BatchNorm2d_output/run_0/Translated__BatchNorm.py index f06f37fa72f55..c77efa6e2d4f4 100644 --- a/ivy/compiler/_cache/Translated_Outputs/Translated_BatchNorm2d_output/run_0/Translated__BatchNorm.py +++ b/ivy/compiler/_cache/Translated_Outputs/Translated_BatchNorm2d_output/run_0/Translated__BatchNorm.py @@ -1,4 +1,4 @@ -import ivy.functional.frontends.torch.nn.functional as F +import ivy.functional.frontends.torch as torch from .Translated__NormBase import Translated__NormBase @@ -45,13 +45,11 @@ def forward(self, input): passed when the update should occur (i.e. in training mode when they are tracked), or when buffer stats are used for normalization (i.e. in eval mode when buffers are not None). """ - return F.batch_norm( + return torch.nn.functional.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, diff --git a/ivy/compiler/_cache/Translated_Outputs/Translated_Conv2d_output/run_0/Translated_Conv2d.py b/ivy/compiler/_cache/Translated_Outputs/Translated_Conv2d_output/run_0/Translated_Conv2d.py index a14badb40bd4b..3ebea731eafa0 100644 --- a/ivy/compiler/_cache/Translated_Outputs/Translated_Conv2d_output/run_0/Translated_Conv2d.py +++ b/ivy/compiler/_cache/Translated_Outputs/Translated_Conv2d_output/run_0/Translated_Conv2d.py @@ -1,7 +1,9 @@ -import ivy.functional.frontends.torch.nn.functional as F +import ivy.functional.frontends.torch as torch from .Translated__ConvNd import Translated__ConvNd -from .helpers import Translated_parse +from .helpers import Translated__ntuple + +_pair = Translated__ntuple(2, "_pair") class Translated_Conv2d(Translated__ConvNd): @@ -20,10 +22,10 @@ def __init__( dtype=None, ): factory_kwargs = {"device": device, "dtype": dtype} - kernel_size_ = Translated_parse(kernel_size) - stride_ = Translated_parse(stride) - padding_ = padding if isinstance(padding, str) else Translated_parse(padding) - dilation_ = Translated_parse(dilation) + kernel_size_ = _pair(kernel_size) + stride_ = _pair(stride) + padding_ = padding if isinstance(padding, str) else _pair(padding) + dilation_ = _pair(dilation) super().__init__( in_channels, out_channels, @@ -32,7 +34,7 @@ def __init__( padding_, dilation_, False, - Translated_parse(0), + _pair(0), groups, bias, padding_mode, @@ -41,18 +43,18 @@ def __init__( def _conv_forward(self, input, weight, bias): if self.padding_mode != "zeros": - return F.conv2d( - F.pad( + return torch.nn.functional.conv2d( + torch.nn.functional.pad( input, self._reversed_padding_repeated_twice, mode=self.padding_mode ), weight, bias, self.stride, - Translated_parse(0), + _pair(0), self.dilation, self.groups, ) - return F.conv2d( + return torch.nn.functional.conv2d( input, weight, bias, self.stride, self.padding, self.dilation, self.groups ) diff --git a/ivy/compiler/_cache/Translated_Outputs/Translated_Conv2d_output/run_0/Translated__ConvNd.py b/ivy/compiler/_cache/Translated_Outputs/Translated_Conv2d_output/run_0/Translated__ConvNd.py index 81f76582c27b2..b177126d465e0 100644 --- a/ivy/compiler/_cache/Translated_Outputs/Translated_Conv2d_output/run_0/Translated__ConvNd.py +++ b/ivy/compiler/_cache/Translated_Outputs/Translated_Conv2d_output/run_0/Translated__ConvNd.py @@ -1,8 +1,8 @@ import ivy.functional.frontends.torch as torch import ivy.functional.frontends.torch.nn as nn -import math import typing +import math from typing import Optional from .helpers import Translated__calculate_fan_in_and_fan_out diff --git a/ivy/compiler/_cache/Translated_Outputs/Translated_Conv2d_output/run_0/helpers.py b/ivy/compiler/_cache/Translated_Outputs/Translated_Conv2d_output/run_0/helpers.py index 26059f643255e..31bc548048323 100644 --- a/ivy/compiler/_cache/Translated_Outputs/Translated_Conv2d_output/run_0/helpers.py +++ b/ivy/compiler/_cache/Translated_Outputs/Translated_Conv2d_output/run_0/helpers.py @@ -4,6 +4,16 @@ import warnings +def Translated__ntuple(n, name="parse"): + def parse(x): + if isinstance(x, collections.abc.Iterable): + return tuple(x) + return tuple(repeat(x, n)) + + parse.__name__ = name + return parse + + def Translated__reverse_repeat_tuple(t, n): return tuple(x for x in reversed(t) for _ in range(n)) @@ -87,10 +97,3 @@ def Translated__no_grad_uniform_(tensor, a, b, generator=None): def Translated_uniform_(tensor, a=0.0, b=1.0, generator=None): return Translated__no_grad_uniform_(tensor, a, b, generator) - - -def Translated_parse(x): - n = 2 - if isinstance(x, collections.abc.Iterable): - return tuple(x) - return tuple(repeat(x, n)) diff --git a/ivy/compiler/_cache/Translated_Outputs/Translated_ConvTranspose2d_output/run_0/Translated_ConvTranspose2d.py b/ivy/compiler/_cache/Translated_Outputs/Translated_ConvTranspose2d_output/run_0/Translated_ConvTranspose2d.py index 41fadb1b073a4..96c4ba3340fd9 100644 --- a/ivy/compiler/_cache/Translated_Outputs/Translated_ConvTranspose2d_output/run_0/Translated_ConvTranspose2d.py +++ b/ivy/compiler/_cache/Translated_Outputs/Translated_ConvTranspose2d_output/run_0/Translated_ConvTranspose2d.py @@ -1,7 +1,9 @@ -import ivy.functional.frontends.torch.nn.functional as F +import ivy.functional.frontends.torch as torch from .Translated__ConvTransposeNd import Translated__ConvTransposeNd -from .helpers import Translated_parse +from .helpers import Translated__ntuple + +_pair = Translated__ntuple(2, "_pair") class Translated_ConvTranspose2d(Translated__ConvTransposeNd): @@ -21,11 +23,11 @@ def __init__( dtype=None, ): factory_kwargs = {"device": device, "dtype": dtype} - kernel_size = Translated_parse(kernel_size) - stride = Translated_parse(stride) - padding = Translated_parse(padding) - dilation = Translated_parse(dilation) - output_padding = Translated_parse(output_padding) + kernel_size = _pair(kernel_size) + stride = _pair(stride) + padding = _pair(padding) + dilation = _pair(dilation) + output_padding = _pair(output_padding) super().__init__( in_channels, out_channels, @@ -57,7 +59,7 @@ def forward(self, input, output_size=None): num_spatial_dims, self.dilation, ) - return F.conv_transpose2d( + return torch.nn.functional.conv_transpose2d( input, self.weight, self.bias, diff --git a/ivy/compiler/_cache/Translated_Outputs/Translated_ConvTranspose2d_output/run_0/Translated__ConvTransposeNd.py b/ivy/compiler/_cache/Translated_Outputs/Translated_ConvTranspose2d_output/run_0/Translated__ConvTransposeNd.py index 53cf1ff9ac6d5..17ecc2f4701b7 100644 --- a/ivy/compiler/_cache/Translated_Outputs/Translated_ConvTranspose2d_output/run_0/Translated__ConvTransposeNd.py +++ b/ivy/compiler/_cache/Translated_Outputs/Translated_ConvTranspose2d_output/run_0/Translated__ConvTransposeNd.py @@ -1,5 +1,7 @@ from .Translated__ConvNd import Translated__ConvNd -from .helpers import Translated_parse +from .helpers import Translated__ntuple + +_single = Translated__ntuple(1, "_single") class Translated__ConvTransposeNd(Translated__ConvNd): @@ -50,7 +52,7 @@ def _output_padding( dilation=None, ): if output_size is None: - ret = Translated_parse(self.output_padding) + ret = _single(self.output_padding) else: has_batch_dim = input.dim() == num_spatial_dims + 2 num_non_spatial_dims = 2 if has_batch_dim else 1 diff --git a/ivy/compiler/_cache/Translated_Outputs/Translated_ConvTranspose2d_output/run_0/helpers.py b/ivy/compiler/_cache/Translated_Outputs/Translated_ConvTranspose2d_output/run_0/helpers.py index 85ff399d2b624..31bc548048323 100644 --- a/ivy/compiler/_cache/Translated_Outputs/Translated_ConvTranspose2d_output/run_0/helpers.py +++ b/ivy/compiler/_cache/Translated_Outputs/Translated_ConvTranspose2d_output/run_0/helpers.py @@ -4,6 +4,16 @@ import warnings +def Translated__ntuple(n, name="parse"): + def parse(x): + if isinstance(x, collections.abc.Iterable): + return tuple(x) + return tuple(repeat(x, n)) + + parse.__name__ = name + return parse + + def Translated__reverse_repeat_tuple(t, n): return tuple(x for x in reversed(t) for _ in range(n)) @@ -87,10 +97,3 @@ def Translated__no_grad_uniform_(tensor, a, b, generator=None): def Translated_uniform_(tensor, a=0.0, b=1.0, generator=None): return Translated__no_grad_uniform_(tensor, a, b, generator) - - -def Translated_parse(x): - n = 1 - if isinstance(x, collections.abc.Iterable): - return tuple(x) - return tuple(repeat(x, n)) diff --git a/ivy/compiler/_cache/Translated_Outputs/Translated_Dropout2d_output/run_0/Translated_Dropout2d.py b/ivy/compiler/_cache/Translated_Outputs/Translated_Dropout2d_output/run_0/Translated_Dropout2d.py index e5b86039095f5..6aac9b6c89f7b 100644 --- a/ivy/compiler/_cache/Translated_Outputs/Translated_Dropout2d_output/run_0/Translated_Dropout2d.py +++ b/ivy/compiler/_cache/Translated_Outputs/Translated_Dropout2d_output/run_0/Translated_Dropout2d.py @@ -1,8 +1,8 @@ -import ivy.functional.frontends.torch.nn.functional as F +import ivy.functional.frontends.torch as torch from .Translated__DropoutNd import Translated__DropoutNd class Translated_Dropout2d(Translated__DropoutNd): def forward(self, input): - return F.dropout2d(input, self.p, self.training, self.inplace) + return torch.nn.functional.dropout2d(input, self.p, self.training, self.inplace) diff --git a/ivy/compiler/_cache/Translated_Outputs/Translated_LayerNorm_output/run_0/Translated_LayerNorm.py b/ivy/compiler/_cache/Translated_Outputs/Translated_LayerNorm_output/run_0/Translated_LayerNorm.py index 7bd3328094032..a5c22719b71e4 100644 --- a/ivy/compiler/_cache/Translated_Outputs/Translated_LayerNorm_output/run_0/Translated_LayerNorm.py +++ b/ivy/compiler/_cache/Translated_Outputs/Translated_LayerNorm_output/run_0/Translated_LayerNorm.py @@ -1,9 +1,8 @@ import ivy.functional.frontends.torch as torch import ivy.functional.frontends.torch.nn as nn -import ivy.functional.frontends.torch.nn.functional as F -import typing import numbers +import typing from .helpers import Translated_ones_ from .helpers import Translated_zeros_ @@ -53,7 +52,7 @@ def reset_parameters(self): Translated_zeros_(self.bias) def forward(self, input): - return F.layer_norm( + return torch.nn.functional.layer_norm( input, self.normalized_shape, self.weight, self.bias, self.eps ) diff --git a/ivy/compiler/_cache/Translated_Outputs/Translated_Linear_output/run_0/Translated_Linear.py b/ivy/compiler/_cache/Translated_Outputs/Translated_Linear_output/run_0/Translated_Linear.py index 807fe1c9a49e0..b78e8e89821be 100644 --- a/ivy/compiler/_cache/Translated_Outputs/Translated_Linear_output/run_0/Translated_Linear.py +++ b/ivy/compiler/_cache/Translated_Outputs/Translated_Linear_output/run_0/Translated_Linear.py @@ -1,9 +1,8 @@ import ivy.functional.frontends.torch as torch import ivy.functional.frontends.torch.nn as nn -import ivy.functional.frontends.torch.nn.functional as F -import math import typing +import math from .helpers import Translated__calculate_fan_in_and_fan_out from .helpers import Translated_kaiming_uniform_ @@ -40,7 +39,7 @@ def reset_parameters(self): Translated_uniform_(self.bias, -bound, bound) def forward(self, input): - return F.linear(input, self.weight, self.bias) + return torch.nn.functional.linear(input, self.weight, self.bias) def extra_repr(self): return f"in_features={self.in_features}, out_features={self.out_features}, bias={self.bias is not None}" diff --git a/ivy/compiler/_cache/Translated_Outputs/Translated_MaxPool2d_output/run_0/Translated_MaxPool2d.py b/ivy/compiler/_cache/Translated_Outputs/Translated_MaxPool2d_output/run_0/Translated_MaxPool2d.py index 4825c62d3994a..dd00212f03afd 100644 --- a/ivy/compiler/_cache/Translated_Outputs/Translated_MaxPool2d_output/run_0/Translated_MaxPool2d.py +++ b/ivy/compiler/_cache/Translated_Outputs/Translated_MaxPool2d_output/run_0/Translated_MaxPool2d.py @@ -1,4 +1,4 @@ -import ivy.functional.frontends.torch.nn.functional as F +import ivy.functional.frontends.torch as torch import typing @@ -12,7 +12,7 @@ class Translated_MaxPool2d(Translated__MaxPoolNd): dilation: typing.Any def forward(self, input): - return F.max_pool2d( + return torch.nn.functional.max_pool2d( input, self.kernel_size, self.stride, diff --git a/ivy/compiler/_cache/Translated_Outputs/Translated_ModuleDict_output/run_0/Translated_ModuleDict.py b/ivy/compiler/_cache/Translated_Outputs/Translated_ModuleDict_output/run_0/Translated_ModuleDict.py index 971e81b4e3e9b..1478992d365e4 100644 --- a/ivy/compiler/_cache/Translated_Outputs/Translated_ModuleDict_output/run_0/Translated_ModuleDict.py +++ b/ivy/compiler/_cache/Translated_Outputs/Translated_ModuleDict_output/run_0/Translated_ModuleDict.py @@ -1,8 +1,8 @@ import ivy.functional.frontends.torch.nn as nn import typing -from collections import OrderedDict from collections import abc as container_abcs +from collections import OrderedDict class Translated_ModuleDict(nn.Module): diff --git a/ivy/compiler/_cache/Translated_Outputs/Translated_Sequential_output/run_0/Translated_Sequential.py b/ivy/compiler/_cache/Translated_Outputs/Translated_Sequential_output/run_0/Translated_Sequential.py index ad48b834649a9..66e2e8acdfb10 100644 --- a/ivy/compiler/_cache/Translated_Outputs/Translated_Sequential_output/run_0/Translated_Sequential.py +++ b/ivy/compiler/_cache/Translated_Outputs/Translated_Sequential_output/run_0/Translated_Sequential.py @@ -1,10 +1,11 @@ +import ivy.functional.frontends.torch as torch import ivy.functional.frontends.torch.nn as nn -import typing import operator -from collections import OrderedDict +import typing from typing import overload from itertools import islice +from collections import OrderedDict class Translated_Sequential(nn.Module): @@ -142,8 +143,10 @@ def append(self, module): return self def insert(self, index, module): - if not isinstance(module, nn.Module): - raise AssertionError(f"module should be of type: {nn.Module}") + if not isinstance(module, torch.nn.modules.module.Module): + raise AssertionError( + f"module should be of type: {torch.nn.modules.module.Module}" + ) n = len(self._modules) if not -n <= index <= n: raise IndexError(f"Index out of range: {index}") diff --git a/ivy/compiler/_cache/Translated_Outputs/ivy_BatchNorm2d_output/run_0/ivy__BatchNorm.py b/ivy/compiler/_cache/Translated_Outputs/ivy_BatchNorm2d_output/run_0/ivy__BatchNorm.py index 808b96cb82c98..fd0f6561cbe40 100644 --- a/ivy/compiler/_cache/Translated_Outputs/ivy_BatchNorm2d_output/run_0/ivy__BatchNorm.py +++ b/ivy/compiler/_cache/Translated_Outputs/ivy_BatchNorm2d_output/run_0/ivy__BatchNorm.py @@ -47,11 +47,9 @@ 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, diff --git a/ivy/compiler/_cache/Translated_Outputs/ivy_Conv2d_output/run_0/ivy_Conv2d.py b/ivy/compiler/_cache/Translated_Outputs/ivy_Conv2d_output/run_0/ivy_Conv2d.py index 0982c15c6ba84..842703da0c2d2 100644 --- a/ivy/compiler/_cache/Translated_Outputs/ivy_Conv2d_output/run_0/ivy_Conv2d.py +++ b/ivy/compiler/_cache/Translated_Outputs/ivy_Conv2d_output/run_0/ivy_Conv2d.py @@ -1,7 +1,9 @@ from .ivy__ConvNd import ivy__ConvNd +from .ivy__helpers import ivy__ntuple from .ivy__helpers import ivy_conv2d_frnt from .ivy__helpers import ivy_pad_frnt -from .ivy__helpers import ivy_parse + +_pair = ivy__ntuple(2, "_pair") class ivy_Conv2d(ivy__ConvNd): @@ -20,10 +22,10 @@ def __init__( dtype=None, ): factory_kwargs = {"device": device, "dtype": dtype} - kernel_size_ = ivy_parse(kernel_size) - stride_ = ivy_parse(stride) - padding_ = padding if isinstance(padding, str) else ivy_parse(padding) - dilation_ = ivy_parse(dilation) + kernel_size_ = _pair(kernel_size) + stride_ = _pair(stride) + padding_ = padding if isinstance(padding, str) else _pair(padding) + dilation_ = _pair(dilation) super().__init__( in_channels, out_channels, @@ -32,7 +34,7 @@ def __init__( padding_, dilation_, False, - ivy_parse(0), + _pair(0), groups, bias, padding_mode, @@ -48,7 +50,7 @@ def _conv_forward(self, input, weight, bias): weight, bias, self.stride, - ivy_parse(0), + _pair(0), self.dilation, self.groups, ) diff --git a/ivy/compiler/_cache/Translated_Outputs/ivy_Conv2d_output/run_0/ivy__ConvNd.py b/ivy/compiler/_cache/Translated_Outputs/ivy_Conv2d_output/run_0/ivy__ConvNd.py index 9145206ed3426..6bca3fd801783 100644 --- a/ivy/compiler/_cache/Translated_Outputs/ivy_Conv2d_output/run_0/ivy__ConvNd.py +++ b/ivy/compiler/_cache/Translated_Outputs/ivy_Conv2d_output/run_0/ivy__ConvNd.py @@ -1,8 +1,8 @@ import ivy from collections import OrderedDict -import math import typing +import math from typing import Optional from .ivy__helpers import ivy__calculate_fan_in_and_fan_out diff --git a/ivy/compiler/_cache/Translated_Outputs/ivy_Conv2d_output/run_0/ivy__helpers.py b/ivy/compiler/_cache/Translated_Outputs/ivy_Conv2d_output/run_0/ivy__helpers.py index da132a72bcfe1..040603d127006 100644 --- a/ivy/compiler/_cache/Translated_Outputs/ivy_Conv2d_output/run_0/ivy__helpers.py +++ b/ivy/compiler/_cache/Translated_Outputs/ivy_Conv2d_output/run_0/ivy__helpers.py @@ -7,6 +7,16 @@ import warnings +def ivy__ntuple(n, name="parse"): + def parse(x): + if isinstance(x, collections.abc.Iterable): + return tuple(x) + return tuple(repeat(x, n)) + + parse.__name__ = name + return parse + + def ivy__reverse_repeat_tuple(t, n): return tuple(x for x in reversed(t) for _ in range(n)) @@ -191,13 +201,6 @@ def ivy_add_frnt_(arr, other, *, alpha=1): return ivy_add_frnt(arr, other, alpha=alpha) -def ivy_parse(x): - n = 2 - if isinstance(x, collections.abc.Iterable): - return tuple(x) - return tuple(repeat(x, n)) - - def ivy__conv_frnt(input, weight, bias=None, stride=1, padding=0, dilation=1, groups=1): dims = len(input.shape) - 2 if isinstance(padding, str): diff --git a/ivy/compiler/_cache/Translated_Outputs/ivy_ConvTranspose2d_output/run_0/ivy_ConvTranspose2d.py b/ivy/compiler/_cache/Translated_Outputs/ivy_ConvTranspose2d_output/run_0/ivy_ConvTranspose2d.py index 9dedaada6c346..da06aed862f45 100644 --- a/ivy/compiler/_cache/Translated_Outputs/ivy_ConvTranspose2d_output/run_0/ivy_ConvTranspose2d.py +++ b/ivy/compiler/_cache/Translated_Outputs/ivy_ConvTranspose2d_output/run_0/ivy_ConvTranspose2d.py @@ -1,6 +1,8 @@ from .ivy__ConvTransposeNd import ivy__ConvTransposeNd +from .ivy__helpers import ivy__ntuple from .ivy__helpers import ivy_conv_transpose2d_frnt -from .ivy__helpers import ivy_parse + +_pair = ivy__ntuple(2, "_pair") class ivy_ConvTranspose2d(ivy__ConvTransposeNd): @@ -20,11 +22,11 @@ def __init__( dtype=None, ): factory_kwargs = {"device": device, "dtype": dtype} - kernel_size = ivy_parse(kernel_size) - stride = ivy_parse(stride) - padding = ivy_parse(padding) - dilation = ivy_parse(dilation) - output_padding = ivy_parse(output_padding) + kernel_size = _pair(kernel_size) + stride = _pair(stride) + padding = _pair(padding) + dilation = _pair(dilation) + output_padding = _pair(output_padding) super().__init__( in_channels, out_channels, diff --git a/ivy/compiler/_cache/Translated_Outputs/ivy_ConvTranspose2d_output/run_0/ivy__ConvTransposeNd.py b/ivy/compiler/_cache/Translated_Outputs/ivy_ConvTranspose2d_output/run_0/ivy__ConvTransposeNd.py index 6205ffa0d4251..f02497b801953 100644 --- a/ivy/compiler/_cache/Translated_Outputs/ivy_ConvTranspose2d_output/run_0/ivy__ConvTransposeNd.py +++ b/ivy/compiler/_cache/Translated_Outputs/ivy_ConvTranspose2d_output/run_0/ivy__ConvTransposeNd.py @@ -1,8 +1,10 @@ from .ivy__ConvNd import ivy__ConvNd +from .ivy__helpers import ivy__ntuple from .ivy__helpers import ivy_dim_frnt_ -from .ivy__helpers import ivy_parse from .ivy__helpers import ivy_size_frnt_ +_single = ivy__ntuple(1, "_single") + class ivy__ConvTransposeNd(ivy__ConvNd): def __init__( @@ -52,7 +54,7 @@ def _output_padding( dilation=None, ): if output_size is None: - ret = ivy_parse(self.output_padding) + ret = _single(self.output_padding) else: has_batch_dim = ivy_dim_frnt_(input) == num_spatial_dims + 2 num_non_spatial_dims = 2 if has_batch_dim else 1 diff --git a/ivy/compiler/_cache/Translated_Outputs/ivy_ConvTranspose2d_output/run_0/ivy__helpers.py b/ivy/compiler/_cache/Translated_Outputs/ivy_ConvTranspose2d_output/run_0/ivy__helpers.py index 687ba8b1e3eb7..d47a130d70360 100644 --- a/ivy/compiler/_cache/Translated_Outputs/ivy_ConvTranspose2d_output/run_0/ivy__helpers.py +++ b/ivy/compiler/_cache/Translated_Outputs/ivy_ConvTranspose2d_output/run_0/ivy__helpers.py @@ -7,6 +7,16 @@ import warnings +def ivy__ntuple(n, name="parse"): + def parse(x): + if isinstance(x, collections.abc.Iterable): + return tuple(x) + return tuple(repeat(x, n)) + + parse.__name__ = name + return parse + + def ivy__reverse_repeat_tuple(t, n): return tuple(x for x in reversed(t) for _ in range(n)) @@ -191,13 +201,6 @@ def ivy_add_frnt_(arr, other, *, alpha=1): return ivy_add_frnt(arr, other, alpha=alpha) -def ivy_parse(x): - n = 1 - if isinstance(x, collections.abc.Iterable): - return tuple(x) - return tuple(repeat(x, n)) - - def ivy__get_transpose_pad_frnt(padding, output_padding, dims): padding, output_padding = map( lambda x: [x] * dims if isinstance(x, int) else x, [padding, output_padding] diff --git a/ivy/compiler/_cache/Translated_Outputs/ivy_LayerNorm_output/run_0/ivy_LayerNorm.py b/ivy/compiler/_cache/Translated_Outputs/ivy_LayerNorm_output/run_0/ivy_LayerNorm.py index 5deb458b7efd1..99e3d44f8a3c9 100644 --- a/ivy/compiler/_cache/Translated_Outputs/ivy_LayerNorm_output/run_0/ivy_LayerNorm.py +++ b/ivy/compiler/_cache/Translated_Outputs/ivy_LayerNorm_output/run_0/ivy_LayerNorm.py @@ -2,8 +2,8 @@ from collections import OrderedDict import threading -import typing import numbers +import typing from .ivy__helpers import ivy_add_frnt_ from .ivy__helpers import ivy_empty_frnt diff --git a/ivy/compiler/_cache/Translated_Outputs/ivy_Linear_output/run_0/ivy_Linear.py b/ivy/compiler/_cache/Translated_Outputs/ivy_Linear_output/run_0/ivy_Linear.py index 89183d65c71a1..d50e3b67a2819 100644 --- a/ivy/compiler/_cache/Translated_Outputs/ivy_Linear_output/run_0/ivy_Linear.py +++ b/ivy/compiler/_cache/Translated_Outputs/ivy_Linear_output/run_0/ivy_Linear.py @@ -2,8 +2,8 @@ from collections import OrderedDict import threading -import math import typing +import math from .ivy__helpers import ivy__calculate_fan_in_and_fan_out from .ivy__helpers import ivy_add_frnt_ diff --git a/ivy/compiler/_cache/Translated_Outputs/ivy_Sequential_output/run_0/ivy_Sequential.py b/ivy/compiler/_cache/Translated_Outputs/ivy_Sequential_output/run_0/ivy_Sequential.py index 1e2ae79d13e78..d0c33a9026f7e 100644 --- a/ivy/compiler/_cache/Translated_Outputs/ivy_Sequential_output/run_0/ivy_Sequential.py +++ b/ivy/compiler/_cache/Translated_Outputs/ivy_Sequential_output/run_0/ivy_Sequential.py @@ -2,8 +2,8 @@ from collections import OrderedDict import threading -import typing import operator +import typing from typing import overload from itertools import islice diff --git a/ivy/compiler/_cache/Translated_Outputs/tensorflow_AdaptiveAvgPool2d_output/run_0/tensorflow__helpers.py b/ivy/compiler/_cache/Translated_Outputs/tensorflow_AdaptiveAvgPool2d_output/run_0/tensorflow__helpers.py index 8a8a6510066e3..e786f9993754d 100644 --- a/ivy/compiler/_cache/Translated_Outputs/tensorflow_AdaptiveAvgPool2d_output/run_0/tensorflow__helpers.py +++ b/ivy/compiler/_cache/Translated_Outputs/tensorflow_AdaptiveAvgPool2d_output/run_0/tensorflow__helpers.py @@ -511,7 +511,9 @@ 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 ) @@ -916,27 +918,21 @@ 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 = [ @@ -1361,7 +1357,9 @@ 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) @@ -1773,7 +1771,9 @@ 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 ] @@ -1885,6 +1885,7 @@ def tensorflow_to_numpy( return np.asarray(tensorflow.convert_to_tensor(x)) +@tensorflow_handle_array_like_without_promotion def tensorflow_to_scalar(x: Union[tensorflow.Tensor, tensorflow.Variable], /): ret = tensorflow_to_numpy(x).item() if x.dtype == tensorflow.bfloat16: @@ -1892,9 +1893,8 @@ def tensorflow_to_scalar(x: Union[tensorflow.Tensor, tensorflow.Variable], /): return ret -@tensorflow_handle_array_like_without_promotion -def tensorflow_to_scalar_bknd(x: Union[tensorflow.Tensor, tf.Tensor], /): - return tensorflow_to_scalar(x) +def tensorflow_to_scalar_bknd_(self: tensorflow.Tensor): + return tensorflow_to_scalar(self) def tensorflow_is_float_dtype_bknd( @@ -1965,11 +1965,9 @@ 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 @@ -2091,7 +2089,7 @@ def tensorflow_prod( def tensorflow__numel_bknd(shape): shape = tuple(shape) - return tensorflow_to_scalar_bknd(tensorflow_prod(shape)) if shape != () else 1 + return tensorflow_to_scalar_bknd_(tensorflow_prod(shape)) if shape != () else 1 def tensorflow_check_one_way_broadcastable(x1, x2): @@ -2203,7 +2201,9 @@ 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) @@ -2363,11 +2363,9 @@ 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]) @@ -2714,21 +2712,17 @@ 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 @@ -2889,7 +2883,9 @@ 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) @@ -3217,7 +3213,9 @@ def tensorflow_divide( 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) @@ -3277,7 +3275,9 @@ def tensorflow_minimum( 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) @@ -3354,7 +3354,9 @@ def tensorflow_greater_equal( 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) diff --git a/ivy/compiler/_cache/Translated_Outputs/tensorflow_AvgPool2d_output/run_0/tensorflow_NestedSequence_bknd.py b/ivy/compiler/_cache/Translated_Outputs/tensorflow_AvgPool2d_output/run_0/tensorflow_NestedSequence_bknd.py index 9f87b4ae29eff..ac8335fe1e56c 100644 --- a/ivy/compiler/_cache/Translated_Outputs/tensorflow_AvgPool2d_output/run_0/tensorflow_NestedSequence_bknd.py +++ b/ivy/compiler/_cache/Translated_Outputs/tensorflow_AvgPool2d_output/run_0/tensorflow_NestedSequence_bknd.py @@ -1,5 +1,5 @@ -from typing import Protocol from typing import TypeVar +from typing import Protocol _T_co = TypeVar("_T_co", covariant=True) diff --git a/ivy/compiler/_cache/Translated_Outputs/tensorflow_AvgPool2d_output/run_0/tensorflow__helpers.py b/ivy/compiler/_cache/Translated_Outputs/tensorflow_AvgPool2d_output/run_0/tensorflow__helpers.py index dcc5b3403b52e..a432f5d0765e4 100644 --- a/ivy/compiler/_cache/Translated_Outputs/tensorflow_AvgPool2d_output/run_0/tensorflow__helpers.py +++ b/ivy/compiler/_cache/Translated_Outputs/tensorflow_AvgPool2d_output/run_0/tensorflow__helpers.py @@ -511,7 +511,9 @@ 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 ) @@ -916,27 +918,21 @@ 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 = [ @@ -1361,7 +1357,9 @@ 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) @@ -1773,7 +1771,9 @@ 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 ] @@ -1885,6 +1885,7 @@ def tensorflow_to_numpy( return np.asarray(tensorflow.convert_to_tensor(x)) +@tensorflow_handle_array_like_without_promotion def tensorflow_to_scalar(x: Union[tensorflow.Tensor, tensorflow.Variable], /): ret = tensorflow_to_numpy(x).item() if x.dtype == tensorflow.bfloat16: @@ -1892,9 +1893,8 @@ def tensorflow_to_scalar(x: Union[tensorflow.Tensor, tensorflow.Variable], /): return ret -@tensorflow_handle_array_like_without_promotion -def tensorflow_to_scalar_bknd(x: Union[tensorflow.Tensor, tf.Tensor], /): - return tensorflow_to_scalar(x) +def tensorflow_to_scalar_bknd_(self: tensorflow.Tensor): + return tensorflow_to_scalar(self) def tensorflow_is_float_dtype_bknd( @@ -1965,11 +1965,9 @@ 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 @@ -2091,7 +2089,7 @@ def tensorflow_prod( def tensorflow__numel_bknd(shape): shape = tuple(shape) - return tensorflow_to_scalar_bknd(tensorflow_prod(shape)) if shape != () else 1 + return tensorflow_to_scalar_bknd_(tensorflow_prod(shape)) if shape != () else 1 def tensorflow_check_one_way_broadcastable(x1, x2): @@ -2203,7 +2201,9 @@ 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) @@ -2363,11 +2363,9 @@ 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]) @@ -2714,21 +2712,17 @@ 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 @@ -2889,7 +2883,9 @@ 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) diff --git a/ivy/compiler/_cache/Translated_Outputs/tensorflow_BatchNorm2d_output/run_0/tensorflow__BatchNorm.py b/ivy/compiler/_cache/Translated_Outputs/tensorflow_BatchNorm2d_output/run_0/tensorflow__BatchNorm.py index f2f4878ab0f3c..855f7a97e77c0 100644 --- a/ivy/compiler/_cache/Translated_Outputs/tensorflow_BatchNorm2d_output/run_0/tensorflow__BatchNorm.py +++ b/ivy/compiler/_cache/Translated_Outputs/tensorflow_BatchNorm2d_output/run_0/tensorflow__BatchNorm.py @@ -1,5 +1,6 @@ import tensorflow + from .tensorflow__NormBase import tensorflow__NormBase from .tensorflow__helpers import tensorflow_add__frnt_ from .tensorflow__helpers import tensorflow_batch_norm_frnt @@ -55,16 +56,12 @@ 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, diff --git a/ivy/compiler/_cache/Translated_Outputs/tensorflow_BatchNorm2d_output/run_0/tensorflow__NormBase.py b/ivy/compiler/_cache/Translated_Outputs/tensorflow_BatchNorm2d_output/run_0/tensorflow__NormBase.py index bf904536e0536..b48ae673ea4b9 100644 --- a/ivy/compiler/_cache/Translated_Outputs/tensorflow_BatchNorm2d_output/run_0/tensorflow__NormBase.py +++ b/ivy/compiler/_cache/Translated_Outputs/tensorflow_BatchNorm2d_output/run_0/tensorflow__NormBase.py @@ -133,13 +133,11 @@ 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, diff --git a/ivy/compiler/_cache/Translated_Outputs/tensorflow_BatchNorm2d_output/run_0/tensorflow__helpers.py b/ivy/compiler/_cache/Translated_Outputs/tensorflow_BatchNorm2d_output/run_0/tensorflow__helpers.py index cb6c0e0c20dfe..7a84c41ecafba 100644 --- a/ivy/compiler/_cache/Translated_Outputs/tensorflow_BatchNorm2d_output/run_0/tensorflow__helpers.py +++ b/ivy/compiler/_cache/Translated_Outputs/tensorflow_BatchNorm2d_output/run_0/tensorflow__helpers.py @@ -472,7 +472,9 @@ 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 ) @@ -905,21 +907,17 @@ 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 @@ -1331,27 +1329,21 @@ 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 = [ @@ -1776,7 +1768,9 @@ 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) @@ -2188,7 +2182,9 @@ 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 ] @@ -2273,11 +2269,6 @@ def tensorflow__parse_query_bknd(query, x_shape, scatter=False): ) -@tensorflow_handle_array_like_without_promotion -def tensorflow_to_scalar_bknd(x: Union[tensorflow.Tensor, tf.Tensor], /): - return tensorflow_to_scalar(x) - - def tensorflow_default_uint_dtype_bknd( *, input: Optional[Union[tensorflow.Tensor, tf.Tensor]] = None, @@ -2302,11 +2293,9 @@ 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 @@ -2402,7 +2391,7 @@ def tensorflow_prod( def tensorflow__numel_bknd(shape): shape = tuple(shape) - return tensorflow_to_scalar_bknd(tensorflow_prod(shape)) if shape != () else 1 + return tensorflow_to_scalar_bknd_(tensorflow_prod(shape)) if shape != () else 1 def tensorflow_check_one_way_broadcastable(x1, x2): @@ -2514,7 +2503,9 @@ 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) @@ -2674,11 +2665,9 @@ 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]) @@ -3064,7 +3053,9 @@ 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) diff --git a/ivy/compiler/_cache/Translated_Outputs/tensorflow_Conv2d_output/run_0/tensorflow_Conv2d.py b/ivy/compiler/_cache/Translated_Outputs/tensorflow_Conv2d_output/run_0/tensorflow_Conv2d.py index 755bb840eda55..6967e1a0cf687 100644 --- a/ivy/compiler/_cache/Translated_Outputs/tensorflow_Conv2d_output/run_0/tensorflow_Conv2d.py +++ b/ivy/compiler/_cache/Translated_Outputs/tensorflow_Conv2d_output/run_0/tensorflow_Conv2d.py @@ -1,10 +1,10 @@ -import tensorflow - from .tensorflow__ConvNd import tensorflow__ConvNd +from .tensorflow__helpers import tensorflow__ntuple from .tensorflow__helpers import tensorflow_conv2d_frnt from .tensorflow__helpers import tensorflow_handle_transpose_in_input_and_output from .tensorflow__helpers import tensorflow_pad_frnt -from .tensorflow__helpers import tensorflow_parse + +_pair = tensorflow__ntuple(2, "_pair") class tensorflow_Conv2d(tensorflow__ConvNd): @@ -23,16 +23,10 @@ def __init__( dtype=None, ): factory_kwargs = {"device": device, "dtype": dtype} - with tensorflow.name_scope("tensorflow_Conv2d/kernel_size_"): - kernel_size_ = tensorflow_parse(kernel_size) - with tensorflow.name_scope("tensorflow_Conv2d/stride_"): - stride_ = tensorflow_parse(stride) - with tensorflow.name_scope("tensorflow_Conv2d/padding_"): - padding_ = ( - padding if isinstance(padding, str) else tensorflow_parse(padding) - ) - with tensorflow.name_scope("tensorflow_Conv2d/dilation_"): - dilation_ = tensorflow_parse(dilation) + kernel_size_ = _pair(kernel_size) + stride_ = _pair(stride) + padding_ = padding if isinstance(padding, str) else _pair(padding) + dilation_ = _pair(dilation) super().__init__( in_channels, out_channels, @@ -41,7 +35,7 @@ def __init__( padding_, dilation_, False, - tensorflow_parse(0), + _pair(0), groups, bias, padding_mode, @@ -57,7 +51,7 @@ def _conv_forward(self, input, weight, bias): weight, bias, self.stride, - tensorflow_parse(0), + _pair(0), self.dilation, self.groups, ) diff --git a/ivy/compiler/_cache/Translated_Outputs/tensorflow_Conv2d_output/run_0/tensorflow_NestedSequence_bknd.py b/ivy/compiler/_cache/Translated_Outputs/tensorflow_Conv2d_output/run_0/tensorflow_NestedSequence_bknd.py index ac8335fe1e56c..9f87b4ae29eff 100644 --- a/ivy/compiler/_cache/Translated_Outputs/tensorflow_Conv2d_output/run_0/tensorflow_NestedSequence_bknd.py +++ b/ivy/compiler/_cache/Translated_Outputs/tensorflow_Conv2d_output/run_0/tensorflow_NestedSequence_bknd.py @@ -1,5 +1,5 @@ -from typing import TypeVar from typing import Protocol +from typing import TypeVar _T_co = TypeVar("_T_co", covariant=True) diff --git a/ivy/compiler/_cache/Translated_Outputs/tensorflow_Conv2d_output/run_0/tensorflow__ConvNd.py b/ivy/compiler/_cache/Translated_Outputs/tensorflow_Conv2d_output/run_0/tensorflow__ConvNd.py index 5c033fbd60f5c..a866ab7b8f83a 100644 --- a/ivy/compiler/_cache/Translated_Outputs/tensorflow_Conv2d_output/run_0/tensorflow__ConvNd.py +++ b/ivy/compiler/_cache/Translated_Outputs/tensorflow_Conv2d_output/run_0/tensorflow__ConvNd.py @@ -1,8 +1,8 @@ import tensorflow from collections import OrderedDict -import math import typing +import math from typing import Optional from .tensorflow__stateful import Layer as tensorflow_keras_Layer diff --git a/ivy/compiler/_cache/Translated_Outputs/tensorflow_Conv2d_output/run_0/tensorflow__helpers.py b/ivy/compiler/_cache/Translated_Outputs/tensorflow_Conv2d_output/run_0/tensorflow__helpers.py index f40c24c3ded6b..9b6e1d7fe8dd1 100644 --- a/ivy/compiler/_cache/Translated_Outputs/tensorflow_Conv2d_output/run_0/tensorflow__helpers.py +++ b/ivy/compiler/_cache/Translated_Outputs/tensorflow_Conv2d_output/run_0/tensorflow__helpers.py @@ -1,5 +1,6 @@ from collections import UserDict from itertools import repeat +from ivy.utils.backend import backend_stack from numbers import Number from numpy.core.numeric import normalize_axis_tuple from operator import mul @@ -421,6 +422,16 @@ def _handle_array_like_without_promotion(*args, **kwargs): return _handle_array_like_without_promotion +def tensorflow__ntuple(n, name="parse"): + def parse(x): + if isinstance(x, collections.abc.Iterable): + return tuple(x) + return tuple(repeat(x, n)) + + parse.__name__ = name + return parse + + def tensorflow_is_native_array(x, /, *, exclusive=False): if "keras.src.backend.tensorflow.core.Variable" in str(x.__class__): return not exclusive @@ -477,7 +488,9 @@ 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 ) @@ -910,21 +923,17 @@ 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 @@ -1312,27 +1321,21 @@ 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 = [ @@ -1781,7 +1784,9 @@ 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) @@ -2193,7 +2198,9 @@ 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 ] @@ -2305,6 +2312,7 @@ def tensorflow_to_numpy( return np.asarray(tensorflow.convert_to_tensor(x)) +@tensorflow_handle_array_like_without_promotion def tensorflow_to_scalar(x: Union[tensorflow.Tensor, tensorflow.Variable], /): ret = tensorflow_to_numpy(x).item() if x.dtype == tensorflow.bfloat16: @@ -2312,9 +2320,8 @@ def tensorflow_to_scalar(x: Union[tensorflow.Tensor, tensorflow.Variable], /): return ret -@tensorflow_handle_array_like_without_promotion -def tensorflow_to_scalar_bknd(x: Union[tensorflow.Tensor, tf.Tensor], /): - return tensorflow_to_scalar(x) +def tensorflow_to_scalar_bknd_(self: tensorflow.Tensor): + return tensorflow_to_scalar(self) def tensorflow_default_uint_dtype_bknd( @@ -2341,11 +2348,9 @@ 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 @@ -2441,7 +2446,7 @@ def tensorflow_prod( def tensorflow__numel_bknd(shape): shape = tuple(shape) - return tensorflow_to_scalar_bknd(tensorflow_prod(shape)) if shape != () else 1 + return tensorflow_to_scalar_bknd_(tensorflow_prod(shape)) if shape != () else 1 def tensorflow_check_one_way_broadcastable(x1, x2): @@ -2553,7 +2558,9 @@ 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) @@ -2713,11 +2720,9 @@ 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]) @@ -2816,10 +2821,6 @@ def tensorflow__reverse_repeat_tuple(t, n): return tuple(x for x in reversed(t) for _ in range(n)) -def tensorflow_to_scalar_bknd_(self: tensorflow.Tensor): - return tensorflow_to_scalar(self) - - def tensorflow_empty_frnt( *args, size=None, @@ -3032,15 +3033,13 @@ def tensorflow_random_uniform( ): shape = tensorflow__check_bounds_and_get_shape_bknd( low, - ( - float( - tensorflow.experimental.numpy.finfo(tensorflow.float32).max - if dtype is None - else tensorflow.experimental.numpy.finfo(dtype).max - ) - if high is None - else high - ), + float( + tensorflow.experimental.numpy.finfo(tensorflow.float32).max + if dtype is None + else tensorflow.experimental.numpy.finfo(dtype).max + ) + if high is None + else high, shape, ) low = tensorflow.cast(low, dtype) @@ -3140,7 +3139,9 @@ 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) @@ -3166,13 +3167,6 @@ def tensorflow_add_frnt_(tensor, other, *, alpha=1): return tensorflow_add_frnt(tensor, other, alpha=alpha) -def tensorflow_parse(x): - n = 2 - if isinstance(x, collections.abc.Iterable): - return tuple(x) - return tuple(repeat(x, n)) - - def tensorflow__get_x_data_format_bknd( dims: int = 2, data_format: str = "channel_first" ): diff --git a/ivy/compiler/_cache/Translated_Outputs/tensorflow_ConvTranspose2d_output/run_0/tensorflow_ConvTranspose2d.py b/ivy/compiler/_cache/Translated_Outputs/tensorflow_ConvTranspose2d_output/run_0/tensorflow_ConvTranspose2d.py index 289d11ef10f8e..d7bd945956963 100644 --- a/ivy/compiler/_cache/Translated_Outputs/tensorflow_ConvTranspose2d_output/run_0/tensorflow_ConvTranspose2d.py +++ b/ivy/compiler/_cache/Translated_Outputs/tensorflow_ConvTranspose2d_output/run_0/tensorflow_ConvTranspose2d.py @@ -1,9 +1,9 @@ -import tensorflow - from .tensorflow__ConvTransposeNd import tensorflow__ConvTransposeNd +from .tensorflow__helpers import tensorflow__ntuple from .tensorflow__helpers import tensorflow_conv_transpose2d_frnt from .tensorflow__helpers import tensorflow_handle_transpose_in_input_and_output -from .tensorflow__helpers import tensorflow_parse + +_pair = tensorflow__ntuple(2, "_pair") class tensorflow_ConvTranspose2d(tensorflow__ConvTransposeNd): @@ -23,16 +23,11 @@ def __init__( dtype=None, ): factory_kwargs = {"device": device, "dtype": dtype} - with tensorflow.name_scope("tensorflow_ConvTranspose2d/kernel_size"): - kernel_size = tensorflow_parse(kernel_size) - with tensorflow.name_scope("tensorflow_ConvTranspose2d/stride"): - stride = tensorflow_parse(stride) - with tensorflow.name_scope("tensorflow_ConvTranspose2d/padding"): - padding = tensorflow_parse(padding) - with tensorflow.name_scope("tensorflow_ConvTranspose2d/dilation"): - dilation = tensorflow_parse(dilation) - with tensorflow.name_scope("tensorflow_ConvTranspose2d/output_padding"): - output_padding = tensorflow_parse(output_padding) + kernel_size = _pair(kernel_size) + stride = _pair(stride) + padding = _pair(padding) + dilation = _pair(dilation) + output_padding = _pair(output_padding) super().__init__( in_channels, out_channels, diff --git a/ivy/compiler/_cache/Translated_Outputs/tensorflow_ConvTranspose2d_output/run_0/tensorflow_NestedSequence_bknd.py b/ivy/compiler/_cache/Translated_Outputs/tensorflow_ConvTranspose2d_output/run_0/tensorflow_NestedSequence_bknd.py index ac8335fe1e56c..9f87b4ae29eff 100644 --- a/ivy/compiler/_cache/Translated_Outputs/tensorflow_ConvTranspose2d_output/run_0/tensorflow_NestedSequence_bknd.py +++ b/ivy/compiler/_cache/Translated_Outputs/tensorflow_ConvTranspose2d_output/run_0/tensorflow_NestedSequence_bknd.py @@ -1,5 +1,5 @@ -from typing import TypeVar from typing import Protocol +from typing import TypeVar _T_co = TypeVar("_T_co", covariant=True) diff --git a/ivy/compiler/_cache/Translated_Outputs/tensorflow_ConvTranspose2d_output/run_0/tensorflow__ConvTransposeNd.py b/ivy/compiler/_cache/Translated_Outputs/tensorflow_ConvTranspose2d_output/run_0/tensorflow__ConvTransposeNd.py index 3a9d696d9941e..03a24ee2e0126 100644 --- a/ivy/compiler/_cache/Translated_Outputs/tensorflow_ConvTranspose2d_output/run_0/tensorflow__ConvTransposeNd.py +++ b/ivy/compiler/_cache/Translated_Outputs/tensorflow_ConvTranspose2d_output/run_0/tensorflow__ConvTransposeNd.py @@ -1,12 +1,15 @@ import tensorflow + from .tensorflow__ConvNd import tensorflow__ConvNd +from .tensorflow__helpers import tensorflow__ntuple from .tensorflow__helpers import tensorflow_dim_frnt_ from .tensorflow__helpers import tensorflow_get_item -from .tensorflow__helpers import tensorflow_parse from .tensorflow__helpers import tensorflow_size_frnt_ from .tensorflow__helpers import tensorflow_store_config_info +_single = tensorflow__ntuple(1, "_single") + class tensorflow__ConvTransposeNd(tensorflow__ConvNd): @tensorflow_store_config_info @@ -57,8 +60,7 @@ def _output_padding( dilation=None, ): if output_size is None: - with tensorflow.name_scope("ret"): - ret = tensorflow_parse(self.output_padding) + ret = _single(self.output_padding) else: with tensorflow.name_scope("has_batch_dim"): has_batch_dim = tensorflow_dim_frnt_(input) == num_spatial_dims + 2 diff --git a/ivy/compiler/_cache/Translated_Outputs/tensorflow_ConvTranspose2d_output/run_0/tensorflow__helpers.py b/ivy/compiler/_cache/Translated_Outputs/tensorflow_ConvTranspose2d_output/run_0/tensorflow__helpers.py index 3a38496294466..12f09e1a25961 100644 --- a/ivy/compiler/_cache/Translated_Outputs/tensorflow_ConvTranspose2d_output/run_0/tensorflow__helpers.py +++ b/ivy/compiler/_cache/Translated_Outputs/tensorflow_ConvTranspose2d_output/run_0/tensorflow__helpers.py @@ -1,5 +1,6 @@ from collections import UserDict from itertools import repeat +from ivy.utils.backend import backend_stack from numbers import Number from numpy.core.numeric import normalize_axis_tuple from operator import mul @@ -420,6 +421,16 @@ def _handle_array_like_without_promotion(*args, **kwargs): return _handle_array_like_without_promotion +def tensorflow__ntuple(n, name="parse"): + def parse(x): + if isinstance(x, collections.abc.Iterable): + return tuple(x) + return tuple(repeat(x, n)) + + parse.__name__ = name + return parse + + def tensorflow_is_native_array(x, /, *, exclusive=False): if "keras.src.backend.tensorflow.core.Variable" in str(x.__class__): return not exclusive @@ -476,7 +487,9 @@ 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 ) @@ -909,21 +922,17 @@ 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 @@ -1311,27 +1320,21 @@ 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 = [ @@ -1780,7 +1783,9 @@ 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) @@ -2192,7 +2197,9 @@ 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 ] @@ -2304,6 +2311,7 @@ def tensorflow_to_numpy( return np.asarray(tensorflow.convert_to_tensor(x)) +@tensorflow_handle_array_like_without_promotion def tensorflow_to_scalar(x: Union[tensorflow.Tensor, tensorflow.Variable], /): ret = tensorflow_to_numpy(x).item() if x.dtype == tensorflow.bfloat16: @@ -2311,9 +2319,8 @@ def tensorflow_to_scalar(x: Union[tensorflow.Tensor, tensorflow.Variable], /): return ret -@tensorflow_handle_array_like_without_promotion -def tensorflow_to_scalar_bknd(x: Union[tensorflow.Tensor, tf.Tensor], /): - return tensorflow_to_scalar(x) +def tensorflow_to_scalar_bknd_(self: tensorflow.Tensor): + return tensorflow_to_scalar(self) def tensorflow_default_uint_dtype_bknd( @@ -2340,11 +2347,9 @@ 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 @@ -2440,7 +2445,7 @@ def tensorflow_prod( def tensorflow__numel_bknd(shape): shape = tuple(shape) - return tensorflow_to_scalar_bknd(tensorflow_prod(shape)) if shape != () else 1 + return tensorflow_to_scalar_bknd_(tensorflow_prod(shape)) if shape != () else 1 def tensorflow_check_one_way_broadcastable(x1, x2): @@ -2552,7 +2557,9 @@ 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) @@ -2712,11 +2719,9 @@ 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]) @@ -2815,10 +2820,6 @@ def tensorflow__reverse_repeat_tuple(t, n): return tuple(x for x in reversed(t) for _ in range(n)) -def tensorflow_to_scalar_bknd_(self: tensorflow.Tensor): - return tensorflow_to_scalar(self) - - def tensorflow_empty_frnt( *args, size=None, @@ -3031,15 +3032,13 @@ def tensorflow_random_uniform( ): shape = tensorflow__check_bounds_and_get_shape_bknd( low, - ( - float( - tensorflow.experimental.numpy.finfo(tensorflow.float32).max - if dtype is None - else tensorflow.experimental.numpy.finfo(dtype).max - ) - if high is None - else high - ), + float( + tensorflow.experimental.numpy.finfo(tensorflow.float32).max + if dtype is None + else tensorflow.experimental.numpy.finfo(dtype).max + ) + if high is None + else high, shape, ) low = tensorflow.cast(low, dtype) @@ -3139,7 +3138,9 @@ 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) @@ -3165,13 +3166,6 @@ def tensorflow_add_frnt_(tensor, other, *, alpha=1): return tensorflow_add_frnt(tensor, other, alpha=alpha) -def tensorflow_parse(x): - n = 1 - if isinstance(x, collections.abc.Iterable): - return tuple(x) - return tuple(repeat(x, n)) - - def tensorflow_current_backend_str(): return "tensorflow" diff --git a/ivy/compiler/_cache/Translated_Outputs/tensorflow_Dropout2d_output/run_0/tensorflow_NestedSequence_bknd.py b/ivy/compiler/_cache/Translated_Outputs/tensorflow_Dropout2d_output/run_0/tensorflow_NestedSequence_bknd.py index 9f87b4ae29eff..ac8335fe1e56c 100644 --- a/ivy/compiler/_cache/Translated_Outputs/tensorflow_Dropout2d_output/run_0/tensorflow_NestedSequence_bknd.py +++ b/ivy/compiler/_cache/Translated_Outputs/tensorflow_Dropout2d_output/run_0/tensorflow_NestedSequence_bknd.py @@ -1,5 +1,5 @@ -from typing import Protocol from typing import TypeVar +from typing import Protocol _T_co = TypeVar("_T_co", covariant=True) diff --git a/ivy/compiler/_cache/Translated_Outputs/tensorflow_Dropout2d_output/run_0/tensorflow__helpers.py b/ivy/compiler/_cache/Translated_Outputs/tensorflow_Dropout2d_output/run_0/tensorflow__helpers.py index 32daecec33d79..e18a4d1968d77 100644 --- a/ivy/compiler/_cache/Translated_Outputs/tensorflow_Dropout2d_output/run_0/tensorflow__helpers.py +++ b/ivy/compiler/_cache/Translated_Outputs/tensorflow_Dropout2d_output/run_0/tensorflow__helpers.py @@ -510,7 +510,9 @@ 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 ) @@ -915,27 +917,21 @@ 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 = [ @@ -1360,7 +1356,9 @@ 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) @@ -1772,7 +1770,9 @@ 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 ] @@ -1884,6 +1884,7 @@ def tensorflow_to_numpy( return np.asarray(tensorflow.convert_to_tensor(x)) +@tensorflow_handle_array_like_without_promotion def tensorflow_to_scalar(x: Union[tensorflow.Tensor, tensorflow.Variable], /): ret = tensorflow_to_numpy(x).item() if x.dtype == tensorflow.bfloat16: @@ -1891,9 +1892,8 @@ def tensorflow_to_scalar(x: Union[tensorflow.Tensor, tensorflow.Variable], /): return ret -@tensorflow_handle_array_like_without_promotion -def tensorflow_to_scalar_bknd(x: Union[tensorflow.Tensor, tf.Tensor], /): - return tensorflow_to_scalar(x) +def tensorflow_to_scalar_bknd_(self: tensorflow.Tensor): + return tensorflow_to_scalar(self) def tensorflow_is_float_dtype_bknd( @@ -1964,11 +1964,9 @@ 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 @@ -2090,7 +2088,7 @@ def tensorflow_prod( def tensorflow__numel_bknd(shape): shape = tuple(shape) - return tensorflow_to_scalar_bknd(tensorflow_prod(shape)) if shape != () else 1 + return tensorflow_to_scalar_bknd_(tensorflow_prod(shape)) if shape != () else 1 def tensorflow_check_one_way_broadcastable(x1, x2): @@ -2202,7 +2200,9 @@ 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) @@ -2362,11 +2362,9 @@ 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]) @@ -2713,21 +2711,17 @@ 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 @@ -2888,7 +2882,9 @@ 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) diff --git a/ivy/compiler/_cache/Translated_Outputs/tensorflow_LayerNorm_output/run_0/tensorflow_LayerNorm.py b/ivy/compiler/_cache/Translated_Outputs/tensorflow_LayerNorm_output/run_0/tensorflow_LayerNorm.py index 6f915dfcecfdf..42815bfc8b5bb 100644 --- a/ivy/compiler/_cache/Translated_Outputs/tensorflow_LayerNorm_output/run_0/tensorflow_LayerNorm.py +++ b/ivy/compiler/_cache/Translated_Outputs/tensorflow_LayerNorm_output/run_0/tensorflow_LayerNorm.py @@ -2,8 +2,8 @@ from collections import OrderedDict import threading -import typing import numbers +import typing from .tensorflow__stateful import Model as tensorflow_keras_Model from .tensorflow__helpers import tensorflow__is_variable_bknd diff --git a/ivy/compiler/_cache/Translated_Outputs/tensorflow_LayerNorm_output/run_0/tensorflow_NestedSequence_bknd.py b/ivy/compiler/_cache/Translated_Outputs/tensorflow_LayerNorm_output/run_0/tensorflow_NestedSequence_bknd.py index ac8335fe1e56c..9f87b4ae29eff 100644 --- a/ivy/compiler/_cache/Translated_Outputs/tensorflow_LayerNorm_output/run_0/tensorflow_NestedSequence_bknd.py +++ b/ivy/compiler/_cache/Translated_Outputs/tensorflow_LayerNorm_output/run_0/tensorflow_NestedSequence_bknd.py @@ -1,5 +1,5 @@ -from typing import TypeVar from typing import Protocol +from typing import TypeVar _T_co = TypeVar("_T_co", covariant=True) diff --git a/ivy/compiler/_cache/Translated_Outputs/tensorflow_LayerNorm_output/run_0/tensorflow__helpers.py b/ivy/compiler/_cache/Translated_Outputs/tensorflow_LayerNorm_output/run_0/tensorflow__helpers.py index 5fb0b4f4c770e..036ba1b17f446 100644 --- a/ivy/compiler/_cache/Translated_Outputs/tensorflow_LayerNorm_output/run_0/tensorflow__helpers.py +++ b/ivy/compiler/_cache/Translated_Outputs/tensorflow_LayerNorm_output/run_0/tensorflow__helpers.py @@ -334,7 +334,9 @@ 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 ) @@ -767,21 +769,17 @@ 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 @@ -1193,27 +1191,21 @@ 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 = [ @@ -1638,7 +1630,9 @@ 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) @@ -2050,7 +2044,9 @@ 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 ] @@ -2135,11 +2131,6 @@ def tensorflow__parse_query_bknd(query, x_shape, scatter=False): ) -@tensorflow_handle_array_like_without_promotion -def tensorflow_to_scalar_bknd(x: Union[tensorflow.Tensor, tf.Tensor], /): - return tensorflow_to_scalar(x) - - def tensorflow_default_uint_dtype_bknd( *, input: Optional[Union[tensorflow.Tensor, tf.Tensor]] = None, @@ -2164,11 +2155,9 @@ 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 @@ -2264,7 +2253,7 @@ def tensorflow_prod( def tensorflow__numel_bknd(shape): shape = tuple(shape) - return tensorflow_to_scalar_bknd(tensorflow_prod(shape)) if shape != () else 1 + return tensorflow_to_scalar_bknd_(tensorflow_prod(shape)) if shape != () else 1 def tensorflow_check_one_way_broadcastable(x1, x2): @@ -2376,7 +2365,9 @@ 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) @@ -2536,11 +2527,9 @@ 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]) @@ -2820,7 +2809,9 @@ def tensorflow_equal( 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) @@ -2892,7 +2883,9 @@ 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) diff --git a/ivy/compiler/_cache/Translated_Outputs/tensorflow_Linear_output/run_0/tensorflow_NestedSequence_bknd.py b/ivy/compiler/_cache/Translated_Outputs/tensorflow_Linear_output/run_0/tensorflow_NestedSequence_bknd.py index 9f87b4ae29eff..ac8335fe1e56c 100644 --- a/ivy/compiler/_cache/Translated_Outputs/tensorflow_Linear_output/run_0/tensorflow_NestedSequence_bknd.py +++ b/ivy/compiler/_cache/Translated_Outputs/tensorflow_Linear_output/run_0/tensorflow_NestedSequence_bknd.py @@ -1,5 +1,5 @@ -from typing import Protocol from typing import TypeVar +from typing import Protocol _T_co = TypeVar("_T_co", covariant=True) diff --git a/ivy/compiler/_cache/Translated_Outputs/tensorflow_Linear_output/run_0/tensorflow__helpers.py b/ivy/compiler/_cache/Translated_Outputs/tensorflow_Linear_output/run_0/tensorflow__helpers.py index 0380bbe57701b..6136707cf74ef 100644 --- a/ivy/compiler/_cache/Translated_Outputs/tensorflow_Linear_output/run_0/tensorflow__helpers.py +++ b/ivy/compiler/_cache/Translated_Outputs/tensorflow_Linear_output/run_0/tensorflow__helpers.py @@ -334,7 +334,9 @@ 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 ) @@ -767,21 +769,17 @@ 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 @@ -1193,27 +1191,21 @@ 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 = [ @@ -1638,7 +1630,9 @@ 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) @@ -2050,7 +2044,9 @@ 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 ] @@ -2162,6 +2158,7 @@ def tensorflow_to_numpy( return np.asarray(tensorflow.convert_to_tensor(x)) +@tensorflow_handle_array_like_without_promotion def tensorflow_to_scalar(x: Union[tensorflow.Tensor, tensorflow.Variable], /): ret = tensorflow_to_numpy(x).item() if x.dtype == tensorflow.bfloat16: @@ -2169,9 +2166,8 @@ def tensorflow_to_scalar(x: Union[tensorflow.Tensor, tensorflow.Variable], /): return ret -@tensorflow_handle_array_like_without_promotion -def tensorflow_to_scalar_bknd(x: Union[tensorflow.Tensor, tf.Tensor], /): - return tensorflow_to_scalar(x) +def tensorflow_to_scalar_bknd_(self: tensorflow.Tensor): + return tensorflow_to_scalar(self) def tensorflow_default_uint_dtype_bknd( @@ -2198,11 +2194,9 @@ 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 @@ -2298,7 +2292,7 @@ def tensorflow_prod( def tensorflow__numel_bknd(shape): shape = tuple(shape) - return tensorflow_to_scalar_bknd(tensorflow_prod(shape)) if shape != () else 1 + return tensorflow_to_scalar_bknd_(tensorflow_prod(shape)) if shape != () else 1 def tensorflow_check_one_way_broadcastable(x1, x2): @@ -2410,7 +2404,9 @@ 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) @@ -2570,11 +2566,9 @@ 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]) diff --git a/ivy/compiler/_cache/Translated_Outputs/tensorflow_MaxPool2d_output/run_0/tensorflow_NestedSequence_bknd.py b/ivy/compiler/_cache/Translated_Outputs/tensorflow_MaxPool2d_output/run_0/tensorflow_NestedSequence_bknd.py index 9f87b4ae29eff..ac8335fe1e56c 100644 --- a/ivy/compiler/_cache/Translated_Outputs/tensorflow_MaxPool2d_output/run_0/tensorflow_NestedSequence_bknd.py +++ b/ivy/compiler/_cache/Translated_Outputs/tensorflow_MaxPool2d_output/run_0/tensorflow_NestedSequence_bknd.py @@ -1,5 +1,5 @@ -from typing import Protocol from typing import TypeVar +from typing import Protocol _T_co = TypeVar("_T_co", covariant=True) diff --git a/ivy/compiler/_cache/Translated_Outputs/tensorflow_MaxPool2d_output/run_0/tensorflow__helpers.py b/ivy/compiler/_cache/Translated_Outputs/tensorflow_MaxPool2d_output/run_0/tensorflow__helpers.py index 1f02c6209012c..bd5614914252d 100644 --- a/ivy/compiler/_cache/Translated_Outputs/tensorflow_MaxPool2d_output/run_0/tensorflow__helpers.py +++ b/ivy/compiler/_cache/Translated_Outputs/tensorflow_MaxPool2d_output/run_0/tensorflow__helpers.py @@ -511,7 +511,9 @@ 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 ) @@ -916,27 +918,21 @@ 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 = [ @@ -1361,7 +1357,9 @@ 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) @@ -1773,7 +1771,9 @@ 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 ] @@ -1885,6 +1885,7 @@ def tensorflow_to_numpy( return np.asarray(tensorflow.convert_to_tensor(x)) +@tensorflow_handle_array_like_without_promotion def tensorflow_to_scalar(x: Union[tensorflow.Tensor, tensorflow.Variable], /): ret = tensorflow_to_numpy(x).item() if x.dtype == tensorflow.bfloat16: @@ -1892,9 +1893,8 @@ def tensorflow_to_scalar(x: Union[tensorflow.Tensor, tensorflow.Variable], /): return ret -@tensorflow_handle_array_like_without_promotion -def tensorflow_to_scalar_bknd(x: Union[tensorflow.Tensor, tf.Tensor], /): - return tensorflow_to_scalar(x) +def tensorflow_to_scalar_bknd_(self: tensorflow.Tensor): + return tensorflow_to_scalar(self) def tensorflow_is_float_dtype_bknd( @@ -1965,11 +1965,9 @@ 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 @@ -2091,7 +2089,7 @@ def tensorflow_prod( def tensorflow__numel_bknd(shape): shape = tuple(shape) - return tensorflow_to_scalar_bknd(tensorflow_prod(shape)) if shape != () else 1 + return tensorflow_to_scalar_bknd_(tensorflow_prod(shape)) if shape != () else 1 def tensorflow_check_one_way_broadcastable(x1, x2): @@ -2203,7 +2201,9 @@ 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) @@ -2363,11 +2363,9 @@ 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]) @@ -2714,21 +2712,17 @@ 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 @@ -2889,7 +2883,9 @@ 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) diff --git a/ivy/compiler/_cache/Translated_Outputs/tensorflow_ModuleDict_output/run_0/tensorflow_NestedSequence_bknd.py b/ivy/compiler/_cache/Translated_Outputs/tensorflow_ModuleDict_output/run_0/tensorflow_NestedSequence_bknd.py index ac8335fe1e56c..9f87b4ae29eff 100644 --- a/ivy/compiler/_cache/Translated_Outputs/tensorflow_ModuleDict_output/run_0/tensorflow_NestedSequence_bknd.py +++ b/ivy/compiler/_cache/Translated_Outputs/tensorflow_ModuleDict_output/run_0/tensorflow_NestedSequence_bknd.py @@ -1,5 +1,5 @@ -from typing import TypeVar from typing import Protocol +from typing import TypeVar _T_co = TypeVar("_T_co", covariant=True) diff --git a/ivy/compiler/_cache/Translated_Outputs/tensorflow_ModuleDict_output/run_0/tensorflow__helpers.py b/ivy/compiler/_cache/Translated_Outputs/tensorflow_ModuleDict_output/run_0/tensorflow__helpers.py index bbfd7f5944514..e3f6ae594e306 100644 --- a/ivy/compiler/_cache/Translated_Outputs/tensorflow_ModuleDict_output/run_0/tensorflow__helpers.py +++ b/ivy/compiler/_cache/Translated_Outputs/tensorflow_ModuleDict_output/run_0/tensorflow__helpers.py @@ -353,7 +353,9 @@ 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 ) @@ -758,27 +760,21 @@ 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 = [ @@ -1203,7 +1199,9 @@ 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) @@ -1615,7 +1613,9 @@ 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 ] @@ -1727,6 +1727,7 @@ def tensorflow_to_numpy( return np.asarray(tensorflow.convert_to_tensor(x)) +@tensorflow_handle_array_like_without_promotion def tensorflow_to_scalar(x: Union[tensorflow.Tensor, tensorflow.Variable], /): ret = tensorflow_to_numpy(x).item() if x.dtype == tensorflow.bfloat16: @@ -1734,9 +1735,8 @@ def tensorflow_to_scalar(x: Union[tensorflow.Tensor, tensorflow.Variable], /): return ret -@tensorflow_handle_array_like_without_promotion -def tensorflow_to_scalar_bknd(x: Union[tensorflow.Tensor, tf.Tensor], /): - return tensorflow_to_scalar(x) +def tensorflow_to_scalar_bknd_(self: tensorflow.Tensor): + return tensorflow_to_scalar(self) def tensorflow_is_float_dtype_bknd( @@ -1807,11 +1807,9 @@ 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 @@ -1933,7 +1931,7 @@ def tensorflow_prod( def tensorflow__numel_bknd(shape): shape = tuple(shape) - return tensorflow_to_scalar_bknd(tensorflow_prod(shape)) if shape != () else 1 + return tensorflow_to_scalar_bknd_(tensorflow_prod(shape)) if shape != () else 1 def tensorflow_check_one_way_broadcastable(x1, x2): @@ -2045,7 +2043,9 @@ 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) @@ -2205,11 +2205,9 @@ 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]) @@ -2556,21 +2554,17 @@ 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 @@ -2731,7 +2725,9 @@ 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) diff --git a/ivy/compiler/_cache/Translated_Outputs/tensorflow_ModuleList_output/run_0/tensorflow__helpers.py b/ivy/compiler/_cache/Translated_Outputs/tensorflow_ModuleList_output/run_0/tensorflow__helpers.py index 139e27cb83817..ca9c9c23ba32e 100644 --- a/ivy/compiler/_cache/Translated_Outputs/tensorflow_ModuleList_output/run_0/tensorflow__helpers.py +++ b/ivy/compiler/_cache/Translated_Outputs/tensorflow_ModuleList_output/run_0/tensorflow__helpers.py @@ -353,7 +353,9 @@ 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 ) @@ -758,27 +760,21 @@ 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 = [ @@ -1203,7 +1199,9 @@ 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) @@ -1615,7 +1613,9 @@ 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 ] @@ -1727,6 +1727,7 @@ def tensorflow_to_numpy( return np.asarray(tensorflow.convert_to_tensor(x)) +@tensorflow_handle_array_like_without_promotion def tensorflow_to_scalar(x: Union[tensorflow.Tensor, tensorflow.Variable], /): ret = tensorflow_to_numpy(x).item() if x.dtype == tensorflow.bfloat16: @@ -1734,9 +1735,8 @@ def tensorflow_to_scalar(x: Union[tensorflow.Tensor, tensorflow.Variable], /): return ret -@tensorflow_handle_array_like_without_promotion -def tensorflow_to_scalar_bknd(x: Union[tensorflow.Tensor, tf.Tensor], /): - return tensorflow_to_scalar(x) +def tensorflow_to_scalar_bknd_(self: tensorflow.Tensor): + return tensorflow_to_scalar(self) def tensorflow_is_float_dtype_bknd( @@ -1807,11 +1807,9 @@ 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 @@ -1933,7 +1931,7 @@ def tensorflow_prod( def tensorflow__numel_bknd(shape): shape = tuple(shape) - return tensorflow_to_scalar_bknd(tensorflow_prod(shape)) if shape != () else 1 + return tensorflow_to_scalar_bknd_(tensorflow_prod(shape)) if shape != () else 1 def tensorflow_check_one_way_broadcastable(x1, x2): @@ -2045,7 +2043,9 @@ 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) @@ -2205,11 +2205,9 @@ 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]) @@ -2556,21 +2554,17 @@ 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 @@ -2742,7 +2736,9 @@ 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) diff --git a/ivy/compiler/_cache/Translated_Outputs/tensorflow_Sequential_output/run_0/tensorflow_NestedSequence_bknd.py b/ivy/compiler/_cache/Translated_Outputs/tensorflow_Sequential_output/run_0/tensorflow_NestedSequence_bknd.py index ac8335fe1e56c..9f87b4ae29eff 100644 --- a/ivy/compiler/_cache/Translated_Outputs/tensorflow_Sequential_output/run_0/tensorflow_NestedSequence_bknd.py +++ b/ivy/compiler/_cache/Translated_Outputs/tensorflow_Sequential_output/run_0/tensorflow_NestedSequence_bknd.py @@ -1,5 +1,5 @@ -from typing import TypeVar from typing import Protocol +from typing import TypeVar _T_co = TypeVar("_T_co", covariant=True) diff --git a/ivy/compiler/_cache/Translated_Outputs/tensorflow_Sequential_output/run_0/tensorflow_Sequential.py b/ivy/compiler/_cache/Translated_Outputs/tensorflow_Sequential_output/run_0/tensorflow_Sequential.py index bef14edf7dc82..3c7a5be748583 100644 --- a/ivy/compiler/_cache/Translated_Outputs/tensorflow_Sequential_output/run_0/tensorflow_Sequential.py +++ b/ivy/compiler/_cache/Translated_Outputs/tensorflow_Sequential_output/run_0/tensorflow_Sequential.py @@ -2,8 +2,8 @@ from collections import OrderedDict import threading -import typing import operator +import typing from typing import overload from itertools import islice diff --git a/ivy/compiler/_cache/Translated_Outputs/tensorflow_Sequential_output/run_0/tensorflow__helpers.py b/ivy/compiler/_cache/Translated_Outputs/tensorflow_Sequential_output/run_0/tensorflow__helpers.py index bbfd7f5944514..e3f6ae594e306 100644 --- a/ivy/compiler/_cache/Translated_Outputs/tensorflow_Sequential_output/run_0/tensorflow__helpers.py +++ b/ivy/compiler/_cache/Translated_Outputs/tensorflow_Sequential_output/run_0/tensorflow__helpers.py @@ -353,7 +353,9 @@ 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 ) @@ -758,27 +760,21 @@ 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 = [ @@ -1203,7 +1199,9 @@ 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) @@ -1615,7 +1613,9 @@ 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 ] @@ -1727,6 +1727,7 @@ def tensorflow_to_numpy( return np.asarray(tensorflow.convert_to_tensor(x)) +@tensorflow_handle_array_like_without_promotion def tensorflow_to_scalar(x: Union[tensorflow.Tensor, tensorflow.Variable], /): ret = tensorflow_to_numpy(x).item() if x.dtype == tensorflow.bfloat16: @@ -1734,9 +1735,8 @@ def tensorflow_to_scalar(x: Union[tensorflow.Tensor, tensorflow.Variable], /): return ret -@tensorflow_handle_array_like_without_promotion -def tensorflow_to_scalar_bknd(x: Union[tensorflow.Tensor, tf.Tensor], /): - return tensorflow_to_scalar(x) +def tensorflow_to_scalar_bknd_(self: tensorflow.Tensor): + return tensorflow_to_scalar(self) def tensorflow_is_float_dtype_bknd( @@ -1807,11 +1807,9 @@ 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 @@ -1933,7 +1931,7 @@ def tensorflow_prod( def tensorflow__numel_bknd(shape): shape = tuple(shape) - return tensorflow_to_scalar_bknd(tensorflow_prod(shape)) if shape != () else 1 + return tensorflow_to_scalar_bknd_(tensorflow_prod(shape)) if shape != () else 1 def tensorflow_check_one_way_broadcastable(x1, x2): @@ -2045,7 +2043,9 @@ 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) @@ -2205,11 +2205,9 @@ 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]) @@ -2556,21 +2554,17 @@ 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 @@ -2731,7 +2725,9 @@ 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) diff --git a/ivy/compiler/_cache/Translated_Outputs/tensorflow_abs_output/run_0/tensorflow_NestedSequence_bknd.py b/ivy/compiler/_cache/Translated_Outputs/tensorflow_abs_output/run_0/tensorflow_NestedSequence_bknd.py index 9f87b4ae29eff..ac8335fe1e56c 100644 --- a/ivy/compiler/_cache/Translated_Outputs/tensorflow_abs_output/run_0/tensorflow_NestedSequence_bknd.py +++ b/ivy/compiler/_cache/Translated_Outputs/tensorflow_abs_output/run_0/tensorflow_NestedSequence_bknd.py @@ -1,5 +1,5 @@ -from typing import Protocol from typing import TypeVar +from typing import Protocol _T_co = TypeVar("_T_co", covariant=True) diff --git a/ivy/compiler/_cache/Translated_Outputs/tensorflow_abs_output/run_0/tensorflow__helpers.py b/ivy/compiler/_cache/Translated_Outputs/tensorflow_abs_output/run_0/tensorflow__helpers.py index 0380bbe57701b..6136707cf74ef 100644 --- a/ivy/compiler/_cache/Translated_Outputs/tensorflow_abs_output/run_0/tensorflow__helpers.py +++ b/ivy/compiler/_cache/Translated_Outputs/tensorflow_abs_output/run_0/tensorflow__helpers.py @@ -334,7 +334,9 @@ 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 ) @@ -767,21 +769,17 @@ 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 @@ -1193,27 +1191,21 @@ 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 = [ @@ -1638,7 +1630,9 @@ 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) @@ -2050,7 +2044,9 @@ 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 ] @@ -2162,6 +2158,7 @@ def tensorflow_to_numpy( return np.asarray(tensorflow.convert_to_tensor(x)) +@tensorflow_handle_array_like_without_promotion def tensorflow_to_scalar(x: Union[tensorflow.Tensor, tensorflow.Variable], /): ret = tensorflow_to_numpy(x).item() if x.dtype == tensorflow.bfloat16: @@ -2169,9 +2166,8 @@ def tensorflow_to_scalar(x: Union[tensorflow.Tensor, tensorflow.Variable], /): return ret -@tensorflow_handle_array_like_without_promotion -def tensorflow_to_scalar_bknd(x: Union[tensorflow.Tensor, tf.Tensor], /): - return tensorflow_to_scalar(x) +def tensorflow_to_scalar_bknd_(self: tensorflow.Tensor): + return tensorflow_to_scalar(self) def tensorflow_default_uint_dtype_bknd( @@ -2198,11 +2194,9 @@ 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 @@ -2298,7 +2292,7 @@ def tensorflow_prod( def tensorflow__numel_bknd(shape): shape = tuple(shape) - return tensorflow_to_scalar_bknd(tensorflow_prod(shape)) if shape != () else 1 + return tensorflow_to_scalar_bknd_(tensorflow_prod(shape)) if shape != () else 1 def tensorflow_check_one_way_broadcastable(x1, x2): @@ -2410,7 +2404,9 @@ 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) @@ -2570,11 +2566,9 @@ 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]) diff --git a/ivy/compiler/_cache/Translated_Outputs/tensorflow_add_output/run_0/tensorflow_NestedSequence_bknd.py b/ivy/compiler/_cache/Translated_Outputs/tensorflow_add_output/run_0/tensorflow_NestedSequence_bknd.py index 9f87b4ae29eff..ac8335fe1e56c 100644 --- a/ivy/compiler/_cache/Translated_Outputs/tensorflow_add_output/run_0/tensorflow_NestedSequence_bknd.py +++ b/ivy/compiler/_cache/Translated_Outputs/tensorflow_add_output/run_0/tensorflow_NestedSequence_bknd.py @@ -1,5 +1,5 @@ -from typing import Protocol from typing import TypeVar +from typing import Protocol _T_co = TypeVar("_T_co", covariant=True) diff --git a/ivy/compiler/_cache/Translated_Outputs/tensorflow_add_output/run_0/tensorflow__helpers.py b/ivy/compiler/_cache/Translated_Outputs/tensorflow_add_output/run_0/tensorflow__helpers.py index 9e72d6d13d0cc..e3969f60253de 100644 --- a/ivy/compiler/_cache/Translated_Outputs/tensorflow_add_output/run_0/tensorflow__helpers.py +++ b/ivy/compiler/_cache/Translated_Outputs/tensorflow_add_output/run_0/tensorflow__helpers.py @@ -310,7 +310,9 @@ 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 ) @@ -854,27 +856,21 @@ 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 = [ @@ -1299,7 +1295,9 @@ 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) @@ -1711,7 +1709,9 @@ 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 ] @@ -1823,6 +1823,7 @@ def tensorflow_to_numpy( return np.asarray(tensorflow.convert_to_tensor(x)) +@tensorflow_handle_array_like_without_promotion def tensorflow_to_scalar(x: Union[tensorflow.Tensor, tensorflow.Variable], /): ret = tensorflow_to_numpy(x).item() if x.dtype == tensorflow.bfloat16: @@ -1830,9 +1831,8 @@ def tensorflow_to_scalar(x: Union[tensorflow.Tensor, tensorflow.Variable], /): return ret -@tensorflow_handle_array_like_without_promotion -def tensorflow_to_scalar_bknd(x: Union[tensorflow.Tensor, tf.Tensor], /): - return tensorflow_to_scalar(x) +def tensorflow_to_scalar_bknd_(self: tensorflow.Tensor): + return tensorflow_to_scalar(self) def tensorflow_is_complex_dtype_bknd( @@ -1901,11 +1901,9 @@ 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 @@ -2027,7 +2025,7 @@ def tensorflow_prod( def tensorflow__numel_bknd(shape): shape = tuple(shape) - return tensorflow_to_scalar_bknd(tensorflow_prod(shape)) if shape != () else 1 + return tensorflow_to_scalar_bknd_(tensorflow_prod(shape)) if shape != () else 1 def tensorflow_check_one_way_broadcastable(x1, x2): @@ -2139,7 +2137,9 @@ 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) @@ -2299,11 +2299,9 @@ 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]) @@ -2552,21 +2550,17 @@ 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 diff --git a/ivy/compiler/_cache/Translated_Outputs/tensorflow_add_output/run_0/tensorflow_add.py b/ivy/compiler/_cache/Translated_Outputs/tensorflow_add_output/run_0/tensorflow_add.py index 9439d9a570191..3e5f36e70fa92 100644 --- a/ivy/compiler/_cache/Translated_Outputs/tensorflow_add_output/run_0/tensorflow_add.py +++ b/ivy/compiler/_cache/Translated_Outputs/tensorflow_add_output/run_0/tensorflow_add.py @@ -1,7 +1,7 @@ import tensorflow -from typing import Optional from typing import Union +from typing import Optional from .tensorflow__helpers import tensorflow_asarray from .tensorflow__helpers import tensorflow_default_dtype_bknd @@ -23,7 +23,9 @@ 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) diff --git a/ivy/compiler/_cache/Translated_Outputs/tensorflow_all_output/run_0/tensorflow_NestedSequence_bknd.py b/ivy/compiler/_cache/Translated_Outputs/tensorflow_all_output/run_0/tensorflow_NestedSequence_bknd.py index ac8335fe1e56c..9f87b4ae29eff 100644 --- a/ivy/compiler/_cache/Translated_Outputs/tensorflow_all_output/run_0/tensorflow_NestedSequence_bknd.py +++ b/ivy/compiler/_cache/Translated_Outputs/tensorflow_all_output/run_0/tensorflow_NestedSequence_bknd.py @@ -1,5 +1,5 @@ -from typing import TypeVar from typing import Protocol +from typing import TypeVar _T_co = TypeVar("_T_co", covariant=True) diff --git a/ivy/compiler/_cache/Translated_Outputs/tensorflow_all_output/run_0/tensorflow__helpers.py b/ivy/compiler/_cache/Translated_Outputs/tensorflow_all_output/run_0/tensorflow__helpers.py index 0380bbe57701b..6136707cf74ef 100644 --- a/ivy/compiler/_cache/Translated_Outputs/tensorflow_all_output/run_0/tensorflow__helpers.py +++ b/ivy/compiler/_cache/Translated_Outputs/tensorflow_all_output/run_0/tensorflow__helpers.py @@ -334,7 +334,9 @@ 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 ) @@ -767,21 +769,17 @@ 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 @@ -1193,27 +1191,21 @@ 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 = [ @@ -1638,7 +1630,9 @@ 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) @@ -2050,7 +2044,9 @@ 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 ] @@ -2162,6 +2158,7 @@ def tensorflow_to_numpy( return np.asarray(tensorflow.convert_to_tensor(x)) +@tensorflow_handle_array_like_without_promotion def tensorflow_to_scalar(x: Union[tensorflow.Tensor, tensorflow.Variable], /): ret = tensorflow_to_numpy(x).item() if x.dtype == tensorflow.bfloat16: @@ -2169,9 +2166,8 @@ def tensorflow_to_scalar(x: Union[tensorflow.Tensor, tensorflow.Variable], /): return ret -@tensorflow_handle_array_like_without_promotion -def tensorflow_to_scalar_bknd(x: Union[tensorflow.Tensor, tf.Tensor], /): - return tensorflow_to_scalar(x) +def tensorflow_to_scalar_bknd_(self: tensorflow.Tensor): + return tensorflow_to_scalar(self) def tensorflow_default_uint_dtype_bknd( @@ -2198,11 +2194,9 @@ 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 @@ -2298,7 +2292,7 @@ def tensorflow_prod( def tensorflow__numel_bknd(shape): shape = tuple(shape) - return tensorflow_to_scalar_bknd(tensorflow_prod(shape)) if shape != () else 1 + return tensorflow_to_scalar_bknd_(tensorflow_prod(shape)) if shape != () else 1 def tensorflow_check_one_way_broadcastable(x1, x2): @@ -2410,7 +2404,9 @@ 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) @@ -2570,11 +2566,9 @@ 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]) diff --git a/ivy/compiler/_cache/Translated_Outputs/tensorflow_all_output/run_0/tensorflow_all.py b/ivy/compiler/_cache/Translated_Outputs/tensorflow_all_output/run_0/tensorflow_all.py index afcd2b52d09b1..d1b70765780c3 100644 --- a/ivy/compiler/_cache/Translated_Outputs/tensorflow_all_output/run_0/tensorflow_all.py +++ b/ivy/compiler/_cache/Translated_Outputs/tensorflow_all_output/run_0/tensorflow_all.py @@ -1,8 +1,8 @@ import tensorflow -from typing import Sequence -from typing import Union from typing import Optional +from typing import Union +from typing import Sequence from .tensorflow__helpers import tensorflow_handle_array_like_without_promotion diff --git a/ivy/compiler/_cache/Translated_Outputs/tensorflow_arange_output/run_0/tensorflow__helpers.py b/ivy/compiler/_cache/Translated_Outputs/tensorflow_arange_output/run_0/tensorflow__helpers.py index 0380bbe57701b..6136707cf74ef 100644 --- a/ivy/compiler/_cache/Translated_Outputs/tensorflow_arange_output/run_0/tensorflow__helpers.py +++ b/ivy/compiler/_cache/Translated_Outputs/tensorflow_arange_output/run_0/tensorflow__helpers.py @@ -334,7 +334,9 @@ 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 ) @@ -767,21 +769,17 @@ 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 @@ -1193,27 +1191,21 @@ 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 = [ @@ -1638,7 +1630,9 @@ 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) @@ -2050,7 +2044,9 @@ 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 ] @@ -2162,6 +2158,7 @@ def tensorflow_to_numpy( return np.asarray(tensorflow.convert_to_tensor(x)) +@tensorflow_handle_array_like_without_promotion def tensorflow_to_scalar(x: Union[tensorflow.Tensor, tensorflow.Variable], /): ret = tensorflow_to_numpy(x).item() if x.dtype == tensorflow.bfloat16: @@ -2169,9 +2166,8 @@ def tensorflow_to_scalar(x: Union[tensorflow.Tensor, tensorflow.Variable], /): return ret -@tensorflow_handle_array_like_without_promotion -def tensorflow_to_scalar_bknd(x: Union[tensorflow.Tensor, tf.Tensor], /): - return tensorflow_to_scalar(x) +def tensorflow_to_scalar_bknd_(self: tensorflow.Tensor): + return tensorflow_to_scalar(self) def tensorflow_default_uint_dtype_bknd( @@ -2198,11 +2194,9 @@ 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 @@ -2298,7 +2292,7 @@ def tensorflow_prod( def tensorflow__numel_bknd(shape): shape = tuple(shape) - return tensorflow_to_scalar_bknd(tensorflow_prod(shape)) if shape != () else 1 + return tensorflow_to_scalar_bknd_(tensorflow_prod(shape)) if shape != () else 1 def tensorflow_check_one_way_broadcastable(x1, x2): @@ -2410,7 +2404,9 @@ 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) @@ -2570,11 +2566,9 @@ 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]) diff --git a/ivy/compiler/_cache/Translated_Outputs/tensorflow_as_native_dtype_output/run_0/tensorflow_NestedSequence_bknd.py b/ivy/compiler/_cache/Translated_Outputs/tensorflow_as_native_dtype_output/run_0/tensorflow_NestedSequence_bknd.py index 9f87b4ae29eff..ac8335fe1e56c 100644 --- a/ivy/compiler/_cache/Translated_Outputs/tensorflow_as_native_dtype_output/run_0/tensorflow_NestedSequence_bknd.py +++ b/ivy/compiler/_cache/Translated_Outputs/tensorflow_as_native_dtype_output/run_0/tensorflow_NestedSequence_bknd.py @@ -1,5 +1,5 @@ -from typing import Protocol from typing import TypeVar +from typing import Protocol _T_co = TypeVar("_T_co", covariant=True) diff --git a/ivy/compiler/_cache/Translated_Outputs/tensorflow_as_native_dtype_output/run_0/tensorflow__helpers.py b/ivy/compiler/_cache/Translated_Outputs/tensorflow_as_native_dtype_output/run_0/tensorflow__helpers.py index 65e3ac208b952..e6d7290d7ddcf 100644 --- a/ivy/compiler/_cache/Translated_Outputs/tensorflow_as_native_dtype_output/run_0/tensorflow__helpers.py +++ b/ivy/compiler/_cache/Translated_Outputs/tensorflow_as_native_dtype_output/run_0/tensorflow__helpers.py @@ -310,7 +310,9 @@ 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 ) @@ -912,27 +914,21 @@ 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 = [ @@ -1357,7 +1353,9 @@ 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) @@ -1769,7 +1767,9 @@ 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 ] @@ -1881,6 +1881,7 @@ def tensorflow_to_numpy( return np.asarray(tensorflow.convert_to_tensor(x)) +@tensorflow_handle_array_like_without_promotion def tensorflow_to_scalar(x: Union[tensorflow.Tensor, tensorflow.Variable], /): ret = tensorflow_to_numpy(x).item() if x.dtype == tensorflow.bfloat16: @@ -1888,9 +1889,8 @@ def tensorflow_to_scalar(x: Union[tensorflow.Tensor, tensorflow.Variable], /): return ret -@tensorflow_handle_array_like_without_promotion -def tensorflow_to_scalar_bknd(x: Union[tensorflow.Tensor, tf.Tensor], /): - return tensorflow_to_scalar(x) +def tensorflow_to_scalar_bknd_(self: tensorflow.Tensor): + return tensorflow_to_scalar(self) def tensorflow_default_uint_dtype_bknd( @@ -1917,11 +1917,9 @@ 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 @@ -2017,7 +2015,7 @@ def tensorflow_prod( def tensorflow__numel_bknd(shape): shape = tuple(shape) - return tensorflow_to_scalar_bknd(tensorflow_prod(shape)) if shape != () else 1 + return tensorflow_to_scalar_bknd_(tensorflow_prod(shape)) if shape != () else 1 def tensorflow_check_one_way_broadcastable(x1, x2): @@ -2129,7 +2127,9 @@ 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) @@ -2289,11 +2289,9 @@ 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]) @@ -2619,21 +2617,17 @@ 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 diff --git a/ivy/compiler/_cache/Translated_Outputs/tensorflow_asarray_output/run_0/tensorflow__helpers.py b/ivy/compiler/_cache/Translated_Outputs/tensorflow_asarray_output/run_0/tensorflow__helpers.py index 0380bbe57701b..6136707cf74ef 100644 --- a/ivy/compiler/_cache/Translated_Outputs/tensorflow_asarray_output/run_0/tensorflow__helpers.py +++ b/ivy/compiler/_cache/Translated_Outputs/tensorflow_asarray_output/run_0/tensorflow__helpers.py @@ -334,7 +334,9 @@ 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 ) @@ -767,21 +769,17 @@ 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 @@ -1193,27 +1191,21 @@ 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 = [ @@ -1638,7 +1630,9 @@ 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) @@ -2050,7 +2044,9 @@ 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 ] @@ -2162,6 +2158,7 @@ def tensorflow_to_numpy( return np.asarray(tensorflow.convert_to_tensor(x)) +@tensorflow_handle_array_like_without_promotion def tensorflow_to_scalar(x: Union[tensorflow.Tensor, tensorflow.Variable], /): ret = tensorflow_to_numpy(x).item() if x.dtype == tensorflow.bfloat16: @@ -2169,9 +2166,8 @@ def tensorflow_to_scalar(x: Union[tensorflow.Tensor, tensorflow.Variable], /): return ret -@tensorflow_handle_array_like_without_promotion -def tensorflow_to_scalar_bknd(x: Union[tensorflow.Tensor, tf.Tensor], /): - return tensorflow_to_scalar(x) +def tensorflow_to_scalar_bknd_(self: tensorflow.Tensor): + return tensorflow_to_scalar(self) def tensorflow_default_uint_dtype_bknd( @@ -2198,11 +2194,9 @@ 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 @@ -2298,7 +2292,7 @@ def tensorflow_prod( def tensorflow__numel_bknd(shape): shape = tuple(shape) - return tensorflow_to_scalar_bknd(tensorflow_prod(shape)) if shape != () else 1 + return tensorflow_to_scalar_bknd_(tensorflow_prod(shape)) if shape != () else 1 def tensorflow_check_one_way_broadcastable(x1, x2): @@ -2410,7 +2404,9 @@ 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) @@ -2570,11 +2566,9 @@ 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]) diff --git a/ivy/compiler/_cache/Translated_Outputs/tensorflow_asarray_output/run_0/tensorflow_asarray.py b/ivy/compiler/_cache/Translated_Outputs/tensorflow_asarray_output/run_0/tensorflow_asarray.py index a4bda6c529d4f..8eb5eb62f943b 100644 --- a/ivy/compiler/_cache/Translated_Outputs/tensorflow_asarray_output/run_0/tensorflow_asarray.py +++ b/ivy/compiler/_cache/Translated_Outputs/tensorflow_asarray_output/run_0/tensorflow_asarray.py @@ -1,8 +1,8 @@ import tensorflow import numpy as np -from typing import Optional from typing import Union +from typing import Optional from typing import TypeVar from .tensorflow_NestedSequence_bknd import tensorflow_NestedSequence_bknd diff --git a/ivy/compiler/_cache/Translated_Outputs/tensorflow_batch_norm_output/run_0/tensorflow_NestedSequence_bknd.py b/ivy/compiler/_cache/Translated_Outputs/tensorflow_batch_norm_output/run_0/tensorflow_NestedSequence_bknd.py index ac8335fe1e56c..9f87b4ae29eff 100644 --- a/ivy/compiler/_cache/Translated_Outputs/tensorflow_batch_norm_output/run_0/tensorflow_NestedSequence_bknd.py +++ b/ivy/compiler/_cache/Translated_Outputs/tensorflow_batch_norm_output/run_0/tensorflow_NestedSequence_bknd.py @@ -1,5 +1,5 @@ -from typing import TypeVar from typing import Protocol +from typing import TypeVar _T_co = TypeVar("_T_co", covariant=True) diff --git a/ivy/compiler/_cache/Translated_Outputs/tensorflow_batch_norm_output/run_0/tensorflow__helpers.py b/ivy/compiler/_cache/Translated_Outputs/tensorflow_batch_norm_output/run_0/tensorflow__helpers.py index 0380bbe57701b..6136707cf74ef 100644 --- a/ivy/compiler/_cache/Translated_Outputs/tensorflow_batch_norm_output/run_0/tensorflow__helpers.py +++ b/ivy/compiler/_cache/Translated_Outputs/tensorflow_batch_norm_output/run_0/tensorflow__helpers.py @@ -334,7 +334,9 @@ 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 ) @@ -767,21 +769,17 @@ 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 @@ -1193,27 +1191,21 @@ 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 = [ @@ -1638,7 +1630,9 @@ 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) @@ -2050,7 +2044,9 @@ 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 ] @@ -2162,6 +2158,7 @@ def tensorflow_to_numpy( return np.asarray(tensorflow.convert_to_tensor(x)) +@tensorflow_handle_array_like_without_promotion def tensorflow_to_scalar(x: Union[tensorflow.Tensor, tensorflow.Variable], /): ret = tensorflow_to_numpy(x).item() if x.dtype == tensorflow.bfloat16: @@ -2169,9 +2166,8 @@ def tensorflow_to_scalar(x: Union[tensorflow.Tensor, tensorflow.Variable], /): return ret -@tensorflow_handle_array_like_without_promotion -def tensorflow_to_scalar_bknd(x: Union[tensorflow.Tensor, tf.Tensor], /): - return tensorflow_to_scalar(x) +def tensorflow_to_scalar_bknd_(self: tensorflow.Tensor): + return tensorflow_to_scalar(self) def tensorflow_default_uint_dtype_bknd( @@ -2198,11 +2194,9 @@ 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 @@ -2298,7 +2292,7 @@ def tensorflow_prod( def tensorflow__numel_bknd(shape): shape = tuple(shape) - return tensorflow_to_scalar_bknd(tensorflow_prod(shape)) if shape != () else 1 + return tensorflow_to_scalar_bknd_(tensorflow_prod(shape)) if shape != () else 1 def tensorflow_check_one_way_broadcastable(x1, x2): @@ -2410,7 +2404,9 @@ 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) @@ -2570,11 +2566,9 @@ 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]) diff --git a/ivy/compiler/_cache/Translated_Outputs/tensorflow_batch_norm_output/run_0/tensorflow_batch_norm.py b/ivy/compiler/_cache/Translated_Outputs/tensorflow_batch_norm_output/run_0/tensorflow_batch_norm.py index 6bad1a0d5c0c1..9294c576eaa1f 100644 --- a/ivy/compiler/_cache/Translated_Outputs/tensorflow_batch_norm_output/run_0/tensorflow_batch_norm.py +++ b/ivy/compiler/_cache/Translated_Outputs/tensorflow_batch_norm_output/run_0/tensorflow_batch_norm.py @@ -1,8 +1,8 @@ import tensorflow from typing import Tuple -from typing import Union from typing import Optional +from typing import Union from .tensorflow__helpers import tensorflow_handle_array_like_without_promotion diff --git a/ivy/compiler/_cache/Translated_Outputs/tensorflow_bernoulli_output/run_0/tensorflow_NestedSequence_bknd.py b/ivy/compiler/_cache/Translated_Outputs/tensorflow_bernoulli_output/run_0/tensorflow_NestedSequence_bknd.py index 9f87b4ae29eff..ac8335fe1e56c 100644 --- a/ivy/compiler/_cache/Translated_Outputs/tensorflow_bernoulli_output/run_0/tensorflow_NestedSequence_bknd.py +++ b/ivy/compiler/_cache/Translated_Outputs/tensorflow_bernoulli_output/run_0/tensorflow_NestedSequence_bknd.py @@ -1,5 +1,5 @@ -from typing import Protocol from typing import TypeVar +from typing import Protocol _T_co = TypeVar("_T_co", covariant=True) diff --git a/ivy/compiler/_cache/Translated_Outputs/tensorflow_bernoulli_output/run_0/tensorflow__helpers.py b/ivy/compiler/_cache/Translated_Outputs/tensorflow_bernoulli_output/run_0/tensorflow__helpers.py index 90d006a3be806..f83ab0fa379a2 100644 --- a/ivy/compiler/_cache/Translated_Outputs/tensorflow_bernoulli_output/run_0/tensorflow__helpers.py +++ b/ivy/compiler/_cache/Translated_Outputs/tensorflow_bernoulli_output/run_0/tensorflow__helpers.py @@ -349,7 +349,9 @@ 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 ) @@ -714,27 +716,21 @@ 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 = [ @@ -1159,7 +1155,9 @@ 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) @@ -1556,7 +1554,9 @@ 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 ] @@ -1668,6 +1668,7 @@ def tensorflow_to_numpy( return np.asarray(tensorflow.convert_to_tensor(x)) +@tensorflow_handle_array_like_without_promotion def tensorflow_to_scalar(x: Union[tensorflow.Tensor, tensorflow.Variable], /): ret = tensorflow_to_numpy(x).item() if x.dtype == tensorflow.bfloat16: @@ -1675,9 +1676,8 @@ def tensorflow_to_scalar(x: Union[tensorflow.Tensor, tensorflow.Variable], /): return ret -@tensorflow_handle_array_like_without_promotion -def tensorflow_to_scalar_bknd(x: Union[tensorflow.Tensor, tf.Tensor], /): - return tensorflow_to_scalar(x) +def tensorflow_to_scalar_bknd_(self: tensorflow.Tensor): + return tensorflow_to_scalar(self) def tensorflow_is_float_dtype_bknd( @@ -1748,11 +1748,9 @@ 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 @@ -1874,7 +1872,7 @@ def tensorflow_prod( def tensorflow__numel_bknd(shape): shape = tuple(shape) - return tensorflow_to_scalar_bknd(tensorflow_prod(shape)) if shape != () else 1 + return tensorflow_to_scalar_bknd_(tensorflow_prod(shape)) if shape != () else 1 def tensorflow_check_one_way_broadcastable(x1, x2): @@ -1986,7 +1984,9 @@ 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) @@ -2146,11 +2146,9 @@ 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]) @@ -2497,21 +2495,17 @@ 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 diff --git a/ivy/compiler/_cache/Translated_Outputs/tensorflow_bernoulli_output/run_0/tensorflow_bernoulli.py b/ivy/compiler/_cache/Translated_Outputs/tensorflow_bernoulli_output/run_0/tensorflow_bernoulli.py index 0309f8bc5c995..96b883d0040a4 100644 --- a/ivy/compiler/_cache/Translated_Outputs/tensorflow_bernoulli_output/run_0/tensorflow_bernoulli.py +++ b/ivy/compiler/_cache/Translated_Outputs/tensorflow_bernoulli_output/run_0/tensorflow_bernoulli.py @@ -2,8 +2,8 @@ import tensorflow as tf from typing import Optional -from typing import Union from typing import Sequence +from typing import Union from .tensorflow__helpers import tensorflow__check_shapes_broadcastable_bknd from .tensorflow__helpers import tensorflow_infer_dtype diff --git a/ivy/compiler/_cache/Translated_Outputs/tensorflow_check_any_output/run_0/tensorflow__helpers.py b/ivy/compiler/_cache/Translated_Outputs/tensorflow_check_any_output/run_0/tensorflow__helpers.py index 49b57b9b86ce1..c118b0fd5fe58 100644 --- a/ivy/compiler/_cache/Translated_Outputs/tensorflow_check_any_output/run_0/tensorflow__helpers.py +++ b/ivy/compiler/_cache/Translated_Outputs/tensorflow_check_any_output/run_0/tensorflow__helpers.py @@ -334,7 +334,9 @@ 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 ) @@ -767,21 +769,17 @@ 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 @@ -1193,27 +1191,21 @@ 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 = [ @@ -1638,7 +1630,9 @@ 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) @@ -2050,7 +2044,9 @@ 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 ] @@ -2162,6 +2158,7 @@ def tensorflow_to_numpy( return np.asarray(tensorflow.convert_to_tensor(x)) +@tensorflow_handle_array_like_without_promotion def tensorflow_to_scalar(x: Union[tensorflow.Tensor, tensorflow.Variable], /): ret = tensorflow_to_numpy(x).item() if x.dtype == tensorflow.bfloat16: @@ -2169,9 +2166,8 @@ def tensorflow_to_scalar(x: Union[tensorflow.Tensor, tensorflow.Variable], /): return ret -@tensorflow_handle_array_like_without_promotion -def tensorflow_to_scalar_bknd(x: Union[tensorflow.Tensor, tf.Tensor], /): - return tensorflow_to_scalar(x) +def tensorflow_to_scalar_bknd_(self: tensorflow.Tensor): + return tensorflow_to_scalar(self) def tensorflow_default_uint_dtype_bknd( @@ -2198,11 +2194,9 @@ 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 @@ -2298,7 +2292,7 @@ def tensorflow_prod( def tensorflow__numel_bknd(shape): shape = tuple(shape) - return tensorflow_to_scalar_bknd(tensorflow_prod(shape)) if shape != () else 1 + return tensorflow_to_scalar_bknd_(tensorflow_prod(shape)) if shape != () else 1 def tensorflow_check_one_way_broadcastable(x1, x2): @@ -2388,7 +2382,9 @@ 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) @@ -2548,11 +2544,9 @@ 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]) diff --git a/ivy/compiler/_cache/Translated_Outputs/tensorflow_check_equal_output/run_0/tensorflow__helpers.py b/ivy/compiler/_cache/Translated_Outputs/tensorflow_check_equal_output/run_0/tensorflow__helpers.py index 49b57b9b86ce1..c118b0fd5fe58 100644 --- a/ivy/compiler/_cache/Translated_Outputs/tensorflow_check_equal_output/run_0/tensorflow__helpers.py +++ b/ivy/compiler/_cache/Translated_Outputs/tensorflow_check_equal_output/run_0/tensorflow__helpers.py @@ -334,7 +334,9 @@ 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 ) @@ -767,21 +769,17 @@ 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 @@ -1193,27 +1191,21 @@ 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 = [ @@ -1638,7 +1630,9 @@ 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) @@ -2050,7 +2044,9 @@ 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 ] @@ -2162,6 +2158,7 @@ def tensorflow_to_numpy( return np.asarray(tensorflow.convert_to_tensor(x)) +@tensorflow_handle_array_like_without_promotion def tensorflow_to_scalar(x: Union[tensorflow.Tensor, tensorflow.Variable], /): ret = tensorflow_to_numpy(x).item() if x.dtype == tensorflow.bfloat16: @@ -2169,9 +2166,8 @@ def tensorflow_to_scalar(x: Union[tensorflow.Tensor, tensorflow.Variable], /): return ret -@tensorflow_handle_array_like_without_promotion -def tensorflow_to_scalar_bknd(x: Union[tensorflow.Tensor, tf.Tensor], /): - return tensorflow_to_scalar(x) +def tensorflow_to_scalar_bknd_(self: tensorflow.Tensor): + return tensorflow_to_scalar(self) def tensorflow_default_uint_dtype_bknd( @@ -2198,11 +2194,9 @@ 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 @@ -2298,7 +2292,7 @@ def tensorflow_prod( def tensorflow__numel_bknd(shape): shape = tuple(shape) - return tensorflow_to_scalar_bknd(tensorflow_prod(shape)) if shape != () else 1 + return tensorflow_to_scalar_bknd_(tensorflow_prod(shape)) if shape != () else 1 def tensorflow_check_one_way_broadcastable(x1, x2): @@ -2388,7 +2382,9 @@ 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) @@ -2548,11 +2544,9 @@ 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]) diff --git a/ivy/compiler/_cache/Translated_Outputs/tensorflow_clip_output/run_0/tensorflow__helpers.py b/ivy/compiler/_cache/Translated_Outputs/tensorflow_clip_output/run_0/tensorflow__helpers.py index db59b549a2625..c6ecc3bd56fb2 100644 --- a/ivy/compiler/_cache/Translated_Outputs/tensorflow_clip_output/run_0/tensorflow__helpers.py +++ b/ivy/compiler/_cache/Translated_Outputs/tensorflow_clip_output/run_0/tensorflow__helpers.py @@ -335,7 +335,9 @@ 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 ) @@ -768,21 +770,17 @@ 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 @@ -1231,27 +1229,21 @@ 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 = [ @@ -1522,7 +1514,9 @@ 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) @@ -1934,7 +1928,9 @@ 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 ] @@ -2068,6 +2064,7 @@ def tensorflow_to_numpy( return np.asarray(tensorflow.convert_to_tensor(x)) +@tensorflow_handle_array_like_without_promotion def tensorflow_to_scalar(x: Union[tensorflow.Tensor, tensorflow.Variable], /): ret = tensorflow_to_numpy(x).item() if x.dtype == tensorflow.bfloat16: @@ -2075,9 +2072,8 @@ def tensorflow_to_scalar(x: Union[tensorflow.Tensor, tensorflow.Variable], /): return ret -@tensorflow_handle_array_like_without_promotion -def tensorflow_to_scalar_bknd(x: Union[tensorflow.Tensor, tf.Tensor], /): - return tensorflow_to_scalar(x) +def tensorflow_to_scalar_bknd_(self: tensorflow.Tensor): + return tensorflow_to_scalar(self) def tensorflow_default_uint_dtype_bknd( @@ -2104,11 +2100,9 @@ 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 @@ -2204,7 +2198,7 @@ def tensorflow_prod( def tensorflow__numel_bknd(shape): shape = tuple(shape) - return tensorflow_to_scalar_bknd(tensorflow_prod(shape)) if shape != () else 1 + return tensorflow_to_scalar_bknd_(tensorflow_prod(shape)) if shape != () else 1 def tensorflow_check_one_way_broadcastable(x1, x2): @@ -2316,7 +2310,9 @@ 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) @@ -2476,11 +2472,9 @@ 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]) diff --git a/ivy/compiler/_cache/Translated_Outputs/tensorflow_clip_output/run_0/tensorflow_clip.py b/ivy/compiler/_cache/Translated_Outputs/tensorflow_clip_output/run_0/tensorflow_clip.py index 011ecfbe0b043..814d9d2fc9da0 100644 --- a/ivy/compiler/_cache/Translated_Outputs/tensorflow_clip_output/run_0/tensorflow_clip.py +++ b/ivy/compiler/_cache/Translated_Outputs/tensorflow_clip_output/run_0/tensorflow_clip.py @@ -1,8 +1,8 @@ import tensorflow -from typing import Union -from numbers import Number from typing import Optional +from numbers import Number +from typing import Union from .tensorflow__helpers import tensorflow_as_native_dtype from .tensorflow__helpers import tensorflow_asarray diff --git a/ivy/compiler/_cache/Translated_Outputs/tensorflow_concat_output/run_0/tensorflow__helpers.py b/ivy/compiler/_cache/Translated_Outputs/tensorflow_concat_output/run_0/tensorflow__helpers.py index 0a830c0a3fe56..38d882c45e3e4 100644 --- a/ivy/compiler/_cache/Translated_Outputs/tensorflow_concat_output/run_0/tensorflow__helpers.py +++ b/ivy/compiler/_cache/Translated_Outputs/tensorflow_concat_output/run_0/tensorflow__helpers.py @@ -1,9 +1,9 @@ import tensorflow +from typing import Union +from typing import Tuple from typing import List from typing import Optional -from typing import Tuple -from typing import Union def tensorflow_concat( diff --git a/ivy/compiler/_cache/Translated_Outputs/tensorflow_concat_output/run_0/tensorflow_concat.py b/ivy/compiler/_cache/Translated_Outputs/tensorflow_concat_output/run_0/tensorflow_concat.py index 2ebcd0cb1e1fb..6eab5cf41622d 100644 --- a/ivy/compiler/_cache/Translated_Outputs/tensorflow_concat_output/run_0/tensorflow_concat.py +++ b/ivy/compiler/_cache/Translated_Outputs/tensorflow_concat_output/run_0/tensorflow_concat.py @@ -1,9 +1,9 @@ import tensorflow +from typing import Union +from typing import Tuple from typing import List from typing import Optional -from typing import Tuple -from typing import Union from .tensorflow__helpers import tensorflow_concat diff --git a/ivy/compiler/_cache/Translated_Outputs/tensorflow_conv_general_dilated_output/run_0/tensorflow_NestedSequence_bknd.py b/ivy/compiler/_cache/Translated_Outputs/tensorflow_conv_general_dilated_output/run_0/tensorflow_NestedSequence_bknd.py index 9f87b4ae29eff..ac8335fe1e56c 100644 --- a/ivy/compiler/_cache/Translated_Outputs/tensorflow_conv_general_dilated_output/run_0/tensorflow_NestedSequence_bknd.py +++ b/ivy/compiler/_cache/Translated_Outputs/tensorflow_conv_general_dilated_output/run_0/tensorflow_NestedSequence_bknd.py @@ -1,5 +1,5 @@ -from typing import Protocol from typing import TypeVar +from typing import Protocol _T_co = TypeVar("_T_co", covariant=True) diff --git a/ivy/compiler/_cache/Translated_Outputs/tensorflow_conv_general_dilated_output/run_0/tensorflow__helpers.py b/ivy/compiler/_cache/Translated_Outputs/tensorflow_conv_general_dilated_output/run_0/tensorflow__helpers.py index 6132fa884d602..a0cea491edef8 100644 --- a/ivy/compiler/_cache/Translated_Outputs/tensorflow_conv_general_dilated_output/run_0/tensorflow__helpers.py +++ b/ivy/compiler/_cache/Translated_Outputs/tensorflow_conv_general_dilated_output/run_0/tensorflow__helpers.py @@ -334,7 +334,9 @@ 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 ) @@ -767,21 +769,17 @@ 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 @@ -1193,27 +1191,21 @@ 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 = [ @@ -1638,7 +1630,9 @@ 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) @@ -2050,7 +2044,9 @@ 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 ] @@ -2162,6 +2158,7 @@ def tensorflow_to_numpy( return np.asarray(tensorflow.convert_to_tensor(x)) +@tensorflow_handle_array_like_without_promotion def tensorflow_to_scalar(x: Union[tensorflow.Tensor, tensorflow.Variable], /): ret = tensorflow_to_numpy(x).item() if x.dtype == tensorflow.bfloat16: @@ -2169,9 +2166,8 @@ def tensorflow_to_scalar(x: Union[tensorflow.Tensor, tensorflow.Variable], /): return ret -@tensorflow_handle_array_like_without_promotion -def tensorflow_to_scalar_bknd(x: Union[tensorflow.Tensor, tf.Tensor], /): - return tensorflow_to_scalar(x) +def tensorflow_to_scalar_bknd_(self: tensorflow.Tensor): + return tensorflow_to_scalar(self) def tensorflow_default_uint_dtype_bknd( @@ -2198,11 +2194,9 @@ 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 @@ -2298,7 +2292,7 @@ def tensorflow_prod( def tensorflow__numel_bknd(shape): shape = tuple(shape) - return tensorflow_to_scalar_bknd(tensorflow_prod(shape)) if shape != () else 1 + return tensorflow_to_scalar_bknd_(tensorflow_prod(shape)) if shape != () else 1 def tensorflow_check_one_way_broadcastable(x1, x2): @@ -2410,7 +2404,9 @@ 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) @@ -2570,11 +2566,9 @@ 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]) diff --git a/ivy/compiler/_cache/Translated_Outputs/tensorflow_conv_general_dilated_output/run_0/tensorflow_conv_general_dilated.py b/ivy/compiler/_cache/Translated_Outputs/tensorflow_conv_general_dilated_output/run_0/tensorflow_conv_general_dilated.py index 6a2b144a3bece..8308fb22d70ea 100644 --- a/ivy/compiler/_cache/Translated_Outputs/tensorflow_conv_general_dilated_output/run_0/tensorflow_conv_general_dilated.py +++ b/ivy/compiler/_cache/Translated_Outputs/tensorflow_conv_general_dilated_output/run_0/tensorflow_conv_general_dilated.py @@ -1,8 +1,8 @@ import tensorflow -from typing import Sequence from typing import Union from typing import Tuple +from typing import Sequence from typing import Optional from .tensorflow__helpers import tensorflow__extend_2d_padding diff --git a/ivy/compiler/_cache/Translated_Outputs/tensorflow_default_device_bknd_output/run_0/tensorflow__helpers.py b/ivy/compiler/_cache/Translated_Outputs/tensorflow_default_device_bknd_output/run_0/tensorflow__helpers.py index 9f4a118502626..e9d5c08e30b6c 100644 --- a/ivy/compiler/_cache/Translated_Outputs/tensorflow_default_device_bknd_output/run_0/tensorflow__helpers.py +++ b/ivy/compiler/_cache/Translated_Outputs/tensorflow_default_device_bknd_output/run_0/tensorflow__helpers.py @@ -343,7 +343,9 @@ 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 ) @@ -776,21 +778,17 @@ 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 @@ -1106,27 +1104,21 @@ 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 = [ @@ -1551,7 +1543,9 @@ 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) @@ -1963,7 +1957,9 @@ 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 ] @@ -2075,6 +2071,7 @@ def tensorflow_to_numpy( return np.asarray(tensorflow.convert_to_tensor(x)) +@tensorflow_handle_array_like_without_promotion def tensorflow_to_scalar(x: Union[tensorflow.Tensor, tensorflow.Variable], /): ret = tensorflow_to_numpy(x).item() if x.dtype == tensorflow.bfloat16: @@ -2082,9 +2079,8 @@ def tensorflow_to_scalar(x: Union[tensorflow.Tensor, tensorflow.Variable], /): return ret -@tensorflow_handle_array_like_without_promotion -def tensorflow_to_scalar_bknd(x: Union[tensorflow.Tensor, tf.Tensor], /): - return tensorflow_to_scalar(x) +def tensorflow_to_scalar_bknd_(self: tensorflow.Tensor): + return tensorflow_to_scalar(self) def tensorflow_default_uint_dtype_bknd( @@ -2111,11 +2107,9 @@ 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 @@ -2211,7 +2205,7 @@ def tensorflow_prod( def tensorflow__numel_bknd(shape): shape = tuple(shape) - return tensorflow_to_scalar_bknd(tensorflow_prod(shape)) if shape != () else 1 + return tensorflow_to_scalar_bknd_(tensorflow_prod(shape)) if shape != () else 1 def tensorflow_check_one_way_broadcastable(x1, x2): @@ -2323,7 +2317,9 @@ 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) @@ -2483,11 +2479,9 @@ 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]) diff --git a/ivy/compiler/_cache/Translated_Outputs/tensorflow_default_device_bknd_output/run_0/tensorflow_default_device_bknd.py b/ivy/compiler/_cache/Translated_Outputs/tensorflow_default_device_bknd_output/run_0/tensorflow_default_device_bknd.py index b8aa4cf378971..3eac8e949361d 100644 --- a/ivy/compiler/_cache/Translated_Outputs/tensorflow_default_device_bknd_output/run_0/tensorflow_default_device_bknd.py +++ b/ivy/compiler/_cache/Translated_Outputs/tensorflow_default_device_bknd_output/run_0/tensorflow_default_device_bknd.py @@ -1,8 +1,8 @@ import tensorflow import tensorflow as tf -from typing import Union from typing import Optional +from typing import Union from .tensorflow__helpers import tensorflow_as_ivy_dev from .tensorflow__helpers import tensorflow_as_native_dev diff --git a/ivy/compiler/_cache/Translated_Outputs/tensorflow_default_dtype_bknd_output/run_0/tensorflow_NestedSequence_bknd.py b/ivy/compiler/_cache/Translated_Outputs/tensorflow_default_dtype_bknd_output/run_0/tensorflow_NestedSequence_bknd.py index ac8335fe1e56c..9f87b4ae29eff 100644 --- a/ivy/compiler/_cache/Translated_Outputs/tensorflow_default_dtype_bknd_output/run_0/tensorflow_NestedSequence_bknd.py +++ b/ivy/compiler/_cache/Translated_Outputs/tensorflow_default_dtype_bknd_output/run_0/tensorflow_NestedSequence_bknd.py @@ -1,5 +1,5 @@ -from typing import TypeVar from typing import Protocol +from typing import TypeVar _T_co = TypeVar("_T_co", covariant=True) diff --git a/ivy/compiler/_cache/Translated_Outputs/tensorflow_default_dtype_bknd_output/run_0/tensorflow__helpers.py b/ivy/compiler/_cache/Translated_Outputs/tensorflow_default_dtype_bknd_output/run_0/tensorflow__helpers.py index 9413a503104b3..1b264b60d096c 100644 --- a/ivy/compiler/_cache/Translated_Outputs/tensorflow_default_dtype_bknd_output/run_0/tensorflow__helpers.py +++ b/ivy/compiler/_cache/Translated_Outputs/tensorflow_default_dtype_bknd_output/run_0/tensorflow__helpers.py @@ -310,7 +310,9 @@ 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 ) @@ -798,27 +800,21 @@ 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 = [ @@ -1243,7 +1239,9 @@ 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) @@ -1655,7 +1653,9 @@ 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 ] @@ -1767,6 +1767,7 @@ def tensorflow_to_numpy( return np.asarray(tensorflow.convert_to_tensor(x)) +@tensorflow_handle_array_like_without_promotion def tensorflow_to_scalar(x: Union[tensorflow.Tensor, tensorflow.Variable], /): ret = tensorflow_to_numpy(x).item() if x.dtype == tensorflow.bfloat16: @@ -1774,9 +1775,8 @@ def tensorflow_to_scalar(x: Union[tensorflow.Tensor, tensorflow.Variable], /): return ret -@tensorflow_handle_array_like_without_promotion -def tensorflow_to_scalar_bknd(x: Union[tensorflow.Tensor, tf.Tensor], /): - return tensorflow_to_scalar(x) +def tensorflow_to_scalar_bknd_(self: tensorflow.Tensor): + return tensorflow_to_scalar(self) def tensorflow_is_float_dtype_bknd( @@ -1847,11 +1847,9 @@ 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 @@ -1973,7 +1971,7 @@ def tensorflow_prod( def tensorflow__numel_bknd(shape): shape = tuple(shape) - return tensorflow_to_scalar_bknd(tensorflow_prod(shape)) if shape != () else 1 + return tensorflow_to_scalar_bknd_(tensorflow_prod(shape)) if shape != () else 1 def tensorflow_check_one_way_broadcastable(x1, x2): @@ -2085,7 +2083,9 @@ 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) @@ -2245,11 +2245,9 @@ 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]) @@ -2596,21 +2594,17 @@ 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 diff --git a/ivy/compiler/_cache/Translated_Outputs/tensorflow_default_dtype_bknd_output/run_0/tensorflow_default_dtype_bknd.py b/ivy/compiler/_cache/Translated_Outputs/tensorflow_default_dtype_bknd_output/run_0/tensorflow_default_dtype_bknd.py index 9aab49dd98ed4..ead8121256ddc 100644 --- a/ivy/compiler/_cache/Translated_Outputs/tensorflow_default_dtype_bknd_output/run_0/tensorflow_default_dtype_bknd.py +++ b/ivy/compiler/_cache/Translated_Outputs/tensorflow_default_dtype_bknd_output/run_0/tensorflow_default_dtype_bknd.py @@ -1,8 +1,8 @@ import tensorflow import tensorflow as tf -from typing import Optional from typing import Union +from typing import Optional from .tensorflow__helpers import tensorflow_as_ivy_dtype from .tensorflow__helpers import tensorflow_as_native_dtype diff --git a/ivy/compiler/_cache/Translated_Outputs/tensorflow_dropout_output/run_0/tensorflow_NestedSequence_bknd.py b/ivy/compiler/_cache/Translated_Outputs/tensorflow_dropout_output/run_0/tensorflow_NestedSequence_bknd.py index 9f87b4ae29eff..ac8335fe1e56c 100644 --- a/ivy/compiler/_cache/Translated_Outputs/tensorflow_dropout_output/run_0/tensorflow_NestedSequence_bknd.py +++ b/ivy/compiler/_cache/Translated_Outputs/tensorflow_dropout_output/run_0/tensorflow_NestedSequence_bknd.py @@ -1,5 +1,5 @@ -from typing import Protocol from typing import TypeVar +from typing import Protocol _T_co = TypeVar("_T_co", covariant=True) diff --git a/ivy/compiler/_cache/Translated_Outputs/tensorflow_dropout_output/run_0/tensorflow__helpers.py b/ivy/compiler/_cache/Translated_Outputs/tensorflow_dropout_output/run_0/tensorflow__helpers.py index 0380bbe57701b..6136707cf74ef 100644 --- a/ivy/compiler/_cache/Translated_Outputs/tensorflow_dropout_output/run_0/tensorflow__helpers.py +++ b/ivy/compiler/_cache/Translated_Outputs/tensorflow_dropout_output/run_0/tensorflow__helpers.py @@ -334,7 +334,9 @@ 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 ) @@ -767,21 +769,17 @@ 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 @@ -1193,27 +1191,21 @@ 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 = [ @@ -1638,7 +1630,9 @@ 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) @@ -2050,7 +2044,9 @@ 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 ] @@ -2162,6 +2158,7 @@ def tensorflow_to_numpy( return np.asarray(tensorflow.convert_to_tensor(x)) +@tensorflow_handle_array_like_without_promotion def tensorflow_to_scalar(x: Union[tensorflow.Tensor, tensorflow.Variable], /): ret = tensorflow_to_numpy(x).item() if x.dtype == tensorflow.bfloat16: @@ -2169,9 +2166,8 @@ def tensorflow_to_scalar(x: Union[tensorflow.Tensor, tensorflow.Variable], /): return ret -@tensorflow_handle_array_like_without_promotion -def tensorflow_to_scalar_bknd(x: Union[tensorflow.Tensor, tf.Tensor], /): - return tensorflow_to_scalar(x) +def tensorflow_to_scalar_bknd_(self: tensorflow.Tensor): + return tensorflow_to_scalar(self) def tensorflow_default_uint_dtype_bknd( @@ -2198,11 +2194,9 @@ 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 @@ -2298,7 +2292,7 @@ def tensorflow_prod( def tensorflow__numel_bknd(shape): shape = tuple(shape) - return tensorflow_to_scalar_bknd(tensorflow_prod(shape)) if shape != () else 1 + return tensorflow_to_scalar_bknd_(tensorflow_prod(shape)) if shape != () else 1 def tensorflow_check_one_way_broadcastable(x1, x2): @@ -2410,7 +2404,9 @@ 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) @@ -2570,11 +2566,9 @@ 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]) diff --git a/ivy/compiler/_cache/Translated_Outputs/tensorflow_dropout_output/run_0/tensorflow_dropout.py b/ivy/compiler/_cache/Translated_Outputs/tensorflow_dropout_output/run_0/tensorflow_dropout.py index 359361767ce4f..21c2844f95cdb 100644 --- a/ivy/compiler/_cache/Translated_Outputs/tensorflow_dropout_output/run_0/tensorflow_dropout.py +++ b/ivy/compiler/_cache/Translated_Outputs/tensorflow_dropout_output/run_0/tensorflow_dropout.py @@ -1,8 +1,8 @@ import tensorflow from typing import Optional -from typing import Sequence from typing import Union +from typing import Sequence from .tensorflow__helpers import tensorflow_astype from .tensorflow__helpers import tensorflow_handle_array_like_without_promotion diff --git a/ivy/compiler/_cache/Translated_Outputs/tensorflow_empty_output/run_0/tensorflow__helpers.py b/ivy/compiler/_cache/Translated_Outputs/tensorflow_empty_output/run_0/tensorflow__helpers.py index 9450383c17498..55e1817c57cb2 100644 --- a/ivy/compiler/_cache/Translated_Outputs/tensorflow_empty_output/run_0/tensorflow__helpers.py +++ b/ivy/compiler/_cache/Translated_Outputs/tensorflow_empty_output/run_0/tensorflow__helpers.py @@ -349,7 +349,9 @@ 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 ) @@ -714,27 +716,21 @@ 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 = [ @@ -1159,7 +1155,9 @@ 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) @@ -1556,7 +1554,9 @@ 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 ] @@ -1668,6 +1668,7 @@ def tensorflow_to_numpy( return np.asarray(tensorflow.convert_to_tensor(x)) +@tensorflow_handle_array_like_without_promotion def tensorflow_to_scalar(x: Union[tensorflow.Tensor, tensorflow.Variable], /): ret = tensorflow_to_numpy(x).item() if x.dtype == tensorflow.bfloat16: @@ -1675,9 +1676,8 @@ def tensorflow_to_scalar(x: Union[tensorflow.Tensor, tensorflow.Variable], /): return ret -@tensorflow_handle_array_like_without_promotion -def tensorflow_to_scalar_bknd(x: Union[tensorflow.Tensor, tf.Tensor], /): - return tensorflow_to_scalar(x) +def tensorflow_to_scalar_bknd_(self: tensorflow.Tensor): + return tensorflow_to_scalar(self) def tensorflow_is_float_dtype_bknd( @@ -1748,11 +1748,9 @@ 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 @@ -1874,7 +1872,7 @@ def tensorflow_prod( def tensorflow__numel_bknd(shape): shape = tuple(shape) - return tensorflow_to_scalar_bknd(tensorflow_prod(shape)) if shape != () else 1 + return tensorflow_to_scalar_bknd_(tensorflow_prod(shape)) if shape != () else 1 def tensorflow_check_one_way_broadcastable(x1, x2): @@ -1986,7 +1984,9 @@ 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) @@ -2146,11 +2146,9 @@ 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]) @@ -2497,21 +2495,17 @@ 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 diff --git a/ivy/compiler/_cache/Translated_Outputs/tensorflow_empty_output/run_0/tensorflow_empty.py b/ivy/compiler/_cache/Translated_Outputs/tensorflow_empty_output/run_0/tensorflow_empty.py index bf7f622fda803..8be7c70882da2 100644 --- a/ivy/compiler/_cache/Translated_Outputs/tensorflow_empty_output/run_0/tensorflow_empty.py +++ b/ivy/compiler/_cache/Translated_Outputs/tensorflow_empty_output/run_0/tensorflow_empty.py @@ -1,9 +1,9 @@ import tensorflow import tensorflow as tf +from typing import Union from typing import Optional from typing import Sequence -from typing import Union from .tensorflow__helpers import tensorflow_handle_array_like_without_promotion from .tensorflow__helpers import tensorflow_infer_dtype diff --git a/ivy/compiler/_cache/Translated_Outputs/tensorflow_equal_output/run_0/tensorflow_NestedSequence_bknd.py b/ivy/compiler/_cache/Translated_Outputs/tensorflow_equal_output/run_0/tensorflow_NestedSequence_bknd.py index 9f87b4ae29eff..ac8335fe1e56c 100644 --- a/ivy/compiler/_cache/Translated_Outputs/tensorflow_equal_output/run_0/tensorflow_NestedSequence_bknd.py +++ b/ivy/compiler/_cache/Translated_Outputs/tensorflow_equal_output/run_0/tensorflow_NestedSequence_bknd.py @@ -1,5 +1,5 @@ -from typing import Protocol from typing import TypeVar +from typing import Protocol _T_co = TypeVar("_T_co", covariant=True) diff --git a/ivy/compiler/_cache/Translated_Outputs/tensorflow_equal_output/run_0/tensorflow__helpers.py b/ivy/compiler/_cache/Translated_Outputs/tensorflow_equal_output/run_0/tensorflow__helpers.py index 9e72d6d13d0cc..e3969f60253de 100644 --- a/ivy/compiler/_cache/Translated_Outputs/tensorflow_equal_output/run_0/tensorflow__helpers.py +++ b/ivy/compiler/_cache/Translated_Outputs/tensorflow_equal_output/run_0/tensorflow__helpers.py @@ -310,7 +310,9 @@ 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 ) @@ -854,27 +856,21 @@ 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 = [ @@ -1299,7 +1295,9 @@ 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) @@ -1711,7 +1709,9 @@ 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 ] @@ -1823,6 +1823,7 @@ def tensorflow_to_numpy( return np.asarray(tensorflow.convert_to_tensor(x)) +@tensorflow_handle_array_like_without_promotion def tensorflow_to_scalar(x: Union[tensorflow.Tensor, tensorflow.Variable], /): ret = tensorflow_to_numpy(x).item() if x.dtype == tensorflow.bfloat16: @@ -1830,9 +1831,8 @@ def tensorflow_to_scalar(x: Union[tensorflow.Tensor, tensorflow.Variable], /): return ret -@tensorflow_handle_array_like_without_promotion -def tensorflow_to_scalar_bknd(x: Union[tensorflow.Tensor, tf.Tensor], /): - return tensorflow_to_scalar(x) +def tensorflow_to_scalar_bknd_(self: tensorflow.Tensor): + return tensorflow_to_scalar(self) def tensorflow_is_complex_dtype_bknd( @@ -1901,11 +1901,9 @@ 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 @@ -2027,7 +2025,7 @@ def tensorflow_prod( def tensorflow__numel_bknd(shape): shape = tuple(shape) - return tensorflow_to_scalar_bknd(tensorflow_prod(shape)) if shape != () else 1 + return tensorflow_to_scalar_bknd_(tensorflow_prod(shape)) if shape != () else 1 def tensorflow_check_one_way_broadcastable(x1, x2): @@ -2139,7 +2137,9 @@ 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) @@ -2299,11 +2299,9 @@ 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]) @@ -2552,21 +2550,17 @@ 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 diff --git a/ivy/compiler/_cache/Translated_Outputs/tensorflow_equal_output/run_0/tensorflow_equal.py b/ivy/compiler/_cache/Translated_Outputs/tensorflow_equal_output/run_0/tensorflow_equal.py index 8d0df71b82b45..e22b79c8ef33a 100644 --- a/ivy/compiler/_cache/Translated_Outputs/tensorflow_equal_output/run_0/tensorflow_equal.py +++ b/ivy/compiler/_cache/Translated_Outputs/tensorflow_equal_output/run_0/tensorflow_equal.py @@ -21,7 +21,9 @@ def tensorflow_equal( 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) diff --git a/ivy/compiler/_cache/Translated_Outputs/tensorflow_erfinv_output/run_0/tensorflow_NestedSequence_bknd.py b/ivy/compiler/_cache/Translated_Outputs/tensorflow_erfinv_output/run_0/tensorflow_NestedSequence_bknd.py index 9f87b4ae29eff..ac8335fe1e56c 100644 --- a/ivy/compiler/_cache/Translated_Outputs/tensorflow_erfinv_output/run_0/tensorflow_NestedSequence_bknd.py +++ b/ivy/compiler/_cache/Translated_Outputs/tensorflow_erfinv_output/run_0/tensorflow_NestedSequence_bknd.py @@ -1,5 +1,5 @@ -from typing import Protocol from typing import TypeVar +from typing import Protocol _T_co = TypeVar("_T_co", covariant=True) diff --git a/ivy/compiler/_cache/Translated_Outputs/tensorflow_erfinv_output/run_0/tensorflow__helpers.py b/ivy/compiler/_cache/Translated_Outputs/tensorflow_erfinv_output/run_0/tensorflow__helpers.py index 0380bbe57701b..6136707cf74ef 100644 --- a/ivy/compiler/_cache/Translated_Outputs/tensorflow_erfinv_output/run_0/tensorflow__helpers.py +++ b/ivy/compiler/_cache/Translated_Outputs/tensorflow_erfinv_output/run_0/tensorflow__helpers.py @@ -334,7 +334,9 @@ 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 ) @@ -767,21 +769,17 @@ 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 @@ -1193,27 +1191,21 @@ 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 = [ @@ -1638,7 +1630,9 @@ 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) @@ -2050,7 +2044,9 @@ 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 ] @@ -2162,6 +2158,7 @@ def tensorflow_to_numpy( return np.asarray(tensorflow.convert_to_tensor(x)) +@tensorflow_handle_array_like_without_promotion def tensorflow_to_scalar(x: Union[tensorflow.Tensor, tensorflow.Variable], /): ret = tensorflow_to_numpy(x).item() if x.dtype == tensorflow.bfloat16: @@ -2169,9 +2166,8 @@ def tensorflow_to_scalar(x: Union[tensorflow.Tensor, tensorflow.Variable], /): return ret -@tensorflow_handle_array_like_without_promotion -def tensorflow_to_scalar_bknd(x: Union[tensorflow.Tensor, tf.Tensor], /): - return tensorflow_to_scalar(x) +def tensorflow_to_scalar_bknd_(self: tensorflow.Tensor): + return tensorflow_to_scalar(self) def tensorflow_default_uint_dtype_bknd( @@ -2198,11 +2194,9 @@ 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 @@ -2298,7 +2292,7 @@ def tensorflow_prod( def tensorflow__numel_bknd(shape): shape = tuple(shape) - return tensorflow_to_scalar_bknd(tensorflow_prod(shape)) if shape != () else 1 + return tensorflow_to_scalar_bknd_(tensorflow_prod(shape)) if shape != () else 1 def tensorflow_check_one_way_broadcastable(x1, x2): @@ -2410,7 +2404,9 @@ 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) @@ -2570,11 +2566,9 @@ 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]) diff --git a/ivy/compiler/_cache/Translated_Outputs/tensorflow_erfinv_output/run_0/tensorflow_erfinv.py b/ivy/compiler/_cache/Translated_Outputs/tensorflow_erfinv_output/run_0/tensorflow_erfinv.py index 9bb43f0d8328b..87f2e1c9b719f 100644 --- a/ivy/compiler/_cache/Translated_Outputs/tensorflow_erfinv_output/run_0/tensorflow_erfinv.py +++ b/ivy/compiler/_cache/Translated_Outputs/tensorflow_erfinv_output/run_0/tensorflow_erfinv.py @@ -1,7 +1,7 @@ import tensorflow -from typing import Optional from typing import Union +from typing import Optional from .tensorflow__helpers import tensorflow_handle_array_like_without_promotion diff --git a/ivy/compiler/_cache/Translated_Outputs/tensorflow_exp_output/run_0/tensorflow__helpers.py b/ivy/compiler/_cache/Translated_Outputs/tensorflow_exp_output/run_0/tensorflow__helpers.py index 0380bbe57701b..6136707cf74ef 100644 --- a/ivy/compiler/_cache/Translated_Outputs/tensorflow_exp_output/run_0/tensorflow__helpers.py +++ b/ivy/compiler/_cache/Translated_Outputs/tensorflow_exp_output/run_0/tensorflow__helpers.py @@ -334,7 +334,9 @@ 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 ) @@ -767,21 +769,17 @@ 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 @@ -1193,27 +1191,21 @@ 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 = [ @@ -1638,7 +1630,9 @@ 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) @@ -2050,7 +2044,9 @@ 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 ] @@ -2162,6 +2158,7 @@ def tensorflow_to_numpy( return np.asarray(tensorflow.convert_to_tensor(x)) +@tensorflow_handle_array_like_without_promotion def tensorflow_to_scalar(x: Union[tensorflow.Tensor, tensorflow.Variable], /): ret = tensorflow_to_numpy(x).item() if x.dtype == tensorflow.bfloat16: @@ -2169,9 +2166,8 @@ def tensorflow_to_scalar(x: Union[tensorflow.Tensor, tensorflow.Variable], /): return ret -@tensorflow_handle_array_like_without_promotion -def tensorflow_to_scalar_bknd(x: Union[tensorflow.Tensor, tf.Tensor], /): - return tensorflow_to_scalar(x) +def tensorflow_to_scalar_bknd_(self: tensorflow.Tensor): + return tensorflow_to_scalar(self) def tensorflow_default_uint_dtype_bknd( @@ -2198,11 +2194,9 @@ 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 @@ -2298,7 +2292,7 @@ def tensorflow_prod( def tensorflow__numel_bknd(shape): shape = tuple(shape) - return tensorflow_to_scalar_bknd(tensorflow_prod(shape)) if shape != () else 1 + return tensorflow_to_scalar_bknd_(tensorflow_prod(shape)) if shape != () else 1 def tensorflow_check_one_way_broadcastable(x1, x2): @@ -2410,7 +2404,9 @@ 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) @@ -2570,11 +2566,9 @@ 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]) diff --git a/ivy/compiler/_cache/Translated_Outputs/tensorflow_exp_output/run_0/tensorflow_exp.py b/ivy/compiler/_cache/Translated_Outputs/tensorflow_exp_output/run_0/tensorflow_exp.py index 2cd2d3e62048e..b2a02898870e5 100644 --- a/ivy/compiler/_cache/Translated_Outputs/tensorflow_exp_output/run_0/tensorflow_exp.py +++ b/ivy/compiler/_cache/Translated_Outputs/tensorflow_exp_output/run_0/tensorflow_exp.py @@ -1,7 +1,7 @@ import tensorflow -from typing import Union from typing import Optional +from typing import Union from .tensorflow__helpers import tensorflow_handle_array_like_without_promotion diff --git a/ivy/compiler/_cache/Translated_Outputs/tensorflow_flatten_output/run_0/tensorflow__helpers.py b/ivy/compiler/_cache/Translated_Outputs/tensorflow_flatten_output/run_0/tensorflow__helpers.py index 0380bbe57701b..6136707cf74ef 100644 --- a/ivy/compiler/_cache/Translated_Outputs/tensorflow_flatten_output/run_0/tensorflow__helpers.py +++ b/ivy/compiler/_cache/Translated_Outputs/tensorflow_flatten_output/run_0/tensorflow__helpers.py @@ -334,7 +334,9 @@ 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 ) @@ -767,21 +769,17 @@ 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 @@ -1193,27 +1191,21 @@ 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 = [ @@ -1638,7 +1630,9 @@ 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) @@ -2050,7 +2044,9 @@ 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 ] @@ -2162,6 +2158,7 @@ def tensorflow_to_numpy( return np.asarray(tensorflow.convert_to_tensor(x)) +@tensorflow_handle_array_like_without_promotion def tensorflow_to_scalar(x: Union[tensorflow.Tensor, tensorflow.Variable], /): ret = tensorflow_to_numpy(x).item() if x.dtype == tensorflow.bfloat16: @@ -2169,9 +2166,8 @@ def tensorflow_to_scalar(x: Union[tensorflow.Tensor, tensorflow.Variable], /): return ret -@tensorflow_handle_array_like_without_promotion -def tensorflow_to_scalar_bknd(x: Union[tensorflow.Tensor, tf.Tensor], /): - return tensorflow_to_scalar(x) +def tensorflow_to_scalar_bknd_(self: tensorflow.Tensor): + return tensorflow_to_scalar(self) def tensorflow_default_uint_dtype_bknd( @@ -2198,11 +2194,9 @@ 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 @@ -2298,7 +2292,7 @@ def tensorflow_prod( def tensorflow__numel_bknd(shape): shape = tuple(shape) - return tensorflow_to_scalar_bknd(tensorflow_prod(shape)) if shape != () else 1 + return tensorflow_to_scalar_bknd_(tensorflow_prod(shape)) if shape != () else 1 def tensorflow_check_one_way_broadcastable(x1, x2): @@ -2410,7 +2404,9 @@ 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) @@ -2570,11 +2566,9 @@ 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]) diff --git a/ivy/compiler/_cache/Translated_Outputs/tensorflow_floor_divide_output/run_0/tensorflow__helpers.py b/ivy/compiler/_cache/Translated_Outputs/tensorflow_floor_divide_output/run_0/tensorflow__helpers.py index 9e72d6d13d0cc..e3969f60253de 100644 --- a/ivy/compiler/_cache/Translated_Outputs/tensorflow_floor_divide_output/run_0/tensorflow__helpers.py +++ b/ivy/compiler/_cache/Translated_Outputs/tensorflow_floor_divide_output/run_0/tensorflow__helpers.py @@ -310,7 +310,9 @@ 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 ) @@ -854,27 +856,21 @@ 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 = [ @@ -1299,7 +1295,9 @@ 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) @@ -1711,7 +1709,9 @@ 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 ] @@ -1823,6 +1823,7 @@ def tensorflow_to_numpy( return np.asarray(tensorflow.convert_to_tensor(x)) +@tensorflow_handle_array_like_without_promotion def tensorflow_to_scalar(x: Union[tensorflow.Tensor, tensorflow.Variable], /): ret = tensorflow_to_numpy(x).item() if x.dtype == tensorflow.bfloat16: @@ -1830,9 +1831,8 @@ def tensorflow_to_scalar(x: Union[tensorflow.Tensor, tensorflow.Variable], /): return ret -@tensorflow_handle_array_like_without_promotion -def tensorflow_to_scalar_bknd(x: Union[tensorflow.Tensor, tf.Tensor], /): - return tensorflow_to_scalar(x) +def tensorflow_to_scalar_bknd_(self: tensorflow.Tensor): + return tensorflow_to_scalar(self) def tensorflow_is_complex_dtype_bknd( @@ -1901,11 +1901,9 @@ 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 @@ -2027,7 +2025,7 @@ def tensorflow_prod( def tensorflow__numel_bknd(shape): shape = tuple(shape) - return tensorflow_to_scalar_bknd(tensorflow_prod(shape)) if shape != () else 1 + return tensorflow_to_scalar_bknd_(tensorflow_prod(shape)) if shape != () else 1 def tensorflow_check_one_way_broadcastable(x1, x2): @@ -2139,7 +2137,9 @@ 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) @@ -2299,11 +2299,9 @@ 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]) @@ -2552,21 +2550,17 @@ 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 diff --git a/ivy/compiler/_cache/Translated_Outputs/tensorflow_floor_divide_output/run_0/tensorflow_floor_divide.py b/ivy/compiler/_cache/Translated_Outputs/tensorflow_floor_divide_output/run_0/tensorflow_floor_divide.py index 22e215c67b61e..9e234c390e4c0 100644 --- a/ivy/compiler/_cache/Translated_Outputs/tensorflow_floor_divide_output/run_0/tensorflow_floor_divide.py +++ b/ivy/compiler/_cache/Translated_Outputs/tensorflow_floor_divide_output/run_0/tensorflow_floor_divide.py @@ -1,7 +1,7 @@ import tensorflow -from typing import Optional from typing import Union +from typing import Optional from .tensorflow__helpers import tensorflow_asarray from .tensorflow__helpers import tensorflow_default_dtype_bknd @@ -21,7 +21,9 @@ def tensorflow_floor_divide( 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) diff --git a/ivy/compiler/_cache/Translated_Outputs/tensorflow_gelu_output/run_0/tensorflow__helpers.py b/ivy/compiler/_cache/Translated_Outputs/tensorflow_gelu_output/run_0/tensorflow__helpers.py index 0380bbe57701b..6136707cf74ef 100644 --- a/ivy/compiler/_cache/Translated_Outputs/tensorflow_gelu_output/run_0/tensorflow__helpers.py +++ b/ivy/compiler/_cache/Translated_Outputs/tensorflow_gelu_output/run_0/tensorflow__helpers.py @@ -334,7 +334,9 @@ 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 ) @@ -767,21 +769,17 @@ 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 @@ -1193,27 +1191,21 @@ 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 = [ @@ -1638,7 +1630,9 @@ 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) @@ -2050,7 +2044,9 @@ 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 ] @@ -2162,6 +2158,7 @@ def tensorflow_to_numpy( return np.asarray(tensorflow.convert_to_tensor(x)) +@tensorflow_handle_array_like_without_promotion def tensorflow_to_scalar(x: Union[tensorflow.Tensor, tensorflow.Variable], /): ret = tensorflow_to_numpy(x).item() if x.dtype == tensorflow.bfloat16: @@ -2169,9 +2166,8 @@ def tensorflow_to_scalar(x: Union[tensorflow.Tensor, tensorflow.Variable], /): return ret -@tensorflow_handle_array_like_without_promotion -def tensorflow_to_scalar_bknd(x: Union[tensorflow.Tensor, tf.Tensor], /): - return tensorflow_to_scalar(x) +def tensorflow_to_scalar_bknd_(self: tensorflow.Tensor): + return tensorflow_to_scalar(self) def tensorflow_default_uint_dtype_bknd( @@ -2198,11 +2194,9 @@ 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 @@ -2298,7 +2292,7 @@ def tensorflow_prod( def tensorflow__numel_bknd(shape): shape = tuple(shape) - return tensorflow_to_scalar_bknd(tensorflow_prod(shape)) if shape != () else 1 + return tensorflow_to_scalar_bknd_(tensorflow_prod(shape)) if shape != () else 1 def tensorflow_check_one_way_broadcastable(x1, x2): @@ -2410,7 +2404,9 @@ 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) @@ -2570,11 +2566,9 @@ 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]) diff --git a/ivy/compiler/_cache/Translated_Outputs/tensorflow_inplace_update_output/run_0/tensorflow_NestedSequence_bknd.py b/ivy/compiler/_cache/Translated_Outputs/tensorflow_inplace_update_output/run_0/tensorflow_NestedSequence_bknd.py index 9f87b4ae29eff..ac8335fe1e56c 100644 --- a/ivy/compiler/_cache/Translated_Outputs/tensorflow_inplace_update_output/run_0/tensorflow_NestedSequence_bknd.py +++ b/ivy/compiler/_cache/Translated_Outputs/tensorflow_inplace_update_output/run_0/tensorflow_NestedSequence_bknd.py @@ -1,5 +1,5 @@ -from typing import Protocol from typing import TypeVar +from typing import Protocol _T_co = TypeVar("_T_co", covariant=True) diff --git a/ivy/compiler/_cache/Translated_Outputs/tensorflow_inplace_update_output/run_0/tensorflow__helpers.py b/ivy/compiler/_cache/Translated_Outputs/tensorflow_inplace_update_output/run_0/tensorflow__helpers.py index 86a9dc5ee0661..16fcf0340beb1 100644 --- a/ivy/compiler/_cache/Translated_Outputs/tensorflow_inplace_update_output/run_0/tensorflow__helpers.py +++ b/ivy/compiler/_cache/Translated_Outputs/tensorflow_inplace_update_output/run_0/tensorflow__helpers.py @@ -334,7 +334,9 @@ 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 ) @@ -767,21 +769,17 @@ 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 @@ -1193,27 +1191,21 @@ 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 = [ @@ -1623,7 +1615,9 @@ 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) @@ -2035,7 +2029,9 @@ 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 ] @@ -2147,6 +2143,7 @@ def tensorflow_to_numpy( return np.asarray(tensorflow.convert_to_tensor(x)) +@tensorflow_handle_array_like_without_promotion def tensorflow_to_scalar(x: Union[tensorflow.Tensor, tensorflow.Variable], /): ret = tensorflow_to_numpy(x).item() if x.dtype == tensorflow.bfloat16: @@ -2154,9 +2151,8 @@ def tensorflow_to_scalar(x: Union[tensorflow.Tensor, tensorflow.Variable], /): return ret -@tensorflow_handle_array_like_without_promotion -def tensorflow_to_scalar_bknd(x: Union[tensorflow.Tensor, tf.Tensor], /): - return tensorflow_to_scalar(x) +def tensorflow_to_scalar_bknd_(self: tensorflow.Tensor): + return tensorflow_to_scalar(self) def tensorflow_default_uint_dtype_bknd( @@ -2183,11 +2179,9 @@ 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 @@ -2283,7 +2277,7 @@ def tensorflow_prod( def tensorflow__numel_bknd(shape): shape = tuple(shape) - return tensorflow_to_scalar_bknd(tensorflow_prod(shape)) if shape != () else 1 + return tensorflow_to_scalar_bknd_(tensorflow_prod(shape)) if shape != () else 1 def tensorflow_check_one_way_broadcastable(x1, x2): @@ -2395,7 +2389,9 @@ 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) @@ -2555,11 +2551,9 @@ 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]) diff --git a/ivy/compiler/_cache/Translated_Outputs/tensorflow_interpolate_output/run_0/tensorflow__helpers.py b/ivy/compiler/_cache/Translated_Outputs/tensorflow_interpolate_output/run_0/tensorflow__helpers.py index e3919ad1b8f74..b00c199c585ca 100644 --- a/ivy/compiler/_cache/Translated_Outputs/tensorflow_interpolate_output/run_0/tensorflow__helpers.py +++ b/ivy/compiler/_cache/Translated_Outputs/tensorflow_interpolate_output/run_0/tensorflow__helpers.py @@ -334,7 +334,9 @@ 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 ) @@ -767,21 +769,17 @@ 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 @@ -1193,27 +1191,21 @@ 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 = [ @@ -1638,7 +1630,9 @@ 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) @@ -2038,7 +2032,9 @@ 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 ] @@ -2150,6 +2146,7 @@ def tensorflow_to_numpy( return np.asarray(tensorflow.convert_to_tensor(x)) +@tensorflow_handle_array_like_without_promotion def tensorflow_to_scalar(x: Union[tensorflow.Tensor, tensorflow.Variable], /): ret = tensorflow_to_numpy(x).item() if x.dtype == tensorflow.bfloat16: @@ -2157,9 +2154,8 @@ def tensorflow_to_scalar(x: Union[tensorflow.Tensor, tensorflow.Variable], /): return ret -@tensorflow_handle_array_like_without_promotion -def tensorflow_to_scalar_bknd(x: Union[tensorflow.Tensor, tf.Tensor], /): - return tensorflow_to_scalar(x) +def tensorflow_to_scalar_bknd_(self: tensorflow.Tensor): + return tensorflow_to_scalar(self) def tensorflow_default_uint_dtype_bknd( @@ -2186,11 +2182,9 @@ 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 @@ -2286,7 +2280,7 @@ def tensorflow_prod( def tensorflow__numel_bknd(shape): shape = tuple(shape) - return tensorflow_to_scalar_bknd(tensorflow_prod(shape)) if shape != () else 1 + return tensorflow_to_scalar_bknd_(tensorflow_prod(shape)) if shape != () else 1 def tensorflow_check_one_way_broadcastable(x1, x2): @@ -2398,7 +2392,9 @@ 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) @@ -2558,11 +2554,9 @@ 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]) @@ -2682,7 +2676,9 @@ def tensorflow_divide( 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) diff --git a/ivy/compiler/_cache/Translated_Outputs/tensorflow_interpolate_output/run_0/tensorflow_interpolate.py b/ivy/compiler/_cache/Translated_Outputs/tensorflow_interpolate_output/run_0/tensorflow_interpolate.py index 7833565ab955b..dc87755da6a04 100644 --- a/ivy/compiler/_cache/Translated_Outputs/tensorflow_interpolate_output/run_0/tensorflow_interpolate.py +++ b/ivy/compiler/_cache/Translated_Outputs/tensorflow_interpolate_output/run_0/tensorflow_interpolate.py @@ -1,9 +1,9 @@ import tensorflow -from typing import Union from typing import Sequence from typing import Literal from typing import Optional +from typing import Union from .tensorflow__helpers import tensorflow__get_size_bknd from .tensorflow__helpers import tensorflow_exists_bknd @@ -54,11 +54,11 @@ def tensorflow_interpolate( mode = ( "bilinear" if mode == "linear" - else ( - "area" - if mode == "tf_area" - else "nearest" if mode == "nearest-exact" else mode - ) + else "area" + if mode == "tf_area" + else "nearest" + if mode == "nearest-exact" + else mode ) if mode == "tf_bicubic": mode = "bicubic" diff --git a/ivy/compiler/_cache/Translated_Outputs/tensorflow_layer_norm_bknd_output/run_0/tensorflow_NestedSequence_bknd.py b/ivy/compiler/_cache/Translated_Outputs/tensorflow_layer_norm_bknd_output/run_0/tensorflow_NestedSequence_bknd.py index 9f87b4ae29eff..ac8335fe1e56c 100644 --- a/ivy/compiler/_cache/Translated_Outputs/tensorflow_layer_norm_bknd_output/run_0/tensorflow_NestedSequence_bknd.py +++ b/ivy/compiler/_cache/Translated_Outputs/tensorflow_layer_norm_bknd_output/run_0/tensorflow_NestedSequence_bknd.py @@ -1,5 +1,5 @@ -from typing import Protocol from typing import TypeVar +from typing import Protocol _T_co = TypeVar("_T_co", covariant=True) diff --git a/ivy/compiler/_cache/Translated_Outputs/tensorflow_layer_norm_bknd_output/run_0/tensorflow__helpers.py b/ivy/compiler/_cache/Translated_Outputs/tensorflow_layer_norm_bknd_output/run_0/tensorflow__helpers.py index 039307653a45a..188aaa68bd1c1 100644 --- a/ivy/compiler/_cache/Translated_Outputs/tensorflow_layer_norm_bknd_output/run_0/tensorflow__helpers.py +++ b/ivy/compiler/_cache/Translated_Outputs/tensorflow_layer_norm_bknd_output/run_0/tensorflow__helpers.py @@ -334,7 +334,9 @@ 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 ) @@ -767,21 +769,17 @@ 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 @@ -1193,27 +1191,21 @@ 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 = [ @@ -1638,7 +1630,9 @@ 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) @@ -2050,7 +2044,9 @@ 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 ] @@ -2162,6 +2158,7 @@ def tensorflow_to_numpy( return np.asarray(tensorflow.convert_to_tensor(x)) +@tensorflow_handle_array_like_without_promotion def tensorflow_to_scalar(x: Union[tensorflow.Tensor, tensorflow.Variable], /): ret = tensorflow_to_numpy(x).item() if x.dtype == tensorflow.bfloat16: @@ -2169,9 +2166,8 @@ def tensorflow_to_scalar(x: Union[tensorflow.Tensor, tensorflow.Variable], /): return ret -@tensorflow_handle_array_like_without_promotion -def tensorflow_to_scalar_bknd(x: Union[tensorflow.Tensor, tf.Tensor], /): - return tensorflow_to_scalar(x) +def tensorflow_to_scalar_bknd_(self: tensorflow.Tensor): + return tensorflow_to_scalar(self) def tensorflow_default_uint_dtype_bknd( @@ -2198,11 +2194,9 @@ 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 @@ -2298,7 +2292,7 @@ def tensorflow_prod( def tensorflow__numel_bknd(shape): shape = tuple(shape) - return tensorflow_to_scalar_bknd(tensorflow_prod(shape)) if shape != () else 1 + return tensorflow_to_scalar_bknd_(tensorflow_prod(shape)) if shape != () else 1 def tensorflow_check_one_way_broadcastable(x1, x2): @@ -2410,7 +2404,9 @@ 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) @@ -2570,11 +2566,9 @@ 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]) @@ -2728,7 +2722,9 @@ 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) diff --git a/ivy/compiler/_cache/Translated_Outputs/tensorflow_layer_norm_bknd_output/run_0/tensorflow_layer_norm_bknd.py b/ivy/compiler/_cache/Translated_Outputs/tensorflow_layer_norm_bknd_output/run_0/tensorflow_layer_norm_bknd.py index 39a88a9686a4d..707cf4c146f6d 100644 --- a/ivy/compiler/_cache/Translated_Outputs/tensorflow_layer_norm_bknd_output/run_0/tensorflow_layer_norm_bknd.py +++ b/ivy/compiler/_cache/Translated_Outputs/tensorflow_layer_norm_bknd_output/run_0/tensorflow_layer_norm_bknd.py @@ -2,8 +2,8 @@ import tensorflow as tf from typing import Optional -from typing import List from typing import Union +from typing import List from .tensorflow__helpers import tensorflow_add from .tensorflow__helpers import tensorflow_handle_array_like_without_promotion diff --git a/ivy/compiler/_cache/Translated_Outputs/tensorflow_leaky_relu_output/run_0/tensorflow_NestedSequence_bknd.py b/ivy/compiler/_cache/Translated_Outputs/tensorflow_leaky_relu_output/run_0/tensorflow_NestedSequence_bknd.py index 9f87b4ae29eff..ac8335fe1e56c 100644 --- a/ivy/compiler/_cache/Translated_Outputs/tensorflow_leaky_relu_output/run_0/tensorflow_NestedSequence_bknd.py +++ b/ivy/compiler/_cache/Translated_Outputs/tensorflow_leaky_relu_output/run_0/tensorflow_NestedSequence_bknd.py @@ -1,5 +1,5 @@ -from typing import Protocol from typing import TypeVar +from typing import Protocol _T_co = TypeVar("_T_co", covariant=True) diff --git a/ivy/compiler/_cache/Translated_Outputs/tensorflow_leaky_relu_output/run_0/tensorflow__helpers.py b/ivy/compiler/_cache/Translated_Outputs/tensorflow_leaky_relu_output/run_0/tensorflow__helpers.py index 0380bbe57701b..6136707cf74ef 100644 --- a/ivy/compiler/_cache/Translated_Outputs/tensorflow_leaky_relu_output/run_0/tensorflow__helpers.py +++ b/ivy/compiler/_cache/Translated_Outputs/tensorflow_leaky_relu_output/run_0/tensorflow__helpers.py @@ -334,7 +334,9 @@ 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 ) @@ -767,21 +769,17 @@ 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 @@ -1193,27 +1191,21 @@ 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 = [ @@ -1638,7 +1630,9 @@ 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) @@ -2050,7 +2044,9 @@ 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 ] @@ -2162,6 +2158,7 @@ def tensorflow_to_numpy( return np.asarray(tensorflow.convert_to_tensor(x)) +@tensorflow_handle_array_like_without_promotion def tensorflow_to_scalar(x: Union[tensorflow.Tensor, tensorflow.Variable], /): ret = tensorflow_to_numpy(x).item() if x.dtype == tensorflow.bfloat16: @@ -2169,9 +2166,8 @@ def tensorflow_to_scalar(x: Union[tensorflow.Tensor, tensorflow.Variable], /): return ret -@tensorflow_handle_array_like_without_promotion -def tensorflow_to_scalar_bknd(x: Union[tensorflow.Tensor, tf.Tensor], /): - return tensorflow_to_scalar(x) +def tensorflow_to_scalar_bknd_(self: tensorflow.Tensor): + return tensorflow_to_scalar(self) def tensorflow_default_uint_dtype_bknd( @@ -2198,11 +2194,9 @@ 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 @@ -2298,7 +2292,7 @@ def tensorflow_prod( def tensorflow__numel_bknd(shape): shape = tuple(shape) - return tensorflow_to_scalar_bknd(tensorflow_prod(shape)) if shape != () else 1 + return tensorflow_to_scalar_bknd_(tensorflow_prod(shape)) if shape != () else 1 def tensorflow_check_one_way_broadcastable(x1, x2): @@ -2410,7 +2404,9 @@ 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) @@ -2570,11 +2566,9 @@ 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]) diff --git a/ivy/compiler/_cache/Translated_Outputs/tensorflow_linspace_output/run_0/tensorflow_NestedSequence_bknd.py b/ivy/compiler/_cache/Translated_Outputs/tensorflow_linspace_output/run_0/tensorflow_NestedSequence_bknd.py index 9f87b4ae29eff..ac8335fe1e56c 100644 --- a/ivy/compiler/_cache/Translated_Outputs/tensorflow_linspace_output/run_0/tensorflow_NestedSequence_bknd.py +++ b/ivy/compiler/_cache/Translated_Outputs/tensorflow_linspace_output/run_0/tensorflow_NestedSequence_bknd.py @@ -1,5 +1,5 @@ -from typing import Protocol from typing import TypeVar +from typing import Protocol _T_co = TypeVar("_T_co", covariant=True) diff --git a/ivy/compiler/_cache/Translated_Outputs/tensorflow_linspace_output/run_0/tensorflow__helpers.py b/ivy/compiler/_cache/Translated_Outputs/tensorflow_linspace_output/run_0/tensorflow__helpers.py index edf55e1c5a25d..4191458d5455b 100644 --- a/ivy/compiler/_cache/Translated_Outputs/tensorflow_linspace_output/run_0/tensorflow__helpers.py +++ b/ivy/compiler/_cache/Translated_Outputs/tensorflow_linspace_output/run_0/tensorflow__helpers.py @@ -349,7 +349,9 @@ 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 ) @@ -714,27 +716,21 @@ 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 = [ @@ -1159,7 +1155,9 @@ 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) @@ -1556,7 +1554,9 @@ 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 ] @@ -1668,6 +1668,7 @@ def tensorflow_to_numpy( return np.asarray(tensorflow.convert_to_tensor(x)) +@tensorflow_handle_array_like_without_promotion def tensorflow_to_scalar(x: Union[tensorflow.Tensor, tensorflow.Variable], /): ret = tensorflow_to_numpy(x).item() if x.dtype == tensorflow.bfloat16: @@ -1675,9 +1676,8 @@ def tensorflow_to_scalar(x: Union[tensorflow.Tensor, tensorflow.Variable], /): return ret -@tensorflow_handle_array_like_without_promotion -def tensorflow_to_scalar_bknd(x: Union[tensorflow.Tensor, tf.Tensor], /): - return tensorflow_to_scalar(x) +def tensorflow_to_scalar_bknd_(self: tensorflow.Tensor): + return tensorflow_to_scalar(self) def tensorflow_is_float_dtype_bknd( @@ -1748,11 +1748,9 @@ 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 @@ -1874,7 +1872,7 @@ def tensorflow_prod( def tensorflow__numel_bknd(shape): shape = tuple(shape) - return tensorflow_to_scalar_bknd(tensorflow_prod(shape)) if shape != () else 1 + return tensorflow_to_scalar_bknd_(tensorflow_prod(shape)) if shape != () else 1 def tensorflow_check_one_way_broadcastable(x1, x2): @@ -1986,7 +1984,9 @@ 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) @@ -2146,11 +2146,9 @@ 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]) @@ -2497,21 +2495,17 @@ 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 diff --git a/ivy/compiler/_cache/Translated_Outputs/tensorflow_linspace_output/run_0/tensorflow_linspace.py b/ivy/compiler/_cache/Translated_Outputs/tensorflow_linspace_output/run_0/tensorflow_linspace.py index 2dfc3badc2ec5..8692fe07d4cc7 100644 --- a/ivy/compiler/_cache/Translated_Outputs/tensorflow_linspace_output/run_0/tensorflow_linspace.py +++ b/ivy/compiler/_cache/Translated_Outputs/tensorflow_linspace_output/run_0/tensorflow_linspace.py @@ -1,7 +1,7 @@ import tensorflow -from typing import Union from typing import Optional +from typing import Union from .tensorflow__helpers import tensorflow__slice_at_axis from .tensorflow__helpers import tensorflow_handle_array_like_without_promotion diff --git a/ivy/compiler/_cache/Translated_Outputs/tensorflow_log2_output/run_0/tensorflow__helpers.py b/ivy/compiler/_cache/Translated_Outputs/tensorflow_log2_output/run_0/tensorflow__helpers.py index 0380bbe57701b..6136707cf74ef 100644 --- a/ivy/compiler/_cache/Translated_Outputs/tensorflow_log2_output/run_0/tensorflow__helpers.py +++ b/ivy/compiler/_cache/Translated_Outputs/tensorflow_log2_output/run_0/tensorflow__helpers.py @@ -334,7 +334,9 @@ 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 ) @@ -767,21 +769,17 @@ 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 @@ -1193,27 +1191,21 @@ 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 = [ @@ -1638,7 +1630,9 @@ 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) @@ -2050,7 +2044,9 @@ 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 ] @@ -2162,6 +2158,7 @@ def tensorflow_to_numpy( return np.asarray(tensorflow.convert_to_tensor(x)) +@tensorflow_handle_array_like_without_promotion def tensorflow_to_scalar(x: Union[tensorflow.Tensor, tensorflow.Variable], /): ret = tensorflow_to_numpy(x).item() if x.dtype == tensorflow.bfloat16: @@ -2169,9 +2166,8 @@ def tensorflow_to_scalar(x: Union[tensorflow.Tensor, tensorflow.Variable], /): return ret -@tensorflow_handle_array_like_without_promotion -def tensorflow_to_scalar_bknd(x: Union[tensorflow.Tensor, tf.Tensor], /): - return tensorflow_to_scalar(x) +def tensorflow_to_scalar_bknd_(self: tensorflow.Tensor): + return tensorflow_to_scalar(self) def tensorflow_default_uint_dtype_bknd( @@ -2198,11 +2194,9 @@ 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 @@ -2298,7 +2292,7 @@ def tensorflow_prod( def tensorflow__numel_bknd(shape): shape = tuple(shape) - return tensorflow_to_scalar_bknd(tensorflow_prod(shape)) if shape != () else 1 + return tensorflow_to_scalar_bknd_(tensorflow_prod(shape)) if shape != () else 1 def tensorflow_check_one_way_broadcastable(x1, x2): @@ -2410,7 +2404,9 @@ 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) @@ -2570,11 +2566,9 @@ 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]) diff --git a/ivy/compiler/_cache/Translated_Outputs/tensorflow_max_pool2d_output/run_0/tensorflow_NestedSequence_bknd.py b/ivy/compiler/_cache/Translated_Outputs/tensorflow_max_pool2d_output/run_0/tensorflow_NestedSequence_bknd.py index 9f87b4ae29eff..ac8335fe1e56c 100644 --- a/ivy/compiler/_cache/Translated_Outputs/tensorflow_max_pool2d_output/run_0/tensorflow_NestedSequence_bknd.py +++ b/ivy/compiler/_cache/Translated_Outputs/tensorflow_max_pool2d_output/run_0/tensorflow_NestedSequence_bknd.py @@ -1,5 +1,5 @@ -from typing import Protocol from typing import TypeVar +from typing import Protocol _T_co = TypeVar("_T_co", covariant=True) diff --git a/ivy/compiler/_cache/Translated_Outputs/tensorflow_max_pool2d_output/run_0/tensorflow__helpers.py b/ivy/compiler/_cache/Translated_Outputs/tensorflow_max_pool2d_output/run_0/tensorflow__helpers.py index 00ff1c82e5464..10b54f6b19c35 100644 --- a/ivy/compiler/_cache/Translated_Outputs/tensorflow_max_pool2d_output/run_0/tensorflow__helpers.py +++ b/ivy/compiler/_cache/Translated_Outputs/tensorflow_max_pool2d_output/run_0/tensorflow__helpers.py @@ -334,7 +334,9 @@ 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 ) @@ -739,27 +741,21 @@ 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 = [ @@ -1184,7 +1180,9 @@ 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) @@ -1596,7 +1594,9 @@ 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 ] @@ -1708,6 +1708,7 @@ def tensorflow_to_numpy( return np.asarray(tensorflow.convert_to_tensor(x)) +@tensorflow_handle_array_like_without_promotion def tensorflow_to_scalar(x: Union[tensorflow.Tensor, tensorflow.Variable], /): ret = tensorflow_to_numpy(x).item() if x.dtype == tensorflow.bfloat16: @@ -1715,9 +1716,8 @@ def tensorflow_to_scalar(x: Union[tensorflow.Tensor, tensorflow.Variable], /): return ret -@tensorflow_handle_array_like_without_promotion -def tensorflow_to_scalar_bknd(x: Union[tensorflow.Tensor, tf.Tensor], /): - return tensorflow_to_scalar(x) +def tensorflow_to_scalar_bknd_(self: tensorflow.Tensor): + return tensorflow_to_scalar(self) def tensorflow_is_float_dtype_bknd( @@ -1788,11 +1788,9 @@ 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 @@ -1914,7 +1912,7 @@ def tensorflow_prod( def tensorflow__numel_bknd(shape): shape = tuple(shape) - return tensorflow_to_scalar_bknd(tensorflow_prod(shape)) if shape != () else 1 + return tensorflow_to_scalar_bknd_(tensorflow_prod(shape)) if shape != () else 1 def tensorflow_check_one_way_broadcastable(x1, x2): @@ -2026,7 +2024,9 @@ 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) @@ -2186,11 +2186,9 @@ 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]) @@ -2537,21 +2535,17 @@ 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 diff --git a/ivy/compiler/_cache/Translated_Outputs/tensorflow_max_pool2d_output/run_0/tensorflow_max_pool2d.py b/ivy/compiler/_cache/Translated_Outputs/tensorflow_max_pool2d_output/run_0/tensorflow_max_pool2d.py index 426036033b209..82aa5cd9ed661 100644 --- a/ivy/compiler/_cache/Translated_Outputs/tensorflow_max_pool2d_output/run_0/tensorflow_max_pool2d.py +++ b/ivy/compiler/_cache/Translated_Outputs/tensorflow_max_pool2d_output/run_0/tensorflow_max_pool2d.py @@ -1,9 +1,9 @@ import tensorflow from typing import Optional +from typing import Union from typing import Tuple from typing import List -from typing import Union from .tensorflow__helpers import tensorflow__determine_depth_max_pooling from .tensorflow__helpers import tensorflow__handle_padding_bknd diff --git a/ivy/compiler/_cache/Translated_Outputs/tensorflow_maximum_output/run_0/tensorflow_NestedSequence_bknd.py b/ivy/compiler/_cache/Translated_Outputs/tensorflow_maximum_output/run_0/tensorflow_NestedSequence_bknd.py index 9f87b4ae29eff..ac8335fe1e56c 100644 --- a/ivy/compiler/_cache/Translated_Outputs/tensorflow_maximum_output/run_0/tensorflow_NestedSequence_bknd.py +++ b/ivy/compiler/_cache/Translated_Outputs/tensorflow_maximum_output/run_0/tensorflow_NestedSequence_bknd.py @@ -1,5 +1,5 @@ -from typing import Protocol from typing import TypeVar +from typing import Protocol _T_co = TypeVar("_T_co", covariant=True) diff --git a/ivy/compiler/_cache/Translated_Outputs/tensorflow_maximum_output/run_0/tensorflow__helpers.py b/ivy/compiler/_cache/Translated_Outputs/tensorflow_maximum_output/run_0/tensorflow__helpers.py index 9e72d6d13d0cc..e3969f60253de 100644 --- a/ivy/compiler/_cache/Translated_Outputs/tensorflow_maximum_output/run_0/tensorflow__helpers.py +++ b/ivy/compiler/_cache/Translated_Outputs/tensorflow_maximum_output/run_0/tensorflow__helpers.py @@ -310,7 +310,9 @@ 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 ) @@ -854,27 +856,21 @@ 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 = [ @@ -1299,7 +1295,9 @@ 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) @@ -1711,7 +1709,9 @@ 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 ] @@ -1823,6 +1823,7 @@ def tensorflow_to_numpy( return np.asarray(tensorflow.convert_to_tensor(x)) +@tensorflow_handle_array_like_without_promotion def tensorflow_to_scalar(x: Union[tensorflow.Tensor, tensorflow.Variable], /): ret = tensorflow_to_numpy(x).item() if x.dtype == tensorflow.bfloat16: @@ -1830,9 +1831,8 @@ def tensorflow_to_scalar(x: Union[tensorflow.Tensor, tensorflow.Variable], /): return ret -@tensorflow_handle_array_like_without_promotion -def tensorflow_to_scalar_bknd(x: Union[tensorflow.Tensor, tf.Tensor], /): - return tensorflow_to_scalar(x) +def tensorflow_to_scalar_bknd_(self: tensorflow.Tensor): + return tensorflow_to_scalar(self) def tensorflow_is_complex_dtype_bknd( @@ -1901,11 +1901,9 @@ 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 @@ -2027,7 +2025,7 @@ def tensorflow_prod( def tensorflow__numel_bknd(shape): shape = tuple(shape) - return tensorflow_to_scalar_bknd(tensorflow_prod(shape)) if shape != () else 1 + return tensorflow_to_scalar_bknd_(tensorflow_prod(shape)) if shape != () else 1 def tensorflow_check_one_way_broadcastable(x1, x2): @@ -2139,7 +2137,9 @@ 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) @@ -2299,11 +2299,9 @@ 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]) @@ -2552,21 +2550,17 @@ 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 diff --git a/ivy/compiler/_cache/Translated_Outputs/tensorflow_maximum_output/run_0/tensorflow_maximum.py b/ivy/compiler/_cache/Translated_Outputs/tensorflow_maximum_output/run_0/tensorflow_maximum.py index c017eba0785be..49fd331886bf1 100644 --- a/ivy/compiler/_cache/Translated_Outputs/tensorflow_maximum_output/run_0/tensorflow_maximum.py +++ b/ivy/compiler/_cache/Translated_Outputs/tensorflow_maximum_output/run_0/tensorflow_maximum.py @@ -1,7 +1,7 @@ import tensorflow -from typing import Optional from typing import Union +from typing import Optional from .tensorflow__helpers import tensorflow_asarray from .tensorflow__helpers import tensorflow_default_dtype_bknd @@ -22,7 +22,9 @@ def tensorflow_maximum( 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) diff --git a/ivy/compiler/_cache/Translated_Outputs/tensorflow_multiply_output/run_0/tensorflow_NestedSequence_bknd.py b/ivy/compiler/_cache/Translated_Outputs/tensorflow_multiply_output/run_0/tensorflow_NestedSequence_bknd.py index 9f87b4ae29eff..ac8335fe1e56c 100644 --- a/ivy/compiler/_cache/Translated_Outputs/tensorflow_multiply_output/run_0/tensorflow_NestedSequence_bknd.py +++ b/ivy/compiler/_cache/Translated_Outputs/tensorflow_multiply_output/run_0/tensorflow_NestedSequence_bknd.py @@ -1,5 +1,5 @@ -from typing import Protocol from typing import TypeVar +from typing import Protocol _T_co = TypeVar("_T_co", covariant=True) diff --git a/ivy/compiler/_cache/Translated_Outputs/tensorflow_multiply_output/run_0/tensorflow__helpers.py b/ivy/compiler/_cache/Translated_Outputs/tensorflow_multiply_output/run_0/tensorflow__helpers.py index 9e72d6d13d0cc..e3969f60253de 100644 --- a/ivy/compiler/_cache/Translated_Outputs/tensorflow_multiply_output/run_0/tensorflow__helpers.py +++ b/ivy/compiler/_cache/Translated_Outputs/tensorflow_multiply_output/run_0/tensorflow__helpers.py @@ -310,7 +310,9 @@ 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 ) @@ -854,27 +856,21 @@ 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 = [ @@ -1299,7 +1295,9 @@ 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) @@ -1711,7 +1709,9 @@ 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 ] @@ -1823,6 +1823,7 @@ def tensorflow_to_numpy( return np.asarray(tensorflow.convert_to_tensor(x)) +@tensorflow_handle_array_like_without_promotion def tensorflow_to_scalar(x: Union[tensorflow.Tensor, tensorflow.Variable], /): ret = tensorflow_to_numpy(x).item() if x.dtype == tensorflow.bfloat16: @@ -1830,9 +1831,8 @@ def tensorflow_to_scalar(x: Union[tensorflow.Tensor, tensorflow.Variable], /): return ret -@tensorflow_handle_array_like_without_promotion -def tensorflow_to_scalar_bknd(x: Union[tensorflow.Tensor, tf.Tensor], /): - return tensorflow_to_scalar(x) +def tensorflow_to_scalar_bknd_(self: tensorflow.Tensor): + return tensorflow_to_scalar(self) def tensorflow_is_complex_dtype_bknd( @@ -1901,11 +1901,9 @@ 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 @@ -2027,7 +2025,7 @@ def tensorflow_prod( def tensorflow__numel_bknd(shape): shape = tuple(shape) - return tensorflow_to_scalar_bknd(tensorflow_prod(shape)) if shape != () else 1 + return tensorflow_to_scalar_bknd_(tensorflow_prod(shape)) if shape != () else 1 def tensorflow_check_one_way_broadcastable(x1, x2): @@ -2139,7 +2137,9 @@ 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) @@ -2299,11 +2299,9 @@ 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]) @@ -2552,21 +2550,17 @@ 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 diff --git a/ivy/compiler/_cache/Translated_Outputs/tensorflow_multiply_output/run_0/tensorflow_multiply.py b/ivy/compiler/_cache/Translated_Outputs/tensorflow_multiply_output/run_0/tensorflow_multiply.py index 81dc60ebf3736..56e25a02b61ec 100644 --- a/ivy/compiler/_cache/Translated_Outputs/tensorflow_multiply_output/run_0/tensorflow_multiply.py +++ b/ivy/compiler/_cache/Translated_Outputs/tensorflow_multiply_output/run_0/tensorflow_multiply.py @@ -21,7 +21,9 @@ 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) diff --git a/ivy/compiler/_cache/Translated_Outputs/tensorflow_nonzero_output/run_0/tensorflow__helpers.py b/ivy/compiler/_cache/Translated_Outputs/tensorflow_nonzero_output/run_0/tensorflow__helpers.py index 0380bbe57701b..6136707cf74ef 100644 --- a/ivy/compiler/_cache/Translated_Outputs/tensorflow_nonzero_output/run_0/tensorflow__helpers.py +++ b/ivy/compiler/_cache/Translated_Outputs/tensorflow_nonzero_output/run_0/tensorflow__helpers.py @@ -334,7 +334,9 @@ 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 ) @@ -767,21 +769,17 @@ 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 @@ -1193,27 +1191,21 @@ 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 = [ @@ -1638,7 +1630,9 @@ 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) @@ -2050,7 +2044,9 @@ 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 ] @@ -2162,6 +2158,7 @@ def tensorflow_to_numpy( return np.asarray(tensorflow.convert_to_tensor(x)) +@tensorflow_handle_array_like_without_promotion def tensorflow_to_scalar(x: Union[tensorflow.Tensor, tensorflow.Variable], /): ret = tensorflow_to_numpy(x).item() if x.dtype == tensorflow.bfloat16: @@ -2169,9 +2166,8 @@ def tensorflow_to_scalar(x: Union[tensorflow.Tensor, tensorflow.Variable], /): return ret -@tensorflow_handle_array_like_without_promotion -def tensorflow_to_scalar_bknd(x: Union[tensorflow.Tensor, tf.Tensor], /): - return tensorflow_to_scalar(x) +def tensorflow_to_scalar_bknd_(self: tensorflow.Tensor): + return tensorflow_to_scalar(self) def tensorflow_default_uint_dtype_bknd( @@ -2198,11 +2194,9 @@ 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 @@ -2298,7 +2292,7 @@ def tensorflow_prod( def tensorflow__numel_bknd(shape): shape = tuple(shape) - return tensorflow_to_scalar_bknd(tensorflow_prod(shape)) if shape != () else 1 + return tensorflow_to_scalar_bknd_(tensorflow_prod(shape)) if shape != () else 1 def tensorflow_check_one_way_broadcastable(x1, x2): @@ -2410,7 +2404,9 @@ 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) @@ -2570,11 +2566,9 @@ 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]) diff --git a/ivy/compiler/_cache/Translated_Outputs/tensorflow_nonzero_output/run_0/tensorflow_nonzero.py b/ivy/compiler/_cache/Translated_Outputs/tensorflow_nonzero_output/run_0/tensorflow_nonzero.py index f1f5a64ec5ebe..8034ee045539d 100644 --- a/ivy/compiler/_cache/Translated_Outputs/tensorflow_nonzero_output/run_0/tensorflow_nonzero.py +++ b/ivy/compiler/_cache/Translated_Outputs/tensorflow_nonzero_output/run_0/tensorflow_nonzero.py @@ -1,8 +1,8 @@ import tensorflow +from typing import Union from typing import Optional from numbers import Number -from typing import Union from .tensorflow__helpers import tensorflow_handle_array_like_without_promotion diff --git a/ivy/compiler/_cache/Translated_Outputs/tensorflow_pad_output/run_0/tensorflow__helpers.py b/ivy/compiler/_cache/Translated_Outputs/tensorflow_pad_output/run_0/tensorflow__helpers.py index f5be1660e97c4..d589a22c82bae 100644 --- a/ivy/compiler/_cache/Translated_Outputs/tensorflow_pad_output/run_0/tensorflow__helpers.py +++ b/ivy/compiler/_cache/Translated_Outputs/tensorflow_pad_output/run_0/tensorflow__helpers.py @@ -334,7 +334,9 @@ 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 ) @@ -767,21 +769,17 @@ 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 @@ -1193,27 +1191,21 @@ 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 = [ @@ -1638,7 +1630,9 @@ 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) @@ -2050,7 +2044,9 @@ 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 ] @@ -2162,6 +2158,7 @@ def tensorflow_to_numpy( return np.asarray(tensorflow.convert_to_tensor(x)) +@tensorflow_handle_array_like_without_promotion def tensorflow_to_scalar(x: Union[tensorflow.Tensor, tensorflow.Variable], /): ret = tensorflow_to_numpy(x).item() if x.dtype == tensorflow.bfloat16: @@ -2169,9 +2166,8 @@ def tensorflow_to_scalar(x: Union[tensorflow.Tensor, tensorflow.Variable], /): return ret -@tensorflow_handle_array_like_without_promotion -def tensorflow_to_scalar_bknd(x: Union[tensorflow.Tensor, tf.Tensor], /): - return tensorflow_to_scalar(x) +def tensorflow_to_scalar_bknd_(self: tensorflow.Tensor): + return tensorflow_to_scalar(self) def tensorflow_default_uint_dtype_bknd( @@ -2198,11 +2194,9 @@ 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 @@ -2298,7 +2292,7 @@ def tensorflow_prod( def tensorflow__numel_bknd(shape): shape = tuple(shape) - return tensorflow_to_scalar_bknd(tensorflow_prod(shape)) if shape != () else 1 + return tensorflow_to_scalar_bknd_(tensorflow_prod(shape)) if shape != () else 1 def tensorflow_check_one_way_broadcastable(x1, x2): @@ -2410,7 +2404,9 @@ 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) @@ -2570,11 +2566,9 @@ 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]) diff --git a/ivy/compiler/_cache/Translated_Outputs/tensorflow_pad_output/run_0/tensorflow_pad.py b/ivy/compiler/_cache/Translated_Outputs/tensorflow_pad_output/run_0/tensorflow_pad.py index 39aea8feca5a2..d761416bc62ba 100644 --- a/ivy/compiler/_cache/Translated_Outputs/tensorflow_pad_output/run_0/tensorflow_pad.py +++ b/ivy/compiler/_cache/Translated_Outputs/tensorflow_pad_output/run_0/tensorflow_pad.py @@ -3,11 +3,11 @@ from typing import Tuple from numbers import Number from typing import Callable -from typing import Any from typing import Iterable +from typing import Any from typing import Optional -from typing import Literal from typing import Union +from typing import Literal from .tensorflow__helpers import tensorflow__to_tf_padding_bknd from .tensorflow__helpers import tensorflow_handle_array_like_without_promotion diff --git a/ivy/compiler/_cache/Translated_Outputs/tensorflow_permute_dims_output/run_0/tensorflow__helpers.py b/ivy/compiler/_cache/Translated_Outputs/tensorflow_permute_dims_output/run_0/tensorflow__helpers.py index 0380bbe57701b..6136707cf74ef 100644 --- a/ivy/compiler/_cache/Translated_Outputs/tensorflow_permute_dims_output/run_0/tensorflow__helpers.py +++ b/ivy/compiler/_cache/Translated_Outputs/tensorflow_permute_dims_output/run_0/tensorflow__helpers.py @@ -334,7 +334,9 @@ 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 ) @@ -767,21 +769,17 @@ 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 @@ -1193,27 +1191,21 @@ 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 = [ @@ -1638,7 +1630,9 @@ 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) @@ -2050,7 +2044,9 @@ 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 ] @@ -2162,6 +2158,7 @@ def tensorflow_to_numpy( return np.asarray(tensorflow.convert_to_tensor(x)) +@tensorflow_handle_array_like_without_promotion def tensorflow_to_scalar(x: Union[tensorflow.Tensor, tensorflow.Variable], /): ret = tensorflow_to_numpy(x).item() if x.dtype == tensorflow.bfloat16: @@ -2169,9 +2166,8 @@ def tensorflow_to_scalar(x: Union[tensorflow.Tensor, tensorflow.Variable], /): return ret -@tensorflow_handle_array_like_without_promotion -def tensorflow_to_scalar_bknd(x: Union[tensorflow.Tensor, tf.Tensor], /): - return tensorflow_to_scalar(x) +def tensorflow_to_scalar_bknd_(self: tensorflow.Tensor): + return tensorflow_to_scalar(self) def tensorflow_default_uint_dtype_bknd( @@ -2198,11 +2194,9 @@ 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 @@ -2298,7 +2292,7 @@ def tensorflow_prod( def tensorflow__numel_bknd(shape): shape = tuple(shape) - return tensorflow_to_scalar_bknd(tensorflow_prod(shape)) if shape != () else 1 + return tensorflow_to_scalar_bknd_(tensorflow_prod(shape)) if shape != () else 1 def tensorflow_check_one_way_broadcastable(x1, x2): @@ -2410,7 +2404,9 @@ 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) @@ -2570,11 +2566,9 @@ 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]) diff --git a/ivy/compiler/_cache/Translated_Outputs/tensorflow_permute_dims_output/run_0/tensorflow_permute_dims.py b/ivy/compiler/_cache/Translated_Outputs/tensorflow_permute_dims_output/run_0/tensorflow_permute_dims.py index fb1ae482b707c..a63fc2bea8a23 100644 --- a/ivy/compiler/_cache/Translated_Outputs/tensorflow_permute_dims_output/run_0/tensorflow_permute_dims.py +++ b/ivy/compiler/_cache/Translated_Outputs/tensorflow_permute_dims_output/run_0/tensorflow_permute_dims.py @@ -1,7 +1,7 @@ import tensorflow -from typing import Tuple from typing import Union +from typing import Tuple from typing import Optional from .tensorflow__helpers import tensorflow_handle_array_like_without_promotion diff --git a/ivy/compiler/_cache/Translated_Outputs/tensorflow_relu_output/run_0/tensorflow__helpers.py b/ivy/compiler/_cache/Translated_Outputs/tensorflow_relu_output/run_0/tensorflow__helpers.py index 0380bbe57701b..6136707cf74ef 100644 --- a/ivy/compiler/_cache/Translated_Outputs/tensorflow_relu_output/run_0/tensorflow__helpers.py +++ b/ivy/compiler/_cache/Translated_Outputs/tensorflow_relu_output/run_0/tensorflow__helpers.py @@ -334,7 +334,9 @@ 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 ) @@ -767,21 +769,17 @@ 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 @@ -1193,27 +1191,21 @@ 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 = [ @@ -1638,7 +1630,9 @@ 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) @@ -2050,7 +2044,9 @@ 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 ] @@ -2162,6 +2158,7 @@ def tensorflow_to_numpy( return np.asarray(tensorflow.convert_to_tensor(x)) +@tensorflow_handle_array_like_without_promotion def tensorflow_to_scalar(x: Union[tensorflow.Tensor, tensorflow.Variable], /): ret = tensorflow_to_numpy(x).item() if x.dtype == tensorflow.bfloat16: @@ -2169,9 +2166,8 @@ def tensorflow_to_scalar(x: Union[tensorflow.Tensor, tensorflow.Variable], /): return ret -@tensorflow_handle_array_like_without_promotion -def tensorflow_to_scalar_bknd(x: Union[tensorflow.Tensor, tf.Tensor], /): - return tensorflow_to_scalar(x) +def tensorflow_to_scalar_bknd_(self: tensorflow.Tensor): + return tensorflow_to_scalar(self) def tensorflow_default_uint_dtype_bknd( @@ -2198,11 +2194,9 @@ 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 @@ -2298,7 +2292,7 @@ def tensorflow_prod( def tensorflow__numel_bknd(shape): shape = tuple(shape) - return tensorflow_to_scalar_bknd(tensorflow_prod(shape)) if shape != () else 1 + return tensorflow_to_scalar_bknd_(tensorflow_prod(shape)) if shape != () else 1 def tensorflow_check_one_way_broadcastable(x1, x2): @@ -2410,7 +2404,9 @@ 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) @@ -2570,11 +2566,9 @@ 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]) diff --git a/ivy/compiler/_cache/Translated_Outputs/tensorflow_scatter_nd_output/run_0/tensorflow_NestedSequence_bknd.py b/ivy/compiler/_cache/Translated_Outputs/tensorflow_scatter_nd_output/run_0/tensorflow_NestedSequence_bknd.py index ac8335fe1e56c..9f87b4ae29eff 100644 --- a/ivy/compiler/_cache/Translated_Outputs/tensorflow_scatter_nd_output/run_0/tensorflow_NestedSequence_bknd.py +++ b/ivy/compiler/_cache/Translated_Outputs/tensorflow_scatter_nd_output/run_0/tensorflow_NestedSequence_bknd.py @@ -1,5 +1,5 @@ -from typing import TypeVar from typing import Protocol +from typing import TypeVar _T_co = TypeVar("_T_co", covariant=True) diff --git a/ivy/compiler/_cache/Translated_Outputs/tensorflow_scatter_nd_output/run_0/tensorflow__helpers.py b/ivy/compiler/_cache/Translated_Outputs/tensorflow_scatter_nd_output/run_0/tensorflow__helpers.py index 6f0db9e378d99..9772c84acb367 100644 --- a/ivy/compiler/_cache/Translated_Outputs/tensorflow_scatter_nd_output/run_0/tensorflow__helpers.py +++ b/ivy/compiler/_cache/Translated_Outputs/tensorflow_scatter_nd_output/run_0/tensorflow__helpers.py @@ -310,7 +310,9 @@ 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 ) @@ -798,27 +800,21 @@ 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 = [ @@ -1221,7 +1217,9 @@ 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) @@ -1633,7 +1631,9 @@ 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 ] @@ -1745,6 +1745,7 @@ def tensorflow_to_numpy( return np.asarray(tensorflow.convert_to_tensor(x)) +@tensorflow_handle_array_like_without_promotion def tensorflow_to_scalar(x: Union[tensorflow.Tensor, tensorflow.Variable], /): ret = tensorflow_to_numpy(x).item() if x.dtype == tensorflow.bfloat16: @@ -1752,9 +1753,8 @@ def tensorflow_to_scalar(x: Union[tensorflow.Tensor, tensorflow.Variable], /): return ret -@tensorflow_handle_array_like_without_promotion -def tensorflow_to_scalar_bknd(x: Union[tensorflow.Tensor, tf.Tensor], /): - return tensorflow_to_scalar(x) +def tensorflow_to_scalar_bknd_(self: tensorflow.Tensor): + return tensorflow_to_scalar(self) def tensorflow_is_float_dtype_bknd( @@ -1825,11 +1825,9 @@ 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 @@ -1951,7 +1949,7 @@ def tensorflow_prod( def tensorflow__numel_bknd(shape): shape = tuple(shape) - return tensorflow_to_scalar_bknd(tensorflow_prod(shape)) if shape != () else 1 + return tensorflow_to_scalar_bknd_(tensorflow_prod(shape)) if shape != () else 1 def tensorflow_check_one_way_broadcastable(x1, x2): @@ -2063,7 +2061,9 @@ 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) @@ -2223,11 +2223,9 @@ 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]) @@ -2561,21 +2559,17 @@ 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 diff --git a/ivy/compiler/_cache/Translated_Outputs/tensorflow_scatter_nd_output/run_0/tensorflow_scatter_nd.py b/ivy/compiler/_cache/Translated_Outputs/tensorflow_scatter_nd_output/run_0/tensorflow_scatter_nd.py index c058d9a20f1f5..c2e07983a4f87 100644 --- a/ivy/compiler/_cache/Translated_Outputs/tensorflow_scatter_nd_output/run_0/tensorflow_scatter_nd.py +++ b/ivy/compiler/_cache/Translated_Outputs/tensorflow_scatter_nd_output/run_0/tensorflow_scatter_nd.py @@ -1,8 +1,8 @@ import tensorflow import tensorflow as tf -from typing import Optional from typing import Union +from typing import Optional from typing import Sequence from .tensorflow__helpers import tensorflow__broadcast_to_bknd @@ -29,11 +29,9 @@ 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]) diff --git a/ivy/compiler/_cache/Translated_Outputs/tensorflow_set_item_bknd_output/run_0/tensorflow_NestedSequence_bknd.py b/ivy/compiler/_cache/Translated_Outputs/tensorflow_set_item_bknd_output/run_0/tensorflow_NestedSequence_bknd.py index ac8335fe1e56c..9f87b4ae29eff 100644 --- a/ivy/compiler/_cache/Translated_Outputs/tensorflow_set_item_bknd_output/run_0/tensorflow_NestedSequence_bknd.py +++ b/ivy/compiler/_cache/Translated_Outputs/tensorflow_set_item_bknd_output/run_0/tensorflow_NestedSequence_bknd.py @@ -1,5 +1,5 @@ -from typing import TypeVar from typing import Protocol +from typing import TypeVar _T_co = TypeVar("_T_co", covariant=True) diff --git a/ivy/compiler/_cache/Translated_Outputs/tensorflow_set_item_bknd_output/run_0/tensorflow__helpers.py b/ivy/compiler/_cache/Translated_Outputs/tensorflow_set_item_bknd_output/run_0/tensorflow__helpers.py index d416f6cbf33b5..5c4c3e8534c25 100644 --- a/ivy/compiler/_cache/Translated_Outputs/tensorflow_set_item_bknd_output/run_0/tensorflow__helpers.py +++ b/ivy/compiler/_cache/Translated_Outputs/tensorflow_set_item_bknd_output/run_0/tensorflow__helpers.py @@ -334,7 +334,9 @@ 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 ) @@ -767,21 +769,17 @@ 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 @@ -1169,27 +1167,21 @@ 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 = [ @@ -1614,7 +1606,9 @@ 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) @@ -2026,7 +2020,9 @@ 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 ] @@ -2138,6 +2134,7 @@ def tensorflow_to_numpy( return np.asarray(tensorflow.convert_to_tensor(x)) +@tensorflow_handle_array_like_without_promotion def tensorflow_to_scalar(x: Union[tensorflow.Tensor, tensorflow.Variable], /): ret = tensorflow_to_numpy(x).item() if x.dtype == tensorflow.bfloat16: @@ -2145,9 +2142,8 @@ def tensorflow_to_scalar(x: Union[tensorflow.Tensor, tensorflow.Variable], /): return ret -@tensorflow_handle_array_like_without_promotion -def tensorflow_to_scalar_bknd(x: Union[tensorflow.Tensor, tf.Tensor], /): - return tensorflow_to_scalar(x) +def tensorflow_to_scalar_bknd_(self: tensorflow.Tensor): + return tensorflow_to_scalar(self) def tensorflow_default_uint_dtype_bknd( @@ -2174,11 +2170,9 @@ 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 @@ -2274,7 +2268,7 @@ def tensorflow_prod( def tensorflow__numel_bknd(shape): shape = tuple(shape) - return tensorflow_to_scalar_bknd(tensorflow_prod(shape)) if shape != () else 1 + return tensorflow_to_scalar_bknd_(tensorflow_prod(shape)) if shape != () else 1 def tensorflow_check_one_way_broadcastable(x1, x2): @@ -2386,7 +2380,9 @@ 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) @@ -2550,11 +2546,9 @@ 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]) diff --git a/ivy/compiler/_cache/Translated_Outputs/tensorflow_set_item_bknd_output/run_0/tensorflow_set_item_bknd.py b/ivy/compiler/_cache/Translated_Outputs/tensorflow_set_item_bknd_output/run_0/tensorflow_set_item_bknd.py index f62ba32eed5e6..8135756f5e151 100644 --- a/ivy/compiler/_cache/Translated_Outputs/tensorflow_set_item_bknd_output/run_0/tensorflow_set_item_bknd.py +++ b/ivy/compiler/_cache/Translated_Outputs/tensorflow_set_item_bknd_output/run_0/tensorflow_set_item_bknd.py @@ -2,9 +2,9 @@ import tensorflow as tf import numpy as np -from typing import Union from typing import Optional from typing import Tuple +from typing import Union from .tensorflow__helpers import tensorflow__parse_query_bknd from .tensorflow__helpers import tensorflow_asarray diff --git a/ivy/compiler/_cache/Translated_Outputs/tensorflow_sign_output/run_0/tensorflow_NestedSequence_bknd.py b/ivy/compiler/_cache/Translated_Outputs/tensorflow_sign_output/run_0/tensorflow_NestedSequence_bknd.py index 9f87b4ae29eff..ac8335fe1e56c 100644 --- a/ivy/compiler/_cache/Translated_Outputs/tensorflow_sign_output/run_0/tensorflow_NestedSequence_bknd.py +++ b/ivy/compiler/_cache/Translated_Outputs/tensorflow_sign_output/run_0/tensorflow_NestedSequence_bknd.py @@ -1,5 +1,5 @@ -from typing import Protocol from typing import TypeVar +from typing import Protocol _T_co = TypeVar("_T_co", covariant=True) diff --git a/ivy/compiler/_cache/Translated_Outputs/tensorflow_sign_output/run_0/tensorflow__helpers.py b/ivy/compiler/_cache/Translated_Outputs/tensorflow_sign_output/run_0/tensorflow__helpers.py index 0380bbe57701b..6136707cf74ef 100644 --- a/ivy/compiler/_cache/Translated_Outputs/tensorflow_sign_output/run_0/tensorflow__helpers.py +++ b/ivy/compiler/_cache/Translated_Outputs/tensorflow_sign_output/run_0/tensorflow__helpers.py @@ -334,7 +334,9 @@ 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 ) @@ -767,21 +769,17 @@ 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 @@ -1193,27 +1191,21 @@ 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 = [ @@ -1638,7 +1630,9 @@ 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) @@ -2050,7 +2044,9 @@ 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 ] @@ -2162,6 +2158,7 @@ def tensorflow_to_numpy( return np.asarray(tensorflow.convert_to_tensor(x)) +@tensorflow_handle_array_like_without_promotion def tensorflow_to_scalar(x: Union[tensorflow.Tensor, tensorflow.Variable], /): ret = tensorflow_to_numpy(x).item() if x.dtype == tensorflow.bfloat16: @@ -2169,9 +2166,8 @@ def tensorflow_to_scalar(x: Union[tensorflow.Tensor, tensorflow.Variable], /): return ret -@tensorflow_handle_array_like_without_promotion -def tensorflow_to_scalar_bknd(x: Union[tensorflow.Tensor, tf.Tensor], /): - return tensorflow_to_scalar(x) +def tensorflow_to_scalar_bknd_(self: tensorflow.Tensor): + return tensorflow_to_scalar(self) def tensorflow_default_uint_dtype_bknd( @@ -2198,11 +2194,9 @@ 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 @@ -2298,7 +2292,7 @@ def tensorflow_prod( def tensorflow__numel_bknd(shape): shape = tuple(shape) - return tensorflow_to_scalar_bknd(tensorflow_prod(shape)) if shape != () else 1 + return tensorflow_to_scalar_bknd_(tensorflow_prod(shape)) if shape != () else 1 def tensorflow_check_one_way_broadcastable(x1, x2): @@ -2410,7 +2404,9 @@ 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) @@ -2570,11 +2566,9 @@ 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]) diff --git a/ivy/compiler/_cache/Translated_Outputs/tensorflow_sign_output/run_0/tensorflow_sign.py b/ivy/compiler/_cache/Translated_Outputs/tensorflow_sign_output/run_0/tensorflow_sign.py index b784bd121edad..ed6c78f2c0609 100644 --- a/ivy/compiler/_cache/Translated_Outputs/tensorflow_sign_output/run_0/tensorflow_sign.py +++ b/ivy/compiler/_cache/Translated_Outputs/tensorflow_sign_output/run_0/tensorflow_sign.py @@ -1,7 +1,7 @@ import tensorflow -from typing import Union from typing import Optional +from typing import Union from .tensorflow__helpers import tensorflow_handle_array_like_without_promotion diff --git a/ivy/compiler/_cache/Translated_Outputs/tensorflow_split_output/run_0/tensorflow_NestedSequence_bknd.py b/ivy/compiler/_cache/Translated_Outputs/tensorflow_split_output/run_0/tensorflow_NestedSequence_bknd.py index 9f87b4ae29eff..ac8335fe1e56c 100644 --- a/ivy/compiler/_cache/Translated_Outputs/tensorflow_split_output/run_0/tensorflow_NestedSequence_bknd.py +++ b/ivy/compiler/_cache/Translated_Outputs/tensorflow_split_output/run_0/tensorflow_NestedSequence_bknd.py @@ -1,5 +1,5 @@ -from typing import Protocol from typing import TypeVar +from typing import Protocol _T_co = TypeVar("_T_co", covariant=True) diff --git a/ivy/compiler/_cache/Translated_Outputs/tensorflow_split_output/run_0/tensorflow__helpers.py b/ivy/compiler/_cache/Translated_Outputs/tensorflow_split_output/run_0/tensorflow__helpers.py index 0380bbe57701b..6136707cf74ef 100644 --- a/ivy/compiler/_cache/Translated_Outputs/tensorflow_split_output/run_0/tensorflow__helpers.py +++ b/ivy/compiler/_cache/Translated_Outputs/tensorflow_split_output/run_0/tensorflow__helpers.py @@ -334,7 +334,9 @@ 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 ) @@ -767,21 +769,17 @@ 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 @@ -1193,27 +1191,21 @@ 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 = [ @@ -1638,7 +1630,9 @@ 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) @@ -2050,7 +2044,9 @@ 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 ] @@ -2162,6 +2158,7 @@ def tensorflow_to_numpy( return np.asarray(tensorflow.convert_to_tensor(x)) +@tensorflow_handle_array_like_without_promotion def tensorflow_to_scalar(x: Union[tensorflow.Tensor, tensorflow.Variable], /): ret = tensorflow_to_numpy(x).item() if x.dtype == tensorflow.bfloat16: @@ -2169,9 +2166,8 @@ def tensorflow_to_scalar(x: Union[tensorflow.Tensor, tensorflow.Variable], /): return ret -@tensorflow_handle_array_like_without_promotion -def tensorflow_to_scalar_bknd(x: Union[tensorflow.Tensor, tf.Tensor], /): - return tensorflow_to_scalar(x) +def tensorflow_to_scalar_bknd_(self: tensorflow.Tensor): + return tensorflow_to_scalar(self) def tensorflow_default_uint_dtype_bknd( @@ -2198,11 +2194,9 @@ 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 @@ -2298,7 +2292,7 @@ def tensorflow_prod( def tensorflow__numel_bknd(shape): shape = tuple(shape) - return tensorflow_to_scalar_bknd(tensorflow_prod(shape)) if shape != () else 1 + return tensorflow_to_scalar_bknd_(tensorflow_prod(shape)) if shape != () else 1 def tensorflow_check_one_way_broadcastable(x1, x2): @@ -2410,7 +2404,9 @@ 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) @@ -2570,11 +2566,9 @@ 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]) diff --git a/ivy/compiler/_cache/Translated_Outputs/tensorflow_split_output/run_0/tensorflow_split.py b/ivy/compiler/_cache/Translated_Outputs/tensorflow_split_output/run_0/tensorflow_split.py index ca6de8827c15e..c3fc2be1e1cc8 100644 --- a/ivy/compiler/_cache/Translated_Outputs/tensorflow_split_output/run_0/tensorflow_split.py +++ b/ivy/compiler/_cache/Translated_Outputs/tensorflow_split_output/run_0/tensorflow_split.py @@ -1,8 +1,8 @@ import tensorflow import math -from typing import Union from typing import Optional +from typing import Union from typing import Sequence from .tensorflow__helpers import tensorflow_handle_array_like_without_promotion diff --git a/ivy/compiler/_cache/Translated_Outputs/tensorflow_swapaxes_output/run_0/tensorflow_NestedSequence_bknd.py b/ivy/compiler/_cache/Translated_Outputs/tensorflow_swapaxes_output/run_0/tensorflow_NestedSequence_bknd.py index 9f87b4ae29eff..ac8335fe1e56c 100644 --- a/ivy/compiler/_cache/Translated_Outputs/tensorflow_swapaxes_output/run_0/tensorflow_NestedSequence_bknd.py +++ b/ivy/compiler/_cache/Translated_Outputs/tensorflow_swapaxes_output/run_0/tensorflow_NestedSequence_bknd.py @@ -1,5 +1,5 @@ -from typing import Protocol from typing import TypeVar +from typing import Protocol _T_co = TypeVar("_T_co", covariant=True) diff --git a/ivy/compiler/_cache/Translated_Outputs/tensorflow_swapaxes_output/run_0/tensorflow__helpers.py b/ivy/compiler/_cache/Translated_Outputs/tensorflow_swapaxes_output/run_0/tensorflow__helpers.py index 0380bbe57701b..6136707cf74ef 100644 --- a/ivy/compiler/_cache/Translated_Outputs/tensorflow_swapaxes_output/run_0/tensorflow__helpers.py +++ b/ivy/compiler/_cache/Translated_Outputs/tensorflow_swapaxes_output/run_0/tensorflow__helpers.py @@ -334,7 +334,9 @@ 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 ) @@ -767,21 +769,17 @@ 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 @@ -1193,27 +1191,21 @@ 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 = [ @@ -1638,7 +1630,9 @@ 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) @@ -2050,7 +2044,9 @@ 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 ] @@ -2162,6 +2158,7 @@ def tensorflow_to_numpy( return np.asarray(tensorflow.convert_to_tensor(x)) +@tensorflow_handle_array_like_without_promotion def tensorflow_to_scalar(x: Union[tensorflow.Tensor, tensorflow.Variable], /): ret = tensorflow_to_numpy(x).item() if x.dtype == tensorflow.bfloat16: @@ -2169,9 +2166,8 @@ def tensorflow_to_scalar(x: Union[tensorflow.Tensor, tensorflow.Variable], /): return ret -@tensorflow_handle_array_like_without_promotion -def tensorflow_to_scalar_bknd(x: Union[tensorflow.Tensor, tf.Tensor], /): - return tensorflow_to_scalar(x) +def tensorflow_to_scalar_bknd_(self: tensorflow.Tensor): + return tensorflow_to_scalar(self) def tensorflow_default_uint_dtype_bknd( @@ -2198,11 +2194,9 @@ 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 @@ -2298,7 +2292,7 @@ def tensorflow_prod( def tensorflow__numel_bknd(shape): shape = tuple(shape) - return tensorflow_to_scalar_bknd(tensorflow_prod(shape)) if shape != () else 1 + return tensorflow_to_scalar_bknd_(tensorflow_prod(shape)) if shape != () else 1 def tensorflow_check_one_way_broadcastable(x1, x2): @@ -2410,7 +2404,9 @@ 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) @@ -2570,11 +2566,9 @@ 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]) diff --git a/ivy/compiler/_cache/Translated_Outputs/tensorflow_swapaxes_output/run_0/tensorflow_swapaxes.py b/ivy/compiler/_cache/Translated_Outputs/tensorflow_swapaxes_output/run_0/tensorflow_swapaxes.py index 57f12ef3d0a72..9d273d75721de 100644 --- a/ivy/compiler/_cache/Translated_Outputs/tensorflow_swapaxes_output/run_0/tensorflow_swapaxes.py +++ b/ivy/compiler/_cache/Translated_Outputs/tensorflow_swapaxes_output/run_0/tensorflow_swapaxes.py @@ -1,7 +1,7 @@ import tensorflow -from typing import Union from typing import Optional +from typing import Union from .tensorflow__helpers import tensorflow_handle_array_like_without_promotion diff --git a/ivy/compiler/_cache/Translated_Outputs/tensorflow_to_numpy_output/run_0/tensorflow_NestedSequence_bknd.py b/ivy/compiler/_cache/Translated_Outputs/tensorflow_to_numpy_output/run_0/tensorflow_NestedSequence_bknd.py index 9f87b4ae29eff..ac8335fe1e56c 100644 --- a/ivy/compiler/_cache/Translated_Outputs/tensorflow_to_numpy_output/run_0/tensorflow_NestedSequence_bknd.py +++ b/ivy/compiler/_cache/Translated_Outputs/tensorflow_to_numpy_output/run_0/tensorflow_NestedSequence_bknd.py @@ -1,5 +1,5 @@ -from typing import Protocol from typing import TypeVar +from typing import Protocol _T_co = TypeVar("_T_co", covariant=True) diff --git a/ivy/compiler/_cache/Translated_Outputs/tensorflow_to_numpy_output/run_0/tensorflow__helpers.py b/ivy/compiler/_cache/Translated_Outputs/tensorflow_to_numpy_output/run_0/tensorflow__helpers.py index 0380bbe57701b..6136707cf74ef 100644 --- a/ivy/compiler/_cache/Translated_Outputs/tensorflow_to_numpy_output/run_0/tensorflow__helpers.py +++ b/ivy/compiler/_cache/Translated_Outputs/tensorflow_to_numpy_output/run_0/tensorflow__helpers.py @@ -334,7 +334,9 @@ 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 ) @@ -767,21 +769,17 @@ 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 @@ -1193,27 +1191,21 @@ 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 = [ @@ -1638,7 +1630,9 @@ 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) @@ -2050,7 +2044,9 @@ 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 ] @@ -2162,6 +2158,7 @@ def tensorflow_to_numpy( return np.asarray(tensorflow.convert_to_tensor(x)) +@tensorflow_handle_array_like_without_promotion def tensorflow_to_scalar(x: Union[tensorflow.Tensor, tensorflow.Variable], /): ret = tensorflow_to_numpy(x).item() if x.dtype == tensorflow.bfloat16: @@ -2169,9 +2166,8 @@ def tensorflow_to_scalar(x: Union[tensorflow.Tensor, tensorflow.Variable], /): return ret -@tensorflow_handle_array_like_without_promotion -def tensorflow_to_scalar_bknd(x: Union[tensorflow.Tensor, tf.Tensor], /): - return tensorflow_to_scalar(x) +def tensorflow_to_scalar_bknd_(self: tensorflow.Tensor): + return tensorflow_to_scalar(self) def tensorflow_default_uint_dtype_bknd( @@ -2198,11 +2194,9 @@ 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 @@ -2298,7 +2292,7 @@ def tensorflow_prod( def tensorflow__numel_bknd(shape): shape = tuple(shape) - return tensorflow_to_scalar_bknd(tensorflow_prod(shape)) if shape != () else 1 + return tensorflow_to_scalar_bknd_(tensorflow_prod(shape)) if shape != () else 1 def tensorflow_check_one_way_broadcastable(x1, x2): @@ -2410,7 +2404,9 @@ 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) @@ -2570,11 +2566,9 @@ 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]) diff --git a/ivy/compiler/_cache/Translated_Outputs/tensorflow_to_scalar_output/run_0/tensorflow_NestedSequence_bknd.py b/ivy/compiler/_cache/Translated_Outputs/tensorflow_to_scalar_output/run_0/tensorflow_NestedSequence_bknd.py index ac8335fe1e56c..9f87b4ae29eff 100644 --- a/ivy/compiler/_cache/Translated_Outputs/tensorflow_to_scalar_output/run_0/tensorflow_NestedSequence_bknd.py +++ b/ivy/compiler/_cache/Translated_Outputs/tensorflow_to_scalar_output/run_0/tensorflow_NestedSequence_bknd.py @@ -1,5 +1,5 @@ -from typing import TypeVar from typing import Protocol +from typing import TypeVar _T_co = TypeVar("_T_co", covariant=True) diff --git a/ivy/compiler/_cache/Translated_Outputs/tensorflow_to_scalar_output/run_0/tensorflow__helpers.py b/ivy/compiler/_cache/Translated_Outputs/tensorflow_to_scalar_output/run_0/tensorflow__helpers.py index 0380bbe57701b..6136707cf74ef 100644 --- a/ivy/compiler/_cache/Translated_Outputs/tensorflow_to_scalar_output/run_0/tensorflow__helpers.py +++ b/ivy/compiler/_cache/Translated_Outputs/tensorflow_to_scalar_output/run_0/tensorflow__helpers.py @@ -334,7 +334,9 @@ 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 ) @@ -767,21 +769,17 @@ 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 @@ -1193,27 +1191,21 @@ 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 = [ @@ -1638,7 +1630,9 @@ 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) @@ -2050,7 +2044,9 @@ 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 ] @@ -2162,6 +2158,7 @@ def tensorflow_to_numpy( return np.asarray(tensorflow.convert_to_tensor(x)) +@tensorflow_handle_array_like_without_promotion def tensorflow_to_scalar(x: Union[tensorflow.Tensor, tensorflow.Variable], /): ret = tensorflow_to_numpy(x).item() if x.dtype == tensorflow.bfloat16: @@ -2169,9 +2166,8 @@ def tensorflow_to_scalar(x: Union[tensorflow.Tensor, tensorflow.Variable], /): return ret -@tensorflow_handle_array_like_without_promotion -def tensorflow_to_scalar_bknd(x: Union[tensorflow.Tensor, tf.Tensor], /): - return tensorflow_to_scalar(x) +def tensorflow_to_scalar_bknd_(self: tensorflow.Tensor): + return tensorflow_to_scalar(self) def tensorflow_default_uint_dtype_bknd( @@ -2198,11 +2194,9 @@ 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 @@ -2298,7 +2292,7 @@ def tensorflow_prod( def tensorflow__numel_bknd(shape): shape = tuple(shape) - return tensorflow_to_scalar_bknd(tensorflow_prod(shape)) if shape != () else 1 + return tensorflow_to_scalar_bknd_(tensorflow_prod(shape)) if shape != () else 1 def tensorflow_check_one_way_broadcastable(x1, x2): @@ -2410,7 +2404,9 @@ 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) @@ -2570,11 +2566,9 @@ 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]) diff --git a/ivy/compiler/_cache/Translated_Outputs/tensorflow_zeros_output/run_0/tensorflow__helpers.py b/ivy/compiler/_cache/Translated_Outputs/tensorflow_zeros_output/run_0/tensorflow__helpers.py index 9450383c17498..55e1817c57cb2 100644 --- a/ivy/compiler/_cache/Translated_Outputs/tensorflow_zeros_output/run_0/tensorflow__helpers.py +++ b/ivy/compiler/_cache/Translated_Outputs/tensorflow_zeros_output/run_0/tensorflow__helpers.py @@ -349,7 +349,9 @@ 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 ) @@ -714,27 +716,21 @@ 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 = [ @@ -1159,7 +1155,9 @@ 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) @@ -1556,7 +1554,9 @@ 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 ] @@ -1668,6 +1668,7 @@ def tensorflow_to_numpy( return np.asarray(tensorflow.convert_to_tensor(x)) +@tensorflow_handle_array_like_without_promotion def tensorflow_to_scalar(x: Union[tensorflow.Tensor, tensorflow.Variable], /): ret = tensorflow_to_numpy(x).item() if x.dtype == tensorflow.bfloat16: @@ -1675,9 +1676,8 @@ def tensorflow_to_scalar(x: Union[tensorflow.Tensor, tensorflow.Variable], /): return ret -@tensorflow_handle_array_like_without_promotion -def tensorflow_to_scalar_bknd(x: Union[tensorflow.Tensor, tf.Tensor], /): - return tensorflow_to_scalar(x) +def tensorflow_to_scalar_bknd_(self: tensorflow.Tensor): + return tensorflow_to_scalar(self) def tensorflow_is_float_dtype_bknd( @@ -1748,11 +1748,9 @@ 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 @@ -1874,7 +1872,7 @@ def tensorflow_prod( def tensorflow__numel_bknd(shape): shape = tuple(shape) - return tensorflow_to_scalar_bknd(tensorflow_prod(shape)) if shape != () else 1 + return tensorflow_to_scalar_bknd_(tensorflow_prod(shape)) if shape != () else 1 def tensorflow_check_one_way_broadcastable(x1, x2): @@ -1986,7 +1984,9 @@ 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) @@ -2146,11 +2146,9 @@ 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]) @@ -2497,21 +2495,17 @@ 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 diff --git a/ivy/compiler/_cache/Translated_Outputs/tensorflow_zeros_output/run_0/tensorflow_zeros.py b/ivy/compiler/_cache/Translated_Outputs/tensorflow_zeros_output/run_0/tensorflow_zeros.py index 931f944360e1c..f934d9c905c12 100644 --- a/ivy/compiler/_cache/Translated_Outputs/tensorflow_zeros_output/run_0/tensorflow_zeros.py +++ b/ivy/compiler/_cache/Translated_Outputs/tensorflow_zeros_output/run_0/tensorflow_zeros.py @@ -1,9 +1,9 @@ import tensorflow import tensorflow as tf +from typing import Union from typing import Sequence from typing import Optional -from typing import Union from .tensorflow__helpers import tensorflow_handle_array_like_without_promotion from .tensorflow__helpers import tensorflow_infer_dtype diff --git a/ivy/compiler/_cache/ivy_to_tensorflow_translation_cache.pkl b/ivy/compiler/_cache/ivy_to_tensorflow_translation_cache.pkl index 4803831d7b3d9..f37b6e3b41dcc 100644 --- a/ivy/compiler/_cache/ivy_to_tensorflow_translation_cache.pkl +++ b/ivy/compiler/_cache/ivy_to_tensorflow_translation_cache.pkl @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:870d6ed02d1595a167aca21498cac849722fac3d6f109fa8cee3656239088aa9 -size 134141161 +oid sha256:042183ae30836c076ea0a4e8c3f1e13e8968f316542888ae7142b969572e83de +size 133939339 diff --git a/ivy/compiler/_cache/torch_frontend_to_ivy_translation_cache.pkl b/ivy/compiler/_cache/torch_frontend_to_ivy_translation_cache.pkl index 7568c8ed78c8a..01802ee2f6595 100644 --- a/ivy/compiler/_cache/torch_frontend_to_ivy_translation_cache.pkl +++ b/ivy/compiler/_cache/torch_frontend_to_ivy_translation_cache.pkl @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:f0938ae79d2a17e2906de520774aebca544ad8bc3fc3847550dfc0fc71c064a3 -size 2566626 +oid sha256:221efae159f0dce339b58498d8d949fa1881a7c21316a051ac43779829425764 +size 2560194 diff --git a/ivy/compiler/_cache/torch_to_torch_frontend_translation_cache.pkl b/ivy/compiler/_cache/torch_to_torch_frontend_translation_cache.pkl index 4135428f97de8..19efd19c880c4 100644 --- a/ivy/compiler/_cache/torch_to_torch_frontend_translation_cache.pkl +++ b/ivy/compiler/_cache/torch_to_torch_frontend_translation_cache.pkl @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:7c0e8da7ea3a9ab0fb0cfc9daea466472ab36515b6f4c7fe07e1931a0816ee48 -size 1105896 +oid sha256:ad0d2dac403be29dffaafe641dacd4a2a508c5d7fd428a9886e5f6c497180a21 +size 1138347