code: def test_matrix():
      m = ci.Cifti2Matrix()
  
      with pytest.raises(ValueError):
          m.metadata = ci.Cifti2Parcel()
  
      with pytest.raises(TypeError):
          m[0] = ci.Cifti2Parcel()
  
      with pytest.raises(TypeError):
          m.insert(0, ci.Cifti2Parcel())
  
      mim_none = ci.Cifti2MatrixIndicesMap(
          None, "CIFTI_INDEX_TYPE_LABELS"
      )
      mim_0 = ci.Cifti2MatrixIndicesMap(0, "CIFTI_INDEX_TYPE_LABELS")
      mim_1 = ci.Cifti2MatrixIndicesMap(1, "CIFTI_INDEX_TYPE_LABELS")
      mim_01 = ci.Cifti2MatrixIndicesMap(
          [0, 1], "CIFTI_INDEX_TYPE_LABELS"
      )
  
      with pytest.raises(ci.Cifti2HeaderError):
          m.insert(0, mim_none)
  
      assert m.mapped_indices == []
  
      h = ci.Cifti2Header(matrix=m)
      assert m.mapped_indices == []
      m.insert(0, mim_0)
      assert h.mapped_indices == [0]
      assert h.number_of_mapped_indices == 1
      with pytest.raises(ci.Cifti2HeaderError):
          m.insert(0, mim_0)
  
      with pytest.raises(ci.Cifti2HeaderError):
          m.insert(0, mim_01)
  
      m[0] = mim_1
      assert list(m.mapped_indices) == [1]
      m.insert(0, mim_0)
      assert list(sorted(m.mapped_indices)) == [0, 1]
      assert h.number_of_mapped_indices == 2
      assert h.get_index_map(0) == mim_0
      assert h.get_index_map(1) == mim_1
      with pytest.raises(ci.Cifti2HeaderError):
          h.get_index_map(2)
  
imports: import collections
  from xml.etree import ElementTree
  import numpy
  import pytest
  from nibabel import cifti2
  from nibabel.cifti2.cifti2 import Cifti2HeaderError, _float_01, _value_if_klass
  from nibabel.nifti2 import Nifti2Header
  from nibabel.tests.test_dataobj_images import TestDataobjAPI
  from nibabel.tests.test_image_api import DtypeOverrideMixin, SerializeMixin
label_desc: Use image node_id 15 for calling a global function with example usage: test_matrix() without return types