code: def testAnchorReference(self):
      # Test simple case with one aspect ratio and one scale.
      base_size = 256
      aspect_ratios = [1.0]
      scales = [1.0]
      anchor_reference = generate_anchors_reference(
          base_size=base_size,
          aspect_ratios=aspect_ratios,
          scales=scales,
      )
  
      # Should return a single anchor.
      self.assertEqual(anchor_reference.shape, (1, 4))
      self.assertAllEqual(
          anchor_reference[0],
          [
              -(base_size - 1) / 2.0,
              -(base_size - 1) / 2.0,
              (base_size - 1) / 2.0,
              (base_size - 1) / 2.0,
          ],
      )
  
      # Test with fixed ratio and different scales.
      scales = np.array([0.5, 1.0, 2.0, 4.0])
      anchor_reference = generate_anchors_reference(
          base_size=base_size,
          aspect_ratios=aspect_ratios,
          scales=scales,
      )
  
      # Check that we have the correct number of anchors.
      self.assertEqual(anchor_reference.shape, (4, 4))
      width_heights = self._get_widths_heights(anchor_reference)
      # Check that anchors are squares (aspect_ratio = [1.0]).
      self.assertTrue(
          (width_heights[:, 0] == width_heights[:, 1]).all()
      )
      # Check that widths are consistent with scales times base_size.
      self.assertAllEqual(width_heights[:, 0], base_size * scales)
      # Check exact values.
      self.assertAllEqual(
          anchor_reference,
          np.array(
              [
                  [-63.5, -63.5, 63.5, 63.5],
                  [-127.5, -127.5, 127.5, 127.5],
                  [-255.5, -255.5, 255.5, 255.5],
                  [-511.5, -511.5, 511.5, 511.5],
              ]
          ),
      )
  
      # Test with different ratios and scales.
      scales = np.array([0.5, 1.0, 2.0])
      aspect_ratios = np.array([0.5, 1.0, 2.0])
      anchor_reference = generate_anchors_reference(
          base_size=base_size,
          aspect_ratios=aspect_ratios,
          scales=scales,
      )
  
      # Check we have the correct number of anchors.
      self.assertEqual(
          anchor_reference.shape, (len(scales) * len(aspect_ratios), 4)
      )
  
      width_heights = self._get_widths_heights(anchor_reference)
  
      # Check ratios of height / widths
      anchor_ratios = width_heights[:, 1] / width_heights[:, 0]
      # Check scales (applied to )
      anchor_scales = np.sqrt(
          (width_heights[:, 1] * width_heights[:, 0]) / (base_size**2)
      )
  
      # Test that all ratios are used in the correct order.
      self.assertAllClose(
          anchor_ratios, [0.5, 0.5, 0.5, 1.0, 1.0, 1.0, 2.0, 2.0, 2.0]
      )
      # Test that all scales are used in the correct order.
      self.assertAllClose(
          anchor_scales, [0.5, 1.0, 2.0, 0.5, 1.0, 2.0, 0.5, 1.0, 2.0]
      )
  
file_path: luminoth/luminoth/utils/anchors_test.py
imports: import numpy
  import tensorflow
  from luminoth.utils.anchors import generate_anchors_reference
label_desc: Use image node_id 3 for calling the AnchorsTest obj's underlying member method code with example usage: obj.testAnchorReference() without return types