void Multiplication::generateOperation(std::ostream &stream, const std::vector<std::string>& arg, const std::vector<std::string>& res, CodeGenerator& gen) const{ // Clear the result stream << " casadi_fill(" << sparsity().size() << ",0.0," << res.front() << ",1);" << endl; // Perform sparse matrix multiplication stream << " casadi_mm_nt_sparse("; for(int i=0; i<2; ++i){ stream << arg.at(i) << ",s" << gen.getSparsity(dep(i).sparsity()) << ","; } stream << res.front() << ",s" << gen.getSparsity(sparsity()) << ");" << endl; }
void Multiplication<TrX,TrY>::generateOperation(std::ostream &stream, const std::vector<std::string>& arg, const std::vector<std::string>& res, CodeGenerator& gen) const{ // Check if inplace bool inplace = arg.at(0).compare(res.front())==0; // Copy first argument if not inplace if(!inplace){ stream << " for(i=0; i<" << this->size() << "; ++i) " << res.front() << "[i]=" << arg.at(0) << "[i];" << endl; } // Perform sparse matrix multiplication gen.addAuxiliary(CodeGenerator::AUX_MM_TN_SPARSE); stream << " casadi_mm_tn_sparse("; stream << arg.at(1) << ",s" << gen.getSparsity(dep(1).sparsity()) << ","; stream << arg.at(2) << ",s" << gen.getSparsity(dep(2).sparsity()) << ","; stream << res.front() << ",s" << gen.getSparsity(sparsity()) << ");" << endl; }
void EvaluationMX::generateOperation(std::ostream &stream, const std::vector<std::string>& arg, const std::vector<std::string>& res, CodeGenerator& gen) const{ // Get the index of the function int f = gen.getDependency(fcn_); stream << " f" << f << "_buffered("; // Pass inputs to the function input buffers for(int i=0; i<arg.size(); ++i){ // Pass argument to the function stream << arg.at(i) << ","; // Pass argument sparsity to the function if(dep(i).isNull()){ stream << "0"; } else { int sp_i = gen.getSparsity(dep(i).sparsity()); stream << "s" << sp_i; } // Separate with a space to visualize argument grouping if(i+1<arg.size()+res.size()) stream << ", "; } // Separate arguments and results with two extra spaces stream << " "; // Pass results to the function input buffers for(int i=0; i<res.size(); ++i){ // Pass results buffer to the function stream << res.at(i) << ","; // Pass argument sparsity to the function int sp_i = gen.getSparsity(sparsity(i)); stream << "s" << sp_i; // Separate with a space to visualize argument grouping if(i+1<res.size()) stream << ", "; } // Finalize the function call stream << ");" << endl; }