Hello everyone, 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); } 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); 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. Do somebody help my to write this code correctly? Or fix library? Regards, Alexey.
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
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
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
Hi Joerg, you wrote:
Interesting problem: the naive solution
---------- #include
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
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.
Hi Alexey, you wrote: [snip]
Which compiler are you using?
VC++ 7.1
Sorry, I should have concluded that from one of your earlier postings.
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
I'm unsure about this one: matrix_type currently describes the type of a referenced matrix for matrix proxies. What should the new definition be?
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.
Added that one (the omission is probably a bug).
It may be need to add the same code for other proxy types .
And these.
After those changes my code shown above compiles correctly and even runs. ;)
My current iteration is:
----------
#include
Hi Alexey,
you wrote:
[snip]
Which compiler are you using?
VC++ 7.1
Sorry, I should have concluded that from one of your earlier postings.
:)
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
I'm unsure about this one: matrix_type currently describes the type of a referenced matrix for matrix proxies. What should the new definition be?
The general idea is not differ the matrix and matrix proxies in code where that differ is not nessesory. The new definition should be next: matrix_type describes the type of a referenced matrix for matrix proxies or the type of matrix if it is not proxy. At addition, if client want to public inherit from class matrix he must redefine matrix_type as type of new class.
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.
Added that one (the omission is probably a bug).
Thank you :)
It may be need to add the same code for other proxy types .
And these.
And once agane thank you :)
After those changes my code shown above compiles correctly and even runs. ;)
My current iteration is:
---------- #include
using namespace boost::numeric::ublas;
typedef matrix<double> Matrix; typedef matrix_range
MatrixRange; void ProcessRecursive(MatrixRange& m) { 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 m; MatrixRange mr(m, range::all(), range::all()); ProcessRecursive(mr); }
int main() { StartProcess(); }
----------
Is something like that OK for you?
Yes, it is work... but I like my code more ;) Thanks, Alexey.
participants (2)
-
Alexey Nikitin
-
jhr.walter@t-online.de