TOpenCLVector.NormL2 Method

Overload List

#SignatureDescription
1Double NormL2Calculate the L2-norm of the calling vector.
└ indexed: Double NormL2(Int32 Index, Int32 Len)
2Double NormL2(TOpenCLMtxVec Vec, Boolean RelativeError)The L2-norm.
└ indexed: Double NormL2(TOpenCLMtxVec Vec, Int32 VecIndex, Int32 Index, Int32 Len, Boolean RelativeError)

Overload 1: Double NormL2

Calculate the L2-norm of the calling vector.

Returns: Double - L2 norm, defined by: NormaL2 = ( Sum(|a[i]|^2) )^0.5 , 0 < i < Length-1 .

Indexed: Double NormL2(Int32 Index, Int32 Len)

Calculates the L2 norm from calling vector elements [Index]..[Index+Len-1].

#NameTypeDescription
1IndexInt32start index
2LenInt32element count

Returns: Double

Overload 2: Double NormL2(TOpenCLMtxVec Vec, Boolean RelativeError)

The L2-norm.

#NameTypeDescription
1VecTOpenCLMtxVecsource TOpenCLVector or TOpenCLMatrix
2RelativeErrorBoolean

Returns: Double - L2 norm, defined by ||V-Vec||, where V is calling vector.

Remarks:

If the NormL2 is called without any parameters, the NormL2 calculates the norm of calling vector. The L2 norm of ||V-Vec|| is defined by the formula:

VVecL2=k=0Length1(V[k]Vec[k])2\|\text{V} - \text{Vec}\| _{L2} = \sqrt{\sum _{k=0} ^{\text{Length}-1}\left(|\text{V}[k]-\text{Vec}[k]| \right)^2}

If RelativeError is true then the computed norm is divided by the norm of V, and the function returns the "relative error":

VVecV\frac{\| \text{V} - \text{Vec}\|}{\|\text{V}\|}
Examples
using Dew.Math;
using Dew.Math.Units;

namespace Dew.Examples
{
    void Example()
    {
        TOpenCLVector a,b;
        clMtxVec.CreateIt(out a, out b);
        try
        {
            a.CopyFromArray(new double[] {1,2,3,4});
            a.CopyFromArray(new double[] {4,3,2,1});
            double c = a.NormL2(b,true);
        }
        finally
        {
            clMtxVec.FreeIt(ref a,ref b);
        }
    }
}

Indexed: Double NormL2(TOpenCLMtxVec Vec, Int32 VecIndex, Int32 Index, Int32 Len, Boolean RelativeError)

Calculates the L2 norm ||V-Vec|| between Vec elements [VecIndex]..[VecIndex+Len-1] and calling vector elements [Index]..[Index+Len-1].

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

Returns: Double