Re: [eigen] Sign function |

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

*To*: eigen@xxxxxxxxxxxxxxxxxxx*Subject*: Re: [eigen] Sign function*From*: Carlos Becker <carlosbecker@xxxxxxxxx>*Date*: Sat, 8 Dec 2012 17:18:43 +0100*Dkim-signature*: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=494Q02g3d/xjOcrW+ny95yqqE75OZGvIOFJV3lR62W4=; b=DQKb+A7zU0Avx5IvDyR8gLwtQIBgkZ26jzhBPA+QPyVJozGb7798iAv8sM+2aMgVRh MgvLLh0LuKypNh5fY0fAZdVD76FJfQ36Z80d1Bn+nXZ+eBeyYm4nLN8RhqoreRUAb6Ft UmbyWenSjSX1q5arzvhe/ntzWIIqd7OiuGEjShDhcEwNLWKofAelxJsBXyjdjnDOxF2Z HJ61ho46EoXNkZlTSOrq0TIHdUbd0/9XZT3DF+BlIMfe/3RbGjB+rvUZT0Ii+NiI6jkQ Ta/bcFzcy/HM2+MBw5QBG8tRkyZHQmogd5sgRfyG3yMUN5H0FE32ZZ+rO0yem5wOxR1X EskQ==

Ok that sounds great.

I thought that for VectorXd it would be VectorXd::Constant(rows, k), which seems to be working in my code.

Thanks, that was very useful.

------------------------------------------

Carlos

On Sat, Dec 8, 2012 at 5:12 PM, Gael Guennebaud <gael.guennebaud@xxxxxxxxx> wrote:

Actually it is rather MatType::Constant(rows,cols,k), and this is an _expression_, so no allocation at all.On Sat, Dec 8, 2012 at 3:13 PM, Carlos Becker <carlosbecker@xxxxxxxxx> wrote:

Hi Gael,thanks!If MatType is something 'huge' in the example you gave, would it get instantiated in memory? because then I should probably use another way of doing it.For example, I would replace MatType::Constant(k) with VectorXd::Constant( N, k ), where N could be pretty large.thanks again.

------------------------------------------Carlos

On Sat, Dec 8, 2012 at 2:08 PM, Gael Guennebaud <gael.guennebaud@xxxxxxxxx> wrote:You can do something like:A += (B.array()>0)..select(MatType::Constant(k),-k);Unfortunately the following cannot work because we have to know the matrix type returned by select from at least one of its arguments:A += (B.array()>0).select(k,-k);You can also use B.unaryExpr(std::ptr_fun(sign)) to reproduce "sign(B)".gaelOn Sat, Dec 8, 2012 at 12:26 PM, Carlos Becker <carlosbecker@xxxxxxxxx> wrote:Hello everyone,I am wondering which would be the fast way to compute the sign of every element in a vector or matrix, since I have to do the following element-wise:A = A + k * sign(B)where A and B are double matrices and k is a scalar.I was trying to find some information in the docs but so far I didn't succeed.I know I can do a boolean operation and then cast to double, multiply by 2 and subtract 1, but that doesn't seem very efficient.Maybe some kind of custom element-wise processing, since it would be enough to compute the sign and then add k or -k to each element of A ?Thanks!

**References**:**[eigen] Sign function***From:*Carlos Becker

**Re: [eigen] Sign function***From:*Gael Guennebaud

**Re: [eigen] Sign function***From:*Carlos Becker

**Re: [eigen] Sign function***From:*Gael Guennebaud

**Messages sorted by:**[ date | thread ]- Prev by Date:
**Re: [eigen] Sign function** - Next by Date:
**Re: [eigen] New Levenberg Marquardt stuff** - Previous by thread:
**Re: [eigen] Sign function** - Next by thread:
**Re: [eigen] Sign function**

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