Ejemplo n.º 1
0
  void copy(const VectorType & cpu_vector,
            vector_range<vector<SCALARTYPE> > & gpu_vector_range )
  {
    assert(cpu_vector.end() - cpu_vector.begin() >= 0 && bool("Range must have nonnegative length!"));

    if (cpu_vector.end() - cpu_vector.begin() > 0)
    {
      //we require that the size of the gpu_vector is larger or equal to the cpu-size
      std::vector<SCALARTYPE> temp_buffer(cpu_vector.end() - cpu_vector.begin());
      std::copy(cpu_vector.begin(), cpu_vector.end(), temp_buffer.begin());
      viennacl::backend::memory_write(gpu_vector_range.handle(), sizeof(SCALARTYPE)*gpu_vector_range.start(), sizeof(SCALARTYPE)*temp_buffer.size(), &(temp_buffer[0]));
    }
  }
Ejemplo n.º 2
0
  void copy(vector_range<vector<SCALARTYPE> > const & gpu_vector_range,
            VectorType & cpu_vector)
  {
    assert(cpu_vector.end() - cpu_vector.begin() >= 0 && bool("Range must have nonnegative length!"));

    if (cpu_vector.end() > cpu_vector.begin())
    {
      std::vector<SCALARTYPE> temp_buffer(cpu_vector.end() - cpu_vector.begin());
      viennacl::backend::memory_read(gpu_vector_range.handle(), sizeof(SCALARTYPE)*gpu_vector_range.start(), sizeof(SCALARTYPE)*temp_buffer.size(), &(temp_buffer[0]));

      //now copy entries to cpu_vec:
      std::copy(temp_buffer.begin(), temp_buffer.end(), cpu_vector.begin());
    }
  }
Ejemplo n.º 3
0
template<typename VectorType> void vectorSum(const VectorType& w)
{
  typedef typename VectorType::Scalar Scalar;
  int size = w.size();

  VectorType v = VectorType::Random(size);
  for(int i = 1; i < size; i++)
  {
    Scalar s = Scalar(0);
    for(int j = 0; j < i; j++) s += v[j];
    VERIFY_IS_APPROX(s, v.start(i).sum());
  }

  for(int i = 0; i < size-1; i++)
  {
    Scalar s = Scalar(0);
    for(int j = i; j < size; j++) s += v[j];
    VERIFY_IS_APPROX(s, v.end(size-i).sum());
  }

  for(int i = 0; i < size/2; i++)
  {
    Scalar s = Scalar(0);
    for(int j = i; j < size-i; j++) s += v[j];
    VERIFY_IS_APPROX(s, v.segment(i, size-2*i).sum());
  }
}
Ejemplo n.º 4
0
// Constant vector tests.
TEST_F(SmallVectorTest, ConstVectorTest) {
  const VectorType constVector;

  EXPECT_EQ(0u, constVector.size());
  EXPECT_TRUE(constVector.empty());
  EXPECT_TRUE(constVector.begin() == constVector.end());
}
Ejemplo n.º 5
0
	void put(T *t) {
		std::lock_guard<Lock> l(_lock);
		
		_data.push_back(t);
		std::sort(_data.begin(), _data.end(), Comparator());
		
		assert(sem_post(&_count) == 0);
	}
Ejemplo n.º 6
0
 void printvector(VectorType const & vec)
 {
   #ifdef VIENNACL_AMG_DEBUGBENCH
   for (typename VectorType::const_iterator iter = vec.begin(); iter != vec.end(); ++iter)
   {
     std::cout << *iter << " ";
   }
   std::cout << std::endl;
   #endif
 }
Ejemplo n.º 7
0
VectorType conjVector(const VectorType & v){
  VectorType result(v.dimension());
  typename VectorType::const_iterator b = v.begin(), e = v.end();
  typename VectorType::iterator  r = result.begin();
  while(b!=e){
    *r = conj(*b);
    ++r; ++b;
  }
  return result;
}
Ejemplo n.º 8
0
size_t
ChromeHangAnnotations::SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const
{
  size_t result = sizeof(mAnnotations) +
                  mAnnotations.capacity() * sizeof(AnnotationType);
  for (IteratorType i = mAnnotations.begin(), e = mAnnotations.end(); i != e;
       ++i) {
    result += i->first.SizeOfExcludingThisIfUnshared(aMallocSizeOf);
    result += i->second.SizeOfExcludingThisIfUnshared(aMallocSizeOf);
  }

  return result;
}
Ejemplo n.º 9
0
VError VJSONArray::Clone( VJSONValue& outValue, VJSONCloner& inCloner) const
{
    VError err = VE_OK;

    VJSONArray *clone = new VJSONArray;
    if (clone != NULL)
    {
        VectorType clonedVector = fVector;

        for( VectorType::iterator i = clonedVector.begin() ; (i != clonedVector.end()) && (err == VE_OK) ; ++i)
        {
            if (i->IsObject())
            {
                VJSONObject *theOriginalObject = RetainRefCountable( i->GetObject());
                err = inCloner.CloneObject( theOriginalObject, *i);
                VJSONGraph::Connect( &clone->fGraph, *i);
                ReleaseRefCountable( &theOriginalObject);
            }
            else if (i->IsArray())
            {
                VJSONArray *theOriginalArray = RetainRefCountable( i->GetArray());
                err = theOriginalArray->Clone( *i, inCloner);
                VJSONGraph::Connect( &clone->fGraph, *i);
                ReleaseRefCountable( &theOriginalArray);
            }
        }

        if (err == VE_OK)
            clone->fVector.swap( clonedVector);
    }
    else
    {
        err = VE_MEMORY_FULL;
    }
    outValue.SetArray( clone);
    ReleaseRefCountable( &clone);

    return err;
}
Ejemplo n.º 10
0
ResultType matrixByVector(const MatrixType& m,const VectorType& u){
  ResultType result(m.numberOfRows(),true);
  if(m.numberOfColumns()!=u.dimension())
    throw std::range_error("operator Matrix*Vector: incompatible dimensions");

  typename ResultType::iterator b=result.begin(), e=result.end();
  typename MatrixType::const_iterator i = m.begin();
  while(b!=e)
  {
    typename ResultType::ScalarType x = chomp::TypeTraits<typename ResultType::ScalarType>::zero();
    typename VectorType::const_iterator bv=u.begin(), be=u.end();
    while(bv!=be)
    {
      x += (*bv) * (*i);
      ++bv;
      ++i;
    }
    *b=x;
    ++b;
  }
  return result;
}
Ejemplo n.º 11
0
 void erase_if(VectorType& vec, Pred pred)
 {
     const auto new_end = remove_if(vec.begin(), vec.end(), pred);
     if (new_end != vec.end())
         vec.erase(new_end);
 }