|
Boost Users : |
From: speedsnaii
Date: 2003-02-27 14:39:11
Hi Joerg,
> Yep. Here it goes:
> ----------
> #include <boost/numeric/ublas/vector.hpp>
> using namespace boost::numeric::ublas;
> template<class T, class E>
> class spline : public std::unary_function<T, T> {
> public:
> spline(const vector_expression<E> &e) : e_ (e) {}
> T operator() (const T& x){
> // the spline interpolation algorithm goes here ...
> return e_ (0); // do something useful ;-)
> }
> private:
> const vector_expression<E> &e_;
> };
> int main() {
> vector<double> v(3);
> spline<double, vector<double> > s1(v);
> // With GCC's extensions the following works :-)
> spline<double, typeof (v) > s2(v);
> }
>
> ----------
Exactly. This is what I was thinking of. But as I understand now it
probably is not such a good idea to keep a reference to an expression
at all. Wouldn't it be reevaluated every time I "arg().(i,j)" i.e?
>
> Maybe as an ordinary user you simply should copy the vector
expression into
> another vector ;-)
>
I was thinking of this already. But now as I know my options and have
a better idea what is going on behind the scenes I am much more
comfortable with this. :-)
So I most certainly will end up like that:
void foo(vector<double> arg)
{
}
matrix<double> m(3,3);
vector<double> v(3);
foo(m.row(0));
foo(v);
And the converting constructor will create my temporary, which I do
need anyway, as I can understand now.
And when I really need to keep a reference to my data (or need to
pass a really huge vector):
template<class T>
void foo(const vector<T>& arg)
{
}
template<class E>
void foo(vector_expression<E> arg)
{
foo(vector<E::value_type>(arg));
}
I can have the above overloads and call the same function with an
expression too.
The more I understand the uBLAS, the more I like it. You have really
done a good job! ( At least this is my opinion from user-land. :-)
Thank you again!
Roland
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net