Boost logo

Ublas :

Subject: [ublas] Converting Fortran 90 array access to use Matrix?
From: Reich, Darrell (DARRELL.REICH_at_[hidden])
Date: 2014-01-08 20:05:45

What is the most efficient way to convert Fortran's column array access
like shown below to C++?

a(i,:) = 0 ! set entire column to zero


I suspect best solution might use matrix proxies like matrix_row?

Can this be done on one line without the for loop?

Can you help me fix the syntax on the commented out code that attempted
to use iterators?


#include "boost/numeric/ublas/matrix.hpp"

#include "boost/numeric/ublas/matrix_proxy.hpp"

#include "boost/numeric/ublas/io.hpp"


int main()


   const int N = 3;

   boost::numeric::ublas::matrix<double> M(N,N,1.0);

> row1(M,1);



   //??how to set the matrix row to zero on one line like Fortran 90

   //for (mit = row1.begin(); mit != row1.end(); ++mit)

   //for_each(row1.begin(), row1.end(), [] (const std::unique_ptr<??>&

   for (int i = 0; i < row1.size(); ++i) // not i++

      row1(i) = 0.0;


   std::cout << "row = " << row1 << std::endl;

   std::cout << "Matrix = " << M << std::endl;


   return N;