|
Ublas : |
Subject: Re: [ublas] Assignement operation proposal.
From: Jesse Perla (jesseperla_at_[hidden])
Date: 2010-04-11 13:13:47
Nasos Iliopoulos <nasos_i <at> hotmail.com> writes:
> Dear all,based on the comments by Gunter
> and David, I modified and uploaded the new version of the assignment operator
(together with unit tests, examples, documentation and benchmarks). A
description of the changes can be found here
Wow. This is great. It solves not only the assignment problem, but also
the issues of stacking matrices/vectors a la matlab( e.g. [A; B;], etc.)
The following questions are without testing the code, so apologies if I have
missed something in reading the examples:
1) Since the assignment is a matrix/vector expression, it looks like you could
cool things such as the following type of usage possible/efficient?:
template<typename MatrixType>
ublas::matrix<double> func1(const MatrixType& mat) //or matrix_expression<>
{
return 2 * mat; //This wouldn't work in the current code since only <<=?
}
ublas::vector<double> v1(3);
v1 <== 1, 2, 3;
ublas::vector<double> v2(3);
v1 <== 1, 2, 3;
ublas::matrix<double> m = func1( (v1, v2) ); //Passes in stacked expression?
2) It would also be nice to be able to pass stacked vectors back in functions
Is this kind of thing possible, and maybe even efficient with RVO and
move semantics?
template<typename Vec1, typename Vec2>
ublas::matrix<double> func2(const Vec1& vec1, const Vec2& vec2)
{
return (2 * vec1, vec2); //i.e stacks doubling first vector first
}
// here func2(v1, v2) -> [2 4, 6; 1 2 3]
ublas::matrix<double> mat2 = func2(v1, v2);
.... It doesn't look like these are possible right now since it is the
<== overloaded instead of the =, but thought I would bring them up as a
possible use case. They come up quite often in my code.