0

Why I cannot read ublas vectors from a binary file in a way like (instead of reading by one element at a time):

boost::numeric::ublas::vector<double> floatVector(10);
myFile.read( (char *)&vector, 10 * sizeof(double));

Is there a way to initialize ublas vector from the array?

double d[10];
Alexander
  • 847
  • 1
  • 9
  • 18

1 Answers1

0

You can use something like this

   double array[] = {1., 2., 3.};
   boost::numeric::ublas::vector<double> v(sizeof(array) / sizeof(*array));
   std::copy(array, array + sizeof(array) / sizeof(*array), v.data().begin());
ForEveR
  • 55,233
  • 2
  • 119
  • 133