check for attribute error in unit test
@@ -31,6 +31,9 @@ class TestMultitaskGaussianLikelihood(BaseLikelihoodTestCase, unittest.TestCase)
def test_setters(self):
likelihood = MultitaskGaussianLikelihood(num_tasks=3, rank=0)
+ a = torch.randn(3, 2)
+ mat = a.matmul(a.transpose(-1, -2))
+
# test rank 0 setters
likelihood.noise = 0.5
self.assertAlmostEqual(0.5, likelihood.noise.item())
@@ -39,16 +42,22 @@ class TestMultitaskGaussianLikelihood(BaseLikelihoodTestCase, unittest.TestCase)
for i in range(3):
self.assertAlmostEqual(0.04, likelihood.task_noises[i].item())
+ with self.assertRaises(AttributeError) as context:
+ likelihood.task_noise_covar = mat
+ self.assertTrue("task noises" in str(context.exception))
+
# test low rank setters
likelihood = MultitaskGaussianLikelihood(num_tasks=3, rank=2)
likelihood.noise = 0.5
self.assertAlmostEqual(0.5, likelihood.noise.item())
- a = torch.randn(3, 2)
- mat = a.matmul(a.transpose(-1, -2))
likelihood.task_noise_covar = mat
self.assertAllClose(mat, likelihood.task_noise_covar)
+ with self.assertRaises(AttributeError) as context:
+ likelihood.task_noises = torch.tensor([0.04, 0.04, 0.04])
+ self.assertTrue("task noises" in str(context.exception))
+
class TestMultitaskGaussianLikelihoodBatch(TestMultitaskGaussianLikelihood):
seed = 0
