code: def expand_packed_triangular(
      n, packed, lower=True, diagonal_only=False
  ):
      r"""Convert a packed triangular matrix into a two dimensional array.
  
      Triangular matrices can be stored with better space efficiency by
      storing the non-zero values in a one-dimensional array. We number
      the elements by row like this (for lower or upper triangular matrices):
  
          [[0 - - -]     [[0 1 2 3]
           [1 2 - -]      [- 4 5 6]
           [3 4 5 -]      [- - 7 8]
           [6 7 8 9]]     [- - - 9]
  
      Parameters
      ----------
      n: int
          The number of rows of the triangular matrix.
      packed: pytensor.vector
          The matrix in packed format.
      lower: bool, default=True
          If true, assume that the matrix is lower triangular.
      diagonal_only: bool
          If true, return only the diagonal of the matrix.
      """
      if packed.ndim != 1:
          raise ValueError("Packed triangular is not one dimensional.")
      if not isinstance(n, int):
          raise TypeError("n must be an integer")
  
      if diagonal_only and lower:
          diag_idxs = np.arange(1, n + 1).cumsum() - 1
          return packed[diag_idxs]
      elif diagonal_only and not lower:
          diag_idxs = np.arange(2, n + 2)[::-1].cumsum() - n - 1
          return packed[diag_idxs]
      elif lower:
          out = pt.zeros((n, n), dtype=pytensor.config.floatX)
          idxs = np.tril_indices(n)
          # tag as lower triangular to enable pytensor rewrites
          out = pt.set_subtensor(out[idxs], packed)
          out.tag.lower_triangular = True
          return out
      elif not lower:
          out = pt.zeros((n, n), dtype=pytensor.config.floatX)
          idxs = np.triu_indices(n)
          # tag as upper triangular to enable pytensor rewrites
          out = pt.set_subtensor(out[idxs], packed)
          out.tag.upper_triangular = True
          return out
  
imports: import sys
  import warnings
  from functools import partial, reduce
  import numpy
  import pytensor
  import pytensor.sparse
  import pytensor.tensor
  import pytensor.tensor.slinalg
  import scipy
  import scipy.sparse
  from pytensor.graph.basic import Apply
  from pytensor.graph.op import Op
  from pytensor.tensor import abs, and_, arccos, arccosh, arcsin, arcsinh, arctan, arctanh, broadcast_to, ceil, clip, concatenate, constant, cos, cosh, cumprod, cumsum, dot, eq, erf, erfc, erfcinv, erfinv, exp, flatten, floor, full, full_like, ge, gt, le, log, log1pexp, logaddexp, logsumexp, lt, matmul, max, maximum, mean, min, minimum, neq, ones, ones_like, or_, prod, sgn, sigmoid, sin, sinh, sqr, sqrt, stack, sum, switch, tan, tanh, where, zeros, zeros_like
  from pytensor.tensor.linalg import solve_triangular
  from pytensor.tensor.nlinalg import matrix_inverse
  from pytensor.tensor.special import log_softmax, softmax
  from scipy.linalg import block_diag
  from pymc.pytensorf import floatX, ix_, largest_common_dtype
label_desc: Use image node_id 17 for calling a global function with example usage: expand_packed_triangular(n, packed, lower, diagonal_only) and returns: packed, packed, out, out