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*: Ricard Marxer Piñón <email@xxxxxxxxxxxxxxxx>*Date*: Fri, 5 Feb 2010 15:53:04 +0100*Dkim-signature*: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:sender:received:in-reply-to :references:from:date:x-google-sender-auth:message-id:subject:to :content-type:content-transfer-encoding; bh=fGfeF4QsBgL3N3zapGhJz3eC7HBzl1GfpzWRG5zn9hc=; b=PdLe1tQJJwTvhtQ0ujDGNxa9dgejMalUzF9sRf/tC555oUgPiL5Ef+n10G2xeW3VNU WBQSL2VUXoFg7+Vko957qh1sNgslbOB6aSoTfRasyCP+TZf/gHTPZyfubYGlUFhEE+sf DnHR7mOB0mJH1CTS4Pzc47tqaQELTAh4/VoOo=*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=sS/qaubQ1rpsd14bLnfyHusDBJE5B6InIC+jbwl50NHiJ3EUq7wBpNkUAxryczv7vV DZAQxY0JXea2ygiICFy0t7pI+CYei0jgESeUIoczYMs/Ga647N9tg4bPqlgfeXjN7mhl 3ia1tgAhwLop3dHPILn2tZoMoWAFS0ICphgRk=

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

**Follow-Ups**:**Re: [eigen] array slicing/range***From:*Benoit Jacob

**References**:**[eigen] array slicing/range***From:*Jinglei Hu

**Re: [eigen] array slicing/range***From:*Rohit Garg

**Re: [eigen] array slicing/range***From:*Aron Ahmadia

**Re: [eigen] array slicing/range***From:*Rohit Garg

**Messages sorted by:**[ date | thread ]- Prev by Date:
**Re: [eigen] array slicing/range** - Next by Date:
**Re: [eigen] ideas about the corner types** - Previous by thread:
**Re: [eigen] array slicing/range** - Next by thread:
**Re: [eigen] array slicing/range**

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