github.com/gopherd/gonum@v0.0.4/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 "github.com/gopherd/gonum/internal/asm/f64" 9 ) 10 11 // Ddot computes the dot product of the two vectors 12 // \sum_i x[i]*y[i] 13 func (Implementation) Ddot(n int, x []float64, incX int, y []float64, incY int) float64 { 14 if incX == 0 { 15 panic(zeroIncX) 16 } 17 if incY == 0 { 18 panic(zeroIncY) 19 } 20 if n <= 0 { 21 if n == 0 { 22 return 0 23 } 24 panic(nLT0) 25 } 26 if incX == 1 && incY == 1 { 27 if len(x) < n { 28 panic(shortX) 29 } 30 if len(y) < n { 31 panic(shortY) 32 } 33 return f64.DotUnitary(x[:n], y[:n]) 34 } 35 var ix, iy int 36 if incX < 0 { 37 ix = (-n + 1) * incX 38 } 39 if incY < 0 { 40 iy = (-n + 1) * incY 41 } 42 if ix >= len(x) || ix+(n-1)*incX >= len(x) { 43 panic(shortX) 44 } 45 if iy >= len(y) || iy+(n-1)*incY >= len(y) { 46 panic(shortY) 47 } 48 return f64.DotInc(x, y, uintptr(n), uintptr(incX), uintptr(incY), uintptr(ix), uintptr(iy)) 49 }