Re: [eigen] How can I improve this function |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/eigen Archives
]
- To: eigen@xxxxxxxxxxxxxxxxxxx
- Subject: Re: [eigen] How can I improve this function
- From: Gael Guennebaud <gael.guennebaud@xxxxxxxxx>
- Date: Sat, 22 Sep 2012 23:17:52 +0200
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; bh=IOhB3I3Ve8B1Nx3Omwn3Hmgtb4fQDPY2Ss9xY3pF4kQ=; b=aG6C588Li8IeJKVWRceLCuXEMmy/b8uVtYm0z2teHQKOfZAHtZj/cZLFm5K9+kKsXb eOpDa6/x1iAkobgIp6KxXMwO2ppvDdGTIuuSpDPEsihYKf6VSEdxhEfKl49V1BxLkPS+ XeYlfcs9gBtXy4+JHs9xtWSB4vtRxyCNPurqV4fJdGF5jX17kuKaRcDejLV1B1LGm+wJ qrxGA5AlGNLMNWLoy9fpDe3S4iXx9WDggjItLMk1c9xbrd2OUG9FVwf5tQM5vcFZbMw1 TdI4D8JJsiPUA9hP+fECyayZn7mmtGrCznK/OG9gQG20/lj+jEVy/XmAe0cTE66y9qTg obsw==
you could try:
x = (x.array()>0).select(xval, (y.array()>0).select(yval, x) );
but that won't be faster.
gael
On Sat, Sep 22, 2012 at 1:54 AM, Hung Dang <hungptit@xxxxxxxxx> wrote:
> Hi all,
>
> I have below function and I would like to improve it using Eigen's way. Any
> suggestion?
>
> Thanks a lot
> Hung
>
> template<typename T>
> void combine(Eigen::Matrix<T, Eigen::Dynamic, 1> & x, const T xval,
> const Eigen::Matrix<T, Eigen::Dynamic, 1> & y, const T yval) {
> const size_t len = x.rows();
> for (size_t idx = 0; idx < len; idx ++) {
> if (x(idx,0) > 0) {
> x(idx,0) = xval;
> } else {
> if (y(idx,0) > 0) x(idx,0) = yval;
> }
> }
> }
>
>
>