Boost logo

Boost Users :

From: speedsnaii speedsnaii_at_[hidden])
Date: 2003-02-26 17:26:24


Hi Joerg,

> OK, I think I understand now what you're aiming at: you want ublas
to give
> you the characteristics of (ordinary ;-) runtime polymorphism. But
would you
> be willing to pay the performance penalty for using an virtual
operator()
> then, for example?

I think generally not.
Hmmm, but is there a way to do without? After a lot of reading and
thinking and with your help :-) I came out with the following. May I
show you a code snippet from my spline function to show you my actual
problem?
================================================================
template<class T>
class vector_proxy_base {
    public:
        virtual T operator[] (unsigned int idx) = 0;
};

template<class E>
class vector_proxy : public vector_proxy_base<E::value_type>
{
    public:
        vector_proxy(vector_expression<E> e) : m_e(e) {}
        typename E::value_type operator[] (unsigned int idx)
        { return m_e().operator[](idx); }
    private:
        vector_expression<E> m_e;
};

template<class T>
class spline : public std::unary_function<T, T> {
public:
    template<class E>
        spline(vector_expression<E> e) : ex(new vector_proxy<E>(e)) {}
    ~ppi0() { delete ex; }
    T operator() (const T& x){
        // the spline interpolation algorithm goes here ...
        return ex->[0]; // do something useful ;-)
        // ugly, indirection and virtual function call
    }
private:
    vector_proxy_base<T>* ex;
};
================================================================

I can not see a way to do this differently, since otherwise I would
need to
template<class T, class E>
class spline {
....
}

where E is the expression type.
But instantiating the functor then would be infeasible since I do not
know the complete expression hierarchy, or at least it is too
cumbersome to specify. The automatic template parameter deduction
does not work for class templates as it does for funtion templates,
does it?

What yet is missing of course are all the other member functions that
make a vector or matrix.

Perhaps there is a simpler solution I do not see?

>
> vector_reference<> is mainly needed to describe the signatures of
operators
> returning expression templates.
>

I was trying to
template<class E>
void foo(vector_reference<E> e)
{
    e.size(); // some use of e
}

and call it
foo(m.column(0));

But my compiler chokes. So am I right, that vector_reference is not
intended for this kind of usage?

>
> groups.yahoo.com/group/ublas-dev
>

Oh, I may read this as an ordinary user? Didn't try this yet. Thank
you for the hint.

BTW.: I've delayed the idea of COW (Copy On Write?) This was before I
realized that vector_expression is kind of a reference to my data.

Regards,
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