@@ -214,38 +214,23 @@ end
214
214
@inbounds return similar_type (a, typeof (Signed (a[2 ]* b[3 ])- Signed (a[3 ]* b[2 ])))(((Signed (a[2 ]* b[3 ])- Signed (a[3 ]* b[2 ]), Signed (a[3 ]* b[1 ])- Signed (a[1 ]* b[3 ]), Signed (a[1 ]* b[2 ])- Signed (a[2 ]* b[1 ]))))
215
215
end
216
216
217
- @inline dot (a:: StaticVector , b:: StaticVector ) = _vecdot (same_size (a, b), a, b)
218
- @generated function _vecdot (:: Size{S} , a:: StaticArray , b:: StaticArray ) where {S}
219
- if prod (S) == 0
220
- return :(zero (promote_op (* , eltype (a), eltype (b))))
221
- end
222
-
223
- expr = :(adjoint (a[1 ]) * b[1 ])
224
- for j = 2 : prod (S)
225
- expr = :($ expr + adjoint (a[$ j]) * b[$ j])
226
- end
217
+ @inline dot (a:: StaticVector , b:: StaticVector ) = _vecdot (same_size (a, b), a, b, dot)
218
+ @inline bilinear_vecdot (a:: StaticArray , b:: StaticArray ) = _vecdot (same_size (a, b), a, b, * )
227
219
228
- return quote
229
- @_inline_meta
230
- @inbounds return $ expr
231
- end
232
- end
233
-
234
- @inline bilinear_vecdot (a:: StaticArray , b:: StaticArray ) = _bilinear_vecdot (same_size (a, b), a, b)
235
- @generated function _bilinear_vecdot (:: Size{S} , a:: StaticArray , b:: StaticArray ) where {S}
220
+ @inline function _vecdot (:: Size{S} , a:: StaticArray , b:: StaticArray , product) where {S}
236
221
if prod (S) == 0
237
- return :( zero (promote_op ( * , eltype (a), eltype (b)) ))
238
- end
239
-
240
- expr = :(a[ 1 ] * b[ 1 ])
241
- for j = 2 : prod (S)
242
- expr = :( $ expr + a[ $ j] * b[ $ j ])
222
+ za, zb = zero (eltype (a)), zero ( eltype (b))
223
+ else
224
+ # Use an actual element if there is one, to support e.g. Vector{<:Number}
225
+ # element types for which runtime size information is required to construct
226
+ # a zero element.
227
+ za, zb = zero (a[ 1 ]), zero (b[ 1 ])
243
228
end
244
-
245
- return quote
246
- @_inline_meta
247
- @inbounds return $ expr
229
+ ret = product (za, zb) + product (za, zb)
230
+ @inbounds @simd for j = 1 : prod (S)
231
+ ret += product (a[j], b[j])
248
232
end
233
+ return ret
249
234
end
250
235
251
236
@inline LinearAlgebra. norm_sqr (v:: StaticVector ) = mapreduce (abs2, + , v; init= zero (real (eltype (v))))
0 commit comments