Accord.Math.Vector.Dot C# (CSharp) Method

Dot() public static method

Gets the inner product (scalar product) between two vectors (a'*b).
public static Dot ( this a, Sparse b ) : double
a this A vector.
b Sparse A vector.
return double
        public static double Dot(this Sparse<double> a, Sparse<double> b)
        {
            double sum = 0;

            int i = 0, j = 0;

            while (i < a.Indices.Length && j < b.Indices.Length)
            {
                int posx = a.Indices[i];
                int posy = b.Indices[j];

                if (posx == posy)
                {
                    sum += a.Values[i] * b.Values[j];
                    i++;
                    j++;
                }
                else if (posx < posy)
                {
                    i++;
                }
                else if (posx > posy)
                {
                    j++;
                }
            }

            return sum;
        }

Same methods

Vector::Dot ( this a, double b ) : double