|
Ublas : |
From: glen stark (stark_at_[hidden])
Date: 2005-02-17 12:26:31
ublas-request_at_[hidden] wrote:
>>>I think this is a good way to go. If you like the = syntax you can define
>>> operator= (scalar_vector<double> v, double s)
>>> {
>>> v = scalar_vector<double> (v.size(), s);
>>> }
>>>A good compiler should turn this into efficient code.
>>>
>>>
>>Unfortunately, operator=() must be a member function.
>>
>>fres
>>
>>
Well, I copy and pasted the wrong code segment, so it must have been
late for me too :P...
I meant to post this:
BOOST_UBLAS_INLINE
scalar_vector &operator = (const value_type& v){
value_ = v;
return *this;
}
Which maybe is more understandable. Instead I posted some part of the
vector header I dont' understand myself. This just overloads = operator
in an obvious way for a scalar vector.
So, I don't think supporting scalar_vector=value_type is a bad idea,
but I don't mind seing it done as a set(value_type) function, which
could also be used to set all members of a dense vector (or matrix for
that matter) to a particular value. Wasn't there some discussion on the
list earlier about needing a way to initialize matrix elements anyway?
My two cents worth regarding syntax: I think it would be elegant to
overload the = operator for all matrix and vector types, where all non
zero elements are set to rhs. For banded, diagonal, or sparce
matricies, I would expect this to set all non zero elements to the rhs.
I don't have a strong opinion about the syntax, but I think this is
functionality that should be implemented, and ought not to be difficult
to do. Certainly I could pull it off for scalar and dense vectors. Who
makes the executive decision on these things? Is it Joerg? I'm willing
to try submitting a patch if the syntax is agreed on.
Glen