
Ublas : 
From: Gunter Winkler (guwi17_at_[hidden])
Date: 20060424 08:52:48
On Monday 24 April 2006 12:53, Russell Coggrave wrote:
> I recently successfully implemented binary relational operators for vector
> and matrix expressions that model the following
>
> V3 = lt( V1, V2 )
> where
> V3[i] = (V1[i] < V2[i])
> and the value_type for V3 is vector_expression<bool>
>
> However, I would like to extend this to a more general implementation as
> follows:
>
> V3 = lt_quad( V1, V2, r1, r2 )
> where
> V3[i] = (V1[i] < V2[i]) ? r1 : r2
> and the value_type for V3 is is
> promote_type<r1::value_type,r2::value_type>.
I did not read your code, yet, but what application do you have in mind?
I'd like to suggest another way: Generalize the operator.
v3 = elementwise_binary_op< OP >(v1, v2)
which returns
v3[i] = OP(v1, v2)
and OP can be any functor (like e.g. scalar_multiplies). Then you can use
MY_OP::operator()(x1, x2) { return (x1 < x2) ? r1 : r2; }
Of course this only works if you know r1 and r2 at compile time.
mfg
Gunter