class_docstr: Plain convolutional kernel as described in :cite:t:`vdw2017convgp`. Defines
  a GP :math:`f()` that is constructed from a sum of responses of individual patches
  in an image:
  
  .. math::
     f(x) = \sum_p x^{[p]}
  
  where :math:`x^{[p]}` is the :math:`p`'th patch in the image.
  
  The key reference is :cite:t:`vdw2017convgp`.
class_docstr_tok: ["Plain","convolutional","kernel","as","described","in",":","cite",":","t",":","`","vdw2017convgp","`",".","Defines","a","GP",":","math",":","`","f","(",")","`","that","is","constructed","from","a","sum","of","responses","of","individual","patches","in","an","image",":","..","math",":",":","f","(","x",")","=","\\sum_p","x^","{","[","p","]","}","where",":","math",":","`","x^","{","[","p","]","}","`","is","the",":","math",":","`","p","`","'th","patch","in","the","image",".","The","key","reference","is",":","cite",":","t",":","`","vdw2017convgp","`","."]
code: def K_diag(self, X: TensorType) -> tf.Tensor:
      Xp = cs(self.get_patches(X), "[batch..., N, P, S]")
  
      rank = tf.rank(Xp) - 3
      P = tf.shape(Xp)[-2]
      ones = tf.ones((rank,), dtype=tf.int32)
  
      W2 = cs(self.weights[:, None] * self.weights[None, :], "[P, P]")
      W2 = cs(
          tf.reshape(W2, tf.concat([ones, [1, P, P]], 0)),
          "[..., 1, P, P]",
      )
  
      bigK = cs(self.base_kernel.K(Xp), "[batch..., N, P, P]")
  
      return (
          tf.reduce_sum(bigK * W2, [rank + 1, rank + 2])
          / self.num_patches**2.0
      )
  
file_path: GPflow/gpflow/kernels/convolutional.py
imports: from typing import Optional, Sequence, cast
  import numpy
  import tensorflow
  from check_shapes import check_shape
  from check_shapes import check_shapes, inherit_check_shapes
  from ..base import Parameter, TensorType
  from ..config import default_float
  from ..utilities import to_default_float
  from .base import Kernel
label_desc: Use image node_id 4 for calling the Convolutional obj's underlying member method code with example usage: obj.K_diag(X) and returns: unknown