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;
}