[eigen] something like cwise trinary operator? |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/eigen Archives
]
- To: eigen@xxxxxxxxxxxxxxxxxxx
- Subject: [eigen] something like cwise trinary operator?
- From: David Roundy <roundyd@xxxxxxxxxxxxxxxxxxxxxxx>
- Date: Thu, 30 Sep 2010 14:11:41 -0400
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:mime-version:sender:received:from:date :x-google-sender-auth:message-id:subject:to:content-type; bh=vMAeu+5PF2ukg5YKBdWHZjxhZ8rr2MzpS42j659yivs=; b=slNs58MVeH+tWpd5PC1UnV51ZIr3GdxDy+IthHSwz7bRE0UphwWGwxI6QnCeNisM3t 8PqcA/K9ZzmXFxQAYcB7VQZmrIx5fWLFj40zOupM8/d/LIjktxvHAZ5p/mNPoixMOzTX oIAiryScxjCLuzPgs98tvBny7BmwJ5ZflNq2A=
- 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