def test_eval_ad_nonsmooth(self): dut = al.AugmentedLagrangianNonsmooth(prog=self.prog, include_x_bounds=True) x_val = InitializeAutoDiff(np.array([1., 3])) al_val, constraint_residue, cost = dut.Eval(x=x_val, lambda_val=np.array([0.5]), mu=0.1) self.assertIsInstance(al_val, AutoDiffXd) self.assertIsInstance(constraint_residue, np.ndarray) self.assertIsInstance(cost, AutoDiffXd)
def test_math_utils(self): a = InitializeAutoDiff(value=[1, 2, 3], num_derivatives=3, deriv_num_start=0) np.testing.assert_array_equal(ExtractValue(auto_diff_matrix=a), np.array([[1, 2, 3]]).T) np.testing.assert_array_equal(ExtractGradient(auto_diff_matrix=a), np.eye(3)) a, b = InitializeAutoDiffTuple([1], [2, 3]) np.testing.assert_array_equal(ExtractValue(a), np.array([[1]])) np.testing.assert_array_equal(ExtractValue(b), np.array([[2, 3]]).T) np.testing.assert_array_equal(ExtractGradient(a), np.eye(1, 3)) np.testing.assert_array_equal(ExtractGradient(b), np.hstack((np.zeros((2, 1)), np.eye(2)))) c_grad = [[2, 4, 5], [1, -1, 0]] c = InitializeAutoDiff(value=[2, 3], gradient=c_grad) np.testing.assert_array_equal(ExtractValue(c), np.array([2, 3]).reshape((2, 1))) np.testing.assert_array_equal(ExtractGradient(c), np.array(c_grad))