class_docstr: Class that satisfies the `Linker` interface by acting as a `VM` factory.
  
  Parameters
  ----------
  allow_gc
      Force the virtual machine to clean up unnecessary references, in order
      to allow garbage collection on intermediate values during computation
      of a function.  If ``None``, use as default the value of the PyTensor
      flag `allow_gc`.
  use_cloop
      Use the C-based virtual machine if possible
  callback
      A callable object to call after each call to a thunk within the virtual
      machine.  It will be called with four arguments: ``node``, ``thunk``,
      ``storage_map``, and ``compute_map``.
  callback_input
      A callable object to call on each input to the graph (variables with no
      owner).  This includes constants and shared variables values.  It will
      be called with two arguments: ``var``, ``value``.
  lazy
      Useful only when `use_cloop` is False. When `lazy` is ``None``, use the
      PyTensor flag ``vm__lazy`` value. Then if we have a ``None`` (default) we
      auto detect if lazy evaluation is needed and use the appropriate
      version. If `lazy` is ``True`` or ``False``, we force the version used
      between `Loop` and `Stack`.
  c_thunks
      If ``None`` or ``True``, don't change the default. If ``False``, don't
      compile C code for the thunks.
  allow_partial_eval
      If ``True``, enforces usage of `Stack` or `CVM`, to allow for partial
      evaluation of functions (calculating a subset of outputs).
class_docstr_tok: ["Class","that","satisfies","the","`","Linker","`","interface","by","acting","as","a","`","VM","`","factory",".","Parameters","--","--","--","--","--","allow_gc","Force","the","virtual","machine","to","clean","up","unnecessary","references",",","in","order","to","allow","garbage","collection","on","intermediate","values","during","computation","of","a","function",".","If","``","None","``",",","use","as","default","the","value","of","the","PyTensor","flag","`","allow_gc","`",".","use_cloop","Use","the","C-based","virtual","machine","if","possible","callback","A","callable","object","to","call","after","each","call","to","a","thunk","within","the","virtual","machine",".","It","will","be","called","with","four","arguments",":","``","node","``",",","``","thunk","``",",","``","storage_map","``",",","and","``","compute_map","``",".","callback_input","A","callable","object","to","call","on","each","input","to","the","graph","(","variables","with","no","owner",")",".","This","includes","constants","and","shared","variables","values",".","It","will","be","called","with","two","arguments",":","``","var","``",",","``","value","``",".","lazy","Useful","only","when","`","use_cloop","`","is","False",".","When","`","lazy","`","is","``","None","``",",","use","the","PyTensor","flag","``","vm__lazy","``","value",".","Then","if","we","have","a","``","None","``","(","default",")","we","auto","detect","if","lazy","evaluation","is","needed","and","use","the","appropriate","version",".","If","`","lazy","`","is","``","True","``","or","``","False","``",",","we","force","the","version","used","between","`","Loop","`","and","`","Stack","`",".","c_thunks","If","``","None","``","or","``","True","``",",","do","n't","change","the","default",".","If","``","False","``",",","don't","compile","C","code","for","the","thunks",".","allow_partial_eval","If","``","True","``",",","enforces","usage","of","`","Stack","`","or","`","CVM","`",",","to","allow","for","partial","evaluation","of","functions","(","calculating","a","subset","of","outputs",")","."]
docstr: Reuse storage cells in a storage map.
  
  `storage_map` is updated in-place.
  
  When this feature is used, `storage_map` will no longer have a
  one-to-one mapping with the original variables, because--for
  example--some outputs may share storage with intermediate values.
  
  Returns
  -------
  A tuple of the variables that were reallocated.
docstr_tok: ["Reuse","storage","cells","in","a","storage","map",".","`","storage_map","`","is","updated","in-place",".","When","this","feature","is","used",",","`","storage_map","`","will","no","longer","have","a","one-to-one","mapping","with","the","original","variables",",","because","--","for","example","--","some","outputs","may","share","storage","with","intermediate","values",".","Returns","--","--","--","-","A","tuple","of","the","variables","that","were","reallocated","."]
code: def reduce_storage_allocations(
      self, storage_map: "StorageMapType", order: Sequence[Apply]
  ) -> tuple[Variable, ...]:
      """Reuse storage cells in a storage map.
  
      `storage_map` is updated in-place.
  
      When this feature is used, `storage_map` will no longer have a
      one-to-one mapping with the original variables, because--for
      example--some outputs may share storage with intermediate values.
  
      Returns
      -------
      A tuple of the variables that were reallocated.
  
      """
      # Collect Reallocation Info
      compute_map_re: defaultdict[Variable, list[bool]] = defaultdict(
          lambda: [False]
      )
      for var in self.fgraph.inputs:
          compute_map_re[var][0] = True
  
      if getattr(self.fgraph.profile, "dependencies", None):
          dependencies = self.fgraph.profile.dependencies
      else:
          dependencies = self.compute_gc_dependencies(storage_map)
  
      reallocated_info: dict[
          Variable, list[Variable]
      ] = calculate_reallocate_info(
          order, self.fgraph, storage_map, compute_map_re, dependencies
      )
      for pair in reallocated_info.values():
          storage_map[pair[1]] = storage_map[pair[0]]
  
      return tuple(reallocated_info.keys())
  
imports: import platform
  import sys
  import time
  import warnings
  from abc import ABC, abstractmethod
  from collections import defaultdict
  from collections.abc import Sequence
  from itertools import zip_longest
  from typing import TYPE_CHECKING, Any, Optional
  from pytensor.configdefaults import config
  from pytensor.graph.basic import Apply, Constant, Variable
  from pytensor.link.basic import Container, LocalLinker
  from pytensor.link.c.exceptions import MissingGXX
  from pytensor.link.utils import gc_helper, get_destroy_dependencies, map_storage, raise_with_op
label_desc: Use image node_id 5 for calling the VMLinker obj's underlying member method code with example usage: obj.reduce_storage_allocations(storage_map, order) and returns: tuple