11#
22# Copyright 2023 Martin Pavella
3- # Copyright 2023-2024 NXP
3+ # Copyright 2023-2025 NXP
44#
55# License: MIT
66# See the LICENSE_MIT for more details.
1212'conversion/builtin/' directory.
1313"""
1414
15- from typing import Any , List , MutableSequence , Optional
15+ from typing import List , MutableSequence , Optional
1616
1717import executorch .backends .nxp .backend .ir .logger as logger
1818from executorch .backends .nxp .backend .ir .tflite_generator import tflite_model
2222 max_pool_2d_options ,
2323 transpose_conv_options ,
2424)
25- from torch .fx import Node
26-
27-
28- def exactly_one_is_none (obj1 : Optional , obj2 : Optional ) -> bool :
29- """Determine if exactly 1 of the arguments is None, or not."""
30- return (obj1 is None and obj2 is not None ) or (obj1 is not None and obj2 is None )
31-
32-
33- def contains_duplicates (list_to_check : List [Any ]) -> bool :
34- """Determine if given list has duplicate elements or not."""
35- return len (list_to_check ) != len (set (list_to_check ))
36-
37-
38- def clamp (val : int , start : int , end : int ) -> int :
39- """Clamp an int value between start and end (inclusive) and return it."""
40- if val < start :
41- return start
42-
43- elif val > end :
44- return end
4525
46- return val
26+ from torch . fx import Node
4727
4828
4929def try_get_input (t_op : tflite_model .Operator , idx : int ) -> tflite_model .Tensor | None :
@@ -62,11 +42,6 @@ def try_get_input(t_op: tflite_model.Operator, idx: int) -> tflite_model.Tensor
6242
6343 tensor = t_op .tmp_inputs [idx ]
6444
65- if tensor .name == "" :
66- # ONNX allows the name "" for optional tensors. It indicates that the tensor should be ignored, and a default
67- # value should be used. Just like if the tensor was omitted altogether.
68- return None
69-
7045 return tensor
7146
7247
@@ -188,32 +163,6 @@ def node_uses_shape_broadcasting(node: Node) -> bool:
188163 )
189164
190165
191- def uses_multiple_input_types (t_op : tflite_model .Operator ) -> bool :
192- """Determine if the input tensors of given TFLite operator use different data types or not.
193-
194- :param t_op: TFLite operator with 'tmp_inputs' initialized.
195- :return: True, if any two input tensors have a different data type.
196- False, if all input tensors use the same data type.
197- """
198-
199- if t_op .tmp_inputs is None :
200- logger .e (
201- logger .Code .INTERNAL_ERROR ,
202- "common.uses_multiple_input_types(): 'tmp_inputs' are None!" ,
203- )
204-
205- if len (t_op .tmp_inputs ) == 0 :
206- logger .e (
207- logger .Code .INTERNAL_ERROR ,
208- "common.uses_multiple_input_types(): Operator has no inputs!" ,
209- )
210-
211- first_input_type = t_op .tmp_inputs [0 ].type
212- return any (
213- input_tensor .type != first_input_type for input_tensor in t_op .tmp_inputs [1 :]
214- )
215-
216-
217166class OpsList :
218167 """
219168 Holder of TFLite operator (middle_op) that can be prefixed (pre_ops) of suffixed (post_ops)
0 commit comments