code: def clean_gallery_out(build_dir):
      """Deletes images under the sphx_glr namespace in the build directory"""
      # Sphinx hack: sphinx copies generated images to the build directory
      #  each time the docs are made.  If the desired image name already
      #  exists, it appends a digit to prevent overwrites.  The problem is,
      #  the directory is never cleared.  This means that each time you build
      #  the docs, the number of images in the directory grows.
      #
      # This question has been asked on the sphinx development list, but there
      #  was no response: https://git.net/ml/sphinx-dev/2011-02/msg00123.html
      #
      # The following is a hack that prevents this behavior by clearing the
      #  image build directory from gallery images each time the docs are built.
      #  If sphinx changes their layout between versions, this will not
      #  work (though it should probably not cause a crash).
      # Tested successfully on Sphinx 1.0.7
  
      build_image_dir = os.path.join(build_dir, "_images")
      if os.path.exists(build_image_dir):
          filelist = os.listdir(build_image_dir)
          for filename in filelist:
              if filename.startswith("sphx_glr") and filename.endswith(
                  "png"
              ):
                  os.remove(os.path.join(build_image_dir, filename))
  
file_path: tensorly/doc/sphinx_ext/sphinx_gallery/gen_gallery.py
imports: from __future__ import division, print_function, absolute_import
  import codecs
  import copy
  import re
  import os
  from .None import glr_path_static
  from .None import sphinx_compatibility
  from .gen_rst import generate_dir_rst, SPHX_GLR_SIG
  from .docs_resolv import embed_code_links
  from .downloads import generate_zipfiles
label_desc: Use image node_id 1 for calling a global function with example usage: clean_gallery_out(build_dir) without return types