prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  🐛 [Bug] Bug in `aten.where` converter for Numpy array inputs
  ##  Bug Description
  - When applying converter to Numpy arrays or constants, the compilation fails due to use of the `expand` operator, which only applies to Torch tensors
  
  
  </issue>
  <code>
  [start of py/torch_tensorrt/dynamo/conversion/impl/condition/ops.py]
  1 from typing import Optional
  2 
  3 import numpy as np
  4 import tensorrt as trt
  5 import torch
  6 from torch.fx.node import Target
  7 from torch_tensorrt.dynamo._SourceIR import SourceIR
  8 from torch_tensorrt.dynamo.conversion._ConversionContext import ConversionContext
  9 from torch_tensorrt.dynamo.conversion.converter_utils import (
  10     broadcastable,
  11     get_trt_tensor,
  12 )
  13 from torch_tensorrt.dynamo.conversion.impl.slice import expand
  14 from torch_tensorrt.fx.converters.converter_utils import broadcast, set_layer_name
  15 from torch_tensorrt.fx.types import TRTTensor
  16 
  17 
  18 def where(
  19     ctx: ConversionContext,
  20     target: Target,
  21     source_ir: Optional[SourceIR],
  22     name: str,
  23     input: TRTTensor,
  24     other: TRTTensor,
  25     condition: TRTTensor,
  26 ) -> TRTTensor:
  27     if not (broadcastable(input, other)):
  28         assert "The two torch tensors should be broadcastable"
  29 
  30     # get output shape
  31     # purpose of this is to bring input and other rank same as
  32     # output_shape to input it to the add_expand operation
  33     # condition will have dimension of either input or other
  34     input, other = broadcast(ctx.net, input, other, f"{name}_x", f"{name}_y")
  35     if len(tuple(condition.shape)) != len(tuple(input.shape)):
  36         condition, input = broadcast(
  37             ctx.net, condition, input, f"{name}_condition", f"{name}_x"
  38         )
  39 
  40     x_shape = list(input.shape)
  41     y_shape = list(other.shape)
  42     condition_shape = list(condition.shape)
  43 
  44     output_shape = list(torch.broadcast_shapes(condition_shape, x_shape, y_shape))
  45 
  46     # expand shape
  47     if not isinstance(condition, TRTTensor):
  48         assert condition.dtype in (torch.bool, np.bool_), "condition dtype is not bool"
  49         if condition_shape != output_shape:
  50             condition = (
  51                 condition.expand(output_shape)
  52                 if isinstance(condition, torch.Tensor)
  53                 else np.broadcast_to(condition, output_shape)
  54             )
  55         condition_val = get_trt_tensor(ctx, condition, f"{name}_condition")
  56     else:
  57         assert condition.dtype == trt.bool, "mask dtype is not bool!"
  58         if condition_shape != output_shape:
  59             condition_val = expand(
  60                 ctx, target, source_ir, f"{name}_expand", condition, output_shape
  61             )
  62         else:
  63             condition_val = condition
  64 
  65     if not isinstance(input, TRTTensor):
  66         if x_shape != output_shape:
  67             # special case where 1 element in input
  68             if len(input.shape) == 0:
  69                 input = (
  70                     input.unsqueeze(0)
  71                     if isinstance(input, torch.Tensor)
  72                     else np.expand_dims(input, axis=0)
  73                 )
  74             input = input.expand(output_shape)
  75         x_val = get_trt_tensor(ctx, input, f"{name}_x")
  76     else:
  77         x_val = input
  78         if x_shape != output_shape:
  79             x_val = expand(
  80                 ctx, target, source_ir, f"{name}_x_expand", input, output_shape
  81             )
  82 
  83     if not isinstance(other, TRTTensor):
  84         if y_shape != output_shape:
  85             # special case where 1 element in other
  86             if len(other.shape) == 0:
  87                 other = (
  88                     other.unsqueeze(0)
  89                     if isinstance(other, torch.Tensor)
  90                     else np.expand_dims(other, axis=0)
  91                 )
  92             other = other.expand(output_shape)
  93         y_val = get_trt_tensor(ctx, other, f"{name}_y")
  94     else:
  95         y_val = other
  96         if y_shape != output_shape:
  97             y_val = expand(
  98                 ctx, target, source_ir, f"{name}_y_expand", y_val, output_shape
  99             )
  100 
  101     select_layer = ctx.net.add_select(condition_val, x_val, y_val)
  102 
  103     set_layer_name(select_layer, target, f"{name}_select")
  104 
  105     return select_layer.get_output(0)
  106
  [end of py/torch_tensorrt/dynamo/conversion/impl/condition/ops.py]
  </code>
  
  I need you to solve this issue by generating a single patch file that I can apply directly to this repository using git apply. Please respond with a single patch file in the following format.
  <patch>
  diff --git a/file.py b/file.py
  --- a/file.py
  +++ b/file.py
  @@ -1,27 +1,35 @@
   def euclidean(a, b):
  -    while b:
  -        a, b = b, a % b
  -    return a
  +    if b == 0:
  +        return a
  +    return euclidean(b, a % b)
   
   
   def bresenham(x0, y0, x1, y1):
       points = []
       dx = abs(x1 - x0)
       dy = abs(y1 - y0)
  -    sx = 1 if x0 < x1 else -1
  -    sy = 1 if y0 < y1 else -1
  -    err = dx - dy
  +    x, y = x0, y0
  +    sx = -1 if x0 > x1 else 1
  +    sy = -1 if y0 > y1 else 1
   
  -    while True:
  -        points.append((x0, y0))
  -        if x0 == x1 and y0 == y1:
  -            break
  -        e2 = 2 * err
  -        if e2 > -dy:
  -            err -= dy
  -            x0 += sx
  -        if e2 < dx:
  -            err += dx
  -            y0 += sy
  +    if dx > dy:
  +        err = dx / 2.0
  +        while x != x1:
  +            points.append((x, y))
  +            err -= dy
  +            if err < 0:
  +                y += sy
  +                err += dx
  +            x += sx
  +    else:
  +        err = dy / 2.0
  +        while y != y1:
  +            points.append((x, y))
  +            err -= dx
  +            if err < 0:
  +                x += sx
  +                err += dy
  +            y += sy
  +
  +    points.append((x, y))
       return points
  
  </patch>
