Esempio n. 1
0
 SparseStorage<DataType>::SparseStorage(const Sparsity& sparsity, const std::vector<DataType>& d)
     : sparsity_(sparsity), data_(d) {
   casadi_assert_message(sparsity.size()==d.size(),
                         "Size mismatch." << std::endl << "You supplied a sparsity of "
                         << sparsity_.dimString()
                         << ", but the supplied vector is of length " << d.size());
 }
Esempio n. 2
0
 /// Convert scalar to matrix
 inline static MX toMatrix(const MX& x, const Sparsity& sp) {
   if (x.size()==sp.size()) {
     return x;
   } else {
     return MX(sp, x);
   }
 }
Esempio n. 3
0
 MX GenericCall::projectArg(const MX& x, const Sparsity& sp, int i) {
   if (x.size()==sp.size()) {
     // Insert sparsity projection nodes if needed
     return project(x, sp);
   } else {
     // Different dimensions
     if (x.is_empty() || sp.is_empty()) { // NOTE: To permissive?
       // Replace nulls with zeros of the right dimension
       return MX::zeros(sp);
     } else if (x.is_scalar()) {
       // Scalar argument means set all
       return MX(sp, x);
     } else if (x.size1()==sp.size2() && x.size2()==sp.size1() && sp.is_vector()) {
       // Transposed vector
       return projectArg(x.T(), sp, i);
     } else {
       // Mismatching dimensions
       casadi_error("Cannot create function call node: Dimension mismatch for argument "
                    << i << ". Argument has shape " << x.size()
                    << " but function input has shape " << sp.size());
     }
   }
 }
Esempio n. 4
0
 Reshape::Reshape(const MX& x, Sparsity sp) {
   casadi_assert(x.size()==sp.size());
   setDependencies(x);
   setSparsity(sp);
 }
Esempio n. 5
0
 SparseStorage<DataType>::SparseStorage(const Sparsity& sparsity, const DataType& val) :
   sparsity_(sparsity), data_(sparsity.size(), val) {}