code: def convolve(A, B, axes=None, dot_axes=[(), ()], mode="full"):
      assert mode in [
          "valid",
          "full",
      ], "Mode {0} not yet implemented".format(mode)
      if axes is None:
          axes = [list(range(A.ndim)), list(range(A.ndim))]
      wrong_order = any(
          [B.shape[ax_B] < A.shape[ax_A] for ax_A, ax_B in zip(*axes)]
      )
      if wrong_order:
          if mode == "valid" and not all(
              [
                  B.shape[ax_B] <= A.shape[ax_A]
                  for ax_A, ax_B in zip(*axes)
              ]
          ):
              raise Exception(
                  "One array must be larger than the other along all convolved dimensions"
              )
          elif mode != "full" or B.size <= A.size:  # Tie breaker
              i1 = B.ndim - len(dot_axes[1]) - len(axes[1])  # B ignore
              i2 = (
                  i1 + A.ndim - len(dot_axes[0]) - len(axes[0])
              )  # A ignore
              i3 = i2 + len(axes[0])
              ignore_B = list(range(i1))
              ignore_A = list(range(i1, i2))
              conv = list(range(i2, i3))
              return convolve(
                  B,
                  A,
                  axes=axes[::-1],
                  dot_axes=dot_axes[::-1],
                  mode=mode,
              ).transpose(ignore_A + ignore_B + conv)
  
      if mode == "full":
          B = pad_to_full(B, A, axes[::-1])
      B_view_shape = list(B.shape)
      B_view_strides = list(B.strides)
      flipped_idxs = [slice(None)] * A.ndim
      for ax_A, ax_B in zip(*axes):
          B_view_shape.append(abs(B.shape[ax_B] - A.shape[ax_A]) + 1)
          B_view_strides.append(B.strides[ax_B])
          B_view_shape[ax_B] = A.shape[ax_A]
          flipped_idxs[ax_A] = slice(None, None, -1)
      B_view = as_strided(B, B_view_shape, B_view_strides)
      A_view = A[tuple(flipped_idxs)]
      all_axes = [list(axes[i]) + list(dot_axes[i]) for i in [0, 1]]
      return einsum_tensordot(A_view, B_view, all_axes)
  
file_path: autograd/autograd/scipy/signal.py
imports: from __future__ import absolute_import
  from builtins import range, zip
  from functools import partial
  import autograd.numpy
  import numpy
  from autograd.extend import primitive, defvjp
  from numpy.lib.stride_tricks import as_strided
  from six import iteritems
label_desc: Use image node_id 1 for calling a global function with example usage: convolve(A, B, axes, dot_axes, mode) and returns: einsum_tensordot, convolve