void FixedSmithLrDleInternal::init() { iter_ = getOption("iter"); LrDleInternal::init(); casadi_assert_message(!pos_def_, "pos_def option set to True: Solver only handles the indefinite case."); MX H = MX::sym("H", H_); MX A = MX::sym("A", A_); MX C = MX::sym("C", C_); MX V = MX::sym("V", V_); MX Vs = (V+V.T())/2; MX D = with_C_ ? C : DMatrix::eye(A_.size1()); std::vector<MX> HPH(Hs_.size(), 0); std::vector<MX> Hs = with_H_? horzsplit(H, Hi_) : std::vector<MX>(); MX out = 0; for (int i=0;i<iter_;++i) { if (with_H_) { for (int k=0;k<Hs.size();++k) { MX v = mul(D.T(), Hs[k]); HPH[k]+= mul(v.T(), mul(Vs, v)); } } else { out += mul(D, mul(Vs, D.T())); } D = mul(A, D); } std::vector<MX> dle_in(LR_DLE_NUM_IN); dle_in[LR_DLE_A] = A; dle_in[LR_DLE_V] = V; if (with_C_) dle_in[LR_DLE_C] = C; if (with_H_) dle_in[LR_DLE_H] = H; f_ = MXFunction(dle_in, lrdleOut("y", with_H_? diagcat(HPH): out)); f_.init(); Wrapper<FixedSmithLrDleInternal>::checkDimensions(); }
void SimpleIndefDleInternal::init() { DleInternal::init(); casadi_assert_message(!pos_def_, "pos_def option set to True: Solver only handles the indefinite case."); n_ = A_.size1(); MX As = MX::sym("A", A_); MX Vs = MX::sym("V", V_); MX Cs = MX::sym("C", C_); MX Hs = MX::sym("H", H_); MX Vss = (Vs+Vs.T())/2; if (with_C_) Vss = mul(mul(Cs, Vss), Cs.T()); MX A_total = DMatrix::eye(n_*n_) - kron(As,As); // Should be treated by solve node MX Pf = solve(A_total, vec(Vss), getOption("linear_solver")); std::vector<MX> v_in; v_in.push_back(As); v_in.push_back(Vs); v_in.push_back(Cs); MX P = reshape(Pf,n_,n_); std::vector<MX> HPH; if (with_H_) { std::vector<MX> H = horzsplit(Hs,Hi_); for (int k=0;k<H.size();++k) { HPH.push_back(mul(H[k].T(),mul(P,H[k]))); } } std::vector<MX> dle_in(DLE_NUM_IN); dle_in[DLE_A] = As; dle_in[DLE_V] = Vs; if (with_C_) dle_in[DLE_C] = Cs; if (with_H_) dle_in[DLE_H] = Hs; f_ = MXFunction(dle_in,dleOut("p",with_H_? diagcat(HPH) : P(output().sparsity()))); f_.init(); casadi_assert(nOut()==f_.nOut()); for (int i=0;i<nIn();++i) { casadi_assert_message(input(i).sparsity()==f_.input(i).sparsity(), "Sparsity mismatch for input " << i << ":" << input(i).dimString() << " <-> " << f_.input(i).dimString() << "."); } for (int i=0;i<nOut();++i) { casadi_assert_message(output(i).sparsity()==f_.output(i).sparsity(), "Sparsity mismatch for output " << i << ":" << output(i).dimString() << " <-> " << f_.output(i).dimString() << "."); } }