Example #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)
     for i in range(n):
         for j in range(n):
             self.assertEqual(hess.get_element(i, j), H[i,j], 'Wrong value for (i,j)=(%g,%g): got %g, expecting %g'
                              % (i, j, hess.get_element(i, j), H[i,j]))
Example #2
0
 def runTest(self):
     n = 4
     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.get_element(-1, 0))
     self.assertRaises(AssertionError, lambda: hess.get_element(-1, 0))
     self.assertRaises(AssertionError, lambda: hess.get_element(-3, n-1))
     self.assertRaises(AssertionError, lambda: hess.get_element(n, 0))
     self.assertRaises(AssertionError, lambda: hess.get_element(n+3, 0))
     self.assertRaises(AssertionError, lambda: hess.get_element(n+7, n-1))
     self.assertRaises(AssertionError, lambda: hess.get_element(0, -1))
     self.assertRaises(AssertionError, lambda: hess.get_element(0, -1))
     self.assertRaises(AssertionError, lambda: hess.get_element(n-1, -3))
     self.assertRaises(AssertionError, lambda: hess.get_element(0, n))
     self.assertRaises(AssertionError, lambda: hess.get_element(0, n+3))
     self.assertRaises(AssertionError, lambda: hess.get_element(n-1, n+7))