golden_diff: diff --git a/py/torch_tensorrt/dynamo/conversion/impl/condition/ops.py b/py/torch_tensorrt/dynamo/conversion/impl/condition/ops.py
  --- a/py/torch_tensorrt/dynamo/conversion/impl/condition/ops.py
  +++ b/py/torch_tensorrt/dynamo/conversion/impl/condition/ops.py
  @@ -1,4 +1,4 @@
  -from typing import Optional
  +from typing import Optional, Union
   
   import numpy as np
   import tensorrt as trt
  @@ -11,7 +11,7 @@
       get_trt_tensor,
   )
   from torch_tensorrt.dynamo.conversion.impl.slice import expand
  -from torch_tensorrt.fx.converters.converter_utils import broadcast, set_layer_name
  +from torch_tensorrt.fx.converters.converter_utils import set_layer_name
   from torch_tensorrt.fx.types import TRTTensor
   
   
  @@ -20,23 +20,13 @@
       target: Target,
       source_ir: Optional[SourceIR],
       name: str,
  -    input: TRTTensor,
  -    other: TRTTensor,
  -    condition: TRTTensor,
  +    input: Union[TRTTensor, np.ndarray, torch.Tensor],
  +    other: Union[TRTTensor, np.ndarray, torch.Tensor],
  +    condition: Union[TRTTensor, np.ndarray, torch.Tensor],
   ) -> TRTTensor:
       if not (broadcastable(input, other)):
           assert "The two torch tensors should be broadcastable"
   
  -    # get output shape
  -    # purpose of this is to bring input and other rank same as
  -    # output_shape to input it to the add_expand operation
  -    # condition will have dimension of either input or other
  -    input, other = broadcast(ctx.net, input, other, f"{name}_x", f"{name}_y")
  -    if len(tuple(condition.shape)) != len(tuple(input.shape)):
  -        condition, input = broadcast(
  -            ctx.net, condition, input, f"{name}_condition", f"{name}_x"
  -        )
  -
       x_shape = list(input.shape)
       y_shape = list(other.shape)
       condition_shape = list(condition.shape)
  @@ -71,7 +61,11 @@
                       if isinstance(input, torch.Tensor)
                       else np.expand_dims(input, axis=0)
                   )
  -            input = input.expand(output_shape)
  +            input = (
  +                input.expand(output_shape)
  +                if isinstance(input, torch.Tensor)
  +                else np.broadcast_to(input, output_shape)
  +            )
           x_val = get_trt_tensor(ctx, input, f"{name}_x")
       else:
           x_val = input
  @@ -89,7 +83,11 @@
                       if isinstance(other, torch.Tensor)
                       else np.expand_dims(other, axis=0)
                   )
  -            other = other.expand(output_shape)
  +            other = (
  +                other.expand(output_shape)
  +                if isinstance(other, torch.Tensor)
  +                else np.broadcast_to(other, output_shape)
  +            )
           y_val = get_trt_tensor(ctx, other, f"{name}_y")
       else:
           y_val = other
  
