
Ublas : 
From: Russ (c.r.coggrave_at_[hidden])
Date: 20060424 10:05:39
Gunter Winkler <guwi17 <at> gmx.de> writes:
>
> 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
I quite agree it would be nice to generalise this, but in the first instance I
am trying to get a concrete example working :)
However, you have given me an idea where I might be going wrong...
I was assuming that the first hurdle is to get vector_expression<E> that stores
4 arguments. At the moment the most complicated example in the library is
vector_binary that stores 2 arguments. This is where vector_quad_relop comes in,
since it is able to store 4 arguments. This implementation is assuming that r1
and r2 ARE NOT known at compile time and need to be stored by the
vector_expression<E>.
However, now I think of it in terms of functors, if we consider the situation
where r1 and r2 ARE known at compile time then I can probably reuse
vector_binary<E1,E2,F> using a fuctor F that takes four arguments. This might be
easier to implement and get going, but not as general. I think I should try and
get this working before tackling the more general case above.
Does that sound right?
Regards,
Russ