gonum.org/v1/gonum@v0.14.0/blas/gonum/level1float64_ddot.go (about) 1 // Copyright ©2015 The Gonum Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package gonum 6 7 import ( 8 "gonum.org/v1/gonum/internal/asm/f64" 9 ) 10 11 // Ddot computes the dot product of the two vectors 12 // 13 // \sum_i x[i]*y[i] 14 func (Implementation) Ddot(n int, x []float64, incX int, y []float64, incY int) float64 { 15 if incX == 0 { 16 panic(zeroIncX) 17 } 18 if incY == 0 { 19 panic(zeroIncY) 20 } 21 if n <= 0 { 22 if n == 0 { 23 return 0 24 } 25 panic(nLT0) 26 } 27 if incX == 1 && incY == 1 { 28 if len(x) < n { 29 panic(shortX) 30 } 31 if len(y) < n { 32 panic(shortY) 33 } 34 return f64.DotUnitary(x[:n], y[:n]) 35 } 36 var ix, iy int 37 if incX < 0 { 38 ix = (-n + 1) * incX 39 } 40 if incY < 0 { 41 iy = (-n + 1) * incY 42 } 43 if ix >= len(x) || ix+(n-1)*incX >= len(x) { 44 panic(shortX) 45 } 46 if iy >= len(y) || iy+(n-1)*incY >= len(y) { 47 panic(shortY) 48 } 49 return f64.DotInc(x, y, uintptr(n), uintptr(incX), uintptr(incY), uintptr(ix), uintptr(iy)) 50 }