code: def expand_empty(tensor_var, size):
      """
      Transforms the shape of a tensor from (d1, d2 ... ) to ( d1+size, d2, ..)
      by adding uninitialized memory at the end of the tensor.
  
      """
  
      if size == 0:
          return tensor_var
      shapes = [tensor_var.shape[x] for x in range(tensor_var.ndim)]
      new_shape = [size + shapes[0]] + shapes[1:]
      empty = AllocEmpty(tensor_var.dtype)(*new_shape)
  
      ret = set_subtensor(empty[: shapes[0]], tensor_var)
      ret.tag.nan_guard_mode_check = False
      return ret
  
imports: import copy
  import dataclasses
  import logging
  from collections import OrderedDict, namedtuple
  from collections.abc import Sequence
  from itertools import chain
  from typing import TYPE_CHECKING, Callable, Optional, Union
  from typing import cast
  import numpy
  from pytensor import scalar
  from pytensor import tensor
  from pytensor.compile.profiling import ProfileStats
  from pytensor.configdefaults import config
  from pytensor.graph.basic import Constant, Variable, equal_computations, graph_inputs
  from pytensor.graph.op import get_test_value
  from pytensor.graph.replace import clone_replace
  from pytensor.graph.type import HasDataType
  from pytensor.graph.utils import TestValueError
  from pytensor.tensor.basic import AllocEmpty, cast
  from pytensor.tensor.subtensor import set_subtensor
  from pytensor.tensor.variable import TensorConstant
label_desc: Use image node_id 3 for calling a global function with example usage: expand_empty(tensor_var, size) and returns: ret, tensor_var