code: def test_io_axis_indices():
      # Test routine to get input and output axis indices
      cmap = AffineTransform("ijk", "xyz", np.eye(4))
      for i, in_name, out_name in zip(range(3), "ijk", "xyz"):
          assert io_axis_indices(cmap, i) == (i, i)
          assert io_axis_indices(cmap, in_name) == (i, i)
          assert io_axis_indices(cmap, out_name) == (i, i)
      flipped = [[0, 0, 1, 1], [0, 1, 0, 2], [1, 0, 0, 3], [0, 0, 0, 1]]
      cmap_f = AffineTransform("ijk", "xyz", flipped)
      for i, in_name, out_name in zip(range(3), "ijk", "xyz"):
          assert io_axis_indices(cmap_f, i) == (i, 2 - i)
          assert io_axis_indices(cmap_f, in_name) == (i, 2 - i)
          assert io_axis_indices(cmap_f, out_name) == (2 - i, i)
      # Names can be same in input and output but they must match
      cmap_m = AffineTransform("ijk", "kji", flipped)
      for i, in_name, out_name in zip(range(3), "ijk", "kji"):
          assert io_axis_indices(cmap_m, i) == (i, 2 - i)
          assert io_axis_indices(cmap_m, in_name) == (i, 2 - i)
          assert io_axis_indices(cmap_m, out_name) == (2 - i, i)
      # If they don't match, AxisError, if selecting by name
      cmap_b = AffineTransform("ijk", "xiz", np.eye(4))
      pytest.raises(AxisError, io_axis_indices, cmap_b, "i")
      # ... but not if name corresponds
      assert io_axis_indices(cmap_b, "k") == (2, 2)
      # ... or if input name not found in output
      assert io_axis_indices(cmap_b, "j") == (1, 1)
      # ... or if selecting by number
      assert io_axis_indices(cmap_b, 0) == (0, 0)
      # Name not found, AxisError
      pytest.raises(AxisError, io_axis_indices, cmap_b, "q")
      # 0 leads to no match if fix0 set to false
      cmap_z = AffineTransform("ijk", "xyz", np.diag([2, 3, 0, 1]))
      assert io_axis_indices(cmap_z, "y") == (1, 1)
      assert io_axis_indices(cmap_z, "z") == (2, 2)
      assert io_axis_indices(cmap_z, "z", fix0=False) == (None, 2)
      # For either input or output
      assert io_axis_indices(cmap_z, "k") == (2, 2)
      assert io_axis_indices(cmap_z, "k", fix0=False) == (2, None)
      # axis name and number access without fix0
      cmap = AffineTransform("ijkt", "xyzt", np.diag([1, 1, 1, 0, 1]))
      pytest.raises(AxisError, io_axis_indices, cmap, "t", fix0=False)
      in_ax, out_ax = io_axis_indices(cmap, -1, fix0=False)
      assert (in_ax, out_ax) == (3, None)
      # Non-square is OK
      cmap = AffineTransform(
          "ij", "xyz", [[0, 1, 0], [0, 0, 0], [1, 0, 0], [0, 0, 1]]
      )
      assert io_axis_indices(cmap, "j") == (1, 0)
      assert io_axis_indices(cmap, "y") == (None, 1)
      assert io_axis_indices(cmap, "z") == (0, 2)
      cmap = AffineTransform(
          "ijk", "xy", [[0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]]
      )
      assert io_axis_indices(cmap, "i") == (0, None)
      assert io_axis_indices(cmap, "j") == (1, 0)
      assert io_axis_indices(cmap, "y") == (2, 1)
  
imports: from copy import copy
  from types import SimpleNamespace
  import numpy
  from ..coordinate_map import AffineTransform, AxisError, CoordinateMap, CoordMapMaker, CoordMapMakerError, _as_coordinate_map, _fix0, append_io_dim, axmap, compose, drop_io_dim, equivalent, input_axis_index, io_axis_indices, orth_axes, product, shifted_domain_origin, shifted_range_origin
  from ..coordinate_system import CoordinateSystem, CoordinateSystemError, CoordSysMaker
  import pytest
  from numpy.testing import assert_almost_equal, assert_array_equal
label_desc: Use image node_id 38 for calling a global function with example usage: test_io_axis_indices() without return types