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


C++ SparseVector类代码示例

本文整理汇总了C++中SparseVector的典型用法代码示例。如果您正苦于以下问题:C++ SparseVector类的具体用法?C++ SparseVector怎么用?C++ SparseVector使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了SparseVector类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: multadd_ns

void multadd_ns(DenseVector &w, const SparseVector &b, base_type factor, size_t offset)
{
    for (SparseVector::const_iterator iter = b.begin(); iter!=b.end(); ++iter)
    {
        w[iter->first+offset] += factor*iter->second;
    }
}
开发者ID:solittlework,项目名称:PSSP_V2,代码行数:7,代码来源:sparse_vector_func.hpp

示例2: while

SparseVector<T_Element,T_Alloc>::SparseVector(
    const SparseVector<T_Element,T_Alloc>& sp_vec )
  :
      alloc_(sp_vec.alloc_), size_(sp_vec.size_), max_nz_(sp_vec.max_nz_)
    , assume_sorted_(sp_vec.assume_sorted_)
    , know_is_sorted_(sp_vec.know_is_sorted_)
{
  // Allocate the memory for the elements and set the memory of the sparse vector.
  index_lookup_.set_sp_vec(
#ifdef _PG_CXX
    new element_type[max_nz_]
#else
    alloc_.allocate(max_nz_,NULL)
#endif
    ,sp_vec.nz(),sp_vec.offset());
  // Perform an uninitialized copy of the elements
  iterator		ele_to_itr		= index_lookup_.ele();
  const_iterator	ele_from_itr	= sp_vec.begin();
  while(ele_from_itr != sp_vec.end()) {
#ifdef _PG_CXX
    new (ele_to_itr++) element_type(*ele_from_itr++);
#else
    alloc_.construct(ele_to_itr++,*ele_from_itr++);
#endif
  }
}
开发者ID:00liujj,项目名称:trilinos,代码行数:26,代码来源:AbstractLinAlgPack_SparseVectorClassDef.hpp

示例3:

//update all rows of Z^t
void M3LLinear::update_all_rows( SparseVector& x, const M3LFloat* Rrow, const M3LFloat& scale)
{
	
	
	M3LFloat* Zk=Z;
	M3LFloat mk;
	int nnz=x.get_nnz();
	for(int k=0;k<L;k++)
	{
		
		if(Rrow[k]==0)
		{
			Zk+=d;
			continue;
		}
		mk=Rrow[k]*scale;
		for(int i=0;i<nnz;i++)
		{
			Zk[x.get_ith_index(i)]+=mk*(x.get_ith_value(i));
		}
		b[k]+=Rrow[k]*scale*bias;	
		Zk+=d;
	}
	
}
开发者ID:anukat2015,项目名称:ramesh-acl15,代码行数:26,代码来源:M3LLinear.cpp

示例4: InitSparse

void MiraFeatureVector::InitSparse(const SparseVector& sparse, size_t ignoreLimit)
{
  vector<size_t> sparseFeats = sparse.feats();
  bool bFirst = true;
  size_t lastFeat = 0;
  m_sparseFeats.reserve(sparseFeats.size());
  m_sparseVals.reserve(sparseFeats.size());
  for(size_t i=0; i<sparseFeats.size(); i++) {
    if (sparseFeats[i] < ignoreLimit) continue;
    size_t feat = m_dense.size() + sparseFeats[i];
    m_sparseFeats.push_back(feat);
    m_sparseVals.push_back(sparse.get(sparseFeats[i]));

    // Check ordered property
    if(bFirst) {
      bFirst = false;
    } else {
      if(lastFeat>=feat) {
        cerr << "Error: Feature indeces must be strictly ascending coming out of SparseVector" << endl;
        exit(1);
      }
    }
    lastFeat = feat;
  }
}
开发者ID:Deseaus,项目名称:mosesdecoder,代码行数:25,代码来源:MiraFeatureVector.cpp

示例5: sprod_ns

base_type sprod_ns(const DenseVector &w, const SparseVector &b, size_t offset)
{
    base_type ans=0;
    for (SparseVector::const_iterator iter = b.begin(); iter!=b.end(); ++iter)
    {
        ans += w[iter->first+offset]*iter->second;
    }
    return ans;
}
开发者ID:solittlework,项目名称:PSSP_V2,代码行数:9,代码来源:sparse_vector_func.hpp

示例6:

Real MonotonicSpline::TDeriv2(Real u) const
{
  SparseVector v;
  basis.Deriv2(u,v);
  Real sum=Zero;
  for(SparseVector::const_iterator i=v.begin();i!=v.end();i++) 
    sum += t[i->first]*i->second;
  return sum;
}
开发者ID:krishauser,项目名称:KrisLibrary,代码行数:9,代码来源:MonotonicSpline.cpp

示例7: add

