Boost logo

Ublas :

From: Shawn D. Pautz (sdpautz_at_[hidden])
Date: 2005-08-19 15:00:15

I understand how to use inner_prod with ublas::vectors of intrinsic
types, such as vector<double>:

ublas::vector<double> vec1, vec2;
// assign values to vec1, vec2
double result = inner_prod(vec1, vec2);

Is there a way to use inner_prod (or something similar) for vectors of
more complicated types? I would like to form the inner product of a
vector<double> and a vector<matrix<double> >, with the following semantics:

vector<double> vec;
vector<matrix<double> > vecOfMatrices;
matrix<double> result; // = 0
// result = inner_product(vec, vecOfMatrices); // won't compile
for (int i = 0; i < vec.size(); ++i)
  result += vec[i]*vecOfMatrices[i];

What's the best way to perform the above operation without resorting to
writing loops?

Shawn D. Pautz
Simulation Technology Research, MS 1179
Sandia National Laboratories
P.O. Box 5800
Albuquerque, NM 87185
Phone: 505-284-4291
Fax: 505-844-0092
E-Mail: sdpautz_at_[hidden]