Skip to content

Commit

Permalink
improve performance of generic dotu similar to dot, cf. JuliaLang#27678
Browse files Browse the repository at this point in the history
  • Loading branch information
ranocha committed Jun 21, 2018
1 parent aeb2a38 commit 11078cc
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions stdlib/LinearAlgebra/src/generic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -763,22 +763,27 @@ julia> dotu(σ, σ)
function dotu(x, y) # arbitrary iterables
ix = iterate(x)
iy = iterate(y)
if ix == nothing
if iy != nothing
if ix === nothing
if iy !== nothing
throw(DimensionMismatch("x and y are of different lengths!"))
end
return zero(eltype(x)) * zero(eltype(y))
end
if iy == nothing
if iy === nothing
throw(DimensionMismatch("x and y are of different lengths!"))
end
s = ix[1] * iy[1]
ix, iy = iterate(x, ix[2]), iterate(y, iy[2])
while ix != nothing && iy != nothing
s += ix[1] * iy[1]
ix, iy = iterate(x, ix[2]), iterate(y, iy[2])
(vx, xs) = ix
(vy, ys) = iy
s = vx * vy
while true
ix = iterate(x, xs)
iy = iterate(y, ys)
ix === nothing && break
iy === nothing && break
(vx, xs), (vy, ys) = ix, iy
s += vx * vy
end
if !(iy == nothing && ix == nothing)
if !(iy === nothing && ix === nothing)
throw(DimensionMismatch("x and y are of different lengths!"))
end
return s
Expand Down

0 comments on commit 11078cc

Please sign in to comment.