[eigen] something like cwise trinary operator?
• To: eigen@xxxxxxxxxxxxxxxxxxx
• Subject: [eigen] something like cwise trinary operator?
• From: David Roundy <roundyd@xxxxxxxxxxxxxxxxxxxxxxx>
• Date: Thu, 30 Sep 2010 14:11:41 -0400
• Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:sender:from:date:x-google-sender-auth:message-id :subject:to:content-type; b=CuYIFYJv2Agyulj9gcPrAUq8DZYWa2H+GKqF3oPf9cjiZ9rPZp77ZuC9IzEQn8/y+w sL3gpdOG3BPVtEtvwORMOlxYlzDgl8OQaF45lN0lDwGrt9jLvSvnrxapIHLWkeRfXWxh ZIiWjPU2GretacCvmqZIE+yzTDgif5pMnwRPk=

```Hi all,

I'm wondering if there is a way to generate something like the ((a <
b) ? c : d) expression that will efficiently operate component-wise on
an array?

My particular issue is that I am computing (with eigen2)
x.cwise()*(x.cwise().log()), which is a NaN for elements of x that
have a value of zero, but the actual limiting value is well-defined
and zero.  Right now, I'm doing this with an explicit for loop, but
it'd be considerably nicer if I could do this with an expression.

Any ideas?

For the curious (or those of you who might recognize this function),
it is the same as the Shannon entropy, but in my context it's to
compute the free energy of an ideal gas at fixed temperature (which is
-TS where S is the entropy).  To get the actual free energy, we'd have
to add in the energy term, which would be 3/2kT for a monatomic ideal
gas.
--
David Roundy

```

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