Example #1
0
typename T1::ScalarType scalarProduct(const T1& v1,const T2& v2)
{
  if(v1.dimension()!=v2.dimension())
    throw std::range_error("chomp::vectalg::scalarProduct: Incompatible dimensions");
  typename T1::ScalarType result(0);
  typename T1::const_iterator b1=v1.begin();
  typename T2::const_iterator b2=v2.begin(), e2=v2.end();
  while(b2!=e2)
  {
    result += (*b1) * (*b2);
    ++b1;
    ++b2;
  }
  return result;
}
Example #2
0
bool equal (const T1& v1, const T2& v2)
{
  if(v1.dimension()!=v2.dimension())
    throw std::range_error("chomp::vectalg::equal: Incompatible dimensions");
  typename T1::const_iterator b1=v1.begin(), e1=v1.end();
  typename T2::const_iterator b2=v2.begin();
  
  while(b1!=e1)
  {
    if(!(*b1 == *b2))
       return false;
    ++b1;
    ++b2;
  }
  return true;
}
Example #3
0
ResultType subtractObjects(const T1& v1,const T2& v2)
{
  if(v1.dimension()!=v2.dimension())
    throw std::range_error("chomp::vectalg::subtractObjects: Incompatible dimensions");
  ResultType result(v1.dimension(),true);
  typename ResultType::iterator b=result.begin(), e=result.end();
  typename T1::const_iterator b1=v1.begin();
  typename T2::const_iterator b2=v2.begin();
  while(b!=e)
  {
    *b = (*b1) - (*b2);
    ++b;
    ++b1;
    ++b2;
  }
  return result;
}