go.charczuk.com@v0.0.0-20240327042549-bc490516bd1a/sdk/matrix/vector.go (about)

     1  /*
     2  
     3  Copyright (c) 2024 - Present. Will Charczuk. All rights reserved.
     4  Use of this source code is governed by a MIT license that can be found in the LICENSE file at the root of the repository.
     5  
     6  */
     7  
     8  package matrix
     9  
    10  // Vector is just an array of values.
    11  type Vector []float64
    12  
    13  // DotProduct returns the dot product of two vectors.
    14  func (v Vector) DotProduct(v2 Vector) (result float64, err error) {
    15  	if len(v) != len(v2) {
    16  		err = ErrDimensionMismatch
    17  		return
    18  	}
    19  
    20  	for i := 0; i < len(v); i++ {
    21  		result = result + (v[i] * v2[i])
    22  	}
    23  	return
    24  }