|
Boost Users : |
From: Alexey Nikitin (yg-boost-users_at_[hidden])
Date: 2003-06-24 03:57:26
Hi Joerg,
you wrote:
> 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 ;-)
>
I'll try to write the code like I want to see:
----------
#include <boost/numeric/ublas/matrix.hpp>
using namespace boost::numeric::ublas;
template<class Matrix>
void ProcessRecursive(Matrix& m)
{
typedef matrix_range<typename Matrix::matrix_type> MatrixRange;
// this compile only for Matrix == matrix_range,
// because for matrix matrix_type is not defined (why not?)
MatrixRange mr = project(m, range(0,m.size1()/2), range(0,m.size2()/2));
// here compiler always selects non-specialized version of project,
// because m is non-constant reference.
if (mr.size1() > 0 && mr.size2() > 0)
ProcessRecursive(mr);
}
void StartProcess()
{
matrix<double> m(10, 10); // ;)
ProcessRecursive(m);
}
int main()
{
StartProcess();
}
----------
>
> Which compiler are you using?
>
VC++ 7.1
> > Do somebody help my to write this code correctly? Or fix library?
>
> How?
>
1. Add "typedef self_type matrix_type;" in definition of class matrix
2. Add
template<class M>
BOOST_UBLAS_INLINE
matrix_range<M> project (matrix_range<M> &data, const range &r1, const
range &r2) {
return data.project (r1, r2);
}
in matix_proxy.hpp (ver. 1.12) on line 3585. It may be need to add the
same code for other proxy types .
After those changes my code shown above compiles correctly and even runs. ;)
Thanks,
Alexey.
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