clMatrix.DotProd Method

Double DotProd(TOpenCLMtxVec Vec)

Scalar product of two real arrays.

#NameTypeDescription
1VecTOpenCLMtxVecsource TOpenCLVector or TOpenCLMatrix

Returns: Double

Remarks:

Calculates the dot product (scalar value) of the calling object and Vec object and returns a real scalar value. The dot product is defined by the equation:

VV=k=0Length1V[k]V[k]\text{V}\cdot \text{V} = \sum _{k=0} ^{\text{Length}-1}\text{V}[k]\cdot \text{V}[k]

Both objects must be of equal size. If they are not, the method will return the dot product of the largest sub-array.

Examples
using Dew.Math;
using Dew.Math.Units;

namespace Dew.Examples
{
    void Example()
    {
        clMtxVec.TOpenCLMatrix a,b;
        clMtxVec.CreateIt(out a, out b);
        try
        {
            a.Size(2,2, TclFloatPrecision.clFloat, false);
            b.Size(2,2, TclFloatPrecision.clFloat, false);

            a.CopyFromArray(new double[] {1,2,3,4});
            b.CopyFromArray(new double[] {4,3,2,1});

            double prod = a.DotProd(b); // = 1*5 + 2*6 + * 3*7 + 4*8
        }
        finally
        {
            clMtxVec.FreeIt(ref a,ref b);
        }
    }
}
See Also: clMatrix.DotProdc

Indexed: Double DotProd(TOpenCLMtxVec Vec, Int32 VecIndex, Int32 Index, Int32 Len)

Returns the scalar product between Vec elements [VecIndex]..[VecIndex+Len-1] and calling object elements [Index]..[Index+Len-1].

#NameTypeDescription
1VecTOpenCLMtxVecsource TOpenCLVector or TOpenCLMatrix
2VecIndexInt32
3IndexInt32start index
4LenInt32element count

Returns: Double

Remarks:

An exception is raised if Vec and calling object Dew.Math.clMatrix.Complex property is True. An exception is raised if array borders are overrun or underrun.