code: def test_extract_patches_max_patches(downsampled_face):
      face = downsampled_face
      i_h, i_w = face.shape
      p_h, p_w = 16, 16
  
      patches = extract_patches_2d(face, (p_h, p_w), max_patches=100)
      assert patches.shape == (100, p_h, p_w)
  
      expected_n_patches = int(0.5 * (i_h - p_h + 1) * (i_w - p_w + 1))
      patches = extract_patches_2d(face, (p_h, p_w), max_patches=0.5)
      assert patches.shape == (expected_n_patches, p_h, p_w)
  
      with pytest.raises(ValueError):
          extract_patches_2d(face, (p_h, p_w), max_patches=2.0)
      with pytest.raises(ValueError):
          extract_patches_2d(face, (p_h, p_w), max_patches=-1.0)
  
imports: import numpy
  import pytest
  from scipy import ndimage
  from scipy.sparse.csgraph import connected_components
  from sklearn.feature_extraction.image import PatchExtractor, _extract_patches, extract_patches_2d, grid_to_graph, img_to_graph, reconstruct_from_patches_2d
label_desc: Use image node_id 13 for calling a global function with example usage: test_extract_patches_max_patches(downsampled_face) without return types