Boost logo

Ublas :

From: Michael Stevens (mail_at_[hidden])
Date: 2006-11-30 12:34:48


On Thursday, 30. November 2006 13:28, Gunter Winkler wrote:
> On Wednesday 29 November 2006 23:04, Manoj Rajagopalan wrote:
> > closure_type and const_closure_type appear often in ublas class
> > declarations. What does closure mean and why is it required / useful?
>
> This is a quite difficult topic. I never understood the concept in all
> details, but I look at a closure as a mutable or constant reference to
> something. The idea is to have
> a) closure_type ... everything is mutable
> b) const_closure_type ... everthing is const (read: add the const qualifier
> wherever possible)
>
> Is is required or useful: I don't use it, because it never worked the way I
> thought.

The name Closure comes from functional programming languages. I just looked at
  http://en.wikipedia.org/wiki/Closure_(computer_science)
so I should know!!
In principle the uBLAS closure types are not much more then references.
They hold references for the variables that appear in the uBLAS expressions.

So when you write
        prod (a, b)
the expression is converted into a type that represents the binary operator
(product) and referenced to a and b. When you assign this expression to
something
     c = prod (a, b);
the function implementing the prod operator access it's left and right hand
sides using the closure types.

I guess it makes sense to call these types closures as uBLAS expressions are
functional in their nature. In fact the complete uBLAS expressions are really
the closures. They combine code with a binding (as references) to variables
in a function.

In principle you can do stuff like:
       
        matrix_expression<Something complex> pab = prod (a, b);
        change a; change b;
        c = pab;

In this case 'c' is computed using their values after they we changed as uBLAS
expressions use references to a and b.
        
Michael

-- 
___________________________________
Michael Stevens Systems Engineering
34128 Kassel, Germany
Phone/Fax: +49 561 5218038
Navigation Systems, Estimation  and
                 Bayesian Filtering
    http://bayesclasses.sf.net
___________________________________