Boost logo

Ublas :

From: Manoj Rajagopalan (rmanoj_at_[hidden])
Date: 2008-05-08 16:44:44


Hi Ian,

   The vector-scalar addition function would add flexibility but it
might interfere with others to who the strict definition matters. Take
for example the Clifford algebra case that was mentioned a few emails ago.

   In any case, for our individual applications we can use the
fundamental theorem of software engineering and write the operator for
our respective applications in a few minutes. However, if it is present
in ublas, bypassing this is a difficult task.

   For breadth-of-adoption reasons, the fewer assumptions a library like
ublas makes about adopting non-standard conventions for the sake of
convenience, the better.

cheers!
Manoj

Ian Fellows wrote:
> Paul,
> I think that it would be useful to have a vector-scalar addition function. Not every application of matrix algebra is a strict representation vector spaces over fields. I doubt that it would cause anyone any confusion to include the operator, and it would add a bit of flexibility. The same goes for matrix scalar addition.
>
> Ian
>
> -----Original Message-----
> From: ublas-bounces_at_[hidden] [mailto:ublas-bounces_at_[hidden]]On Behalf Of Paul C. Leopardi
> Sent: Tuesday, April 29, 2008 4:23 PM
> To: ublas mailing list
> Subject: Re: [ublas] add value to each element in a vector
>
> Hi Johan,
> My reply is below.
> On Tue, 29 Apr 2008, Johan Compen wrote:
>> On Mon, Apr 28, 2008 at 5:41 PM, Andreas Klckner
>>
>> <lists_at_[hidden]> wrote:
>>> On Montag 28 April 2008, Johan Compen wrote:
>>> > Hi,
>>> >
>>> > I'm using the vector and matrix classes in Boost to convert some
>>> > Matlab code to C++. I'm having troubles with this code:
>>> >
>>> > typedef boost::numeric::ublas::vector<double> Vector_t;
>>> > Vector_t a(3);
>>> > a(0) = 0; a(1)=1; a(2)=2;
>>> >
>>> > Vector_t b = a * 0.5; //works
>>> > Vector_t c = a + 0.5; //compiler error
>>> >
>>> > error C2678: binary '+' : no operator found which takes a left-hand
>>> > operand of type 'Vector_t' (or there is no acceptable conversion)
>>> >
>>> > How can I solve this? How can I add a constant value to each element
>>> > in a vector?
>>>
>>> c = a + scalar_vector<double>(a.size(), 0.5);
>> Ok this works, but why isn't there an operator+ that adds a constant
>> value to each element in a vector?
>> It seems inconsistent to me that this works
>> Vector_t b = a * 0.5;
>> but this doesn't
>> Vector_t c = a + 0.5;
>>
>> Johan.
>
> Understandable from your point of view.
>
> The abstract definition of a vector space over a field (in mathematics, not
> necessarily in uBLAS) includes the operations of addition of two vectors and
> multiplication by an element of the field, but does not define the addition
> of a vector and a field element.
>
> In Clifford algebras over a field, the addition of a vector and a field
> element is defined, but it does something different from what you would
> expect, because the field element 1 is different from the vector of all ones.
>
> So while it might be useful for uBLAS to have an operator+ with the definition
> you expect, it isn't really any more consistent to do so.
> Best, Paul
>
>
> _______________________________________________
> ublas mailing list
> ublas_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/ublas
>
>