|
Ublas : |
Subject: Re: [ublas] Accumulators with vectors
From: Rafael Calsaverini (rafael.calsaverini_at_[hidden])
Date: 2010-12-01 06:45:05
Tried to change the line:
accumulator_set < ublas::vector<double> , stats<tag::mean> > acc;
To:
ublas::vector<double> v0 = ublas::zero_vector<double>(3);
accumulator_set < ublas::vector<double> , stats<tag::mean> >
acc(sample=v0);
And still got the same error. The error occurs when I try to
accumulate: acc(x);.
It seems that the size of the initial vector of the accumulator conflicts
with the size of the vector I want to accumulate. Is there a way to
initialize the accumulator with a vector of a given size?
--- Rafael Calsaverini Dep. de Física Geral, Sala 336 Instituto de Física - Universidade de São Paulo rafael.calsaverini_at_[hidden] http://stoa.usp.br/calsaverini/weblog CEL: (11) 7525-6222 USP: (11) 3091-6803 On Wed, Dec 1, 2010 at 09:27, Rafael Calsaverini < rafael.calsaverini_at_[hidden]> wrote: > I was trying to use vectors with accumulators and someone suggested to use > ublas vectors that have mathematical operators already defined. But when I > tried I got what seems to be a size mismatch error. This is the code I was > trying to use: > > #include <boost/accumulators/accumulators.hpp> > #include <boost/accumulators/statistics.hpp> > #include <boost/accumulators/statistics/stats.hpp> > > using namespace boost::accumulators; > using namespace boost::numeric; > > int main() { > > ublas::vector<double> x(3), y(3), z(3); > > x[0] = 1; x[1] = 1; x[2] = 1; > x[0] = 1; x[1] = 1; x[2] = 2; > x[0] = 2; x[1] = 1; x[2] = 1; > > accumulator_set < ublas::vector<double> , stats<tag::mean> > acc; > > acc(x); > acc(y); > acc(z); > std::cout << mean(acc) << std::endl; > > return 0; > } > > > The error message is: > > Check failed in file > /usr/include/boost/numeric/ublas/detail/vector_assign.hpp at line 262: > size1 == size2 > terminate called after throwing an instance of > 'boost::numeric::ublas::bad_argument' > what(): bad argument > Aborted > > Did any of you succeded/know how to use vectors as variables to accumulate > with boost accumulators? > > --- > Rafael Calsaverini > Dep. de Física Geral, Sala 336 > Instituto de Física - Universidade de São Paulo > > rafael.calsaverini_at_[hidden] > http://stoa.usp.br/calsaverini/weblog > CEL: (11) 7525-6222 > USP: (11) 3091-6803 > >