code: def test_extract_crops(mock_pdf):
      doc_img = DocumentFile.from_pdf(mock_pdf)[0]
      num_crops = 2
      rel_boxes = np.array(
          [
              [
                  idx / num_crops,
                  idx / num_crops,
                  (idx + 1) / num_crops,
                  (idx + 1) / num_crops,
              ]
              for idx in range(num_crops)
          ],
          dtype=np.float32,
      )
      abs_boxes = np.array(
          [
              [
                  int(idx * doc_img.shape[1] / num_crops),
                  int(idx * doc_img.shape[0]) / num_crops,
                  int((idx + 1) * doc_img.shape[1] / num_crops),
                  int((idx + 1) * doc_img.shape[0] / num_crops),
              ]
              for idx in range(num_crops)
          ],
          dtype=np.float32,
      )
  
      with pytest.raises(AssertionError):
          geometry.extract_crops(doc_img, np.zeros((1, 5)))
  
      for boxes in (rel_boxes, abs_boxes):
          croped_imgs = geometry.extract_crops(doc_img, boxes)
          # Number of crops
          assert len(croped_imgs) == num_crops
          # Data type and shape
          assert all(
              isinstance(crop, np.ndarray) for crop in croped_imgs
          )
          assert all(crop.ndim == 3 for crop in croped_imgs)
  
      # Identity
      assert np.all(
          doc_img
          == geometry.extract_crops(
              doc_img,
              np.array([[0, 0, 1, 1]], dtype=np.float32),
              channels_last=True,
          )[0]
      )
      torch_img = np.transpose(doc_img, axes=(-1, 0, 1))
      assert np.all(
          torch_img
          == np.transpose(
              geometry.extract_crops(
                  doc_img,
                  np.array([[0, 0, 1, 1]], dtype=np.float32),
                  channels_last=False,
              )[0],
              axes=(-1, 0, 1),
          )
      )
  
      # No box
      assert geometry.extract_crops(doc_img, np.zeros((0, 4))) == []
  
file_path: doctr/tests/common/test_utils_geometry.py
imports: from copy import deepcopy
  from math import hypot
  import numpy
  import pytest
  from doctr.io import DocumentFile
  from doctr.utils import geometry
label_desc: Use image node_id 10 for calling a global function with example usage: test_extract_crops(mock_pdf) without return types