Boost logo

Boost Users :

From: jhr.walter_at_[hidden]
Date: 2003-06-23 17:05:27


Hi Alexey,

you wrote:

> I am try to use Ublas library and have some questions.
>
> I am want to write next code:
>
> template<class Matrix>
> void ProcessRecursive(Matrix& m)
> {
> typedef matrix_range<typename Matrix::matrix_type> MatrixRange;
> ...
> MatrixRange mr = project(m, range(...), range(...));
> ...
> ProcessRecursive(mr);
> ...
> }
>
> void StartProcess()
> {
> ...
> matrix<double> m;
> ...
> ProcessRecursive(m);
> }

Interesting problem: the naive solution

----------
#include <boost/numeric/ublas/matrix.hpp>

using namespace boost::numeric::ublas;

template<class Matrix>
 void ProcessRecursive(Matrix& m)
 {
   typedef matrix_range<Matrix> MatrixRange;
   MatrixRange mr = project(m, range(0,m.size1()/2), range(0,m.size2()/2));
   if (mr.size1() > 0 && mr.size2() > 0)
     ProcessRecursive(mr);
 }

void StartProcess()
 {
   matrix<double> m;
   ProcessRecursive(m);
 }

int main()
 {
    StartProcess();
 }

----------

doesn't terminate to compile ;-)

> But I have not enough type matrix_type in class matrix<...> and function
> template<class M>
> matrix_range<M> project(matrix_range<M>& data, const range& r1, const
range&
> r2);

This one terminates compiling (and running ;-) under GCC 3.2.1:

----------
#include <boost/numeric/ublas/matrix.hpp>

using namespace boost::numeric::ublas;

template<class Matrix>
 void ProcessRecursive(matrix_range<Matrix>& m)
 {
   typedef matrix_range<matrix<double> > MatrixRange;
   MatrixRange mr = m.project(range(0,m.size1()/2), range(0,m.size2()/2));
   if (mr.size1() > 0 && mr.size2() > 0)
     ProcessRecursive(mr);
 }

template<class Matrix>
 void ProcessRecursive(Matrix& m)
 {
   typedef matrix_range<matrix<double> > MatrixRange;
   MatrixRange mr = project (m, range(0,m.size1()/2), range(0,m.size2()/2));
   if (mr.size1() > 0 && mr.size2() > 0)
     ProcessRecursive(mr);
 }

void StartProcess()
 {
   matrix<double> m;
   ProcessRecursive(m);
 }

int main()
 {
    StartProcess();
 }

----------

I admit that using the undocumented matrix_range::project() is a hack.

> There is almost the same function project but reciving const referens to
> matrix_range and compiler can't find it even using partial template
> ordering.

Which compiler are you using?

> Do somebody help my to write this code correctly? Or fix library?

How?

Best,
Joerg


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