Re: [eigen] array slicing/range
• To: eigen@xxxxxxxxxxxxxxxxxxx
• Subject: Re: [eigen] array slicing/range
• From: Ricard Marxer Piñón <email@xxxxxxxxxxxxxxxx>
• Date: Fri, 5 Feb 2010 18:41:51 +0100
• Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:sender:in-reply-to:references:from:date :x-google-sender-auth:message-id:subject:to:content-type :content-transfer-encoding; b=jgL7OKpU26y90bZGYtlV3myPAVvZRWZ8KAclrj59qfR3Wo4//AqM7kUkTI6cCu7zob 0GcGCW81jQeXPa/GIMBnl0LJ40yKIVzsZME4OClXGimsflnNrIg9wftYWZMN2UTLQZsm L2EjK8lLF4S+FtSAe+yZB89sYgKSuYzDiJaSA=

```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;
>>
>>
>> This could allow us to set the coefficients 0th, 2nd and 4th to 1.
>>
>> Or for example do:
>>
>>
>> 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

Hehe, I also think mask is a bad name, it was just to show what I
meant with code, because sometimes my explanations are not the best.

And I must have missed the discussion about it before, I have been a
bit "out" of Eigen's ML lately, will try to pick up a bit more again.

cheers
ricard

>
> 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/
>>>>>
>>>>> Department of Physics
>>>>> Indian Institute of Technology
>>>>> Bombay
>>>>>
>>>>>
>>>>>
>>>>
>>>>
>>>>
>>>
>>>
>>>
>>> --
>>> Rohit Garg
>>>
>>> http://rpg-314.blogspot.com/
>>>
>>> Department of Physics
>>> Indian Institute of Technology
>>> Bombay
>>>
>>>
>>>
>>
>>
>>
>> --
>> ricard
>> http://www.ricardmarxer.com
>> http://www.caligraft.com
>>
>>
>>
>
>
>

--
ricard
http://www.ricardmarxer.com
http://www.caligraft.com

```

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