code: def test_ard(self):
      a = torch.tensor([[1, 2], [3, 4]], dtype=torch.float)
      b = torch.tensor([[1, 4], [1, 4]], dtype=torch.float)
      lengthscales = torch.tensor([1, 2], dtype=torch.float).view(
          1, 1, 2
      )
  
      kernel = MaternKernel(nu=2.5, ard_num_dims=2)
      kernel.initialize(lengthscale=lengthscales)
      kernel.eval()
  
      dist = torch.tensor([[1, 1], [2, 2]], dtype=torch.float)
      dist.mul_(math.sqrt(5))
      actual = (dist**2 / 3 + dist + 1).mul(torch.exp(-dist))
      res = kernel(a, b).to_dense()
      self.assertLess(torch.norm(res - actual), 1e-3)
  
      # diag
      res = kernel(a, b).diagonal(dim1=-1, dim2=-2)
      actual = actual.diagonal(dim1=-1, dim2=-2)
      self.assertLess(torch.norm(res - actual), 1e-5)
  
      # batch_dims
      dist = torch.tensor(
          [[[0, 0], [2, 2]], [[1, 1], [0, 0]]], dtype=torch.float
      )
      dist.mul_(math.sqrt(5))
      actual = (dist**2 / 3 + dist + 1).mul(torch.exp(-dist))
      res = kernel(a, b, last_dim_is_batch=True).to_dense()
      self.assertLess(torch.norm(res - actual), 1e-5)
  
      # batch_dims + diag
      res = kernel(a, b, last_dim_is_batch=True).diagonal(
          dim1=-1, dim2=-2
      )
      actual = torch.cat(
          [
              actual[i].diagonal(dim1=-1, dim2=-2).unsqueeze(0)
              for i in range(actual.size(0))
          ]
      )
      self.assertLess(torch.norm(res - actual), 1e-5)
  
imports: import math
  import pickle
  import unittest
  import torch
  from gpytorch.kernels import MaternKernel
  from gpytorch.priors import NormalPrior
  from gpytorch.test.base_kernel_test_case import BaseKernelTestCase
label_desc: Use image node_id 6 for calling the TestMaternKernel obj's underlying member method code with example usage: obj.test_ard() without return types