code: def test_connectivity_matrix():
      label_volume = np.array([[[3, 0, 0], [0, 0, 5], [0, 0, 4]]])
      streamlines = [
          np.array([[0, 0, 0], [0, 1, 2], [0, 2, 2]], "float"),
          np.array([[0, 0, 0], [0, 1, 1], [0, 2, 2]], "float"),
          np.array([[0, 2, 2], [0, 1, 1], [0, 0, 0]], "float"),
      ]
      expected = np.zeros((6, 6), "int")
      expected[3, 4] = 2
      expected[4, 3] = 1
      # Check basic Case
      matrix = connectivity_matrix(
          streamlines, np.eye(4), label_volume, symmetric=False
      )
      npt.assert_array_equal(matrix, expected)
      # Test mapping
      matrix, mapping = connectivity_matrix(
          streamlines,
          np.eye(4),
          label_volume,
          symmetric=False,
          return_mapping=True,
      )
      npt.assert_array_equal(matrix, expected)
      npt.assert_equal(mapping[3, 4], [0, 1])
      npt.assert_equal(mapping[4, 3], [2])
      npt.assert_equal(mapping.get((0, 0)), None)
      # Test mapping and symmetric
      matrix, mapping = connectivity_matrix(
          streamlines,
          np.eye(4),
          label_volume,
          symmetric=True,
          return_mapping=True,
      )
      npt.assert_equal(mapping[3, 4], [0, 1, 2])
      # When symmetric only (3,4) is a key, not (4, 3)
      npt.assert_equal(mapping.get((4, 3)), None)
      # expected output matrix is symmetric version of expected
      expected = expected + expected.T
      npt.assert_array_equal(matrix, expected)
      # Test mapping_as_streamlines, mapping dict has lists of streamlines
      matrix, mapping = connectivity_matrix(
          streamlines,
          np.eye(4),
          label_volume,
          symmetric=False,
          return_mapping=True,
          mapping_as_streamlines=True,
      )
      assert_true(mapping[3, 4][0] is streamlines[0])
      assert_true(mapping[3, 4][1] is streamlines[1])
      assert_true(mapping[4, 3][0] is streamlines[2])
  
      # Test Inclusive streamline analysis
      # Check basic Case (inclusive)
      expected = np.zeros((6, 6), "int")
      expected[3, 4] = 2
      expected[4, 3] = 1
      expected[3, 5] = 1
      expected[5, 4] = 1
      expected[0, 3:5] = 1
      expected[3:5, 0] = 1
  
      matrix = connectivity_matrix(
          streamlines,
          np.eye(4),
          label_volume,
          symmetric=False,
          inclusive=True,
      )
      npt.assert_array_equal(matrix, expected)
  
      # Test mapping
      matrix, mapping = connectivity_matrix(
          streamlines,
          np.eye(4),
          label_volume,
          inclusive=True,
          symmetric=False,
          return_mapping=True,
      )
      npt.assert_array_equal(matrix, expected)
      npt.assert_equal(mapping[3, 4], [0, 1])
      npt.assert_equal(mapping[4, 3], [2])
      npt.assert_equal(mapping[0, 4], [1])
      npt.assert_equal(mapping[3, 5], [0])
      npt.assert_equal(mapping.get((0, 0)), None)
  
      # Test mapping and symmetric
      matrix, mapping = connectivity_matrix(
          streamlines,
          np.eye(4),
          label_volume,
          inclusive=True,
          symmetric=True,
          return_mapping=True,
      )
      npt.assert_equal(mapping[3, 4], [0, 1, 2])
      npt.assert_equal(mapping[0, 3], [1, 2])
      npt.assert_equal(mapping[0, 4], [1, 2])
      npt.assert_equal(mapping[3, 5], [0])
      npt.assert_equal(mapping[4, 5], [0])
  
      # When symmetric only (3,4) is a key, not (4,3)
      npt.assert_equal(mapping.get((4, 3)), None)
  
      # expected output matrix is symmetric version of expected
      expected = expected + expected.T
      npt.assert_array_equal(matrix, expected)
      # Test mapping_as_streamlines, mapping dict has lists of streamlines
      matrix, mapping = connectivity_matrix(
          streamlines,
          np.eye(4),
          label_volume,
          symmetric=False,
          inclusive=True,
          return_mapping=True,
          mapping_as_streamlines=True,
      )
      assert_true(mapping[0, 3][0] is streamlines[2])
      assert_true(mapping[0, 4][0] is streamlines[1])
      assert_true(mapping[3, 0][0] is streamlines[1])
      assert_true(mapping[3, 4][0] is streamlines[0])
      assert_true(mapping[3, 4][1] is streamlines[1])
      assert_true(mapping[3, 5][0] is streamlines[0])
      assert_true(mapping[4, 0][0] is streamlines[2])
      assert_true(mapping[4, 3][0] is streamlines[2])
      assert_true(mapping[5, 4][0] is streamlines[0])
  
      # Test passing affine to connectivity_matrix
      affine = np.diag([-1, -1, -1, 1.0])
      streamlines = [-i for i in streamlines]
      matrix = connectivity_matrix(streamlines, affine, label_volume)
      # In the symmetrical case, the matrix should be, well, symmetric:
      npt.assert_equal(matrix[4, 3], matrix[4, 3])
  
imports: import warnings
  import numpy
  import pytest
  from dipy.tracking import metrics
  from dipy.tracking.streamline import transform_streamlines
  from dipy.tracking.utils import connectivity_matrix, density_map, length, ndbincount, reduce_labels, seeds_from_mask, random_seeds_from_mask, target, target_line_based, unique_rows, near_roi, reduce_rois, path_length, _min_at, max_angle_from_curvature, min_radius_curvature_from_angle
  from dipy.tracking._utils import _to_voxel_coordinates
  from dipy.tracking.vox2track import streamline_mapping
  import numpy.testing
  from dipy.testing import assert_true
  from dipy.testing.decorators import set_random_number_generator
label_desc: Use image node_id 4 for calling a global function with example usage: test_connectivity_matrix() without return types