code: def test_slices2aff():
      # Take a series of slices, return equivalent affine
      for N in range(1, 5):
          slices = [slice(None) for n in range(N)]
          aff = np.eye(N + 1)
          assert_array_equal(slices2aff(slices), aff)
          slices = [slice(2) for n in range(N)]
          assert_array_equal(slices2aff(slices), aff)
          slices = [slice(2, 4) for n in range(N)]
          aff2 = aff.copy()
          aff2[:-1, -1] = [2] * N
          assert_array_equal(slices2aff(slices), aff2)
          slices = [slice(2, 4, 5) for n in range(N)]
          aff3 = np.diag([5] * N + [1])
          aff3[:-1, -1] = [2] * N
          assert_array_equal(slices2aff(slices), aff3)
      slices = [
          slice(2.1, 11, 4.9),
          slice(3.2, 11, 5.8),
          slice(4.3, 11, 6.7),
      ]
      assert_array_equal(
          slices2aff(slices),
          [
              [4.9, 0, 0, 2.1],
              [0, 5.8, 0, 3.2],
              [0, 0, 6.7, 4.3],
              [0, 0, 0, 1],
          ],
      )
  
file_path: nipy/nipy/algorithms/registration/tests/test_affine.py
imports: import numpy
  import pytest
  from numpy.testing import assert_array_almost_equal, assert_array_equal
  from ....testing import assert_almost_equal
  from ..affine import Affine, Affine2D, Rigid, Rigid2D, Similarity, Similarity2D, rotation_mat2vec, slices2aff, subgrid_affine
label_desc: Use image node_id 7 for calling a global function with example usage: test_slices2aff() without return types