//helper functions
void add(M3LFloat* s, SparseVector a, M3LFloat scale)
{
	
	int nnz=a.get_nnz();
	for(int i=0;i<nnz;i++)
	{
		s[a.get_ith_index(i)]+=scale*(a.get_ith_value(i));
	}
}
开发者ID:anukat2015,项目名称:ramesh-acl15,代码行数:10,代码来源:M3LLinear.cpp

示例8: timesColumn

double SparseRow::timesColumn(const SparseVector &v) const  
{
    double sum = 0;
    int loc;
    for (int cnt = 0; cnt < this->size; ++cnt)
        if (v.isNonZero( loc = nb[cnt].getIx() ))
            sum += v.getValue( loc ) * nb[cnt].getWeight();
    return sum;
}
开发者ID:gouchangjiang,项目名称:opengeoda,代码行数:9,代码来源:SparseRow.cpp

示例9: addTimes

void SparseVector::addTimes(const SparseVector &v, const double &w)  {

    for (int cnt = 0; cnt < v.getNzEntries(); ++cnt)  {

        int ix = v.getIx(cnt);

        this->plusAt( ix, v.getValue(ix) * w );

    }

}
开发者ID:jontheepi,项目名称:geoda,代码行数:11,代码来源:SparseVector.cpp

示例10: runTest

    void runTest() {
        std::stringstream oss;
        m_A.marshal_out(oss);

        SparseVector<Pairing<GA, GB>> B;

        std::stringstream iss(oss.str());
        checkPass(B.marshal_in(iss));

        checkPass(m_A == B);
    }
开发者ID:alexwzk,项目名称:snarklib,代码行数:11,代码来源:AutoTest_Marshalling.hpp

示例11: Assert

Real MonotonicSpline::UtoT(Real u) const
{
  if(u < basis.knots[basis.Degree()]) return t.front();
  if(u >= basis.knots[basis.knots.size()-basis.Degree()]) return t.back();
  SparseVector v;
  basis.Evaluate(u,v);
  Assert(v.numEntries()!=0);
  Real sum=Zero;
  for(SparseVector::const_iterator i=v.begin();i!=v.end();i++) 
    sum += t[i->first]*i->second;
  return sum;
}
开发者ID:krishauser,项目名称:KrisLibrary,代码行数:12,代码来源:MonotonicSpline.cpp

示例12: accumQuery

 void accumQuery(const SparseVector<Pairing<GA, GB>>& query,
                 const std::size_t reserveTune,
                 ProgressCallback* callback) {
     m_val = m_val
         + (*m_random_d) * query.getElementForIndex(Z_INDEX)
         + query.getElementForIndex(3)
         + multiExp01(query,
                      *m_witness,
                      4,
                      4 + m_numVariables,
                      0 == reserveTune ? reserveTune : m_numVariables / reserveTune,
                      callback);
 }
开发者ID:alexwzk,项目名称:snarklib,代码行数:13,代码来源:PPZK_witness.hpp

示例13: outputSample

static void outputSample(ostream& out, const FeatureDataItem& f1, const FeatureDataItem& f2) {
  // difference in score in regular features
  for(unsigned int j=0; j<f1.dense.size(); j++)
    if (abs(f1.dense[j]-f2.dense[j]) > 0.00001)
      out << " F" << j << " " << (f1.dense[j]-f2.dense[j]);

  if (f1.sparse.size() || f2.sparse.size()) {
    out << " ";

    // sparse features
    const SparseVector &s1 = f1.sparse;
    const SparseVector &s2 = f2.sparse;
    SparseVector diff = s1 - s2;
    diff.write(out);
  }
}
开发者ID:Applied-Language-Solutions,项目名称:mosesdecoder,代码行数:16,代码来源:pro.cpp

示例14: add_row

void SparseSystem::add_row(const SparseVector& new_row, double new_r) {
  ensure_num_cols(new_row.last()+1);

  append_new_rows(1);
  int row = num_rows() - 1;
  _rhs(row) = new_r;
  set_row(row, new_row);
}
开发者ID:Gabs48,项目名称:HaloLinux_Software,代码行数:8,代码来源:SparseSystem.cpp

示例15: outputSample

void Data::outputSample( ostream &out, const FeatureStats &f1, const FeatureStats &f2 ) 
{
  // difference in score in regular features
	for(unsigned int j=0; j<f1.size(); j++)
		if (abs(f1.get(j)-f2.get(j)) > 0.00001)
			out << " F" << j << " " << (f1.get(j)-f2.get(j));

  if (!hasSparseFeatures())
    return;

  out << " ";

  // sparse features
  const SparseVector &s1 = f1.getSparse();
  const SparseVector &s2 = f2.getSparse();
  SparseVector diff = s1 - s2;
  diff.write(out);
}
开发者ID:hypertornado,项目名称:mosesdecoder,代码行数:18,代码来源:Data.cpp


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