本文整理汇总了C++中CodeGenerator::getSparsity方法的典型用法代码示例。如果您正苦于以下问题:C++ CodeGenerator::getSparsity方法的具体用法?C++ CodeGenerator::getSparsity怎么用?C++ CodeGenerator::getSparsity使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CodeGenerator
的用法示例。
在下文中一共展示了CodeGenerator::getSparsity方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: generateOperation
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;
}
示例2: for
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;
}
示例3: generateOperation
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;
}