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