From ee78ad20498f20179a28f9867ab607201b74ed16 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Adjemian=20=28Hermes=29?= Date: Wed, 30 Dec 2015 13:29:28 +0100 Subject: [PATCH] Improved execution speed. Removed some calls to bsxfun which is not optimal on sparse matrices. I only removed the calls where I identified bottlenecks (with a Smets and Wouters model), more tests are needed to decide if we have to remove other occurences of bsxfun on sparse matrices. --- matlab/lmmcp/lmmcp.m | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/matlab/lmmcp/lmmcp.m b/matlab/lmmcp/lmmcp.m index aa170222c..1ac1c5e0a 100644 --- a/matlab/lmmcp/lmmcp.m +++ b/matlab/lmmcp/lmmcp.m @@ -537,7 +537,7 @@ end I1a = I(Indexset==1 & alpha_l==1); if any(I1a) - H2(I1a,:) = bsxfun(@times,x(I1a)-lb(I1a),DFx(I1a,:))+... + H2(I1a,:) = spdiags(x(I1a)-lb(I1a), 0, length(I1a), length(I1a))*DFx(I1a,:) +... sparse(1:length(I1a),I1a,Fx(I1a),length(I1a),n,length(I1a)); end @@ -619,7 +619,7 @@ if any(I3a) sparse(1:length(I3a),I3a,Fx(I3a),length(I3a),n,length(I3a)); end -H1 = bsxfun(@times,Db,DFx); -H1 = spdiags(diag(H1)+Da,0,H1); +H1 = spdiags(Db,0,length(Db),length(Db))*DFx; +H1 = H1 + spdiags(Da, 0, length(Da), length(Da)); H = [lambda1*H1; lambda2*H2];