Beispiel #1
0
  void GetNonzerosVector::generateOperation(std::ostream &stream,
                                            const std::vector<std::string>& arg,
                                            const std::vector<std::string>& res,
                                            CodeGenerator& gen) const {
    // Condegen the indices
    int ind = gen.getConstant(nz_, true);

    // Codegen the assignments
    stream << "  for (ii=s" << ind << ", rr=" << res.front() << ", ss=" << arg.front()
           << "; ii!=s" << ind << "+" << nz_.size()
           << "; ++ii) *rr++ = *ii>=0 ? ss[*ii] : 0;" << endl;
  }
  void SetNonzerosVector<Add>::
  generate(CodeGenerator& g, const std::string& mem,
           const std::vector<int>& arg, const std::vector<int>& res) const {
    // Copy first argument if not inplace
    if (arg[0]!=res[0]) {
      g.body << "  " << g.copy(g.work(arg[0], this->dep(0).nnz()), this->nnz(),
                               g.work(res[0], this->nnz())) << endl;
    }

    // Condegen the indices
    int ind = g.getConstant(this->nz_, true);

    // Perform the operation inplace
    g.body << "  for (cii=s" << ind << ", rr=" << g.work(res[0], this->nnz()) << ", "
           << "ss=" << g.work(arg[1], this->dep(1).nnz()) << "; cii!=s" << ind
           << "+" << this->nz_.size() << "; ++cii, ++ss)";
    g.body << " if (*cii>=0) rr[*cii] " << (Add?"+=":"=") << " *ss;" << endl;
  }