Boost logo

Ublas :

Subject: [ublas] compressed_matrix resize and matrix_indirect assignment
From: Umut Tabak (u.tabak_at_[hidden])
Date: 2011-04-26 17:22:36


Dear all

With the below, code I try to extract a submatrix from a compressed
matrix, if I would like to assign the result to a resized form of the
original compressed matrix, I get only zeros in the matrix. If I create
another compressed matrix and assign onto that, then the result seems to
be ok. resize function of the compressed_matrix takes a preserve
parameter which is true by default, however I would like to set that to
false for this operation for write, however that does not seem to work
as expected. I could not understand this. Could someone clarify this
point for me? Basically I am trying to apply the boundary conditions on
an assembled FE matrix by use of indirect_matrix. Other suggestions to
accomplish this task efficiently are also welcome.

Best,
Umut

#include <iostream>

#include "boost/numeric/ublas/matrix_sparse.hpp"
#include "boost/numeric/ublas/matrix_proxy.hpp"
#include "boost/numeric/ublas/io.hpp"
#include "boost/numeric/ublas/storage.hpp"
#include "boost/numeric/ublas/storage_sparse.hpp"

using boost::numeric::ublas::indirect_array;
using boost::numeric::ublas::compressed_matrix;
using boost::numeric::ublas::matrix_indirect;

using namespace std;

int main()
{
   compressed_matrix<double> m (3, 3, 3 * 3);
   for (unsigned i = 0; i < m.size1 (); ++ i){
     for (unsigned j = 0; j < m.size2 (); ++ j)
       m (i, j) = 3 * i + j;
   }
   cout << m << endl;
   int iarr[] = { 1,2 };
   indirect_array< vector<int> > ia( iarr, iarr+2 );
   matrix_indirect<compressed_matrix<double>, indirect_array<vector<int>
> > k(m, ia,ia);
   compressed_matrix<double> m1(2,2);
   //m.resize( 2,2,false);
   //m.assign(k);
   m1.assign(k);
   cout << m1 << endl;
   //cout << m << endl;
   return 0;
}