Re: [eigen] find command or equivalent |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/eigen Archives
]
- To: eigen@xxxxxxxxxxxxxxxxxxx
- Subject: Re: [eigen] find command or equivalent
- From: Gael Guennebaud <gael.guennebaud@xxxxxxxxx>
- Date: Fri, 3 Sep 2010 09:33:08 +0200
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:mime-version:received:in-reply-to :references:from:date:message-id:subject:to:content-type :content-transfer-encoding; bh=hwZF9aaceB48w90ITjbebj6MSy/TZMfeoh55MneCBVw=; b=X/hs9YakxykTjxvpsK9fGTGSc++Xrd09J7nC8PPuyRPxUK3IscpXbomi+0vHGa+1go Pt1lPtL1lGZF6Zu/1JVF/kVLKT9n4RkABy1J+IiLc+D/vQFQvq2F3RtOlOHjfH8druEO z8v/W14gDzGb6F+q1VrpqGGTq+lAhGUtHwu28=
- Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type:content-transfer-encoding; b=yCCG7fhbFh7808aw8liRbNGbKDwBCkGtpLxOBzeWeSjyB/X+uNP1wtLmEFu71Bhbqo 3Hn3h0zBXKrGzhtRJy6tUt1Zse71ymfj1898mdWgTxQfhkV8zn6wdfYTWq9ljgin6iur h375VeqxP3nZNoJLpFtidmFY5o86q0pt3U3PU=
interesting, here is how this is compiled by gcc 4.5:
..L418:
leaq (%rsi,%rdx), %rcx
addq $1, %rax
addq $4, %rdx
cmpq %rbx, %rax
movss (%rcx), %xmm0
movaps %xmm0, %xmm1
movaps %xmm0, %xmm3
cmpnltss %xmm2, %xmm1
movaps %xmm1, %xmm0
andps %xmm1, %xmm3
andnps %xmm4, %xmm0
orps %xmm3, %xmm0
movss %xmm0, (%rcx)
jne .L418
where %xmm2 contains 0.0001, and %xmm4 is initialized to zero
(xorps %xmm4, %xmm4).
- Since GCC knows that %xmm4 == 0, it should be able to optimize away
these two instructions which have no effect:
andnps %xmm4, %xmm0
orps %xmm3, %xmm0
- It is also weird that it generates packet instructions while the
loop is not vectorized (andss, andnss, orss would be enough).
- there are too many movaps instructions.
here is what gcc should be able to easily generate:
..L418:
leaq (%rsi,%rdx), %rcx
addq $1, %rax
addq $4, %rdx
cmpq %rbx, %rax
movss (%rcx), %xmm0
movaps %xmm0, %xmm1
cmpnltss %xmm2, %xmm1
andss %xmm1, %xmm0
movss %xmm0, (%rcx)
jne .L418
maybe it is worth a bug report ?
gael
On Fri, Sep 3, 2010 at 9:19 AM, Gael Guennebaud
<gael.guennebaud@xxxxxxxxx> wrote:
> you can do:
>
> A = (A.array()<0.0001).select(0,A);
>
> where the "select" method mimics the c++ ?: operator.
>
> gael
>
>
> On Fri, Sep 3, 2010 at 6:40 AM, Suresh Kumar
> <suresh.amritapuri@xxxxxxxxx> wrote:
>> Hi
>> I want to replace all elements of a matrix, which are less than a threshold
>> by zero. How to do it without writing a nested for loop?
>> I am looking for something like this in matlab. A(A < 0.001) = 0 where A is
>> a matrix.
>> Thanks
>> suresh
>>
>> --
>> R Suresh Kumar,
>> http://www.ee.ucr.edu/~sramachandranna
>> --
>> Dhyaana–moolam Guror murtih
>> Puja-moolam Guroh padam
>> Mantra – moolam Guror vakyam
>> Moksha – moolam Guroh krpa.
>>
>