Good remark indeed.

I wonder what kind of optimization gcc or llvm will do on that ?
I'm not sure they will be able to infer that A(i)(k,l) is a good replacement for accessing the matrix: I mean, I'm not sure if they will find the right overloaded operator. In that case, it would cost a copy of a matrix, which can be pretty expensive.

Do someone know better on that topic ?

Cheers,
David


On Sat, Aug 6, 2011 at 14:12, Ralf Philipp Denzer <Ralf.Denzer@web.de> wrote:
Hello Yajima,

just a remark: you can access the component (k,l) of the i-th matrix A(i)
directly by, e.g. 

A(i)(k,l) = 1.0;

So, it's not necessary to introduce 'local' matrices b and/or c. But it's
not wrong to do so.

Bye

Ralf 



On 08/04/2011 05:40 PM, Masanao Yajima wrote:
Hi Ralf

That is exactly what I was looking for.
Your code worked perfectly.
Thank you so much!

Cheers

Yajima

On Thu, Aug 4, 2011 at 12:33 AM, Ralf Philipp Denzer <Ralf.Denzer@web.de> wrote:
Hello Yajima,

you can do something like

ublas::vector<ublas::matrix<double> > A;

I.e.:

ublas::vector<dmatrix> A;
A.resize(10);   // vector containing 10 ublas::matrices

for( int i=0;i<10;i++){
  dmatrix b(10,10);
  set values to b;
 
  // set the correct size of matrix A(i)
  A(i).resize(b.size1(), b.size2());
  A(i) =b;
}

That should work ... (not tested)

You can use also:
std::vector<ublas::matrix<double> > A;
or
std::map<int, ublas::matrix<double> > A;
or other containers ...
Depends what you prefer ...

Bye

Ralf






On 08/04/2011 01:03 AM, Masanao Yajima wrote:
Hi List

Is there away to create a "set" of ublas matrix.
(by set I mean it in the most abstract way)

I would like to create bunch of matrix<double> and store it in some form of a data structure
then retrieve them by an index and use it as a matrix<double>.

Here is a vague pseudo code for what I would like to do

something A;
for( int i=0;i<10;i++){
  dmatrix b(10,10);
  set values to b;
  A(i) =b;
}

//then use it as

for( int i=0;i<10;i++){
  dmatrix c = A(i); 
  do calculation with c
}

Or if you have better way to do something similar, I'd appreciate your input.

Thank you for your help.

Cheers
Yajima
_______________________________________________ ublas mailing list ublas@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/ublas Sent to: Ralf.Denzer@web.de


_______________________________________________
ublas mailing list
ublas@lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/ublas
Sent to: yajiyajijp@yahoo.co.jp



--
Masanao Yajima
_______________________________________________ ublas mailing list ublas@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/ublas Sent to: Ralf.Denzer@web.de


_______________________________________________
ublas mailing list
ublas@lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/ublas
Sent to: david.bellot@gmail.com