code: def test_generator_from_neighbour_matrix():
      # Test too large batch_size raises exception
      with pytest.raises(Exception):
          generator_from_neighbour_matrix(
              np.zeros(shape=(4, 4)),
              None,
              np.zeros(shape=(4, 2)),
              batch_size=32,
          )
      with pytest.raises(Exception):
          generator_from_neighbour_matrix(
              np.zeros(shape=(4, 4)),
              np.zeros(shape=(4,)),
              np.zeros(shape=(4, 2)),
              batch_size=32,
          )
  
      # Test with valid hyperparameters
      unsupervised_gen = generator_from_neighbour_matrix(
          np.zeros(shape=(4, 4)),
          None,
          np.zeros(shape=(4, 2)),
          batch_size=2,
      )
  
      for triplets, labels in unsupervised_gen:
          assert isinstance(triplets, tuple)
          assert len(triplets) == 3
          for triplet in triplets:
              assert triplet.shape == (2, 4)
  
      supervised_gen = generator_from_neighbour_matrix(
          np.zeros(shape=(4, 4)),
          np.ones(shape=(4,)),
          np.zeros(shape=(4, 2)),
          batch_size=2,
      )
  
      for triplets, labels in supervised_gen:
          assert isinstance(triplets, tuple)
          assert len(triplets) == 3
          for triplet in triplets:
              assert triplet.shape == (2, 4)
          assert isinstance(labels, tuple)
          assert np.all(np.unique(labels) == 1)
  
imports: import numpy
  import pytest
  from sklearn import datasets
  from ivis.data.generators import generator_from_neighbour_matrix
  from ivis.data.generators import UnsupervisedTripletGenerator
label_desc: Use image node_id 2 for calling a global function with example usage: test_generator_from_neighbour_matrix() without return types