code: def test_univariate(self):
      for dtype in (torch.float, torch.double):
          tkwargs = {"device": self.device, "dtype": dtype}
          # test input validation
          with self.assertRaises(BotorchError) as e:
              LinearEllipticalSliceSampler()
              self.assertTrue(
                  "requires either inequality constraints or bounds"
                  in str(e)
              )
          # special case: N(0, 1) truncated to negative numbers
          A = torch.ones(1, 1, **tkwargs)
          b = torch.zeros(1, 1, **tkwargs)
          x0 = -torch.rand(1, 1, **tkwargs)
          sampler = LinearEllipticalSliceSampler(
              inequality_constraints=(A, b), interior_point=x0
          )
          self.assertIsNone(sampler._mean)
          self.assertIsNone(sampler._covariance_root)
          self.assertTrue(torch.equal(sampler._x, x0))
          self.assertTrue(torch.equal(sampler.x0, x0))
          samples = sampler.draw(n=3)
          self.assertEqual(samples.shape, torch.Size([3, 1]))
          self.assertLessEqual(samples.max().item(), 0.0)
          self.assertFalse(torch.equal(sampler._x, x0))
          # same case as above, but instantiated with bounds
          sampler = LinearEllipticalSliceSampler(
              bounds=torch.tensor([[-float("inf")], [0.0]], **tkwargs),
              interior_point=x0,
          )
          self.assertIsNone(sampler._mean)
          self.assertIsNone(sampler._covariance_root)
          self.assertTrue(torch.equal(sampler._x, x0))
          self.assertTrue(torch.equal(sampler.x0, x0))
          samples = sampler.draw(n=3)
          self.assertEqual(samples.shape, torch.Size([3, 1]))
          self.assertLessEqual(samples.max().item(), 0.0)
          self.assertFalse(torch.equal(sampler._x, x0))
          # same case as above, but with redundant constraints
          sampler = LinearEllipticalSliceSampler(
              inequality_constraints=(A, b),
              bounds=torch.tensor([[-float("inf")], [1.0]], **tkwargs),
              interior_point=x0,
          )
          self.assertIsNone(sampler._mean)
          self.assertIsNone(sampler._covariance_root)
          self.assertTrue(torch.equal(sampler._x, x0))
          self.assertTrue(torch.equal(sampler.x0, x0))
          samples = sampler.draw(n=3)
          self.assertEqual(samples.shape, torch.Size([3, 1]))
          self.assertLessEqual(samples.max().item(), 0.0)
          self.assertFalse(torch.equal(sampler._x, x0))
          # narrow feasible region, automatically find interior point
          sampler = LinearEllipticalSliceSampler(
              inequality_constraints=(A, b),
              bounds=torch.tensor([[-0.25], [float("inf")]], **tkwargs),
          )
          self.assertIsNone(sampler._mean)
          self.assertIsNone(sampler._covariance_root)
          self.assertTrue(torch.all(sampler._is_feasible(sampler.x0)))
          samples = sampler.draw(n=3)
          self.assertEqual(samples.shape, torch.Size([3, 1]))
          self.assertLessEqual(samples.max().item(), 0.0)
          self.assertGreaterEqual(samples.min().item(), -0.25)
          self.assertFalse(torch.equal(sampler._x, x0))
          # non-standard mean / variance
          mean = torch.tensor([[0.25]], **tkwargs)
          covariance_matrix = torch.tensor([[4.0]], **tkwargs)
          error_msg = ".*either covariance_matrix or covariance_root, not both.*"
          with self.assertRaisesRegex(ValueError, error_msg):
              LinearEllipticalSliceSampler(
                  bounds=torch.tensor(
                      [[0.0], [float("inf")]], **tkwargs
                  ),
                  covariance_matrix=covariance_matrix,
                  covariance_root=covariance_matrix.sqrt(),
              )
          error_msg = ".*Covariance matrix is not positive definite.*"
          with self.assertRaisesRegex(ValueError, error_msg):
              LinearEllipticalSliceSampler(
                  bounds=torch.tensor(
                      [[0.0], [float("inf")]], **tkwargs
                  ),
                  covariance_matrix=-covariance_matrix,
              )
          sampler = LinearEllipticalSliceSampler(
              bounds=torch.tensor([[0.0], [float("inf")]], **tkwargs),
              mean=mean,
              covariance_matrix=covariance_matrix,
          )
          self.assertTrue(torch.equal(sampler._mean, mean))
          self.assertTrue(
              torch.equal(
                  sampler._covariance_root, covariance_matrix.sqrt()
              )
          )
          self.assertTrue(torch.all(sampler._is_feasible(sampler.x0)))
          samples = sampler.draw(n=4)
          self.assertEqual(samples.shape, torch.Size([4, 1]))
          self.assertGreaterEqual(samples.min().item(), 0.0)
          self.assertFalse(torch.equal(sampler._x, x0))
  
file_path: botorch/test/utils/probability/test_lin_ess.py
imports: from __future__ import annotations
  import itertools
  import math
  from unittest.mock import patch
  import torch
  from botorch.exceptions.errors import BotorchError
  from botorch.utils.constraints import get_monotonicity_constraints
  from botorch.utils.probability.lin_ess import LinearEllipticalSliceSampler
  from botorch.utils.testing import BotorchTestCase
  from torch import Tensor
label_desc: Use image node_id 1 for calling the TestLinearEllipticalSliceSampler obj's underlying member method code with example usage: obj.test_univariate() without return types