Beispiel #1
0
/*! return its largest absolute value */
inline comple damax(const zhsmatrix& mat)
{VERBOSE_REPORT;
  std::vector<zcomponent>::const_iterator itx(mat.data.begin());
  double vmax =0.;
  for(std::vector<zcomponent>::const_iterator it=mat.data.begin(); it!=mat.data.end(); it++){
    if( vmax < norm(it->v) ){
      vmax =norm(it->v);
      itx =it;
    }
  }
  return itx->v;
}
Beispiel #2
0
/*! search the index of element having the largest absolute value
  in 0-based numbering system */
inline void idamax(long& i, long& j, const zhsmatrix& mat)
{VERBOSE_REPORT;
  std::vector<zcomponent>::const_iterator itx(mat.data.begin());
  double vmax =0.;
  for(std::vector<zcomponent>::const_iterator it=mat.data.begin(); it!=mat.data.end(); it++){
    if( vmax < norm(it->v) ){
      vmax =norm(it->v);
      itx =it;
    }
  }
  i =itx->i;
  j =itx->j;
}
Beispiel #3
0
/*! search the index of element having the largest absolute value
  in 0-based numbering system */
inline void idamax(long& i, long& j, const _dssmatrix& mat)
{VERBOSE_REPORT;
  std::vector<dcomponent>::const_iterator itx(mat.data.begin());
  double vmax(0);
  for(std::vector<dcomponent>::const_iterator it=mat.data.begin(); it!=mat.data.end(); it++){
    if(vmax < it->v){
      vmax=fabs(it->v);
      itx=it;
    }
  }
  i=itx->i;
  j=itx->j;
  mat.destroy();
}
Beispiel #4
0
/*! return its largest absolute value */
inline double damax(const _dgsmatrix& mat)
{VERBOSE_REPORT;
  std::vector<dcomponent>::const_iterator itx(mat.data.begin());
  double vmax(0);
  for(std::vector<dcomponent>::const_iterator it=mat.data.begin(); it!=mat.data.end(); it++){
    if(vmax < it->v){
      vmax=fabs(it->v);
      itx=it;
    }
  }
  
  mat.destroy();
  return itx->v;
}
Beispiel #5
0
Eigen::SparseMatrix<Type> kronecker(Eigen::SparseMatrix<Type> x,
				    Eigen::SparseMatrix<Type> y){
  typedef Eigen::Triplet<Type> T;
  typedef typename Eigen::SparseMatrix<Type>::InnerIterator Iterator;
  std::vector<T> tripletList;
  int n1=x.rows(),n2=x.cols(),n3=y.rows(),n4=y.cols();
  int i,j,k,l;
  // Loop over nonzeros of x
  for (int cx=0; cx<x.outerSize(); cx++)
    for (Iterator itx(x,cx); itx; ++itx)
      // Loop over nonzeros of y
      for (int cy=0; cy<y.outerSize(); cy++)
  	for (Iterator ity(y,cy); ity; ++ity)
  	  {
  	    i=itx.row();
  	    j=itx.col();
  	    k=ity.row();
  	    l=ity.col();
  	    tripletList.push_back(T(i*n3+k,j*n4+l, itx.value()*ity.value() ));
   	  }
  Eigen::SparseMatrix<Type> mat(n1*n3,n2*n4);
  mat.setFromTriplets(tripletList.begin(), tripletList.end());
  return mat;
}
Beispiel #6
0
inline int split_sentence(const std::string & text,
        std::vector<std::string> & sentences,
        int encoding = strutils::codecs::UTF8) {
  sentences.clear();
  std::string sentence; sentence.reserve(512);

  int len = text.size();
  strutils::codecs::iterator itx(text, encoding);
  for (; itx.is_good() && !itx.is_end(); ++ itx) {
    if (itx->second == itx->first + 1) {
      sentence.append(text.substr(itx->first, 1));
      char ch = text[itx->first];
      if (ch == '\r' || ch == '\n' || ch == '!' ||
          ch == '?' || ch == ';') {
        sentences.push_back(sentence);
        sentence.clear();
      }
    } else if (itx->second == itx->first + 3) {
      bool found_periods = false;
      if (itx->second + 6 < len) {
        std::string chunk = text.substr(itx->first, 9);
        size_t hashval = utility::__Default_String_HashFunction()(chunk);
        // The following black magic number is calculated by
        // hasher()(__three_periods_utf8_buff__)
        if (hashval == __three_periods_utf8_key__[0]
            || hashval == __three_periods_utf8_key__[1]
            || hashval == __three_periods_utf8_key__[2]
            || hashval == __three_periods_utf8_key__[3]) {
          sentence.append(chunk);
          sentences.push_back(sentence);
          sentence.clear();
          found_periods = true;
          ++itx;
          ++itx;
        }
      }
      if (!found_periods && itx->second + 3 < len) {
        std::string chunk= text.substr(itx->first, 6);
        size_t hashval = utility::__Default_String_HashFunction()(chunk);
        if (hashval == __two_periods_utf8_key__[0]
            || hashval == __two_periods_utf8_key__[1]
            || hashval == __two_periods_utf8_key__[2]
            || hashval == __two_periods_utf8_key__[3]
            || hashval == __two_periods_utf8_key__[4]
            || hashval == __two_periods_utf8_key__[5]) {
          sentence.append(chunk);
          sentences.push_back(sentence);
          sentence.clear();
          found_periods = true;
          ++ itx;
        }
      }
      if (!found_periods) {
        std::string chunk = text.substr(itx->first, 3);
        size_t hashval = utility::__Default_String_HashFunction()(chunk);
        if (hashval == __one_periods_utf8_key__[0]
            || hashval == __one_periods_utf8_key__[1]
            || hashval == __one_periods_utf8_key__[2]
            || hashval == __one_periods_utf8_key__[3]) {
          sentence.append(text.substr(itx->first,3));
          sentences.push_back(sentence);
          sentence.clear();
          found_periods = true;
        }
      }
      if (!found_periods) {
        sentence.append(text.substr(itx->first,3));
      }
    } else {
      sentence.append(text.substr(itx->first,itx->second- itx->first));
    }
  }

  if (sentence.size()!=0) {
    sentences.push_back(sentence);
  }
  return sentences.size();
}