Boost logo

Ublas :

Subject: Re: [ublas] todo list
From: Nasos Iliopoulos (nasos_i_at_[hidden])
Date: 2010-07-24 23:37:02


Matwey,

> However, there is one more well-known option:
Sure, I am using SVD as an example for the interface and not to describe the best implementations for SVD. This of course has its value when we talk about the SVD itself.

> I can't understand third option because a function can't be overloaded by
> returned type.

take a look at Jesse's implementation for "tie" in trac:
https://svn.boost.org/trac/boost/ticket/4436

this can be generalized to achieve "referenced return" or sort of. Imagine for example:

template <class T>
class svd_impl{
template <class T>
svd_impl(T &Mat): A(Mat) { }
apply1(T &S) {
// Cunmpute S only
}
apply2(T &Q, T &W) {
// equivallent svd(Q, A, W) called like tie(Q,W) = svd(A); with A:=S
}
apply3(T &U, T &S, T &V) {

// Compute all

}
private:
T &A;
};

template <class T>
svd_impl<T> svd(T &A) {
  return svd_impl(A);
}

And then the "tie" operator = can call apply1 if tie is called with one argument apply2 if it is called with 2 or apply3 if it is called with 3 arguments.

overall, you will be able to do things like:
S = svd(A);
tie(Q,W) = svd(A);
tie(U, S, V) = svd(A);

I think the above interface is achievable, expressive and well situated with linear algebra algorithms.

Best
Nasos

> To: ublas_at_[hidden]
> From: matwey.kornilov_at_[hidden]
> Date: Sat, 24 Jul 2010 23:57:39 +0400
> Subject: Re: [ublas] todo list
>
> Nasos Iliopoulos wrote:
>
> > To recapitulate my view is that we should provide custom implementations,
> > open the development as possible so that people can contribute (maybe make
> > an easy to access branch for all), and most importantly first define the
> > interface it should have. The interface choices that come into my mind are
> > the following (I will take SVD as an example): 1. Procedural:
> > svd(A,U,S,V); 2. Functional - procedural: S = svd(A,U,V); 3. tieable:
> > tie(U, S, V) = svd(A); tie(S) = svd(A); //or just S=svd(A); 4.
> > Classical/or stl like: SVD(A.begin<1>(), A.end<1>(), S.begin<1>(),
> > U.begin<1>(), V.begin<1>()) (ugly uh? fairly generic though).
> >
> >
> > Overall I would vote for (3), but we need first to implement the "tie"
> > interface.
>
> I can't understand third option because a function can't be overloaded by
> returned type.
>
>
> However, there is one more well-known option:
>
> void svd( Q, A, W ); // A := S, Q := U^T Q, W := W V
>
> This is for memory economy. When we want to solve linear set Ax=y by means
> of SVD decomposition we write
>
> A=USV^T =>
> USV^Tx=y =>
> SV^Tx=U^Ty =>
> x=V S^{-1} U^T y
>
> and we see that (U^T y) can be calculated from y at place instead of
> calculation U and performing matrix multiplication. Imagine that y is big
> enough (say, 100), consequently U should be 100x100.
>
>
>
> _______________________________________________
> ublas mailing list
> ublas_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/ublas
> Sent to: nasos_i_at_[hidden]
                                               
_________________________________________________________________
Hotmail is redefining busy with tools for the New Busy. Get more from your inbox.
http://www.windowslive.com/campaign/thenewbusy?ocid=PID28326::T:WLMTAGL:ON:WL:en-US:WM_HMP:042010_2