Re: [eigen] Matrix multiplication seems to be exceptionally slow in one specific case |

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

*To*: eigen <eigen@xxxxxxxxxxxxxxxxxxx>*Subject*: Re: [eigen] Matrix multiplication seems to be exceptionally slow in one specific case*From*: Gael Guennebaud <gael.guennebaud@xxxxxxxxx>*Date*: Mon, 16 Jun 2014 15:36:25 +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=lWPa+G7BSoi3fRsuBN16OFAx6ei6Q4FpXQ2zm0+1yA4=; b=zX2EQ1fWVxeBn3YtewpEvgytM2sATJj0A42mRUW48mZ4Bsl2zdMI2McIT0KqkMIbna UhO889w74frvraPHmvyf3J866FIhQkx0NIzJhkRa7qvVoXRiiSladcIfyf0ICVPTrIUC uTCOuplWHcFVHBULqDzHaKJzNryKooShe4FuGJOTHXACCVKdex1PuD6fM2ZSqtXyVaue V+ooC+6o7XY8QZ0NozqVImXRqFoexb4VEarIwDt+BecjAHo/pDUezkwEHzE0LC++uar2 g3v0fW+Sj0sSeApN+zCVwmnO77PxhnBdLk3fZTMpUidR1tCv9nyPnrsa0SJZ06mAIWRb vGrA==

Please do not use the auto keyword when you don't known what is actually returned by an _expression_. In your case you are probably computing "L*U.real().transpose()" for every row of M.

cheers,

gael

On Mon, Jun 16, 2014 at 3:14 PM, <Thijs.Kooi@xxxxxxxxxxxxx> wrote:

Hi,

I am trying to implement a whitening transform using Eigen3, but I find that one of the matrix operations is extremely slow and I can't understand why. Below is the code:

MatrixXd M = convertToEigen(data);

MatrixXd mu = M.rowwise() - M.colwise().mean();

MatrixXd S = (mu.adjoint()*mu)/double(M.rows());

EigenSolver<MatrixXd> es(S, true);

auto V(es.eigenvalues());

auto U(es.eigenvectors());

V = V.cwiseSqrt().asDiagonal();

MatrixXd L(S.rows(), S.cols());

for(size_t d = 0; d < L.rows(); d++)

L(d, d) = 1./real(L(d, d));

MatrixXd Y(M.rows(), M.cols());

auto T = L*U.real().transpose();

for(size_t n = 0; n < M.rows(); n++)

{

Y.row(n) = T*(M.row(n) - mu);

}

Y = Y.transpose();

I clocked some of the operations and find that the T*() inside the for-loop is the bottle neck, which takes about 0.047688 seconds on a 4th generation intel i7 and about the same time as the eigenvalue decomposition, which takes 0.049989 seconds, so that can't be right. M is a 12498 x 225 matrix, so T is 225 x 225 and so is mu.

I am running Kubuntu 14.04, Eigen 3.2.0-8, which is in the repositories and all optimisation flags are turned on. Does anybody know what the problem is?

Best regards,

Thijs

Het Radboudumc staat geregistreerd bij de Kamer van Koophandel in het handelsregister onder nummer 41055629.

The Radboud university medical center is listed in the Commercial Register of the Chamber of Commerce under file number 41055629.

**References**:

**Messages sorted by:**[ date | thread ]- Prev by Date:
**Re: [eigen] Matrix multiplication seems to be exceptionally slow in one specific case** - Next by Date:
**RE: [eigen] Matrix multiplication seems to be exceptionally slow in one specific case** - Previous by thread:
**Re: [eigen] Matrix multiplication seems to be exceptionally slow in one specific case** - Next by thread:
**Re: [eigen] Matrix multiplication seems to be exceptionally slow in one specific case**

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