Beispiel #1
0
 def runTest(self):
     n = 3
     A = np.arange(n ** 2, dtype=np.float).reshape((n, n))
     H = A + A.T  # force symmetric
     hess = Hessian(n, vals=H)
     H2 = np.sin(H)
     for i in range(n):
         for j in range(n):
             hess.set_element(i, j, H2[i,j])
     for i in range(n):
         for j in range(n):
             self.assertEqual(hess.get_element(i, j), H2[i, j], 'Wrong value for (i,j)=(%g,%g): got %g, expecting %g'
                              % (i, j, hess.get_element(i, j), H2[i, j]))
Beispiel #2
0
 def runTest(self):
     n = 5
     A = np.arange(n ** 2, dtype=np.float).reshape((n, n))
     H = A + A.T  # force symmetric
     hess = Hessian(n, vals=H)
     # When testing for assertion errors, need lambda to stop assertion from actually happening
     self.assertRaises(AssertionError, lambda: hess.set_element(-1, 0, 1.0))
     self.assertRaises(AssertionError, lambda: hess.set_element(-1, 0, 2.0))
     self.assertRaises(AssertionError, lambda: hess.set_element(-3, n - 1, 3.0))
     self.assertRaises(AssertionError, lambda: hess.set_element(n, 0, 4.0))
     self.assertRaises(AssertionError, lambda: hess.set_element(n + 3, 0, -4.0))
     self.assertRaises(AssertionError, lambda: hess.set_element(n + 7, n - 1, 5.0))
     self.assertRaises(AssertionError, lambda: hess.set_element(0, -1, 6.0))
     self.assertRaises(AssertionError, lambda: hess.set_element(0, -1, 7.0))
     self.assertRaises(AssertionError, lambda: hess.set_element(n - 1, -3, -7.0))
     self.assertRaises(AssertionError, lambda: hess.set_element(0, n, -76.3))
     self.assertRaises(AssertionError, lambda: hess.set_element(0, n + 3, 2.8))
     self.assertRaises(AssertionError, lambda: hess.set_element(n - 1, n + 7, -1.0))