Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Slow sparse kronecker products #4958

Closed
ghost opened this issue Nov 27, 2013 · 6 comments
Closed

Slow sparse kronecker products #4958

ghost opened this issue Nov 27, 2013 · 6 comments

Comments

@ghost
Copy link

ghost commented Nov 27, 2013

I have found that the kronecker products are much slower compared to matlab.
Is there something that can be done?

In Julia

ddx(n) = spdiagm((-ones(n), ones(n)),[0 1],n,n+1) 
D3 = ddx(128);
tic(); A = kron(kron(D3,speye(128)),speye(128)); toc()

elapsed time: 1.625884532 seconds

In matlab

ddx = @(n) spdiags([-ones(n,1), ones(n,1)],[0,1],n,n+1);
D3 = ddx(128);
tic; A = kron(kron(D3,speye(128)),speye(128)); toc

Elapsed time is 0.395843 seconds.

@ViralBShah
Copy link
Member

There are some other bugs in kron too. I am fixing them now.

@ViralBShah
Copy link
Member

The speedup comes from devectorizing one more inner loop, and allocating much fewer objects. For me the original time was 1.7 seconds, but now is faster than matlab:

julia> tic(); A = kron(kron(D3,speye(128)),speye(128)); toc()
elapsed time: 0.090981935 seconds
0.090981935

@ViralBShah
Copy link
Member

BTW, there were no bugs in kron, but a bug in show that I fixed in an earlier commit.

@timholy
Copy link
Member

timholy commented Nov 29, 2013

Nice 20x speedup, Viral!

@StefanKarpinski
Copy link
Member

Seriously, that's not shabby at all.

@ViralBShah
Copy link
Member

This one turned out to be surprisingly easy. It is getting harder to find such "opportunities"!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants