class_docstr: weakref.ref which makes tf.Tensor and np.array objects hashable.
  
  We take care to ensure that a hash can still be provided in the case that the
  ref has been cleaned up. This ensures that the WeakKeyDefaultDict doesn't
  suffer memory leaks by failing to clean up HashableWeakRef key objects whose
  referrents have gone out of scope and been destroyed (as in
  https://github.com/tensorflow/probability/issues/647).
class_docstr_tok: ["weakref.ref","which","makes","tf.Tensor","and","np.array","objects","hashable",".","We","take","care","to","ensure","that","a","hash","can","still","be","provided","in","the","case","that","the","ref","has","been","cleaned","up",".","This","ensures","that","the","WeakKeyDefaultDict","doesn't","suffer","memory","leaks","by","failing","to","clean","up","HashableWeakRef","key","objects","whose","referrents","have","gone","out","of","scope","and","been","destroyed","(","as","in","https",":","\/\/github.com\/tensorflow\/probability\/issues\/647",")","."]
docstr: weakref.ref which makes tf.Tensor and np.array objects hashable.
  
  Args:
    referrent: Object that is being referred to.
    callback: Optional callback to invoke when object is GCed.
docstr_tok: ["weakref.ref","which","makes","tf.Tensor","and","np.array","objects","hashable",".","Args",":","referrent",":","Object","that","is","being","referred","to",".","callback",":","Optional","callback","to","invoke","when","object","is","GCed","."]
code: def __init__(self, referrent, callback=None):
      """weakref.ref which makes tf.Tensor and np.array objects hashable.
  
      Args:
        referrent: Object that is being referred to.
        callback: Optional callback to invoke when object is GCed.
      """
      if isinstance(referrent, np.generic):
          raise ValueError("Unable to weakref np.generic")
      elif isinstance(referrent, np.ndarray):
          referrent.flags.writeable = False
      super(HashableWeakRef, self).__init__(referrent, callback)
      self._hash = hash(hashable_structure(referrent))
  
imports: import collections
  import weakref
  import numpy
  import tensorflow.compat.v2
  from tensorflow.python.util import nest
label_desc: Use image node_id 1 to create a new HashableWeakRef object from inherited base classes: weakref with example: obj = HashableWeakRef(referrent, callback)