@@ -621,21 +621,6 @@ opnorm(v::TransposeAbsVec) = norm(v.parent)
621
621
622
622
norm (v:: Union{TransposeAbsVec,AdjointAbsVec} , p:: Real ) = norm (v. parent, p)
623
623
624
- function dot (x:: AbstractArray , y:: AbstractArray )
625
- lx = _length (x)
626
- if lx != _length (y)
627
- throw (DimensionMismatch (" first array has length $(lx) which does not match the length of the second, $(_length (y)) ." ))
628
- end
629
- if lx == 0
630
- return dot (zero (eltype (x)), zero (eltype (y)))
631
- end
632
- s = zero (dot (first (x), first (y)))
633
- for (Ix, Iy) in zip (eachindex (x), eachindex (y))
634
- @inbounds s += dot (x[Ix], y[Iy])
635
- end
636
- s
637
- end
638
-
639
624
"""
640
625
dot(x, y)
641
626
x ⋅ y
@@ -678,14 +663,13 @@ function dot(x, y) # arbitrary iterables
678
663
while true
679
664
ix = iterate (x, xs)
680
665
iy = iterate (y, ys)
681
- if (ix == nothing ) || (iy == nothing )
682
- break
683
- end
666
+ ix === nothing && break
667
+ iy === nothing && break
684
668
(vx, xs), (vy, ys) = ix, iy
685
669
s += dot (vx, vy)
686
670
end
687
- if ! (iy == nothing && ix == nothing )
688
- throw (DimensionMismatch (" x and y are of different lengths!" ))
671
+ if ! (iy === nothing && ix = == nothing )
672
+ throw (DimensionMismatch (" x and y are of different lengths!" ))
689
673
end
690
674
return s
691
675
end
@@ -709,24 +693,19 @@ julia> dot([im; im], [1; 1])
709
693
0 - 2im
710
694
```
711
695
"""
712
- function dot (x:: AbstractVector , y:: AbstractVector )
713
- if length (LinearIndices (x)) != length (LinearIndices (y))
714
- throw (DimensionMismatch (" dot product arguments have unequal lengths $(length (LinearIndices (x))) and $(length (LinearIndices (y))) " ))
696
+ function dot (x:: AbstractArray , y:: AbstractArray )
697
+ lx = _length (x)
698
+ if lx != _length (y)
699
+ throw (DimensionMismatch (" first array has length $(lx) which does not match the length of the second, $(_length (y)) ." ))
715
700
end
716
- ix = iterate (x)
717
- if ix === nothing
718
- # we only need to check the first vector, since equal lengths have been asserted
701
+ if lx == 0
719
702
return dot (zero (eltype (x)), zero (eltype (y)))
720
703
end
721
- iy = iterate (y)
722
- s = dot (ix[1 ], iy[1 ])
723
- ix, iy = iterate (x, ix[2 ]), iterate (y, iy[2 ])
724
- while ix != nothing
725
- s += dot (ix[1 ], iy[1 ])
726
- ix = iterate (x, ix[2 ])
727
- iy = iterate (y, iy[2 ])
704
+ s = zero (dot (first (x), first (y)))
705
+ for (Ix, Iy) in zip (eachindex (x), eachindex (y))
706
+ @inbounds s += dot (x[Ix], y[Iy])
728
707
end
729
- return s
708
+ s
730
709
end
731
710
732
711
0 commit comments