-
Notifications
You must be signed in to change notification settings - Fork 98
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
3-argument dot method #173
Comments
IIRC, the 3-arg dot is slower than using BLAS twice (which I just confirmed with a quick benchmark for |
I get quite different benchmark results, for the example in Distances, the 3-argument version seems to be faster (and, of course, avoid the allocation): julia> using LinearAlgebra, BenchmarkTools
julia> z = rand(5);
julia> Q = rand(5, 5);
julia> f(z, Q) = dot(z, Q * z)
f (generic function with 1 method)
julia> g(z, Q) = dot(z, Q, z)
g (generic function with 1 method)
julia> @btime f($z, $Q);
90.175 ns (1 allocation: 128 bytes)
julia> @btime g($z, $Q);
28.354 ns (0 allocations: 0 bytes)
julia> z = rand(100);
julia> Q = rand(100, 100);
julia> @btime f($z, $Q);
4.842 μs (1 allocation: 896 bytes)
julia> @btime g($z, $Q);
1.670 μs (0 allocations: 0 bytes) |
Oh, I was benchmarking large matrices (dimension several hundreds). I wasn't sure what the typical use case for |
Yes, I can confirm that at some point the current implementation becomes faster. Would it make sense to add an empirical cutoff in the |
Although it sounds difficult to come up with good threshold values for arbitrary vector and matrix (not possible currently, but I guess the type constraints of SqMahalanobis could be relaxed?) types. |
Distances.jl/src/mahalanobis.jl
Line 23 in 44036b5
dot_percol
could benefit from the 3-argument methoddot(x, A, y)
. However, since this version was only introduced in Julia 1.4, Compat >= 3.2.0 would be required to support earlier Julia versions.Of course, this would increase loading times on Julia < 1.4 (by hiding the import behind a
@static if VERSION < v"1.4.0-DEV.92"
check it should be possible to avoid this with recent Julia versions, I assume). As an example, on my computer (with Julia 1.5 though) I get on masterwhereas with an additional
using Compat
I getWould it still be OK to add Compat as a dependency?
Alternatively, one could maybe define and use internally
which would just fall back to the current implementation for older Julia versions (in contrast to the implementation in https://github.com/JuliaLang/Compat.jl/blob/773db6a10c299a9af68eae5bf0f238117517bd1b/src/Compat.jl#L127-L144 that avoids the intermediate creation of an array).
The text was updated successfully, but these errors were encountered: