// Dot computes the inner product of // two vectors d = xi*yi + xj*yj + xz*yz+... func Dot(n int, x, y []float64) (d float64) { if n == 3 { d = x[0]*y[0] + x[1]*y[1] + x[2]*y[2] } else if n == 4 { d = x[0]*y[0] + x[1]*y[1] + x[2]*y[2] + x[3]*y[3] } else if n == 6 { d = x[0]*y[0] + x[1]*y[1] + x[2]*y[2] + x[3]*y[3] + x[4]*y[4] + x[5]*y[5] } else { d = blas.Ddot(n, x, 1, y, 1) } return }
// MVMul multiplies a matrix with a vector // y = alpha*A*x + y func MVMul(N, m, n int, alpha float64, A, x, y []float64) { if N != n { panic("vec: Dimensions invalid. A.Cols() != Vec.Len()") } if alpha == 0 { return } if alpha == 1 { goto alg } blas.Dscal(N, alpha, A, 1) goto alg alg: { if N < 8 { idx, ptr := 0, 0 extra := n - n%4 ub := ((n / 4) * 4) - 1 for i := 0; i < m; i++ { idx = i * n for j := 0; j < ub; j += 4 { ptr = idx + j y[i] += A[ptr]*x[j] + A[ptr+1]*x[j+1] + A[ptr+2]*x[j+2] + A[ptr+3]*x[j+3] } for j := extra; j < n; j++ { y[i] += A[idx+j] * x[j] } } return } for i := 0; i < m; i++ { y[i] += blas.Ddot(N, A[n*i:n*i+n], 1, x, 1) } } }
func dot64(X, Y []float64) float64 { return blas.Ddot(len(X), X, 1, Y, 1) }