|
Ublas : |
From: James N. Knight (nate_at_[hidden])
Date: 2006-10-08 17:56:55
Hello all.
I'm trying to implement a concatenation feature as an extension to
ublas. I think this will be generally useful so I wanted to try and get
some input.
A simple method to do this would look something like
concat(A,B,'v')
where
??? concat (...)
{
// verify dimensions of A and B match given
// 'v' or 'h' (vertical or horizontal)
// declare new matrix of correct size
// use project to assign A and B to correct parts
// of new matrix C
if(c = 'v'){
project( C, range(0,A.size1()), range(0,A.size2())) = A;
project( C, range(A.size1(),A.size1()+B.size1()), range(0,B.size2()))
= B;
}
else {
project( C, range(0,A.size1()), range(0,A.size2())) = A;
project( C, range(0,B.size1()),
range(A.size2(),A.size2()+B.size2())) = B;
}
}
This has a big problem though.
If C does not need to be modified (as in D*concat(A,B,'v')) then
creating a new matrix and copying all of the elements is a waste of time
and space.
Anyway, what I'm really thinking is that a better way to do this would
be to create a concat matrix expression that I can lazily evaluate when
needed. The expression would need to join the iterators of the two
component matrices in some way. When evaluated the expression's
iterators would iterate over all of the elements of the contained
matrices. This would allow me to use the concatenation in a constant
way if I want and copy it to a matrix if I want to modify it.
Does this seem feasible?
Is there any interest in something like this?
Any ideas on this are appreciated.
Thanks,
Nate
PS- I have also considered using some special type of matrix that has as
its elements other matrices and uses special iterators to iterate over
all elements of the submatrices. This might be useful beyond the
concatenation scenario.