Boost logo

Boost :

From: Tarjei Knapstad (tarjeik_at_[hidden])
Date: 2002-08-23 10:06:37


On Fri, 2002-08-23 at 14:06, Joerg Walter wrote:

Hi Joerg,

> Hi Tarjei,
>
> you wrote:
>
> > On Tue, 2002-08-06 at 22:41, Toon Knapen wrote:
> > > Are there any component-wise operators available in ublas ?
> > > For instance, I would like to do a element-per-element multiplication of
> two
> > > ublas vectors.
> > >
> > To my knowledge Hadamar products (element-by-element multiplication) are
> > not part of the BLAS specification, which means you'd need to implement
> > it yourself. Shouldn't be too hard, have a look at matrix/vector_et.h.
>
> Indeed, the simplest solution is to use:
>
> // hadamard_prod (v1, v2) [i] = v1 [i] * v2 [i]
> template<class E1, class E2>
> BOOST_UBLAS_INLINE
> typename vector_binary_traits<E1, E2, scalar_multiplies<typename
> E1::value_type,
> typename
> E2::value_type> >::result_type
> hadamard_prod (const vector_expression<E1> &e1,
> const vector_expression<E2> &e2) {
> typedef BOOST_UBLAS_TYPENAME vector_binary_traits<E1, E2,
> scalar_multiplies<BOOST_UBLAS_TYPENAME E1::value_type,
>
> BOOST_UBLAS_TYPENAME E2::value_type> >::expression_type expression_type;
> return expression_type (e1 (), e2 ());
> }
>
> To get more performance, we'd have to extend vector_binary.
>
> Is there a good rationale to extend uBLAS in this direction?
>
> Thanks for your feedback and best regards
>
First of all, have me excused for (yet) not being too familiar with
uBLAS and it's internals, and for taking the liberty to crosspost this
over to the Boost developers list.

I'm a bit unsure if this would be wise. After all, BLAS (to my
knowledge) is a quite strict specification of a set of basic linear
algebra containers and operations. I think uBLAS should remain what it's
name tells, namely that it is an implementation of the BLAS standard,
and that extensions should at least be properly tagged as such, or
maybe/preferably be moved into a separate uBLASExtensions library.

If the extensions needed in vector_binary can not be inserted
efficiently enough through inheritance (or other means), then it would
be the only option to include it in uBLAS. If this means sacrificing
performance (in both ways of speed and resource) with regards to any
operation that is allready in uBLAS it's not an option at all.

If elementwise operations also involve adding/subtracting/etc. a single
scalar to a vector/matrix then my view changes a bit towards extending
uBLAS to at least handle this. If we are just talking of Hadamar
multiplication/division, I think this kind of thing probably belongs in
an extensions library, which leads me to another question. Are there any
plans to make extensions to uBLAS in the direction of a uLAPACK type of
library, which includes matrix decomposition algorithms and the like?

Other opinions are welcome.

Best regards,

-- 
Tarjei Knapstad

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk