TOpenCLVector.NormL2 Method

Overload List

#SignatureDescription
1function NormL2: Double;Calculate the L2-norm of the calling vector.
└ indexed: function NormL2(Index: Integer; Len: Integer): Double;
2function NormL2(const Vec: TOpenCLMtxVec; RelativeError: Boolean): Double;The L2-norm.
└ indexed: function NormL2(const Vec: TOpenCLMtxVec; VecIndex: Integer; Index: Integer; Len: Integer; RelativeError: Boolean): Double;

Overload 1: function NormL2: Double;

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: function NormL2(Index: Integer; Len: Integer): Double;

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

#NameTypeDescription
1IndexIntegerstart index
2LenIntegerelement count

Returns: Double

Overload 2: function NormL2(const Vec: TOpenCLMtxVec; RelativeError: Boolean): Double;

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
var a,b: clVector;
c: double;
begin
    a.CopyFromArray( TDoubleArray.Create(1,2,3,4));
    b.CopyFromArray( TDoubleArray.Create(4,3,2,1));
    c := a.NormL2(b,True);
end;

Indexed: function NormL2(const Vec: TOpenCLMtxVec; VecIndex: Integer; Index: Integer; Len: Integer; RelativeError: Boolean): Double;

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
2VecIndexInteger
3IndexIntegerstart index
4LenIntegerelement count
5RelativeErrorBoolean

Returns: Double

Examples
var a,b: clMatrix;
c: double;
begin
    a.Size(2,2, clFloat, false);
    b.Size(2,2, clFloat, false);

    a.CopyFromArray( TDoubleArray.Create(1,2,3,4));
    b.CopyFromArray( TDoubleArray.Create(4,3,2,1));

    c := a.NormL2(b,True);
end;