Boost logo

Ublas :

Subject: [ublas] Howto convert std::vector to Ublas Vector
From: Gundala Viswanath (gundalav_at_[hidden])
Date: 2009-02-01 23:03:15


Dear all,

Is there a way to do it?
Why my code below can compile but can't execute?
Is there a right way to do it

//___ BEGIN__
#include <iostream>
#include <vector>
#include <boost/numeric/ublas/vector.hpp>
#include <boost/assign/std/vector.hpp>
#include <vector>
#include <stdio.h>
#include <stdlib.h>
using namespace boost::assign;
using namespace std;
namespace ublas = boost::numeric::ublas;

int main() {
   std::vector <double> theP;
    theP += 0.4, 0.2, 0.2, 0.2, 0.2;

    ublas::vector <double> Test;
    for (int i = 0; i < theP.size(); i++) {
        Test(i) = theP[i];
    }
}
// End

The error it gave is this:
Check failed in file
/opt/local/include/boost/numeric/ublas/storage.hpp at line 195:
i < size_
terminate called after throwing an instance of
'boost::numeric::ublas::bad_index'
  what(): bad index

- Gundala Viswanath
Jakarta - Indonesia