Boost logo

Boost Users :

Subject: Re: [Boost-users] [uBLAS] Predefined subrange or project
From: sguazt (marco.guazzone_at_[hidden])
Date: 2011-03-09 03:59:23


On Tue, Mar 8, 2011 at 8:44 PM, Ryan <mccorywork_at_[hidden]> wrote:
> 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


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