当前位置: 首页>>代码示例>>C++>>正文


C++ CodeGenerator::getSparsity方法代码示例

本文整理汇总了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;
}
开发者ID:kozatt,项目名称:casadi,代码行数:12,代码来源:multiplication.cpp

示例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;
  }
开发者ID:zhenglei-gao,项目名称:casadi,代码行数:16,代码来源:multiplication_impl.hpp

示例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;  
}
开发者ID:kozatt,项目名称:casadi,代码行数:42,代码来源:evaluation_mx.cpp


注:本文中的CodeGenerator::getSparsity方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。