code: def iterate_residual_field_ssd_3d(
      delta_field, sigmasq_field, grad, target, lambda_param, dfield
  ):
      r"""
      This implementation is for testing purposes only. The problem
      with Gauss-Seidel iterations is that it depends on the order
      in which we iterate over the variables, so it is necessary to
      replicate the implementation under test.
      """
      nslices, nrows, ncols = delta_field.shape
      if target is None:
          b = np.zeros_like(grad)
          for i in range(3):
              b[..., i] = delta_field * grad[..., i]
      else:
          b = target
  
      y = np.ndarray((3,))
      for s in range(nslices):
          for r in range(nrows):
              for c in range(ncols):
                  g = grad[s, r, c]
                  # delta = delta_field[s, r, c]
                  sigmasq = (
                      sigmasq_field[s, r, c]
                      if sigmasq_field is not None
                      else 1
                  )
                  nn = 0
                  y[:] = 0
                  for dSlice, dRow, dCol in [
                      (-1, 0, 0),
                      (0, -1, 0),
                      (0, 0, 1),
                      (0, 1, 0),
                      (0, 0, -1),
                      (1, 0, 0),
                  ]:
                      ds = s + dSlice
                      if ds < 0 or ds >= nslices:
                          continue
                      dr = r + dRow
                      if dr < 0 or dr >= nrows:
                          continue
                      dc = c + dCol
                      if dc < 0 or dc >= ncols:
                          continue
                      nn += 1
                      y += dfield[ds, dr, dc]
                  if np.isinf(sigmasq):
                      dfield[s, r, c] = y / nn
                  elif sigmasq < 1e-9:
                      nrm2 = np.sum(g**2)
                      if nrm2 < 1e-9:
                          dfield[s, r, c, :] = 0
                      else:
                          dfield[s, r, c, :] = b[s, r, c] / nrm2
                  else:
                      tau = sigmasq * lambda_param * nn
                      y = b[s, r, c] + sigmasq * lambda_param * y
                      G = np.outer(g, g) + tau * np.eye(3)
                      try:
                          dfield[s, r, c] = np.linalg.solve(G, y)
                      except np.linalg.linalg.LinAlgError:
                          nrm2 = np.sum(g**2)
                          if nrm2 < 1e-9:
                              dfield[s, r, c, :] = 0
                          else:
                              dfield[s, r, c] = b[s, r, c] / nrm2
  
file_path: dipy/dipy/align/tests/test_sumsqdiff.py
imports: import numpy
  from dipy.align import floating
  from dipy.align import sumsqdiff
  from numpy.testing import assert_equal, assert_almost_equal, assert_array_almost_equal, assert_allclose
  from dipy.testing.decorators import set_random_number_generator
label_desc: Use image node_id 2 for calling a global function with example usage: iterate_residual_field_ssd_3d(delta_field, sigmasq_field, grad, target, lambda_param, dfield) without return types