(self)
| 1688 | @requires_expm("slicot") |
| 1689 | @memory_heavy() |
| 1690 | def test_expm(self): |
| 1691 | eps = 1e-6 |
| 1692 | t = MX.sym('t') |
| 1693 | tnum = 0.2 |
| 1694 | |
| 1695 | n = 4 |
| 1696 | |
| 1697 | np.random.seed(0) |
| 1698 | Anum = np.random.random((n,n)) |
| 1699 | Bnum = np.random.random((n,2)) |
| 1700 | Bb = np.random.random((n,2)) |
| 1701 | |
| 1702 | dA = np.random.random((n,n)) |
| 1703 | Yb = np.random.random((n,2)) |
| 1704 | |
| 1705 | def expm(A): |
| 1706 | |
| 1707 | n = A.shape[0] |
| 1708 | x = MX.sym('x',n) |
| 1709 | As = MX.sym('A',n,n) |
| 1710 | |
| 1711 | dae = {'x':x,'p':vec(As),'ode':mtimes(As,x)} |
| 1712 | intg = integrator('intg','cvodes',dae,{'reltol':1e-14,'abstol':1e-14}) |
| 1713 | |
| 1714 | Intg = intg.map('identity','serial',n,[1],[]) |
| 1715 | |
| 1716 | out = Intg(x0=DM.eye(n),p=vec(As)) |
| 1717 | expmF = Function('expm',[As],[out["xf"]]) |
| 1718 | return expmF(A) |
| 1719 | |
| 1720 | A = MX.sym("A",n,n) |
| 1721 | t = MX.sym("t") |
| 1722 | fr = Function('fr',[A,t],[expm(A*t)]) |
| 1723 | f = Function('f',[A,t],[casadi.expm(A*t)]) |
| 1724 | |
| 1725 | self.checkfunction(fr,f,inputs=[Anum, 1.1],digits=8) |
| 1726 | |
| 1727 | fr = Function('fr',[t],[expm(Anum*t)]) |
| 1728 | f = Function('f',[t],[casadi.expm_const(Anum,t)]) |
| 1729 | |
| 1730 | self.checkfunction(fr,f,inputs=[1.1],digits=8) |
| 1731 | |
| 1732 | JA = jacobian(casadi.expm(A*t),A) |
| 1733 | Jt = jacobian(casadi.expm(A*t),t) |
| 1734 | |
| 1735 | self.assertTrue(JA.nnz()==n**4) |
| 1736 | self.assertTrue(Jt.nnz()==n**2) |
| 1737 | |
| 1738 | JA = jacobian(casadi.expm_const(A,t),A) |
| 1739 | Jt = jacobian(casadi.expm_const(A,t),t) |
| 1740 | |
| 1741 | self.assertTrue(JA.nnz()==0) |
| 1742 | self.assertTrue(Jt.nnz()==n**2) |
| 1743 | |
| 1744 | def test_conditional(self): |
| 1745 |
nothing calls this directly
no test coverage detected