Boost logo

Ublas :

Subject: [ublas] Using uBlas and Boost Accumulators
From: Jeremy Conlin (jeremit0_at_[hidden])
Date: 2009-01-26 13:30:50


Does anyone have any experience with using Boost Accumulators with uBlas
vectors? I can compile a simple example, but when it is run I get errors
about mismatched size types. If anyone has any insight, I would appreciate
the assistance. I have copied the output and my code below.
Thanks,
Jeremy

Output:
===========
Testing/learning the Boost Accumulator library.
Mean = 3
Variance = 2

Now trying with uBlas vectors.
vec: [5](1,1,1,1,1)
vec*2: [5](2,2,2,2,2)
Check failed in file ./boost/numeric/ublas/vector_expression.hpp at line
548:
size1 == size2
terminate called after throwing an instance of
'boost::numeric::ublas::bad_argument'
  what(): bad argument

Code:
==============
/*test_BoostAccumulator.cpp

 This file is used for testing/learning about Boost.org Accumulator library

*/

#include<iostream>
#include "boost/accumulators/accumulators.hpp"
#include "boost/accumulators/statistics/stats.hpp"
#include "boost/accumulators/statistics/mean.hpp"
#include "boost/accumulators/statistics/variance.hpp"
#include "boost/numeric/ublas/vector.hpp"
#include "boost/numeric/ublas/io.hpp"
#include "libs/numeric/bindings/lapack/test/utils.h"

using std::cout;
using std::endl;

namespace accumulate = boost::accumulators;
namespace ublas = boost::numeric::ublas;

void WithUBlas();

int main(){

    cout << "Testing/learning the Boost Accumulator library." << endl;

    accumulate::accumulator_set<double,
        accumulate::stats<accumulate::tag::mean,
            accumulate::tag::variance(accumulate::lazy)> > acc;

    // Add some data
    for( int i = 0; i < 5; ++i ) acc(i+1);

    // Display results
    cout << "Mean = " << accumulate::mean(acc) << endl;
    cout << "Variance = " << accumulate::variance(acc) << endl;

    WithUBlas();
    return 0;
}

void WithUBlas(){
    cout << "\nNow trying with uBlas vectors." << endl;

    ublas::vector<double> vec(5,1.0);
    cout << "vec: " << vec << endl;
    cout << "vec*2: " << vec*2 << endl;

    accumulate::accumulator_set<ublas::vector<double>,
        accumulate::stats<accumulate::tag::mean> > acc;

    // Add some data
    for( int i = 0; i < 5; ++i ) acc( vec*(i+1) );

    // Display results
    cout << "Displaying results\nMean = " << accumulate::mean(acc) << endl;

}