code: def iterate_residual_field_ssd_2d(
      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.
      """
      nrows, ncols = delta_field.shape
      if target is None:
          b = np.zeros_like(grad)
          b[..., 0] = delta_field * grad[..., 0]
          b[..., 1] = delta_field * grad[..., 1]
      else:
          b = target
  
      y = np.zeros(2)
      for r in range(nrows):
          for c in range(ncols):
              sigmasq = (
                  sigmasq_field[r, c]
                  if sigmasq_field is not None
                  else 1
              )
              # This has to be done inside the nested loops because
              # some d[...] may have been previously modified
              nn = 0
              y[:] = 0
              for dRow, dCol in [(-1, 0), (0, 1), (1, 0), (0, -1)]:
                  dr = r + dRow
                  if dr < 0 or dr >= nrows:
                      continue
                  dc = c + dCol
                  if dc < 0 or dc >= ncols:
                      continue
                  nn += 1
                  y += dfield[dr, dc]
  
              if np.isinf(sigmasq):
                  dfield[r, c] = y / nn
              else:
                  tau = sigmasq * lambda_param * nn
                  A = np.outer(grad[r, c], grad[r, c]) + tau * np.eye(2)
                  det = np.linalg.det(A)
                  if det < 1e-9:
                      nrm2 = np.sum(grad[r, c] ** 2)
                      if nrm2 < 1e-9:
                          dfield[r, c, :] = 0
                      else:
                          dfield[r, c] = b[r, c] / nrm2
                  else:
                      y = b[r, c] + sigmasq * lambda_param * y
                      dfield[r, c] = np.linalg.solve(A, y)
  
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 1 for calling a global function with example usage: iterate_residual_field_ssd_2d(delta_field, sigmasq_field, grad, target, lambda_param, dfield) without return types