You must give the ublas::vector the correct initial size if you are going to assign to its elements like that
int main() {
std::vector <double> theP;
theP += 0.4, 0.2, 0.2, 0.2, 0.2;
//************** notice how this line has changed *****************/
ublas::vector <double> Test(theP.size());
for (int i = 0; i < theP.size(); i++) {
Test(i) = theP[i];
}
}
// End
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
_______________________________________________
ublas mailing list
ublas@lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/ublas