Re: [eigen] array slicing/range |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/eigen Archives
]
- To: eigen@xxxxxxxxxxxxxxxxxxx
- Subject: Re: [eigen] array slicing/range
- From: Benoit Jacob <jacob.benoit.1@xxxxxxxxx>
- Date: Fri, 5 Feb 2010 10:03:57 -0500
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :date:message-id:subject:from:to:content-type :content-transfer-encoding; bh=5D4vP5KsYFWu4Mh1v5yMNLAgUg1k/5b538HIFGl9eII=; b=xIELefoBIs5J5wS80v2YLk340j7zYG+VnPqokrMkTIF3vebosNi7OJuX03XGFhl/zp 7YkigZHK3feMnLUgH/LGrr3faxngb87ZXsdlLaWAA4R6hqjiuqZppD0XHx13/hQnBI6l WlpQ3yuoHg5FVY7MjdQopmMO+ewWZ/lp68cP8=
- 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=O/+hMxI2GX5Nw7HmIN2K+XzJWdUsrYKqcGXUhU2DWR4cTCM17pIgXTJsdcC4jAaNpp KnZRGdtweyGN9eXwtQzTCjTspdBv5Vwilq6eVviETG787gBp305MWNrXaIS1/AXz6jee 9kL8gDrw3IEM2/Gj03DWvEUkmLwqhjEqzbao8=
2010/2/5 Ricard Marxer Piñón <email@xxxxxxxxxxxxxxxx>:
> Just a small clarification, AFAICT:
>
> array.segment(i,j)in Eigen
>
> is different from
>
> array(i:j) in Fortran
>
> I'm no expert of Fortran but I think that "i:j" creates a vector of
> the form "{i, i+1, i+2, ... j}".
> And since vectors in Fortran can be indexed with other vectors then
> array(i:j) returns a new vector containing the values of array at the
> positions "i, i+1, i+2, ... j".
> In Eigen array.segment(i, j) returns a segment view of the vector
> "array" starting at i and of size j. So the counterpart of Fortran
> would be array(i:i+j).
> Am I wrong or missing something here?
You're right. Even array(i:i+j-1), otherwise you get j+1 indices in the range.
> This raises an interesting point, I don't think we should add syntax
> that doesn't belong to the C++ language by use of a preprocessor, just
> to be more similar to Fortran. However it would be nice to have an
> expression in Eigen that would allow us to have a view of a vector
> given a vector of indices. I don't know of a name but if it would be
> called "mask" it could work as:
>
>
> VectorXI indices(3);
> indices << 0, 2, 4;
>
> array.mask(indices) = 1;
>
> This could allow us to set the coefficients 0th, 2nd and 4th to 1.
>
> Or for example do:
>
> myOtherArray.mask(indices) += array.mask(indices);
>
> This could also be extended to matrices by giving two arguments to the
> function one of the row indices and another of the column indices.
>
> Would this be of general interest?
Yes and this has already been discussed: AFAICR there's general
agreement that this would be useful, and not difficult to do. Search
the archives, I don't remember how much that was discussed and if an
API was decided (I'm not sure about the 'mask' name).
Benoit
>
> ricard
>
> On Fri, Feb 5, 2010 at 3:11 PM, Rohit Garg <rpg.314@xxxxxxxxx> wrote:
>> On Fri, Feb 5, 2010 at 7:02 PM, Aron Ahmadia <aja2111@xxxxxxxxxxxx> wrote:
>>> The Fortran/MATLAB syntax has the advantage of being incredibly terse.
>>> I come from a MATLAB background, and I strongly appreciate the way
>>> linear algebra routines look in MATLAB/Fortran as opposed to other
>>> languages. It would be fun to come up with a preprocessor that does
>>> what Jinglei is asking, but I don't think any of us have that kind of
>>> time :)
>>>
>>
>> Fair enough. However, my point is that the difference between
>> array.segment(i, j) and array(i:j) is small enough to not warrant
>> that kind of investment of time and effort.
>>
>> Not to mention that such a preprocessor hack, if done, is a de facto
>> fork of the _language_ . And my philosophy is that tools should always
>> be good citizens of native environment. One of my pet peeves against
>> Qt. Although it is a fine toolkit otherwise.
>>
>>
>>> A
>>>
>>> On Fri, Feb 5, 2010 at 4:26 PM, Rohit Garg <rpg.314@xxxxxxxxx> wrote:
>>>> Seriously,
>>>>
>>>> why do you want to hack the fortran syntax into eigen? What's the upside?
>>>>
>>>> On Fri, Feb 5, 2010 at 4:23 PM, Jinglei Hu <jingleihu@xxxxxxxxx> wrote:
>>>>> Hi guys,
>>>>>
>>>>> I knew from the Eigen developer that one can use array.segment(i, j) to get
>>>>> slice of an array. I'm wondering if it's possible to use array(i:j) to get
>>>>> slice just like Fortran.
>>>>>
>>>>> Cheers,
>>>>> Jinglei
>>>>>
>>>>>
>>>>>
>>>>
>>>>
>>>>
>>>> --
>>>> Rohit Garg
>>>>
>>>> http://rpg-314.blogspot.com/
>>>>
>>>> Senior Undergraduate
>>>> Department of Physics
>>>> Indian Institute of Technology
>>>> Bombay
>>>>
>>>>
>>>>
>>>
>>>
>>>
>>
>>
>>
>> --
>> Rohit Garg
>>
>> http://rpg-314.blogspot.com/
>>
>> Senior Undergraduate
>> Department of Physics
>> Indian Institute of Technology
>> Bombay
>>
>>
>>
>
>
>
> --
> ricard
> http://www.ricardmarxer.com
> http://www.caligraft.com
>
>
>