BinaryMX<ScX, ScY>::BinaryMX(Operation op, const MX& x, const MX& y) : op_(op) { setDependencies(x, y); if (ScX) { setSparsity(y.sparsity()); } else { setSparsity(x.sparsity()); } }
Multiplication<TrX,TrY>::Multiplication(const MX& z, const MX& x, const MX& y){ casadi_assert_message(TrX || !TrY, "Illegal combination"); casadi_assert_message(TrX, "Not implemented"); casadi_assert_message(!TrY,"Not implemented"); casadi_assert_message(x.size1() == y.size1() && x.size2() == z.size1() && y.size2() == z.size2(),"Multiplication::Multiplication: dimension mismatch. Attempting to multiply trans(" << x.dimString() << ") with " << y.dimString() << " and add the result to " << z.dimString()); setDependencies(z,x,y); setSparsity(z.sparsity()); }
Assertion::Assertion(const MX& x, const MX& y, const std::string & fail_message) : fail_message_(fail_message) { casadi_assert_message(y.is_scalar(), "Assertion:: assertion expression y must be scalar, but got " << y.dim()); setDependencies(x, y); setSparsity(x.sparsity()); }
UnaryMX::UnaryMX(Operation op, MX x) : op_(op) { // Put a densifying node in between if necessary if (!operation_checker<F00Checker>(op_)) { x.densify(); } setDependencies(x); setSparsity(x->sparsity()); }
Multiplication::Multiplication(const MX& x, const MX& y_trans){ casadi_assert_message(x.size2() == y_trans.size2(),"Multiplication::Multiplication: dimension mismatch. Attempting to multiply " << x.dimString() << " with " << y_trans.dimString()); setDependencies(x,y_trans); // Create the sparsity pattern for the matrix-matrix product CRSSparsity spres = x->sparsity().patternProduct(y_trans.sparsity()); // Save sparsity setSparsity(spres); }
Vertcat::Vertcat(const std::vector<MX>& x) : Concat(x) { // Construct the sparsity casadi_assert(!x.empty()); Sparsity sp = x.front().sparsity(); for (vector<MX>::const_iterator i=x.begin()+1; i!=x.end(); ++i) { sp.append(i->sparsity()); } setSparsity(sp); }
Diagcat::Diagcat(const std::vector<MX>& x) : Concat(x) { // Construct the sparsity casadi_assert(!x.empty()); std::vector<Sparsity> sp; for (int i=0;i<x.size(); ++i) { sp.push_back(x[i].sparsity()); } setSparsity(blkdiag(sp)); }
HorzRepsum::HorzRepsum(const MX& x, int n) : n_(n) { casadi_assert(x.size2() % n == 0); std::vector<Sparsity> sp = horzsplit(x.sparsity(), x.size2()/n); Sparsity block = sp[0]; for (int i=1;i<sp.size();++i) { block = block+sp[i]; } Sparsity goal = repmat(block, 1, n); setDependencies(project(x, goal)); setSparsity(block); }
EvaluationMX::EvaluationMX(const FX& fcn, const std::vector<MX> &arg) : fcn_(fcn) { // Number inputs and outputs int num_in = fcn.getNumInputs(); // All dependencies of the function vector<MX> d = arg; d.resize(num_in); setDependencies(d); setSparsity(CRSSparsity(1, 1, true)); }
Call::Call(const Function& fcn, const vector<MX>& arg) : fcn_(fcn) { // Number inputs and outputs int num_in = fcn.n_in(); casadi_assert_message(arg.size()==num_in, "Argument list length (" << arg.size() << ") does not match number of inputs (" << num_in << ")" << " for function " << fcn.name()); // Create arguments of the right dimensions and sparsity vector<MX> arg1(num_in); for (int i=0; i<num_in; ++i) { arg1[i] = projectArg(arg[i], fcn_.sparsity_in(i), i); } setDependencies(arg1); setSparsity(Sparsity::scalar()); }
SymbolicMX::SymbolicMX(const std::string& name, const CRSSparsity & sp) : name_(name) { setSparsity(sp); }
HorzRepmat::HorzRepmat(const MX& x, int n) : n_(n) { setDependencies(x); setSparsity(repmat(x.sparsity(), 1, n)); }
SymbolicMX::SymbolicMX(const std::string& name, int nrow, int ncol) : name_(name) { setSparsity(Sparsity::dense(nrow, ncol)); }
SymbolicMX::SymbolicMX(const std::string& name, int n, int m) : name_(name) { setSparsity(CRSSparsity(n,m,true)); }
Split::Split(const MX& x, const std::vector<int>& offset) : offset_(offset) { setDependencies(x); setSparsity(Sparsity::scalar()); }
OutputNode::OutputNode(const MX& parent, int oind) : oind_(oind){ setDependencies(parent); // Save the sparsity pattern setSparsity(dep(0)->sparsity(oind)); }
GetNonzeros::GetNonzeros(const Sparsity& sp, const MX& y) { setSparsity(sp); setDependencies(y); }
Transpose::Transpose(const MX& x) { setDependencies(x); setSparsity(x.sparsity().T()); }
InnerProd::InnerProd(const MX& x, const MX& y) { casadi_assert(x.sparsity()==y.sparsity()); setDependencies(x, y); setSparsity(Sparsity::scalar()); }
Densification::Densification(const MX& x){ setDependencies(x); setSparsity(CRSSparsity(x.size1(),x.size2(),true)); }
Project::Project(const MX& x, const Sparsity& sp) { setDependencies(x); setSparsity(Sparsity(sp)); }
Reshape::Reshape(const MX& x, Sparsity sp) { casadi_assert(x.size()==sp.size()); setDependencies(x); setSparsity(sp); }
Inverse::Inverse(const MX& x) { casadi_assert_message(x.size1()==x.size2(), "Inverse: matrix must be square, but you supllied " << x.dimString()); setDependencies(x); setSparsity(Sparsity::dense(x.size1(), x.size2())); }
Determinant::Determinant(const MX& x) { setDependencies(x); setSparsity(Sparsity::dense(1, 1)); }
Solve<Tr>::Solve(const MX& r, const MX& A, const LinearSolver& linear_solver) : linear_solver_(linear_solver){ casadi_assert_message(r.size1() == A.size2(),"Solve::Solve: dimension mismatch."); setDependencies(r,A); setSparsity(r.sparsity()); }