Converting Fortran 90 array access to use Matrix?

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Converting Fortran 90 array access to use Matrix?

Reich, Darrell-2

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);

   boost::numeric::ublas::matrix_row<boost::numeric::ublas::matrix<double> > row1(M,1);

   //??std::vector<boost::numeric::ublas::matrix<double>*>::iterator mit;

 

   //??how to set the matrix row to zero on one line like Fortran 90 a(1,:)=0.0

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

   //for_each(row1.begin(), row1.end(), [] (const std::unique_ptr<??>& 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;

}

 

 


_______________________________________________
ublas mailing list
[hidden email]
http://lists.boost.org/mailman/listinfo.cgi/ublas
Sent to: [hidden email]
Reply | Threaded
Open this post in threaded view
|

Re: Converting Fortran 90 array access to use Matrix?

Hartley, Bob-2
Does subrange not do what you want?

<snippet... it should be mostly readable...>

  (...input matrix a of size nxn )

  int n = a.size2();
  int size = 2*n;

  boost::numeric::ublas::matrix<double>p(size,size);

  boost::numeric::ublas::subrange(p, 0,n,    0,n)    = -trans(a);
  boost::numeric::ublas::subrange(p, 0,n,    n,size) = ublas::zero_matrix<double>(n,n);
  boost::numeric::ublas::subrange(p, n,size, 0,n)    = temp * dt;
  boost::numeric::ublas::subrange(p, n,size, n,size) = a;


Bob the amateur.

________________________________________


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?


_______________________________________________
ublas mailing list
[hidden email]
http://lists.boost.org/mailman/listinfo.cgi/ublas
Sent to: [hidden email]
Reply | Threaded
Open this post in threaded view
|

Re: Converting Fortran 90 array access to use Matrix?

Reich, Darrell-2
In reply to this post by Reich, Darrell-2
Good answer! I didn't realize from the nerdy / cryptic documentation
pages that subrange could be used on the LHS (an L-value). When this
project is over, I really should collect up a few examples and post them
for boost ublas newbies on how to use the library. The current
documentation assumes more of a computer science / linear algebra PhD
background. Anyway, once you get it, more fun that C arrays.

I promote you to Bob the advanced beginner IMHO. I was looking in the
right place but close only counts in horseshoes...

Thanks!
Darrell the rookie apprentice

-----Original Message-----
From: Hartley, Bob [mailto:[hidden email]]
Sent: Thursday, January 09, 2014 9:49 AM
To: [hidden email]
Subject: Re: [ublas] Converting Fortran 90 array access to use Matrix?

Does subrange not do what you want?

<snippet... it should be mostly readable...>

  (...input matrix a of size nxn )

  int n = a.size2();
  int size = 2*n;

  boost::numeric::ublas::matrix<double>p(size,size);

  boost::numeric::ublas::subrange(p, 0,n,    0,n)    = -trans(a);
  boost::numeric::ublas::subrange(p, 0,n,    n,size) =
ublas::zero_matrix<double>(n,n);
  boost::numeric::ublas::subrange(p, n,size, 0,n)    = temp * dt;
  boost::numeric::ublas::subrange(p, n,size, n,size) = a;


Bob the amateur.

________________________________________


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?



_______________________________________________
ublas mailing list
[hidden email]
http://lists.boost.org/mailman/listinfo.cgi/ublas
Sent to: [hidden email]