[uBLAS] Predefined subrange or project

Is it possible to predefine a subrange or project with a specific range so that when called I only had to pass in the matrix? I'm currently dealing with several 9x9 matrices that I need to access the 3x3 submatrix (topleft, topmiddle, topright, etc.). Is there a way to typedef or templatize a subrange or project so that I just need to pass the 9x9 matrix and get the topleft matrix? Example: typedef subrange(input_matrix, 0, 3, 0, 3) topleft; //This is what I want to somehow define. matrix<double> A(9,9); topleft(A) = zero_matrix<double>(3,3); Ryan

On Tue, Mar 8, 2011 at 8:44 PM, Ryan
Is it possible to predefine a subrange or project with a specific range so that when called I only had to pass in the matrix? I'm currently dealing with several 9x9 matrices that I need to access the 3x3 submatrix (topleft, topmiddle, topright, etc.). Is there a way to typedef or templatize a subrange or project so that I just need to pass the 9x9 matrix and get the topleft matrix?
Example:
typedef subrange(input_matrix, 0, 3, 0, 3) topleft; //This is what I want to somehow define.
You can't do that. If you don't want to write every time the "subrange" expression you can always create a macro or (better) a function like the one: namespace ublas = ::boost::numeric::ublas; template <typename MatrixT> inline ublas::matrix_range<MatrixT> topleft(MatrixT& M) { return ublas::subrange(M, 0, 3, 0, 3); } and use this function just like the case here below:
matrix<double> A(9,9); topleft(A) = zero_matrix<double>(3,3);
Best, -- Marco

On 09/03/2011 09:59, sguazt wrote:
namespace ublas = ::boost::numeric::ublas;
template<typename MatrixT> inline ublas::matrix_range<MatrixT> topleft(MatrixT& M) { return ublas::subrange(M, 0, 3, 0, 3); }
and use this function just like the case here below:
matrix<double> A(9,9); topleft(A) = zero_matrix<double>(3,3);
You might want to provide a const overload as well.

On Wed, Mar 9, 2011 at 4:09 AM, Mathias Gaunard < mathias.gaunard@ens-lyon.org> wrote:
On 09/03/2011 09:59, sguazt wrote:
namespace ublas = ::boost::numeric::ublas;
template<typename MatrixT> inline ublas::matrix_range<MatrixT> topleft(MatrixT& M) { return ublas::subrange(M, 0, 3, 0, 3); }
You might want to provide a const overload as well.
Why would I want a const overload? I want to be able to change the values in the matrix passed to the function. Ryan

On 09/03/2011 17:11, Ryan wrote:
On Wed, Mar 9, 2011 at 4:09 AM, Mathias Gaunard
mailto:mathias.gaunard@ens-lyon.org> wrote: On 09/03/2011 09:59, sguazt wrote:
namespace ublas = ::boost::numeric::ublas;
template<typename MatrixT> inline ublas::matrix_range<MatrixT> topleft(MatrixT& M) { return ublas::subrange(M, 0, 3, 0, 3); }
You might want to provide a const overload as well.
Why would I want a const overload? I want to be able to change the values in the matrix passed to the function.
To allow rvalues and propagate constness, so as to make it behave more like a typedef or macro. In the snippet you gave, of course, it needs to be non-const. But it's good practice to provide both when you write such adaptors.

On Wed, Mar 9, 2011 at 6:48 PM, Mathias Gaunard < mathias.gaunard@ens-lyon.org> wrote:
To allow rvalues and propagate constness, so as to make it behave more like a typedef or macro.
In the snippet you gave, of course, it needs to be non-const. But it's good practice to provide both when you write such adaptors.
Could you provide a snippet in which the "rvalues and propagate constness" needs to occur? Ryan
participants (3)
-
Mathias Gaunard
-
Ryan
-
sguazt