class_docstr: Structured interpolation to approximate a large matrix.
  
  This implements a component of the Structured Kernel Interpolation [1]
  algorithm. We approximate the pairwise `kernel` values for two inputs `x1`,
  `x2` with the following product:
  
  ```none
  k(x1, x2) = r(x1) @ k(u, u) @ r(x2)^T
  ```
  
  where `u` is a set of points regularly spaced on grid and `r` is an
  interpolation matrix. In short, instead of evaluating `kernel` on `x1` and
  `x2`, we evaluate it on `u`, which is chosen to contain fewer points than `x1`
  and `x2` and the interpolate using the interpolation matrix.
  
  This construction lets us compute matrix products efficiently. If `x1`/`x2`
  are of shape `O(n)` and `u` is of shape `O(m)`, this reduces the compute cost
  and memory to `O(n + m^2)` from `O(n^2)`.
  
  In practice, the interpolation matrix is implicitly defined using `interp_fn`,
  of which `tfp.math.batch_interp_regular_nd_grid` linear interpolation is a
  prototypical example. When `x1 == x2` we can relatively cheaply compute the
  diagonal of that matrix exactly, to preserve positive-semi-definiteness.
  
  Since we rely on a dense grid `u`, this method works best when the the kernel
  inputs are low dimensional (2 or 3).
  
  #### References
  
  [1]: Wilson, A. G., & Nickisch, H. Kernel Interpolation for Scalable
       Structured Gaussian Processes (KISS-GP). 2005. arXiv.
       http://arxiv.org/abs/1503.01057
class_docstr_tok: ["Structured","interpolation","to","approximate","a","large","matrix",".","This","implements","a","component","of","the","Structured","Kernel","Interpolation","[","1","]","algorithm",".","We","approximate","the","pairwise","`","kernel","`","values","for","two","inputs","`","x1","`",",","`","x2","`","with","the","following","product",":","``","`","none","k","(","x1",",","x2",")","=","r","(","x1",")","@","k","(","u",",","u",")","@","r","(","x2",")","^T","``","`","where","`","u","`","is","a","set","of","points","regularly","spaced","on","grid","and","`","r","`","is","an","interpolation","matrix",".","In","short",",","instead","of","evaluating","`","kernel","`","on","`","x1","`","and","`","x2","`",",","we","evaluate","it","on","`","u","`",",","which","is","chosen","to","contain","fewer","points","than","`","x1","`","and","`","x2","`","and","the","interpolate","using","the","interpolation","matrix",".","This","construction","lets","us","compute","matrix","products","efficiently",".","If","`","x1","`","\/","`","x2","`","are","of","shape","`","O","(","n",")","`","and","`","u","`","is","of","shape","`","O","(","m",")","`",",","this","reduces","the","compute","cost","and","memory","to","`","O","(","n","+","m^2",")","`","from","`","O","(","n^2",")","`",".","In","practice",",","the","interpolation","matrix","is","implicitly","defined","using","`","interp_fn","`",",","of","which","`","tfp.math.batch_interp_regular_nd_grid","`","linear","interpolation","is","a","prototypical","example",".","When","`","x1","==","x2","`","we","can","relatively","cheaply","compute","the","diagonal","of","that","matrix","exactly",",","to","preserve","positive-semi-definiteness",".","Since","we","rely","on","a","dense","grid","`","u","`",",","this","method","works","best","when","the","the","kernel","inputs","are","low","dimensional","(","2","or","3",")",".","#","#","#","#","References","[","1","]",":","Wilson",",","A.","G.",",","&","Nickisch",",","H.","Kernel","Interpolation","for","Scalable","Structured","Gaussian","Processes","(","KISS-GP",")",".","2005.","arXiv",".","http",":","\/\/arxiv.org\/abs\/1503.01057"]
code: def _diag_part(self):
      if USE_EXACT_DIAG:
          res = self._exact_diag_part()
      else:
          res = self._approx_diag_part()
      if self._diag_shift is not None:
          res += self._diag_shift[..., tf.newaxis]
      return res
  
imports: import functools
  import numpy
  import tensorflow.compat.v2
  from tensorflow_probability.python.internal import distribution_util
  from tensorflow_probability.python.internal import dtype_util
  from tensorflow_probability.python.internal import prefer_static
  from tensorflow_probability.python.internal import tensor_util
  from tensorflow_probability.python.math import gradient
  from tensorflow_probability.python.math import interpolation
label_desc: Use image node_id 17 for calling the LinearOperatorInterpolatedPSDKernel obj's underlying member method code with example usage: obj._diag_part() and returns: res