code: def _convolve_nd(
      in1: Array, in2: Array, mode: str, *, precision: PrecisionLike
  ) -> Array:
      if mode not in ["full", "same", "valid"]:
          raise ValueError(
              "mode must be one of ['full', 'same', 'valid']"
          )
      if in1.ndim != in2.ndim:
          raise ValueError(
              "in1 and in2 must have the same number of dimensions"
          )
      if in1.size == 0 or in2.size == 0:
          raise ValueError(
              f"zero-size arrays not supported in convolutions, got shapes {in1.shape} and {in2.shape}."
          )
      in1, in2 = promote_dtypes_inexact(in1, in2)
  
      no_swap = all(s1 >= s2 for s1, s2 in zip(in1.shape, in2.shape))
      swap = all(s1 <= s2 for s1, s2 in zip(in1.shape, in2.shape))
      if not (no_swap or swap):
          raise ValueError(
              "One input must be smaller than the other in every dimension."
          )
  
      shape_o = in2.shape
      if swap:
          in1, in2 = in2, in1
      shape = in2.shape
      in2 = jnp.flip(in2)
  
      if mode == "valid":
          padding = [(0, 0) for s in shape]
      elif mode == "same":
          padding = [
              (s - 1 - (s_o - 1) // 2, s - s_o + (s_o - 1) // 2)
              for (s, s_o) in zip(shape, shape_o)
          ]
      elif mode == "full":
          padding = [(s - 1, s - 1) for s in shape]
  
      strides = tuple(1 for s in shape)
      result = lax.conv_general_dilated(
          in1[None, None],
          in2[None, None],
          strides,
          padding,
          precision=precision,
      )
      return result[0, 0]
  
imports: from __future__ import annotations
  from collections.abc import Sequence
  from functools import partial
  import math
  import operator
  from typing import Callable
  import warnings
  import numpy
  import scipy.signal
  from scipy.fft import next_fast_len
  import jax
  import jax.numpy.fft
  import jax.numpy
  from jax import lax
  from jax._src.api_util import _ensure_index_tuple
  from jax._src import dtypes
  from jax._src.lax.lax import PrecisionLike
  from jax._src.numpy import linalg
  from jax._src.numpy.util import check_arraylike, _wraps, promote_dtypes_inexact, promote_dtypes_complex
  from jax._src.third_party.scipy import signal_helper
  from jax._src.typing import Array, ArrayLike
  from jax._src.util import canonicalize_axis, tuple_delete, tuple_insert
label_desc: Use image node_id 3 for calling a global function with example usage: _convolve_nd(in1, in2, mode) and returns: result