Re: [eigen] Feature suggestion: interior row and column ranges [patch attached]

[ Thread Index | Date Index | More lists.tuxfamily.org/eigen Archives ]


I came with rowRange and colRange just like Gael did, for lack of a 
one-name-fits-all solution. But I'd advocate innerRows or interiorRows rather 
than middleRows - the selection need not be in the middle.

Also, rowRange seems to indicate contiguity. How about rangeOfRows() - does it 
fit better with topRows() and bottomRows()

-- Manoj



On Saturday 26 June 2010 06:53:26 pm Benoit Jacob wrote:
> How about middleRows(first, count)?
>
> by analogy with topRows(count) and bottomRows(count).
>
> Benoit
>
> 2010/6/26 Gael Guennebaud <gael.guennebaud@xxxxxxxxx>:
> > hi,
> >
> > thanks for the patch.
> >
> > Let's discuss function names: to be consistent with
> > bottomRows/topRows/leftCols/rightCols, they should be: rows(int,int)
> > and cols(int,int), but then there is a name clash with rows() and
> > cols() returning the matrix sizes.  In the sparse module I used
> > subRows, and subCols for the same feature because I wanted names that
> > finish by "rows" and "cols", but they are not very good names! So yes
> > why not colRange and rowRange. I'm not 100% convinced, but since I
> > have nothing better to propose...
> >
> > gael
> >
> > On Sat, Jun 26, 2010 at 11:52 PM, Manoj Rajagopalan <rmanoj@xxxxxxxxx> 
wrote:
> >> On Saturday 26 June 2010 05:32:31 pm FMDSPAM wrote:
> >>>   Am 26.06.2010 22:58, schrieb Manoj Rajagopalan:
> >>> > Hi,
> >>> >
> >>> >    I've noticed leftCols(), rightCols(), topRows() and bottomRows()
> >>> > in the DenseBase API. I have, on occasion felt the need to access a
> >>> > contiguous range of rows/columns that start and end in the interior -
> >>> > the above functions allow access only to the extremes. Could
> >>> > DenseBase member functions, possibly named colRange(Index start,
> >>> > Index size) and rowRange(Index start, Index size), be supported
> >>> > sometime in the future?
> >>> >
> >>> > Thanks,
> >>> > Manoj
> >>>
> >>> It's already in upcomming eigen 3.0:
> >>> Use dynamic sized block: mat1.block(i,j,rows,cols)
> >>> or fixed sized block: mat1.block<rows,cols>(i,j)
> >>> to have Read-write access to sub-matrices.
> >>>
> >>> see devel-doc:Tutorial Matrix Blocks
> >>> <http://eigen.tuxfamily.org/dox-devel/TutorialCore.html#TutorialCoreMat
> >>>rixB locks>
> >>>
> >>> cheers
> >>> Frank
> >>
> >> Attaching a patch implementing my suggestion for the consideration of
> >> the developers/maintainers.
> >>
> >> @Frank: I wished the API would let me choose, say 3 columns starting
> >> with the 4th, in a 10x10 matrix. This should be a 10x3 submatrix
> >> starting at column #3 (0-base-indexing). With leftCols() (or
> >> rightCols()), the starting (or ending) column is fixed to an extreme and
> >> there is currently no API method to extract a few contiguous columns or
> >> rows purely in the interior.
> >>
> >> DenseBase::block() is the master method that allows the access of any
> >> contiguous 2D sub-region and is used to implement leftCol() and
> >> rightCol() but the latter are much more readable functions. So I present
> >> DenseBase::rowRange() and DenseBase::colRange() which use
> >> DenseBase::block() to extract contiguous interior rows and columns
> >> respectively.
> >>
> >> Example of rowRange usage:
> >>
> >>        int const N = 10;
> >>        MatrixXi A(N,N);
> >>        A.setRandom();
> >>        cout << "A =\n" << A << '\n' << endl;
> >>        cout << "A(3..5,:) =\n" << A.rowRange(3,3) << endl;
> >>        // alternatively, since #cols is known at compile time
> >>        cout << "A(3..5,:) =\n" << A.rowRange<3>(3) << endl;
> >>
> >> Output:
> >>
> >> A =
> >>  7   0 -10   0   1   1  -5   1   4  10
> >>  -2   3  -5   7   6  -9  10 -10  -7   2
> >>  6  -3  -8   2  -2  -6   8  -1  -1   3
> >>  6   0   6  -4   8   3   7   9   8   8
> >>  9   9  -7   3  -5   8  -5   9   7  -1
> >>  -6   9  -2   1  -3  -3   1   5  -4   9
> >>  -3   3  -8   0   6  -9  -3  -5  -6  -2
> >>  6   5  -8  10   9 -10   5   5   8   7
> >>  -5  -8  10  -4  -9  -1   0   3  -3   4
> >>  1   2  -6   6   9  -9   4  -3   4   9
> >>
> >> A(3..5,:) =
> >>  0   1   1
> >>  7   6  -9
> >>  2  -2  -6
> >>  -4   8   3
> >>  3  -5   8
> >>  1  -3  -3
> >>  0   6  -9
> >>  10   9 -10
> >>  -4  -9  -1
> >>  6   9  -9
> >>
> >>
> >> I have written small test programs like the above and have tested static
> >> and dynamic versions of rowRange() and colRange().
> >>
> >> Thanks,
> >> Manoj




Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/