
Ublas : 
From: Jesse Manning (manning.jesse_at_[hidden])
Date: 20080820 17:06:35
also you could do this for the 3 variable constructor:
class vector3 : public ublas::vector<double, ublas::bounded_array<double,3>
>
{
typedef ublas::vector<double, ublas::bounded_array<double,3> >
Base_vector;
public:
// Default construction
vector3 (double x, double y, double z) : Base_vector(3)
{ data()[0] = x; data()[1] = y; data()[2] = z; }
// Construction and assignment from a uBLAS vector expression or copy
assignment
template <class R> vector3 (const ublas::vector_expression<R>& r) :
Base_vector(r)
{}
template <class R> void operator=(const ublas::vector_expression<R>& r)
{
Base_vector::operator=(r);
}
template <class R> void operator=(const Base_vector& r)
{
Base_vector::operator=(r);
}
};
I took this class from the effective ublas wiki and just added the
constructor you wanted.
Link to effective ublas wiki:
http://www.crystalclearsoftware.com/cgibin/boost_wiki/wiki.pl?Effective_UBLAS
On Wed, Aug 20, 2008 at 4:39 PM, Leon Gu <leongu_at_[hidden]> wrote:
> the boost assignment library might be helpful.
>
> an example:
>
> #include <boost/assign/std/vector.hpp>
> std::vector<float> v;
> v += 13.7,15.8,38.1;
> bounded_vector<float, 3> u;
> std::copy(v.begin(), v.end(), u.begin());
>
> Leon
>
>
> Rob McDonald wrote:
>
>> I would like to be able to have a bounded_vector<double, 3> which I can
>> instantiate something like this...
>>
>> typedef bounded_vector<double, 3> vect;
>> vect v = vect(0.0, 1.23, 3.45);
>>
>> This requires a new constructor of the form
>>
>> bounded_vector(T x, T y, T z);
>>
>> Since constructors and the equals operator aren't inherited, I can't just
>> implement this one constructor. And, while I'm at it, I may as well keep
>> the code generic to type, but specific to 3 elements...
>>
>> So, I've copied the code for a bounded_vector from vector.hpp. So far,
>> all I've really done is change the template parameter N to a 3. At this
>> point, I can't figure out how to implement my desired constructor...
>>
>> I need to either 1) access the data directly or 2) use the available
>> interface.
>>
>> I poked around in the source such that 'data () [i] =' looked like it
>> might be promising, but that doesn't seem to work. No combinations of
>> 'this(i) =' or what not have worked either.
>>
>> For 1), I haven't been able to figure out for sure where the data is
>> really stored and if I have access permissions to it.
>>
>> For 2), I haven't been able to figure out how to access the overloaded ()
>> operator in the constructor.
>>
>> Here is one of many failed attempts:
>>
>> BOOST_UBLAS_INLINE
>> bounded_vector3 (T x, T y, T z):vector_type(3){
>> data () [0] = x;
>> data () [1] = y;
>> data () [2] = z;
>> }
>>
>> After I get that working, I have another similar challenge...
>>
>> I would like to be able to assign one of these vectors with a comma
>> delimited list. This is currently done in Blitz++, and I am migrating some
>> code from Blitz to boost::ublas.
>>
>> So, I want to be able to do this....
>>
>> vect v;
>> v = (1.2), (3.5), (7.8); // I'm not sure if the () are significant.
>>
>> Any help will be greatly appreciated,
>>
>> Rob
>>
>>
>> _______________________________________________
>> ublas mailing list
>> ublas_at_[hidden]
>> http://lists.boost.org/mailman/listinfo.cgi/ublas
>>
>>
> _______________________________________________
> ublas mailing list
> ublas_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/ublas
>