Boost logo

Boost :

From: jhrwalter (walter_at_[hidden])
Date: 2002-03-14 05:14:11


--- In boost_at_y..., Kresimir Fresl <fresl_at_g...> wrote:
>
> rwgk wrote:
>
> [...]
>
> > Unfortunately I am having trouble compiling this minimal
> > example:
> >
> > #include <vector>
> > #include <boost/numeric/ublas/config.h>
> > #include <boost/numeric/ublas/vector.h>
> >
> > int main()
> > {
> > numerics::vector<float, std::vector<float> > ua(1000);
> > ua = ua * ua;
> > return 0;
> > }
> >
> > Attached are the minimal patches that I applied to config.h
> > and iterator.h, and the output from two compilers.
> > Advice on how to fix the problems is very much appreciated.
>
> [...]
>
> > gcc 3.0.4 (RedHat 7.1):
> >
> > g++ -fPIC -ftemplate-depth-50 -DUSE_GCC -g -
> > I"/net/cci/rwgk/boost" -c ublas_shared.cpp
> > ublas_shared.cpp: In function `int main()':
> > ublas_shared.cpp:8: ambiguous overload for
`numerics::vector<float,
> > std::vector<float, std::allocator<float> > >& *
> > numerics::vector<float,
> > std::vector<float, std::allocator<float> > >&' operator
>
> [...]
>
> It seems that error messages are misleading. There is
> no ambiguity in your example. Rather, in ublas there is no
>
> operator* (vector<> const&, vector<> const&)
>
> or, more precisely,
>
> operator* (vector_expression<> const&,
> vector_expression<> const&)
>
> My guess is that authors decided not to provide this operator
> because it is not clear whether it denotes inner product
> or elementwise multiplication.

This is also an issue of MSVC compatibility.
 
> `operator*()' can only be used to multiply vectors (and matrices)
> with scalars. (So, you can change the test operation to
> `ua = 2. * ua;'. Or, you can use `+' or `-'.)
>
> To compute inner product you must use function `inner_prod()'.
>
> As far as I know, there is currently no way to do elementwise
> multiplication. Strictly speaking, this is not linear algebra
operation,
> but I hope that authors will in some future version add some means
> to do this and similar array operations (eg. apply some function to
> all elements in a vector).

I see two alternatives to extending ublas: element-wise operations
could be a nice extension of boost.multi_array. Or one could use
something like the expression templated valarray<> of gcc (but I'm
unsure, if valarray<> is a legal array_type of numerics::vector
currently ;-).
 
Regards
 
Joerg


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