code: def test_dtype_cmap_inverses():
      # Check that we can make functional inverses of AffineTransforms, and
      # CoordinateMap versions of AffineTransforms
      arr_p1 = np.eye(4)[:, [0, 2, 1, 3]]
      in_list = [0, 1, 2]
      out_list = [0, 2, 1]
      for dt in _SYMPY_SAFE_DTYPES:
          in_cs = CoordinateSystem("ijk", coord_dtype=dt)
          out_cs = CoordinateSystem("xyz", coord_dtype=dt)
          cmap = AffineTransform(in_cs, out_cs, arr_p1.astype(dt))
          coord = np.array(in_list, dtype=dt)
          out_coord = np.array(out_list, dtype=dt)
          # Expected output type of inverse, not preserving
          if dt in np.sctypes["int"] + np.sctypes["uint"]:
              exp_i_dt = np.float64
          else:
              exp_i_dt = dt
          # Default inverse cmap may alter coordinate types
          try:
              r_cmap = cmap.inverse()
          except:
              1 / 0
          res = r_cmap(out_coord)
          assert_array_equal(res, coord)
          assert res.dtype == exp_i_dt
          # Default behavior is preserve_type=False
          r_cmap = cmap.inverse(preserve_dtype=False)
          res = r_cmap(out_coord)
          assert_array_equal(res, coord)
          assert res.dtype == exp_i_dt
          # Preserve_dtype=True - preserves dtype
          r_cmap = cmap.inverse(preserve_dtype=True)
          res = r_cmap(out_coord)
          assert_array_equal(res, coord)
          assert res.dtype == dt
          # Preserve_dtype=True is default for conversion to CoordinateMap
          cm_cmap = _as_coordinate_map(cmap)
          assert_array_equal(cm_cmap(coord), out_list)
          rcm_cmap = cm_cmap.inverse()
          assert_array_equal(rcm_cmap(coord), out_list)
          res = rcm_cmap(out_coord)
          assert_array_equal(res, coord)
          assert res.dtype == dt
      # For integer types, where there is no integer inverse, return floatey
      # inverse by default, and None for inverse when preserve_dtype=True
      arr_p2 = arr_p1 * 2
      arr_p2[-1, -1] = 1
      out_list = [0, 4, 2]
      for dt in np.sctypes["int"] + np.sctypes["uint"]:
          in_cs = CoordinateSystem("ijk", coord_dtype=dt)
          out_cs = CoordinateSystem("xyz", coord_dtype=dt)
          cmap = AffineTransform(in_cs, out_cs, arr_p2.astype(dt))
          coord = np.array(in_list, dtype=dt)
          out_coord = np.array(out_list, dtype=dt)
          # Default
          r_cmap = cmap.inverse()
          res = r_cmap(out_coord)
          assert_array_equal(res, coord)
          assert res.dtype == np.float64
          # Default is preserve_type=False
          r_cmap = cmap.inverse(preserve_dtype=False)
          res = r_cmap(out_coord)
          assert_array_equal(res, coord)
          assert res.dtype == np.float64
          # preserve_dtype=True means there is no valid inverse for non integer
          # affine inverses, as here
          assert cmap.inverse(preserve_dtype=True) == None
  
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 40 for calling a global function with example usage: test_dtype_cmap_inverses() without return types