Boost logo

Ublas :

Subject: Re: [ublas] std::accumulate with vector and matrix
From: Philipp Kraus (philipp.kraus_at_[hidden])
Date: 2010-12-04 03:55:45


On 2010-12-03 22:33:46 +0100, Kraus Philipp said:

> I have a std::vector< ublas::matrix<T> > and std::vector<
> ublas::vector<T> >. How can I use the std::accumulate for summerize
> over the vector. Vector and matrix data have both the same size.
> I would like to create (for example with the vector)
>
> std::vector< ublas::vector<T> > x;
> ublas::vector<T> sum = x[0];
> fill x with data
> for (std::size_t i=1; i < x.size(); ++i)
> sum += x[i];
>
> I wouldn't use a loop, so how can I use the std::accumulate?

I solve it myself with:
ublas::matrix<T> x = std::accumulate( l_in.begin(), l_in.end(),
ublas::matrix<T>( out.size1(), out.size2(), 0) );