I would like to calculate a quadratic form: x' Q y in Julia.
What would be the most efficient way to calculate this for the cases:
- No assumption.
Qis symmetric.xandyare the same (x = y).- Both
Qis symmetric andx = y.
I know Julia has dot(). But I wonder if it is faster than BLAS call.
CodePudding user response:
It is a BLAS call. (you can use @edit to confirm this).
CodePudding user response:
If your matrix is symmetric use the Symmetric wrapper to improve performance (a different method is called then):
julia> a = rand(10000); b = rand(10000);
julia> x = rand(10000, 10000); x = (x x') / 2;
julia> y = Symmetric(x);
julia> @btime dot($a, $x, $b);
47.000 ms (0 allocations: 0 bytes)
julia> @btime dot($a, $y, $b);
27.392 ms (0 allocations: 0 bytes)

