Пример #1
0
 def test_real(self):
     """Test that the procedure works for real numbers."""
     for _ in range(self.num_test_repetitions):
         v = numpy.random.randn(2)
         G_left = givens_matrix_elements(v[0], v[1], which='left')
         G_right = givens_matrix_elements(v[0], v[1], which='right')
         self.assertAlmostEqual(G_left.dot(v)[0], 0.)
         self.assertAlmostEqual(G_right.dot(v)[1], 0.)
Пример #2
0
 def test_already_zero(self):
     """Test when some entries are already zero."""
     # Test when left entry is zero
     v = numpy.array([0., numpy.random.randn()])
     G = givens_matrix_elements(v[0], v[1])
     self.assertAlmostEqual(G.dot(v)[0], 0.)
     # Test when right entry is zero
     v = numpy.array([numpy.random.randn(), 0.])
     G = givens_matrix_elements(v[0], v[1])
     self.assertAlmostEqual(G.dot(v)[0], 0.)
Пример #3
0
 def test_bad_input(self):
     """Test bad input."""
     A = numpy.random.randn(3, 3)
     v = numpy.random.randn(2)
     G = givens_matrix_elements(v[0], v[1])
     with self.assertRaises(ValueError):
         double_givens_rotate(A, G, 0, 1, which='a')
Пример #4
0
 def test_odd_dimension(self):
     """Test that it raises an error for odd-dimensional input."""
     A = numpy.random.randn(3, 3)
     v = numpy.random.randn(2)
     G = givens_matrix_elements(v[0], v[1])
     with self.assertRaises(ValueError):
         double_givens_rotate(A, G, 0, 1, which='row')
     with self.assertRaises(ValueError):
         double_givens_rotate(A, G, 0, 1, which='col')
Пример #5
0
 def test_bad_input(self):
     """Test bad input."""
     with self.assertRaises(ValueError):
         v = numpy.random.randn(2)
         G = givens_matrix_elements(v[0], v[1], which='a')