Re: [eigen] Feature suggestion: interior row and column ranges [patch attached] |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/eigen Archives
]
- To: eigen@xxxxxxxxxxxxxxxxxxx
- Subject: Re: [eigen] Feature suggestion: interior row and column ranges [patch attached]
- From: Benoit Jacob <jacob.benoit.1@xxxxxxxxx>
- Date: Sat, 26 Jun 2010 18:53:26 -0400
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:received:in-reply-to :references:date:message-id:subject:from:to:content-type :content-transfer-encoding; bh=vfTO6YGks90RBmBxkgYZLreZ+Hz5O1dpRs1o5gNiSWY=; b=dcDOFweP6cgxoZa6xysNz8xSXgs37eLR1hY9QQjf3ogoeYBRPCFpLuCu34pLOSZorS sQ6Nobf6NAFpEuaRMeykDU6syXLDdUN+qMogOy/FjcEjtBaozc2WVat0NG59VO+/Mizn U9TPwOe2wjRNFyjRBY9I0WLHwRrUiM04s2Bsk=
- Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:content-transfer-encoding; b=GF5HKuHidt3XXazZlFR59VGB3tKt7JfnHGq1gm4KyQRxjnhQGTK3DvuE7WIZ3Agq9Y AMgU5MwQwVKtyY9KHCaXZKa/DDIK1Kg1JrxvGYgKHauRz2CcRhB6Rix8yOI4kNBpAdH7 Jj1VDH7rdzjaKUUWwD7ejASNTy/dUXBfzU4pE=
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#TutorialCoreMatrixB
>>>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
>>
>
>
>