verification_info: {"golden_diff": "diff --git a/py/torch_tensorrt/dynamo/conversion/impl/condition/ops.py b/py/torch_tensorrt/dynamo/conversion/impl/condition/ops.py\n--- a/py/torch_tensorrt/dynamo/conversion/impl/condition/ops.py\n+++ b/py/torch_tensorrt/dynamo/conversion/impl/condition/ops.py\n@@ -1,4 +1,4 @@\n-from typing import Optional\n+from typing import Optional, Union\n \n import numpy as np\n import tensorrt as trt\n@@ -11,7 +11,7 @@\n     get_trt_tensor,\n )\n from torch_tensorrt.dynamo.conversion.impl.slice import expand\n-from torch_tensorrt.fx.converters.converter_utils import broadcast, set_layer_name\n+from torch_tensorrt.fx.converters.converter_utils import set_layer_name\n from torch_tensorrt.fx.types import TRTTensor\n \n \n@@ -20,23 +20,13 @@\n     target: Target,\n     source_ir: Optional[SourceIR],\n     name: str,\n-    input: TRTTensor,\n-    other: TRTTensor,\n-    condition: TRTTensor,\n+    input: Union[TRTTensor, np.ndarray, torch.Tensor],\n+    other: Union[TRTTensor, np.ndarray, torch.Tensor],\n+    condition: Union[TRTTensor, np.ndarray, torch.Tensor],\n ) -> TRTTensor:\n     if not (broadcastable(input, other)):\n         assert \"The two torch tensors should be broadcastable\"\n \n-    # get output shape\n-    # purpose of this is to bring input and other rank same as\n-    # output_shape to input it to the add_expand operation\n-    # condition will have dimension of either input or other\n-    input, other = broadcast(ctx.net, input, other, f\"{name}_x\", f\"{name}_y\")\n-    if len(tuple(condition.shape)) != len(tuple(input.shape)):\n-        condition, input = broadcast(\n-            ctx.net, condition, input, f\"{name}_condition\", f\"{name}_x\"\n-        )\n-\n     x_shape = list(input.shape)\n     y_shape = list(other.shape)\n     condition_shape = list(condition.shape)\n@@ -71,7 +61,11 @@\n                     if isinstance(input, torch.Tensor)\n                     else np.expand_dims(input, axis=0)\n                 )\n-            input = input.expand(output_shape)\n+            input = (\n+                input.expand(output_shape)\n+                if isinstance(input, torch.Tensor)\n+                else np.broadcast_to(input, output_shape)\n+            )\n         x_val = get_trt_tensor(ctx, input, f\"{name}_x\")\n     else:\n         x_val = input\n@@ -89,7 +83,11 @@\n                     if isinstance(other, torch.Tensor)\n                     else np.expand_dims(other, axis=0)\n                 )\n-            other = other.expand(output_shape)\n+            other = (\n+                other.expand(output_shape)\n+                if isinstance(other, torch.Tensor)\n+                else np.broadcast_to(other, output_shape)\n+            )\n         y_val = get_trt_tensor(ctx, other, f\"{name}_y\")\n     else:\n         y_val = other\n", "issue": "\ud83d\udc1b [Bug] Bug in `aten.where` converter for Numpy array inputs\n##  Bug Description\r\n- When applying converter to Numpy arrays or constants, the compilation fails due to use of the `expand` operator, which only applies to Torch tensors\r\n\n", "before_files": [{"content": "from typing import Optional\n\nimport numpy as np\nimport tensorrt as trt\nimport torch\nfrom torch.fx.node import Target\nfrom torch_tensorrt.dynamo._SourceIR import SourceIR\nfrom torch_tensorrt.dynamo.conversion._ConversionContext import ConversionContext\nfrom torch_tensorrt.dynamo.conversion.converter_utils import (\n    broadcastable,\n    get_trt_tensor,\n)\nfrom torch_tensorrt.dynamo.conversion.impl.slice import expand\nfrom torch_tensorrt.fx.converters.converter_utils import broadcast, set_layer_name\nfrom torch_tensorrt.fx.types import TRTTensor\n\n\ndef where(\n    ctx: ConversionContext,\n    target: Target,\n    source_ir: Optional[SourceIR],\n    name: str,\n    input: TRTTensor,\n    other: TRTTensor,\n    condition: TRTTensor,\n) -> TRTTensor:\n    if not (broadcastable(input, other)):\n        assert \"The two torch tensors should be broadcastable\"\n\n    # get output shape\n    # purpose of this is to bring input and other rank same as\n    # output_shape to input it to the add_expand operation\n    # condition will have dimension of either input or other\n    input, other = broadcast(ctx.net, input, other, f\"{name}_x\", f\"{name}_y\")\n    if len(tuple(condition.shape)) != len(tuple(input.shape)):\n        condition, input = broadcast(\n            ctx.net, condition, input, f\"{name}_condition\", f\"{name}_x\"\n        )\n\n    x_shape = list(input.shape)\n    y_shape = list(other.shape)\n    condition_shape = list(condition.shape)\n\n    output_shape = list(torch.broadcast_shapes(condition_shape, x_shape, y_shape))\n\n    # expand shape\n    if not isinstance(condition, TRTTensor):\n        assert condition.dtype in (torch.bool, np.bool_), \"condition dtype is not bool\"\n        if condition_shape != output_shape:\n            condition = (\n                condition.expand(output_shape)\n                if isinstance(condition, torch.Tensor)\n                else np.broadcast_to(condition, output_shape)\n            )\n        condition_val = get_trt_tensor(ctx, condition, f\"{name}_condition\")\n    else:\n        assert condition.dtype == trt.bool, \"mask dtype is not bool!\"\n        if condition_shape != output_shape:\n            condition_val = expand(\n                ctx, target, source_ir, f\"{name}_expand\", condition, output_shape\n            )\n        else:\n            condition_val = condition\n\n    if not isinstance(input, TRTTensor):\n        if x_shape != output_shape:\n            # special case where 1 element in input\n            if len(input.shape) == 0:\n                input = (\n                    input.unsqueeze(0)\n                    if isinstance(input, torch.Tensor)\n                    else np.expand_dims(input, axis=0)\n                )\n            input = input.expand(output_shape)\n        x_val = get_trt_tensor(ctx, input, f\"{name}_x\")\n    else:\n        x_val = input\n        if x_shape != output_shape:\n            x_val = expand(\n                ctx, target, source_ir, f\"{name}_x_expand\", input, output_shape\n            )\n\n    if not isinstance(other, TRTTensor):\n        if y_shape != output_shape:\n            # special case where 1 element in other\n            if len(other.shape) == 0:\n                other = (\n                    other.unsqueeze(0)\n                    if isinstance(other, torch.Tensor)\n                    else np.expand_dims(other, axis=0)\n                )\n            other = other.expand(output_shape)\n        y_val = get_trt_tensor(ctx, other, f\"{name}_y\")\n    else:\n        y_val = other\n        if y_shape != output_shape:\n            y_val = expand(\n                ctx, target, source_ir, f\"{name}_y_expand\", y_val, output_shape\n            )\n\n    select_layer = ctx.net.add_select(condition_val, x_val, y_val)\n\n    set_layer_name(select_layer, target, f\"{name}_select\")\n\n    return select_layer.get_output(0)\n", "path": "py/torch_tensorrt/dynamo/conversion/impl/condition/ops.py"}]}