Julia: Performance issue of mul! in Q matrices from QR factorizations

Created on 22 Feb 2019  ·  2Comments  ·  Source: JuliaLang/julia

Following this Julia Discourse thread:

mul! seems to be much slower than lmul!, rmul! and * in a dense QR factorisation:

Minimal example:

n, m = 500, 10
Q = qr(randn(n, m)).Q;
x = randn(n)
y = randn(n)
@time mul!(y, Q, x);
@time y = Q*x;

In the example above mul! runs in the order of seconds, while * in the order of microseconds.

Julia version: 1.0.1
macOS 10.14.2

linear algebra performance

Most helpful comment

I suspect mul! hits the generic fallback which would make it fascinatingly inefficient since getindex for Q has Θ(n²) complexity so the complete mul! computation is Θ(n⁵). Applying a compact Q matrix is really an in-place operation. We could hide that fact by adding a mul! method for Q matrices that just calls copy! and lmul!.

All 2 comments

I suspect mul! hits the generic fallback which would make it fascinatingly inefficient since getindex for Q has Θ(n²) complexity so the complete mul! computation is Θ(n⁵). Applying a compact Q matrix is really an in-place operation. We could hide that fact by adding a mul! method for Q matrices that just calls copy! and lmul!.

Hi, I was planning to contribute towards GSoC 2019. I want to contribute to this issue. Please give me some guidelines

Was this page helpful?
0 / 5 - 0 ratings