Hi Jesse,
> 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?:
> ....
> 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?
Those are very nice suggestions!
I will look into it time permitting. From my experience with the assigner classes, a very primitive assessment is the following:
It is possible to overload "operator," on matrices and vectors so that a "stack" object is created, that waits for another vector (or matrix) and stacks back when is assigned, using expression templates (maybe RVO kicks in anyway here). Because though the order of evaluation is not guaranteed for comma operator this overload on matrix and vector types may be problematic and in general comma overloading on types that do other jobs also is generally not recommended. Also a bit more verbose interface maye be needed to signify that this returns a vector or matrix.
I would love to have this feature if the above problem can be faced somehow. Any other ideas of how this suggestion could be implemented would be very helpful.
Maybe an interface like the following is easier, but would probably require implicit conversion from "stack" object to vector or matrix containers (or from the already implemented assigner objects to matrix and vector containers):
return stack() <<= v1, v2;
> <== overloaded instead of the =, but thought I would bring them up as a
> possible use case. They come up quite often in my code.
I thought of overloading operator =, but it didn't look as a good choice, since it would interfere with expression templates.
Very nice suggestions, it would be nice to hear what other people think!
Best
Nasos
> To: ublas@lists.boost.org
> From: jesseperla@gmail.com
> Date: Sun, 11 Apr 2010 17:13:47 +0000
> Subject: Re: [ublas] Assignement operation proposal.
>
> 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.
>
>
> _______________________________________________
> ublas mailing list
> ublas@lists.boost.org
> http://lists.boost.org/mailman/listinfo.cgi/ublas
> Sent to: nasos_i@hotmail.com
Hotmail is redefining busy with tools for the New Busy. Get more from your inbox. See how.