Re: [eigen] array slicing/range

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




On Fri, Feb 5, 2010 at 4:03 PM, Benoit Jacob <jacob.benoit.1@xxxxxxxxx> wrote:
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).

ah funny, I've just talked about that in the other thread! And if I'm right there is a (old) patch posted in the ML. I never took the time to take core of it, shame on me.

gael.
 

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
>
>
>








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