Boost logo

Ublas :

Subject: Re: [ublas] submatrix with indexvector
From: Ralf Denzer (Ralf.Denzer_at_[hidden])
Date: 2010-07-23 02:48:08


Hallo Philipp,

yes, something very similar works:
Please check  indirect_array<> in ublas/storage.hpp
It's not well documented, but works since long time.

Something like the following should work:

//----------------------------
namespace ublas = boost::numeric::ublas;

const unsigned N = 7;
ublas::matrix<int> A(N,N);
ublas::vector<int> V(N);

... fill matrix A and vector V here ...

// define an indirect_array
const unsigned n = 3;
ublas::indirect_array<> ia(n);
ia[0] = 1;
ia[1] = 2;
ia[2] = 4;

// ia(n) to extract some indices
ublas::matrix_indirect<ublas::matrix<int> > Mindirect(M, ia,ia);
std::cout << "Mindirect=\n" << Mindirect << std::endl;

// or use ublas::project
std::cout << "Mprojected=\n" << ublas::project(M, ia, ia) << std::endl;

// similar for vectors
ublas::vector_indirect<ublas::vector<int> > Vindirect(V,ia);
std::cout << "Vindirect=\n" << Vindirect << std::endl;

// and
std::cout << "Vprojected=\n" << ublas::project(V, ia) << std::endl;

//----------------------------

Thus, with 'ublas::indirect_array<> indexvector' you should be able
to peform exactly your operation

project(x, indexvector, indexvector) += other matrix with indexvector.size x indexvector.size

Bye

Ralf

PS: Thanks to David, at least
ublas::matrix_indirect and ublas::vector_indirect
is now a bit documented. See http://ublas.sourceforge.net/refdoc/


 
Hello,

can I extract a submatrix from a ublas::matrix with an indexvector? I've got a ublas::vector with index values and a ublas::matrix(1000,1000). The indexvector holds only 12 index position and I need something like:

ublas::matrix x(1000,1000);
project(x, indexvector, indexvector) += other matrix with indexvector.size x indexvector.size

I must cut a submatrix which is not continously and adds another matrix.  Are there any boost operations or should I run over all elements?

Thanks

Phil
  

Neu: WEB.DE De-Mail - Einfach wie E-Mail, sicher wie ein Brief!    
Jetzt De-Mail-Adresse reservieren: https://produkte.web.de/go/demail02