(*Implements base classes for vector, matrix and sparse matrix. Implements base classes for vector, matrix and sparse matrix. All end-user objects are created from this base classes. *) unit AbstractMtxVec; {$I BdsppDefs.inc} interface uses Math387, IppsplTypes, MtxVecBase, MtxVecInt, AbstractMtxVecInt ,Lapack_dfti, DFTIDescriptors ,Nmkl ,NmklSingle ,Ippspl ,ippsplSingle ,MtxVecUtils ,Classes ,SysUtils ; {$WARN SYMBOL_DEPRECATED ON} {$Z4} type TMtxVec = class; TDenseMtxVec = class; TDoubleFunc = function (const v: double): double; TSingleFunc = function (const v: single): single; TComplexFunc = function (const v: TCplx): TCplx; TSComplexFunc = function (const v: TSCplx): TSCplx; (* Abstract class for TVec and TMtx. *) TMtxVec = class(TMtxVecSample) strict private FDirty: boolean; fZeroTolerance: double; procedure setDirty(const value: boolean); procedure setComplex(const value: boolean); procedure setPrecision(const value: TPrecision); procedure setRounding(const value: TRounding); procedure setZeroTolerance(const value: double); procedure SetFloatPrecision(const value: TMtxFloatPrecision); function GetFirst: double; function GetFirstc: TCplx; function GetLast: double; function GetLastc: TCplx; procedure SetFirst(const value: double); procedure SetFirstc(const value: TCplx); procedure SetLast(const value: double); procedure SetLastc(const value: TCplx); public function LoadFromStream(const Src: TStream): Int64; override; procedure SaveToStream(const Dst: TStream); override; strict protected RISeed: cardinal; GISeed: cardinal; COffset: integer; fPrecision: TPrecision; fRounding: TRounding; function GetRealValues: string; virtual; function GetComplexValues: string; virtual; procedure ReleaseMemory; override; function ElemSize: Integer; override; function InternalResize(Len: integer; ZeroIt: boolean = False): TMtxVec; overload; virtual; procedure HookPointers; override; procedure DoSetComplex; virtual; function DoubleCachePointer: TDoubleArray; virtual; function DoubleCacheOffset: integer; virtual; function CplxDoubleCachePointer: TCplxDoubleArray; virtual; function CplxDoubleCacheOffset: integer; virtual; function SingleCachePointer: TSingleArray; virtual; function SingleCacheOffset: integer; virtual; function CplxSingleCachePointer: TCplxSingleArray; virtual; function CplxSingleCacheOffset: integer; virtual; procedure SubRangeLoadState; override; procedure AllocMemory; override; procedure AllocCacheMemory; override; procedure SetCapacityInElements(const value: Int64); override; function GetCapacityInElements: Int64; override; procedure ValidateRealIndexLen (const Index, RealSrcLen: integer); procedure Sin (const Src,Dst: TMtxVec; const SrcIdx,DstIdx, Len: integer); overload; procedure Cos (const Src,Dst: TMtxVec; const SrcIdx,DstIdx, Len: integer ); overload; procedure Tan (const Src,Dst: TMtxVec; const SrcIdx,DstIdx, Len: integer ); overload; procedure Cot (const Src,Dst: TMtxVec; const SrcIdx,DstIdx, Len: integer ); overload; procedure Sec (const Src,Dst: TMtxVec; const SrcIdx,DstIdx, Len: integer ); overload; procedure Csc (const Src,Dst: TMtxVec; const SrcIdx,DstIdx, Len: integer ); overload; procedure ArcSin (const Src,Dst: TMtxVec; const SrcIdx,DstIdx, Len: integer ); overload; procedure ArcCos (const Src,Dst: TMtxVec; const SrcIdx,DstIdx, Len: integer ); overload; procedure ArcTan (const Src,Dst: TMtxVec; const SrcIdx,DstIdx, Len: integer ); overload; procedure ArcCot (const Src,Dst: TMtxVec; const SrcIdx,DstIdx, Len: integer ); overload; procedure ArcSec (const Src,Dst: TMtxVec; const SrcIdx,DstIdx, Len: integer ); overload; procedure ArcCsc (const Src,Dst: TMtxVec; const SrcIdx,DstIdx, Len: integer ); overload; procedure Sinh (const Src,Dst: TMtxVec; const SrcIdx,DstIdx, Len: integer ); overload; procedure Cosh (const Src,Dst: TMtxVec; const SrcIdx,DstIdx, Len: integer ); overload; procedure Tanh (const Src,Dst: TMtxVec; const SrcIdx,DstIdx, Len: integer ); overload; procedure Coth (const Src,Dst: TMtxVec; const SrcIdx,DstIdx, Len: integer ); overload; procedure Sech (const Src,Dst: TMtxVec; const SrcIdx,DstIdx, Len: integer ); overload; procedure Csch(const Src,Dst: TMtxVec; const SrcIdx,DstIdx, Len: integer ); overload; procedure ArcSinh (const Src,Dst: TMtxVec; const SrcIdx,DstIdx, Len: integer ); overload; procedure ArcCosh (const Src,Dst: TMtxVec; const SrcIdx,DstIdx, Len: integer ); overload; procedure ArcTanh (const Src,Dst: TMtxVec; const SrcIdx,DstIdx, Len: integer ); overload; procedure ArcCoth (const Src,Dst: TMtxVec; const SrcIdx,DstIdx, Len: integer ); overload; procedure ArcSech (const Src,Dst: TMtxVec; const SrcIdx,DstIdx, Len: integer ); overload; procedure ArcCsch (const Src,Dst: TMtxVec; const SrcIdx,DstIdx, Len: integer ); overload; procedure Sqr (const Src,Dst: TMtxVec; const SrcIdx,DstIdx, Len: integer ); overload; procedure Sqrt (const Src,Dst: TMtxVec; const SrcIdx,DstIdx, Len: integer ); overload; procedure Cbrt (const Src,Dst: TMtxVec; const SrcIdx,DstIdx, Len: integer ); overload; procedure Ln (const Src,Dst: TMtxVec; const SrcIdx,DstIdx, Len: integer ); overload; procedure Log10(const Src,Dst: TMtxVec; const SrcIdx,DstIdx, Len: integer ); overload; procedure Log2 (const Src,Dst: TMtxVec; const SrcIdx,DstIdx, Len: integer ); overload; procedure Exp (const Src,Dst: TMtxVec; const SrcIdx,DstIdx, Len: integer ); overload; procedure Exp2 (const Src,Dst: TMtxVec; const SrcIdx,DstIdx, Len: integer ); overload; procedure Exp10(const Src,Dst: TMtxVec; const SrcIdx,DstIdx, Len: integer ); overload; procedure Inv (const Src,Dst: TMtxVec; Threshold: double; const SrcIdx,DstIdx, Len: integer ); overload; procedure Inv (const Src,Dst: TMtxVec; const SrcIdx,DstIdx, Len: integer ); overload; procedure InvSqrt (const Src,Dst: TMtxVec; const SrcIdx,DstIdx, Len: integer ); overload; procedure InvCbrt (const Src,Dst: TMtxVec; const SrcIdx,DstIdx, Len: integer ); overload; procedure Abs (const Src,Dst: TMtxVec; const SrcIdx,DstIdx, Len: integer ); overload; procedure MulI (const Src,Dst: TMtxVec; SrcIndex, DstIndex, Len: integer); overload; procedure Flip (const Src,Dst: TMtxVec; const SrcIdx,DstIdx,Len: integer); overload; procedure FlipConj(const Src,Dst: TMtxVec; const SrcIdx,DstIdx,Len: integer); overload; procedure Copy (const Src,Dst: TMtxVec; const SrcIdx,DstIdx,Len: integer); overload; procedure CopyTo(const Src,Dst: TMtxVec;const SrcIdx,DstIdx,Len: integer); overload; function StripNanAndInf(const Src, Dst: TMtxVec; SrcIdx, DstIdx, Len: integer): integer; overload; procedure SinhCosh(const Src, SinhX, CoshX: TMtxVec;const SrcIndex, SinhIndex, CoshIndex, Len: integer); overload; procedure CopyFromArray(const Src: TDoubleArray; const Dst: TMtxVec; const SrcIdx, DstIdx, Len: integer); overload; procedure CopyFromArray(const Src: TSingleArray; const Dst: TMtxVec; const SrcIdx, DstIdx, Len: integer); overload; procedure CopyFromArray(const Src: TCplxArray; const Dst: TMtxVec; const SrcIdx, DstIdx, Len: integer); overload; procedure CopyFromArray(const Src: TSCplxArray; const Dst: TMtxVec; const SrcIdx, DstIdx, Len: integer); overload; procedure CopyFromArray(const Src: TIntegerArray; const Dst: TMtxVecBase; const SrcIdx, DstIdx, Len: integer); overload; override; procedure CopyFromArray(const Src: TSmallIntArray; const Dst: TMtxVecBase; const SrcIdx, DstIdx, Len: integer); overload; override; procedure CopyFromArray(const Src: Math387.TByteArray; const Dst: TMtxVecBase; const SrcIdx, DstIdx, Len: integer); overload; override; procedure CopyToArrayInternal(const Src: TMtxVecBase; const Dst: TDoubleArray; const Index,DstIdx,Len: integer); overload; override; procedure CopyToArrayInternal(const Src: TMtxVecBase; const Dst: TSingleArray; const Index,DstIdx,Len: integer); overload; override; procedure CopyToArrayInternal(const Src: TMtxVec; const Dst: TSCplxArray; const Index,DstIdx,Len: integer); overload; procedure CopyToArrayInternal(const Src: TMtxVec; const Dst: TCplxArray; const Index,DstIdx,Len: integer); overload; procedure CopyToArrayInternal(const Src: TMtxVec; const Dst: TIntegerArray; Rounding: TRounding; const Index,DstIdx,Len: integer); overload; procedure CopyToArrayInternal(const Src: TMtxVec; const Dst: TSmallIntArray; Rounding: TRounding; const Index,DstIdx,Len: integer); overload; procedure CopyToArrayInternal(const Src: TMtxVec; const Dst: Math387.TByteArray; Rounding: TRounding; const Index,DstIdx,Len: integer); overload; function DotProdc(const Src1,Src2: TMtxVec; const ConjVec: boolean; const VecIndex, Index, Len: integer): TCplx; overload; procedure RoundTrunc(const Src,Dst: TMtxVec; const Rounding: TRounding; const SrcIndex,DstIndex,Len: integer); overload; function Skewness(const Src: TMtxVec;const AMean, AStdDev: double; const Index,Len: integer): double; overload; function Kurtosis(const Src: TMtxVec;const AMean, AStdDev: double; const Index,Len: integer): double; overload; procedure setIsDouble(const value: boolean); override; public (*Allows setting/getting the real value at position Indx. Allows setting/getting the real value at position Indx. This property reads/writes to the same memory as and properties. *) Values: TDoubleArray; (*Allows setting/getting the complex value at position Indx. Allows setting/getting the complex value at position Indx. This property reads/writes to the same memory as and properties. *) CValues: TCplxArray; (*Allows setting/getting the real value at position Indx. Allows setting/getting the real value at position Indx. This property reads/writes to the same memory as and properties. *) Values1D: TDoubleArray; (*Allows setting/getting the complex value at position Indx. Allows setting/getting the complex value at position Indx. This property reads/writes to the same memory as and properties. *) CValues1D: TCplxArray; (*Allows setting/getting the real value at position Indx. Allows setting/getting the real value at position Indx. This property reads/writes to the same memory as and properties. *) SValues: TSingleArray; (*Allows setting/getting the complex value at position Indx. Allows setting/getting the complex value at position Indx. This property reads/writes to the same memory as and properties. *) SCValues: TCplxSingleArray; (*Allows setting/getting the real value at position Indx. Allows setting/getting the real value at position Indx. This property reads/writes to the same memory as and properties. *) SValues1D: TSingleArray; (*Allows setting/getting the complex value at position Indx. Allows setting/getting the complex value at position Indx. This property reads/writes to the same memory as and properties. *) SCValues1D: TCplxSingleArray; strict protected function get_DefaultArray(const Indx: integer): double; procedure set_DefaultArray(const Indx: integer; const value: double); public (*Additional parameter for certain Lapack methods. Additional parameter for certain Lapack methods. When this value is used, it is mentioned in the method description. This parameter has been made a field of the object, to reduce the number of parameters required by a method, because it is not used very often. *) Beta: TCplx; (*Additional parameter for certain Lapack methods. Additional parameter for certain Lapack methods. When this value is used, it is mentioned in the method description. This parameter has been made a field of the object, to reduce the number of parameters required by a method, because it is not used very often. *) Alfa: TCplx; (*Defines the precision (single, float) and type (real, complex) of the floating point operations. *) property FloatPrecision: TMtxFloatPrecision read fFloatPrecision write SetFloatPrecision; property RealValues: string read GetRealValues; property ComplexValues: string read GetComplexValues; (*Defines the rounding used by streaming routines. *) property Rounding: TRounding read FRounding write setRounding; (*Defines the precision used by streaming routines. *) property Precision: TPrecision read FPrecision write setPrecision; (*True after object property changes. Set this to true after property has changed. Initially when the object is created this property is set to false. But when a change to object or it's elements is made, Dirty can be changed to true. Use this property to determine if the calling object and it's properties have changed. This property never changes automatically. *) property Dirty: boolean read FDirty write setDirty; (*The tolerance used by . The tolerance used by when the comparison type is relative. *) property ZeroTolerance: double read fZeroTolerance write setZeroTolerance; (*Allows setting/getting the real value at position Indx. Allows setting/getting the real value at position Indx. This property reads/writes to the same memory as and properties. *) property DefaultArray[const Indx: integer]: Double read get_DefaultArray write set_DefaultArray; default; procedure Assign(Src: TPersistent); override; procedure ValidateParams2 (const X: TMtxVec; const XIndex: integer;const Index: integer; var Len: integer); overload; procedure ValidateParamsPrecision(const X1: TMtxVec; const xIndex1, Index: integer; var Len: integer); overload; procedure ValidateParamsPrecision(const X1, X2: TMtxVec; const xIndex1,xIndex2,Index: integer; var Len: integer); overload; procedure ValidateParamsPrecision(const X1, X2, X3: TMtxVec; const xIndex1, xIndex2, xIndex3, Index: integer; var Len: integer); overload; function IsComplex: boolean; virtual; (*Finds a match for X in sorted object values using binary search. The data in the vector must be sorted in ascending order for this function to work correctly. the index of last matched element. If no matching elements are found, the result is -1.*) function BinarySearch(const x: double): Integer; overload; function BinarySearch(const x: double; const Index: integer; Len: integer): Integer; overload; function BinarySearch(const x: TCplx): Integer; overload; function BinarySearch(const x: TCplx; const Index: integer; Len: integer): Integer; overload; (*Finds exact or closest index match for X in sorted object values using binary search. The data in the vector must be sorted in ascending order for this function to work correctly. The closest match is the index of first bigger or smaller value in the array. To ensure bigger value write: Data := [0,2,3]; Data.BinarySearch(Value, XIndex); if Data[XIndex] > Value then Dec(XIndex); To ensure smaller value write: Data := [0,2,3]; Data.BinarySearch(1, XIndex); if Data[XIndex] < Value then Inc(XIndex); True and exact index in XIndex, if found and False and the index of the next bigger or smaller value in XIndex, if not found. *) function BinarySearch(const x: double; var XIndex: integer): boolean; overload; function BinarySearch(const x: double; var XIndex: integer; const Index: integer; Len: integer): boolean; overload; function BinarySearch(const x: TCplx; var XIndex: integer): boolean; overload; function BinarySearch(const x: TCplx; var XIndex: integer; const Index: integer; Len: integer): boolean; overload; (*Sine function. Calculate the sine of all caling object elements in-place. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TVec a; MtxVec.CreateIt(out a); try { a.SetIt(true, new double[] {1,-2,3,4}); a.Sin(); // Computes complex sine } finally { MtxVec.FreeIt(ref a); } } } *) function Sin: TMtxVec; overload; (*Calculate the sine of calling object elements [Index]...[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function Sin(Index: integer; Len: integer): TMtxVec; overload; (*Calculate the sine of all X object elements and store the results in calling object. Size and properties of calling object are adjusted automatically. *) function Sin(const X: TMtxVec): TMtxVec; overload; (*Calculate the sine of X object elements [XIndex]...[XIndex+Len-1]. The results are stored in calling object elements [Index]...[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if array borders are overrun. *) function Sin(const X: TMtxVec; XIndex: integer; Index: integer; Len: integer): TMtxVec; overload; (*Cosine. Calculate the cosine of all caling object elements in-place. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TVec a; MtxVec.CreateIt(out a); try { a.SetIt(true, new double[] {1,-2,3,4}); a.Cos(); // Computes complex sine } finally { MtxVec.FreeIt(ref a); } } } *) function Cos: TMtxVec; overload; (*Calculate the cosine of calling object elements [Index]...[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function Cos(Index: integer; Len: integer): TMtxVec; overload; (*Calculate the cosine of all X object elements. Store the results in the calling object.vSize and properties of calling object are adjusted automatically. *) function Cos(const X: TMtxVec): TMtxVec; overload; (*Calculate the cosine of X object elements [XIndex]...[XIndex+Len-1]. The results are stored in calling object elements [Index]...[Index+Len-1]. Size and properties of calling object and the calling object must be set explicitly. An exception is raised if array borders are overrun. *) function Cos(const X: TMtxVec; XIndex: integer; Index: integer; Len: integer): TMtxVec; overload; (*Tangens. Calculate the tangens of all caling object elements in-place. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TVec a; MtxVec.CreateIt(out a); try { a.SetIt(true, new double[] {1,-2,3,4}); a.Tan(); // Computes complex tangens } finally { MtxVec.FreeIt(ref a); } } } *) function Tan: TMtxVec; overload; (*Calculate the tangens of calling object elements [Index]...[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function Tan (Index: integer; Len: integer): TMtxVec; overload; (*Calculate the tangens of all X object elements. Store the results in the calling object. Size and properties of calling object are adjusted automatically. *) function Tan(const X: TMtxVec): TMtxVec; overload; (*Calculate the tangens of X object elements [XIndex]...[XIndex+Len-1]. The results are stored in calling object elements [Index]...[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if array borders are overrun. *) function Tan(const X: TMtxVec; XIndex: integer; Index: integer; Len: integer): TMtxVec; overload; (*Cotangens. Calculate the cotangens of all caling object elements in-place. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TVec a; MtxVec.CreateIt(out a); try { a.SetIt(true, new double[] {1,-2,3,4}); a.Cot(); // Computes complex cotangens } finally { MtxVec.FreeIt(ref a); } } } *) function Cot: TMtxVec; overload; (*Calculate the cotangens of calling object elements [Index]...[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function Cot(Index, Len: integer): TMtxVec; overload; (*Calculate the cotangens of all X object elements. Store the results in the calling object. Size and properties of calling object are adjusted automatically. *) function Cot(const X: TMtxVec): TMtxVec; overload; (*Calculate the cotangens of X object elements [XIndex]...[XIndex+Len-1]. The results are stored in calling object elements [Index]...[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if array borders are overrun. *) function Cot(const X: TMtxVec; XIndex, Index, Len: integer): TMtxVec; overload; (*Secant. Calculate the secant of all caling object elements in-place. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TVec a; MtxVec.CreateIt(out a); try { a.SetIt(true, new double[] {1,-2,3,4}); a.Sec(); // Computes complex secant } finally { MtxVec.FreeIt(ref a); } } } *) function Sec: TMtxVec; overload; (*Calculate the secant of calling object elements [Index]...[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function Sec(Index, Len: integer): TMtxVec; overload; (*Calculate the secant of all X object elements. Store the results in the calling object. Size and properties of calling object are adjusted automatically. *) function Sec(const X: TMtxVec): TMtxVec; overload; (*Calculate the secant of X object elements [XIndex]...[XIndex+Len-1]. The results are stored in calling object elements [Index]...[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if array borders are overrun. *) function Sec(const X: TMtxVec; XIndex, Index, Len: integer): TMtxVec; overload; (*Cosecant. Calculate the cosecant of all caling object elements in-place. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TVec a; MtxVec.CreateIt(out a); try { a.SetIt(true, new double[] {1,-2,3,4}); a.Csc(); // Computes complex cosecant } finally { MtxVec.FreeIt(ref a); } } } *) function Csc: TMtxVec; overload; (*Calculate the cosecant of calling object elements [Index]...[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function Csc(Index, Len: integer): TMtxVec; overload; (*Calculate the cosecant of all X object elements. Store the results in the calling object. Size and properties of calling object are adjusted automatically. *) function Csc(const X: TMtxVec): TMtxVec; overload; (*Calculate the cosecant of X object elements [XIndex]...[XIndex+Len-1]. The results are stored in calling object elements [Index]...[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if array borders are overrun. *) function Csc(const X: TMtxVec; XIndex, Index, Len: integer): TMtxVec; overload; (*The inverse sine. Calculate the inverse sine of all calling object elements in-place. Values must be between -1 and 1. The return values will be in the range [0,], in radians. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TVec a; MtxVec.CreateIt(out a); try { a.SetIt(true, new double[] {1,-0.5,0.11,0.9}); a.ArcSin(); // Computes complex inverse sine } finally { MtxVec.FreeIt(ref a); } } } *) function ArcSin: TMtxVec; overload; (*Calculate the inverse sine of calling object elements [Index]...[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function ArcSin(Index, Len: integer): TMtxVec; overload; (*Calculate the inverse sine of all X object elements. Store the results in the calling object. Size and properties of calling object are adjusted automatically. *) function ArcSin(const X: TMtxVec): TMtxVec; overload; (*Calculate the inverse sine of X object elements [XIndex]...[XIndex+Len-1]. The results are stored in calling object elements [Index]...[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if array borders are overrun. *) function ArcSin(const X: TMtxVec; XIndex, Index, Len: integer): TMtxVec; overload; (*The inverse cosine. Calculate the inverse cosine of all calling object elements in-place. Values must be between -1 and 1. The return values will be in the range [0,], in radians. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TVec a; MtxVec.CreateIt(out a); try { a.SetIt(true, new double[] {1,-0.5,0.11,0.9}); a.ArcCos(); // Computes complex inverse cosine } finally { MtxVec.FreeIt(ref a); } } } *) function ArcCos: TMtxVec; overload; (*Calculate the inverse cosine of calling object elements [Index]...[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function ArcCos(Index, Len: integer): TMtxVec; overload; (*Calculate the inverse cosine of all X object elements. Store the results in the calling object. Size and properties of calling object are adjusted automatically. *) function ArcCos(const X: TMtxVec): TMtxVec; overload; (*Calculate the inverse cosine of X object elements [XIndex]...[XIndex+Len-1]. The results are stored in calling object elements [Index]...[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if array borders are overrun. *) function ArcCos(const X: TMtxVec; XIndex, Index, Len: integer): TMtxVec; overload; (*Inverse tangens of Y/X. Calculates the inverse tangens of Y/X, and returns an angle in the correct quadrant. The results are stored in calling object elements. Size and properties of calling object are adjusted automatically to match those of X and Y objects. An exception is raised if X and Y size and properties do not match. Note that is calculated as ArcTan2(1, X). *) function ArcTan2(const Y, X: TMtxVec): TMtxVec; overload; (*Calculate the inverse tangens of Y/X. Calculation uses Y elements [YIndex]..[YIndex+Len-1], X elements [XIndex]..[XIndex+Len-1] and stores the results in calling object elements [Index]..[Index+Len-1]. An exception is raised if array borders are overrun. *) function ArcTan2(const Y, X: TMtxVec; YIndex, XIndex, Index: integer; Len: integer): TMtxVec; overload; (*Inverse tangens. Calculate the inverse tangens for all calling object elements in-place. The return values are expressed in radians. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TMtx A,B; MtxVec.CreateIt(out A, out B); try { A.SetIt(2,2,true, new double[] {1,0, 2,0, 2,0 4,1}]); // 2x2, complex matrix B.ArcTan(A); } finally { MtxVec.FreeIt(ref A, ref B); } } } *) function ArcTan: TMtxVec; overload; (*Calculate the inverse tangens of calling object elements [Index]...[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function ArcTan(Index, Len: integer): TMtxVec; overload; (*Calculate the inverse tangens of all X object elements. Store the results in the calling object. Size and properties of calling object are adjusted automatically. *) function ArcTan(const X: TMtxVec): TMtxVec; overload; (*Calculate the inverse tangens of X object elements [XIndex]...[XIndex+Len-1]. The results are stored in calling object elements [Index]...[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if array borders are overrun. *) function ArcTan(const X: TMtxVec; XIndex, Index, Len: integer): TMtxVec; overload; (*Inverse cotangens. Calculate the inverse cotangens for all calling object elements in-place. The return values are expressed in radians. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TMtx A,B; MtxVec.CreateIt(out A, out B); try { A.SetIt(2,2,true, new double[] {1,0, 2,0, 2,0 4,1}]); // 2x2, complex matrix B.ArcCot(A); } finally { MtxVec.FreeIt(ref A, ref B); } } } *) function ArcCot: TMtxVec; overload; (*Calculate the inverse cotangens of calling object elements [Index]...[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function ArcCot(Index, Len: integer): TMtxVec; overload; (*Calculate the inverse cotangens of all X object elements. Store the results in the calling object. Size and properties of calling object are adjusted automatically. *) function ArcCot(const X: TMtxVec): TMtxVec; overload; (*Calculate the inverse cotangens of X object elements [XIndex]...[XIndex+Len-1]. The results are stored in calling object elements [Index]...[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if array borders are overrun. *) function ArcCot(const X: TMtxVec; XIndex, Index, Len: integer): TMtxVec; overload; (*Inverse secant. Calculate the inverse secant for all calling object elements in-place. *) function ArcSec: TMtxVec; overload; (*Calculate the inverse secant of calling object elements [Index]...[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function ArcSec(Index, Len: integer): TMtxVec; overload; (*Calculate the inverse secant of all X object elements and store the results in the calling object. Size and properties of calling object are adjusted automatically. *) function ArcSec(const X: TMtxVec): TMtxVec; overload; (*Calculate the inverse secant of X object elements [XIndex]...[XIndex+Len-1]. The results are stored in calling object elements [Index]...[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if array borders are overrun. *) function ArcSec(const X: TMtxVec; XIndex, Index, Len: integer): TMtxVec; overload; (*Inverse cosecant. Calculate the inverse cosecant for all calling object elements in-place. *) function ArcCsc: TMtxVec; overload; (*Calculate the inverse cosecant of calling object elements [Index]...[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function ArcCsc(Index, Len: integer): TMtxVec; overload; (*Calculate the inverse cosecant of all X object elements. Store the results in the calling object. Size and properties of calling object are adjusted automatically. *) function ArcCsc(const X: TMtxVec): TMtxVec; overload; (*Calculate the inverse cosecant of X object elements [XIndex]..[XIndex+Len-1]. The results are stored in the calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if array borders are overrun. *) function ArcCsc(const X: TMtxVec; XIndex, Index, Len: integer): TMtxVec; overload; (*Hyperbolic sine. Calculate the hyperbolic sine of all caling object elements in-place. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TVec a; MtxVec.CreateIt(out a); try { a.SetIt(false, new double[] {1, 1.5, 2, 0.3}); a.Sinh(); } finally { MtxVec.FreeIt(ref a); } } } *) function Sinh: TMtxVec; overload; (*Calculate the hyperbolic sine of calling object elements [Index]...[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function Sinh(Index, Len: integer): TMtxVec; overload; (*Calculate the hyperbolic sine of all X object elements. Store the results in the calling object. Size and properties of calling object are adjusted automatically. *) function Sinh(const X: TMtxVec): TMtxVec; overload; (*Calculate the hyperbolic sine for X object elements [XIndex]..[XIndex+Len-1]. The results are stored in the calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if array borders are overrun. *) function Sinh(const X: TMtxVec; XIndex, Index, Len: integer): TMtxVec; overload; (*Hyperbolic cosine. Calculate the hyperbolic cosine of all caling object elements in-place. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TVec a; MtxVec.CreateIt(out a); try { a.SetIt(false, new double[] {1, 1.5, 2, 0.3}); a.Cosh(); } finally { MtxVec.FreeIt(ref a); } } } *) function Cosh: TMtxVec; overload; (*Calculate the hyperbolic cosine for calling object elements [Index]..[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function Cosh(Index, Len: integer): TMtxVec; overload; (*Calculate the hyperbolic cosine for all X object elements. Store the results in the calling object. Size and properties of calling object are adjusted automatically. *) function Cosh(const X: TMtxVec): TMtxVec; overload; (*Calculate the hyperbolic cosine for X object elements [XIndex]..[XIndex+Len-1]. The results are stored in calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if array borders are overrun. *) function Cosh(const X: TMtxVec; XIndex, Index, Len: integer): TMtxVec; overload; (*Hyperbolic tangens. Calculate the hyperbolic tangens of all caling object elements in-place. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TVec a; MtxVec.CreateIt(out a); try { a.SetIt(false, new double[] {1, 1.5, 2, 0.3}); a.Tanh(); } finally { MtxVec.FreeIt(ref a); } } } *) function Tanh: TMtxVec; overload; (*Calculate the hyperbolic tangens for calling object elements [Index]..[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function Tanh(Index, Len: integer): TMtxVec; overload; (*Calculate the hyperbolic tangens for all X object elements. Store the results in the calling object. Size and properties of calling object are adjusted automatically. *) function Tanh(const X: TMtxVec): TMtxVec; overload; (*Calculate the hyperbolic tangens for X object elements [XIndex]..[XIndex+Len-1]. The results are stored in the calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if array borders are overrun. *) function Tanh(const X: TMtxVec; XIndex, Index, Len: integer): TMtxVec; overload; (*Hyperbolic cotangens. Calculate the hyperbolic cotangens of all caling object elements in-place. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TVec a; MtxVec.CreateIt(out a); try { a.SetIt(false, new double[] {1, 1.5, 2, 0.3}); a.Coth(); } finally { MtxVec.FreeIt(ref a); } } } *) function Coth: TMtxVec; overload; (*Calculate the hyperbolic cotangens for calling object elements [Index]...[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function Coth(Index, Len: integer): TMtxVec; overload; (*Calculate the hyperbolic cotangens for all X object elements. Store the results in the calling object. Size and properties of calling object are adjusted automatically. *) function Coth(const X: TMtxVec): TMtxVec; overload; (*Calculate the hyperbolic cotangens for X object elements [XIndex]..[XIndex+Len-1]. The results are stored in calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if array borders are overrun. *) function Coth(const X: TMtxVec; XIndex, Index, Len: integer): TMtxVec; overload; (*Hyperbolic secant. Calculate the hyperbolic secant of all caling object elements in-place. *) function Sech: TMtxVec; overload; (*Calculate the hyperbolic secant for calling object elements [Index]...[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function Sech(Index, Len: integer): TMtxVec; overload; (*Calculate the hyperbolic secant for all X object elements. Store the results in the calling object. Size and properties of calling object are adjusted automatically. *) function Sech(const X: TMtxVec): TMtxVec; overload; (*Calculate the hyperbolic secant for X object elements [XIndex]..[XIndex+Len-1]. The results are stored in calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if array borders are overrun. *) function Sech(const X: TMtxVec; XIndex, Index, Len: integer): TMtxVec; overload; (*Hyperbolic cosecant. Calculate the hyperbolic cosecant of all caling object elements in-place. *) function Csch: TMtxVec; overload; (*Calculate the hyperbolic cosecant for calling object elements [Index]..[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function Csch(Index, Len: integer): TMtxVec; overload; (*Calculate the hyperbolic cosecant for all X object elements. Store the results in the calling object. Size and properties of calling object are adjusted automatically. *) function Csch(const X: TMtxVec): TMtxVec; overload; (*Calculate the hyperbolic cosecant for X object elements [XIndex]..[XIndex+Len-1]. The results are stored in calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if array borders are overrun. *) function Csch(const X: TMtxVec; XIndex, Index, Len: integer): TMtxVec; overload; (*Absolute values. Calculate the absolute value of all calling object elemets in-place. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TVec a; MtxVec.CreateIt(out a); try { a.SetIt(true, new double[] {1,-2,3,4}); a.Abs(); // a = [1,2,3,4] } finally { MtxVec.FreeIt(ref a); } } } *) function Abs: TMtxVec; overload; (*Calculate the absolute value for calling object elements [Index]..[Index+Len-1]. An exception is raised if array borders are overrun or underrun. *) function Abs(Index, Len: integer): TMtxVec; overload; (*Calculate the absolute value for all X object and store the results in the calling object. Size and properties of calling object are adjusted automatically. *) function Abs(const X: TMtxVec): TMtxVec; overload; (*Calculate the absolute value of X object elements [XIndex]..[XIndex+Len-1]. Store the results in calling object elements [Index]..[Index+Len-1]. An exception is raised if array borders are overrun or underrun. *) function Abs(const X: TMtxVec; XIndex, Index, Len: integer): TMtxVec; overload; (*Inverse hyperbolic sine. Calculate the inverse hyperbolic sine for all caling object elements in-place. *) function ArcSinh: TMtxVec; overload; (*Calculate the inverse hyperbolic sine for calling object elements [Index]..[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function ArcSinh(Index, Len: integer): TMtxVec; overload; (*Calculate the inverse hyperbolic sine for all X object elements. Store the results in the calling object. Size and properties of calling object are adjusted automatically. *) function ArcSinh(const X: TMtxVec): TMtxVec; overload; (*Calculate the inverse hyperbolic sine for X object elements [XIndex]..[XIndex+Len-1]. The results are stored in calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if array borders are overrun. *) function ArcSinh(const X: TMtxVec; XIndex, Index, Len: integer): TMtxVec; overload; (*Inverse hyperbolic cosine. Calculate the inverse hyperbolic cosine for all caling object elements in-place. *) function ArcCosh: TMtxVec; overload; (*Calculate the inverse hyperbolic cosine for calling object elements [Index]..[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function ArcCosh(Index, Len: integer): TMtxVec; overload; (*Calculate the inverse hyperbolic cosine for all X object elements. Store the results in the calling object. Size and properties of calling object are adjusted automatically. *) function ArcCosh(const X: TMtxVec): TMtxVec; overload; (*Calculate the inverse hyperbolic cosine for X object elements [XIndex]..[XIndex+Len-1]. The results are stored in calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if array borders are overrun. *) function ArcCosh(const X: TMtxVec; XIndex, Index, Len: integer): TMtxVec; overload; (*Inverse hyperbolic tangens. Calculate the inverse hyperbolic tangens for all caling object elements in-place. *) function ArcTanh: TMtxVec; overload; (*Calculate the inverse hyperbolic tangens for calling object elements [Index]..[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function ArcTanh(Index, Len: integer): TMtxVec; overload; (*Calculate the inverse hyperbolic tangens for all X object elements. Store the results in the calling object. Size and properties of calling object are adjusted automatically. *) function ArcTanh(const X: TMtxVec): TMtxVec; overload; (*Calculate the inverse hyperbolic tangens for X object elements [XIndex]..[XIndex+Len-1]. The results are storedi n the calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if array borders are overrun. *) function ArcTanh(const X: TMtxVec; XIndex, Index, Len: integer): TMtxVec; overload; (*Inverse hyperbolic cotangens. Calculate the inverse hyperbolic cotangens for all caling object elements in-place. *) function ArcCoth: TMtxVec; overload; (*Calculate the inverse hyperbolic cotangens for calling object elements [Index]..[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function ArcCoth(Index, Len: integer): TMtxVec; overload; (*Calculate the inverser hyperbolic cotangens for all X object elements. Store the results in calling object. Size and properties of calling object are adjusted automatically. *) function ArcCoth(const X: TMtxVec): TMtxVec; overload; (*Calculate the inverse hyperbolic cotangens for X object elements [XIndex]..[XIndex+Len-1]. The results are stored in the calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if array borders are overrun. *) function ArcCoth(const X: TMtxVec; XIndex, Index, Len: integer): TMtxVec; overload; (*Inverse hyperbolic secant. Calculate the inverse hyperbolic secant for all caling object elements in-place. *) function ArcSech: TMtxVec; overload; (*Calculate the inverse hyperbolic secant for calling object elements [Index]..[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function ArcSech(Index, Len: integer): TMtxVec; overload; (*Calculate the inverse hyperbolic secant for all X object elements. Store the results in calling object. Size and properties of calling object are adjusted automatically. *) function ArcSech(const X: TMtxVec): TMtxVec; overload; (*Calculate the inverse hyperbolic secant for X object elements [XIndex]..[XIndex+Len-1]. The results are stored in calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if array borders are overrun. *) function ArcSech(const X: TMtxVec; XIndex, Index, Len: integer): TMtxVec; overload; (*Inverse hyperbolic cosecant. Calculate the inverse hyperbolic cosecant for all caling object elements in-place. *) function ArcCsch: TMtxVec; overload; (*Calculate the inverse hyperbolic cosecant for calling object elements [Index]...[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function ArcCsch(Index, Len: integer): TMtxVec; overload; (*Calculate the inverse hyperbolic cosecant for all X object elements. Store the results in calling object. Size and properties of calling object are adjusted automatically. *) function ArcCsch(const X: TMtxVec): TMtxVec; overload; (*Calculate the inverse hyperbolic cosecant for X object elements [XIndex]..[XIndex+Len-1]. The results are stored in calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if array borders are overrun. *) function ArcCsch(const X: TMtxVec; XIndex, Index, Len: integer): TMtxVec; overload; (*The cube root. Calculate the cube root of all calling object elements in-place. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TVec a; MtxVec.CreateIt(out a); try { a.SetIt(true, new double[] {1,8}); a.Cbrt(); // a = [1,2] } finally { MtxVec.FreeIt(ref a); } } } *) function Cbrt: TMtxVec; overload; (*Calculate the cube root of calling object elements [Index]..[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function Cbrt(Index, Len: integer): TMtxVec; overload; (*Calculate the cube root of all X object elements. Store the results in calling object. Size and properties of calling object are adjusted automatically. *) function Cbrt(const X: TMtxVec): TMtxVec; overload; (*Calculate the cube root of X object elements [XIndex]..[XIndex+Len-1]. The results are stored in the calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if array borders are overrun. *) function Cbrt(const X: TMtxVec; XIndex, Index, Len: integer): TMtxVec; overload; (*Rounds towards positive infinity. Rounds all calling object elements towards positive infinity in-place. Ceil(-2.8) = -2 Ceil(2.8) = 3 Ceil(-1.0) = -1 *) function Ceil: TMtxVec; overload; (*Rounds calling object elements [Index]..[Index+Len-1] towards positive infinity in-place. An exception is raised if array borders are overrun. *) function Ceil(Index,Len: integer): TMtxVec; overload; (*Rounds all Src object elements towards positive infinity. Stores the result in the calling object. Size and properties of the calling object are adjusted automatically. *) function Ceil(const Src: TMtxVec): TMtxVec; overload; (*Rounds Src object elements [SrcIndex]..[SrcIndex+Len-1] towards positive infinity. Stores the result in the calling object elements [Index]..[Index+Len-1] Size and properties of the calling object must be set explicitly. An exception is raised if array borders are overrun. *) function Ceil(const Src: TMtxVec; SrcIndex, Index,Len: integer): TMtxVec; overload; (*Natural logarithm. Calculate the natural log for all calling object elements in-place. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TVec a; MtxVec.CreateIt(out a); try { a.SetIt(false, new double[] {1,8}); a.Ln(); } finally { MtxVec.FreeIt(ref a); } } } *) function Ln: TMtxVec; overload; (*Calculate the natural algorithm for all X elements. Store the results in the calling object. Size and properties of the calling vector are set implicitly to match the X object. *) function Ln(const X: TMtxVec): TMtxVec; overload; (*Calculate the natural logarithm for calling object elements [Index]..[Index+Len-1] in-place. An exception is raised if ConditionCheck is True and array borders are overrun. *) function Ln(Index, Len: integer): TMtxVec; overload; (*Calculate the natural logarithm for X elements [XIndex]..[XIndex+Len-1]. Store the results in the calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if ConditionCheck is True and array borders are overrun. *) function Ln(const X: TMtxVec; XIndex, Index, Len: integer): TMtxVec; overload; (*Log base 10. Calculate the log base 10 for all calling object elements in-place. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TVec a; MtxVec.CreateIt(out a); try { a.SetIt(false, new double[] {10,100,1000,10000}); a.Log10(); // a = [1,2,3,4] } finally { MtxVec.FreeIt(ref a); } } } *) function Log10: TMtxVec; overload; (*Calculate the log base 10 for all X elements. Store the results in the calling object. Size and properties of the calling vector are set implicitly to match the X object. *) function Log10(const X: TMtxVec): TMtxVec; overload; (*Calculate the log base 10 for calling object elements [Index]..[Index+Len-1] in-place. An exception is raised if ConditionCheck is True and array borders are overrun. *) function Log10(Index, Len: integer): TMtxVec; overload; (*Calculate the log base 10 for X elements [XIndex]..[XIndex+Len-1]. Store the results in the calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if ConditionCheck is True and array borders are overrun. *) function Log10(const X: TMtxVec; XIndex, Index, Len: integer): TMtxVec; overload; (*Log base 2. Calculate the log base 2 for all calling object elements in-place. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TVec a; MtxVec.CreateIt(out a); try { a.SetIt(false, new double[] {1,2,4,8}); a.Log2(); // a = [0,1,2,3] } finally { MtxVec.FreeIt(ref a); } } } *) function Log2: TMtxVec; overload; (*Calculate the log base 2 for all X elements. Store the results in the calling object. Size and properties of the calling vector are set implicitly to match the X object. *) function Log2(const X: TMtxVec): TMtxVec; overload; (*Calculate the log base 2 for calling object elements [Index]..[Index+Len-1] in-place. An exception is raised if ConditionCheck is True and array borders are overrun. *) function Log2(Index, Len: integer): TMtxVec; overload; (*Calculate the log base 2 for X elements [XIndex]..[XIndex+Len-1]. Store the results in the calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if ConditionCheck is True and array borders are overrun. *) function Log2(const X: TMtxVec; XIndex, Index, Len: integer): TMtxVec; overload; (*Exponent (e^). Calculate the exponent (e^) for all calling object elements in-place. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TVec a; MtxVec.CreateIt(out a); try { a.SetIt(false, new double[] {1,System.Math.E}); a.Exp(); // a = [0.0,1.00000] } finally { MtxVec.FreeIt(ref a); } } } *) function Exp: TMtxVec; overload; (*Calculate the exponent (e^) for all X elements. Store the results in the calling object. Size and properties of the calling vector are set implicitly to match the X object. *) function Exp(const X: TMtxVec): TMtxVec; overload; (*Calculate the exponent (e^) for calling object elements [Index]..[Index+Len-1] in-place. An exception is raised if ConditionCheck is True and array borders are overrun. *) function Exp(Index, Len: integer): TMtxVec; overload; (*Calculate the exponent (e^) for X elements [XIndex]..[XIndex+Len-1]. Store the results in the calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if ConditionCheck is True and array borders are overrun. *) function Exp(const X: TMtxVec; XIndex, Index, Len: integer): TMtxVec; overload; (*Exponent base 2 (2^). Calculate the exponent base 2 (2^) for all calling object elements in-place. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TVec a; MtxVec.CreateIt(out a); try { a.SetIt(false, new double[] {1,2,3,4}); a.Exp2(); // a = [1,4,9,16] } finally { MtxVec.FreeIt(ref a); } } } *) function Exp2: TMtxVec; overload; (*Calculate the exponent base 2 (2^) for all X elements. Store the results in the calling object. Size and properties of the calling vector are set implicitly to match the X object. *) function Exp2(const X: TMtxVec): TMtxVec; overload; (*Calculate the exponent base 2 (2^) for calling object elements [Index]..[Index+Len-1] in-place. An exception is raised if ConditionCheck is True and array borders are overrun. *) function Exp2(Index, Len: integer): TMtxVec; overload; (*Calculate the exponent base 2 (2^) for X elements [XIndex]..[XIndex+Len-1]. Store the results in the calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if ConditionCheck is True and array borders are overrun. *) function Exp2(const X: TMtxVec; XIndex, Index, Len: integer): TMtxVec; overload; (*Exponent base 10 (10^). Calculate the exponent base 10 (10^) for all calling object elements in-place. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TVec a; MtxVec.CreateIt(out a); try { a.SetIt(false, new double[] {1,2,3,4}); a.Exp10(); // a = [10,100,1000,10000] } finally { MtxVec.FreeIt(ref a); } } } *) function Exp10: TMtxVec; overload; (*Calculate the exponent base 10 (10^) for all X elements. Store the results in the calling object. Size and properties of the calling vector are set implicitly to match the X object. *) function Exp10(const X: TMtxVec): TMtxVec; overload; (*Calculate the exponent base 10 (10^) for calling object elements [Index]..[Index+Len-1] in-place. An exception is raised if ConditionCheck is True and array borders are overrun. *) function Exp10(Index, Len: integer): TMtxVec; overload; (*Calculate the exponent base 10 (10^) for X elements [XIndex]..[XIndex+Len-1]. Store the results in the calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if ConditionCheck is True and array borders are overrun. *) function Exp10(const X: TMtxVec; XIndex, Index, Len: integer): TMtxVec; overload; (*Gets the imaginary part of a complex object. Gets the imaginary part of a complex object Vec and stores the real results in the calling object. Size and properties of the calling object are set implicitly to match Vec object. Vec must be true otherwise the exception will be raised. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TVec a,b; MtxVec.CreateIt(out a, out b); try { a.SetIt(true,new double[] {1,2,3,4}); // a= [1+2i, 3+4i] b.ImagPart(a); // b = [2, 4] } finally { MtxVec.FreeIt(ref a,ref b); } } } *) function ImagPart(const Vec: TMtxVec): TMtxVec; overload; (*Gets the imaginary part of complex object Vec elements [VecIndex]..[VecIndex+Len-1]. Stores the result in calling object. An exception is raised if the calling object is complex, if Vec is not complex or if array borders are overrun/underrun. *) function ImagPart(const Vec: TMtxVec; VecIndex,Index,Len: integer): TMtxVec; overload; (*Power (integer exponent). Calculate the power ^(Exponent) for all caling object elements using the integer parameter Exponent. For non integer exponents, the and methods can be used. var a: TVec; begin CreateIt(a); try a.SetIt(False,[1,2,3,4]); a.IntPower(3); finally FreeIt(a); end; end; *) function IntPower(Exponent: Integer): TMtxVec; overload; (*Calculate the power Base^(Exponent) for all Base object elements. Calclation uses the integer Exponent value and stores the results in calling object. Size and properties of calling object are adjusted automatically. *) function IntPower(const Base: TMtxVec; Exponent: Integer): TMtxVec; overload; (*Inverse elements. Calculates the inverse of all calling object elements in-place without limiting inverse operation. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TVec a,b; MtxVec.CreateIt(out a, out b); try { a.SetIt(false, new double[] {1, 2, 3, 4}); b.Inv(a); // b = [1.0, 0.5, 0.3333, 0.25] } finally { MtxVec.FreeIt(ref a, ref b); } } } *) function Inv: TMtxVec; overload; (*Calculate the inverse of calling object elements [Index]..[Index+Len-1] in-place. An exception is raised if array borders are overrun/underrun. *) function Inv(Index, Len: integer): TMtxVec; overload; (*Calculate the inverse of all calling object elements in-place. The computation occurs after first limiting the magnitude of each element by the lower bound of Threshold. The limiting operation is performed to avoid division by zero. Since Threshold represents a magnitude, it is always real and must always be positive. For complex versions, the magnitude of the input is limited, but the phase remains unchanged. Zero-valued input is assumed to have zero phase. *) function Inv(const Threshold: double): TMtxVec; overload; (*Calculate the inverse of calling object elements [Index]..[Index+Len-1] in-place after limiting the magnitude of each element by the lower bound of Threshold. An exception is raised if array borders are overrun/underrun. *) function Inv(const Threshold: double; Index, Len: integer): TMtxVec; overload; (*Calculate the inverse of all X object elements without limiting operating. Store the results in calling object. Size and property of calling object are adjusted automatically. *) function Inv(const X: TMtxVec): TMtxVec; overload; (*Calculate the inverse of X object elements [XIndex]..[XIndex+Len-1] without limiting operating. Store the results in calling object elements [Index]..[Index+Len-1]. An exception is raised if X and calling object property does not match or array borders are overrun/underrun. *) function Inv(const X: TMtxVec; XIndex, Index, Len: integer): TMtxVec; overload; (*Calculate the inverse of all X object elements anmd store the results to calling object elements. Size and property of calling obhect are adjusted automatically. The computation occurs after first limiting the magnitude of each element by the lower bound of Threshold. The limiting operation is performed to avoid division by zero. Since Threshold represents a magnitude, it is always real and must always be positive. For complex versions, the magnitude of the input is limited, but the phase remains unchanged. Zero-valued input is assumed to have zero phase. *) function Inv(const X: TMtxVec; const Threshold: double): TMtxVec; overload; (*Calculate the inverse of X object elements [XIndex]..[XIndex+Len-1] after limiting the magnitude of each element by the lower bound of Threshold. Store the results in calling object elements [Index]..[Index+Len-1]. An exception is raised if X and calling object property do not match or array borders are overrun/underrun. *) function Inv(const X: TMtxVec; const Threshold: double; XIndex, Index, Len: integer): TMtxVec; overload; (*Converts elements from cartesian to polar coordinate form. Converts all calling object elements from cartesian to polar coordinate form, storing the magnitude (radius) component of corresponding elements in the AmpltVec and the phase (angle) component of corresponding elements in the PhaseVec. If you want to use this method then the calling matrix property must be true. If this is not the case, an exception is raised. Size and properties of AmpltVec and PhaseVec are set automatically. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TMtx A, Ampl, Phase; MtxVec.CreateIt(out A, out Ampl, out Phase); try { a.SetIt(2, 2, true, new double[] {1,0, 2,0, 2,0, 4,1}); A.CartToPolar(Amplt, Phasw); } finally { MtxVec.FreeIt(ref A, ref Amplt, ref Phase); } } } *) procedure CartToPolar(const AmpltVec, PhaseVec: TMtxVec); overload; (*Convert calling object elements [Index] to [Index+Len-1] from cartesian to polar form. Store the results in AmpltVec (radius values) and PhaseVec(phase values). Size and properties of the calling vector must be set explicitly. An exception is raised if ConditionCheck is True and array borders are overrun or underrun. *) procedure CartToPolar(const AmpltVec, PhaseVec: TMtxVec; AmpltIndex, PhaseIndex, Index, Len: integer); overload; (*Copy object values. Copy each of Vec elements to the calling object. Size and properties of the calling object are set implicitly to match Vec object. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TVec a,b,c; MtxVec.CreateIt(out a, out b, out c); try { a.SetIt(true,new double[] {1,2,3,4}); // a = [1,2,3,4] i.e 1+2i ; 3+4i b.Copy(a); // b = [1,2,3,4] c.Copy(a,b); //concatenate a and b and store in c = [1,2,3,4,1,2,3,4] } finally { MtxVec.FreeIt(ref a,ref b,ref c); } } } *) function Copy(const Src: TMtxVec): TMtxVec; overload; (*Copy object values. Copy each of Vec elements to the calling object. Size and properties of the calling object are set implicitly to match Vec object. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TVec a,b,c; MtxVec.CreateIt(out a, out b, out c); try { a.SetIt(true,new double[] {1,2,3,4}); // a = [1,2,3,4] i.e 1+2i ; 3+4i b.Copy(a, mvSingle); // convert to single precision } finally { MtxVec.FreeIt(ref a,ref b,ref c); } } } *) function Copy(const Src: TMtxVec; const dstFloatPrecision: TMtxFloatPrecision): TMtxVec; overload; (*Copy Vec elements [VecIndex]..[VecIndex+Len-1] in the calling object elements [Index]..[Index+Len-1]. Size and properties must be set explicitly. An exception is raised if ConditionCheck is True and array borders are overrun or underrun. *) function Copy(const Vec: TMtxVec; VecIndex, Index, Len: integer): TMtxVec; overload; (*Copy and convert values from TVecInt. Applies appropriate conversion and copy data from TVecInt. The destinaton data format is determined with dstFloatPrecision. *) function Copy(const Src: TMtxVecInt; const dstFloatPrecision: TMtxFloatPrecision):TMtxVec; overload; virtual; (*Copy and convert values from TVecInt at indexes [SrcIndex]...[SrcIndex+Len-1]. Applies appropriate conversion and copy data from TVecInt. The results are stored in calling object elements [Index]...[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if array borders are overrun. *) function Copy(const Src: TMtxVecInt; SrcIndex, Index, Len: integer):TMtxVec; overload; (*Copy and convert values to TVecInt. Applies appropriate conversion and copy data to TVecInt. The value TVecInt.IntPrecision is preserved. *) procedure CopyTo(const Dst: TMtxVecInt; const Rounding: TRounding); overload; (*Copy and convert values to specified dstFloatPrecision. Dst will be sized to hold all calling object data in specified dstFloatPrecision. The single/double and Complex/Not Complex conversion cant be handled concurrently. *) procedure CopyTo(const Dst: TMtxVec; const dstFloatPrecision: TMtxFloatPrecision); overload; (*Copy and convert values to Dst.FloatPrecision at indexes [DstIndex]...[DstIndex+Len-1]. Applies appropriate conversion and copy data from Src. The results are stored in Dst object elements [Index]...[Index+Len-1]. Size and properties of the destination object must be set explicitly. An exception is raised if array borders are overrun. *) procedure CopyTo(const Dst: TMtxVec; const DstIndex, Index: integer; Len: integer); overload; (*Copy and if needed convert values to Dst, but keep Dst.FloatPrecision.*) procedure CopyTo(const Dst: TMtxVec); overload; (*Copy and convert values to TVecInt at indexes [DstIndex]...[DstIndex+Len-1]. Applies appropriate conversion and copy data from TVecInt. The results are stored in to Dst object elements [Index]...[Index+Len-1]. Size and properties of the destination object must be set explicitly. An exception is raised if array borders are overrun. *) procedure CopyTo(const Dst: TMtxVecInt; const Rounding: TRounding; DstIndex, Index, Len: integer); overload; (*Conjugate. Conjugate all calling object elements in-place. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TVec a; MtxVec.CreateIt(out a); try { a.SetIt(true, new double[] {1,-2,3,4}); a.Conj(); } finally { MtxVec.FreeIt(ref a); } } } *) function Conj: TMtxVec; overload; (*Conjugate calling object elements [Index]..[Index+Len-1] in-place. An exception is raised if ConditionCheck is true and array borders are overrun. *) function Conj(Index,Len: integer): TMtxVec; overload; (*Conjugate each of Vec elements. Store the results in the calling object. The Size and properties of the calling object are set implicitly to match Vec vector. *) function Conj(const Vec: TMtxVec): TMtxVec; overload; (*Conjugate Vec elements Vec[VecIndex]..Vec[VecIndex+Len-1]. Store them in the calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if ConditionCheck is true and array borders are overrun. *) function Conj(const Vec: TMtxVec; VecIndex, Index, Len: integer): TMtxVec; overload; (*Copies values from an array. Copies values from a complex array. The size and properties of the calling object are set implicitely. *) function CopyFromArray(const Src: TSCplxArray): TMtxVec; overload; (*Copies values from an array. Copies values from a complex array. The size and properties of the calling object are set implicitely. *) function CopyFromArray(const Src: TCplxArray): TMtxVec; overload; (*Copies values from the Src array [SrcIndex]..[SrcIndex+Len-1] to the calling object values [Index]..[Index+len-1]. The size of the calling object is not changed. If the array border are overrun an exception will be raised. *) function CopyFromArray(const Src: TCplxArray; SrcIndex,Index,Len: integer): TMtxVec; overload; (*Copies values from the Src array [SrcIndex]..[SrcIndex+Len-1] to the calling object values [Index]..[Index+len-1]. The size of the calling object is not changed. If the array border are overrun an exception will be raised. *) function CopyFromArray(const Src: TSCplxArray; SrcIndex,Index,Len: integer): TMtxVec; overload; (*Copies values from a real Src array. The size and properties of the calling object are set implicitely. *) function CopyFromArray(const Src: TDoubleArray): TMtxVec; overload; (*Copies values from the double precision floating point Src array [SrcIndex]..[SrcIndex+Len-1] to the calling object values [Index]..[Index+len-1]. The size of the calling object is not changed. If the array border are overrun an exception will be raised. *) function CopyFromArray(const Src: TDoubleArray; SrcIndex,Index,Len: integer): TMtxVec; overload; (*Copies values from a real single precision floating point Src array. The size and properties of the calling object are set implicitely. *) function CopyFromArray(const Src: TSingleArray): TMtxVec; overload; (*Copies values from the single precision floating point Src array [SrcIndex]..[SrcIndex+Len-1] to the calling object values [Index]..[Index+len-1]. The size of the calling object is not changed. If the array border are overrun an exception will be raised. *) function CopyFromArray(const Src: TSingleArray; SrcIndex,Index,Len: integer): TMtxVec; overload; (*Copies values from an integer type Src array. The size and properties of the calling object are set implicitely. *) function CopyFromArray(const Src: TIntegerArray): TMtxVec; overload; (*Copies values from a 4 byte signed integer type Src array [SrcIndex]..[SrcIndex+Len-1]. Store the results to the calling object values [Index]..[Index+len-1]. The size of the calling object is not changed. If the array border are overrun an exception will be raised. *) function CopyFromArray(const Src: TIntegerArray; SrcIndex,Index,Len: integer): TMtxVec; overload; (*Copies values from an 2 byte signed integer type Src array. The size and properties of the calling object are set implicitely. *) function CopyFromArray(const Src: TSmallIntArray): TMtxVec; overload; (*Copies values from a 2 byte signed integer type Src array [SrcIndex]..[SrcIndex+Len-1] to the calling object values [Index]..[Index+len-1]. The size of the calling object is not changed. If the array border are overrun an exception will be raised. *) function CopyFromArray(const Src: TSmallIntArray; SrcIndex,Index,Len: integer): TMtxVec; overload; (*Copies values from a 1 byte unsigned integer type Src array. The size and properties of the calling object are set implicitely. *) function CopyFromArray(const Src: Math387.TByteArray): TMtxVec; overload; (*Copies values from a 1 byte unsigned integer type Src array [SrcIndex]..[SrcIndex+Len-1] to the calling object values [Index]..[Index+len-1]. The size of the calling object is not changed. If the array border are overrun an exception will be raised. *) function CopyFromArray(const Src: Math387.TByteArray; SrcIndex,Index,Len: integer): TMtxVec; overload; (*Copy values to an array. Copy complex values to Dst array. The size of the array is set automatically. If the calling object is not complex an exception will be raised. *) function CopyToArray(var Dst: TCplxArray): TMtxVec; overload; (*Copy complex values from the calling object [Index]..[Index+len-1] to the Dst array at positions [DstIndex]...[DstIndex+Len-1]. The size of the Dst array is not changed. *) function CopyToArray(var Dst: TCplxArray; DstIndex, Index,Len: integer): TMtxVec; overload; (*Copy values to an array. Copy complex values to Dst array. The size of the array is set automatically. If the calling object is not complex an exception will be raised. *) function CopyToArray(var Dst: TSCplxArray): TMtxVec; overload; (*Copy complex values from the calling object [Index]..[Index+len-1] to the Dst array at positions [DstIndex]...[DstIndex+Len-1]. The size of the Dst array is not changed. *) function CopyToArray(var Dst: TSCplxArray; DstIndex, Index,Len: integer): TMtxVec; overload; (*Copies values from the calling object to the Dst array and converts floating point data to integer numbers. The rounding method used is specified with the Rounding parameter. *) function CopyToArray(var Dst: TIntegerArray; Rounding: TRounding): TMtxVec; overload; (*Copy real or complex values from the calling object [Index]..[Index+len-1] to the Dst integer array at positions [DstIndex]...[DstIndex+Len-1]. The size of the Dst array is not changed. If the calling object is complex, the Index and Len parameters define the number of complex elements. The method converts floating point values to integer. Values exceeding the range of the integer type are clipped. *) function CopyToArray(var Dst: TIntegerArray; Rounding: TRounding; DstIndex, Index,Len: integer): TMtxVec; overload; (*Copies values from the calling object to the Dst array and converts floating point data to 2 byte signed integer numbers. The rounding method used is specified with the Rounding parameter. *) function CopyToArray(var Dst: TSmallIntArray; Rounding: TRounding): TMtxVec; overload; (*Copy real or complex values from the calling object [Index]..[Index+len-1] to the Dst integer array at positions [DstIndex]...[DstIndex+Len-1]. The size of the Dst array is not changed. If the calling object is complex, the Index and Len parameters define the number of complex elements. The method converts floating point values to integers. Values exceeding the range of a 2 byte signed integer type are clipped. *) function CopyToArray(var Dst: TSmallIntArray; Rounding: TRounding; DstIndex, Index,Len: integer): TMtxVec; overload; (*Copies values from the calling object to the Dst array and converts floating point data to 1 byte unsigned integer numbers. The rounding method used is specified with the Rounding parameter. *) function CopyToArray(var Dst: Math387.TByteArray; Rounding: TRounding): TMtxVec; overload; (*Copy real or complex values from the calling object [Index]..[Index+len-1] to the Dst integer array at positions [DstIndex]...[DstIndex+Len-1]. The size of the Dst array is not changed. If the calling object is complex, the Index and Len parameters define the number of complex elements. The method converts floating point values to integers. Values exceeding the range of 1 byte unsigned integer type are clipped. *) function CopyToArray(var Dst: Math387.TByteArray; Rounding: TRounding; DstIndex,Index,Len: integer): TMtxVec; overload; (*Split complex calling object in real and imaginary part. Split calling object into real and imaginary components. Store all real components in ReVec and all imaginary components in ImVec. Size and properties of ReVec and ImVec are set implicitly to match with the calling vector. An execption is raised if calling object is not complex. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TVec a,b,c; MtxVec.CreateIt(out a, out b, out c); try { a.SetIt(true, new double[] {1,-2,3,4}); a.CplxToReal(b,c); } finally { MtxVec.FreeIt(ref a, ref b, ref c); } } } *) procedure CplxToReal(const ReVec, ImVec: TMtxVec); overload; (*Split calling object elements [Index]..[Index+Len-1] into real and imaginary components. Store real components in ReVec elements [ReIndex]..[ReIndex+Len-1] and imaginary components in ImVec elements [ImIndex]..[ImIndex+Len-1]. Size and properties must be set explicitly. An exception is raised if ConditionCheck is true and array borders are overrun or underrun. *) procedure CplxToReal(const ReVec, ImVec: TMtxVec; ReIndex, ImIndex, Index, Len: integer); overload; (*DegToRad converts degrees to radians. DegToRad converts degrees to radians for all calling object elements in-place. The following transformation is used: Radians = PI*180*Degrees *) function DegToRad: TMtxVec; overload; (*DegToRad converts the degrees for calling object elements [Index]..[Index+Len-1] in-place to radians. An exception is raised, if array borders are overrun or underrun. *) function DegToRad(Index, Len: integer): TMtxVec; overload; (*DegToRad converts the degrees to radians for all X object elements. Stores the results in the calling object. Size and properties of calling object are adjusted automatically. *) function DegToRad(const X: TMtxVec): TMtxVec; overload; (*DegToRad converts degrees to radians for all X object elements [XIndex]..[XIndex+Len-1]. Stores the results in the calling object elements [Index]..[Index+Len-1]. An exception is raised, if array borders are overrun or underrun. *) function DegToRad(const X: TMtxVec; XIndex, Index, Len: integer): TMtxVec; overload; (*RadToDeg converts radians to degrees. RadToDeg converts radians to degrees for all calling object elements in-place. The following transformation is used: Degrees = Radians/(PI*180) *) function RadToDeg: TMtxVec; overload; (*RadToDeg converts the radians for calling object elements [Index]..[Index+Len-1] in-place to degrees. An exception is raised, if array borders are overrun or underrun. *) function RadToDeg(Index, Len: integer): TMtxVec; overload; (*RadToDeg converts the radians to degrees for all X object elements. Stores the results in the calling object. Size and properties of calling object are adjusted automatically. *) function RadToDeg(const X: TMtxVec): TMtxVec; overload; (*RadToDeg converts degrees to radians for all X object elements [XIndex]..[XIndex+Len-1]. Stores the results in the calling object elements [Index]..[Index+Len-1]. An exception is raised, if array borders are overrun or underrun. *) function RadToDeg(const X: TMtxVec; XIndex, Index, Len: integer): TMtxVec; overload; (*Extends a real object to a complex object. Extend the calling object to complex vector. After the calling of ExtendToComplex the imaginary part becomes the same as real part if Zeros is false. If Zeros is true the imaginary part is set to zero. The use of the in-place version of the method is discouraged because it requires 3*N copy operations, while the not-in-place version requires only 2*N copy operations. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TVec a,b; MtxVec.CreateIt(out a, out b); try { a.SetIt(false, new double[] {1, 2, 3, 4}); b.ExtendToComplex(a,true); } finally { MtxVec.FreeIt(ref a, ref b); } } } *) function ExtendToComplex(Zeros: boolean = True): TMtxVec; overload; (*Extend Vec object to complex calling object. If Zeros is true then the calling vector imaginary part is set to zero, otherwise the calling object imaginary part is the same as calling object real part. *) function ExtendToComplex(const Src: TMtxVec; Zeros: Boolean): TMtxVec; overload; (*Converts the source to complex. Converts the source to complex by setting the imaginary part to either zero (zeros = True) or same as real (zeros = false). Does not set size of the calling vector. If there is not sufficient space available to store the result an exception will be raised. *) function ExtendToComplex(const Src: TMtxVec; Zeros: Boolean; SrcIndex,DstIndex, Len: integer): TMtxVec; overload; (*Sets angle in [-2PI,2PI]. ThetaRad within -2 and interval. Calling this function prior to passing the value to trigonometric functions can significantly improve numerical accuracy. For arguments larger than 10000, the computation of sine/cosine is speeded up by about 10x for SSE2/SSE3. The performance gains for classic FPU math are also significant. The cost of this function call is approx 30% of the cost of the sine function. It is important to mention that the sine/cosine appear within many other functions especially complex versions of trigonometric functions. FixAngle method is never used implicitely within TMtxVec methods. To achieve maximum performance make sure that the arguments passed to complex trigonometric functions are "small" or scaled down. Note The vector must be real. *) function FixAngle: TMtxVec; overload; (*FixAngle for calling object complex elements [Index]..[Index+Len-1] in-place. An exception is raised if calling object property is True or if array borders are overrun/underrun. *) function FixAngle(Index,Len: integer): TMtxVec; overload; (*Sets angle in [-2PI,2PI] for all Src elements. Stores the results in the calling object. Size and properties of the calling vector are set implicitly to match the Src object. *) function FixAngle(const Src: TMtxVec): TMtxVec; overload; (*Sets angle in [-2PI,2PI] for Src elements [SrcIndex]..[SrcIndex+Len-1] and store the results in the calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if ConditionCheck is True and array borders are overrun. *) function FixAngle(const Src: TMtxVec; SrcIndex, Index,Len: integer): TMtxVec; overload; (*Rounds towards negative infinity. Rounds all calling object elements towards negative infinity in-place. Floor(-2.8) = -3 Floor(2.8) = 2 Floor(-1.0) = -1 *) function Floor: TMtxVec; overload; (*Rounds calling object elements [Index]..[Index+Len-1] towards negative infinity in-place. An exception is raised if array borders are overrun. *) function Floor(Index,Len: integer): TMtxVec; overload; (*Rounds all Src object elements towards negative infinity and stores the result in the calling object. Size and properties of the calling object are adjusted automatically. *) function Floor(const Src: TMtxVec): TMtxVec; overload; (*Rounds Src object elements [SrcIndex]..[SrcIndex+Len-1] towards negative infinity and stores the result in the calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if array borders are overrun. *) function Floor(const Src: TMtxVec; SrcIndex, Index,Len: integer): TMtxVec; overload; (*A complex exponential e^(j*Omega)). Calculate the calling object complex exponential in-place. An exception is raised if calling object is complex. If object is complex, you should use the method instead. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TVec a; MtxVec.CreateIt(out a); try { a.SetIt(false, new double[] {1,2,3,4}); a.Expj(); } finally { MtxVec.FreeIt(ref a); } } } *) function Expj: TMtxVec; overload; (*Calculate the e^(j*Omega), a complex exponential. Omega must be a real object. If omega is complex, then use the method. *) function Expj(const Omega: TMtxVec): TMtxVec; overload; (*Calculate the complex exponential for Omega elements [OmegaIndex]..[OmegaIndex+Len-1]. Store the results in calling object elemets [Index]..[Index+Len-1]. Size and properties of the calling vector must be set explicitly. An exception is raised if ConditionCheck is True and array borders are overrun or underrun. *) function Expj(const Omega: TMtxVec; OmegaIndex, Index, Len: integer): TMtxVec; overload; (*Finds a match for X in object values. the index of last matched element. If no matching elements are found, the result is -1. Compare real value X with all calling object elements. Note This method also supports the NAN and INF search. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TVec a; MtxVec.CreateIt(out a); try { a.SetIt(false, new double[] {2,5,1,6}); int indes = a.Find(1.0); // returns 2 (the arrays are zero based) } finally { MtxVec.FreeIt(ref a); } } } *) function Find(const x: double): integer; overload; (*Compare complex value X with all calling object elements. the index of last matched element. If no matching elements are found, the result is -1. An exception is raised if calling object property is false. *) function Find(const x: TCplx): integer; overload; (*Fractional part of values. Calculates the fractional part for all object values in-place. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TVec a; MtxVec.CreateIt(out a); try { a.SetIt(false, new double[] {1,5.5,-1.6,6}); a.Frac(); // a = [0, 0.5, -0.6, 0] } finally { MtxVec.FreeIt(ref a); } } } *) function Frac: TMtxVec; overload; (*Calculates the fractional part for all X object values. Stores the result in calling object. Size and properties of calling object are adjusted automatically. *) function Frac(const X: TMtxVec): TMtxVec; overload; (*Calculates the fractional part for calling object elements [Index]..[Index+Len-1] in-place. An exception is raised if array borders are overrun or underrun. *) function Frac(Index,Len: integer): TMtxVec; overload; (*Calculates the fractional part for X object elements [XIndex]..[XIndex+Len-1]. Stores the result in calling object elements [Index]..[Index+Len-1]. An exception is raised if array borders are overrun or underrun. *) function Frac(const X: TMtxVec; XIndex, Index, Len: integer): TMtxVec; overload; (*Complementary error functon of values. Calculates the complementary error function value for all object values in-place. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TVec a; MtxVec.CreateIt(out a); try { a.SetIt(false, new double[] {1,5.5,-1.6,6}); a.Erfc(); } finally { MtxVec.FreeIt(ref a); } } } *) function Erfc: TMtxVec; overload; (*Calculates the complementary error function value for all Src object values. Stores the result in calling object. Size and properties of calling object are adjusted automatically. *) function Erfc(const Src: TMtxVec): TMtxVec; overload; (*Calculates the complementary error function value for calling object elements [Index]..[Index+Len-1] in-place. An exception is raised if array borders are overrun or underrun. *) function Erfc(Index,Len: integer): TMtxVec; overload; (*Calculates the complementary error function value for Src object elements [SrcIndex]..[SrcIndex+Len-1]. Stores the result in calling object elements [Index]..[Index+Len-1]. An exception is raised if array borders are overrun or underrun. *) function Erfc(const Src: TMtxVec; SrcIndex, Index, Len: integer): TMtxVec; overload; (*Error functon of values. Calculates the error function for all object values in-place. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TVec a; MtxVec.CreateIt(out a); try { a.SetIt(false, new double[] {1, 5.5, -1.6, 6}); a.Erf(); } finally { MtxVec.FreeIt(ref a); } } } *) function Erf: TMtxVec; overload; (*Calculates the error function for all Src object values. Stores the result in calling object. Size and properties of calling object are adjusted automatically. *) function Erf(const Src: TMtxVec): TMtxVec; overload; (*Calculates the error function for calling object elements [Index]..[Index+Len-1] in-place. An exception is raised if array borders are overrun or underrun. *) function Erf(Index,Len: integer): TMtxVec; overload; (*Calculates the error function for Src object elements [SrcIndex]..[SrcIndex+Len-1]. Stores the result in calling object elements [Index]..[Index+Len-1]. An exception is raised if array borders are overrun or underrun. *) function Erf(const Src: TMtxVec; SrcIndex, Index, Len: integer): TMtxVec; overload; (*Inverse error functon of values. Calculates the Inverse error function value for all object values in-place. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TVec a; MtxVec.CreateIt(out a); try { a.SetIt(false, new double[] {1, 5.5, -1.6, 6}); a.ErfInv(); } finally { MtxVec.FreeIt(ref a); } } } *) function ErfInv: TMtxVec; overload; (*Calculates the inverse error function value for all Src object values. Stores the result in calling object. Size and properties of calling object are adjusted automatically. *) function ErfInv(const Src: TMtxVec): TMtxVec; overload; (*Calculates the inverse error function value for calling object elements [Index]..[Index+Len-1] in-place. An exception is raised if array borders are overrun or underrun. *) function ErfInv(Index,Len: integer): TMtxVec; overload; (*Calculates the inverse error function value for Src object elements [SrcIndex]..[SrcIndex+Len-1]. Stores the result in calling object elements [Index]..[Index+Len-1]. An exception is raised if array borders are overrun or underrun. *) function ErfInv(const Src: TMtxVec; SrcIndex, Index, Len: integer): TMtxVec; overload; (*Flips the real and imaginary part of complex numbers. Flipped real and imaginary part of complex numbers for all calling object elements in-place. The following transformation is used: a + i*b -> b + i*a *) function Flip: TMtxVec; overload; (*Flips the real and imaginary part of complex numbers for calling object elements [Index]..[Index+Len-1] in-place. An exception is raised if array borders are overrun or underrun. *) function Flip(Index, Len: integer): TMtxVec; overload; (*Flips the real and imaginary part of complex numbers for all X object elements. Xtore the results in the calling object. Size and properties of calling object are adjusted automatically. *) function Flip(const X: TMtxVec): TMtxVec; overload; (*Flips the real and imaginary part of complex numbers for X object elements [XIndex]..[XIndex+Len-1]. Store the results in the calling object elements [Index]..[Index+Len-1]. An exception is raised if array borders are overrun or underrun. *) function Flip(const X: TMtxVec; XIndex, Index, Len: integer): TMtxVec; overload; (*Flips the real and imaginary part of complex numbers and conjugates the complex numbers. Performs the following transformation: a + i*bi ==> b - i*a Method flips the real and imaginary part and conjugates calling object complex elements in-place. *) function FlipConj: TMtxVec; overload; (*Flip calling object complex elements [Index]..[Index+Len-1] in-place. An exception is raised if calling object property is false or if array borders are overrun/underrun. *) function FlipConj(Index, Len: integer): TMtxVec; overload; (*Flip all X object complex elements. Store the results in calling object. Size and property of calling object are adjusted automatically. *) function FlipConj(const X: TMtxVec): TMtxVec; overload; (*Flip X object complex elements [XIndex]..[XIndex+Len-1]. Store the results in calling object elements [Index]..[Index+Len-1]. An exception is raised if calling object property is false or if array borders are overrun/underrun. *) function FlipConj(const X: TMtxVec; XIndex, Index, Len: integer): TMtxVec; overload; (*The inverse of square root 1/(v)^1/2. Calculate the inverse square root 1/(element)^(1/2)) of all calling object elements in-place. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TVec a; MtxVec.CreateIt(out a); try { a.SetIt(false, new double[] {1, 16}); a.InvSqrt(); // returns [1,0.25] } finally { MtxVec.FreeIt(ref a); } } } *) function InvSqrt: TMtxVec; overload; (*Calculate the inverse of square root for calling object elements [Index]..[Index+Len-1] in-place. An exception is raised if ConditionCheck is True and array borders are overrun. *) function InvSqrt(Index, Len: integer): TMtxVec; overload; (*Calculate the inverse of square root for all X elements. Store the results in the calling object. Size and properties of the calling vector are set implicitly to match the X object. *) function InvSqrt(const X: TMtxVec): TMtxVec; overload; (*Calculate the inverse of square root for X elements [XIndex]..[XIndex+Len-1]. Store the results in the calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if ConditionCheck is True and array borders are overrun. *) function InvSqrt(const X: TMtxVec; XIndex, Index, Len: integer): TMtxVec; overload; (*The inverse of cube root 1/(v)^1/3. Calculate the inverse cube root (1/(element)^(1/3)) of all calling object elements in-place. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TVec a; MtxVec.CreateIt(out a); try { a.SetIt(false, new double[] {-1, 8}); a.InvCbrt(); // returns [-1,0.5] } finally { MtxVec.FreeIt(ref a); } } } *) function InvCbrt: TMtxVec; overload; (*Calculate the inverse of cube root for calling object elements [Index]..[Index+Len-1] in-place. An exception is raised if ConditionCheck is True and array borders are overrun. *) function InvCbrt(Index, Len: integer): TMtxVec; overload; (*Calculate the inverse of cube root for all X elements. Store the results in the calling object. Size and properties of the calling vector are set implicitly to match the X object. *) function InvCbrt(const X: TMtxVec): TMtxVec; overload; (*Calculate the inverse of cube root for X elements [XIndex]..[XIndex+Len-1]. Store the results in the calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if ConditionCheck is True and array borders are overrun. *) function InvCbrt(const X: TMtxVec; XIndex, Index, Len: integer): TMtxVec; overload; (*The Reminder after division X/Y. Calculates reminder after division according to formula: x[i]-y[i]*Trunc(x[i]/y[i]). The results will be saved to the calling vector. X and Y must be a real and have the same length. Size and properties of the calling vector are set implicitly to match the X object. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TVec a,b,c; MtxVec.CreateIt(out a, out b, out c); try { a.SetIt(false, new double[] {0,1,10,-1,-10}); // a = [0, 1, 10, -1, -10]; b.SetIt(false,new double[],{0,1,System.Math.PI,-1,-System.Math.PI}); // b = [0, 1, Pi, -1, -Pi]; c.Rem(a,b); // c = [0, 0, 0.5752, 0, -0.5752] } finally { MtxVec.FreeIt(ref a,ref b,ref c); } } } *) function Rem(const X, Y: TMtxVec): TMtxVec; overload; (*Calculates reminder after division X/Y. Calculation uses the following formula: z[i] = x[xi]-y[yi]*Trunc(x[xi]/y[yi]), where i in [Index..Index+Len], xi in [XIndex..XIndex+Len], yi in [YIndex..YIndex+Len]. The results will be saved to the calling vector. X must be a real. An exception will be raised if ConditionCheck is True and array borders are overrun. *) function Rem(const X, Y: TMtxVec; XIndex, YIndex, Index, Len: integer): TMtxVec; overload; (*Calculates reminder after division X/Y. Reminder is calculated by using the following formula: x[i]-y*Trunc(x[i]/y). X must be a real. The results will be saved to the calling vector. Size and properties of the calling vector are set implicitly to match the X object. *) function Rem(const X: TMtxVec; const Y: double): TMtxVec; overload; (*Calculates reminder after division X/Y. Reminder is calculated by using the following formula: x[i]-y*Trunc(x[i]/y). X must be a real. The results will be saved to the calling vector. An exception will be raised if ConditionCheck is True and array borders are overrun. *) function Rem(const X: TMtxVec; const Y: double; XIndex, Index, Len: integer): TMtxVec; overload; (*Magnitude. Calculate the magnitude for all calling object elements in-place. This method has the same function as the method. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TVec a; MtxVec.CreateIt(out a); try { a.SetIt(false, new double[] {1,-2,3,4}); // a = [1,-2, 3,4] a.Mag(); // a = [1, 2, 3,4] } finally { MtxVec.FreeIt(ref a); } } } *) function Mag: TMtxVec; overload; (*Calculate the magnitude for calling object elements [Index]..[Index+Len-1] in-place. An exception is raised if ConditionCheck is True and array borders are overrun. *) function Mag(Index, Len: integer): TMtxVec; overload; (*Calculate the magnitude for all X elements. Store the results in the calling object elements. Size and properties of the calling vector are set implicitly to match Vec vector. *) function Mag(const X: TMtxVec): TMtxVec; overload; (*Calculate the magnitude for X elements [XIndex]..[XIndex+Len-1]. Store the results in the calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if ConditionCheck is True and array borders are overrun. *) function Mag(const X: TMtxVec; XIndex, Index, Len: integer): TMtxVec; overload; (*Multiply object elements with Value. Multiply all calling object elements with Value in-place. This method is the same as the method overloads multiplying with vector elements with a scalar. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TVec a; MtxVec.CreateIt(out a); try { a.SetIt(false, new double[] {2,3,5}); // a = [2,3,5] a.Scale(3); // a = [6,9,15] } finally { MtxVec.FreeIt(ref a); } } } *) function Scale(const Factor: double): TMtxVec; overload; (*Multipy calling object elements [Index]..[Index+Len-1] with Value in-place. An exception is raised if array borders are overrun or underrun. *) function Scale(const Factor: double; Index, Len: integer): TMtxVec; overload; (*Multiply all calling object elements with a complex Value in-place.*) function Scale(const Factor: TCplx): TMtxVec; overload; (*Multipy calling object elements [Index]..[Index+Len-1] with complex Value in-place. An exception is raised if array borders are overrun or underrun. *) function Scale(const Factor: TCplx; Index, Len: integer): TMtxVec; overload; (*Scatter object elements. Scatter the elements of the Src and store them in the calling object according to the IndexType, Increment and Offset parameters. The Indexes vector is used only if IndexType is either indVector or indMask. If IndexType is indVector, the values from the Indexes object denote the index positions in the calling object to which the values should be copied from the Src. The Indexes vector must have the indexes stored in the IValues array. The IValues integer arrays points the same memory as Values array. The Increment and Offset parameters are used only if TIndexType is indIncrement. They define the target offset and a fixed step (increment) between calling vector elements. If IndexType is indMaks the Indexes object must have the same size as the Src object. The routine will copy only those elements from the Src to the calling object, for which there is a 1 at the coresponding index in the Indexes object.The elements in the calling object are stored consecutively. See the method to see how to perform gathering. The performance of the CPU heavily depends on the assumption that elements are stored at consecutive memory locations. If it is neccessary to apply a set of operations only to elements at specific indexes, performance-wise it can prove to be very helpfull, if the elements are gathered first. *) function Scatter(const Src: TMtxVec; const Indexes: TVecInt = nil; IndexType: TIndexType = indVector; Increment: integer = 1; Offset: integer = 0): TMtxVec; overload; (* Scatters Src elements starting at Offset and with Increment to the calling object. *) function ScatterByIncr(const Src: TMtxVec; Increment: integer = 1; Offset: integer = 0): TMtxVec; overload; (* Scatters Src elements defined with indices stored in Indexes to the calling object. *) function ScatterByIndexes(const Src: TMtxVec; const Indexes: TVecInt): TMtxVec; overload; (* Scatters Src elements defined with the Mask to the calling object. The elements are assumed to be not scattered in the Src! This is not a masked copy operation. It is a reverse of GatherByMask. *) function ScatterByMask(const Src: TMtxVec; const Mask: TMtxVecInt; allow_resizing: boolean = False): TMtxVec; overload; (*Copies those values from MaskVec, at which aMask is different from 0.*) function Mask(const MaskVec: TMtxVec; const aMask: TMtxVecInt): TMtxVec; overload; (*Copies those values from MaskVecNot, at which aMask is equal to 0.*) function MaskNot(const MaskVecNot: TMtxVec; const aMask: TMtxVecInt): TMtxVec; overload; (*Assigns Value at indexes of the calling object, at which aMask is different from 0.*) function Mask(const Value: double; const aMask: TMtxVecInt): TMtxVec; overload; (*Assigns Value at indexes of the calling object, at which aMask is equal to 0.*) function MaskNot(const Value: double; const aMask: TMtxVecInt): TMtxVec; overload; (*Assigns Value at indexes of the calling object, at which aMask is different from 0.*) function Mask(const Value: TCplx; const aMask: TMtxVecInt): TMtxVec; overload; (*Assigns Value at indexes of the calling object, at which aMask is equal to 0.*) function MaskNot(const Value: TCplx; const aMask: TMtxVecInt): TMtxVec; overload; (*Sets object values. Set object values. Method call does not change object's size or property, but it does check for array overrun. The elements of A array are copied to the calling object elements, starting at Index. If the calling object is complex, then real parts of complex numbers are on even (0,2,4..) and imaginary parts on odd indexes.(1,3,5,..). *) function SetIt(Index: integer; const A: array of double): TMtxVec; overload; (*The elements of A array, starting at aIndex, are copied to the calling object elements, starting at Index. If the calling object is complex, then real parts of complex numbers in the A array are on even (0,2,4..) and imaginary parts on odd indexes.(1,3,5,..). *) function SetIt(Index, aIndex, Len: integer; const A: array of double): TMtxVec; overload; (*Sets object complex values. The a array complex values are copied to the calling object CValues from [Index]..[Index+Length(a)-1]. An exception is raised if calling object array borders are overrun/underrun. Note Use this method for complex array only. *) function SetCplx(Index: integer; const A: array of TCplx): TMtxVec; overload; (*Sets object values (single). The single elements of A array are copied to the calling object elements [Index]..[Index+Length(A)-1]. An exception is raised if calling object array borders are overrun/underrun. Note Use this method for integer array only. *) function SetSingle(Index: integer; const A: array of single): TMtxVec; overload; function SetSingle(Index: integer; aIndex, Len: integer; const A: array of single): TMtxVec; overload; (*Sets object values (double). The double elements of A array are copied to the calling object elements [Index]..[Index+Length(A)-1]. An exception is raised if calling object array borders are overrun/underrun. Note Use this method for integer array only. *) function SetDouble(Index: integer; const A: array of double): TMtxVec; overload; function SetDouble(Index: integer; aIndex, Len: integer; const A: array of double): TMtxVec; overload; (*Sets object values (integer). The integer elements of A array are copied to the calling object elements [Index]..[Index+Length(A)-1]. An exception is raised if calling object array borders are overrun/underrun. Note Use this method for integer array only. *) function SetInteger(Index: integer; const A: array of Integer): TMtxVec; overload; function SetInteger(Index: integer; aIndex, Len: integer; const A: array of Integer): TMtxVec; overload; (*Square. Calculate the square of all caling object elements in-place. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TVec a; MtxVec.CreateIt(out a); try { a.SetIt(true,new double[] {1,2,3,4}); a.Sqr(); // a=[1,4,9,16] } finally { MtxVec.FreeIt(ref a); } } } *) function Sqr: TMtxVec; overload; (*Calculate the square of calling object elements [Index]...[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function Sqr(Index, Len: integer): TMtxVec; overload; (*Calculate the square of all X object elements. Store the results in the calling object. Size and properties of calling object are adjusted automatically. *) function Sqr(const X: TMtxVec): TMtxVec; overload; (*Calculate the square of X object elements [XIndex]..[XIndex+Len-1]. The results are stored in calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object are not changed. An exception is raised if array borders are overrun. *) function Sqr(const X: TMtxVec; XIndex, Index, Len: integer): TMtxVec; overload; (*Square root. Calculate the square root of all caling object elements in-place. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TVec a; MtxVec.CreateIt(out a); try { a.SetIt(true,new double[] {1,4,9}); a.Sqrt(); // a=[1,2,3] } finally { MtxVec.FreeIt(ref a); } } } *) function Sqrt: TMtxVec; overload; (*Calculate the square root of calling object elements [Index]...[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function Sqrt(Index, Len: integer): TMtxVec; overload; (*Calculate the square root of all X object elements. Store the results in the calling object. Size and properties of the calling object are adjusted automatically. *) function Sqrt(const X: TMtxVec): TMtxVec; overload; (*Calculate the square root of X object elements [XIndex]..[XIndex+Len-1]. The results are stored in calling object elements [Index]..[Index+Len-1]. Size and properties of calling object are not changed. An exception is raised if array borders are overrun. *) function Sqrt(const X: TMtxVec; XIndex, Index, Len: integer): TMtxVec; overload; (*Log base N. Log base N for all calling object elements in-place. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TVec a; MtxVec.CreateIt(out a); try { a.SetIt(true,new double[] {1,2,3,4}); a.LogN(10.0); // log base 10, the slow way a = [Log10(1), Log10(2),...] } finally { MtxVec.FreeIt(ref a); } } } *) function LogN(const N: double): TMtxVec; overload; (*Calculate the log base N of calling object elements [Index]..[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function LogN(const N: double; Index, Len: integer):TMtxVec; overload; (*Calculate the log base N of all X object elements. Store the results in calling object. Size and properties of the calling object are adjusted automatically. *) function LogN(const N: double; const X: TMtxVec): TMtxVec; overload; (*Calculate the log base N of X object elements [XIndex]..[XIndex+Len-1]. The results are stored in calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object are not changed. An exception is raised if array borders are overrun. *) function LogN(const N: double; const X: TMtxVec; XIndex, Index, Len: integer): TMtxVec; overload; (*Multiply object elements with Value. Multiplies all calling object elements with Value in-place. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TVec a; MtxVec.CreateIt(out a); try { a.SetIt(false,new double[] {2,3,5}); // a = [2,3,5] a.Mul(3); // a = [6,9,15] } finally { MtxVec.FreeIt(ref a); } } } *) function Mul(const Value: double): TMtxVec; overload; (*Multiply all calling object elements with complex Value in-place.*) function Mul(const Value: TCplx): TMtxVec; overload; (*Multipy calling object elements [Index]..[Index+Len-1] with Value in-place. An exception is raised if array borders are overrun or underrun. *) function Mul(const Value: double; Index, Len: integer): TMtxVec; overload; (*Multipy calling object elements [Index]..[Index+Len-1] with complex Value in-place. An exception is raised if array borders are overrun or underrun. *) function Mul(const Value: TCplx; Index, Len: integer): TMtxVec; overload; (*Multiply each element of Vec with Value. Store the result in the calling object. Size and properties of the calling object are adjusted automatically. *) function Mul(const Vec: TMtxVec; const Value: double): TMtxVec; overload; (*Multiply each element of Vec with complex Value. Store the result in the calling object. Size of the calling object is set automatically. property of the calling object is set to True. *) function Mul(const Vec: TMtxVec; const Value: TCplx): TMtxVec; overload; (*Multiply Vec elements [VecIndex]..[VecIndex+Len-1] with Value. Store the result in calling object elements [Index]..[Index+Len-1]. Size of the calling object is not changed. An exception is raised if array borders are overrun or underrun. propertiy of the calling object is set implicitly. *) function Mul(const Vec: TMtxVec; const Value: double; VecIndex, Index, Len: integer): TMtxVec; overload; (*Multiply Vec elements [VecIndex]..[VecIndex+Len-1] with complex Value. Store the result in calling object elements [Index]..[Index+Len-1]. Size of the calling object is not changed. An exception is raised if array borders are overrun or underrun. propertiy of the calling object is set to True. *) function Mul(const Vec: TMtxVec; const Value: TCplx; VecIndex, Index, Len: integer): TMtxVec; overload; (*Multiply elements by imaginary unit I.*) function MulI: TMtxVec; overload; (*Multipy calling object elements [Index]..[Index+Len-1] with I in-place.*) function MulI(Index: integer; Len: integer): TMtxVec; overload; (*Multiply X elements with I and store the result in the calling object.*) function MulI(const X: TMtxVec): TMtxVec; overload; (*Multipy X elements [XIndex]..[XIndex+Len-1] with I. Xtore the result in the calling object at locations [Index]..[Index+Len-1]. *) function MulI(const X: TMtxVec; XIndex: integer; Index: integer; Len: integer): TMtxVec; overload; (*Normalize data. Normalizes values in the calling object by subtracting a constant Offset from Elements and dividing the result by constant Factor: The results are stored in calling object. Use this method if you want to do a multiply and add (scale and offset) operations in a single method call. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TVec a; MtxVec.CreateIt(out a); try { a.SetIt(false,new double[] {1,2,3,4}); // a = [1,2,3,4] a.Normalize(2,3); } finally { MtxVec.FreeIt(ref a); } } } *) function Normalize(const SubOffset, DivFactor: double): TMtxVec; overload; (*Normalize by subtracting a complex constant SubOffset from Vec elements and dividing the result by complex constant DivFactor. Size and property of calling object are adjusted automatically. An exception is raised, if object is complex. *) function Normalize(const SubOffset, DivFactor: TCplx): TMtxVec; overload; (*Normalize objects complex values [Index]..[Index+Len-1] by subtracting a complex constant SubOffset from Vec elements and dividing the result by complex constant DivFactor. An exception is raised, if object is not complex or array borders are overrun/underrun. *) function Normalize(const SubOffset, DivFactor: TCplx; Index,Len: integer): TMtxVec; overload; (*Normalize object values [Index]..[Index+Len-1] by subtracting a real constant SubOffset from Vec elements and dividing the result by complex constant DivFactor. Store the results in calling vector values [Index]..[Index+Len-1]. An exception is raised, if Vec or calling object is complex or array borders are overrun/underrun. *) function Normalize(const SubOffset, DivFactor: double; Index,Len: integer): TMtxVec; overload; (*Normalize object by subtracting a complex constant SubOffset from elements and dividing the result by real constant DivFactor. An exception is raised, if object is not complex. *) function Normalize(const SubOffset: TCplx; const DivFactor: double): TMtxVec; overload; (*Normalize objects complex values [Index]..[Index+Len-1] by subtracting a complex constant SubOffset from elements and dividing the result by real constant DivFactor. Store the results in calling vector complex values [Index]..[Index+Len-1]. An exception is raised, if the calling object is not complex or array borders are overrun/underrun. *) function Normalize(const SubOffset: TCplx; const DivFactor: double; Index,Len: integer): TMtxVec; overload; (*Normalize object. Normalizes Vec object by subtracting a constant Offset from Vec elements and dividing the result by constant Factor: The results are stored in calling object. Use this method if you want to do a multiply and add (scale and offset) operations in a single method call. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TVec a,b; MtxVec.CreateIt(out a, out b); try { a.SetIt(false,new double[] {1,2,3,4}); // a = [1,2,3,4] b.Normalize(a,2,3); } finally { MtxVec.FreeIt(ref a, ref b); } } } *) function Normalize(const Vec: TMtxVec; const SubOffset, DivFactor: Double): TMtxVec; overload; (*Normalize Vec object by subtracting a complex constant SubOffset from Vec elements and dividing the result by complex constant DivFactor. Size and property of calling object are adjusted automatically. An exception is raised if Vec is complex. *) function Normalize(const Vec: TMtxVec; const SubOffset, DivFactor: TCplx): TMtxVec; overload; (*Normalize Vec object complex values [VecIndex]..[VecIndex+Len-1] by subtracting a complex constant SubOffset from Vec elements and dividing the result by complex constant DivFactor. Store the results in calling vector complex values [Index]..[Index+Len-1]. An exception is raised if Vec or calling object is not complex or array borders are overrun/underrun. *) function Normalize(const Vec: TMtxVec; const SubOffset, DivFactor: TCplx; VecIndex,Index,Len: integer): TMtxVec; overload; (*Normalize Vec object values [VecIndex]..[VecIndex+Len-1] by subtracting a real constant SubOffset from Vec elements and dividing the result by complex constant DivFactor. Store the results in calling vector values [Index]..[Index+Len-1]. An exception is raised if Vec or calling object is complex or array borders are overrun/underrun. *) function Normalize(const Vec: TMtxVec; const SubOffset, DivFactor: Double; VecIndex,Index,Len: integer): TMtxVec; overload; (*Normalize Vec object by subtracting a complex constant SubOffset from Vec elements and dividing the result by real constant DivFactor. Size and property of calling object are adjusted automatically. An exception is raised if Vec is complex. *) function Normalize(const Vec: TMtxVec; const SubOffset: TCplx; const DivFactor: Double): TMtxVec; overload; (*Normalize Vec object complex values [VecIndex]..[VecIndex+Len-1] by subtracting a complex constant SubOffset from Vec elements and dividing the result by real constant DivFactor. Store the results in calling vector complex values [Index]..[Index+Len-1]. An exception is raised if Vec or calling object is not complex or array borders are overrun/underrun. *) function Normalize(const Vec: TMtxVec; const SubOffset: TCplx; const DivFactor: Double; VecIndex,Index,Len: integer): TMtxVec; overload; (*Converts the polar magnitude/phase pairs to cartesian pairs. Convert all AmpltVec and PhaseVec elements (combined) from polar to cartesian form. If AmpltVec and PhaseVec size is not the same , an exeption is raised. The results are stored as complex numbers (x=Re, y=Im) in the calling object. Size and properties of the calling object are set implicitly to match AmpltVec and PhaseVec objects. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TVec a,b,c; MtxVec.CreateIt(out a, out b, out c); try { a.SetIt(false, new double[] {1,2,3,4}); // a = [1,2,3, 4] //magnitude b.SetIt(false, new double[] {1,0,1,-1}); // b = [1,0,1,-1] /phase c.PolarToCart(a,b); // result stored in c = projections to Re and Im axis } finally { MtxVec.FreeIt(ref a, ref b, ref c); } } } *) function PolarToCart(const AmpltVec, PhaseVec: TMtxVec): TMtxVec; overload; (*Convert AmpltVec elements [aIndex]..[aIndex+Len-1] and PhaseVec elements [PIndex]..[PIndex+Len-1] from polar form (radius,angle) to cartesian form (x,y). The results are stored as complex numbers (x=Re, y=Im) in the calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if ConditionCheck is True and array borders are overrun/underrun. *) function PolarToCart(const AmpltVec, PhaseVec: TMtxVec; aIndex, PIndex,Index, Len: integer): TMtxVec; overload; (*Raises base object elements to any power. Raises Base calling object elements to any power. The is faster, if Exponent is an integer. Real valued power can handle only positive Exponent. can handle negative exponent also. To compute a power to the negative exponent in general case or when the base is negative, use the complex version of the function. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TVec a; MtxVec.CreateIt(out a); try { a.SetIt(false, new double[] {1,2,3,4}); // a = [1,2,3, 4] //magnitude a.Power(1.2); } finally { MtxVec.FreeIt(ref a); } } } *) function Power(const Exponent: double): TMtxVec; overload; (*Raises all calling vector elements to complex power Exponent in-place. If the calling vector is real and has negative elements, the result will be NAN at those entries. To obtain a valid result in this case, extend the calling vector to complex with method. In all real/complex combinations, the Power method will not automatically assume that a number is complex to speed up the computation. Alternatively the user can of course always convert the real numbers to complex before passing them to the Power routine. *) function Power(const Exponent: TCplx): TMtxVec; overload; (*The phase angles (spectrum) of object elements. Calculates the phase angles (spectrum) of all Vec object elements. Phase values are returned in radians and are in the range -PI,PI. Size and properties of the calling object are set implicitly to match Vec object. The phase angles are calculated from the following equation: using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TVec a,b; MtxVec.CreateIt(out a, out b); try { a.SetIt(true, new double[] {1,2,3,-4}); b.PhaseSpectrum(a); // b = [arctan2(1,2), arctan2(3,-4)]; } finally { MtxVec.FreeIt(ref a, ref b); } } } *) function PhaseSpectrum(const Vec: TMtxVec): TMtxVec; overload; (*Calculates the power spectrum from the Vec elements [VecIndex]..[VecIndex+Len-1]. Store the results in calling object elements [Index]..[Index+Len-1]. An exception is raised if array borders are overrun/underrun. *) function PhaseSpectrum(const Vec: TMtxVec; VecIndex, Index,Len: integer): TMtxVec; overload; (*The power spectrum from object complex values. Calculates the power spectrum from the Vec object complex values and stores the results (power spectrum) in the real calling object. Size and properties of the calling object are set implicitly to match Vec object. The spectrum elements are squares of the magnitudes of the complex input elements: using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TVec a,b; MtxVec.CreateIt(out a, out b); try { a.SetIt(true, new double[] {1,2,3,4}); // a = [1 + 2i, 3 - 4i] b.PhaseSpectrum(a); // b = [arctan2(1,2), arctan2(3,-4)]; } finally { MtxVec.FreeIt(ref a, ref b); } } } *) function PowerSpectrum(const Vec: TMtxVec): TMtxVec; overload; (*Calculates the power spectrum from the Vec complex elements [VecIndex]..[VecIndex+Len-1]. Store the results in calling object real elements [Index]..[Index+Len-1]. An exception is raised if calling object property is true or if array borders are overrun/underrun. *) function PowerSpectrum(const Vec: TMtxVec; VecIndex, Index,Len: integer): TMtxVec; overload; (*Raises base elements to exponent power. Raises Base value to Exponent object values powers and store the results to calling object values. Size and properties of calling object are adjusted automatically. *) function Power(const Base: double; const Exponent: TMtxVec): TMtxVec; overload; (*Raises Base complex value to Exponent object values powers. Store the results to calling object values. Size and properties of calling object are adjusted automatically. *) function Power(const Base: TCplx; const Exponent: TMtxVec): TMtxVec; overload; (*Raises each of Base object elements to corresponding power, stored in Exponenet elements. Power[i] = Base[i]^Exponent[i] Size and property of calling object are adjusted automatically. An exception is raised if Base and Exponent sizes do not match. *) function Power(const Base, Exponent: TMtxVec): TMtxVec; overload; (*Raises each of the Base object elements to complex Exponent power. Size and properties of calling object are adjusted automatically. *) function Power(const Base: TMtxVec; const Exponent: TCplx): TMtxVec; overload; (*Raises each of the Base object elements to real Exponent power. Size and properties of calling object are adjusted automatically. *) function Power(const Base: TMtxVec; const Exponent: double): TMtxVec; overload; (*Raises Base object elements to Exponent object elements power. Raises Base elements to Exponent elements power. Only positive exponents can be handled if exponent object property is True. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TVec a,b,c; MtxVec.CreateIt(out a, out b, out c); try { a.SetIt(true, new double[] {1,2,3,4}); b.SetIt(true, new double[] {3,2,2,2}); c.PowerVec(a,b); } finally { MtxVec.FreeIt(ref a, ref b, ref c); } } } *) function PowerVec(const Base, Exponent: TMtxVec): TMtxVec; (*Elements product. the product of all calling object elements An exception is raised if calling object property is true. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TVec a; MtxVec.CreateIt(out a); try { a.SetIt(true, new double[] {1,2,3,4}); double c = a.Product_(); // c= 24 } finally { MtxVec.FreeIt(ref a); } } } *) function Product: double; overload; (*Returns the product for calling object elements [Index]..[Index+Len-1]. An exception is raised if array borders are overrun or underrun. *) function Product(Index,Len: integer): double; overload; (*Calculate the product of all calling object complex elements. Store the result in complex variable X. *) procedure Product(out X: TCplx); overload; (*Calculate the product for calling object complex elements [Index]..[Index+Len-1]. Store the result in complex variable X. An exception is raised if array borders are overrun or underrun. *) procedure Product(out X: TCplx; Index,Len: integer); overload; (*Calculate the product of all calling object elements. Store the result in real variable X. *) procedure Product(out X: double); overload; (*Calculate the product for calling object elements [Index]..[Index+Len-1]. Store the result in real variable X. An exception is raised if array borders are overrun or underrun. *) procedure Product(out X: double; Index,Len: integer); overload; (*Elements product. the complex product of all calling object complext elements. An exception is raised if calling object property is false. *) function Productc: TCplx; overload; (*Returns the complex product for calling object complex elements [Index]..[Index+Len-1]. An exception is raised if array borders are overrun or underrun or if propety is false. *) function Productc(Index,Len: integer): TCplx; overload; (*The pseudo random sample generator with Gaussian distribution. Fills the calling object values with pseudo random samples following the Gaussian distribution with parameters: Mean = 0, StdDev = 1 ("Standard disctribution"). The value for the seed is obtained from the CPU clock. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TVec a; MtxVec.CreateIt(out a); try { a.Size(500,false); a.RandGauss(); } finally { MtxVec.FreeIt(ref a); } } } *) function RandGauss: TMtxVec; overload; (*Fills the calling object values with pseudo random samples following the Gaussian distribution. The algorithm uses parameter AMean and AStdDev. The value for the seed is obtained from the CPU clock. *) function RandGauss(AMean, AStdDev: double): TMtxVec; overload; (*Fills the calling object values with pseudo random samples following the Gaussian distribution. The algorithm uses parameters AMean, AStdDev and Seed. *) function RandGauss(Seed: cardinal; AMean, AStdDev: double): TMtxVec; overload; (*Randomly shuffles the content of the vector. Scrambles the contents of the vector randomly by using the Fisher Yates shuffle. *) function RandomShuffle: TMtxVec; (*The pseudo random sample generator with continuous uniform distribution. Fills the calling object values with pseudo random samples following the continuous uniform distribution using the parameters Low = 0, High = 1. The value for the seed is obtained from the CPU clock. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TVec a; MtxVec.CreateIt(out a); try { a.Size(100,false); a.RandUniform(); } finally { MtxVec.FreeIt(ref a); } } } *) function RandUniform: TMtxVec; overload; (*Fills the calling object values with pseudo random samples following the continuous uniform distribution. The algorithm used parameters Low and High. The value for the seed is obtained from the CPU clock. *) function RandUniform(aLow, aHigh: double): TMtxVec; overload; (*Fills the calling object values with pseudo random samples following the continuous uniform distribution. The algorithm uses parameters Low and High and Seed. *) function RandUniform(Seed: cardinal; aLow, aHigh: double): TMtxVec; overload; (*Gets real part of complex object values. The method method gets the real part of a complex object Vec and stores the real results in the calling object. Size and properties of the calling object are set implicitly to match Vec object. Vec property must be true otherwise an exception is raised. var a,b: TVec; begin CreateIt(a,b); try a.SetIt(True,[1,2,3,4]); // = [1+2i, 3+4i] b.RealPart(a); // b = [1,3] finally FreeIt(a,b); end; end; *) function RealPart(const Vec: TMtxVec): TMtxVec; overload; (*Gets the real part of a Vec object complex elements [VecIndex]..[VecIndex+Len-1]. Stores the results in calling object real elements [Index]..[Index+Len-1]. An exception is raised if array borders are overrun or underrun or if Vec object propety is false. *) function RealPart(const Vec: TMtxVec; VecIndex,Index,Len: integer): TMtxVec; overload; (*Read values content from stream to object. Reads values content from SrcStream stream to calling objct. No other values describing the data type or length are read from the DstStream. Number type is defined by the Precision parameter, which can be obtained from method call. The function returns the number of bytes read. Note Use this method separately only, if you want user defined storage format. var b: TVec; AStream: TFileStream; Precision: TPrecision; begin CreateIt(b); AStream := TFileStream.Create('C:\test.bin',fmOpenRead); try Precision := b.ReadHeader(AStream); // Read info for b b.ReadValues(AStream,Precision); // Read values of b finally AStream.Free; FreeIt(b); end; end; *) function ReadValues(const Src: TStream; Precision: TPrecision; Endian: TEndianness = MtxSystemEndianness): Int64; overload; virtual; (*Constructs a complex object from two real objects. Construct a complex object from the ReVec (real part) and the ImVec (imaginary part) objects. The results are stored in the calling object. Size and properties of the calling object are set implicitly to match ReVec and ImVec objects. An exception is raised if ReVec or ImVec property is True. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TVec a,b,c; MtxVec.CreateIt(out a, out b, out c); try { a.SetIt(true, new double[] {1,2, 3,4}); // 1+2i ; 3+4i b.SetIt(true, new double[] {2,2,3,4}); // 2+2i ; 3+4i c.RealToCplx(a,b); } finally { MtxVec.FreeIt(ref a, ref b, ref c); } } } *) function RealToCplx(const ReVec, ImVec: TMtxVec): TMtxVec; overload; (*Construct a complex object from the ReVec elements [ReIndex]..[ReIndex+Len-1] (real part) and the ImVec elements [ImIndex]..[ImIndex+Len-1] (imaginary part). The results are stored to calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if ConditionCheck is True and array borders are overrun. An exception is also raised if ReVec or ImVec property is True. *) function RealToCplx(const ReVec, ImVec: TMtxVec; ReIndex, ImIndex, Index, Len: integer): TMtxVec; overload; (*Resets object properties to default values. Resets object properties to default values. The method is used by the Object cache management to reset the properties of the object freed with a call to . *) procedure Reset; override; (*Search and replace a value. Replaces the SearchValue with a ReplaceValue, where the searchValue is compared with Tol to the values of the calling object. *) function Replace(const SearchValue, ReplaceValue: double; const Tol: double = 0.0001): TMtxVec; overload; function Replace(const SearchValue, ReplaceValue: single; const Tol: single = 0.0001): TMtxVec; overload; (*Replaces the SearchValue with a ReplaceValue, where the searchValue is compared with Tol to the calling object elements [Index]..[Index+Len-1]. An exception is raised if array borders are overrun/underrun. *) function Replace(const SearchValue, ReplaceValue: double; Index, Len: integer; const Tol: double = 0.0001): TMtxVec; overload; function Replace(const SearchValue, ReplaceValue: single; Index, Len: integer; const Tol: single = 0.0001): TMtxVec; overload; (*Search and replace a complex value.*) function Replace(const SearchValue, ReplaceValue: TCplx; const Tol: double = 0.0001): TMtxVec; overload; function Replace(const SearchValue, ReplaceValue: TSCplx; const Tol: single = 0.0001): TMtxVec; overload; (*Replaces the SearchValue with a ReplaceValue, where the searchValue is compared with Tol to the calling object elements [Index]..[Index+Len-1]. An exception is raised if array borders are overrun/underrun. *) function Replace(const SearchValue, ReplaceValue: TCplx; Index, Len: integer; const Tol: double = 0.0001): TMtxVec; overload; function Replace(const SearchValue, ReplaceValue: TSCplx; Index, Len: integer; const Tol: single = 0.0001): TMtxVec; overload; (*Root mean square (RMS). Calculate the root mean square value for all calling object elements in-place. The root mean square (RMS) is defined by the equation: using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TVec a; MtxVec.CreateIt(out a); try { a.SetIt(true, new double[] {1,2, 3,4}); // 1+2i ; 3+4i double c = a.RMS(); } finally { MtxVec.FreeIt(ref a); } } } *) function RMS: double; overload; (*Calculate the RMS for calling object elements [Index]..[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function RMS(Index, Len: integer): double; overload; (*Elements rounded to the nearest whole number. Rounds all calling object elements to the nearest whole number. The result can be stored to an array of integers or as floating point number. *) function Round: TMtxVec; overload; (*Round calling object elements [Index]..[Index+Len-1] in-place. An exception is raised if array borders are overrun/underrun. *) function Round(Index,Len: integer): TMtxVec; overload; (*Round all Src object elements. Store the results in calling object elements. Size and property of calling object are adjusted automatically. *) function Round(const Src: TMtxVec): TMtxVec; overload; (*Rounds the calling object elements to 4 byte integers. Stores the result in the Dst array. The size of the Dst array is set automatically. If the complex property is True then the length of the array will be equal to Self.Length*2. *) function Round(var Dst: TIntegerArray): TMtxVec; overload; (*Round Src object elements [SrcIndex]..[SrcIndex+Len-1]. Store the results to calling object elements [Index]..[Index+Len-1]. Size and property of the calling object must be set explicitly. An exception is raised if array borders are overrun/underrun. *) function Round(const Src: TMtxVec; SrcIndex,Index,Len: integer): TMtxVec; overload; (*Initialize elements to Value. Set all calling object elements to Value. If the calling object is complex then the real part is set to Value and the imaginary is set to zero. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TVec a; MtxVec.CreateIt(out a); try { a.Size(false, 4); a.SetVal(1); } finally { MtxVec.FreeIt(ref a); } } } *) function SetVal(const Value: double): TMtxVec; overload; (*Set all calling object elements [Index]..[Index+Len-1] to real Value. If the calling object is complex then the real part is set to Value and the imaginary is set to zero. An exception is raised if array borders are overrun/underrun. *) function SetVal(const Value: double; Index, Len: integer): TMtxVec; overload; (*Set all calling object complex elements to complex Value.*) function SetVal(const Value: TCplx): TMtxVec; overload; (*Set calling object complex elements [Index]..[Index+Len-1] to complex Value. property of the calling object are set to true even before the call it was false. An exception is raised if calling object array borders are overrun/underrun. *) function SetVal(const Value: TCplx; Index: integer; Len: integer): TMtxVec; overload; (*Initializes object elements to zero. *) function SetZero: TMtxVec; overload; (*Initializes calling object elements [Index]..[Index+Len-1] to zero. An exception is raised if array borders are overrun. *) function SetZero(Index, Len: integer): TMtxVec; overload; (*Changes elements sign. Changes all calling object elements sign (v -> -v) in-place. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TVec a; MtxVec.CreateIt(out a); try { a.SetIt(false, new double[] {-1,2,-3,4); a.Sign(); // a = 1,-2, 3, -4 } finally { MtxVec.FreeIt(ref a); } } } *) function Sign: TMtxVec; overload; (*Change calling object elements [Index]..[Index+Len-1] sign in-place. An exception is raised if array borders are overrun or underrun. *) function Sign(Index,Len: integer): TMtxVec; overload; (*Change all X object elements sign. Store the results in calling object. Size and properties of calling object are adjusted automatically. *) function Sign(const X: TMtxVec): TMtxVec; overload; (*Change X object elements [XIndex]..[XIndex+Len-1] sign. Store the results in callingobject elements [Index]..[Index+Len-1]. An exception is raised if array borders are overrun or underrun. *) function Sign(const X: TMtxVec; XIndex,Index,Len: integer): TMtxVec; overload; (* Computes signum function of calling object elements. Signum(X) is 1 for X > 0 , equal to zero for X = 0 and -1 for X < 0. *) function Sgn: TMtxVec; overload; (* Computes signum function of calling object elements [Index..Index+Len-1]. Signum(X) is 1 for X > 0 , equal to zero for X = 0 and -1 for X < 0. *) function Sgn(Index, Len: integer): TMtxVec; overload; (* Computes signum function from Src elements and stores the result in the calling object. Size and properties of calling object are adjusted automatically. Signum(X) is 1 for X > 0 , equal to zero for X = 0 and -1 for X < 0. *) function Sgn(const Src: TMtxVec): TMtxVec; overload; (* Computes signum function from Src elements [SrcIndex..SrcIndex+Len-1] and stores the result in the calling object [Index..Index+Len-1]. Size and properties of calling object are adjusted automatically. Signum(X) is 1 for X > 0 , equal to zero for X = 0 and -1 for X < 0. *) function Sgn(const Src: TMtxVec; SrcIndex,Index,Len: integer): TMtxVec; overload; (*Signum. Calculates the signum of all Src object elements and multiplies it with the calling object elements accordingly. Signum(X) is 1 for X > 0 , equal to zero for X = 0 and -1 for X < 0. The length of Src and of the calling object must match or an exception will be raised. Size and property of calling object are adjusted automatically. *) function SgnMul(const Src: TMtxVec): TMtxVec; overload; (*Size the object. Assignes the size of the Src object to the calling object. If the calling object is a TVec object then the Src can be of any type, otherwise TMtx can only obtain size from a TMtx object and TSparseMtx can only obtain size from a TSparseMtx object. If the calling object and Src are of different types, the complex property can be different, if both objects have a matching property. In this case only the Complex property of the calling object will changed, while all other properties describing the size of the object (rows, cols, length, nonZeros) will be preserved. This is different from simply setting the Complex property. Changing the Complex property directly would also change the Length, Cols and NonZeros properties. *) function Size(const Src: TMtxVecBase): TMtxVec ; overload; (*Allows the complex property of the calling object to become of AComplex value instead of Src.Complex value. It is also possible to pass the calling object as the Src with a different AComplex value. The value of the complex property can be changed without knowing the actual type of the object. *) function Size(const Src: TMtxVecBase; AComplex: boolean): TMtxVec ; overload; virtual; (*Allows the floatPrecision and complex properties of the calling object to become of aFloatPrecision value instead of Src.FloatPrecision and Src.Complex value. It is also possible to pass the calling object as the Src with a different aFloatPrecision value. The value of the FloatPrecision property can be changed without knowing the actual type of the object (matrix of vector). *) function Size(const Src: TMtxVecBase; const aFloatPrecision: TMtxFloatPrecision): TMtxVec; overload; virtual; (*Sizes the array. Sizes the Dst array so that it can hold all the values stored in the calling object. If the property is false an exception will be raised. *) procedure SizeToArray(var Dst: TCplxArray); overload; (*Sizes the array. Sizes the Dst array so that it can hold all the values stored in the calling object. If the property is false an exception will be raised. *) procedure SizeToArray(var Dst: TSCplxArray); overload; (*Compares two objects. True, if they are equal. Compares two objects and returns True, if they are equal. The IsEqual uses cmpAbsolute comparison method with comparison tolerance of 10*EPS by default. The method compares only and properties and coresponding values. To compare matrices or sparse matrices, use the method. *) function IsEqual(const Vec: TMtxVec): boolean; overload; (*Compares Vec elements [VecIndex]..[VecIndex+Len-1] with calling object elements [Index]..[Index+Len-1].*) function IsEqual(const Vec: TMtxVec; VecIndex, Index, Len: integer): boolean; overload; (*Compares Vec elements with coresponding calling object elements. Method uses comparison algorithm specified by property. *) function IsEqual(const Vec: TMtxVec; const Precision: double; const Compare: TCompare = cmpAbsolute): boolean; overload; (*Compares Vec elements [VecIndex]..[VecIndex+Len-1] with calling object elements [Index]..[Index+Len-1]. Algorithm uses the type and specified . *) function IsEqual(const Vec: TMtxVec; VecIndex, Index, Len: integer; const Precision: double; const Compare: TCompare = cmpAbsolute): boolean; overload; (*Compares complex Value with all calling object elements.*) function IsEqual(const Value: TCplx): boolean; overload; (*Compares real Value with all calling object elements.*) function IsEqual(const Value: double): boolean; overload; (*Compares real Value with all calling object elements. Algorithm uses the Compare method and specified Tolerance. *) function IsEqual(const Value: double; const Tolerance: double; const Compare: TCompare): boolean; overload; (*Compares complex Value with all calling object elements. Algorithm uses the Compare method and specified Tolerance. *) function IsEqual(const Value: TCplx; const Tolerance: double; const Compare: TCompare): boolean; overload; (*Standard deviation. Calculate the standard deviation of all calling object elements. The result is a real value. An exception is raised if calling vector property is true. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TVec a; MtxVec.CreateIt(out a); try { a.SetIt(false, new double[] {-1,2,-3,4); double amean = a.Mean(); double c = a.StdDev(amean); // alternative ... c = a.StdDev(); } finally { MtxVec.FreeIt(ref a); } } } *) function StdDev: double; overload; (*Returns the standard deviation of calling object elements [Index]..[Index+Len-1]. An exception is raised if calling object property is true or if array borders are overrun/underrun. *) function StdDev(Index,Len: integer): double; overload; (*Returns the standard deviation of all calling object complex elements. The average of all calling object elements must be passed as a AMean parameter. An exception is raised if calling object property is false. *) function StdDev(const AMean: TCplx): TCplx; overload; (*Returns the standard deviation of calling object complex elements [Index]..[Index+Len-1]. The average of all calling object elements must be passed as a AMean parameter. An exception is raised if calling object property is false or if array borders are overrun/underrun. *) function StdDev(const AMean: TCplx; Index, Len: integer): TCplx; overload; (*Returns the standard deviation of all calling object elements. The average of all calling object elements must be passed as a AMean parameter. An exception is raised if calling object property is true. *) function StdDev(const AMean: double): double; overload; (*Returns the standard deviation of calling object elements [Index]..[Index+Len-1]. The average of the coresponding elements must be passed as a parameter. An exception is raised if calling object property is true or if array borders are overrun/underrun. *) function StdDev(const AMean: double; Index, Len: integer): double; overload; (*Returns the standard deviation of all calling object elements. The average of all calling object elements must be passed as a AMean parameter. An exception is raised if calling object property is true. *) procedure MeanAndStdDev(var aMean, aStdDev: double); overload; (*Returns the standard deviation of calling object elements [Index]..[Index+Len-1]. The average of the coresponding elements must be passed as a parameter. An exception is raised if calling object property is true or if array borders are overrun/underrun. *) procedure MeanAndStdDev(var aMean, aStdDev: double; Index, Len: integer); overload; (*Sine and cosine. Calculates the sine and cosine for all calling object elements and stores the sines to SinX and cosines to CosX. Size and property of SinX and CosX are adjusted automatically. Note Use this method if you require both sine and cosine. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TVec a,s,v; MtxVec.CreateIt(out a, out s, out c); try { a.SetIt(false, new double[] {0,Math387.PiDiv2,Math387.PI); a.SinCos(s,c); // s=[0,1,0], c =[1,0,-1] } finally { MtxVec.FreeIt(ref a, ref s, ref c); } } } *) procedure SinCos(const SinX, CosX: TMtxVec); overload; (*Calculates the sine and cosine for calling object elements [Index]..[Index+Len-1]. stores the sines to SinX elemets [SinXIndex]..[SinXIndex+Len-1] and cosines to CosX elements [CosXIndex]..[CosXIndex+Len-1] elements. Size and property of SinX and CosX objects are not set automatically. An exception is raised if ConditionCheck and array borders are overrun/underun. *) procedure SinCos(const SinX, CosX: TMtxVec; SinXIndex, CosXIndex, Index, Len: integer); overload; (*Hyperbolic sine and cosine. Calculates the hyperbolic sine and hyperbolic cosine for all calling object elements and stores the sines to SinhX and cosines to CoshX. Size and property of SinhX and CoshX are adjusted automatically. Note Use this method if you require hyperbolic sine and hyperbolic cosine. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TVec a,s,v; MtxVec.CreateIt(out a, out s, out c); try { a.SetIt(false, new double[] {0,Math387.PiDiv2,Math387.PI); a.SinhCosh(s,c); } finally { MtxVec.FreeIt(ref a, ref s, ref c); } } } *) procedure SinhCosh(const SinhX, CoshX: TMtxVec); overload; (*Calculates the hyperbolic sine and hyperbolic cosine for calling object elements [Index]..[Index+Len-1]. Stores the sines to SinhX elemets [SinhIndex]..[SinhIndex+Len-1] and cosines to CoshX elements [CoshIndex]..[CoshIndex+Len-1] elements. Size and property of SinhX and CoshX objects are not set automatically. An exception is raised if ConditionCheck and array borders are overrun/underun. *) procedure SinhCosh(const SinhX, CoshX: TMtxVec; SinhIndex, CoshIndex, Index, Len: integer); overload; (*Sums vector values. the sum of all calling object elements. An exception is raised if calling object property is true. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TVec a; MtxVec.CreateIt(out a); try { a.SetIt(false, new double[] {1,3,-2}); doouble s = a.Sum(); // s = 2 } finally { MtxVec.FreeIt(ref a); } } } *) function Sum: double; overload; (*Returns the sum of calling object elements [Index]..[Index+Len-1]. An exception is raised if calling object property is True or array borders are overrun/underrun. *) function Sum(Index,Len: integer): double; overload; (*Calculates the sum of calling object elements [Index]..[Index+Len-1]. Stores the result in real ASum variable. An exception is raised if calling object property is True or array borders are overrun/underrun. *) procedure Sum(out ASum: double; Index, Len: integer); overload; (*Calculates the sum of all calling object complex elements. Stores the result in complex ASum variable. An exception is raised if calling object property is False. *) procedure Sum(out ASum: TCplx); overload; (*Calculates the sum of calling object complex elements [Index]..[Index+Len-1]. Stores the result in complex ASum variable. An exception is raised if calling object property is False or array borders are overrun/underrun. *) procedure Sum(out ASum: TCplx; Index, Len: integer); overload; (*Sum (complex value). the complex sum of all calling object complex elements. An exception is raised if calling object property is False. *) function Sumc: TCplx; overload; (*Returns the complex sum of calling object complex elements [Index]..[Index+Len-1]. An exception is raised if calling object property is False or array borders are overrun/underrun. *) function Sumc(Index,Len: integer): TCplx; overload; (*Threshold bottom operation. Perform threshold operation on all calling object values. The Value parameter is a lower bound for threshold operation. All values smaller than Value will be replaced with Value. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TVec a; MtxVec.CreateIt(out a); try { a.SetIt(false, new double[] {2, 0.1, 3, 4}); a.ThreshBottom(0.2); // a = [2,0.2,3,4] } finally { MtxVec.FreeIt(ref a); } } } *) function ThreshBottom(const Value: double): TMtxVec; overload; (*Perform the threshold operation on calling object values [Index]..[Index+Len-1]. An exception is raised if array borders are overrun/underrun. *) function ThreshBottom(const Value: double; Index, Len: integer): TMtxVec; overload; (*Perform threshold operation on all Src object values. Store the results in calling object. Size and properties of the calling object are adjusted automatically. *) function ThreshBottom(const Src: TMtxVec; const Value: double): TMtxVec; overload; (*Perform a threshold operation on Vec elements [VecIndex]..[VecIndex+Len-1]. Store the results in the calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if ConditionCheck is true and array borders are overrun/underrun. *) function ThreshBottom(const Vec: TMtxVec; const Value: double; VecIndex, Index, Len: integer): TMtxVec; overload; (*Threshold top operation. Perform threshold operation on all calling object values. The Value parameter is an upper bound for threshold operation. All values bigger than Value will be replaced with Value. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TVec a; MtxVec.CreateIt(out a); try { a.SetIt(false, new double[] {2, 0.1, 3, 4}); a.ThreshTop(0.2); // a = [0.2, 0.1, 0.2, 0.2] } finally { MtxVec.FreeIt(ref a); } } } *) function ThreshTop(const Value: double): TMtxVec; overload; (*Perfrom the threshold operation on calling object values [Index]..[Index+Len-1]. An exception is raised if array borders are overrun/underrun. *) function ThreshTop(const Value: double; Index, Len: integer): TMtxVec; overload; (*Perform threshold operation on all Src object values. Store the results in calling object. Size and properties of the calling object are adjusted automatically. *) function ThreshTop(const Src: TMtxVec; const Value: double): TMtxVec; overload; (*Perform a threshold operation Vec elements [VecIndex]..[VecIndex+Len-1]. Store the results in the calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if ConditionCheck is true and array borders are overrun/underrun. *) function ThreshTop(const Vec: TMtxVec; const Value: double; VecIndex, Index, Len: integer): TMtxVec; overload; (*Threshold top and bottom centered around zero. Perform threshold operation on all calling object values. The Value parameter is an upper bound for threshold operation. All values smaller than Value will be replaced with Value and all values bigger than -Value will be replaced with -Value. The comparison checks if abs(Values[i]) < Value. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TVec a; MtxVec.CreateIt(out a); try { a.SetIt(false, new double[] {2,-0.1,3,4}); a.ThreshAbsLT(0.2); // a = [2,-0.2,3,4] } finally { MtxVec.FreeIt(ref a); } } } *) function ThreshAbsLT(const Value: Double): TMtxVec; overload; (*Perfrom the threshold operation on calling object values [Index]..[Index+Len-1]. An exception is raised if array borders are overrun/underrun. *) function ThreshAbsLT(const Value: Double; Index, Len: integer): TMtxVec; overload; (*Perform threshold operation on all Src object values. Store the results in calling object. Size and properties of the calling object are adjusted automatically. *) function ThreshAbsLT(const Src: TMtxVec; const Value: Double): TMtxVec; overload; (*Perform a threshold operation Vec elements [VecIndex]..[VecIndex+Len-1]. Store the results in the calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if ConditionCheck is true and array borders are overrun/underrun. *) function ThreshAbsLT(const Vec: TMtxVec; const Value: Double; VecIndex, Index, Len: integer): TMtxVec; overload; (*Threshold top and bottom centered around zero. Perform threshold operation on all calling object values. The Value parameter is an upper bound for threshold operation. All values bigger than Value will be replaced with Value and all values smaller than -Value will be replaced with -Value. The comparison checks if abs(Values[i]) > Value. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TVec a; MtxVec.CreateIt(out a); try { a.SetIt(false, new double[] {2, -1, 3, 4}); a.ThreshAbsGT(0.2); // a = [0.2, -0.2, 0.2, 0.2] } finally { MtxVec.FreeIt(ref a); } } } *) function ThreshAbsGT(const Value: double): TMtxVec; overload; (*Perfrom the threshold operation on calling object values [Index]..[Index+Len-1]. An exception is raised if array borders are overrun/underrun. *) function ThreshAbsGT(const Value: double; Index, Len: integer): TMtxVec; overload; (*Perform threshold operation on all Src object values. Store the results in calling object. Size and properties of the calling object are adjusted automatically. *) function ThreshAbsGT(const Src: TMtxVec; const Value: double): TMtxVec; overload; (*Perform a threshold operation Vec elements [VecIndex]..[VecIndex+Len-1]. Store the results in the calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if ConditionCheck is true and array borders are overrun/underrun. *) function ThreshAbsGT(const Vec: TMtxVec; const Value: double; VecIndex, Index, Len: integer): TMtxVec; overload; (*Threshold less than operation. Perform operation on all calling object values. The LTValue parameter is a lower bound for threshold operation. All values less than LTLevel will be replaced with LTValue. For complex number comparation is applied with norm of complex value. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TVec a; MtxVec.CreateIt(out a); try { a.SetIt(false, new double[] {2, 0.1, 3, 4}); a.ThresholdLT(2.3,1.5); // a = [1.5,1.5,3,4] } finally { MtxVec.FreeIt(ref a); } } } *) function ThresholdLT(const LTLevel, LTValue: double): TMtxVec; overload; (*Perfrom "less than" threshold operation on the calling object values in range [Index]..[Index+Len-1]. An exception is raised if array borders are overrun/underrun. *) function ThresholdLT(const LTLevel, LTValue: double; Index, Len: integer): TMtxVec; overload; (*Perform "less than" threshold operation on all Vec object values. Store the results in calling object. Size and properties of the calling object are adjusted automatically. *) function ThresholdLT(const Vec: TMtxVec; const LTLevel, LTValue: double): TMtxVec; overload; (*Perform "less than" threshold operation on Vec elements from range [VecIndex]..[VecIndex+Len-1]. Store the results in the calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if ConditionCheck is true and array borders are overrun/underrun. An exception will be raised if Vec.Complex and Complex of the calling object are not equal. *) function ThresholdLT(const Vec: TMtxVec; const LTLevel, LTValue: double; VecIndex, Index, Len: integer): TMtxVec; overload; (*Perfrom "less than" threshold operation for complex numbers. If the calling object contains none Complex values, an exception will be raised. *) function ThresholdLT(const LTLevel: double; const LTValue: TCplx): TMtxVec; overload; (*Perfrom "less than" threshold operation for complex numbers on the calling object values in range [Index]..[Index+Len-1]. An exception is raised if array borders are overrun/underrun. If the calling object contains none Complex values, an exception will be raised. *) function ThresholdLT(const LTLevel: double; const LTValue: TCplx; Index, Len: integer): TMtxVec; overload; (*Perform "less than" threshold operation for complex numbers on all Vec object values. Store the results in calling object. Size and properties of the calling object are adjusted automatically. If Vec object contains none Complex values, an exception will be raised. *) function ThresholdLT(const Vec: TMtxVec; const LTLevel: double; const LTValue: TCplx): TMtxVec; overload; (*Perform "less than" threshold operation for complex numbers on Vec elements from range [VecIndex]..[VecIndex+Len-1]. Store the results in the calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if ConditionCheck is true and array borders are overrun/underrun. If Vec object or calling object contain none Complex values, an exception will be raised. *) function ThresholdLT(const Vec: TMtxVec; const LTLevel: double; const LTValue: TCplx; VecIndex, Index, Len: integer): TMtxVec; overload; (*Threshold greater than operation. Perform operation on all calling object values. The GTValue parameter is an upper bound for threshold operation. All values bigger than LTLevel will be replaced with GTValue. For complex number comparation is applied with norm of complex value. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TVec a; MtxVec.CreateIt(out a); try { a.SetIt(false, new double[] {2, 0.1, 3, 4}); a.ThresholdGT(2.3,3.4); // a = [2,0.1,3.4,3.4] } finally { MtxVec.FreeIt(ref a); } } } *) function ThresholdGT(const GTLevel, GTValue: double): TMtxVec; overload; (*Perfrom "greater than" threshold operation on the calling object values in range [Index]..[Index+Len-1]. An exception is raised if array borders are overrun/underrun. *) function ThresholdGT(const GTLevel, GTValue: double; Index, Len: integer): TMtxVec; overload; (*Perform "greater than" threshold operation on all Vec object values. Store the results in calling object. Size and properties of the calling object are adjusted automatically. *) function ThresholdGT(const Vec: TMtxVec; const GTLevel, GTValue: double): TMtxVec; overload; (*Perform "greater than" threshold operation on Vec elements from range [VecIndex]..[VecIndex+Len-1]. Store the results in the calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if ConditionCheck is true and array borders are overrun/underrun. An exception will be raised if Vec.Complex and Complex of the calling object are not equal. *) function ThresholdGT(const Vec: TMtxVec; const GTLevel, GTValue: double; VecIndex, Index, Len: integer): TMtxVec; overload; (*Perfrom "greater than" threshold operation for complex numbers. If the calling object contains none Complex values, an exception will be raised. *) function ThresholdGT(const GTLevel: double; const GTValue: TCplx): TMtxVec; overload; (*Perfrom "greater than" threshold operation for complex numbers on the calling object values in range [Index]..[Index+Len-1]. An exception is raised if array borders are overrun/underrun. If the calling object contains none Complex values, an exception will be raised. *) function ThresholdGT(const GTLevel: double; const GTValue: TCplx; Index, Len: integer): TMtxVec; overload; (*Perform "greater than" threshold operation for complex numbers on all Vec object values. Store the results in calling object. Size and properties of the calling object are adjusted automatically. If Vec object contains none Complex values, an exception will be raised. *) function ThresholdGT(const Vec: TMtxVec; const GTLevel: double; const GTValue: TCplx): TMtxVec; overload; (*Perform "greater than" threshold operation for complex numbers on Vec elements from range [VecIndex]..[VecIndex+Len-1]. Store the results in the calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if ConditionCheck is true and array borders are overrun/underrun. If Vec object or calling object contain none Complex values, an exception will be raised. *) function ThresholdGT(const Vec: TMtxVec; const GTLevel: double; const GTValue: TCplx; VecIndex, Index, Len: integer): TMtxVec; overload; (*Threshold greater than and less than operation. Perform operation on all calling object values. The LTValue parameter is an lower bound for threshold operation. The GTValue parameter is an upper bound for threshold operation. All values less than LTLevel will be replaced with LTValue. All values bigger than GTLevel will be replaced with GTValue. Operation is available only for not Complex values. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TVec a; MtxVec.CreateIt(out a); try { a.SetIt(false, new double[] {2, 0.1, 3, 4}); a.ThresholdGT_LT(2.3,3.4,1,0.5); // a = [2,0.5,3.4,3.4] } finally { MtxVec.FreeIt(ref a); } } } *) function ThresholdGT_LT (const GTLevel, GTValue, LTLevel, LTValue: double): TMtxVec; overload; (*Perfrom "greater than and less than" threshold operation on the calling object values in range [Index]..[Index+Len-1]. An exception is raised if array borders are overrun/underrun. An exception will be raised if the calling object contains complex numbers. *) function ThresholdGT_LT (const GTLevel, GTValue, LTLevel, LTValue: double; Index, Len: integer): TMtxVec; overload; (*Perform "greater than and less than" threshold operation on all Vec object values. Store the results in calling object. Size and properties of the calling object are adjusted automatically. An exception will be raised if Vec object contains complex numbers. *) function ThresholdGT_LT (const Vec: TMtxVec; const GTLevel, GTValue, LTLevel, LTValue: double): TMtxVec; overload; (*Perform "greater than and less than" threshold operation on Vec elements from range [VecIndex]..[VecIndex+Len-1]. Store the results in the calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if ConditionCheck is true and array borders are overrun/underrun. An exception will be raised if Vec object or the calling object contain complex numbers. *) function ThresholdGT_LT(const Vec: TMtxVec; const GTLevel, GTValue, LTLevel, LTValue: double; VecIndex, Index, Len: integer): TMtxVec; overload; (*Rounds a real number towards zero and returns the fractional part. Rounds all calling object elements towards zero to an integer and stores the result in the TruncDst object as floating point numbers. The fractional part is stored in the FracDst. *) procedure TruncAndFrac(const TruncDst: TMtxVec; const FracDst: TDenseMtxVec); overload; (*Truncate calling object elements [Index]..[Index+Len-1] and store the results to TruncDst object elements [TruncIdx]..[TruncIdx+Len-1]. The fractional parts are saved in FracDst elements [FracIdx]..[FracIdx+Len-1]. Size and property of calling object must be set explicitly to match those of Src object. An exception is raised if array borders are overrun/underrun. *) procedure TruncAndFrac(const TruncDst: TMtxVec; const FracDst: TDenseMtxVec; TruncIdx, FracIdx, Index, Len: integer); overload; (*Rounds a real number towards zero. Rounds all calling object elements towards zero to an integer and stores the result in the calling object again as floating point numbers. *) function Trunc: TMtxVec; overload; (*Truncate calling object elements [Index]..[Index+Len-1] in-place. An exception is raised if array borders are overrun/underrun. *) function Trunc(Index,Len: integer): TMtxVec; overload; (*Truncate all Src object elements. Store the results in calling object elements. Size and property of calling object are adjusted automatically. *) function Trunc(const Src: TMtxVec): TMtxVec; overload; (*Truncate all calling object elements. Store the result in the Dst integer array. Length of the array is automatically adjusted. If the calling object is Complex, the length of the Dst array is equal to 2*. *) function Trunc(var Dst: TIntegerArray): TMtxVec; overload; (*Truncate Src object elements [SrcIndex]..[SrcIndex+Len-1]. Store the results to calling object elemenents [Index]..[Index+Len-1]. Size and property of calling object must be set explicitly to match those of Src object. An exception is raised if array borders are overrun/underrun. *) function Trunc(const Src: TMtxVec; SrcIndex, Index,Len: integer): TMtxVec; overload; constructor Create; override; destructor Destroy; override; (*Writes object Values content to a stream. Writes the calling object Values content to the DstStream stream. No other values describing the data type or length are written to the DstStream. Number type is defined by the Precision parameter. Rounding defines the rounding for integer types. When saving double precision as single precision, all overflows are saved as INF (-INF). When saving to integer types all overflows are clipped. Attempt to save single precision as double precision will raise an exception. The paramateres must be the same as for the method. Use this method separately only, if you want user defined storage format. var b: TVec; AStream: TFileStream; begin CreateIt(b); b.SetIt(False,[0,0,1,3,2]); AStream := TFileStream.Create('C:\test.Vec',fmCreate); try b.WriteHeader(AStream); // Write info for b b.WriteValues(AStream); // Write values of b finally AStream.Free; end; FreeIt(b); end; *) procedure WriteValues(const Dst: TStream; Precision: TPrecision; Rounding: TRounding = rnTrunc; Endian: TEndianness = MtxSystemEndianness); overload; virtual; (*Writes the header information for the calling vector to a stream.*) procedure WriteValues(const Dst: TStream); overload; virtual; (*Writes the header information for the calling vector to a stream. Writes the header information for the calling object to a DstStream stream. The header information contains information about object (size, complex, type of values in Values array, ...) which all define the state of the object. Number type is defined by the Precision parameter. Rounding defines the rounding for integer types. When saving double precision as single precision, all overflows are saved as INF (-INF). When saving to integer types all overflows are clipped. Attempt to save single precision as double precision will raise an exception. The data format uses VersionControl to insure backward compatibilty for future versions of MtxVec. var b: TVec; AStream: TFileStream; begin CreateIt(b); b.SetIt(False,[0,0,1,3,2]); AStream := TFileStream.Create('C:\test.bin',fmCreate); try b.WriteHeader(AStream); // Write info for b b.WriteValues(AStream); // Write values of b finally AStream.Free; FreeIt(b); end; end; *) procedure WriteHeader(const Dst: TStream; Precision: TPrecision; Rounding: TRounding = rnTrunc; Endian: TEndianness = MtxSystemEndianness); overload; virtual; (*Writes the header information for the calling vector to a stream.*) procedure WriteHeader(const Dst: TStream); overload; virtual; (*Reads the header information from a stream to object. Reads the header information from a DstStream stream to calling object. The header information contains all necessary information defining the object. The function returns the precision in which the data was stored. This information is required for the method. var b: TVec; AStream: TFileStream; Precision: TPrecision; begin CreateIt(b); AStream := TFileStream.Create('C:\test.bin',fmOpenRead); try Precision := b.ReadHeader(AStream); // Read info for b b.ReadValues(AStream,Precision); // Read values of b finally AStream.Free; FreeIt(b); end; end; *) function ReadHeader(const Src: TStream; Endian: TEndianness = MtxSystemEndianness): TPrecision; overload; virtual; published (*Defines if object values are complex. If true, will treat it's elements as complex numbers. Two successive number in the values array be treated as real and imaginary part of the complex number. When property is false, object will treat it's elements as real numbers. You should always set the value of the Complex property before setting object size ( for vector or , for matrix). Setting Complex from true to false does not cause memory reallocation. It simply doubles the value of the Length property. Setting Complex from false to true halves the vector length or number of matrix columns, but retains all data. Complex property is initially false. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TVec a,b,c; MtxVec.CreateIt(out a, out b, out c); try { a.SetIt(true, new double[] {1,2,3,4}); b.SetIt(false,new double[] {8,9,6,7}); b.Complex = true; c.Mul(a,b); // = [(1+2i)*(8*9i), (3+4i)*(6+7i)] } finally { MtxVec.FreeIt(ref a,ref b,ref c); } } } *) property Complex: boolean read fComplex write setComplex stored false; (*First element in object Values array. first real element in object Values array. *) property First: double read GetFirst write SetFirst stored false; (*First element in object CValues array. first complex element in object CValues array. An exception is raised if calling object property is false. *) property Firstc: TCplx read GetFirstc write SetFirstc stored false; (*Last complex element in object CValues array. last complex element in object CValues array. *) property Lastc: TCplx read GetLastc write SetLastC stored false; (*Last element in object Values array. the last real element in object Values array. *) property Last: double read GetLast write SetLast stored false; end; (*Base class for TVec and TMtx objects.*) TDenseMtxVec = class(TMtxVec) strict private fFFTStorageFormat: TFFTStorageFormat; fFFTScrambledOrder: boolean; fFFTOddLength: boolean; public procedure Assign(Src: TPersistent); override; procedure Reset; override; constructor Create; override; (*The FFT storage format. The FFT storage format specifies how will the result of an operation be stored in the destination. This affects both 1D and 2D FFT's. *) property FFTStorageFormat: TFFTStorageFormat read fFFTStorageFormat write fFFTStorageFormat; (*Leave FFT scrambeled. The last stage (or first) of an FFT, is a sorting operation. This sorting will be left out, if this property will be set to True. Note This can improve performance for certain applications, if you used properly. *) property FFTScrambled: boolean read fFFTScrambledOrder write fFFTScrambledOrder; (*Defines if FFT transform length is odd. The property should be set to True, if the length of a forward real to complex FFT is odd and if the result of an inverser complex to real FFT should be odd. *) property FFTOddLength: boolean read fFFTOddLength write fFFTOddLength; (*Replaces all NAN values with Value. The function will replace all occurences of NAN. If the vector is complex, it will replace any real/imag parts, which are NAN. *) function ReplaceNAN(const Value: double): TMtxVec; overload; (*Replaces all NAN values with Value within calling object elements [Index]..[Index+Len-1]. The function will replace all occurences of NAN. If the vector is complex, it will replace any real/imag parts, which are NAN. An exception is raised, if array borders are overrun. *) function ReplaceNAN(const Value: double; Index, Len: integer): TMtxVec; overload; (*Adds Value to object elements. *) function Add(const Value: double): TMtxVec; overload; (*Adds complex Value to all calling object complex elements.*) function Add(const Value: TCplx): TMtxVec; overload; (*Adds Value to calling object elements [Index]..[Index+Len-1]. An exception is raised if array borders are overrun. *) function Add(const Value: double; Index, Len: integer): TMtxVec; overload; (*Adds complex Value to calling object complex elements [Index]..[Index+Len-1]. An exception is raised if array borders are overrun. *) function Add(const Value: TCplx; Index, Len: integer): TMtxVec; overload; (*Adds Value to the each element of the Vec object. Stores the result in the calling object. Size and properties of the calling object are set automatically. *) function Add(const Vec: TMtxVec; const Value: double): TMtxVec; overload; (*Adds complex Value to each element of the Vec object. Store the result to the calling object. Size property of the calling object is set automatically. property of the calling object is set to True. *) function Add(const Vec: TMtxVec; const Value: TCplx): TMtxVec; overload; (*Adds Value to each element of Vec object in range [VecIndex]..[VecIndex+Len-1]. Stores result to elements [Index]..[Index+Len-1] of the calling object. Size of the calling object is not changed. An exception is raised if array borders are overrun. property of the calling object is set implicitly. *) function Add(const Vec: TMtxVec; const Value: double; VecIndex, Index, Len: integer): TMtxVec; overload; (*Adds complex Value to each elements of the Vec object in range [VecIndex]..[VecIndex+Len-1]. Stores the result to elements [Index]..[Index+Len-1] of the calling object. Size of the calling object is not changed. An exception is raised if array borders are overrun. property of the calling object is set to True. *) function Add(const Vec: TMtxVec; const Value: TCplx; VecIndex, Index, Len: integer): TMtxVec; overload; (*Array addition. Add each of Vec elements to corresponding elements in the calling object. *) function Add(const Vec: TMtxVec): TMtxVec; overload; (*Add each of Vec elements to corresponding elements in the calling object. In addition, the following formula is being used: result = result+ aScale*Vec . The results are stored in the calling object. Size and properties of the calling object are set implicitly to match the Vec object. *) function AddScaled(const Vec: TMtxVec; const aScale: double): TMtxVec; overload; (*Add each of Vec elements to corresponding elements in the calling object. In addition, the following formula is being used: result = result+ Cplx(RScale,IScale)*Vec . When default values for parameters are being used the "normal" addition is being performed. The results are stored in the calling object. Size and properties of the calling object are set implicitly to match the Vec object. *) function AddScaled(const Vec: TMtxVec; const RScale: double; const IScale: double): TMtxVec; overload; (*Add each of Vec elements to corresponding elements in the calling object. In addition, the following formula is being used: result = result+ aScale*Vec . The results are stored in the calling object. Size and properties of the calling object are set implicitly to match the Vec object. *) function AddScaled(const Vec: TMtxVec; const aScale: TCplx): TMtxVec; overload; (*Add each of Vec2 elements to corresponding elements in Vec1. The results are stored in the calling object. Size and properties of the calling object are set implicitly to match Vec1 and Vec2 vectors. *) function Add(const Vec1, Vec2: TMtxVec): TMtxVec; overload; (*Add Vec elements [VecIndex]..[VecIndex+Len-1] to calling object elements [Index]..[Index+Len-1]. An exception is raised if ConditionCheck is true and array borders are overrun. *) function Add(const Vec: TMtxVec; VecIndex, Index, Len: integer): TMtxVec; overload; (*Adds Vec elements [VecIndex]..[VecIndex+Len-1] to calling object elements [Index]..[Index+Len-1]. The following formula is being used: result = result + aScale*Vec . An exception is raised if ConditionCheck is true and array borders are overrun. *) function AddScaled(const Vec: TMtxVec; const aScale: double; VecIndex, Index, Len: integer): TMtxVec; overload; (*Adds Vec elements [VecIndex]..[VecIndex+Len-1] to calling object elements [Index]..[Index+Len-1]. In addition, the following formula is being used: result = result+ aScale*Vec . An exception is raised if ConditionCheck is true and array borders are overrun. *) function AddScaled(const Vec: TMtxVec; const aScale: TCplx; VecIndex, Index, Len: integer): TMtxVec; overload; (* Compute X + Y*yScale *) function AddScaled(const X, Y: TMtxVec; const yScale: Double): TMtxVec; overload; (* Compute X + Y*yScale with complex arguments.*) function AddScaled(const X, Y: TMtxVec; const yScale: TCplx): TMtxVec; overload; (* Compute X + Y*yScale on sub arrays. *) function AddScaled(const X: TMtxVec; xIndex: integer; const Y: TMtxVec; yIndex: integer; const yScale: Double; Index, Len: integer): TMtxVec; overload; (* Compute X + Y*yScale on sub arrays with complex arguments. *) function AddScaled(const X: TMtxVec; xIndex: integer; const Y: TMtxVec; yIndex: integer; const yScale: TCplx; Index, Len: integer): TMtxVec; overload; (* Compute sqr(X + Y*yScale) By making use of yScale, it is also possible to compute the following (at the same or higher speed): (X - Y)^2 = X^2 - 2XY +Y^2 *) function AddScaledSqr(const X, Y: TMtxVec; const yScale: Double): TMtxVec; overload; (* Compute sqr(X + Y*yScale) *) function AddScaledSqr(const X, Y: TMtxVec; const yScale: TCplx): TMtxVec; overload; (* Compute sqr(X + Y*yScale) on sub arrays *) function AddScaledSqr(const X: TMtxVec; xIndex: integer; const Y: TMtxVec; yIndex: integer; const yScale: Double; Index, Len: integer): TMtxVec; overload; (* Compute sqr(X + Y*yScale) on sub arrays *) function AddScaledSqr(const X: TMtxVec; xIndex: integer; const Y: TMtxVec; yIndex: integer; const yScale: TCplx; Index, Len: integer): TMtxVec; overload; (* Compute sqr(X) + sqr(Y)*yScale By making use of yScale, it is also possible to compute the following (at the same or higher speed): X^2 - Y^2 *) function SqrAddScaled(const X, Y: TMtxVec; const yScale: Double): TMtxVec; overload; (* Compute sqr(X) + sqr(Y)*yScale *) function SqrAddScaled(const X, Y: TMtxVec; const yScale: TCplx): TMtxVec; overload; (* Compute sqr(X) + sqr(Y)*yScale on sub arrays *) function SqrAddScaled(const X: TMtxVec; xIndex: integer; const Y: TMtxVec; yIndex: integer; const yScale: Double; Index, Len: integer): TMtxVec; overload; (* Compute sqr(X) + sqr(Y)*yScale on sub arrays *) function SqrAddScaled(const X: TMtxVec; xIndex: integer; const Y: TMtxVec; yIndex: integer; const yScale: TCplx; Index, Len: integer): TMtxVec; overload; (* Compute X + Y + Z *) function Add(const X, Y, Z: TMtxVec): TMtxVec; overload; (* Compute X + Y + Z on sub arrays *) function Add(const X: TMtxVec; xIndex: integer; const Y: TMtxVec; yIndex: integer; const Z: TMtxVec; zIndex: integer; Index, Len: integer): TMtxVec; overload; (* Compute X + Y + Z*zScale *) function AddScaled(const X, Y, Z: TMtxVec; const zScale: Double): TMtxVec; overload; (* Compute X + Y + Z*zScale *) function AddScaled(const X, Y, Z: TMtxVec; const zScale: TCplx): TMtxVec; overload; (* Compute X + Y + Z*zScale on sub arrays *) function AddScaled(const X: TMtxVec; xIndex: integer; const Y: TMtxVec; yIndex: integer; const Z: TMtxVec; zIndex: integer; const zScale: Double; Index, Len: integer): TMtxVec; overload; (* Compute X + Y + Z*zScale on sub arrays *) function AddScaled(const X: TMtxVec; xIndex: integer; const Y: TMtxVec; yIndex: integer; const Z: TMtxVec; zIndex: integer; const zScale: TCplx; Index, Len: integer): TMtxVec; overload; (* Compute X + Y*yScale + Z*zScale *) function AddScaled(const X, Y: TMtxVec; const yScale: Double; const Z: TMtxVec; const zScale: Double): TMtxVec; overload; (* Compute X + Y*yScale + Z*zScale *) function AddScaled(const X, Y: TMtxVec; const yScale: TCplx; const Z: TMtxVec; const zScale: TCplx): TMtxVec; overload; (* Compute X + Y*yScale + Z*zScale on sub arrays *) function AddScaled(const X: TMtxVec; xIndex: integer; const Y: TMtxVec; yIndex: integer; const yScale: Double; const Z: TMtxVec; zIndex: integer; const zScale: Double; Index, Len: integer): TMtxVec; overload; (* Compute X + Y*yScale + Z*zScale on sub arrays *) function AddScaled(const X: TMtxVec; xIndex: integer; const Y: TMtxVec; yIndex: integer; const yScale: TCplx; const Z: TMtxVec; zIndex: integer; const zScale: TCplx; Index, Len: integer): TMtxVec; overload; (* Compute X + Y + zScalar *) function Add(const X, Y: TMtxVec; const Z: Double): TMtxVec; overload; (* Compute X + Y + zScalar *) function Add(const X, Y: TMtxVec; const Z: TCplx): TMtxVec; overload; (* Compute X + Y + zScalar on sub arrays *) function Add(const X: TMtxVec; xIndex: integer; const Y: TMtxVec; yIndex: integer; const Z: Double; Index, Len: integer): TMtxVec; overload; (* Compute X + Y + zScalar on sub arrays *) function Add(const X: TMtxVec; xIndex: integer; const Y: TMtxVec; yIndex: integer; const Z: TCplx; Index, Len: integer): TMtxVec; overload; (* Compute X + Y*yScale + zScalar *) function AddScaledC(const X, Y: TMtxVec; const yScale: Double; const Z: Double): TMtxVec; overload; (* Compute X + Y*yScale + zScalar *) function AddScaledC(const X, Y: TMtxVec; const yScale: TCplx; const Z: TCplx): TMtxVec; overload; (* Compute X + Y*yScale + zScalar on sub arrays *) function AddScaledC(const X: TMtxVec; xIndex: integer; const Y: TMtxVec; yIndex: integer; const yScale: Double; const Z: Double; Index, Len: integer): TMtxVec; overload; (* Compute X + Y*yScale + zScalar on sub arrays *) function AddScaledC(const X: TMtxVec; xIndex: integer; const Y: TMtxVec; yIndex: integer; const yScale: TCplx; const Z: TCplx; Index, Len: integer): TMtxVec; overload; (* Compute X - Y - Z *) function Sub(const X, Y, Z: TMtxVec): TMtxVec; overload; (* Compute X - Y - Z on sub array*) function Sub(const X: TMtxVec; xIndex: integer; const Y: TMtxVec; yIndex: integer;const Z: TMtxVec; zIndex: integer; Index, Len: integer): TMtxVec; overload; (* Compute X - Y*yScale - Z*zScale *) function SubScaled(const X, Y: TMtxVec; const yScale: Double; const Z: TMtxVec; const zScale: Double): TMtxVec; overload; (* Compute X - Y*yScale - Z*zScale *) function SubScaled(const X, Y: TMtxVec; const yScale: TCplx; const Z: TMtxVec; const zScale: TCplx): TMtxVec; overload; (* Compute X - Y*yScale - Z*zScale on sub array*) function SubScaled(const X: TMtxVec; xIndex: integer; const Y: TMtxVec; yIndex: integer; const yScale: Double; const Z: TMtxVec; zIndex: integer; const zScale: Double; Index, Len: integer): TMtxVec; overload; (* Compute X - Y*yScale - Z*zScale on sub array*) function SubScaled(const X: TMtxVec; xIndex: integer; const Y: TMtxVec; yIndex: integer; const yScale: TCplx; const Z: TMtxVec; zIndex: integer; const zScale: TCplx; Index, Len: integer): TMtxVec; overload; (* Compute X - Y - Z*zScale *) function SubScaled(const X, Y, Z: TMtxVec; const zScale: Double): TMtxVec; overload; (* Compute X - Y - Z*zScale *) function SubScaled(const X, Y, Z: TMtxVec; const zScale: TCplx): TMtxVec; overload; (* Compute X - Y - Z*zScale on sub array*) function SubScaled(const X: TMtxVec; xIndex: integer; const Y: TMtxVec; yIndex: integer; const Z: TMtxVec; zIndex: integer; const zScale: Double; Index, Len: integer): TMtxVec; overload; (* Compute X - Y - Z*zScale on sub array*) function SubScaled(const X: TMtxVec; xIndex: integer; const Y: TMtxVec; yIndex: integer; const Z: TMtxVec; zIndex: integer; const zScale: TCplx; Index, Len: integer): TMtxVec; overload; (* Compute X - Y - zScalar *) function Sub(const X, Y: TMtxVec; const Z: Double): TMtxVec; overload; (* Compute X - Y - zScalar *) function Sub(const X, Y: TMtxVec; const Z: TCplx): TMtxVec; overload; (* Compute X - Y - zScalar on sub array*) function Sub(const X: TMtxVec; xIndex: integer; const Y: TMtxVec; yIndex: integer; const Z: Double; Index, Len: integer): TMtxVec; overload; (* Compute X - Y - zScalar on sub array*) function Sub(const X: TMtxVec; xIndex: integer; const Y: TMtxVec; yIndex: integer; const Z: TCplx; Index, Len: integer): TMtxVec; overload; (* Compute X - Y*yScale - zScalar *) function SubScaledC(const X, Y: TMtxVec; const yScale: Double; const Z: Double): TMtxVec; overload; (* Compute X - Y*yScale - zScalar *) function SubScaledC(const X, Y: TMtxVec; const yScale: TCplx; const Z: TCplx): TMtxVec; overload; (* Compute X - Y*yScale - zScalar on sub array*) function SubScaledC(const X: TMtxVec; xIndex: integer; const Y: TMtxVec; yIndex: integer; const yScale: Double; const Z: Double; Index, Len: integer): TMtxVec; overload; (* Compute X - Y*yScale - zScalar on sub array*) function SubScaledC(const X: TMtxVec; xIndex: integer; const Y: TMtxVec; yIndex: integer; const yScale: TCplx; const Z: TCplx; Index, Len: integer): TMtxVec; overload; (* Compute X * Y / Z *) function MulAndDiv(const X, Y, Z: TMtxVec): TMtxVec; overload; (* Compute X * Y / Z on sub array*) function MulAndDiv(const X: TMtxVec; xIndex: integer; const Y: TMtxVec; yIndex: integer; const Z: TMtxVec; zIndex: integer; Index, Len: integer): TMtxVec; overload; (* Compute (X + Y)*Z *) function AddAndMul(const X, Y, Z: TMtxVec): TMtxVec; overload; (* Compute (X + Y)*Z on sub array*) function AddAndMul(const X: TMtxVec; xIndex: Integer; const Y: TMtxVec; yIndex: Integer; const Z: TMtxVec; zIndex: Integer; Index, Len: Integer): TMtxVec; overload; (* Compute (X + Y)*Z*zScale *) function AddAndMul(const X, Y, Z: TMtxVec; const zScale: double): TMtxVec; overload; (* Compute (X + Y)*Z*zScale *) function AddAndMul(const X, Y, Z: TMtxVec; const zScale: TCplx): TMtxVec; overload; (* Compute (X + Y)*Z*zScale on sub array*) function AddAndMul(const X: TMtxVec; xIndex: Integer; const Y: TMtxVec; yIndex: Integer; const Z: TMtxVec; zIndex: Integer; const zScale: double; Index, Len: Integer): TMtxVec; overload; (* Compute (X + Y)*Z*zScale on sub array*) function AddAndMul(const X: TMtxVec; xIndex: Integer; const Y: TMtxVec; yIndex: Integer; const Z: TMtxVec; zIndex: Integer; const zScale: TCplx; Index, Len: Integer): TMtxVec; overload; (* Compute (X + Y*yScale)*Z*zScale *) function AddAndMul(const X, Y: TMtxVec; const yScale: double; const Z: TMtxVec; const zScale: double): TMtxVec; overload; (* Compute (X + Y*yScale)*Z*zScale *) function AddAndMul(const X, Y: TMtxVec;const yScale: TCplx; const Z: TMtxVec;const zScale: TCplx): TMtxVec; overload; (* Compute (X + Y*yScale)*Z*zScale on sub array*) function AddAndMul(const X: TMtxVec; xIndex: Integer; const Y: TMtxVec; yIndex: Integer; const yScale: double; const Z: TMtxVec; zIndex: Integer; const zScale: double; Index, Len: Integer): TMtxVec; overload; (* Compute (X + Y*yScale)*Z*zScale on sub array*) function AddAndMul(const X: TMtxVec; xIndex: Integer; const Y: TMtxVec; yIndex: Integer; const yScale: TCplx; const Z: TMtxVec; zIndex: Integer; const zScale: TCplx; Index, Len: Integer): TMtxVec; overload; (* Compute (X + Y)*zScalar *) function AddAndMul(const X, Y: TMtxVec; const Z: Double): TMtxVec; overload; (* Compute (X + Y)*zScalar *) function AddAndMul(const X, Y: TMtxVec; const Z: TCplx): TMtxVec; overload; (* Compute (X + Y)*zScalar on sub array*) function AddAndMul(const X: TMtxVec; xIndex: Integer; const Y: TMtxVec; yIndex: Integer; const Z: Double; Index, Len: Integer): TMtxVec; overload; (* Compute (X + Y)*zScalar on sub array*) function AddAndMul(const X: TMtxVec; xIndex: Integer; const Y: TMtxVec; yIndex: Integer; const Z: TCplx; Index, Len: Integer): TMtxVec; overload; (* Compute (X + Y*yScale)*zScalar *) function AddAndMul(const X, Y: TMtxVec; const yScale, Z: Double): TMtxVec; overload; (* Compute (X + Y*yScale)*zScalar *) function AddAndMul(const X, Y: TMtxVec; const yScale, Z: TCplx): TMtxVec; overload; (* Compute (X + Y*yScale)*zScalar on sub array*) function AddAndMul(const X: TMtxVec; xIndex: Integer; const Y: TMtxVec; yIndex: Integer; const yScale, Z: Double; Index, Len: Integer): TMtxVec; overload; (* Compute (X + Y*yScale)*zScalar on sub array*) function AddAndMul(const X: TMtxVec; xIndex: Integer; const Y: TMtxVec; yIndex: Integer; const yScale, Z: TCplx; Index, Len: Integer): TMtxVec; overload; (* Compute (X + yScalar)*Z*zScale *) function AddAndMul(const X: TMtxVec; const Y: Double; const Z: TMtxVec; const zScale: Double): TMtxVec; overload; (* Compute (X + yScalar)*Z*zScale *) function AddAndMul(const X: TMtxVec; const Y: TCplx; const Z: TMtxVec; const zScale: TCplx): TMtxVec; overload; (* Compute (X + yScalar)*Z*zScale on sub-array*) function AddAndMul(const X: TMtxVec; xIndex: integer; const Y: Double; const Z: TMtxVec; zIndex: integer; const zScale: Double; Index, Len: integer): TMtxVec; overload; (* Compute (X + yScalar)*Z*zScale on sub-array*) function AddAndMul(const X: TMtxVec; xIndex: integer; const Y: TCplx; const Z: TMtxVec; zIndex: integer; const zScale: TCplx; Index, Len: integer): TMtxVec; overload; (* Compute (X*xScale + yScalar)*Z *) function AddAndMul(const X: TMtxVec; const xScale, Y: Double; const Z: TMtxVec): TMtxVec; overload; (* Compute (X*xScale + yScalar)*Z *) function AddAndMul(const X: TMtxVec; const xScale, Y: TCplx; const Z: TMtxVec): TMtxVec; overload; (* Compute (X*xScale + yScalar)*Z on sub-array*) function AddAndMul(const X: TMtxVec; xIndex: integer; const xScale, Y: Double; const Z: TMtxVec; zIndex: integer; Index, Len: integer): TMtxVec; overload; (* Compute (X*xScale + yScalar)*Z on sub-array*) function AddAndMul(const X: TMtxVec; xIndex: integer; const xScale, Y: TCplx; const Z: TMtxVec; zIndex: integer; Index, Len: integer): TMtxVec; overload; (* Compute (X + yScalar)*Z *) function AddAndMul(const X: TMtxVec; const Y: Double; const Z: TMtxVec): TMtxVec; overload; (* Compute (X + yScalar)*Z *) function AddAndMul(const X: TMtxVec; const Y: TCplx; const Z: TMtxVec): TMtxVec; overload; (* Compute (X + yScalar)*Z on sub-array*) function AddAndMul(const X: TMtxVec; xIndex: integer; const Y: Double; const Z: TMtxVec; zIndex: integer; Index, Len: integer): TMtxVec; overload; (* Compute (X + yScalar)*Z on sub-array*) function AddAndMul(const X: TMtxVec; xIndex: integer; const Y: TCplx; const Z: TMtxVec; zIndex: integer; Index, Len: integer): TMtxVec; overload; (* Compute (X + yScalar)*zScalar *) function AddAndMul(const X: TMtxVec; const Y, Z: Double): TMtxVec; overload; (* Compute (X + yScalar)*zScalar *) function AddAndMul(const X: TMtxVec; const Y, Z: TCplx): TMtxVec; overload; (* Compute (X + yScalar)*zScalar on sub-array*) function AddAndMul(const X: TMtxVec; xIndex: integer; const Y, Z: Double; Index, Len: integer): TMtxVec; overload; (* Compute (X + yScalar)*zScalar on sub-array*) function AddAndMul(const X: TMtxVec; xIndex: integer; const Y, Z: TCplx; Index, Len: integer): TMtxVec; overload; (* Compute (X - Y)*Z *) function SubAndMul(const X, Y, Z: TMtxVec): TMtxVec; overload; (* Compute (X + Y)*Z on sub array*) function SubAndMul(const X: TMtxVec; xIndex: Integer; const Y: TMtxVec; yIndex: Integer; const Z: TMtxVec; zIndex: Integer; Index, Len: Integer): TMtxVec; overload; (* Compute (X - Y)*Z*zScale *) function SubAndMul(const X, Y, Z: TMtxVec; const zScale: double): TMtxVec; overload; (* Compute (X - Y)*Z*zScale *) function SubAndMul(const X, Y, Z: TMtxVec; const zScale: TCplx): TMtxVec; overload; (* Compute (X - Y)*Z*zScale on sub array*) function SubAndMul(const X: TMtxVec; xIndex: Integer; const Y: TMtxVec; yIndex: Integer; const Z: TMtxVec; zIndex: Integer;const zScale: double; Index, Len: Integer): TMtxVec; overload; (* Compute (X - Y)*Z*zScale on sub array*) function SubAndMul(const X: TMtxVec; xIndex: Integer; const Y: TMtxVec; yIndex: Integer; const Z: TMtxVec; zIndex: Integer;const zScale: TCplx; Index, Len: Integer): TMtxVec; overload; (* Compute (X - Y*yScale)*Z*zScale *) function SubAndMul(const X, Y: TMtxVec; const yScale: double; Z: TMtxVec; const zScale: double): TMtxVec; overload; (* Compute (X - Y*yScale)*Z*zScale *) function SubAndMul(const X, Y: TMtxVec; const yScale: TCplx; Z: TMtxVec; const zScale: TCplx): TMtxVec; overload; (* Compute (X - Y*yScale)*Z*zScale on sub array*) function SubAndMul(const X: TMtxVec; xIndex: Integer; const Y: TMtxVec; yIndex: Integer; const yScale: double; const Z: TMtxVec; zIndex: Integer; const zScale: double; Index, Len: Integer): TMtxVec; overload; (* Compute (X - Y*yScale)*Z*zScale on sub array*) function SubAndMul(const X: TMtxVec; xIndex: Integer; const Y: TMtxVec; yIndex: Integer; const yScale: TCplx; const Z: TMtxVec; zIndex: Integer; const zScale: TCplx; Index, Len: Integer): TMtxVec; overload; (* Compute (X - Y)*zScalar *) function SubAndMul(const X, Y: TMtxVec; const Z: Double): TMtxVec; overload; (* Compute (X - Y)*zScalar *) function SubAndMul(const X, Y: TMtxVec; const Z: TCplx): TMtxVec; overload; (* Compute (X - Y)*zScalar on sub array*) function SubAndMul(const X: TMtxVec; xIndex: Integer; const Y: TMtxVec; yIndex: Integer; const Z: Double; Index, Len: Integer): TMtxVec; overload; (* Compute (X - Y)*zScalar on sub array*) function SubAndMul(const X: TMtxVec; xIndex: Integer; const Y: TMtxVec; yIndex: Integer; const Z: TCplx; Index, Len: Integer): TMtxVec; overload; (* Compute (X - Y*yScale)*zScalar *) function SubAndMul(const X, Y: TMtxVec; const yScale, Z: Double): TMtxVec; overload; (* Compute (X - Y*yScale)*zScalar *) function SubAndMul(const X, Y: TMtxVec; const yScale, Z: TCplx): TMtxVec; overload; (* Compute (X - Y*yScale)*zScalar on sub array*) function SubAndMul(const X: TMtxVec; xIndex: Integer; const Y: TMtxVec; yIndex: Integer; const yScale, Z: Double; Index, Len: Integer): TMtxVec; overload; (* Compute (X - Y*yScale)*zScalar on sub array*) function SubAndMul(const X: TMtxVec; xIndex: Integer; const Y: TMtxVec; yIndex: Integer; const yScale, Z: TCplx; Index, Len: Integer): TMtxVec; overload; (* Compute (X - yScalar)*Z*zScale *) function SubAndMul(const X: TMtxVec; const Y: Double; const Z: TMtxVec; const zScale: Double): TMtxVec; overload; (* Compute (X - yScalar)*Z*zScale *) function SubAndMul(const X: TMtxVec; const Y: TCplx; const Z: TMtxVec; const zScale: TCplx): TMtxVec; overload; (* Compute (X - yScalar)*Z*zScale on sub-array*) function SubAndMul(const X: TMtxVec; xIndex: integer; const Y: Double; const Z: TMtxVec; zIndex: integer; const zScale: Double; Index, Len: integer): TMtxVec; overload; (* Compute (X - yScalar)*Z*zScale on sub-array*) function SubAndMul(const X: TMtxVec; xIndex: integer; const Y: TCplx; const Z: TMtxVec; zIndex: integer; const zScale: TCplx; Index, Len: integer): TMtxVec; overload; (* Compute (X*xScale - yScalar)*Z *) function SubAndMul(const X: TMtxVec; const xScale, Y: Double; const Z: TMtxVec): TMtxVec; overload; (* Compute (X*xScale - yScalar)*Z *) function SubAndMul(const X: TMtxVec; const xScale, Y: TCplx; const Z: TMtxVec): TMtxVec; overload; (* Compute (X*xScale - yScalar)*Z on sub-array*) function SubAndMul(const X: TMtxVec; xIndex: integer; const xScale, Y: Double; const Z: TMtxVec; zIndex: integer; Index, Len: integer): TMtxVec; overload; (* Compute (X*xScale - yScalar)*Z on sub-array*) function SubAndMul(const X: TMtxVec; xIndex: integer; const xScale, Y: TCplx; const Z: TMtxVec; zIndex: integer; Index, Len: integer): TMtxVec; overload; (* Compute (X - yScalar)*Z *) function SubAndMul(const X: TMtxVec; const Y: Double; const Z: TMtxVec): TMtxVec; overload; (* Compute (X - yScalar)*Z *) function SubAndMul(const X: TMtxVec; const Y: TCplx; const Z: TMtxVec): TMtxVec; overload; (* Compute (X - yScalar)*Z on sub-array*) function SubAndMul(const X: TMtxVec; xIndex: integer; const Y: Double; const Z: TMtxVec; zIndex: integer; Index, Len: integer): TMtxVec; overload; (* Compute (X - yScalar)*Z on sub-array*) function SubAndMul(const X: TMtxVec; xIndex: integer; const Y: TCplx; const Z: TMtxVec; zIndex: integer; Index, Len: integer): TMtxVec; overload; (* Compute (X - yScalar)*zScalar *) function SubAndMul(const X: TMtxVec; const Y, Z: Double): TMtxVec; overload; (* Compute (X - yScalar)*zScalar *) function SubAndMul(const X: TMtxVec; const Y, Z: TCplx): TMtxVec; overload; (* Compute (X - yScalar)*zScalar on sub-array*) function SubAndMul(const X: TMtxVec; xIndex: integer; const Y, Z: Double; Index, Len: integer): TMtxVec; overload; (* Compute (X - yScalar)*zScalar on sub-array*) function SubAndMul(const X: TMtxVec; xIndex: integer; const Y, Z: TCplx; Index, Len: integer): TMtxVec; overload; (* Compute X*Y + Z *) function MulAndAdd(const X, Y, Z: TMtxVec): TMtxVec; overload; (* Compute X*Y + Z on sub array*) function MulAndAdd(const X: TMtxVec; xIndex: Integer; const Y: TMtxVec; yIndex: Integer; const Z: TMtxVec; zIndex: Integer; Index, Len: Integer): TMtxVec; overload; (* Compute X*Y*xyScale + Z *) function MulAndAdd(const X, Y: TMtxVec; const xyScale: double; const Z: TMtxVec): TMtxVec; overload; (* Compute X*Y*xyScale + Z *) function MulAndAdd(const X, Y: TMtxVec; const xyScale: TCplx; const Z: TMtxVec): TMtxVec; overload; (* Compute X*Y*xyScale + Z on sub array*) function MulAndAdd(const X: TMtxVec; xIndex: Integer; const Y: TMtxVec; yIndex: Integer; const xyScale: double; const Z: TMtxVec; zIndex: Integer; Index, Len: Integer): TMtxVec; overload; (* Compute X*Y*xyScale + Z on sub array*) function MulAndAdd(const X: TMtxVec; xIndex: Integer; const Y: TMtxVec; yIndex: Integer; const xyScale: TCplx; const Z: TMtxVec; zIndex: Integer; Index, Len: Integer): TMtxVec; overload; (* Compute X*Y + Z*zScale *) function MulAndAdd(const X, Y, Z: TMtxVec; const zScale: double): TMtxVec; overload; (* Compute X*Y + Z*zScale *) function MulAndAdd(const X, Y, Z: TMtxVec; const zScale: TCplx): TMtxVec; overload; (* Compute X*Y + Z*zScale on sub array*) function MulAndAdd(const X: TMtxVec; xIndex: Integer; const Y: TMtxVec; yIndex: Integer; const Z: TMtxVec; zIndex: Integer; const zScale: double; Index, Len: Integer): TMtxVec; overload; (* Compute X*Y + Z*zScale on sub array*) function MulAndAdd(const X: TMtxVec; xIndex: Integer; const Y: TMtxVec; yIndex: Integer; const Z: TMtxVec; zIndex: Integer; const zScale: TCplx; Index, Len: Integer): TMtxVec; overload; (* Compute X*Y + zScalar *) function MulAndAdd(const X, Y: TMtxVec; const Z: Double): TMtxVec; overload; (* Compute X*Y + zScalar *) function MulAndAdd(const X, Y: TMtxVec; const Z: TCplx): TMtxVec; overload; (* Compute X*Y + zScalar on sub array*) function MulAndAdd(const X: TMtxVec; xIndex: Integer; const Y: TMtxVec; yIndex: Integer; const Z: Double; Index, Len: Integer): TMtxVec; overload; (* Compute X*Y + zScalar on sub array*) function MulAndAdd(const X: TMtxVec; xIndex: Integer; const Y: TMtxVec; yIndex: Integer; const Z: TCplx; Index, Len: Integer): TMtxVec; overload; (* Compute X*Y - Z *) function MulAndSub(const X, Y, Z: TMtxVec): TMtxVec; overload; (* Compute X*Y + Z on sub array*) function MulAndSub(const X: TMtxVec; xIndex: Integer; const Y: TMtxVec; yIndex: Integer; const Z: TMtxVec; zIndex: Integer; Index, Len: Integer): TMtxVec; overload; (* Compute X*Y*xyScale - Z *) function MulAndSub(const X, Y: TMtxVec; const xyScale: double; const Z: TMtxVec): TMtxVec; overload; (* Compute X*Y*xyScale - Z *) function MulAndSub(const X, Y: TMtxVec; const xyScale: TCplx; const Z: TMtxVec): TMtxVec; overload; (* Compute X*Y*xyScale + Z on sub array*) function MulAndSub(const X: TMtxVec; xIndex: Integer; const Y: TMtxVec; yIndex: Integer; const xyScale: double; const Z: TMtxVec; zIndex: Integer; Index, Len: Integer): TMtxVec; overload; (* Compute X*Y*xyScale + Z on sub array*) function MulAndSub(const X: TMtxVec; xIndex: Integer; const Y: TMtxVec; yIndex: Integer; const xyScale: TCplx; const Z: TMtxVec; zIndex: Integer; Index, Len: Integer): TMtxVec; overload; (* Compute X*Y - Z*zScale *) function MulAndSub(const X, Y, Z: TMtxVec; const zScale: double): TMtxVec; overload; (* Compute X*Y - Z*zScale *) function MulAndSub(const X, Y, Z: TMtxVec; const zScale: TCplx): TMtxVec; overload; (* Compute X*Y + Z*zScale on sub array*) function MulAndSub(const X: TMtxVec; xIndex: Integer; const Y: TMtxVec; yIndex: Integer; const Z: TMtxVec; zIndex: Integer; const zScale: double; Index, Len: Integer): TMtxVec; overload; (* Compute X*Y + Z*zScale on sub array*) function MulAndSub(const X: TMtxVec; xIndex: Integer; const Y: TMtxVec; yIndex: Integer; const Z: TMtxVec; zIndex: Integer; const zScale: TCplx; Index, Len: Integer): TMtxVec; overload; (* Compute X*Y - zScalar *) function MulAndSub(const X, Y: TMtxVec; const Z: Double): TMtxVec; overload; (* Compute X*Y - zScalar *) function MulAndSub(const X, Y: TMtxVec; const Z: TCplx): TMtxVec; overload; (* Compute X*Y - zScalar on sub array*) function MulAndSub(const X: TMtxVec; xIndex: Integer; const Y: TMtxVec; yIndex: Integer; const Z: Double; Index, Len: Integer): TMtxVec; overload; (* Compute X*Y - zScalar on sub array*) function MulAndSub(const X: TMtxVec; xIndex: Integer; const Y: TMtxVec; yIndex: Integer; const Z: TCplx; Index, Len: Integer): TMtxVec; overload; (* Compute X/Y + Z *) function DivAndAdd(const X, Y, Z: TMtxVec): TMtxVec; overload; (* Compute X/Y + Z on sub array*) function DivAndAdd(const X: TMtxVec; xIndex: Integer; const Y: TMtxVec; yIndex: Integer; const Z: TMtxVec; zIndex: Integer; Index, Len: Integer): TMtxVec; overload; (* Compute X/Y*xyScale + Z *) function DivAndAdd(const X, Y: TMtxVec; const xyScale: double; const Z: TMtxVec): TMtxVec; overload; (* Compute X/Y*xyScale + Z *) function DivAndAdd(const X, Y: TMtxVec; const xyScale: TCplx; const Z: TMtxVec): TMtxVec; overload; (* Compute X/Y*xyScale + Z on sub array*) function DivAndAdd(const X: TMtxVec; xIndex: Integer; const Y: TMtxVec; yIndex: Integer; const xyScale: double; const Z: TMtxVec; zIndex: Integer; Index, Len: Integer): TMtxVec; overload; (* Compute X/Y*xyScale + Z on sub array*) function DivAndAdd(const X: TMtxVec; xIndex: Integer; const Y: TMtxVec; yIndex: Integer; const xyScale: TCplx; const Z: TMtxVec; zIndex: Integer; Index, Len: Integer): TMtxVec; overload; (* Compute X/Y + Z*zScale *) function DivAndAdd(const X, Y, Z: TMtxVec; const zScale: double): TMtxVec; overload; (* Compute X/Y + Z*zScale *) function DivAndAdd(const X, Y, Z: TMtxVec; const zScale: TCplx): TMtxVec; overload; (* Compute X/Y + Z*zScale on sub array*) function DivAndAdd(const X: TMtxVec; xIndex: Integer; const Y: TMtxVec; yIndex: Integer; const Z: TMtxVec; zIndex: Integer; const zScale: double; Index, Len: Integer): TMtxVec; overload; (* Compute X/Y + Z*zScale on sub array*) function DivAndAdd(const X: TMtxVec; xIndex: Integer; const Y: TMtxVec; yIndex: Integer; const Z: TMtxVec; zIndex: Integer; const zScale: TCplx; Index, Len: Integer): TMtxVec; overload; (* Compute X/Y + zScalar *) function DivAndAdd(const X, Y: TMtxVec; const Z: Double): TMtxVec; overload; (* Compute X/Y + zScalar *) function DivAndAdd(const X, Y: TMtxVec; const Z: TCplx): TMtxVec; overload; (* Compute X/Y + zScalar on sub array*) function DivAndAdd(const X: TMtxVec; xIndex: Integer; const Y: TMtxVec; yIndex: Integer; const Z: Double; Index, Len: Integer): TMtxVec; overload; (* Compute X/Y + zScalar on sub array*) function DivAndAdd(const X: TMtxVec; xIndex: Integer; const Y: TMtxVec; yIndex: Integer; const Z: TCplx; Index, Len: Integer): TMtxVec; overload; (* Compute X/Y - Z *) function DivAndSub(const X, Y, Z: TMtxVec): TMtxVec; overload; (* Compute X/Y - Z on sub array*) function DivAndSub(const X: TMtxVec; xIndex: Integer; const Y: TMtxVec; yIndex: Integer; const Z: TMtxVec; zIndex: Integer; Index, Len: Integer): TMtxVec; overload; (* Compute X/Y*xyScale - Z *) function DivAndSub(const X, Y: TMtxVec; const xyScale: double; const Z: TMtxVec): TMtxVec; overload; (* Compute X/Y*xyScale - Z *) function DivAndSub(const X, Y: TMtxVec; const xyScale: TCplx; const Z: TMtxVec): TMtxVec; overload; (* Compute X/Y*xyScale - Z on sub array*) function DivAndSub(const X: TMtxVec; xIndex: Integer; const Y: TMtxVec; yIndex: Integer; const xyScale: double; const Z: TMtxVec; zIndex: Integer; Index, Len: Integer): TMtxVec; overload; (* Compute X/Y*xyScale - Z on sub array*) function DivAndSub(const X: TMtxVec; xIndex: Integer; const Y: TMtxVec; yIndex: Integer; const xyScale: TCplx; const Z: TMtxVec; zIndex: Integer; Index, Len: Integer): TMtxVec; overload; (* Compute X/Y - Z*zScale *) function DivAndSub(const X, Y, Z: TMtxVec; const zScale: double): TMtxVec; overload; (* Compute X/Y - Z*zScale *) function DivAndSub(const X, Y, Z: TMtxVec; const zScale: TCplx): TMtxVec; overload; (* Compute X/Y - Z*zScale on sub array*) function DivAndSub(const X: TMtxVec; xIndex: Integer; const Y: TMtxVec; yIndex: Integer; const Z: TMtxVec; zIndex: Integer; const zScale: double; Index, Len: Integer): TMtxVec; overload; (* Compute X/Y - Z*zScale on sub array*) function DivAndSub(const X: TMtxVec; xIndex: Integer; const Y: TMtxVec; yIndex: Integer; const Z: TMtxVec; zIndex: Integer; const zScale: TCplx; Index, Len: Integer): TMtxVec; overload; (* Compute X/Y - zScalar *) function DivAndSub(const X, Y: TMtxVec; const Z: Double): TMtxVec; overload; (* Compute X/Y - zScalar *) function DivAndSub(const X, Y: TMtxVec; const Z: TCplx): TMtxVec; overload; (* Compute X/Y - zScalar on sub array*) function DivAndSub(const X: TMtxVec; xIndex: Integer; const Y: TMtxVec; yIndex: Integer; const Z: Double; Index, Len: Integer): TMtxVec; overload; (* Compute X/Y - zScalar on sub array*) function DivAndSub(const X: TMtxVec; xIndex: Integer; const Y: TMtxVec; yIndex: Integer; const Z: TCplx; Index, Len: Integer): TMtxVec; overload; (* Compute X*xScale + Y*yScale *) function AddScaled(const X: TMtxVec; const xScale: Double; const Y: TMtxVec; const yScale: Double): TMtxVec; overload; (* Compute X*xScale + Y*yScale *) function AddScaled(const X: TMtxVec; const xScale: TCplx; const Y: TMtxVec; const yScale: TCplx): TMtxVec; overload; (* Compute X*xScale + Y*yScale on sub arrays *) function AddScaled(const X: TMtxVec; xIndex: integer; const xScale: Double; const Y: TMtxVec; yIndex: integer; const yScale: Double; Index, Len: integer): TMtxVec; overload; (* Compute X*xScale + Y*yScale on sub arrays *) function AddScaled(const X: TMtxVec; xIndex: integer; const xScale: TCplx; const Y: TMtxVec; yIndex: integer; const yScale: TCplx; Index, Len: integer): TMtxVec; overload; (* Compute sqr(X*xScale + Y*yScale) *) function AddScaledSqr(const X: TMtxVec; const xScale: Double; const Y: TMtxVec; const yScale: Double): TMtxVec; overload; (* Compute sqr(X*xScale + Y*yScale) *) function AddScaledSqr(const X: TMtxVec; const xScale: TCplx; const Y: TMtxVec; const yScale: TCplx): TMtxVec; overload; (* Compute sqr(X*xScale + Y*yScale) on sub arrays *) function AddScaledSqr(const X: TMtxVec; xIndex: integer; const xScale: Double; const Y: TMtxVec; yIndex: integer; const yScale: Double; Index, Len: integer): TMtxVec; overload; (* Compute sqr(X*xScale + Y*yScale) on sub arrays *) function AddScaledSqr(const X: TMtxVec; xIndex: integer; const xScale: TCplx; const Y: TMtxVec; yIndex: integer; const yScale: TCplx; Index, Len: integer): TMtxVec; overload; (* Compute sqr(X)*xScale + sqr(Y)*yScale *) function SqrAddScaled(const X: TMtxVec; const xScale: Double; const Y: TMtxVec; const yScale: Double): TMtxVec; overload; (* Compute sqr(X)*xScale + sqr(Y)*yScale *) function SqrAddScaled(const X: TMtxVec; const xScale: TCplx; const Y: TMtxVec; const yScale: TCplx): TMtxVec; overload; (* Compute sqr(X)*xScale + sqr(Y)*yScale on sub arrays *) function SqrAddScaled(const X: TMtxVec; xIndex: integer; const xScale: Double; const Y: TMtxVec; yIndex: integer; const yScale: Double; Index, Len: integer): TMtxVec; overload; (* Compute sqr(X)*xScale + sqr(Y)*yScale on sub arrays *) function SqrAddScaled(const X: TMtxVec; xIndex: integer; const xScale: TCplx; const Y: TMtxVec; yIndex: integer; const yScale: TCplx; Index, Len: integer): TMtxVec; overload; (* Compute X*xScale + Y*yScale + Z*zScale *) function AddScaled(const X: TMtxVec; const xScale: Double; const Y: TMtxVec; const yScale: Double; const Z: TMtxVec; const zScale: Double): TMtxVec; overload; (* Compute X*xScale + Y*yScale + Z*zScale *) function AddScaled(const X: TMtxVec; const xScale: TCplx; const Y: TMtxVec; const yScale: TCplx; const Z: TMtxVec; const zScale: TCplx): TMtxVec; overload; (* Compute X*xScale + Y*yScale + Z*zScale on sub arrays *) function AddScaled(const X: TMtxVec; xIndex: integer; const xScale: Double; const Y: TMtxVec; yIndex: integer; const yScale: Double; const Z: TMtxVec; zIndex: integer; const zScale: Double; Index, Len: integer): TMtxVec; overload; (* Compute X*xScale + Y*yScale + Z*zScale on sub arrays *) function AddScaled(const X: TMtxVec; xIndex: integer; const xScale: TCplx; const Y: TMtxVec; yIndex: integer; const yScale: TCplx; const Z: TMtxVec; zIndex: integer; const zScale: TCplx; Index, Len: integer): TMtxVec; overload; (* Compute X*xScale + Y*yScale + zScalar *) function AddScaledC(const X: TMtxVec; const xScale: Double; const Y: TMtxVec; const yScale: Double; const Z: Double): TMtxVec; overload; (* Compute X*xScale + Y*yScale + zScalar *) function AddScaledC(const X: TMtxVec; const xScale: TCplx; const Y: TMtxVec; const yScale: TCplx; const Z: TCplx): TMtxVec; overload; (* Compute X*xScale + Y*yScale + z on sub arrays *) function AddScaledC(const X: TMtxVec; xIndex: integer; const xScale: Double; const Y: TMtxVec; yIndex: integer; const yScale: Double; const Z: Double; Index, Len: integer): TMtxVec; overload; (* Compute X*xScale + Y*yScale + z on sub arrays *) function AddScaledC(const X: TMtxVec; xIndex: integer; const xScale: TCplx; const Y: TMtxVec; yIndex: integer; const yScale: TCplx; const Z: TCplx; Index, Len: integer): TMtxVec; overload; (* Compute X*xScale - Y*yScale - Z*zScale *) function SubScaled(const X: TMtxVec; const xScale: Double; const Y: TMtxVec; const yScale: Double; const Z: TMtxVec; const zScale: Double): TMtxVec; overload; (* Compute X*xScale - Y*yScale - Z*zScale *) function SubScaled(const X: TMtxVec; const xScale: TCplx; const Y: TMtxVec; const yScale: TCplx; const Z: TMtxVec; const zScale: TCplx): TMtxVec; overload; (* Compute X*xScale - Y*yScale - zScalar *) function SubScaledC(const X: TMtxVec; const xScale: Double; const Y: TMtxVec; const yScale: Double; const Z: Double): TMtxVec; overload; (* Compute X*xScale - Y*yScale - zScalar *) function SubScaledC(const X: TMtxVec; const xScale: TCplx; const Y: TMtxVec; const yScale: TCplx; const Z: TCplx): TMtxVec; overload; (* Compute X*xScale - Y*yScale - Z*zScale on sub array*) function SubScaled(const X: TMtxVec; xIndex: integer; const xScale: Double; const Y: TMtxVec; yIndex: integer; const yScale: Double; const Z: TMtxVec; zIndex: integer; const zScale: Double; Index, Len: integer): TMtxVec; overload; (* Compute X*xScale - Y*yScale - Z*zScale on sub array*) function SubScaled(const X: TMtxVec; xIndex: integer; const xScale: TCplx; const Y: TMtxVec; yIndex: integer; const yScale: TCplx; const Z: TMtxVec; zIndex: integer; const zScale: TCplx; Index, Len: integer): TMtxVec; overload; (* Compute X*xScale - Y*yScale - zScalar on sub array*) function SubScaledC(const X: TMtxVec; xIndex: integer; const xScale: Double; const Y: TMtxVec; yIndex: integer; const yScale: Double; const Z: Double; Index, Len: integer): TMtxVec; overload; (* Compute X*xScale - Y*yScale - zScalar on sub array*) function SubScaledC(const X: TMtxVec; xIndex: integer; const xScale: TCplx; const Y: TMtxVec; yIndex: integer; const yScale: TCplx; const Z: TCplx; Index, Len: integer): TMtxVec; overload; (* Compute X*Y*Z The following expression would also run at the same or higher speed, when passing X also for the Z parameter: X^2*Y *) function Mul(const X, Y,Z: TMtxVec): TMtxVec; overload; (* Compute X*Y*zScalar The following expression would also run at the same or higher speed, when passing X also for the Z parameter: X^2*zScalar *) function Mul(const X,Y: TMtxVec; const Z: Double): TMtxVec; overload; (* Compute X*Y*zScalar The following expression would also run at the same or higher speed, when passing X also for the Z parameter: X^2*zScalar *) function Mul(const X,Y: TMtxVec; const Z: TCplx): TMtxVec; overload; (* Compute X*Y*Z on sub array*) function Mul(const X: TMtxVec; xIndex: integer; const Y: TMtxVec; yIndex: integer; const Z: TMtxVec; zIndex: integer; Index, Len: integer): TMtxVec; overload; (* Compute X*Y*zScalar on sub array*) function Mul(const X: TMtxVec; xIndex: integer; const Y: TMtxVec; yIndex: integer; const Z: Double; Index, Len: integer): TMtxVec; overload; (* Compute X*Y*zScalar on sub array*) function Mul(const X: TMtxVec; xIndex: integer; const Y: TMtxVec; yIndex: integer; const Z: TCplx; Index, Len: integer): TMtxVec; overload; (* Compute X / (Y*Z) The following expression would also run at the same or higher speed, when passing Y also for the Z parameter: X / (Y^2) *) function Divide(const X, Y, Z: TMtxVec): TMtxVec; overload; (* Compute X/( Y*Z ) on sub array*) function Divide(const X: TMtxVec; xIndex: integer; const Y: TMtxVec; yIndex: integer; const Z: TMtxVec; zIndex: integer; Index, Len: integer): TMtxVec; overload; (* Compute X / (Y*zScale) *) function DivideC(const X, Y: TMtxVec; const Z: Double): TMtxVec; overload; (* Compute X / (Y*zScale) *) function DivideC(const X, Y: TMtxVec; const Z: TCplx): TMtxVec; overload; (* Compute X / (Y*zScalar) on sub array*) function DivideC(const X: TMtxVec; xIndex: integer; const Y: TMtxVec; yIndex: integer; const Z: Double; Index, Len: integer): TMtxVec; overload; (* Compute X / (Y*zScalar) on sub array*) function DivideC(const X: TMtxVec; xIndex: integer; const Y: TMtxVec; yIndex: integer; const Z: TCplx; Index, Len: integer): TMtxVec; overload; (* Compute X * Y * xyScale / Z The following expression would also run at the same or higher speed, when passing X also for the Y parameter: X^2 * xyScale/ Z *) function MulAndDiv(const X, Y: TMtxVec; const xyScale: Double; const Z: TMtxVec): TMtxVec; overload; (* Compute X * Y * xyScale / Z The following expression would also run at the same or higher speed, when passing X also for the Y parameter: X^2 * xyScale/ Z *) function MulAndDiv(const X, Y: TMtxVec; const xyScale: TCplx; const Z: TMtxVec): TMtxVec; overload; (* Compute X * Y * xyScale / Z on sub array*) function MulAndDiv(const X: TMtxVec; xIndex: integer; const Y: TMtxVec; yIndex: integer; const xyScale: Double; const Z: TMtxVec; zIndex: integer; Index, Len: integer): TMtxVec; overload; (* Compute X * Y * xyScale / Z on sub array*) function MulAndDiv(const X: TMtxVec; xIndex: integer; const Y: TMtxVec; yIndex: integer; const xyScale: TCplx; const Z: TMtxVec; zIndex: integer; Index, Len: integer): TMtxVec; overload; (* Compute X * Y / zScalar *) function MulAndDiv(const X, Y: TMtxVec; const Z: Double): TMtxVec; overload; (* Compute X * Y / zScalar *) function MulAndDiv(const X, Y: TMtxVec; const Z: TCplx): TMtxVec; overload; (* Compute X * Y / zScalar on sub array*) function MulAndDiv(const X: TMtxVec; xIndex: integer; const Y: TMtxVec; yIndex: integer; const Z: Double; Index, Len: integer): TMtxVec; overload; (* Compute X * Y / zScalar on sub array*) function MulAndDiv(const X: TMtxVec; xIndex: integer; const Y: TMtxVec; yIndex: integer; const Z: TCplx; Index, Len: integer): TMtxVec; overload; (* Compute xScalar / (Y*Z) *) function Divide(const X: Double; const Y, Z: TMtxVec): TMtxVec; overload; (* Compute xScalar / (Y*Z) *) function Divide(const X: TCplx; const Y, Z: TMtxVec): TMtxVec; overload; (* Compute xScalar / (Y*Z) on sub array*) function Divide(const X: Double; const Y: TMtxVec; yIndex: integer; const Z: TMtxVec; zIndex: integer; Index, Len: integer): TMtxVec; overload; (* Compute xScalar / (Y*Z) on sub array*) function Divide(const X: TCplx; const Y: TMtxVec; yIndex: integer; const Z: TMtxVec; zIndex: integer; Index, Len: integer): TMtxVec; overload; (* Compute (X*xScale + Y*yScale)*Z*zScale The following is also possible at the same or higher speed: X^2 * xScale + XY * yScale by passing X also for the Z parameter. *) function AddAndMul(const X: TMtxVec; xScale: Double; const Y: TMtxVec; yScale: Double; const Z: TMtxVec; zScale: Double): TMtxVec; overload; (* Compute (X*xScale + Y*yScale)*Z*zScale The following is also possible at the same or higher speed: X^2 * xScale + XY * yScale by passing X also for the Z parameter. *) function AddAndMul(const X: TMtxVec; xScale: TCplx; const Y: TMtxVec; yScale: TCplx; const Z: TMtxVec; zScale: TCplx): TMtxVec; overload; (* Compute (X*xScale + Y*yScale)*Z*Scale on sub array*) function AddAndMul(const X: TMtxVec; xIndex: Integer; xScale: Double; const Y: TMtxVec; yIndex: Integer; yScale: Double; const Z: TMtxVec; zIndex: Integer; zScale: Double; Index, Len: Integer): TMtxVec; overload; (* Compute (X*xScale + Y*yScale)*Z*Scale on sub array*) function AddAndMul(const X: TMtxVec; xIndex: Integer; xScale: TCplx; const Y: TMtxVec; yIndex: Integer; yScale: TCplx; const Z: TMtxVec; zIndex: Integer; zScale: TCplx; Index, Len: Integer): TMtxVec; overload; (* Compute (X*xScale + Y*yScale)*zScalar*) function AddAndMul(const X: TMtxVec; const xScale: Double; const Y: TMtxVec; const yScale: Double; const Z: Double): TMtxVec; overload; (* Compute (X*xScale + Y*yScale)*zScalar*) function AddAndMul(const X: TMtxVec; const xScale: TCplx; const Y: TMtxVec; const yScale: TCplx; const Z: TCplx): TMtxVec; overload; (* Compute (X*xScale + Y*yScale)*zScalar on sub array*) function AddAndMul(const X: TMtxVec; xIndex: Integer; const xScale: Double; const Y: TMtxVec; yIndex: Integer; const yScale: Double; const Z: Double; Index, Len: Integer): TMtxVec; overload; (* Compute (X*xScale + Y*yScale)*zScalar on sub array*) function AddAndMul(const X: TMtxVec; xIndex: Integer; const xScale: TCplx; const Y: TMtxVec; yIndex: Integer; const yScale: TCplx; const Z: TCplx; Index, Len: Integer): TMtxVec; overload; (* Compute (X* xScale + yScalar)*Z*zScale*) function AddAndMul(const X: TMtxVec; const xScale: Double; const Y: Double; const Z: TMtxVec; const zScale: Double): TMtxVec; overload; (* Compute (X* xScale + yScalar)*Z*zScale*) function AddAndMul(const X: TMtxVec; const xScale: TCplx; const Y: TCplx; const Z: TMtxVec; const zScale: TCplx): TMtxVec; overload; (* Compute (X* xScale + yScalar)*Z*zScale on sub-array*) function AddAndMul(const X: TMtxVec; xIndex: integer; const xScale: Double; const Y: Double; const Z: TMtxVec; zIndex: integer; const zScale: Double; Index, Len: integer): TMtxVec; overload; (* Compute (X* xScale + yScalar)*Z*zScale on sub-array*) function AddAndMul(const X: TMtxVec; xIndex: integer; const xScale: TCplx; const Y: TCplx; const Z: TMtxVec; zIndex: integer; const zScale: TCplx; Index, Len: integer): TMtxVec; overload; (* Compute (X*xScale + yScalar)*zScalar*) function AddAndMul(const X: TMtxVec; const xScale: Double; const Y, Z: Double): TMtxVec; overload; (* Compute (X*xScale + yScalar)*zScalar*) function AddAndMul(const X: TMtxVec; const xScale: TCplx; const Y, Z: TCplx): TMtxVec; overload; (* Compute (X*xScale + yScalar)*zScalar on sub array*) function AddAndMul(const X: TMtxVec; xIndex: integer; const xScale: Double; const Y, Z: Double; Index, Len: integer): TMtxVec; overload; (* Compute (X*xScale + yScalar)*zScalar on sub array*) function AddAndMul(const X: TMtxVec; xIndex: integer; const xScale: TCplx; const Y, Z: TCplx; Index, Len: integer): TMtxVec; overload; (* Compute (X*xScale - Y*yScale)*Z*zScale*) function SubAndMul(const X: TMtxVec; const xScale: Double; const Y: TMtxVec; const yScale: Double; const Z: TMtxVec; const zScale: Double): TMtxVec; overload; (* Compute (X*xScale - Y*yScale)*Z*zScale*) function SubAndMul(const X: TMtxVec; const xScale: TCplx; const Y: TMtxVec; const yScale: TCplx; const Z: TMtxVec; const zScale: TCplx): TMtxVec; overload; (* Compute (X*xScale - Y*yScale)*Z*Scale on sub array*) function SubAndMul(const X: TMtxVec; xIndex: Integer; const xScale: Double; const Y: TMtxVec; yIndex: Integer; const yScale: Double; const Z: TMtxVec; zIndex: Integer; const zScale: Double; Index, Len: Integer): TMtxVec; overload; (* Compute (X*xScale - Y*yScale)*Z*Scale on sub array*) function SubAndMul(const X: TMtxVec; xIndex: Integer; const xScale: TCplx; const Y: TMtxVec; yIndex: Integer; const yScale: TCplx; const Z: TMtxVec; zIndex: Integer; const zScale: TCplx; Index, Len: Integer): TMtxVec; overload; (* Compute (X*xScale - Y*yScale)*zScalar*) function SubAndMul(const X: TMtxVec; const xScale: Double; const Y: TMtxVec; const yScale: Double; const Z: Double): TMtxVec; overload; (* Compute (X*xScale - Y*yScale)*zScalar*) function SubAndMul(const X: TMtxVec; const xScale: TCplx; const Y: TMtxVec; const yScale: TCplx; const Z: TCplx): TMtxVec; overload; (* Compute (X*xScale - Y*yScale)*zScalar on sub array*) function SubAndMul(const X: TMtxVec; xIndex: Integer; const xScale: Double; const Y: TMtxVec; yIndex: Integer; const yScale: Double; const Z: Double; Index, Len: Integer): TMtxVec; overload; (* Compute (X*xScale - Y*yScale)*zScalar on sub array*) function SubAndMul(const X: TMtxVec; xIndex: Integer; const xScale: TCplx; const Y: TMtxVec; yIndex: Integer; const yScale: TCplx; const Z: TCplx; Index, Len: Integer): TMtxVec; overload; (* Compute (X*xScale - yScalar)*Z*zScale*) function SubAndMul(const X: TMtxVec; const xScale: Double; const Y: Double; const Z: TMtxVec; const zScale: Double): TMtxVec; overload; (* Compute (X*xScale - yScalar)*Z*zScale*) function SubAndMul(const X: TMtxVec; const xScale: TCplx; const Y: TCplx; const Z: TMtxVec; const zScale: TCplx): TMtxVec; overload; (* Compute (X*xScale - yScalar)*Z*zScale on sub-array*) function SubAndMul(const X: TMtxVec; xIndex: integer; const xScale: Double; const Y: Double; const Z: TMtxVec; zIndex: integer; const zScale: Double; Index, Len: integer): TMtxVec; overload; (* Compute (X*xScale - yScalar)*Z*zScale on sub-array*) function SubAndMul(const X: TMtxVec; xIndex: integer; const xScale: TCplx; const Y: TCplx; const Z: TMtxVec; zIndex: integer; const zScale: TCplx; Index, Len: integer): TMtxVec; overload; (* Compute (X*xScale - yScalar)*zScalar*) function SubAndMul(const X: TMtxVec; const xScale: Double; const Y, Z: Double): TMtxVec; overload; (* Compute (X*xScale - yScalar)*zScalar*) function SubAndMul(const X: TMtxVec; const xScale: TCplx; const Y, Z: TCplx): TMtxVec; overload; (* Compute (X*xScale - yScalar)*zScalar on sub array*) function SubAndMul(const X: TMtxVec; xIndex: integer; const xScale: Double; const Y, Z: Double; Index, Len: integer): TMtxVec; overload; (* Compute (X*xScale - yScalar)*zScalar on sub array*) function SubAndMul(const X: TMtxVec; xIndex: integer; const xScale: TCplx; const Y, Z: TCplx; Index, Len: integer): TMtxVec; overload; (* Compute (X*Y)*xyScale + Z*zScale The following expression would also run at the same or higher speed, when passing X also for the Y parameter: X^2*xyScale + Z*zScale *) function MulAndAdd(const X: TMtxVec; const Y: TMtxVec; const xyScale: Double; const Z: TMtxVec; const zScale: Double): TMtxVec; overload; (* Compute (X*Y)*xyScale + Z*zScale on sub array*) function MulAndAdd(const X: TMtxVec; xIndex: Integer; const Y: TMtxVec; yIndex: Integer; const xyScale: Double; const Z: TMtxVec; zIndex: Integer; const zScale: Double; Index, Len: Integer): TMtxVec; overload; (* Compute (X*Y)*xyScale + Z*zScale The following expression would also run at the same or higher speed, when passing X also for the Y parameter: X^2*xyScale + Z*zScale *) function MulAndAdd(const X: TMtxVec; const Y: TMtxVec; const xyScale: TCplx; const Z: TMtxVec; const zScale: TCplx): TMtxVec; overload; (* Compute (X*Y)*xyScale + Z*zScale on sub array*) function MulAndAdd(const X: TMtxVec; xIndex: Integer; const Y: TMtxVec; yIndex: Integer; const xyScale: TCplx; const Z: TMtxVec; zIndex: Integer;const zScale: TCplx; Index, Len: Integer): TMtxVec; overload; (* Compute (X*Y)*xyScale + zScalar*) function MulAndAdd(const X: TMtxVec; const Y: TMtxVec; const xyScale: Double; const Z: Double): TMtxVec; overload; (* Compute (X*Y)*xyScale + zScalar on sub array The following expression would also run at the same or higher speed, when passing X also for the Y parameter: X^2*xyScale + zScale *) function MulAndAdd(const X: TMtxVec; xIndex: Integer; const Y: TMtxVec; yIndex: Integer; const xyScale: Double; const Z: Double; Index, Len: Integer): TMtxVec; overload; (* Compute (X*Y)*xyScale + zScalar*) function MulAndAdd(const X: TMtxVec; const Y: TMtxVec; const xyScale: TCplx; const Z: TCplx): TMtxVec; overload; (* Compute (X*Y)*xyScale + zScalar on sub array The following expression would also run at the same or higher speed, when passing X also for the Y parameter: X^2*xyScale + zScale *) function MulAndAdd(const X: TMtxVec; xIndex: Integer; const Y: TMtxVec; yIndex: Integer; const xyScale: TCplx; const Z: TCplx; Index, Len: Integer): TMtxVec; overload; (* Compute (X*yScalar) + zScalar*) function MulAndAdd(const X: TMtxVec; const Y, Z: Double): TMtxVec; overload; (* Compute (X*yScalar) + zScalar*) function MulAndAdd(const X: TMtxVec; xIndex: integer; const Y, Z: Double; Index, Len: integer): TMtxVec; overload; (* Compute (X*yScalar) + zScalar*) function MulAndAdd(const X: TMtxVec; const Y, Z: TCplx): TMtxVec; overload; (* Compute (X*yScalar) + zScalar*) function MulAndAdd(const X: TMtxVec; xIndex: integer; const Y, Z: TCplx; Index, Len: integer): TMtxVec; overload; (* Compute (X*Y)*xyScale - Z*zScale*) function MulAndSub(const X: TMtxVec; const Y: TMtxVec; const xyScale: Double; const Z: TMtxVec; const zScale: Double): TMtxVec; overload; (* Compute (X*Y)*xyScale - Z*zScale*) function MulAndSub(const X: TMtxVec; const Y: TMtxVec; const xyScale: TCplx; const Z: TMtxVec; const zScale: TCplx): TMtxVec; overload; (* Compute (X*Y)*xyScale - Z*zScale on sub array*) function MulAndSub(const X: TMtxVec; xIndex: Integer; const Y: TMtxVec; yIndex: Integer; const xyScale: Double; const Z: TMtxVec; zIndex: Integer; const zScale: Double; Index, Len: Integer): TMtxVec; overload; (* Compute (X*Y)*xyScale - Z*zScale on sub array*) function MulAndSub(const X: TMtxVec; xIndex: Integer; const Y: TMtxVec; yIndex: Integer; const xyScale: TCplx; const Z: TMtxVec; zIndex: Integer; const zScale: TCplx; Index, Len: Integer): TMtxVec; overload; (* Compute (X*Y)*xyScale - zScalar*) function MulAndSub(const X: TMtxVec; const Y: TMtxVec; const xyScale, Z: Double): TMtxVec; overload; (* Compute (X*Y)*xyScale - zScalar*) function MulAndSub(const X: TMtxVec; const Y: TMtxVec; const xyScale, Z: TCplx): TMtxVec; overload; (* Compute (X*Y)*xyScale - zScalar on sub array*) function MulAndSub(const X: TMtxVec; xIndex: Integer; const Y: TMtxVec; yIndex: Integer; const xyScale: Double; const Z: Double; Index, Len: Integer): TMtxVec; overload; (* Compute (X*Y)*xyScale - zScalar on sub array*) function MulAndSub(const X: TMtxVec; xIndex: Integer; const Y: TMtxVec; yIndex: Integer; const xyScale: TCplx; const Z: TCplx; Index, Len: Integer): TMtxVec; overload; (* Compute X*yScalar - Z*zScale*) function MulAndSub(const X: TMtxVec; const Y: Double; const Z: TMtxVec; const zScale: Double): TMtxVec; overload; (* Compute X*yScalar - Z*zScale*) function MulAndSub(const X: TMtxVec; const Y: TCplx; const Z: TMtxVec; const zScale: TCplx): TMtxVec; overload; (* Compute X*yScalar - Z*zScale on sub array*) function MulAndSub(const X: TMtxVec; xIndex: integer; const Y: Double; const Z: TMtxVec; zIndex: integer; const zScale: Double; Index, Len: integer): TMtxVec; overload; (* Compute X*yScalar - Z*zScale on sub array*) function MulAndSub(const X: TMtxVec; xIndex: integer; const Y: TCplx; const Z: TMtxVec; zIndex: integer; const zScale: TCplx; Index, Len: integer): TMtxVec; overload; (* Compute (X / Y)*xyScale + Z*zScale The following expression would also run at the same or higher speed, when passing Z also for the Y parameter: (X / Z) * xyScale + Z * zScale *) function DivAndAdd(const X: TMtxVec; const Y: TMtxVec; const xyScale: Double; const Z: TMtxVec; const zScale: Double): TMtxVec; overload; (* Compute (X / Y)*xyScale + Z*zScale on sub array*) function DivAndAdd(const X: TMtxVec; xIndex: Integer; const Y: TMtxVec; yIndex: Integer; const xyScale: Double; const Z: TMtxVec; zIndex: Integer; const zScale: Double; Index, Len: Integer): TMtxVec; overload; (* Compute (X / Y)*xyScale + Z*zScale The following expression would also run at the same or higher speed, when passing Z also for the Y parameter: (X / Z) * xyScale + Z * zScale *) function DivAndAdd(const X: TMtxVec; const Y: TMtxVec; const xyScale: TCplx; const Z: TMtxVec; const zScale: TCplx): TMtxVec; overload; (* Compute (X / Y)*xyScale + Z*zScale on sub array*) function DivAndAdd(const X: TMtxVec; xIndex: Integer; const Y: TMtxVec; yIndex: Integer; const xyScale: TCplx; const Z: TMtxVec; zIndex: Integer; const zScale: TCplx; Index, Len: Integer): TMtxVec; overload; (* Compute (X / Y) * xyScale + zScalar*) function DivAndAdd(const X: TMtxVec; const Y: TMtxVec; const xyScale: Double; const Z: Double): TMtxVec; overload; (* Compute (X / Y) * xyScale + zScalar*) function DivAndAdd(const X: TMtxVec; xIndex: Integer; const Y: TMtxVec; yIndex: Integer; const xyScale: Double; const Z: Double; Index, Len: Integer): TMtxVec; overload; (* Compute (X / Y) * xyScale + zScalar*) function DivAndAdd(const X: TMtxVec; const Y: TMtxVec; const xyScale: TCplx; const Z: TCplx): TMtxVec; overload; (* Compute (X / Y) * xyScale + zScalar*) function DivAndAdd(const X: TMtxVec; xIndex: Integer; const Y: TMtxVec; yIndex: Integer; const xyScale: TCplx; const Z: TCplx; Index, Len: Integer): TMtxVec; overload; (* Compute (X / Y) * xyScale - Z*zScale *) function DivAndSub(const X: TMtxVec; const Y: TMtxVec; const xyScale: Double; const Z: TMtxVec; const zScale: Double): TMtxVec; overload; (* Compute (X / Y) * xyScale - Z on sub array*) function DivAndSub(const X: TMtxVec; xIndex: Integer; const Y: TMtxVec; yIndex: Integer; const xyScale: Double; const Z: TMtxVec; zIndex: Integer; const zScale: Double; Index, Len: Integer): TMtxVec; overload; (* Compute (X / Y) * xyScale - Z*zScale *) function DivAndSub(const X: TMtxVec; const Y: TMtxVec; const xyScale: TCplx; const Z: TMtxVec; const zScale: TCplx): TMtxVec; overload; (* Compute (X / Y) * xyScale - Z on sub array*) function DivAndSub(const X: TMtxVec; xIndex: Integer; const Y: TMtxVec; yIndex: Integer; const xyScale: TCplx; const Z: TMtxVec; zIndex: Integer; const zScale: TCplx; Index, Len: Integer): TMtxVec; overload; (* Compute (X / Y) * xyScale - zScalar*) function DivAndSub(const X: TMtxVec; const Y: TMtxVec; const xyScale: Double; const Z: Double): TMtxVec; overload; (* Compute (X / Y) * xyScale - zScalar on sub array*) function DivAndSub(const X: TMtxVec; xIndex: Integer; const Y: TMtxVec; yIndex: Integer; const xyScale: Double; const Z: Double; Index, Len: Integer): TMtxVec; overload; (* Compute (X / Y) * xyScale - zScalar*) function DivAndSub(const X: TMtxVec; const Y: TMtxVec; const xyScale: TCplx; const Z: TCplx): TMtxVec; overload; (* Compute (X / Y) * xyScale - zScalar on sub array*) function DivAndSub(const X: TMtxVec; xIndex: Integer; const Y: TMtxVec; yIndex: Integer; const xyScale: TCplx; const Z: TCplx; Index, Len: Integer): TMtxVec; overload; (*Calculate the cumulative product for all Vec elements. The size must be set by the user. The function will store all powers of Value: Values[Index + i] := IntPower(Value, i + 1) at the corresponding array Index. *) function CumProduct(Value: Double; Index, Len: integer): TMtxVec; overload; (*Calculate the cumulative product for all Vec elements. The size must be set by the user. The function will store all powers of Value: Values[Index + i] := IntPower(Value, i + 1) at the corresponding array Index. *) function CumProduct(const Value: TCplx; Index, Len: integer): TMtxVec; overload; (*Add Vec1 elements [Vec1Index]..[Vec1Index+Len-1] to Vec2 elements [Vec2Index]..[Vec2Index+Len-1]. Store the results in calling object elements [Index]..[Index+Len-1]. An exception is raised if ConditionCheck is true and array borders are overrun. *) function Add(const Vec1, Vec2: TMtxVec; Vec1Index, Vec2Index, Index, Len: integer): TMtxVec; overload; (*Add a product of two vectors. Multiply Vec1 elements with coresponding Vec2 elements and add the result to the calling vector. The size of the calling vector is set implicitly. *) function AddProduct(const Vec1, Vec2: TMtxVec): TMtxVec; overload; (*Multiply Vec1 elements [Vec1Index]..[Vec1Index+Len-1] with Vec2 elements [Vec2Index]..[Vec2Index+Len-1] and add the results to the calling object elements [Index]..[Index+Len-1]. An exception is raised if ConditionCheck is true and array borders are overrun. *) function AddProduct(const Vec1, Vec2: TMtxVec; Vec1Index, Vec2Index, Index, Len: integer): TMtxVec; overload; (*Conjugate and multiply. Conjugate each of Vec elements and multiply them with corresponding elements in the calling object. The results are stored in the calling object. Size and properties of the calling object are set implicitly to match Vec. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TVec a,b,c; MtxVec.CreateIt(out a, out b, out c); try { a.SetIt(false, new double[] {1,2,3,4}); b.SetIt(false, new double[] {4,3,,2,1}); c.ConjMul(a,b); } finally { MtxVec.FreeIt(ref a,ref b,ref c); } } } *) function ConjMul(const Vec: TMtxVec): TMtxVec; overload; (*Conjugate Vec elements Vec[VecIndex]..Vec[VecIndex+Len-1] and multiply them with corresponding calling object elements [Index]..[Index+Len-1]. The results are stored in the calling object elements [Index]..[Index+Len-1]. Size and properties are not set. An exception is raised if ConditionCheck is true and array borders are overrun or underrun. *) function ConjMul(const Vec: TMtxVec; VecIndex, Index, Len: integer): TMtxVec; overload; (*Conjugate each of Vec2 elements and multiply them with corresponding elements in Vec1. The results are stored in the calling object. Size and properties of the calling object are set implicitly to match Vec1 and Vec2 objects. *) function ConjMul(const Vec1, Vec2: TMtxVec): TMtxVec; overload; (*Conjugate Vec2 elements [Vec2Index]..[Vec2Index+Len-1] and multiply them with corresponding Vec1 elements [Vec1Index]..[Vec1Index+Len-1]. The results are stored in the calling object elements [Index]..[Index+Len-1]. Size and properties of the calling vector must be set explicitly. An exception is raised if ConditionCheck is true and array borders are overrun. *) function ConjMul(const Vec1, Vec2: TMtxVec; Vec1Index, Vec2Index, Index, Len: integer): TMtxVec; overload; (*Cumulative sum. Calculate the cumulative sum for calling object elements [Index]..[Index+Len-1] in-place. An exception is raised if ConditionCheck is true and array borders are overrun. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TVec a; MtxVec.CreateIt(out a); try { a.SetIt(true,new double[] {1,2,3,4}); a.CumSum(); // a = [1,3,6,10] } finally { MtxVec.FreeIt(ref a); } } } *) function CumSum(Index, Len: Integer): TMtxVec; overload; (*Calculate the cumulative sum for Vec elements [VecIndex]..[VecIndex+Len-1]. Store the results in calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. Exception is raised if ConditionCheck property is True and array borders are overrun. *) function CumSum(const Vec: TMtxVec; VecIndex,Index,Len: Integer): TMtxVec; overload; (*The forward discrete cosine transform (DCT). Calculates the forward discrete cosine transform (DCT) of the Vec and writes the result in the calling vector. If Vec.Length is a power of 2, the function uses an efficient algorithm that is significantly faster than the direct computation of DCT. For other values of Vec Length, this function uses the direct formulas given below; however, the symmetry of cosine function is taken into account, which allows to perform about half of the multiplication operations in the formulas. In the following definition of DCT, N=Vec.Length and V is the calling vector: using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TVec a,b; MtxVec.CreateIt(out a, out b); try { a.SetIt(false,new double[] {1,-2,3,4}); b.DCT(a); } finally { MtxVec.FreeIt(ref a,ref b); } } } *) function DCT(const Vec: TMtxVec; VecIndex, Index, Len: integer): TMtxVec; overload; (*Difference. Calculate the difference for Vec elements [VecIndex]..[VecIndex+Len-1] and store the results in the calling object elements [Index]..[Index+Len-1]. Size and properties of the calling vector must be set explicitly. The following formula is used to calculate the difference: An exception is raised if ConditionCheck is True and array borders are overrun or underrun. *) function Difference(const Vec: TMtxVec; VecIndex, Index, Len: integer; Lag: integer = 1): TMtxVec; overload; (*Vector division. Divide each of Vec elements with corresponding elements in the calling object. Size and property of the calling object are set automatically. The result is stored in the calling object. The threshold parameter is used to prevent against division by zero and numerical instabilities in the follow on processing. All values of Vec smaller than Threshold will be replaced with Threshold. *) function Divide(const Vec: TMtxVec; const Threshold: double): TMtxVec; overload; (*Divide each of Vec elements with corresponding elements in the calling object. Store the result in the calling object. Size and property of the calling object are set automatically. *) function Divide(const Vec: TMtxVec; const Threshold: double; VecIndex, Index, Len: integer): TMtxVec; overload; (*Divide each of Vec1 elements with corresponding elements in the Vec2 object. Store the result in the calling vector. *) function Divide(const Vec1, Vec2: TMtxVec; const Threshold: double): TMtxVec; overload; (*Divide Vec1 elements [Vec1Index]...[Vec1Index+Len-1] with corresponding elements [Vec2Index]...[Vec2Index+Len-1] from the Vec object. Store the result in the calling vector [Index]...[Index+Len-1]. *) function Divide(const Vec1, Vec2: TMtxVec; const Threshold: double; Vec1Index, Vec2Index, Index, Len: integer): TMtxVec; overload; (*Divide each of Num elements with corresponding elements in Den. Size and property of the calling object are set automatically. The result is stored in the calling object. The result of division by zero will be the INF constant. Division of zero by zero will result in NAN. *) function Divide(const Num, Den: TMtxVec): TMtxVec; overload; (*Divide each of calling vector elements with corresponding elements in the Vec object. Size and property of the calling object are set automatically. The result is stored in the calling object. The result of division by zero will be the INF constant. Division of zero by zero will result in NAN. *) function Divide(const Vec: TMtxVec): TMtxVec; overload; (*Divide calling vector elements [Index]...[Index+Len-1] with corresponding elements [VecIndex]...[VecIndex+Len-1] from the Vec object. Store the result in the claling vector. The of the calling vector is not changed. An exception is raised if ConditionCheck is True and array borders are overrun or underrun. The result of division by zero will be the INF constant. Division of zero by zero will result in NAN. *) function Divide(const Vec: TMtxVec; VecIndex, Index, Len: integer): TMtxVec; overload; (*Divide [NumIndex]..[NumIndex+Len-1] Num elements with [DenIndex]..[DenIndex+Len-1] elements in Den. and store result in the calling vector at positions [Index]..[Index+Len-1] and property of the calling object are not changed. An exception is raised if ConditionCheck is True and array borders are overrun or underrun. The result of division by zero will be the INF constant. Division of zero by zero will result in NAN. *) function Divide(const Num, Den: TMtxVec; NumIndex, DenIndex, Index, Len: integer): TMtxVec; overload; (*Divide Value with elements of the calling object and store the result in the calling object.*) function DivideBy(const Value: double): TMtxVec; overload; (*Divide complex Value with elements of the calling object. Store the result in the calling object. Calling vector will be extended to complex, if the calling vector is real. *) function DivideBy(const Value: TCplx): TMtxVec; overload; (*Divide Value with elements [Index]...[Index+Len-1] from the calling object. Store the result in the calling object at position [Index]...[Index+Len-1]. An exception will be raised if ConditionCheck is True and array borders are overrun or underrun. *) function DivideBy(const Value: double; Index, Len: integer): TMtxVec; overload; (*Divide complex Value with elements [Index]...[Index+Len-1] from the calling object. Store the result in the calling object at position [Index]...[Index+Len-1]. Calling vector will be extended to complex, if the calling vector is real. An exception will be raised if ConditionCheck is True and array borders are overrun or underrun. *) function DivideBy(const Value: TCplx; Index, Len: integer): TMtxVec; overload; (*Divide Value with elements from Vec and store the result in the corresponding elements of the calling object. Size and properties of the calling object are set automatically. *) function DivideBy(const Value: double; const Vec: TMtxVec): TMtxVec; overload; (*Divide complex Value with elements from Vec and store the result in the corresponding elements of the calling object. Size of the calling object is set automatically. property of the calling object is set to True. *) function DivideBy(const Value: TCplx; const Vec: TMtxVec): TMtxVec; overload; (*Divide Value with Vec elements [VecIndex]..[VecIndes+Len-1]. Store the result in the elements [Index]..[Index+Len-1] of the calling object. Size of the calling object is not changed. An exception will be raised if ConditionCheck is True and array borders are overrun or underrun. property of the calling object is set implicitly. *) function DivideBy(const Value: double; const Vec: TMtxVec; VecIndex, Index, Len: integer): TMtxVec; overload; (*Divide complex Value with elements [VecIndex]..[VecIndes+Len-1] from Vec. Store the result in the elements [Index]..[Index+Len-1] of the calling object. Size of the calling object is not changed. An exception will be raised if ConditionCheck is True and array borders are overrun or underrun. property of the calling object is set to True. *) function DivideBy(const Value: TCplx; const Vec: TMtxVec; VecIndex, Index, Len: integer): TMtxVec; overload; (*Same as the method.*) function DivideVec(const Num, Den: TMtxVec): TMtxVec; overload; deprecated; (*Same as the method.*) function DivideVec(const Vec: TMtxVec): TMtxVec; overload; deprecated; (*Same as the method.*) function DivideVec(const Vec: TMtxVec; VecIndex, Index, Len: integer): TMtxVec; overload; deprecated; (*Scalar product of two real arrays. 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: Both objects must be of equal size. If they are not, the method will return the dot product of the largest sub-array. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TVec a,b; MtxVec.CreateIt(out a, out b); try { a.SetIt(false, new double[] {1,2,3,4}); b.SetIt(false, new double[] {5,6,7,8}); double prod = a.DotProd(b); // = 1*5 + 2*6 + * 3*7 + 4*8 } finally { MtxVec.FreeIt(ref a,ref b); } } } *) function DotProd(const Vec: TMtxVec): double; overload; (*Returns the scalar product between Vec elements [VecIndex]..[VecIndex+Len-1] and calling object elements [Index]..[Index+Len-1]. An exception is raised if Vec and calling object property is True. An exception is raised if ConditionCheck is True and array borders are overrun or underrun. *) function DotProd(const Vec: TMtxVec; VecIndex, Index, Len: integer): double; overload; (*Scalar product of two complex arrays. Calculates the dot product (scalar value) of the calling object and Vec object and returns a complex scalar value. An exception is raised if calling or Vec object property is false. The dot product is defined by the equation: Both objects must be of equal size. If they are not, the method will return the dot product of the largest sub-array. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TVec a,b; MtxVec.CreateIt(out a, out b); try { a.SetIt(false, new double[] {1,2,3,4}); b.SetIt(false, new double[] {5,6,7,8}); double prod = a.DotProdc(b); //= (1+2i)*(5+6i)+(3+4i)*(7+8i) } finally { MtxVec.FreeIt(ref a,ref b); } } } *) function DotProdc(const Vec: TMtxVec): TCplx; overload; (*Returns the scalar product between Vec (complex) elements [VecIndex]..[VecIndex+Len-1] and calling object (complex) elements [Index]..[Index+Len-1]. An exception is raised if Vec and calling object property is False. An exception is raised if ConditionCheck is True and array borders are overrun or underrun. *) function DotProdc(const Vec: TMtxVec; VecIndex, Index, Len: integer): TCplx; overload; (*Returns the scalar product between Vec and calling object complex elements. If ConjVec is True, scalar product between calling object and conjugated Vec object elements is calculated. An exception is raised if Vec and calling object property is False. *) function DotProdc(const Vec: TMtxVec; ConjVec: boolean): TCplx; overload; (*Returns the scalar product between Vec (complex) elements [VecIndex]..[VecIndex+Len-1] and calling object (complex) elements [Index]..[Index+Len-1]. If ConjVec is True, scalar product between calling object and conjugated Vec object elements is calculated. An exception is raised if Vec and calling object property is False. An exception is raised if ConditionCheck is True and array borders are overrun or underrun. *) function DotProdc(const Vec: TMtxVec; ConjVec: boolean; VecIndex, Index, Len: integer): TCplx; overload; (*Downsamples object values. Copy only every Factor sample from Src starting at SrcIndex up to Len to the calling object starting at Index. The phase parameter determines the initial sample offset. Phase must be less then Factor. Size and properties of the calling object are set implicitly. An exception is raised if array borders are overrun/underrun. *) function DownSample(const Src: TMtxVec; Factor, SrcIndex, Index, Len: integer; Phase: integer = 0): TMtxVec; overload; (*Fast Furier Transformation (FFT) from complex to complex or from real to complex. Calculate the FFT from Vec elements [VecIndex]..[VecIndex+Len-1] and store the results in the calling object elements [Index]..[Index+Len-1]. The Len parameter must be a power of two. Size and properties of the calling object must be set explicitly. An exception is raised if ConditionCheck is True and array borders are overrun. If Vec is complex, then complex to complex forward FFT is performed. If Vec is real, then real to complex forward FFT is performed. This is the indexed version of the FFT routine . Look there for more information on FFT parameters and storage requirements. *) function FFT(const Vec: TMtxVec; ConjugateExtend: boolean; VecIndex, Index, Len: integer): TMtxVec; overload; (*The forward Fast Fourier Transformation (FFT) from real to complex. Calculate the FFT from real Vec elements [VecIndex]..[VecIndex+Len-1] and store the results in the calling object elements [Index]..[Index+Len-1]. The Len parameter must not be a power of two. Size and properties of the calling object must be set explicitly. An exception is raised if ConditionCheck is True and Vec is not complex or if array borders are overrun. This is the indexed version of the FFT routine . Look there for more information on FFT parameters and storage requirements. *) function FFTFromReal(const Vec: TMtxVec; VecIndex, Index, Len: integer): TMtxVec; overload; (*The inverse discrete cosine transform (DCT). Calculate the inverse discrete cosine transform (DCT) from Vec elements [VecIndex]..[VecIndex+Len-1] and store the results in the calling object elements [Index]..[Index+Len-1]. The Len parameter must be the power of two. Size and properties of the calling vector must be set explicitly. An exception is raised if ConditionCheck is True and array borders are overrun. *) function IDCT(const Vec: TMtxVec; VecIndex, Index, Len: integer): TMtxVec; overload; (*The inverse FFT from complex to complex. Calculate the inverse FFT from Vec elements [VecIndex]..[VecIndex+Len-1] and store the results in the calling object elements [Index]..[Index+Len-1]. The Len parameter must be the power of two. Size and properties of the calling vector must be set explicitly. An exception is raised if ConditionCheck is True and array borders are overrun. This is the indexed version of the FFT routine . Look there For more information on FFT parameters and storage requirements. *) function IFFT(const Vec: TMtxVec; VecIndex, Index, Len: integer; NoScale: boolean=False): TMtxVec; overload; (*The inverse FFT from complex to real. Calculate the inverse FFT from Vec elements [VecIndex]..[VecIndex+Len-1] and store the results in the calling object elements [Index]..[Index+Len-1]. The Len parameter must not be a power of two. Size and properties of the calling object must be set explicitly. An exception is raised if ConditionCheck is True and array borders are overrun. This is the indexed version of the FFT routine . Look there for more information on FFT parameters and storage requirements. *) function IFFTToReal(const Vec: TMtxVec; VecIndex, Index, Len: integer; NoScale: boolean=False): TMtxVec; overload; (*The Kurtosis (fourth central momentum). Calculate the calling object kurtosis by using mean value AMean and standard deviation AStdDev. Kurtosis is the fourth central moment, divided by fourth power of standard deviation: *) function Kurtosis(const AMean, AStdDev: double): double; overload; (*Calculate the kurtosis for elements [Index]..[Index+Len-1]. An exception is raised if ConditionCheck is True and array borders are overrun. The AMean and AStdDev passed as parameters must be computed from the same elements (Index, Len) as the Kurtosis itself. *) function Kurtosis(const AMean, AStdDev: double; Index, Len: integer): double; overload; (*Median. Calculate median value for all calling object elements. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TVec a; MtxVec.CreateIt(out a); try { a.SetIt(false, new double[] {1,2,3,4,5}); double c = a.Median(); // 3.0 } finally { MtxVec.FreeIt(ref a); } } } *) function Median: double; overload; (*Calculate median value for calling vector elements [Index]..[Index+Len-1]. An exception is raised if ConditionCheck is true and array borders are overrun. *) function Median(Index: integer; Len: integer): double; overload; (*Vector multiplication. Multiply each of Vec elements with corresponding elements in the calling object. Size and property of the calling object are set automatically. The result is stored in the calling object. *) function Mul(const Vec: TMtxVec): TMtxVec; overload; (*Multiply Vec elements [VecIndex]..[VecIndex+Len-1] with calling object elements [Index]..[Index+Len-1] in-place. An exception is raised if Vec and calling object property do not match or if array borders are overrun/underrun. *) function Mul(const Vec: TMtxVec; VecIndex, Index, Len: integer): TMtxVec; overload; (*Multiply all Vec1 elements with corresponding Vec2 elements. Store the results in calling object. Size and property of calling object are adjusted automatically to match those of Vec1 and Vec2. An exception is raised if Vec1 and Vec2 size and property do not match. *) function Mul(const Vec1, Vec2: TMtxVec): TMtxVec; overload; (*Multiply Vec1 elements [Vec1Index]..[Vec1Index+Len-1] with Vec2 object elements [Vec2Index]..[Vec2Index+Len-1]. Store the results in calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if ConditionCheck is True and array borders are overrun or underrun. *) function Mul(const Vec1, Vec2: TMtxVec; Vec1Index, Vec2Index, Index, Len: integer): TMtxVec; overload; (*Vectorised maximum. Compares Vec values with corresponding elements in the calling object and stores the bigger value in Self. Size and property of the calling object are set automatically. Supports real value data only. *) function MaxEvery(const Vec: TMtxVec): TMtxVec; overload; (*Compare Vec elements [VecIndex]..[VecIndex+Len-1] with calling object elements [Index]..[Index+Len-1] and store result in Self. An exception is raised if Vec and calling object property do not match or if array borders are overrun/underrun. Supports real value data only. *) function MaxEvery(const Vec: TMtxVec; VecIndex, Index, Len: integer): TMtxVec; overload; (*Compare all Vec1 elements with corresponding Vec2 elements and store bigger value in Self. Stores the results in to the calling object. Size and property of calling object are adjusted automatically to match those of Vec1 and Vec2. An exception is raised if Vec1 and Vec2 size and property do not match. Supports real value data only. *) function MaxEvery(const Vec1, Vec2: TMtxVec): TMtxVec; overload; (*Compare Vec1 elements [Vec1Index]..[Vec1Index+Len-1] with Vec2 object elements [Vec2Index]..[Vec2Index+Len-1] and store bigger value in Self. Stores the results in to the calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if ConditionCheck is True and array borders are overrun or underrun. *) function MaxEvery(const Vec1, Vec2: TMtxVec; Vec1Index, Vec2Index, Index, Len: integer): TMtxVec; overload; (*Vectorised minimum. Compares Vec values with corresponding elements in the calling object and stores the smaller value in Self. Size and property of the calling object are set automatically. Supports real value data only. *) function MinEvery(const Vec: TMtxVec): TMtxVec; overload; (*Compare Vec elements [VecIndex]..[VecIndex+Len-1] with calling object elements [Index]..[Index+Len-1] and store result in Self. An exception is raised if Vec and calling object property do not match or if array borders are overrun/underrun. Supports real value data only. *) function MinEvery(const Vec: TMtxVec; VecIndex, Index, Len: integer): TMtxVec; overload; (*Compare all Vec1 elements with corresponding Vec2 elements and store the smaller value in Self. Stores the results in to the calling object. Size and property of calling object are adjusted automatically to match those of Vec1 and Vec2. An exception is raised if Vec1 and Vec2 size and property do not match. Supports real value data only. *) function MinEvery(const Vec1, Vec2: TMtxVec): TMtxVec; overload; (*Compare Vec1 elements [Vec1Index]..[Vec1Index+Len-1] with Vec2 object elements [Vec2Index]..[Vec2Index+Len-1] and store the smaller value in Self. Stores the results in to the calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if ConditionCheck is True and array borders are overrun or underrun. *) function MinEvery(const Vec1, Vec2: TMtxVec; Vec1Index, Vec2Index, Index, Len: integer): TMtxVec; overload; (*Maximum value. the maximum value of all calling object elements. The result is a real value. An exception is raised is calling object is true. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TVec a; MtxVec.CreateIt(out a); try { a.SetIt(false, new double[] {1,2,3,4}); double b = a.Max(); // 4.0 } finally { MtxVec.FreeIt(ref a); } } } *) function Max: double; overload; (*Returns the maximum value from calling object elements [Index]..[Index+Len-1]. The result is a real value. An exception is raised if calling object property is true or array borders are overrun. *) function Max(Index,Len: integer): double; overload; (*Calculate the maximum value from calling object elements [Index]..[Index+Len-1]. The result AMean is a real value. An exception is raised if calling object property is true or array borders are overrun. *) procedure Max(out AMax: double; Index,Len: integer); overload; (*Calculate the maximum value of all calling object elements. The AMax parameter returns the maximum value. The aIndex parameter returns the index of maximum value. An exception is raised if calling object property is true. *) procedure Max(out AMax: double; out aIndex: integer); overload; (*Calculate the maximum value of calling object elements [Index]..[Index+Len-1]. The AMax parameter returns the maximum value. The aIndex parameter returns the index of maximum value. An exception is raised if calling object property is true or array borders are overrud/underrun. *) procedure Max(out AMax: double; out aIndex: integer; Index, Len: integer); overload; (*Same as method.*) function Max(out AMax: TCplx; Index, Len: integer): integer; overload; deprecated; (*Maximum value. the maximum value of all calling object complex elements. Complex elements are first compared by the amplitude and then by the argument. An exception is raised if calling object is False. *) function Maxc: TCplx; overload; (*Returns the maximum value of calling object complex elements [Index]..[Index+Len-1]. The result is a complex value. Complex elements are first compared by the amplitude and then by the argument. An exception is raised if calling object property is False or array borders are overrud/underrun. *) function Maxc(Index,Len: integer): TCplx; overload; (*Calculate the maximum value of calling object complex elements [Index]..[Index+Len-1]. The AMax parameter returns complex maximum value. Returns the index of maximum value. Complex elements are first compared by the amplitude and then by the argument. The aIndex parameter returns the index of maximum value. An exception is raised if calling object property is False or array borders are overrud/underrun. *) function Maxc(out AMax: TCplx; Index, Len: integer): integer; overload; (*Maximum and minimum value in a single pass. Calculates the maximum and minimum value of all calling object elements in a single pass. Maximum value is stored in AMax parameter, minimum value is stored in AMin parameter. Use this method if you require minimum AND maximum value. *) procedure MaxMin(out AMax,AMin: double); overload; (*Calculates the maximum and minimum value of calling object elements [Index]..[Index+Len-1]. Maximum value is stored in AMax parameter, minimum value is stored in AMin parameter. An exception is raised if calling object property is true or array borders are overrud/underrun. *) procedure MaxMin(out AMax,AMin: double; Index, Len: integer); overload; (*Calculates the maximum and minimum value of all calling object elements. Maximum value is returned in AMax parameter, minimum value in AMin parameter. The MaxIdx parameter returns the index of maximum value. The MinIdx parameter returns the index of minimum value. An exception is raised if calling object property is true. *) procedure MaxMin(out AMax: double; out MaxIdx: integer; out AMin: double; out MinIdx: integer); overload; (*Calculates the maximum and minimum value of calling object elements [Index]..[Index+Len-1]. Maximum value is returned in AMax parameter, minimum value in AMin parameter. The MaxIdx parameter returns the index of maximum value. The MinIdx parameter returns the index of minimum value. An exception is raised if calling object property is true or if array borders are overrun/underrun. *) procedure MaxMin(out AMax: double; out MaxIdx: integer; out AMin: double; out MinIdx: integer; Index, Len: integer); overload; (*Mean value. Calculate the mean value of all calling object elements. The result is a real value. An exception is raised if calling object property is true. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TVec a; MtxVec.CreateIt(out a); try { a.SetIt(false, new double[] {1,2,3,4}); double m = a.Mean(); // 2.5 } finally { MtxVec.FreeIt(ref a); } } } *) function Mean: double; overload; (*Returns real mean value from calling object elements [Index]..[Index+Len-1]. An exception is raised if calling object property is true or array borders are overrun. *) function Mean(Index, Len: integer): double; overload; (*Calculate the mean value from calling object elements [Index]..[Index+Len-1]. The result AMean is a real value. An exception is raised if calling object property is true or array borders are overrun/underrun. *) procedure Mean(out AMean: double; Index, Len: integer); overload; (*Same as .*) procedure Mean(out AMean: TCplx); overload; deprecated; (*Same as .*) procedure Mean(out AMean: TCplx; Index, Len: integer); overload; deprecated; (*Mean value. the mean value of all calling object complex elements. The result is a complex value. An exception is raised is calling object is False. *) function Meanc: TCplx; overload; (*Returns complex mean value from calling object complex elements [Index]..[Index+Len-1]. An exception is raised if calling object property is False or array borders are overrun/underrun. *) function Meanc(Index, Len: integer): TCplx; overload; (*Calculate the mean value from all calling object complex elements. The result AMean is a complex value. An exception is raised if calling object property is False. *) procedure Meanc(out AMean: TCplx); overload; (*Calculate the mean value from calling object complex elements [Index]..[Index+Len-1]. The result AMean is a complex value. An exception is raised if calling object property is False or array borders are overrun/underrun. *) procedure Meanc(out AMean: TCplx; Index, Len: integer); overload; (*Minimum value. The minimum value of all calling object elements. The result is a real value. An exception is raised if calling object property is true. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TVec a; MtxVec.CreateIt(out a); try { a.SetIt(false, new double[] {1,2,3,4}); double b = a.Min(); // 1.0 } finally { MtxVec.FreeIt(ref a); } } } *) function Min: double; overload; (*Calculate the minimum value from calling object elements [Index]..[Index+Len-1]. The result is a real value. An exception is raised if calling object property is true or array borders are overrun. *) function Min(Index,Len: integer): double; overload; (*Calculate the minimum value from calling object elements [Index]..[Index+Len-1]. The result AMin is a real value. An exception is raised if calling object property is true or array borders are overrun. *) procedure Min(out AMin: double; Index,Len: integer); overload; (*Calculate the minimum value of calling object elements [Index]..[Index+Len-1]. The AMax parameter returns the minimum value. The aIndex parameter returns the index of minimum value. An exception is raised if calling object property is true or array borders are overrud/underrun. *) procedure Min(out AMin: double; out aIndex: Integer; Index, Len: integer); overload; (*Calculate the minimum value of all calling object elements. The AMin parameter returns the minimum value. The aIndex parameter returns the index of minimum value. An exception is raised if calling object property is true. *) procedure Min(out AMin: double; out aIndex: integer); overload; (*Same as the method.*) function Min(out AMin: TCplx; Index, Len: integer): integer; overload; deprecated; (*Minimum value. Returns the minimum value of all calling object complex elements. Complex elements are first compared by the amplitude and then by the argument. An exception is raised if calling object is False. *) function Minc: TCplx; overload; (*Returns the minimum value of calling object complex elements [Index]..[Index+Len-1]. The result is a complex value. Complex elements are first compared by the amplitude and then by the argument. An exception is raised if calling object. property is False or array borders are overrud/underrun. *) function Minc(Index,Len: integer): TCplx; overload; (*Calculate the minimum value of calling object complex elements [Index]..[Index+Len-1]. The AMin parameter returns complex minimum value. Returns the index of minimum value. Complex elements are first compared by the amplitude and then by the argument. An exception is raised if calling object property is False or array borders are overrun/underrun. *) function Minc(out AMin: TCplx; Index, Len: integer): integer; overload; (*The C-norm. C norm: ||V-Vec||, where V is the calling vector. If the NormC is called without any parameters, the NormC calculates the norm of the calling vector. The C norm of ||V-Vec|| is defined by the formula: If RelativeError is true then the computed norm is divided by the norm of V, and the function returns the "relative error": using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TVec a,b; MtxVec.CreateIt(out a, out b); try { a.SetIt(false, new double[] {1,2,3,4}); a.SetIt(false, new double[] {4,3,2,1}); double c = a.NormC(b,true); } finally { MtxVec.FreeIt(ref a,ref b); } } } *) function NormC(const Vec: TDenseMtxVec; RelativeError: boolean = False): double; overload; (*Calculates the C norm ||V-Vec|| between Vec elements [VecIndex]..[VecIndex+Len-1] and calling vector elements [Index]..[Index+Len-1].*) function NormC(const Vec: TDenseMtxVec; VecIndex,Index,Len: integer; RelativeError: boolean = False): double; overload; (*Calculate the C-norm of calling vector. NormC = max|a[i]|, 0 < i < Length-1 .*) function NormC: double; overload; (*Calculates the C norm from calling vector elements [Index]..[Index+Len-1].*) function NormC(Index,Len: integer): double; overload; (*The L1-norm. L-1 norm, defined by: ||V-Vec||, where V is calling vector. If the NormL1 is called without any parameters, the NormL1 calculates the norm of calling vector. The L1 norm of ||V-Vec|| is defined by the formula: If RelativeError is true then the computed norm is divided by the norm of V, and the function returns the "relative error": using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TVec a,b; MtxVec.CreateIt(out a, out b); try { a.SetIt(false, new double[] {1,2,3,4}); a.SetIt(false, new double[] {4,3,2,1}); double c = a.NormL1(b,true); } finally { MtxVec.FreeIt(ref a,ref b); } } } *) function NormL1(const Vec: TDenseMtxVec; RelativeError: boolean = False): double; overload; (*Calculates the L1 norm ||V-Vec|| between Vec elements [VecIndex]..[VecIndex+Len-1] and calling vector elements [Index]..[Index+Len-1].*) function NormL1(const Vec: TDenseMtxVec; VecIndex,Index,Len: integer; RelativeError: boolean = False): double; overload; (*Calculate the L1-norm of the calling vector. L-1 norm, defined by the following equation: NormL1 = Sum(|a[i]|), 0 < i < Length-1*) function NormL1: double; overload; (*Calculates the L1 norm from calling vector elements [Index]..[Index+Len-1].*) function NormL1(Index,Len: integer): double; overload; (*The L2-norm. L2 norm, defined by ||V-Vec||, where V is calling vector. 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: If RelativeError is true then the computed norm is divided by the norm of V, and the function returns the "relative error": using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TVec a,b; MtxVec.CreateIt(out a, out b); try { a.SetIt(false, new double[] {1,2,3,4}); a.SetIt(false, new double[] {4,3,2,1}); double c = a.NormL2(b,true); } finally { MtxVec.FreeIt(ref a,ref b); } } } *) function NormL2(const Vec: TDenseMtxVec; RelativeError: boolean = False): double; overload; (*Calculates the L2 norm ||V-Vec|| between Vec elements [VecIndex]..[VecIndex+Len-1] and calling vector elements [Index]..[Index+Len-1].*) function NormL2(const Vec: TDenseMtxVec; VecIndex,Index,Len: integer; RelativeError: boolean = False): double; overload; (*Calculate the L2-norm of the calling vector. L2 norm, defined by: NormaL2 = ( Sum(|a[i]|^2) )^0.5 , 0 < i < Length-1 .*) function NormL2: double; overload; (*Calculates the L2 norm from calling vector elements [Index]..[Index+Len-1].*) function NormL2(Index,Len: integer): double; overload; (*Add/Subtract a value. Depreciated Use (Value) instead. *) function Offset(const Value: double): TMtxVec; overload; (*Add/Subtract a complex value.*) function Offset(const Value: TCplx): TMtxVec; overload; (*Add/Subtract a value from [Index]..[Index+Len-1].*) function Offset(const Value: double; Index,Len: integer): TMtxVec; overload; (*Add/Subtract a complex value from [Index]..[Index+Len-1].*) function Offset(const Value: TCplx; Index,Len: integer): TMtxVec; overload; (*Calculate the range from all calling object elements.*) function Range: double; overload; (*Returns real range value from calling object elements [Index]..[Index+Len-1]. An exception is raised if calling object property is true or array borders are overrun. *) function Range(Index, Len: integer): double; overload; (*Calculate the range from calling object elements [Index]..[Index+Len-1]. The result ARange is a real value. An exception is raised if calling object property is true or array borders are overrun/underrun. *) procedure Range(out ARange: double; Index, Len: integer); overload; (*Reverse vector elements. The method reverses Vec vector elements from [VecIndex].. [VecIndex+Len-1] and stores them in the calling vector from [Index]...[Index+Len-1] by using the following equation: This overload reverses calling vector elements in-place. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { MtxVec.CreateIt(out a); try { a.SetIt(false, new double[] {1,2,3,4); a.Reverse(); // a = [4,3,2,1] } finally { MtxVec.FreeIt(ref a); } } } *) function Reverse(const Vec: TMtxVec; VecIndex, Index, Len: integer): TMtxVec; overload; (*Reverses the calling object elements [Index]..[Index+Len-1]. An exception is raised if array borders are overrun. *) function Reverse(Index, Len: integer): TMtxVec; overload; (*A cyclic shift on vector elements in range. Performs cyclic shift on vector elements in specified range [Index..Index+Len]. The number of elements to shift is specified in the Offset parameter. Offset can be any integer number, positive or negative. *) function Rotate(Offset: integer; Index: integer; Len: integer = MtxVecEOA): TMtxVec; overload; (*A cyclic shift on vector elements in range. Performs cyclic shift on source vector elements in specified range [Index..Index+Len] and stores them to calling vector. The number of elements to shift is specified in the Offset parameter. Offset can be any integer number, positive or negative. *) function Rotate(const Vec: TMtxVec; Offset: integer; VecIndex,Index: integer; Len: integer = MtxVecEOA): TMtxVec; overload; (*Shift vector elements in range. Shifts calling vector elements in specified range [Index..Index+Len]. The number of elements by which to shift is specified in the Offset parameter. Offset can be any integer number, positive or negative. *) function Shift(Offset: integer; Index: integer; Len: integer = MtxVecEOA): TMtxVec; overload; (*A shift on vector elements in range. Performs shift on source vector elements in specified range [Index..Index+Len] and stores them to calling vector. The number of elements to shift is specified in the Offset parameter. Offset can be any integer number, positive or negative. *) function Shift(const Vec: TMtxVec; Offset: integer; VecIndex,Index: integer; Len: integer = MtxVecEOA): TMtxVec; overload; (*Subtracts Value from object elements. Subtracts Value from all calling object elements. *) function Sub(const Value: double): TMtxVec; overload; (*Subtracts complex Value from all calling object complex elements.*) function Sub(const Value: TCplx): TMtxVec; overload; (*Subtracts Value from calling object elements [Index]..[Index+Len-1]. An exception is raised if array borders are overrun. *) function Sub(const Value: double; Index, Len: integer): TMtxVec; overload; (*Subtracts complex Value from calling object complex elements [Index]..[Index+Len-1]. An exception is raised if array borders are overrun. *) function Sub(const Value: TCplx; Index, Len: integer): TMtxVec; overload; (*Subtract real Value from Src. Store the results in calling object. Size and property of calling object are adjusted automatically. *) function Sub(const Src: TMtxVec; const Value: double): TMtxVec; overload; (*Subtract complex Value from Src. Store the results in calling object. Size and property of calling object are adjusted automatically. *) function Sub(const Src: TMtxVec; const Value: TCplx): TMtxVec; overload; (*Subtract real Value from Src elements [SrcIndex]..[SrcIndex+Len-1]. Stores the result in calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if ConditionCheck is True and array borders are overrun or underrun. *) function Sub(const Src: TMtxVec; const Value: double; SrcIndex, Index, Len: integer): TMtxVec; overload; (*Subtract complex Value from Src elements [SrcIndex]..[SrcIndex+Len-1]. Stores the result in calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if ConditionCheck is True and array borders are overrun or underrun. *) function Sub(const Src: TMtxVec; const Value: TCplx; SrcIndex, Index, Len: integer): TMtxVec; overload; (*Array subtraction. Subtract each of Vec elements from corresponding elements in the calling object. An exception is raised if Vec and calling object size and properties do not match. *) function Sub(const Vec: TMtxVec): TMtxVec; overload; (*Subtract Vec2 elements from Vec1 elements. Stores the results in calling object. Size and property of calling object are adjusted automatically. An exception is raised if Vec1 and Vec2 size and property do not match. *) function Sub(const Vec1, Vec2: TMtxVec): TMtxVec; overload; (*Subtract Vec elements [VecIndex]..[VecIndex+Len-1] from corresponding calling object elements [Index]..[Index+Len-1]. The results are stored in the calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if ConditionCheck is True and array borders are overrun or underrun. *) function Sub(const Vec: TMtxVec; VecIndex, Index, Len: integer): TMtxVec; overload; (*Subtract Vec22 elements [Vec2Index]..[Vec2Index+Len-1] from Vec1 object elements [Vec1Index]..[Vec1Index+Len-1]. Stores the results in calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if ConditionCheck is True and array borders are overrun or underrun. *) function Sub(const Vec1, Vec2: TMtxVec; Vec1Index, Vec2Index, Index, Len: integer): TMtxVec; overload; (*Subtraction from value. Subtract each of calling object elements from Value. *) function SubFrom(const Value: double): TMtxVec; overload; (*Subtract each of calling object elements from complex Value. If the calling vector s not complex, the conversion is performed automatically in a performance efficient way. *) function SubFrom(const Value: TCplx): TMtxVec; overload; (*Subtract elements [Index]..[Index+Len-1] from Value. Store the result in calling vector. An exception is raised if ConditionCheck is True and array borders are overrun or underrun. *) function SubFrom(const Value: double; Index,Len: integer): TMtxVec; overload; (*Subtract elements [Index]..[Index+Len-1] from complex Value. Store the result in calling object. If the calling vector is not complex, the conversion to complex is performed automatically in performance efficient way. An exception is raised if ConditionCheck is True and array borders are overrun or underrun. *) function SubFrom(const Value: TCplx; Index,Len: integer): TMtxVec; overload; (*Substract Vec elements from Value. Stores the result in the calling object. Size and properties of calling object are adjusted automatically. *) function SubFrom(const Value: double; const Vec: TMtxVec): TMtxVec; overload; (*Substract complex Vec elements from Value. Stores the result in the calling object. Size property of the calling object is set automatically. property of the calling object is set to True. *) function SubFrom(const Value: TCplx; const Vec: TMtxVec): TMtxVec; overload; (*Substract Vec elements [VecIndex]..[VecIndex+Len-1] from Value. Stores the result to the calling object elements [Index]..[Index+Len-1]. Size property of the calling object is not changed. An exception is raised if ConditionCheck is True and array borders are overrun or underrun. property of the calling object is adjusted automatically. *) function SubFrom(const Value: double; const Vec: TMtxVec; VecIndex, Index, Len: integer): TMtxVec; overload; (*Substract Vec elements [VecIndex]..[VecIndex+Len-1] from complex Value and store the result to the calling object elements [Index]..[Index+Len-1]. Size property of the calling object is not changed. An exception is raised if ConditionCheck is True and array borders are overrun or underrun. property of the calling object is set to True. *) function SubFrom(const Value: TCplx; const Vec: TMtxVec; VecIndex, Index, Len: integer): TMtxVec; overload; (*Calculate the Sum of squares of the calling vector. For complex numbers, the routine computes the squared L2 norm. SumOfSquares = Sum(|a[i]|^2) , 0 < i < Length-1. *) function SumOfSquares: double; overload; (*Calculates the sum of squares from the calling vector elements [Index]..[Index+Len-1].*) function SumOfSquares(Index,Len: integer): double; overload; (*Inserts zeroes between consecutive array values. Copy Len values from Src starting at SrcIndex to the calling object starting at position Index and place Factor-1 zeros between consecutive values. Size and properties of the calling object must be set explicitly. Phase parameter defines the initial sample offset and must be less then Factor. An exception is raised, if array borders are overrun/underrun. *) function UpSample(const Src: TMtxVec; Factor,SrcIndex, Index, Len: integer; Phase: integer = 0): TMtxVec; overload; (*Skewness (third central momentum). Calculate the calling object skewness by using mean value AMean and standard deviation AStdDev. Skewness is the third central moment, divided by third power of standard deviation: using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { MtxVec.CreateIt(out a); try { a.SetIt(false, new double[] {1,2,3,4); double d = a.Mean(); double c = a.Skewness(d.a.StdDev(d)); } finally { MtxVec.FreeIt(ref a); } } } *) function Skewness(const AMean, AStdDev: double): double; overload; (*Calculate the skewness for elements [Index]..[Index+Len-1]. An exception is raised if ConditionCheck is True and array borders are overrun. The AMean and AStdDev parameters must be computed from the same elements from which the Skewness is to be computed. *) function Skewness(const AMean, AStdDev: double; Index, Len: integer): double; overload; end; procedure VecFunc (const Src,Dst: TMtxVec; SrcIdx,DstIdx: integer; Len: integer; DoubleFunc: TDoubleFunc; ComplexFunc: TComplexFunc; SingleFunc: TSingleFunc; SComplexFunc: TSComplexFunc); procedure EAbsIsNotAllowedOnComplexSubrange; (* Returns true if A >= B for all elements. *) function GreaterThanOrEqual(const a, b: TMtxVec): boolean; overload; (* Returns true if A <= B for all elements. *) function LessThanOrEqual(const a, b: TMtxVec): boolean; overload; (* Returns true if ALeft < B for all elements. *) function LessThan(const ALeft: TCplx; const a: TMtxVec): Boolean; overload; (* Returns true if A < ARight for all elements. *) function LessThan(const a: TMtxVec; const ARight: TCplx): Boolean; overload; (* Returns true if A < ARight for all elements. *) function LessThan(const a: TMtxVec; const ARight: double): Boolean; overload; (* Returns true if A < ARight for all elements. *) function LessThan(const a, b: TMtxVec): Boolean; overload; (* Returns true if ALeft < A for all elements. *) function LessThan(const ALeft: double; a: TMtxVec): Boolean; overload; (* Returns true if ALeft <= A for all elements. *) function LessThanOrEqual(const ALeft: double; a: TMtxVec): Boolean; overload; (* Returns true if A <= ARight for all elements. *) function LessThanOrEqual(const a: TMtxVec; const ARight: double): Boolean; overload; (* Returns true if A <= ARight for all elements. *) function LessThanOrEqual(const a: TMtxVec; const ARight: TCplx): Boolean; overload; (* Returns true if ALeft <= A for all elements. *) function LessThanOrEqual(const ALeft: TCplx; const a: TMtxVec): Boolean; overload; (* Returns true if ALeft > A for all elements. *) function GreaterThan(const ALeft: TCplx; const a: TMtxVec): Boolean; overload; (* Returns true if A > ARight for all elements. *) function GreaterThan(const a: TMtxVec; const ARight: TCplx): Boolean; overload; (* Returns true if A > ARight for all elements. *) function GreaterThan(const a: TMtxVec; const ARight: double): Boolean; overload; (* Returns true if A > B for all elements. *) function GreaterThan(const a, b: TMtxVec): Boolean; overload; (* Returns true if ALeft > A for all elements. *) function GreaterThan(const ALeft: double; const a: TMtxVec): Boolean; overload; (* Returns true if ALeft >= A for all elements. *) function GreaterThanOrEqual(const ALeft: double; const a: TMtxVec): Boolean; overload; (* Returns true if A >= ARight for all elements. *) function GreaterThanOrEqual(const a: TMtxVec; const ARight: double): Boolean; overload; (* Returns true if A >= ARight for all elements. *) function GreaterThanOrEqual(const a: TMtxVec; const ARight: TCplx): Boolean; overload; (* Returns true if ALeft >= A for all elements. *) function GreaterThanOrEqual(const ALeft: TCplx; const a: TMtxVec): Boolean; overload; procedure FindMask(const Dst: TMtxVecInt; const a: TMtxVec; const op: TMtxCompareOp; const b: TMtxVec); overload; procedure FindMask(const Dst: TMtxVecInt; const a: TMtxVec; const op: TMtxCompareOp; const b: TCplx); overload; procedure FindMask(const Dst: TMtxVecInt; const a: TMtxVec; const op: TMtxCompareOp; const b: double); overload; procedure FindAndSplit(const Dst: TMtxVecInt; const a: TMtxVec; const op: string; const b: TMtxVec; const MaskVec, NotMaskVec: TMtxVec); overload; procedure FindAndSplit(const Dst: TMtxVecInt; const a: TMtxVec; const op: string; const b: double; const MaskVec, NotMaskVec: TMtxVec); overload; procedure FindAndSplit(const Dst: TMtxVecInt; const a: TMtxVec; const op: string; const b: TCplx; const MaskVec, NotMaskVec: TMtxVec); overload; function FindIndexesAndLength(const Dst: TVecInt; const a: TMtxVec; const op: string; const b: TCplx): integer; overload; function FindIndexesAndLength(const Dst: TVecInt; const a: TMtxVec;const op: string; const b: double): integer; overload; function FindIndexesAndLength(const Dst: TVecInt; const a: TMtxVec; const op: string; const b: TMtxVec): integer; overload; function aAbs(const X: double): double; overload; function aAbs(const X: single): single; overload; function aAbs(const X: integer): integer; overload; (*Implements abstract TMtxVecInt object. Implements abstract integer math object TMtxVecInt and supporting routines *) unit AbstractMtxVecInt; {$I BdsppDefs.inc} interface uses Math387, MtxVecBase ,Classes ,SysUtils ; type (* Abstract class for TVecInt and TMtxInt. *) TMtxVecInt = class(TMtxVecBase) protected FIDataOffset: integer; FBDataOffset: integer; FSDataOffset: integer; strict protected SIDataOffset: integer; SBDataOffset: integer; SSDataOffset: integer; SValuesPointer: PointerInteger; SIntPrecision: TIntPrecision; FBitCount: Int64; FScaleFactor: integer; FIntPrecision: TIntPrecision; FIntPrecisionLock: boolean; procedure SubRangeLoadState; override; procedure SetIntPrecision(const Value: TIntPrecision); virtual; procedure SetScaleFactor(const Value: integer); procedure SetIntPrecisionLock(const Value: boolean); function ElemSize: Integer; override; procedure HookPointers; override; procedure ReleaseMemory; override; procedure AllocMemory; override; procedure AllocCacheMemory; override; function Int32CachePointer: TIntegerArray; virtual; function Int16CachePointer: TSmallIntArray; virtual; function Int8CachePointer: Math387.TByteArray; virtual; function Int32CacheOffset: integer; virtual; function Int16CacheOffset: integer; virtual; function Int8CacheOffset: integer; virtual; procedure SetCapacityInElements(const value: Int64); override; function GetCapacityInElements: Int64; override; procedure CopyFromArray(const Src: TIntegerArray; const Dst: TMtxVecBase; const SrcIdx, DstIdx, Len: integer); overload; override; procedure CopyFromArray(const Src: TSmallIntArray; const Dst: TMtxVecBase; const SrcIdx, DstIdx, Len: integer); overload; override; procedure CopyFromArray(const Src: Math387.TWordArray; const Dst: TMtxVecBase; const SrcIdx, DstIdx, Len: integer); overload; procedure CopyFromArray(const Src: Math387.TByteArray; const Dst: TMtxVecBase; const SrcIdx, DstIdx, Len: integer); overload; override; procedure CopyFromArray(const Src: TCplxArray; const Dst: TMtxVecInt; Rounding: TRounding; const SrcIdx, DstIdx, Len: integer); overload; procedure CopyFromArray(const Src: TDoubleArray; const Dst: TMtxVecInt; Rounding: TRounding; const SrcIdx, DstIdx, Len: integer); overload; procedure CopyFromArray(const Src: TSingleArray; const Dst: TMtxVecInt; Rounding: TRounding; const SrcIdx, DstIdx, Len: integer); overload; procedure CopyToArrayInternal(const Src: TMtxVecBase; const Dst: TDoubleArray; const Index,DstIdx,Len: integer); overload; override; procedure CopyToArrayInternal(const Src: TMtxVecBase; const Dst: TSingleArray; const Index,DstIdx,Len: integer); overload; override; procedure CopyToArrayInternal(const Src: TMtxVecBase; const Dst: TIntegerArray; const Index,DstIdx,Len: integer); overload; procedure CopyToArrayInternal(const Src: TMtxVecBase; const Dst: TCplxArray; const Index,DstIdx,Len: integer); overload; procedure CopyToArrayInternal(const Src: TMtxVecBase; const Dst: TSCplxArray; const Index,DstIdx,Len: integer); overload; procedure CopyToArrayInternal(const Src: TMtxVecInt; const Dst: TSmallIntArray; const Index,DstIdx,Len: integer); overload; procedure CopyToArrayInternal(const Src: TMtxVecInt; const Dst: Math387.TWordArray; const Index,DstIdx,Len: integer); overload; procedure CopyToArrayInternal(const Src: TMtxVecInt; const Dst: Math387.TByteArray; const Index,DstIdx,Len: integer); overload; procedure Add(const Src1, Src2, Dst: TMtxVecInt; SrcIndex1, SrcIndex2, Index, Len: integer); overload; procedure Add(const Src, SrcDst: TMtxVecInt; SrcIndex, Index, Len: integer); overload; procedure AddValue(const Src: TMtxVecInt; Value: integer; Dst: TMtxVecInt; SrcIndex, Index, Len: integer); overload; procedure AddValue(const SrcDst: TMtxVecInt; Value, Index, Len: integer); overload; procedure BinaryAnd(const Src, SrcDst: TMtxVecInt; SrcIndex, Index, Len: integer); overload; procedure BinaryAnd(const Src1, Src2, Dst: TMtxVecInt; SrcIndex1, SrcIndex2, Index, Len: integer); overload; procedure BinaryAndValue(const SrcDst: TMtxVecInt; Value, Index, Len: integer); overload; procedure BinaryAndValue(const Src: TMtxVecInt; Value: integer; Dst: TMtxVecInt; SrcIndex, Index, Len: integer); overload; procedure BinaryOr(const Src, SrcDst: TMtxVecInt; SrcIndex, Index, Len: integer); overload; procedure BinaryOr(const Src1, Src2, Dst: TMtxVecInt; SrcIndex1, SrcIndex2, Index, Len: integer); overload; procedure BinaryOrValue(const SrcDst: TMtxVecInt; Value, Index, Len: integer); overload; procedure BinaryOrValue(const Src: TMtxVecInt; Value: integer; Dst: TMtxVecInt; SrcIndex, Index, Len: integer); overload; procedure BinaryXOr(const Src, SrcDst: TMtxVecInt; SrcIndex, Index, Len: integer); overload; procedure BinaryXOr(const Src1, Src2, Dst: TMtxVecInt; SrcIndex1, SrcIndex2, Index, Len: integer); overload; procedure BinaryXOrValue(const SrcDst: TMtxVecInt; Value, Index, Len: integer); overload; procedure BinaryXOrValue(const Src: TMtxVecInt; Value: integer; const Dst: TMtxVecInt; SrcIndex, Index, Len: integer); overload; procedure BinaryNot(const SrcDst: TMtxVecInt; Index, Len: integer); overload; procedure BinaryNot(const Src, Dst: TMtxVecInt; SrcIndex, Index, Len: integer); overload; procedure Abs(const SrcDst: TMtxVecInt; Index, Len: integer); overload; procedure Abs(const Src, Dst: TMtxVecInt; SrcIndex, Index, Len: integer); overload; procedure Subtract(const Src1, Src2, Dst: TMtxVecInt; SrcIndex1, SrcIndex2, Index, Len: integer); overload; procedure Subtract(const Src, SrcDst: TMtxVecInt; SrcIndex, Index, Len: integer); overload; procedure SubtractValue(const Src: TMtxVecInt; Value: integer; Dst: TMtxVecInt; SrcIndex, Index, Len: integer); overload; procedure SubtractValue(const SrcDst: TMtxVecInt; Value, Index, Len: integer); overload; procedure SubtractFromValue(const SrcDst: TMtxVecInt; Value, Index, Len: integer); overload; procedure SubtractFromValue(const Src: TMtxVecInt; Value: integer; Dst: TMtxVecInt; SrcIndex, Index, Len: integer); overload; procedure Multiply(const Src1, Src2, Dst: TMtxVecInt; SrcIndex1, SrcIndex2, Index, Len: integer); overload; procedure Multiply(const Src, SrcDst: TMtxVecInt; SrcIndex, Index, Len: integer); overload; procedure MultiplyValue(const Src: TMtxVecInt; Value: integer; Dst: TMtxVecInt; SrcIndex, Index, Len: integer); overload; procedure MultiplyValue(const SrcDst: TMtxVecInt; Value, Index, Len: integer); overload; procedure Divide(const Src1, Src2, Dst: TMtxVecInt; SrcIndex1, SrcIndex2, Index, Len: integer); overload; procedure Divide(const Src, SrcDst: TMtxVecInt; SrcIndex, Index, Len: integer); overload; procedure DivideValue(const Src: TMtxVecInt; Value: integer; Dst: TMtxVecInt; SrcIndex, Index, Len: integer); overload; procedure DivideValue(const SrcDst: TMtxVecInt; Value, Index, Len: integer); overload; procedure DivideByValue(const Src: TMtxVecInt; Value: integer; Dst: TMtxVecInt; SrcIndex, Index, Len: integer); overload; procedure DivideByValue(const SrcDst: TMtxVecInt; Value, Index, Len: integer); overload; procedure BitShift(const Src: TMtxVecInt; Bits: integer; const Dst: TMtxVecInt; SrcIndex, Index, Len: integer); overload; procedure BitShift(const SrcDst: TMtxVecInt; Bits, Index, Len: integer); overload; procedure Copy(const Src, Dst: TMtxVecInt; SrcIndex, Index, Len: integer); overload; procedure Convert(const Src, Dst: TMtxVecInt; DstPrecision: TIntPrecision; SrcIndex, Index, Len: integer); overload; procedure Max1(var aIndex, aMax: integer; Index, Len: integer); overload; procedure Max1(var aMax: integer; Index, Len: integer); overload; procedure MaxMin1(out maxIndex, minIndex, aMax, aMin: integer; Index, Len: integer); overload; procedure MaxMin1(out aMax, aMin: integer; Index, Len: integer); overload; procedure Min1(var aIndex, aMin: integer; Index, Len: integer); overload; procedure Min1(var aMin: integer; Index, Len: integer); overload; procedure Move1(Offset, Index, Len: integer); overload; procedure Median1(const Src, Dst: TMtxVecInt; MaskSize, SrcIndex, Index, Len: integer); overload; procedure Median1(const SrcDst: TMtxVecInt; MaskSize, Index, Len: integer); overload; procedure Sum(out aSum: integer; Index, Len: integer); overload; procedure SetVal1(Value, Index, Len: integer); overload; procedure SetZero1(Index, Len: integer); overload; procedure SortAscend1(Index, Len: integer); overload; procedure SortAscend1(const SortIdx: TMtxVecInt; SortIdxIndex, Index, Len: integer); overload; procedure SortDescend1(Index, Len: integer); overload; procedure SortDescend1(const SortIdx: TMtxVecInt; SortIdxIndex, Index, Len: integer); overload; strict private function get_First: integer; function get_Last: integer; public IData: TIntegerArray; SData: TSmallIntArray; BData: Math387.TByteArray; (*Allows setting/getting the 32bit integer value at position Indx.*) IValues: Math387.TIntegerArray; IValues1D: Math387.TIntegerArray; (*Allows setting/getting the 16bit integer value at position Indx.*) SValues: Math387.TSmallIntArray; SValues1D: Math387.TSmallIntArray; (*Allows setting/getting the 8bit unsigned integer value at position Indx.*) BValues: Math387.TByteArray; BValues1D: Math387.TByteArray; constructor Create; override; destructor Destroy; override; procedure ValidateParams2 (const X: TMtxVecBase; const XIndex: integer;const Index: integer; var Len: integer); overload; procedure ValidateParams (const X: TMtxVecBase; const XIndex: integer;const Index: integer; var Len: integer); overload; procedure ValidateParams (const X1,X2: TMtxVecBase; const xIndex1,xIndex2,Index: integer; var Len: integer); overload; procedure ValidateParams(const X1, X2, X3: TMtxVecBase; const xIndex1, xIndex2, xIndex3, Index: integer; var Len: integer); overload; function DataIndex(Value: integer; aPrecision: TIntPrecision): integer; overload; function DataIndex(Value: integer): integer; overload; (*Save the list to a stream.*) procedure SaveToStream(const DstStream: TStream); overload; override; (*Load the list from a stream.*) function LoadFromStream(const SrcStream: TStream): Int64; overload; override; (*Absolute values. Calculate the absolute value of all calling object elemets in-place. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TVecInt a; MtxVecInt.CreateIt(out a); try { a.SetIt(new int[] {1,-2,3,4}); a.Abs(); // a = [1,2,3,4] } finally { MtxVec.FreeIt(ref a); } } } *) function Abs(): TMtxVecInt; overload; (*Absolute values of calling object elements [Index]..[Index+Len-1]. calling vector elements [Index]..[Index+Len-1] ansolute vslues. An exception is raised if array borders are overrun/underrun. Note Please note the calling vector elements [Index]..[Index+Len-1] are overwritten with result of routine call. *) function Abs(Index, Len: integer): TMtxVecInt; overload; (*Absolute values of all Src vector elements. Src vector elements ansolute vslues.*) function Abs(const Src: TMtxVecInt): TMtxVecInt; overload; (*Absolute values of Src vector elements [VecIndex]..[VecIndex+Len-1]. Src vector elements [VecIndex]..[VecIndex+Len-1] absolute values in calling vector elements [Index]..[Index+Len-1]. An exception is raised if array borders are overrun/underrun. Note Please note the calling vector elements [Index]..[Index+Len-1] are overwritten with result of routine call. *) function Abs(const Src: TMtxVecInt; SrcIndex, Index, Len: integer): TMtxVecInt; overload; (* Converts Src to packed bit storage. Returns the result of bit packing the Src values [SrcIndex]..[SrcIndex+Len-1] and stored in the calling object bits from [0]..[0+Len-1]. If Len is not divisable with 32, the remaining bits in the last sample are left at 0. The storage precision of the calling object is set to prInt32. The size of the calling object is adjusted automatically. *) function BitPack(const Src: TMtxVecInt; const SrcIndex, Index: integer; Len: integer): TMtxVecInt; overload; (* Converts Src to unpacked bit storage. If bit at Src[i] <> 0 then Integer (32, 16 or 8bit) at index "i" in the calling vector is set to 1. Returns the result of bit unpacking the bits stored in Src values [SrcIndex]..[SrcIndex + Len - 1] and stored in the calling object (Self) values [Index]..[Index+Len-1]. The storage precision of the calling object is preserved. The Len parameter specifies the number of bits that will be unpacked from Src. *) function BitUnpack(const Src: TMtxVecInt; SrcIndex, Index, Len: integer): TMtxVecInt; overload; (*Apply binary "and" between coresponding elements in Src1 and Src2. Returns the result of binary "and" of Src1 values with coresponding Src2 values stored in the calling object. *) function BinaryAnd(const Src1, Src2: TMtxVecInt): TMtxVecInt; overload; (* Apply binary "and" between coresponding elements in Src1 and Src2. the result of binary "and" of Src1 values [SrcIndex1]..[SrcIndex1+Len-1] with coresponding Src2 values [SrcIndex2]..[SrcIndex2+Len-1] stored in the calling object at locations [Index]..[Index+Len-1]. *) function BinaryAnd(const Src1, Src2: TMtxVecInt; SrcIndex1, SrcIndex2, Index, Len: integer): TMtxVecInt; overload; (*Apply binary "and" between coresponding elements in Src and Self. the result of binary "and" of Src values with coresponding values in Self (this).*) function BinaryAnd(const Src: TMtxVecInt): TMtxVecInt; overload; (*Apply binary "and" between coresponding elements in Src and Self. the result of binary "and" of Src values [SrcIndex]...[SrcIndex+Len-1] with coresponding values in Self (this) [Index]..[Index+Len-1].*) function BinaryAnd(const Src: TMtxVecInt; SrcIndex, Index, Len: integer): TMtxVecInt; overload; (*Apply binary "and" between elements in Src and Value. the result of binary "and" of Value with coresponding values in Src [SrcIndex]..[SrcIndex+Len-1] stored in the calling object at locations [Index]..[Index+Len-1].*) function BinaryAnd(const Src: TMtxVecInt; Value, SrcIndex, Index, Len: integer): TMtxVecInt; overload; (*Apply binary "and" between elements in the calling object and Value. the result of binary "and" between Value and values in the calling object.*) function BinaryAnd(Value: integer): TMtxVecInt; overload; (*Apply binary "and" between elements in the calling object and Value. the result of binary "and" between Value and values in the calling object at locations [Index]..[Index+Len-1].*) function BinaryAnd(Value, Index, Len: integer): TMtxVecInt; overload; (*Apply binary "and" between elements in Src and Value. the result of binary "and" of Value with coresponding values in Src stored in the calling object.*) function BinaryAnd(const Src: TMtxVecInt; Value: integer): TMtxVecInt; overload; (*Apply binary "or" between coresponding elements in Src1 and Src2. the result of binary "and" of Src1 values with coresponding Src2 values stored in the calling object.*) function BinaryOr(const Src1, Src2: TMtxVecInt): TMtxVecInt; overload; (* Apply binary "or" between coresponding elements in Src1 and Src2. the result of binary "or" of Src1 values [SrcIndex1]..[SrcIndex1+Len-1] with coresponding Src2 values [SrcIndex2]..[SrcIndex2+Len-1] stored in the calling object at locations [Index]..[Index+Len-1]. *) function BinaryOr(const Src1, Src2: TMtxVecInt; SrcIndex1, SrcIndex2, Index, Len: integer): TMtxVecInt; overload; (*Apply binary "or" between coresponding elements in Src and Self. the result of binary "or" of Src values with coresponding values in Self (this).*) function BinaryOr(const Src: TMtxVecInt): TMtxVecInt; overload; (*Apply binary "or" between coresponding elements in Src and Self. the result of binary "or" of Src values [SrcIndex]...[SrcIndex+Len-1] with coresponding values in Self (this) [Index]..[Index+Len-1].*) function BinaryOr(const Src: TMtxVecInt; SrcIndex, Index, Len: integer): TMtxVecInt; overload; (*Apply binary "or" between elements in Src and Value. the result of binary "or" of Value with coresponding values in Src [SrcIndex]..[SrcIndex+Len-1] stored in the calling object at locations [Index]..[Index+Len-1].*) function BinaryOr(const Src: TMtxVecInt; Value, SrcIndex, Index, Len: integer): TMtxVecInt; overload; (*Apply binary "or" between elements in Src and Value. the result of binary "or" of Value with coresponding values in Src stored in the calling object.*) function BinaryOr(const Src: TMtxVecInt; Value: integer): TMtxVecInt; overload; (*Apply binary "or" between elements in the calling object and Value. the result of binary "or" between Value and values in the calling object at locations [Index]..[Index+Len-1] stored back in the calling object.*) function BinaryOr(Value, Index, Len: integer): TMtxVecInt; overload; (*Apply binary "or" between elements in the calling object and Value. the result of binary "or" between Value and values in the calling object.*) function BinaryOr(Value: integer): TMtxVecInt; overload; (*Apply binary "xor" between elements in the calling object and Value. the result of binary "xor" between Value and values in the calling object.*) function BinaryXor(Value: integer): TMtxVecInt; overload; (*Apply binary "xor" between elements in the calling object and Value. the result of binary "xor" between Value and values in the calling object at locations [Index]..[Index+Len-1] stored back in the calling object.*) function BinaryXor(Value, Index, Len: integer): TMtxVecInt; overload; (*Apply binary "xor" between elements in Src and Value. the result of binary "xor" of Value with coresponding values in Src stored in the calling object.*) function BinaryXor(const Src: TMtxVecInt; Value: integer): TMtxVecInt; overload; (*Apply binary "xor" between elements in Src and Value. the result of binary "xor" of Value with coresponding values in Src [SrcIndex]..[SrcIndex+Len-1] stored in the calling object at locations [Index]..[Index+Len-1].*) function BinaryXor(const Src: TMtxVecInt; Value, SrcIndex, Index, Len: integer): TMtxVecInt; overload; (*Apply binary "xor" between coresponding elements in Src1 and Src2. the result of binary "xor" of Src1 values with coresponding Src2 values stored in the calling object.*) function BinaryXor(const Src1, Src2: TMtxVecInt): TMtxVecInt; overload; (* Apply binary "xor" between coresponding elements in Src1 and Src2. the result of binary "xor" of Src1 values [SrcIndex1]..[SrcIndex1+Len-1] with coresponding Src2 values [SrcIndex2]..[SrcIndex2+Len-1] stored in the calling object at locations [Index]..[Index+Len-1]. *) function BinaryXor(const Src1, Src2: TMtxVecInt; SrcIndex1, SrcIndex2, Index, Len: integer): TMtxVecInt; overload; (*Apply binary "xor" between coresponding elements in Src and Self. the result of binary "xor" of Src values with coresponding values in Self (this).*) function BinaryXor(const Src: TMtxVecInt): TMtxVecInt; overload; (*Apply binary "xor" between coresponding elements in Src and Self. the result of binary "xor" of Src values [SrcIndex]...[SrcIndex+Len-1] with coresponding values in Self (this) [Index]..[Index+Len-1] stored back in the calling object.*) function BinaryXor(const Src: TMtxVecInt; SrcIndex, Index, Len: integer): TMtxVecInt; overload; (*Apply binary shift by number of Bits to the left for all elements in the calling object. the result of binary shift to left by number of Bits applied to values in the calling object and stored back in the calling object.*) function BitShiftLeft(Bits: integer): TMtxVecInt; overload; (*Apply binary shift by number of Bits to the left to elements in the calling object. the result of binary shift to left by number of Bits applied to values [Index]..[Index+Len-1] in the calling object and stored back in the calling object.*) function BitShiftLeft(Bits, Index, Len: integer): TMtxVecInt; overload; (*Apply binary shift by number of Bits to the left to elements in Src. the result of binary shift to left by number of Bits applied to Src values [SrcIndex]..[SrcIndex+Len-1] and stored in the calling object (Self) value [Index]..[Index+Len-1].*) function BitShiftLeft(const Src: TMtxVecInt; Bits: integer; SrcIndex, Index, Len: integer): TMtxVecInt; overload; (*Apply binary shift by number of Bits to the left to elements in Src. the result of binary shift to left by number of Bits applied to Src values and stored in the calling object (Self).*) function BitShiftLeft(const Src: TMtxVecInt; Bits: integer): TMtxVecInt; overload; (*Apply binary shift by number of Bits to the right for all elements in the calling object. the result of binary shift to right by number of Bits applied to values in the calling object and stored back in the calling object. The shift preserves the sign of the numbers.*) function BitShiftRight(Bits: integer): TMtxVecInt; overload; (*Apply binary shift by number of Bits to the right to elements in the calling object. the result of binary shift to right by number of Bits applied to values [Index]..[Index+Len-1] in the calling object and stored back in the calling object. The shift preserves the sign of the numbers. *) function BitShiftRight(Bits, Index, Len: integer): TMtxVecInt; overload; (*Apply binary shift by number of Bits to the right to elements in Src. the result of binary shift to right by number of Bits applied to Src values [SrcIndex]..[SrcIndex+Len-1] and stored in the calling object (Self) value [Index]..[Index+Len-1]. The shift preserves the sign of the numbers. *) function BitShiftRight(const Src: TMtxVecInt; Bits: integer; SrcIndex, Index, Len: integer): TMtxVecInt; overload; (*Apply binary shift by number of Bits to the right to elements in Src. the result of binary shift to right by number of Bits applied to Src values and stored in the calling object (Self). The shift preserves the sign of the numbers. *) function BitShiftRight(const Src: TMtxVecInt; Bits: integer): TMtxVecInt; overload; (*Apply binary shift by number of Bits to the left (positive) or right (negative) for all elements in the calling object. the result of binary shift to the left or right by number of Bits applied to values in the calling object and stored back in the calling object. The shift preserves the sign of the numbers.*) function BitShift(Bits: integer): TMtxVecInt; overload; (*Apply binary shift by number of Bits to the left (positive) or right (negative) to elements in the calling object. the result of binary shift to the left or right by number of Bits applied to values [Index]..[Index+Len-1] in the calling object and stored back in the calling object. The sign of the numbers is preserved when doing right shift. *) function BitShift(Bits, Index, Len: integer): TMtxVecInt; overload; (*Apply binary shift by number of Bits to the left (positive) or right (negative) to elements in Src. the result of binary shift to the left or right by number of Bits applied to Src values [SrcIndex]..[SrcIndex+Len-1] and stored in the calling object (Self) value [Index]..[Index+Len-1]. The sign of the numbers is preserved when doing right shift. *) function BitShift(const Src: TMtxVecInt; Bits: integer; SrcIndex, Index, Len: integer): TMtxVecInt; overload; (*Apply binary shift by number of Bits to the left (positive) or right (negative) to elements in Src. the result of binary shift to the left or right by number of Bits applied to Src values and stored in the calling object (Self). The sign of the numbers is preserved when doing right shift. *) function BitShift(const Src: TMtxVecInt; Bits: integer): TMtxVecInt; overload; (*Applies binary "not" operation to elements stored in the object. Calculate the binary "not" value of all calling object elemets in-place. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TVecInt a; MtxVecInt.CreateIt(out a); try { a.SetIt(new int[] {1,0,1,0}); a.BinaryNot(); // a = [-2,-1,-2,-1] } finally { MtxVec.FreeIt(ref a); } } } *) function BinaryNot(): TMtxVecInt; overload; (*Apply binary "not" to elements stored in Self (this). the result of binary "not" of values stored in Self (this).*) function BinaryNot(Index, Len: integer): TMtxVecInt; overload; (*Apply binary "not" to Src elements and store the result in Self (this). the result of binary "not" of Src values stored in Self (this).*) function BinaryNot(const Src: TMtxVecInt): TMtxVecInt; overload; (*Apply binary "not" to Src elements and store the result in Self (this). the result of binary "not" of Src values [SrcIndex]..[SrcIndex+Len-1] stored in Self (this) values [Index]..[Index+Len-1].*) function BinaryNot(const Src: TMtxVecInt; SrcIndex, Index, Len: integer): TMtxVecInt; overload; (*Applies logical "not" operation to elements stored in the object. Calculate the logical "not" value of all calling object elemets in-place. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TVecInt a; MtxVecInt.CreateIt(out a); try { a.SetIt(new int[] {1,0,1,0}); a.LogicalNot(); // a = [0,1,0,1] } finally { MtxVec.FreeIt(ref a); } } } *) function LogicalNot(): TMtxVecInt; overload; (*Apply logical "not" to elements stored in Self (this). the result of logical "not" of values stored in Self (this).*) function LogicalNot(Index, Len: integer): TMtxVecInt; overload; (*Apply logical "not" to Src elements and store the result in Self (this). the result of logical "not" of Src values stored in Self (this).*) function LogicalNot(const Src: TMtxVecInt): TMtxVecInt; overload; (*Apply logical "not" to Src elements and store the result in Self (this). the result of logical "not" of Src values [SrcIndex]..[SrcIndex+Len-1] stored in Self (this) values [Index]..[Index+Len-1].*) function LogicalNot(const Src: TMtxVecInt; SrcIndex, Index, Len: integer): TMtxVecInt; overload; (*Finds a match for X in object values using binary search. The data in the vector must be sorted in ascending order for this function to work correctly. the index of last matched element. If no matching elements are found, the result is -1.*) function BinarySearch(const X: Integer): Integer; overload; function BinarySearch(const X: Integer; const Index: integer; Len: integer): Integer; overload; (*Finds exact or closest index match for X in object values using binary search. True, if found and the index of the next bigger or smaller value in XIndex, if not found. The data in the vector must be sorted in ascending order for this function to work correctly. The closest match is the index of first bigger or smaller value in the array. To ensure bigger value write: Data := [0,2,3]; Data.BinarySearch(Value, XIndex); if Data[XIndex] > Value then Dec(XIndex); To ensure smaller value write: Data := [0,2,3]; Data.BinarySearch(1, XIndex); if Data[XIndex] < Value then Inc(XIndex); *) function BinarySearch(const X: Integer; var XIndex: integer): boolean; overload; function BinarySearch(const X: Integer; var XIndex: integer; const Index: integer; Len: integer): boolean; overload; (*Returns number of values within the interval. Returns number of values which fullfill condition LowValue < Value[i] < HighValue. *) function CountInRange(const LowValue, HighValue: integer): integer; overload; (*Returns number of values within the interval. Returns number of values which fullfill condition LowValue < Value[i] < HighValue, for i traversing the range [Index]..[Index+Len-1] *) function CountInRange(const LowValue, HighValue: integer; const Index: integer; Len: integer): integer; overload; (*Copies values from a real Src array. The size of the calling object is set implicitely. The precision is preserved. *) function CopyFromArray(const Src: Math387.TWordArray): TMtxVecInt; overload; (*Copies values from a 2 byte unsigned integer type Src array [SrcIndex]..[SrcIndex+Len-1] to the calling object values [Index]..[Index+len-1]. The size of the calling object is not changed. If the array border are overrun an exception will be raised. *) function CopyFromArray(const Src: Math387.TWordArray; SrcIndex, Index, Len: integer): TMtxVecInt; overload; (*Copies values from a real Src array. The size of the calling object is set implicitely. The integer precision of the calling object is preserved. *) function CopyFromArray(const Src: TCplxArray; Rounding: TRounding): TMtxVecInt; overload; (*Copies values from the double precision floating point Src array [SrcIndex]..[SrcIndex+Len-1] to the calling object values [Index]..[Index+2*Len-1]. The size of the calling object is not changed. If the array border are overrun an exception will be raised. *) function CopyFromArray(const Src: TCplxArray; Rounding: TRounding; SrcIndex,Index,Len: integer): TMtxVecInt; overload; (*Copies values from a real Src array. The size of the calling object is set implicitely. The integer precision of the calling object is preserved. *) function CopyFromArray(const Src: TDoubleArray; Rounding: TRounding): TMtxVecInt; overload; (*Copies values from the double precision floating point Src array [SrcIndex]..[SrcIndex+Len-1] to the calling object values [Index]..[Index+len-1]. The size of the calling object is not changed. If the array border are overrun an exception will be raised. *) function CopyFromArray(const Src: TDoubleArray; Rounding: TRounding; SrcIndex,Index,Len: integer): TMtxVecInt; overload; (*Copies values from a real single precision floating point Src array. The size property of the calling object is set implicitely. *) function CopyFromArray(const Src: TSingleArray; Rounding: TRounding): TMtxVecInt; overload; (*Copies values from the single precision floating point Src array [SrcIndex]..[SrcIndex+Len-1] to the calling object values [Index]..[Index+len-1]. The size of the calling object is not changed. If the array border are overrun an exception will be raised. *) function CopyFromArray(const Src: TSingleArray; Rounding: TRounding; SrcIndex,Index,Len: integer): TMtxVecInt; overload; (*Copies values from an integer type Src array. The size property of the calling object is set implicitely. The integer precision of the calling object is preserved. *) function CopyFromArray(const Src: TIntegerArray): TMtxVecInt; overload; (*Copies values from a 4 byte signed integer type Src array [SrcIndex]..[SrcIndex+Len-1]. Store the results to the calling object values [Index]..[Index+len-1]. The size of the calling object is not changed. If the array border are overrun an exception will be raised. *) function CopyFromArray(const Src: TIntegerArray; SrcIndex,Index,Len: integer): TMtxVecInt; overload; (*Copies values from an 2 byte signed integer type Src array. The size property of the calling object is set implicitely. The integer precision of the calling object is preserved. *) function CopyFromArray(const Src: TSmallIntArray): TMtxVecInt; overload; (*Copies values from a 2 byte signed integer type Src array [SrcIndex]..[SrcIndex+Len-1] to the calling object values [Index]..[Index+len-1]. The size of the calling object is not changed. If the array border are overrun an exception will be raised. *) function CopyFromArray(const Src: TSmallIntArray; SrcIndex,Index,Len: integer): TMtxVecInt; overload; (*Copies values from a 1 byte unsigned integer type Src array. The size property of the calling object is set implicitely. *) function CopyFromArray(const Src: Math387.TByteArray): TMtxVecInt; overload; (*Copies values from a 1 byte unsigned integer type Src array [SrcIndex]..[SrcIndex+Len-1] to the calling object values [Index]..[Index+len-1]. The size of the calling object is not changed. If the array border are overrun an exception will be raised. *) function CopyFromArray(const Src: Math387.TByteArray; SrcIndex,Index,Len: integer): TMtxVecInt; overload; (*Copies values from the calling object to the Dst array and converts values to to 2 byte signed integer numbers.*) function CopyToArray(var Dst: TSmallIntArray): TMtxVecInt; overload; (*Copy values from the calling object [Index]..[Index+len-1] to the Dst 2 byte signed integer array at positions [DstIndex]...[DstIndex+Len-1]. The size of the Dst array is not changed. The method converts calling object values to 2 byte signed integers. Values exceeding the range of a 2 byte signed integer type are clipped. *) function CopyToArray(var Dst: TSmallIntArray; DstIndex, Index,Len: integer): TMtxVecInt; overload; (*Sizes the array. Sizes the Dst array so that it can hold all the values stored in the calling object. *) procedure SizeToArray(var Dst: TCplxArray); overload; (*Sizes the array. Sizes the Dst array so that it can hold all the values stored in the calling object. *) procedure SizeToArray(var Dst: TSCplxArray); overload; (*Copies values from the calling object to the Dst array and converts data to complex double precision numbers. Consecutive elements are converted to real and imaginary parts. *) function CopyToArray(var Dst: TCplxArray): TMtxVecInt; overload; (*Copy values from the calling object [Index]..[Index+len-1] to the Dst integer array at positions [DstIndex]...[DstIndex + Len/2 - 1]. The size of the Dst array is not changed. The method converts calling object values to complex double precision floating point values. Consecutive elements become real and imaginary parts. Index and Len apply to the integer source array and DstIndex applies to the destination complex array. *) function CopyToArray(var Dst: TCplxArray; DstIndex, Index,Len: integer): TMtxVecInt; overload; (*Copies values from the calling object to the Dst array and converts data to complex double precision numbers. Consecutive elements are converted to real and imaginary parts. *) function CopyToArray(var Dst: TSCplxArray): TMtxVecInt; overload; (*Copy values from the calling object [Index]..[Index+len-1] to the Dst integer array at positions [DstIndex]...[DstIndex + Len/2 - 1]. The size of the Dst array is not changed. The method converts calling object values to complex double precision floating point values. Consecutive elements become real and imaginary parts. Index and Len apply to the integer source array and DstIndex applies to the destination complex array. *) function CopyToArray(var Dst: TSCplxArray; DstIndex, Index,Len: integer): TMtxVecInt; overload; (*Copies values from the calling object to the Dst array and converts data to 4 byte signed integer numbers.*) function CopyToArray(var Dst: TIntegerArray): TMtxVecInt; overload; (*Copy values from the calling object [Index]..[Index+len-1] to the Dst integer array at positions [DstIndex]...[DstIndex+Len-1]. The size of the Dst array is not changed. The method converts calling object values to 4 byte signed integers. Values exceeding the range of a 4 byte signed integer type are clipped. *) function CopyToArray(var Dst: TIntegerArray; DstIndex, Index,Len: integer): TMtxVecInt; overload; (*Copies values from the calling object to the Dst array and converts data to 2 byte unsigned integer numbers. Values exceeding the range of a 2 byte unsigned integer type are clipped. *) function CopyToArray(var Dst: Math387.TWordArray): TMtxVecInt; overload; (*Copy integer values from the calling object [Index]..[Index+len-1] to the Dst integer array at positions [DstIndex]...[DstIndex+Len-1]. The size of the Dst array is not changed. The method converts calling object values to 2 byte unsigned integers. Values exceeding the range of a 2 byte unsigned integer type are clipped. *) function CopyToArray(var Dst: Math387.TWordArray; DstIndex, Index,Len: integer): TMtxVecInt; overload; (*Copies values from the calling object to the Dst array and converts data to 1 byte unsigned integer numbers. Values exceeding the range of a 1 byte unsigned integer type are clipped. *) function CopyToArray(var Dst: Math387.TByteArray): TMtxVecInt; overload; (*Copy values from the calling object [Index]..[Index+len-1] to the Dst integer array at positions [DstIndex]...[DstIndex+Len-1]. The size of the Dst array is not changed. The method converts calling object values to 1 byte unsigned integers. Values exceeding the range of 1 byte unsigned integer type are clipped. *) function CopyToArray(var Dst: Math387.TByteArray; DstIndex,Index,Len: integer): TMtxVecInt; overload; (*Size the object. Assignes the size of the Src object to the calling object. If the calling object is a TVecInt object then the Src can be of any type, otherwise TMtxInt can only obtain size from a TMtxInt object and TSparseMtx can only obtain size from a TSparseMtx object. If the calling object and Src are of different types and both objects have a matching Length property only the IntPrecision property of the calling object will changed, while all other properties describing the size of the object (rows, cols, length) will be preserved. *) function Size(const Src: TMtxVecBase): TMtxVecInt ; overload; virtual; (*Allows the IntPrecision property of the calling object to become of aPrecision value instead of Src.IntPrecision value. It is also possible to pass the calling object as the Src with a different IntPrecision value. The value of the IntPrecision property can be changed without knowing the actual type of the object. *) function Size(const Src: TMtxVecBase; aPrecision: TIntPrecision): TMtxVecInt ; overload; virtual; (*Cumulative sum. Calculate the cumulative sum for calling object elements [Index]..[Index+Len-1] in-place. An exception is raised if ConditionCheck is true and array borders are overrun. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TVecInt a; MtxVecInt.CreateIt(out a); try { a.SetIt(true,new double[] {1,2,3,4}); a.CumSum(); // a = [1,3,6,10] } finally { MtxVecInt.FreeIt(ref a); } } } *) function CumSum(Index, Len: Integer): TMtxVecInt; overload; (*Calculate the cumulative sum for Vec elements [VecIndex]..[VecIndex+Len-1]. Store the results in calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. Exception is raised if ConditionCheck property is True and array borders are overrun. *) function CumSum(const Vec: TMtxVecInt; VecIndex,Index,Len: Integer): TMtxVecInt; overload; (*Finds a match for X in object values. the index of last matched element. If no matching elements are found, the result is -1. Compare real value X with all calling object elements. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TVecInt a; MtxVecInt.CreateIt(out a); try { a.SetIt(new int[] {2,5,1,6}); int indes = a.Find(1); // returns 2 (the arrays are zero based) } finally { MtxVecInt.FreeIt(ref a); } } } *) function Find(const X: integer): integer; overload; function Find(const X: integer; const Index: integer; Len: integer): integer; overload; (*Add coresponding elements in Src2 to Src1. the result of adding Src2 values from coresponding Src1 values.*) function Add(const Src1, Src2: TMtxVecInt): TMtxVecInt; overload; (*Add coresponding elements in Src2 to Src1. Add Src1 elements [Src1Index..Src1Index+Len-1] to corrresponding Src2 elements [Src2Index..Src12ndex+Len] and store the results in calling vector elements [Index..Index+Len-1]. An exception is raised if array borders are overrun. *) function Add(const Src1, Src2: TMtxVecInt; SrcIndex1, SrcIndex2, Index, Len: integer): TMtxVecInt; overload; (*Add Src elements to calling vector elements.*) function Add(const Src: TMtxVecInt): TMtxVecInt; overload; (*Add Src elements [SrcIndex..SrcIndex+Len-1] to calling vector elements. Add Src elements [SrcIndex..SrcIndex+Len-1] to calling vector elements [Index..Index+Len-1]. An exception is raised if array borders are overrun. *) function Add(const Src: TMtxVecInt; SrcIndex, Index, Len: integer): TMtxVecInt; overload; (*Add integer Value to all Src elements. Add integer Value to all Src elements and store the results in calling vector. Size of calling vector is adjusted automatically. *) function Add(const Src: TMtxVecInt; Value: integer): TMtxVecInt; overload; (*Add integer Value to Src elements [SrcIndex..SrcIndex+Len-1]. Add integer Value to Src elements [SrcIndex..SrcIndex+Len-1] and store the results in calling vector elements [Index..Index+Len-1]. An exception is raised if array borders are overrun. *) function Add(const Src: TMtxVecInt; Value, SrcIndex, Index, Len: integer): TMtxVecInt; overload; (*Add integer value to all calling vector elements.*) function Add(Value: integer): TMtxVecInt; overload; (*Add integer value to calling vector elements [Index..Index+Len-1]. An exception is raised if array borders are overrun. *) function Add(Value, Index, Len: integer): TMtxVecInt; overload; (*Subtract coresponding elements in Src2 from Src1. the result of subtracting Src2 values from coresponding Src1 values.*) function Subtract(const Src1, Src2: TMtxVecInt): TMtxVecInt; overload; (*Add coresponding elements in Src1 from Src1. Subtract Src2 elements [Src2Index..Src2Index+Len-1] from corrresponding Src1 elements [Src1Index..Src1ndex+Len] and store the results in calling vector elements [Index..Index+Len-1]. An exception is raised if array borders are overrun. *) function Subtract(const Src1, Src2: TMtxVecInt; SrcIndex1, SrcIndex2, Index, Len: integer): TMtxVecInt; overload; (*Subtract all Src elements from calling vector elements.*) function Subtract(const Src: TMtxVecInt): TMtxVecInt; overload; (*Subtract Src elements [SrcIndex..SrcIndex+Len-1] from calling vector elements. Subtract Src elements [SrcIndex..SrcIndex+Len-1] from calling vector elements [Index..Index+Len-1]. An exception is raised if array borders are overrun. *) function Subtract(const Src: TMtxVecInt; SrcIndex, Index, Len: integer): TMtxVecInt; overload; (*Subtract integer Value from all Src elements. Subtract integer Value from all Src elements and store the results in calling vector. Size of calling vector is adjusted automatically. *) function Subtract(const Src: TMtxVecInt; Value: integer): TMtxVecInt; overload; (*Subtract integer Value from Src elements [SrcIndex..SrcIndex+Len-1]. Subtract integer Value from Src elements [SrcIndex..SrcIndex+Len-1] and store the results in calling vector elements [Index..Index+Len-1]. An exception is raised if array borders are overrun. *) function Subtract(const Src: TMtxVecInt; Value, SrcIndex, Index, Len: integer): TMtxVecInt; overload; (*Subtract integer value from all calling vector elements.*) function Subtract(Value: integer): TMtxVecInt; overload; (*Subtract integer value from calling vector elements [Index..Index+Len-1]. An exception is raised if array borders are overrun. *) function Subtract(Value, Index, Len: integer): TMtxVecInt; overload; (*Subtract all calling vector elements from integer Value.*) function SubtractFrom(Value: integer): TMtxVecInt; overload; (*Subtract calling vector elements [Index..Index+Len-1] from integer Value. An exception is raised if array borders are overrun. *) function SubtractFrom(Value, Index, Len: integer): TMtxVecInt; overload; (*Subtract all Src vector elements from integer Value. and store thje results in calling vector. Size of calling vector is adjusted automatically. *) function SubtractFrom(Value: integer; const Src: TMtxVecInt): TMtxVecInt; overload; (*Subtract Src vector elements [SrcIndex..SrcIndex+Len-1] from integer Value. and store thje results in calling vector elements [Index..Index+Len-1]. Size of calling vector is adjusted automatically. An exception is raised if array borders are overrun. *) function SubtractFrom(Value: integer; const Src: TMtxVecInt; SrcIndex, Index, Len: integer): TMtxVecInt; overload; (*Multiplies coresponding elements in Src2 with Src1. the result of multipliing Src2 values with coresponding Src1 values.*) function Multiply(const Src1, Src2: TMtxVecInt): TMtxVecInt; overload; (*Multiply coresponding elements in Src2 with Src1. Multiply Src1 elements [Src1Index..Src1Index+Len-1] with corrresponding Src2 elements [Src2Index..Src2ndex+Len] and store the results in calling vector elements [Index..Index+Len-1]. An exception is raised if array borders are overrun. *) function Multiply(const Src1, Src2: TMtxVecInt; SrcIndex1, SrcIndex2,Index, Len: integer): TMtxVecInt; overload; (*Multiply Src elements with calling vector elements.*) function Multiply(const Src: TMtxVecInt): TMtxVecInt; overload; (*Mjultiply Src elements [SrcIndex..SrcIndex+Len-1] with calling vector elements. Multiply Src elements [SrcIndex..SrcIndex+Len-1] with calling vector elements [Index..Index+Len-1]. An exception is raised if array borders are overrun. *) function Multiply(const Src: TMtxVecInt; SrcIndex, Index, Len: integer): TMtxVecInt; overload; (*Multiply integer Value with all Src elements. Multiply integer Value with all Src elements and store the results in calling vector. Size of calling vector is adjusted automatically. *) function Multiply(const Src: TMtxVecInt; Value: integer): TMtxVecInt; overload; (*Multiply integer value with Src vector elements [SrcIndex..SrcIndex+Len-1]. Store the results in calling vector elements [Index..Index+Len-1]. An exception is raised if array borders are overrun. *) function Multiply(const Src: TMtxVecInt; Value, SrcIndex, Index, Len: integer): TMtxVecInt; overload; (*Multiply integer value with all calling vector elements.*) function Multiply(Value: integer): TMtxVecInt; overload; (*Multiply integer value with calling vector elements [Index..Index+Len-1]. An exception is raised if array borders are overrun. *) function Multiply(Value,Index, Len: integer): TMtxVecInt; overload; (*Difference. Calculate the difference for Vec elements [VecIndex]..[VecIndex+Len-1] and store the results in the calling object elements [Index]..[Index+Len-1]. Size and of the calling vector must be set explicitly. The following formula is used to calculate the difference: An exception is raised if ConditionCheck is True and array borders are overrun or underrun. *) function Difference(const Vec: TMtxVecInt; VecIndex, Index, Len: integer; Lag: integer = 1): TMtxVecInt; overload; (*Divides coresponding elements in Src1 with Src2. the result of dividing Src1 values with coresponding Src2 values.*) function Divide(const Src1, Src2: TMtxVecInt): TMtxVecInt; overload; (*Divide coresponding elements in Src1 with Src2. Divide Src2 elements [Src2Index..Src2Index+Len-1] with corrresponding Src1 elements [Src1Index..Src1ndex+Len-1] and store the results in calling vector elements [Index..Index+Len-1]. An exception is raised if array borders are overrun. *) function Divide(const Src1, Src2: TMtxVecInt; SrcIndex1, SrcIndex2, Index, Len: integer): TMtxVecInt; overload; (*Divide calling object elements with Src elements.*) function Divide(const Src: TMtxVecInt): TMtxVecInt; overload; (*Divide calling object elements with Src elements [SrcIndex..SrcIndex+Len-1]. Divide calling object elements [Index..Index+Len-1] with Src elements [SrcIndex..SrcIndex+Len-1]. An exception is raised if array borders are overrun. *) function Divide(const Src: TMtxVecInt; SrcIndex, Index, Len: integer): TMtxVecInt; overload; (*Divide all Src vector elements with integer Value. Size of calling vector is adjusted automatically. *) function Divide(const Src: TMtxVecInt; Value: integer): TMtxVecInt; overload; (*Divide Src vector elements [SrcIndex..SrcIndex+Len-1] with integer Value. Divide Src elements [SrcIndex..SrcIndex+Len-1] with integer Value and store tje results in calling vector elements [Index..Index+Len-1]. An exception is raised if array borders are overrun. *) function Divide(const Src: TMtxVecInt; Value, SrcIndex, Index, Len: integer): TMtxVecInt; overload; (*Divide all calling vector elements with integer value.*) function Divide(Value: integer): TMtxVecInt; overload; (*Divide calling vector elements [Index..Index+Len-1] with integer value. An exception is raised if array borders are overrun. *) function Divide(Value, Index, Len: integer): TMtxVecInt; overload; (*Divide Value with calling vector elements.*) function DivideBy(Value: integer): TMtxVecInt; overload; (*Divide Value with calling vector elements [Index..Index+Len-1]. An exception is raised if array borders are overrun. *) function DivideBy(Value, Index, Len: integer): TMtxVecInt; overload; (*Divide Value with Src vector elements and place result in the calling vector. Size of the calling vector is adjusted automatically. *) function DivideBy(Value: integer; const Src: TMtxVecInt): TMtxVecInt; overload; (*Divide Value with Src vector elements [SrcIndex..SrcIndex+Len-1] and place the result in the calling vector elements [Index..Index+Len-1]. An exception is raised if array borders are overrun. *) function DivideBy(Value: integer; const Src: TMtxVecInt; SrcIndex, Index, Len: integer): TMtxVecInt; overload; (* Compute X + Y*yScale *) function AddScaled(const X, Y: TMtxVecInt; const yScale: integer): TMtxVecInt; overload; (* Compute X + Y*yScale on sub arrays *) function AddScaled(const X: TMtxVecInt; xIndex: integer; const Y: TMtxVecInt; yIndex: integer; const yScale: integer; Index, Len: integer): TMtxVecInt; overload; (* Compute sqr(X + Y*yScale) By making use of yScale, it is also possible to compute the following (at the same or higher speed): (X - Y)^2 = X^2 - 2XY +Y^2 *) function AddScaledSqr(const X, Y: TMtxVecInt; const yScale: integer): TMtxVecInt; overload; (* Compute sqr(X + Y*yScale) on sub arrays *) function AddScaledSqr(const X: TMtxVecInt; xIndex: integer; const Y: TMtxVecInt; yIndex: integer; const yScale: integer; Index, Len: integer): TMtxVecInt; overload; (* Compute sqr(X) + sqr(Y)*yScale By making use of yScale, it is also possible to compute the following (at the same or higher speed): X^2 - Y^2 *) function SqrAddScaled(const X, Y: TMtxVecInt; const yScale: integer): TMtxVecInt; overload; (* Compute sqr(X) + sqr(Y)*yScale on sub arrays *) function SqrAddScaled(const X: TMtxVecInt; xIndex: integer; const Y: TMtxVecInt; yIndex: integer; const yScale: integer; Index, Len: integer): TMtxVecInt; overload; (* Compute X + Y + Z *) function Add(const X, Y, Z: TMtxVecInt): TMtxVecInt; overload; (* Compute X + Y + Z on sub arrays *) function Add(const X: TMtxVecInt; xIndex: integer; const Y: TMtxVecInt; yIndex: integer; const Z: TMtxVecInt; zIndex: integer; Index, Len: integer): TMtxVecInt; overload; (* Compute X + Y + Z*zScale *) function AddScaled(const X, Y, Z: TMtxVecInt; const zScale: integer): TMtxVecInt; overload; (* Compute X + Y + Z*zScale on sub arrays *) function AddScaled(const X: TMtxVecInt; xIndex: integer; const Y: TMtxVecInt; yIndex: integer; const Z: TMtxVecInt; zIndex: integer; const zScale: integer; Index, Len: integer): TMtxVecInt; overload; (* Compute X + Y*yScale + Z*zScale *) function AddScaled(const X, Y: TMtxVecInt; const yScale: integer; const Z: TMtxVecInt; const zScale: integer): TMtxVecInt; overload; (* Compute X + Y*yScale + Z*zScale on sub arrays *) function AddScaled(const X: TMtxVecInt; xIndex: integer; const Y: TMtxVecInt; yIndex: integer; const yScale: integer; const Z: TMtxVecInt; zIndex: integer; const zScale: integer; Index, Len: integer): TMtxVecInt; overload; (* Compute X + Y + zScalar *) function Add(const X, Y: TMtxVecInt; const Z: integer): TMtxVecInt; overload; (* Compute X + Y + zScalar on sub arrays *) function Add(const X: TMtxVecInt; xIndex: integer; const Y: TMtxVecInt; yIndex: integer; const Z: integer; Index, Len: integer): TMtxVecInt; overload; (* Compute X + Y*yScale + zScalar *) function AddScaledC(const X, Y: TMtxVecInt; const yScale: integer; const Z: integer): TMtxVecInt; overload; (* Compute X + Y*yScale + zScalar on sub arrays *) function AddScaledC(const X: TMtxVecInt; xIndex: integer; const Y: TMtxVecInt; yIndex: integer; const yScale: integer; const Z: integer; Index, Len: integer): TMtxVecInt; overload; (* Compute X - Y - Z *) function Sub(const X, Y, Z: TMtxVecInt): TMtxVecInt; overload; (* Compute X - Y - Z on sub array*) function Sub(const X: TMtxVecInt; xIndex: integer; const Y: TMtxVecInt; yIndex: integer;const Z: TMtxVecInt; zIndex: integer; Index, Len: integer): TMtxVecInt; overload; (* Compute X - Y*yScale - Z*zScale *) function SubScaled(const X, Y: TMtxVecInt; const yScale: integer; const Z: TMtxVecInt; const zScale: integer): TMtxVecInt; overload; (* Compute X - Y*yScale - Z*zScale on sub array*) function SubScaled(const X: TMtxVecInt; xIndex: integer; const Y: TMtxVecInt; yIndex: integer; const yScale: integer; const Z: TMtxVecInt; zIndex: integer; const zScale: integer; Index, Len: integer): TMtxVecInt; overload; (* Compute X - Y - Z*zScale *) function SubScaled(const X, Y, Z: TMtxVecInt; const zScale: integer): TMtxVecInt; overload; (* Compute X - Y - Z*zScale on sub array*) function SubScaled(const X: TMtxVecInt; xIndex: integer; const Y: TMtxVecInt; yIndex: integer; const Z: TMtxVecInt; zIndex: integer; const zScale: integer; Index, Len: integer): TMtxVecInt; overload; (* Compute X - Y - zScalar *) function Sub(const X, Y: TMtxVecInt; const Z: integer): TMtxVecInt; overload; (* Compute X - Y - zScalar on sub array*) function Sub(const X: TMtxVecInt; xIndex: integer; const Y: TMtxVecInt; yIndex: integer; const Z: integer; Index, Len: integer): TMtxVecInt; overload; (* Compute X - Y*yScale - zScalar *) function SubScaledC(const X, Y: TMtxVecInt; const yScale: integer; const Z: integer): TMtxVecInt; overload; (* Compute X - Y*yScale - zScalar on sub array*) function SubScaledC(const X: TMtxVecInt; xIndex: integer; const Y: TMtxVecInt; yIndex: integer; const yScale: integer; const Z: integer; Index, Len: integer): TMtxVecInt; overload; (* Compute X * Y / Z *) function MulAndDiv(const X, Y, Z: TMtxVecInt): TMtxVecInt; overload; (* Compute X * Y / Z on sub array*) function MulAndDiv(const X: TMtxVecInt; xIndex: integer; const Y: TMtxVecInt; yIndex: integer; const Z: TMtxVecInt; zIndex: integer; Index, Len: integer): TMtxVecInt; overload; (* Compute (X + Y)*Z *) function AddAndMul(const X, Y, Z: TMtxVecInt): TMtxVecInt; overload; (* Compute (X + Y)*Z on sub array*) function AddAndMul(const X: TMtxVecInt; xIndex: Integer; const Y: TMtxVecInt; yIndex: Integer; const Z: TMtxVecInt; zIndex: Integer; Index, Len: Integer): TMtxVecInt; overload; (* Compute (X + Y)*Z*zScale *) function AddAndMul(const X, Y, Z: TMtxVecInt; zScale: integer): TMtxVecInt; overload; (* Compute (X + Y)*Z*zScale on sub array*) function AddAndMul(const X: TMtxVecInt; xIndex: Integer; const Y: TMtxVecInt; yIndex: Integer; const Z: TMtxVecInt; zIndex: Integer; zScale: integer; Index, Len: Integer): TMtxVecInt; overload; (* Compute (X + Y*yScale)*Z*zScale *) function AddAndMul(const X, Y: TMtxVecInt; yScale: integer; const Z: TMtxVecInt; zScale: integer): TMtxVecInt; overload; (* Compute (X + Y*yScale)*Z*zScale on sub array*) function AddAndMul(const X: TMtxVecInt; xIndex: Integer; const Y: TMtxVecInt; yIndex: Integer; yScale: integer; const Z: TMtxVecInt; zIndex: Integer; zScale: integer; Index, Len: Integer): TMtxVecInt; overload; (* Compute (X + Y)*zScalar *) function AddAndMul(const X, Y: TMtxVecInt; Z: integer): TMtxVecInt; overload; (* Compute (X + Y)*zScalar on sub array*) function AddAndMul(const X: TMtxVecInt; xIndex: Integer; const Y: TMtxVecInt; yIndex: Integer; Z: integer; Index, Len: Integer): TMtxVecInt; overload; (* Compute (X + Y*yScale)*zScalar *) function AddAndMul(const X, Y: TMtxVecInt; yScale, Z: integer): TMtxVecInt; overload; (* Compute (X + Y*yScale)*zScalar on sub array*) function AddAndMul(const X: TMtxVecInt; xIndex: Integer; const Y: TMtxVecInt; yIndex: Integer; yScale, Z: integer; Index, Len: Integer): TMtxVecInt; overload; (* Compute (X + yScalar)*Z*zScale *) function AddAndMul(const X: TMtxVecInt; Y: integer; const Z: TMtxVecInt; zScale: integer): TMtxVecInt; overload; (* Compute (X + yScalar)*Z*zScale on sub-array*) function AddAndMul(const X: TMtxVecInt; xIndex: integer; Y: integer; const Z: TMtxVecInt; zIndex: integer; zScale: integer; Index, Len: integer): TMtxVecInt; overload; (* Compute (X*xScale + yScalar)*Z *) function AddAndMul(const X: TMtxVecInt; xScale, Y: integer; const Z: TMtxVecInt): TMtxVecInt; overload; (* Compute (X*xScale + yScalar)*Z on sub-array*) function AddAndMul(const X: TMtxVecInt; xIndex: integer; xScale, Y : integer; const Z: TMtxVecInt; zIndex: integer; Index, Len: integer): TMtxVecInt; overload; (* Compute (X + yScalar)*Z *) function AddAndMul(const X: TMtxVecInt; Y: integer; const Z: TMtxVecInt): TMtxVecInt; overload; (* Compute (X + yScalar)*Z on sub-array*) function AddAndMul(const X: TMtxVecInt; xIndex: integer; Y: integer; const Z: TMtxVecInt; zIndex: integer; Index, Len: integer): TMtxVecInt; overload; (* Compute (X + yScalar)*zScalar *) function AddAndMul(const X: TMtxVecInt; Y, Z: integer): TMtxVecInt; overload; (* Compute (X + yScalar)*zScalar on sub-array*) function AddAndMul(const X: TMtxVecInt; xIndex: integer; Y, Z: integer; Index, Len: integer): TMtxVecInt; overload; (* Compute (X - Y)*Z *) function SubAndMul(const X, Y, Z: TMtxVecInt): TMtxVecInt; overload; (* Compute (X - Y)*Z on sub array*) function SubAndMul(const X: TMtxVecInt; xIndex: Integer; const Y: TMtxVecInt; yIndex: Integer; const Z: TMtxVecInt; zIndex: Integer; Index, Len: Integer): TMtxVecInt; overload; (* Compute (X - Y)*Z*zScale *) function SubAndMul(const X, Y, Z: TMtxVecInt; zScale: integer): TMtxVecInt; overload; (* Compute (X - Y)*Z*zScale on sub array*) function SubAndMul(const X: TMtxVecInt; xIndex: Integer; const Y: TMtxVecInt; yIndex: Integer; const Z: TMtxVecInt; zIndex: Integer; zScale: integer; Index, Len: Integer): TMtxVecInt; overload; (* Compute (X - Y*yScale)*Z*zScale *) function SubAndMul(const X, Y: TMtxVecInt; yScale: integer; const Z: TMtxVecInt; zScale: integer): TMtxVecInt; overload; (* Compute (X - Y*yScale)*Z*zScale on sub array*) function SubAndMul(const X: TMtxVecInt; xIndex: Integer; const Y: TMtxVecInt; yIndex: Integer; yScale: integer; const Z: TMtxVecInt; zIndex: Integer; zScale: integer; Index, Len: Integer): TMtxVecInt; overload; (* Compute (X - Y)*zScalar *) function SubAndMul(const X, Y: TMtxVecInt; Z: integer): TMtxVecInt; overload; (* Compute (X - Y)*zScalar on sub array*) function SubAndMul(const X: TMtxVecInt; xIndex: Integer; const Y: TMtxVecInt; yIndex: Integer; Z: integer; Index, Len: Integer): TMtxVecInt; overload; (* Compute (X - Y*yScale)*zScalar *) function SubAndMul(const X, Y: TMtxVecInt; yScale, Z: integer): TMtxVecInt; overload; (* Compute (X - Y*yScale)*zScalar on sub array*) function SubAndMul(const X: TMtxVecInt; xIndex: Integer; const Y: TMtxVecInt; yIndex: Integer; yScale, Z: integer; Index, Len: Integer): TMtxVecInt; overload; (* Compute (X - yScalar)*Z*zScale *) function SubAndMul(const X: TMtxVecInt; Y: integer; const Z: TMtxVecInt; zScale: integer): TMtxVecInt; overload; (* Compute (X - yScalar)*Z*zScale on sub-array*) function SubAndMul(const X: TMtxVecInt; xIndex: integer; Y: integer; const Z: TMtxVecInt; zIndex: integer; zScale: integer; Index, Len: integer): TMtxVecInt; overload; (* Compute (X*xScale - yScalar)*Z *) function SubAndMul(const X: TMtxVecInt; xScale, Y: integer; const Z: TMtxVecInt): TMtxVecInt; overload; (* Compute (X*xScale - yScalar)*Z on sub-array*) function SubAndMul(const X: TMtxVecInt; xIndex: integer; xScale, Y : integer; const Z: TMtxVecInt; zIndex: integer; Index, Len: integer): TMtxVecInt; overload; (* Compute (X - yScalar)*Z *) function SubAndMul(const X: TMtxVecInt; Y: integer; const Z: TMtxVecInt): TMtxVecInt; overload; (* Compute (X - yScalar)*Z on sub-array*) function SubAndMul(const X: TMtxVecInt; xIndex: integer; Y: integer; const Z: TMtxVecInt; zIndex: integer; Index, Len: integer): TMtxVecInt; overload; (* Compute (X - yScalar)*zScalar *) function SubAndMul(const X: TMtxVecInt; Y, Z: integer): TMtxVecInt; overload; (* Compute (X - yScalar)*zScalar on sub-array*) function SubAndMul(const X: TMtxVecInt; xIndex: integer; Y, Z: integer; Index, Len: integer): TMtxVecInt; overload; (* Compute X*Y + Z *) function MulAndAdd(const X, Y, Z: TMtxVecInt): TMtxVecInt; overload; (* Compute X*Y + Z on sub array*) function MulAndAdd(const X: TMtxVecInt; xIndex: Integer; const Y: TMtxVecInt; yIndex: Integer; const Z: TMtxVecInt; zIndex: Integer; Index, Len: Integer): TMtxVecInt; overload; (* Compute X*Y*xyScale + Z *) function MulAndAdd(const X, Y: TMtxVecInt; xyScale: integer; const Z: TMtxVecInt): TMtxVecInt; overload; (* Compute X*Y*xyScale + Z on sub array*) function MulAndAdd(const X: TMtxVecInt; xIndex: Integer; const Y: TMtxVecInt; yIndex: Integer; xyScale: integer; const Z: TMtxVecInt; zIndex: Integer; Index, Len: Integer): TMtxVecInt; overload; (* Compute X*Y + Z*zScale *) function MulAndAdd(const X, Y, Z: TMtxVecInt; zScale: integer): TMtxVecInt; overload; (* Compute X*Y + Z*zScale on sub array*) function MulAndAdd(const X: TMtxVecInt; xIndex: Integer; const Y: TMtxVecInt; yIndex: Integer; const Z: TMtxVecInt; zIndex: Integer; zScale: integer; Index, Len: Integer): TMtxVecInt; overload; (* Compute X*Y + zScalar *) function MulAndAdd(const X, Y: TMtxVecInt; Z: integer): TMtxVecInt; overload; (* Compute X*Y + zScalar on sub array*) function MulAndAdd(const X: TMtxVecInt; xIndex: Integer; const Y: TMtxVecInt; yIndex: Integer; Z: integer; Index, Len: Integer): TMtxVecInt; overload; (* Compute X*Y - Z *) function MulAndSub(const X, Y, Z: TMtxVecInt): TMtxVecInt; overload; (* Compute X*Y - Z on sub array*) function MulAndSub(const X: TMtxVecInt; xIndex: Integer; const Y: TMtxVecInt; yIndex: Integer; const Z: TMtxVecInt; zIndex: Integer; Index, Len: Integer): TMtxVecInt; overload; (* Compute X*Y*xyScale - Z *) function MulAndSub(const X, Y: TMtxVecInt; xyScale: integer; const Z: TMtxVecInt): TMtxVecInt; overload; (* Compute X*Y*xyScale + Z on sub array*) function MulAndSub(const X: TMtxVecInt; xIndex: Integer; const Y: TMtxVecInt; yIndex: Integer; xyScale: integer; const Z: TMtxVecInt; zIndex: Integer; Index, Len: Integer): TMtxVecInt; overload; (* Compute X*Y - Z*zScale *) function MulAndSub(const X, Y, Z: TMtxVecInt; zScale: integer): TMtxVecInt; overload; (* Compute X*Y - Z*zScale on sub array*) function MulAndSub(const X: TMtxVecInt; xIndex: Integer; const Y: TMtxVecInt; yIndex: Integer; const Z: TMtxVecInt; zIndex: Integer; zScale: integer; Index, Len: Integer): TMtxVecInt; overload; (* Compute X*Y - zScalar *) function MulAndSub(const X, Y: TMtxVecInt; Z: integer): TMtxVecInt; overload; (* Compute X*Y - zScalar on sub array*) function MulAndSub(const X: TMtxVecInt; xIndex: Integer; const Y: TMtxVecInt; yIndex: Integer; Z: integer; Index, Len: Integer): TMtxVecInt; overload; (* Compute X/Y + Z *) function DivAndAdd(const X, Y, Z: TMtxVecInt): TMtxVecInt; overload; (* Compute X/Y + Z on sub array*) function DivAndAdd(const X: TMtxVecInt; xIndex: Integer; const Y: TMtxVecInt; yIndex: Integer; const Z: TMtxVecInt; zIndex: Integer; Index, Len: Integer): TMtxVecInt; overload; (* Compute X/Y*xyScale + Z *) function DivAndAdd(const X, Y: TMtxVecInt; xyScale: integer; const Z: TMtxVecInt): TMtxVecInt; overload; (* Compute X/Y*xyScale + Z on sub array*) function DivAndAdd(const X: TMtxVecInt; xIndex: Integer; const Y: TMtxVecInt; yIndex: Integer; xyScale: integer; const Z: TMtxVecInt; zIndex: Integer; Index, Len: Integer): TMtxVecInt; overload; (* Compute X/Y + Z*zScale *) function DivAndAdd(const X, Y, Z: TMtxVecInt; zScale: integer): TMtxVecInt; overload; (* Compute X/Y + Z*zScale on sub array*) function DivAndAdd(const X: TMtxVecInt; xIndex: Integer; const Y: TMtxVecInt; yIndex: Integer; const Z: TMtxVecInt; zIndex: Integer; zScale: integer; Index, Len: Integer): TMtxVecInt; overload; (* Compute X/Y + zScalar *) function DivAndAdd(const X, Y: TMtxVecInt; Z: integer): TMtxVecInt; overload; (* Compute X/Y + zScalar on sub array*) function DivAndAdd(const X: TMtxVecInt; xIndex: Integer; const Y: TMtxVecInt; yIndex: Integer; Z: integer; Index, Len: Integer): TMtxVecInt; overload; (* Compute X/Y - Z *) function DivAndSub(const X, Y, Z: TMtxVecInt): TMtxVecInt; overload; (* Compute X/Y - Z on sub array*) function DivAndSub(const X: TMtxVecInt; xIndex: Integer; const Y: TMtxVecInt; yIndex: Integer; const Z: TMtxVecInt; zIndex: Integer; Index, Len: Integer): TMtxVecInt; overload; (* Compute X/Y*xyScale - Z *) function DivAndSub(const X, Y: TMtxVecInt; xyScale: integer; const Z: TMtxVecInt): TMtxVecInt; overload; (* Compute X/Y*xyScale - Z on sub array*) function DivAndSub(const X: TMtxVecInt; xIndex: Integer; const Y: TMtxVecInt; yIndex: Integer; xyScale: integer; const Z: TMtxVecInt; zIndex: Integer; Index, Len: Integer): TMtxVecInt; overload; (* Compute X/Y - Z*zScale *) function DivAndSub(const X, Y, Z: TMtxVecInt; zScale: integer): TMtxVecInt; overload; (* Compute X/Y - Z*zScale on sub array*) function DivAndSub(const X: TMtxVecInt; xIndex: Integer; const Y: TMtxVecInt; yIndex: Integer; const Z: TMtxVecInt; zIndex: Integer; zScale: integer; Index, Len: Integer): TMtxVecInt; overload; (* Compute X/Y - zScalar *) function DivAndSub(const X, Y: TMtxVecInt; Z: integer): TMtxVecInt; overload; (* Compute X/Y - zScalar on sub array*) function DivAndSub(const X: TMtxVecInt; xIndex: Integer; const Y: TMtxVecInt; yIndex: Integer; Z: integer; Index, Len: Integer): TMtxVecInt; overload; (* Compute X*xScale + Y*yScale *) function AddScaled(const X: TMtxVecInt; const xScale: integer; const Y: TMtxVecInt; const yScale: integer): TMtxVecInt; overload; (* Compute X*xScale + Y*yScale on sub arrays *) function AddScaled(const X: TMtxVecInt; xIndex: integer; const xScale: integer; const Y: TMtxVecInt; yIndex: integer; const yScale: integer; Index, Len: integer): TMtxVecInt; overload; (* Compute sqr(X*xScale + Y*yScale) *) function AddScaledSqr(const X: TMtxVecInt; const xScale: integer; const Y: TMtxVecInt; const yScale: integer): TMtxVecInt; overload; (* Compute sqr(X*xScale + Y*yScale) on sub arrays *) function AddScaledSqr(const X: TMtxVecInt; xIndex: integer; const xScale: integer; const Y: TMtxVecInt; yIndex: integer; const yScale: integer; Index, Len: integer): TMtxVecInt; overload; (* Compute sqr(X)*xScale + sqr(Y)*yScale *) function SqrAddScaled(const X: TMtxVecInt; const xScale: integer; const Y: TMtxVecInt; const yScale: integer): TMtxVecInt; overload; (* Compute sqr(X)*xScale + sqr(Y)*yScale on sub arrays *) function SqrAddScaled(const X: TMtxVecInt; xIndex: integer; const xScale: integer; const Y: TMtxVecInt; yIndex: integer; const yScale: integer; Index, Len: integer): TMtxVecInt; overload; (* Compute X*xScale + Y*yScale + Z*zScale *) function AddScaled(const X: TMtxVecInt; const xScale: integer; const Y: TMtxVecInt; const yScale: integer; const Z: TMtxVecInt; const zScale: integer): TMtxVecInt; overload; (* Compute X*xScale + Y*yScale + Z*zScale on sub arrays *) function AddScaled(const X: TMtxVecInt; xIndex: integer; const xScale: integer; const Y: TMtxVecInt; yIndex: integer; const yScale: integer; const Z: TMtxVecInt; zIndex: integer; const zScale: integer; Index, Len: integer): TMtxVecInt; overload; (* Compute X*xScale + Y*yScale + zScalar *) function AddScaledC(const X: TMtxVecInt; const xScale: integer; const Y: TMtxVecInt; const yScale: integer; const Z: integer): TMtxVecInt; overload; (* Compute X*xScale + Y*yScale + z on sub arrays *) function AddScaledC(const X: TMtxVecInt; xIndex: integer; const xScale: integer; const Y: TMtxVecInt; yIndex: integer; const yScale: integer; const Z: integer; Index, Len: integer): TMtxVecInt; overload; (* Compute X*xScale - Y*yScale - Z*zScale *) function SubScaled(const X: TMtxVecInt; const xScale: integer; const Y: TMtxVecInt; const yScale: integer; const Z: TMtxVecInt; const zScale: integer): TMtxVecInt; overload; (* Compute X*xScale - Y*yScale - zScalar *) function SubScaledC(const X: TMtxVecInt; const xScale: integer; const Y: TMtxVecInt; const yScale: integer; const Z: integer): TMtxVecInt; overload; (* Compute X*xScale - Y*yScale - Z*zScale on sub array*) function SubScaled(const X: TMtxVecInt; xIndex: integer; const xScale: integer; const Y: TMtxVecInt; yIndex: integer; const yScale: integer; const Z: TMtxVecInt; zIndex: integer; const zScale: integer; Index, Len: integer): TMtxVecInt; overload; (* Compute X*xScale - Y*yScale - zScalar on sub array*) function SubScaledC(const X: TMtxVecInt; xIndex: integer; const xScale: integer; const Y: TMtxVecInt; yIndex: integer; const yScale: integer; const Z: integer; Index, Len: integer): TMtxVecInt; overload; (* Compute X*Y*Z The following expression would also run at the same or higher speed, when passing X also for the Z parameter: X^2*Y *) function Mul(const X, Y,Z: TMtxVecInt): TMtxVecInt; overload; (* Compute X*Y*zScalar The following expression would also run at the same or higher speed, when passing X also for the Z parameter: X^2*zScalar *) function Mul(const X,Y: TMtxVecInt; const Z: integer): TMtxVecInt; overload; (* Compute X*Y*Z on sub array*) function Mul(const X: TMtxVecInt; xIndex: integer; const Y: TMtxVecInt; yIndex: integer; const Z: TMtxVecInt; zIndex: integer; Index, Len: integer): TMtxVecInt; overload; (* Compute X*Y*zScalar on sub array*) function Mul(const X: TMtxVecInt; xIndex: integer; const Y: TMtxVecInt; yIndex: integer; const Z: integer; Index, Len: integer): TMtxVecInt; overload; (* Compute X / (Y*Z) The following expression would also run at the same or higher speed, when passing Y also for the Z parameter: X / (Y^2) *) function Divide(const X, Y, Z: TMtxVecInt): TMtxVecInt; overload; (* Compute X / (Y*zScale) *) function DivideC(const X, Y: TMtxVecInt; const Z: integer): TMtxVecInt; overload; (* Compute X/( Y*Z ) on sub array*) function Divide(const X: TMtxVecInt; xIndex: integer; const Y: TMtxVecInt; yIndex: integer; const Z: TMtxVecInt; zIndex: integer; Index, Len: integer): TMtxVecInt; overload; (* Compute X / (Y*zScalar) on sub array*) function DivideC(const X: TMtxVecInt; xIndex: integer; const Y: TMtxVecInt; yIndex: integer; const Z: integer; Index, Len: integer): TMtxVecInt; overload; (* Compute X * Y * xyScale / Z The following expression would also run at the same or higher speed, when passing X also for the Y parameter: X^2 * xyScale/ Z *) function MulAndDiv(const X, Y: TMtxVecInt; const xyScale: integer; const Z: TMtxVecInt): TMtxVecInt; overload; (* Compute X * Y / zScalar *) function MulAndDiv(const X, Y: TMtxVecInt; const Z: integer): TMtxVecInt; overload; (* Compute xScalar / (Y*Z) *) function Divide(const X: integer; const Y, Z: TMtxVecInt): TMtxVecInt; overload; (* Compute X * Y xyScale / Z on sub array*) function MulAndDiv(const X: TMtxVecInt; xIndex: integer; const Y: TMtxVecInt; yIndex: integer; const xyScale: integer; const Z: TMtxVecInt; zIndex: integer; Index, Len: integer): TMtxVecInt; overload; (* Compute X * Y / zScalar on sub array*) function MulAndDiv(const X: TMtxVecInt; xIndex: integer; const Y: TMtxVecInt; yIndex: integer; const Z: integer; Index, Len: integer): TMtxVecInt; overload; (* Compute xScalar / (Y*Z) on sub array*) function Divide(const X: integer; const Y: TMtxVecInt; yIndex: integer; const Z: TMtxVecInt; zIndex: integer; Index, Len: integer): TMtxVecInt; overload; (* Compute (X*xScale + Y*yScale)*Z*zScale The following is also possible at the same or higher speed: X^2 * xScale + XY * yScale by passing X also for the Z parameter. *) function AddAndMul(const X: TMtxVecInt; xScale: integer; const Y: TMtxVecInt; yScale: integer; const Z: TMtxVecInt; zScale: integer): TMtxVecInt; overload; (* Compute (X*xScale + Y*yScale)*zScalar*) function AddAndMul(const X: TMtxVecInt; xScale: integer; const Y: TMtxVecInt; yScale: integer; Z: integer): TMtxVecInt; overload; (* Compute (X*xScale + Y*yScale)*Z*Scale on sub array*) function AddAndMul(const X: TMtxVecInt; xIndex: Integer; xScale: integer; const Y: TMtxVecInt; yIndex: Integer; yScale: integer; const Z: TMtxVecInt; zIndex: Integer; zScale: integer; Index, Len: Integer): TMtxVecInt; overload; (* Compute (X*xScale + Y*yScale)*zScalar on sub array*) function AddAndMul(const X: TMtxVecInt; xIndex: Integer; xScale: integer; const Y: TMtxVecInt; yIndex: Integer; yScale: integer; Z: integer; Index, Len: Integer): TMtxVecInt; overload; (* Compute (X*xScale + yScalar)*Z*zScale*) function AddAndMul(const X: TMtxVecInt; xScale: integer; Y: integer; const Z: TMtxVecInt; zScale: integer): TMtxVecInt; overload; (* Compute (X*xScale + yScalar)*zScalar*) function AddAndMul(const X: TMtxVecInt; xScale: integer; Y, Z: integer): TMtxVecInt; overload; (* Compute (X*xScale + yScalar)*Z*zScale on sub-array*) function AddAndMul(const X: TMtxVecInt; xIndex: integer; xScale: integer; Y: integer; const Z: TMtxVecInt; zIndex: integer; zScale: integer; Index, Len: integer): TMtxVecInt; overload; (* Compute (X*xScale + yScalar)*zScalar on sub array*) function AddAndMul(const X: TMtxVecInt; xIndex: integer; xScale: integer; Y, Z: integer; Index, Len: integer): TMtxVecInt; overload; (* Compute (X*xScale - Y*yScale)*Z*zScale*) function SubAndMul(const X: TMtxVecInt; xScale: integer; const Y: TMtxVecInt; yScale: integer; const Z: TMtxVecInt; zScale: integer): TMtxVecInt; overload; (* Compute (X*xScale - Y*yScale)*zScalar*) function SubAndMul(const X: TMtxVecInt; xScale: integer; const Y: TMtxVecInt; yScale: integer; Z: integer): TMtxVecInt; overload; (* Compute (X*xScale - Y*yScale)*Z*Scale on sub array*) function SubAndMul(const X: TMtxVecInt; xIndex: Integer; xScale: integer; const Y: TMtxVecInt; yIndex: Integer; yScale: integer; const Z: TMtxVecInt; zIndex: Integer; zScale: integer; Index, Len: Integer): TMtxVecInt; overload; (* Compute (X*xScale - Y*yScale)*zScalar on sub array*) function SubAndMul(const X: TMtxVecInt; xIndex: Integer; xScale: integer; const Y: TMtxVecInt; yIndex: Integer; yScale: integer; Z: integer; Index, Len: Integer): TMtxVecInt; overload; (* Compute (X*xScale - yScalar)*Z*zScale*) function SubAndMul(const X: TMtxVecInt; xScale: integer; Y: integer; const Z: TMtxVecInt; zScale: integer): TMtxVecInt; overload; (* Compute (X*xScale - yScalar)*zScalar*) function SubAndMul(const X: TMtxVecInt; xScale: integer; Y, Z: integer): TMtxVecInt; overload; (* Compute (X*xScale - yScalar)*Z*zScale on sub-array*) function SubAndMul(const X: TMtxVecInt; xIndex: integer; xScale: integer; Y: integer; const Z: TMtxVecInt; zIndex: integer; zScale: integer; Index, Len: integer): TMtxVecInt; overload; (* Compute (X*xScale - yScalar)*zScalar on sub array*) function SubAndMul(const X: TMtxVecInt; xIndex: integer; xScale: integer; Y, Z: integer; Index, Len: integer): TMtxVecInt; overload; (* Compute (X*Y)*xyScale + Z*zScale The following expression would also run at the same or higher speed, when passing X also for the Y parameter: X^2*xyScale + Z*zScale *) function MulAndAdd(const X: TMtxVecInt; const Y: TMtxVecInt; xyScale: integer; const Z: TMtxVecInt; zScale: integer): TMtxVecInt; overload; (* Compute (X*Y)*xyScale + zScalar*) function MulAndAdd(const X: TMtxVecInt; const Y: TMtxVecInt; xyScale: integer; Z: integer): TMtxVecInt; overload; (* Compute (X*Y)*xyScale + Z*zScale on sub array*) function MulAndAdd(const X: TMtxVecInt; xIndex: Integer; const Y: TMtxVecInt; yIndex: Integer; xyScale: integer; const Z: TMtxVecInt; zIndex: Integer; zScale: integer; Index, Len: Integer): TMtxVecInt; overload; (* Compute (X*Y)*xyScale + zScalar on sub array The following expression would also run at the same or higher speed, when passing X also for the Y parameter: X^2*xyScale + zScale *) function MulAndAdd(const X: TMtxVecInt; xIndex: Integer; const Y: TMtxVecInt; yIndex: Integer; xyScale: integer; Z: integer; Index, Len: Integer): TMtxVecInt; overload; (* Compute (X*yScalar) + zScalar*) function MulAndAdd(const X: TMtxVecInt; Y, Z: integer): TMtxVecInt; overload; (* Compute (X*yScalar) + zScalar*) function MulAndAdd(const X: TMtxVecInt; xIndex: integer; Y, Z: integer; Index, Len: integer): TMtxVecInt; overload; (* Compute (X*Y)*xyScale - Z*zScale*) function MulAndSub(const X: TMtxVecInt; const Y: TMtxVecInt; xyScale: integer; const Z: TMtxVecInt; zScale: integer): TMtxVecInt; overload; (* Compute (X*Y)*xyScale - zScalar*) function MulAndSub(const X: TMtxVecInt; const Y: TMtxVecInt; xyScale, Z: integer): TMtxVecInt; overload; (* Compute (X*Y)*xyScale - Z*zScale on sub array*) function MulAndSub(const X: TMtxVecInt; xIndex: Integer; const Y: TMtxVecInt; yIndex: Integer; xyScale: integer; const Z: TMtxVecInt; zIndex: Integer; zScale: integer; Index, Len: Integer): TMtxVecInt; overload; (* Compute (X*Y)*xyScale - zScalar on sub array*) function MulAndSub(const X: TMtxVecInt; xIndex: Integer; const Y: TMtxVecInt; yIndex: Integer; xyScale: integer; Z: integer; Index, Len: Integer): TMtxVecInt; overload; (* Compute X*yScalar - Z*zScale*) function MulAndSub(const X: TMtxVecInt; Y: integer; const Z: TMtxVecInt; zScale: integer): TMtxVecInt; overload; (* Compute X*yScalar - Z*zScale on sub array*) function MulAndSub(const X: TMtxVecInt; xIndex: integer; Y: integer; const Z: TMtxVecInt; zIndex: integer; zScale: integer; Index, Len: integer): TMtxVecInt; overload; (* Compute (X / Y)*xyScale + Z*zScale The following expression would also run at the same or higher speed, when passing Z also for the Y parameter: (X / Z) * xyScale + Z * zScale *) function DivAndAdd(const X: TMtxVecInt; const Y: TMtxVecInt; xyScale: integer; const Z: TMtxVecInt; zScale: integer): TMtxVecInt; overload; (* Compute (X / Y) * xyScale + zScalar*) function DivAndAdd(const X: TMtxVecInt; const Y: TMtxVecInt; xyScale: integer; Z: integer): TMtxVecInt; overload; (* Compute (X / Y)*xyScale + Z*zScale on sub array*) function DivAndAdd(const X: TMtxVecInt; xIndex: Integer; const Y: TMtxVecInt; yIndex: Integer; xyScale: integer; const Z: TMtxVecInt; zIndex: Integer; zScale: integer; Index, Len: Integer): TMtxVecInt; overload; (* Compute (X / Y) * xyScale + zScalar*) function DivAndAdd(const X: TMtxVecInt; xIndex: Integer; const Y: TMtxVecInt; yIndex: Integer; xyScale: integer; Z: integer; Index, Len: Integer): TMtxVecInt; overload; (* Compute (X / Y) * xyScale - Z y*) function DivAndSub(const X: TMtxVecInt; const Y: TMtxVecInt; xyScale: integer; const Z: TMtxVecInt; zScale: integer): TMtxVecInt; overload; (* Compute (X / Y) * xyScale - zScalar*) function DivAndSub(const X: TMtxVecInt; const Y: TMtxVecInt; xyScale: integer; Z: integer): TMtxVecInt; overload; (* Compute (X / Y) * xyScale - Z on sub array*) function DivAndSub(const X: TMtxVecInt; xIndex: Integer; const Y: TMtxVecInt; yIndex: Integer; xyScale: integer; const Z: TMtxVecInt; zIndex: Integer; zScale: integer; Index, Len: Integer): TMtxVecInt; overload; (* Compute (X / Y) * xyScale - zScalar on sub array*) function DivAndSub(const X: TMtxVecInt; xIndex: Integer; const Y: TMtxVecInt; yIndex: Integer; xyScale: integer; Z: integer; Index, Len: Integer): TMtxVecInt; overload; (*Copy object values. Copy each of Vec elements to the calling object. The Size property of the calling object is set implicitly to match Vec object. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TVecInt a,b,c; a = new TVecInt(); b = new TVecInt(); a.SetIt(new int[] {1,2,3,4}); // a = [1,2,3,4] i.e 1+2i ; 3+4i b.Copy(a); // b = [1,2,3,4] } } *) function Copy(const Src: TMtxVecInt): TMtxVecInt; overload; (*Copy Src elements [SrcIndex]..[SrcIndex+Len-1] in the calling object elements [Index]..[Index+Len-1]. Calling vector must be set explicitly. An exception is raised if array borders are overrun or underrun. *) function Copy(const Src: TMtxVecInt; SrcIndex, Index, Len: integer): TMtxVecInt; overload; (* Copy each of Vec elements to the calling object. The Size property of the calling object is set implicitly to match Vec object. The storage precision of the calling object is set to DstIntPrecision. *) function Convert(const Src: TMtxVecInt; DstIntPrecision: TIntPrecision): TMtxVecInt; overload; (*Copy Src elements [SrcIndex]..[SrcIndex+Len-1] in the calling object elements [Index]..[Index+Len-1]. Calling vector must be set explicitly. An exception is raised if array borders are overrun or underrun. If the precision of the calling does not match DstIntPrecision, an exception will be raised. *) function Convert(const Src: TMtxVecInt; DstIntPrecision: TIntPrecision; SrcIndex, Index, Len: integer): TMtxVecInt; overload; (*Compares Value with all calling object elements.*) function IsEqual(Value: integer): boolean; overload; (*Compares Value with all calling object elements.*) function IsEqual(Value, Index, Len: integer): boolean; overload; (*Compares all Vec elements with calling object elements and checks also Length and IntPrecision properties, if they match.*) function IsEqual(Vec: TMtxVecInt): boolean; overload; (*Compares Vec elements [VecIndex]..[VecIndex+Len-1] with calling object elements [Index]..[Index+Len-1].*) function IsEqual(Vec: TMtxVecInt; VecIndex, Index, Len: integer): boolean; overload; (*First element in object Values array. first integer element in object Values array. *) property First: integer read get_First; (*Last element in object Values array. the last integer element in calling object Values array. *) property Last: integer read get_Last; (*Vectorised maximum. Compares Vec values with corresponding elements in the calling object and stores the bigger value in Self. Size and properties need to match. *) function MaxEvery(const Vec: TMtxVecInt): TMtxVecInt; overload; (*Compare Vec elements [VecIndex]..[VecIndex+Len-1] with calling object elements [Index]..[Index+Len-1] and store result in Self. An exception is raised if Vec and calling object property do not match or if array borders are overrun/underrun. *) function MaxEvery(const Vec: TMtxVecInt; VecIndex, Index, Len: integer): TMtxVecInt; overload; (*Compare all Vec1 elements with corresponding Vec2 elements and store bigger value in Self. Stores the results in to the calling object. Size and property of calling object are adjusted automatically to match those of Vec1 and Vec2. An exception is raised if Vec1 and Vec2 size and property do not match. *) function MaxEvery(const Vec1, Vec2: TMtxVecInt): TMtxVecInt; overload; (*Compare Vec1 elements [Vec1Index]..[Vec1Index+Len-1] with Vec2 object elements [Vec2Index]..[Vec2Index+Len-1] and store bigger value in Self. Stores the results in to the calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if ConditionCheck is True and array borders are overrun or underrun. *) function MaxEvery(const Vec1, Vec2: TMtxVecInt; Vec1Index, Vec2Index, Index, Len: integer): TMtxVecInt; overload; (*Vectorised minimum. Compares Vec values with corresponding elements in the calling object and stores the smaller value in Self. Size and property of the calling object are set automatically. *) function MinEvery(const Vec: TMtxVecInt): TMtxVecInt; overload; (*Compare Vec elements [VecIndex]..[VecIndex+Len-1] with calling object elements [Index]..[Index+Len-1] and store result in Self. An exception is raised, if Vec and calling object property do not match or if array borders are overrun/underrun. *) function MinEvery(const Vec: TMtxVecInt; VecIndex, Index, Len: integer): TMtxVecInt; overload; (*Compare all Vec1 elements with corresponding Vec2 elements and store the smaller value in Self. Stores the results in to the calling object. Size and property of calling object are adjusted automatically to match those of Vec1 and Vec2. An exception is raised if Vec1 and Vec2 size and property do not match. *) function MinEvery(const Vec1, Vec2: TMtxVecInt): TMtxVecInt; overload; (*Compare Vec1 elements [Vec1Index]..[Vec1Index+Len-1] with Vec2 object elements [Vec2Index]..[Vec2Index+Len-1] and store the smaller value in Self. Stores the results in to the calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if ConditionCheck is True and array borders are overrun or underrun. *) function MinEvery(const Vec1, Vec2: TMtxVecInt; Vec1Index, Vec2Index, Index, Len: integer): TMtxVecInt; overload; (*Maximum value. The maximum value of all calling object elements. The result is an integer value. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TVecInt a; MtxVecInt.CreateIt(out a); try { a.SetIt(new int[] {1,2,3,4}); int b = a.Max(); // 4 } finally { MtxVecInt.FreeIt(ref a); } } } *) function Max(): integer; overload; (*Calculate the maximum value from calling object elements [Index]..[Index+Len-1]. The result is an integer value. An exception is raised if array borders are overrun. *) function Max(Index, Len: integer): integer; overload; (*Minimum value. The minimum value of all calling object elements. The result is an integer value. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TVecInt a; MtxVecInt.CreateIt(out a); try { a.SetIt(new int[] {1,2,3,4}); int b = a.Min(); // 1 } finally { MtxVecInt.FreeIt(ref a); } } } *) function Min(): integer; overload; (*Calculate the minimum value from calling object elements [Index]..[Index+Len-1]. The result is an integer value. An exception is raised if array borders are overrun. *) function Min(Index, Len: integer): integer; overload; (*Calculate minimum and maximum in one procedure call. Returns calling vector maximum value. Returns calling vector monimum value.*) procedure MaxMin(out aMax, aMin: integer); overload; (*Calculate minimum and maximum in one procedure call. Returns calling vector elements [Index..Index+Len-1] maximum value. Returns calling vector elements [Index..Index+Len-1] minimum value. The starting index at which to start the search. The number of elements to search starting from Index. An exception is raised if array borders are overrun/underrun. *) procedure MaxMin(out aMax, aMin: integer; Index, Len: integer); overload; (*Calculate the maximum value of all calling object elements. the maximum of all calling vector integer elements in-place. Stores maximum value index. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TVecInt a; int ind; MtxVecInt.CreateIt(out a); try { a.SetIt(new int[] {1,2,3,4) int max = a.Max(out ind); //max=3, ind = 3 } finally { MtxVecInt.FreeIt(ref a); } } } *) function Max(out aIndex: integer): integer; overload; (*Calculate the maximum value of calling object elements [Index..Index+Len-1]. the maximum of calling vector integer elements [Index..Index+Len-1]. Returns maximum value index. The starting index at which to start the search. The number of elements to search starting from Index. An exception is raised if array borders are overrun/underrun. *) function Max(out aIndex: integer; Index, Len: integer): integer; overload; (*Calculate the minimum value of all calling object elements. the minimum of all calling vector integer elements in-place. Stores minimum value index. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TVecInt a; int ind; MtxVecInt.CreateIt(out a); try { a.SetIt(new int[] {1,2,3,4); int min = a.Min(out ind); //min=1, ind = 0 } finally { MtxVecInt.FreeIt(ref a); } } } *) function Min(out aIndex: integer): integer; overload; (*Calculate the maximum value of calling object elements [Index..Index+Len-1]. the minimum of calling vector integer elements [Index..Index+Len-1]. Returns minimum value index. The starting index at which to start the search. The number of elements to search starting from Index. An exception is raised if array borders are overrun/underrun. *) function Min(out aIndex: integer; Index, Len: integer): integer; overload; (*Calculate minimum, maximum and their indices in one procedure call. Returns calling vector maximum value. Returns calling vector maximum value index. Returns calling vector monimum value. Returns calling vector minimum value index.*) procedure MaxMinIdx(out aMax, aMaxIdx, aMin, aMinIdx: integer); overload; (*Calculate minimum, maximum and their indices in one procedure call. Returns calling vector elements [Index..Index+Len-1] maximum value. Returns calling vector maximum value index. Returns calling vector elements [Index..Index+Len-1] minimum value. Returns calling vector minimum value index. The starting index at which to start the search. The number of elements to search starting from Index. An exception is raised if array borders are overrun/underrun. *) procedure MaxMinIdx(out aMax, aMaxIdx, aMin, aMinIdx: integer; Index, Len: integer); overload; (*Applies median filter with size Mask to the calling vector elements [Index.. Index+Len-1]. Median filter is a nonlinear filter which replaces each element of the calling vector with the median value, calculated over the fixed range (mask) centered around that element. *) function Median(MaskSize, Index, Len: integer): TMtxVecInt; overload; (*Applies median filter with size Mask to Src object elements [SrcIndex..SrcIndex+Len-1] and stores the result in the calling vector elements [Index..Index+Len-1]. Median filter is a nonlinear filter which replaces each element of the Src vector with the median value, calculated over the fixed range (mask) centered around that element and stores the result in the calling vector. *) function Median(const Src: TMtxVecInt; MaskSize, SrcIndex, Index, Len: integer): TMtxVecInt; overload; (*Calculate median value for calling vector elements [Index]..[Index+Len-1]. An exception is raised if ConditionCheck is true and array borders are overrun. *) function Median(Index: integer; Len: integer): integer; overload; (*Median. Calculate median value for all calling object elements. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TVecInt a; MtxVecInt.CreateIt(out a); try { a.SetIt(new int[] {1,2,3,4,5}); int c = a.Median(); // 3.0 } finally { MtxVecInt.FreeIt(ref a); } } } *) function Median: integer; overload; (*Fills the calling vector elements [Index]..[Index+Len-1]. Method uses the following rule: Values[k] := Offset + k*Step. An exception is raised if calling vector array borders are overrun. *) function Ramp(Offset,Step: double; Index,Len: integer): TMtxVecInt; overload; (*A cyclic shift on vector elements in range. Performs cyclic shift on vector elements in specified range [Index..Index+Len-1]. The number of elements to shift is specified in the Offset parameter. Offset can be any integer number, positive or negative. An exception is raised if array borders are overrun/underrun. *) function Rotate(Offset, Index, Len: integer): TMtxVecInt; overload; (*A cyclic shift on vector elements in range. Performs cyclic shift on source vector elements in specified range [SrcIndex .. SrcIndex+Len-1] and stores them to calling vector elements [Index .. Index+Len-1]. The number of elements to shift is specified in the Offset parameter. Offset can be any integer number, positive or negative. An exception is raised if array borders are overrun/underrun. *) function Rotate(const Src: TMtxVecInt; Offset, SrcIndex, Index, Len: integer): TMtxVecInt; overload; (*Reverse vector elements. The method reverses Vec vector elements from [VecIndex].. [VecIndex+Len-1] and stores them in the calling vector from [Index]...[Index+Len-1] by using the following equation: This overload reverses calling vector elements in-place. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TVecInt a; MtxVec.CreateIt(out a); try { a.SetIt(new int[] {1,2,3,4); a.Reverse(); // a = [4,3,2,1] } finally { MtxVec.FreeIt(ref a); } } } *) function Reverse(Vec: TMtxVecInt; VecIndex, Index, Len: integer): TMtxVecInt; overload; (*Reverses the calling object elements [Index]..[Index+Len-1]. An exception is raised if array borders are overrun. *) function Reverse(Index, Len: integer): TMtxVecInt; overload; (*Divide all Src elements with Value elements and store result of division in the calling object and reminder in RemDst. Size and properties of the calling object and of RemDst are adjusted automatically. *) function RemDiv(Src, Value: TMtxVecInt; RemDst: TMtxVecInt): TMtxVecInt; overload; (*Divide all Src elements with Value and store result of division in the calling object and reminder in RemDst. Store the result of division in the calling object elements [Index]..[Index+Len-1] and remainder in to [RemDstIndex] .. [RemDstIndex+ Len-1]. Size and properties of the calling object and RemDst must be set explicitly. An exception is raised if ConditionCheck is true and array borders are overrun/underrun. *) function RemDiv(Src, Value: TMtxVecInt; RemDst: TMtxVecInt; SrcIndex, ValueIndex, RemDstIndex, Index, Len: integer): TMtxVecInt; overload; (*Divide all Src elements with Value and store result of division in the calling object and reminder in RemDst. Size and properties of the calling object and of RemDst are adjusted automatically. *) function RemDiv(Src: TMtxVecInt; Value: integer; RemDst: TMtxVecInt): TMtxVecInt; overload; (*Divide all Src elements with Value and store result of division in the calling object and reminder in RemDst. Store the result of division in the calling object elements [Index]..[Index+Len-1] and remainder in to [RemDstIndex] .. [RemDstIndex+ Len-1]. Size and properties of the calling object and RemDst must be set explicitly. An exception is raised if ConditionCheck is true and array borders are overrun/underrun. *) function RemDiv(Src: TMtxVecInt; Value: integer; RemDst: TMtxVecInt; SrcIndex, RemDstIndex, Index, Len: integer): TMtxVecInt; overload; (*Divide Src with all Value elements and store result of division in the calling object and reminder in RemDst. Size and properties of the calling object and of RemDst are adjusted automatically. *) function RemDiv(Src: integer; Value: TMtxVecInt; RemDst: TMtxVecInt): TMtxVecInt; overload; (*Divide Src with Value elements and store result of division in the calling object and reminder in RemDst. Store the result of division in the calling object elements [Index]..[Index+Len-1] and remainder in to [RemDstIndex] .. [RemDstIndex+ Len-1]. Size and properties of the calling object and RemDst must be set explicitly. An exception is raised if ConditionCheck is true and array borders are overrun/underrun. *) function RemDiv(Src: integer; Value: TMtxVecInt; RemDst: TMtxVecInt; ValueIndex, RemDstIndex, Index, Len: integer): TMtxVecInt; overload; (*Set all calling object elements [Index]..[Index+Len-1] to Value. An exception is raised if array borders are overrun/underrun. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TVecInt a; MtxVecInt.CreateIt(out a); try { a.SezIt(new int[] {1,2,3,4); a.SetVal(5,2,2); // a = [1,1,5,5] } finally { MtxVecInt.FreeIt(ref a); } } } *) function SetVal(Value, Index, Len: integer): TMtxVecInt; overload; (*Set all calling object elements to Value.*) function SetVal(Value: integer): TMtxVecInt; overload; (*Perform a shift on vector elements in range. Performs shift on vector elements in specified range [Index..Index+Len-1]. The number of elements to shift is specified in the Offset parameter. Offset can be any integer number, positive or negative. An exception is raised if array borders are overrun/underrun. *) function Shift(Offset, Index, Len: integer): TMtxVecInt; overload; (*A shift on vector elements in range. Performs a shift on source vector elements in specified range [SrcIndex .. SrcIndex+Len-1] and stores them to calling vector elements [Index .. Index+Len-1]. The number of elements to shift is specified in the Offset parameter. Offset can be any integer number, positive or negative. An exception is raised if array borders are overrun/underrun. *) function Shift(const Src: TMtxVecInt; Offset, SrcIndex, Index, Len: integer): TMtxVecInt; overload; (*Set all calling vector elements to zero.*) function SetZero(): TMtxVecInt; overload; (*Set calling vector elements [Index..Index+Len-1] to zero. An exception is raised if array borders are overrun/underrun. *) function SetZero(Index, Len: integer): TMtxVecInt; overload; (*Sort calling vector elements [Index..Index+Len-1] in ascending order in-place.*) function SortAscend(Index, Len: integer): TMtxVecInt; overload; (*Sort all calling vector elements in ascending order in-place. calling vector, storing sorted values. After execution stores sorted values indices. The starting index at which to store sorted values indices in DstSortIdx. The starting index at which to start the sort. The number of elements to sort starting from including zero-based Index. Size of DstSortIdx and calling vector are adjusted automatically. *) function SortAscend(DstSortIdx: TMtxVecInt; SortIdxIndex, Index, Len: integer): TMtxVecInt; overload; (*Sort calling vector elements [Index..Index+Len-1] in descending order in-place.*) function SortDescend(Index, Len: integer): TMtxVecInt; overload; (*Sort all calling vector elements in descending order in-place. calling vector, storing sorted values. After execution stores sorted values indices. The starting index at which to store sorted values indices in DstSortIdx. The starting index at which to start the sort. The number of elements to sort starting from including zero-based Index. Size of DstSortIdx and calling vector are adjusted automatically. *) function SortDescend(DstSortIdx: TMtxVecInt; SortIdxIndex, Index, Len: integer): TMtxVecInt; overload; (*Sums vector values. the sum of all calling object elements. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TVecInt a; MtxVecInt.CreateIt(out a); try { a.SetIt(new int[] {1,3,-2}); int s = a.Sum(); // s = 2 } finally { MtxVecInt.FreeIt(ref a); } } } *) function Sum(): integer; overload; (*Returns the sum of calling object elements [Index]..[Index+Len-1]. An exception is raised if array borders are overrun/underrun. *) function Sum(Index, Len: integer): integer; overload; (*Obtains a pointer to the integer value of the vector at Index. The function returns pointer to the current integer relative to the value of the Precision property. *) function PValues(Index: integer): PAPointer; overload; virtual; (*Obtains a pointer to the 32bit signed integer value of the vector at Index. The function returns @Values[i]. *) function PIValues(Index: integer): PAPointer; overload; virtual; (*Obtains a pointer to the 16bit signed integer value of the vector at Index. The function returns @Values[i]. *) function PSValues(Index: integer): PAPointer; overload; virtual; (*Obtains a pointer to the 8bit unsigned integer value of the vector at Index. The function returns @Values[i]. *) function PBValues(Index: integer): PAPointer; overload; virtual; (*Scatter object elements. Scatter the elements of the Src and store them in the calling object according to the IndexType, Increment and Offset parameters. The Indexes vector is used only if IndexType is either indVector or indMask. If IndexType is indVector, the values from the Indexes object denote the index positions in the calling object to which the values should be copied from the Src. The Indexes vector must have the indexes stored in the IValues array. The IValues integer arrays points the same memory as Values array. The Increment and Offset parameters are used only if TIndexType is indIncrement. They define the target offset and a fixed step (increment) between calling vector elements. If IndexType is indMaks the Indexes object must have the same size as the Src object. The routine will copy only those elements from the Src to the calling object, for which there is a 1 at the coresponding index in the Indexes object.The elements in the calling object are stored consecutively. See the method to see how to perform gathering. The performance of the CPU heavily depends on the assumption that elements are stored at consecutive memory locations. If it is neccessary to apply a set of operations only to elements at specific indexes, performance-wise it can prove to be very helpfull, if the elements are gathered first. *) function Scatter(const Src: TMtxVecInt; const Indexes: TMtxVecInt = nil; IndexType: TIndexType = indVector; Increment: integer = 1; Offset: integer = 0): TMtxVecInt; overload; (* Scatters Src elements starting at Offset and with Increment to the calling object. *) function ScatterByIncr(const Src: TMtxVecInt; Increment: integer = 1; Offset: integer = 0): TMtxVecInt; overload; (* Scatters Src elements defined with indices stored in Indexes to the calling object. *) function ScatterByIndexes(const Src: TMtxVecInt; const Indexes: TMtxVecInt): TMtxVecInt; overload; (* Scatters Src elements defined with the Mask to the calling object. *) function ScatterByMask(const Src: TMtxVecInt; const Mask: TMtxVecInt; allow_resizing: boolean = False): TMtxVecInt; overload; virtual; (*Threshold bottom operation. Perform threshold operation on all calling object values. The Value parameter is a lower bound for threshold operation. All values smaller than Value will be replaced with Value. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TVecInt a; MtxVecInt.CreateIt(out a); try { a.SetIt(new int[] {2, 0, 3, 4}); a.ThreshBottom(1); // a = [2,1,3,4] } finally { MtxVecInt.FreeIt(ref a); } } } *) function ThreshBottom(const Value: integer): TMtxVecInt; overload; (*Perform the threshold operation on calling object values [Index]..[Index+Len-1]. An exception is raised if array borders are overrun/underrun. *) function ThreshBottom(const Value: integer; Index, Len: integer): TMtxVecInt; overload; (*Perform threshold operation on all Src object values. Store the results in calling object. Size and properties of the calling object are adjusted automatically. *) function ThreshBottom(const Src: TMtxVecInt; const Value: integer): TMtxVecInt; overload; (*Perform a threshold operation on Vec elements [VecIndex]..[VecIndex+Len-1]. Store the results in the calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if ConditionCheck is true and array borders are overrun/underrun. *) function ThreshBottom(const Vec: TMtxVecInt; const Value: integer; VecIndex, Index, Len: integer): TMtxVecInt; overload; (*Threshold top operation. Perform threshold operation on all calling object values. The Value parameter is an upper bound for threshold operation. All values bigger than Value will be replaced with Value. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TVecInt a; MtxVecInt.CreateIt(out a); try { a.SetIt(new int[] {2, 0, 3, 4}); a.ThreshTop(1); // a = [1, 0, 1, 1] } finally { MtxVec.FreeIt(ref a); } } } *) function ThreshTop(const Value: integer): TMtxVecInt; overload; (*Perfrom the threshold operation on calling object values [Index]..[Index+Len-1]. An exception is raised if array borders are overrun/underrun. *) function ThreshTop(const Value: integer; Index, Len: integer): TMtxVecInt; overload; (*Perform threshold operation on all Src object values. Store the results in calling object. Size and properties of the calling object are adjusted automatically. *) function ThreshTop(const Src: TMtxVecInt; const Value: integer): TMtxVecInt; overload; (*Perform a threshold operation Vec elements [VecIndex]..[VecIndex+Len-1]. Store the results in the calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if ConditionCheck is true and array borders are overrun/underrun. *) function ThreshTop(const Vec: TMtxVecInt; const Value: integer; VecIndex, Index, Len: integer): TMtxVecInt; overload; (*Threshold top and bottom centered around zero. Perform threshold operation on all calling object values. The Value parameter is an upper bound for threshold operation. All values smaller than Value will be replaced with Value and all values bigger than -Value will be replaced with -Value. The comparison checks if abs(Values[i]) < Value. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TVecInt a; MtxVecInt.CreateIt(out a); try { a.SetIt(new int[] {2,-1,3,4}); a.ThreshAbsLT(2); // a = [2,-2,3,4] } finally { MtxVec.FreeIt(ref a); } } } *) function ThreshAbsLT(const Value: Integer): TMtxVecInt; overload; (*Perfrom the threshold operation on calling object values [Index]..[Index+Len-1]. An exception is raised if array borders are overrun/underrun. *) function ThreshAbsLT(const Value: Integer; Index, Len: integer): TMtxVecInt; overload; (*Perform threshold operation on all Src object values. Store the results in calling object. Size and properties of the calling object are adjusted automatically. *) function ThreshAbsLT(const Src: TMtxVecInt; const Value: Integer): TMtxVecInt; overload; (*Perform a threshold operation Vec elements [VecIndex]..[VecIndex+Len-1]. Store the results in the calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if ConditionCheck is true and array borders are overrun/underrun. *) function ThreshAbsLT(const Vec: TMtxVecInt; const Value: Integer; VecIndex, Index, Len: integer): TMtxVecInt; overload; (*Threshold top and bottom centered around zero. Perform threshold operation on all calling object values. The Value parameter is an upper bound for threshold operation. All values bigger than Value will be replaced with Value and all values smaller than -Value will be replaced with -Value. The comparison checks if abs(Values[i]) > Value. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TVecInt a; MtxVec.CreateIt(out a); try { a.SetIt(new int[] {2, -1, 3, 4}); a.ThreshAbsGT(2); // a = [2, -1, 2, 2] } finally { MtxVec.FreeIt(ref a); } } } *) function ThreshAbsGT(const Value: Integer): TMtxVecInt; overload; (*Perfrom the threshold operation on calling object values [Index]..[Index+Len-1]. An exception is raised if array borders are overrun/underrun. *) function ThreshAbsGT(const Value: Integer; Index, Len: integer): TMtxVecInt; overload; (*Perform threshold operation on all Src object values. Store the results in calling object. Size and properties of the calling object are adjusted automatically. *) function ThreshAbsGT(const Src: TMtxVecInt; const Value: Integer): TMtxVecInt; overload; (*Perform a threshold operation Vec elements [VecIndex]..[VecIndex+Len-1]. Store the results in the calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if ConditionCheck is true and array borders are overrun/underrun. *) function ThreshAbsGT(const Vec: TMtxVecInt; const Value: Integer; VecIndex, Index, Len: integer): TMtxVecInt; overload; (*Threshold greater than and less than operation. Perform operation on all calling object values. The LTValue parameter is an lower bound for threshold operation. The GTValue parameter is an upper bound for threshold operation. All values less than LTLevel will be replaced with LTValue. All values bigger than GTLevel will be replaced with GTValue. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TVecInt a; MtxVecInt.CreateIt(out a); try { a.SetIt(new int[] {20,1,30,40}); a.ThresholdGT_LT(23,34,10,5); // a = [20,5,34,34] } finally { MtxVecInt.FreeIt(ref a); } } } *) function ThresholdGT_LT (const GTLevel, GTValue, LTLevel, LTValue: Integer): TMtxVecInt; overload; (*Perfrom "greater than and less than" threshold operation on the calling object values in range [Index]..[Index+Len-1]. An exception is raised if array borders are overrun/underrun. *) function ThresholdGT_LT (const GTLevel, GTValue, LTLevel, LTValue: Integer; Index, Len: integer): TMtxVecInt; overload; (*Perform "greater than and less than" threshold operation on all Vec object values. Store the results in calling object. Size of the calling object is adjusted automatically. *) function ThresholdGT_LT (const Vec: TMtxVecInt; const GTLevel, GTValue, LTLevel, LTValue: Integer): TMtxVecInt; overload; (*Perform "greater than and less than" threshold operation on Vec elements from range [VecIndex]..[VecIndex+Len-1]. Store the results in the calling object elements [Index]..[Index+Len-1]. Size of the calling object must be set explicitly. An exception is raised if ConditionCheck is true and array borders are overrun/underrun. *) function ThresholdGT_LT(const Vec: TMtxVecInt; const GTLevel, GTValue, LTLevel, LTValue: Integer; VecIndex, Index, Len: integer): TMtxVecInt; overload; (*Finds matching indexes and returns their count. The b parameter is of integer type. op parameter can be < , > , >= , <= , = or <> *) function FindIndexesAndLength(const a: TMtxVecInt; const op: string; const b: Integer): integer; overload; (*Finds matching indexes and returns their count. The b parameter is of type. op parameter can be < , > , >= , <= , = or <> *) function FindIndexesAndLength(const a: TMtxVecInt; const op: string; const b: TMtxVecInt): integer; overload; (*Fills the calling vector with indexes, where the logical expression is true. ills the calling vector with indexes, where the Op comparison between a and b is True. Op string parameter can be '<', '>', '>=','<=','=' or '<>' . *) (*Finds matching indexes. The b parameter is of integer type. op parameter can be < , > , >= , <= , = or <> *) function FindIndexes(const a: TMtxVecInt; const op: string; const b: integer): TMtxVecInt; overload; (*Finds matching indexes. The b parameter is of type. op parameter can be < , > , >= , <= , = or <> *) function FindIndexes(const a: TMtxVecInt; const op: string; const b: TMtxVecInt): TMtxVecInt; overload; (*Finds a vector mask. The calling vector will hold the those elements where the Op comparison between a and b is True. Op string parameter can be < , > , >= , <= , = or <> . The calling vector will store the mask, 1 at those index locations where the Op comparison was True and 0 at those index locations where the Op comparison was false. *) function FindMask(const a: TMtxVecInt; const op: string; const b: integer): TMtxVecInt; overload; function FindMask(const a: TMtxVecInt; const op: char; const b: integer): TMtxVecInt; overload; (*The b parameter is of type.*) function FindMask(const a: TMtxVecInt; const op: string; const b: TMtxVecInt): TMtxVecInt; overload; function FindMask(const a: TMtxVecInt; const op: char; const b: TMtxVecInt): TMtxVecInt; overload; (*Read values content from stream to object. Reads values content from SrcStream stream to calling objct. No other values describing the data type or length are read from the DstStream. Number type is defined by the Precision parameter, which can be obtained from method call. Note Use this method separately only, if you want user defined storage format. var b: TVecInt; AStream: TFileStream; Precision: TPrecision; begin CreateIt(b); AStream := TFileStream.Create('C:\test.bin',fmOpenRead); try Precision := b.ReadHeader(AStream); // Read info for b b.ReadValues(AStream,Precision); // Read values of b finally AStream.Free; FreeIt(b); end; end; *) function ReadValues(SrcStream: TStream; aPrecision: TPrecision = prInteger; Endian: TEndianness = MtxSystemEndianness): integer; overload; virtual; (*Writes object Values content to a stream. Writes the calling object Values content to the DstStream stream. No other values describing the data type or length are written to the DstStream. Number type is defined by the Precision parameter, but only integer formats are accepted. Attempt to save single (float) precision or double precision will raise an exception. The paramateres must be the same as for the method. Use this method separately only, if you want user defined storage format. var b: TVecInt; AStream: TFileStream; begin CreateIt(b); b.SetIt([0,0,1,3,2]); AStream := TFileStream.Create('C:\test.Vec',fmCreate); try b.WriteHeader(AStream); // Write info for b b.WriteValues(AStream); // Write values of b finally AStream.Free; end; FreeIt(b); end; *) procedure WriteValues(DstStream: TStream; aPrecision: TPrecision = prInteger; Endian: TEndianness = MtxSystemEndianness); overload; virtual; (*Writes the header information for the calling vector to a stream. Writes the header information for the calling object to a DstStream stream. The header information contains information about object (size, type of values in Values array, ...) which all define the state of the object. Number type is defined by the Precision parameter. Attempt to save single precision or double precision will raise an exception. var b: TVecInt; AStream: TFileStream; begin CreateIt(b); b.SetIt([0,0,1,3,2]); AStream := TFileStream.Create('C:\test.bin',fmCreate); try b.WriteHeader(AStream); // Write info for b b.WriteValues(AStream); // Write values of b finally AStream.Free; FreeIt(b); end; end; *) procedure WriteHeader(const DstStream: TStream; aPrecision: TPrecision = prInteger; Endian: TEndianness = MtxSystemEndianness); overload; virtual; (*Reads the header information from a stream to object. Reads the header information from a DstStream stream to calling object. The header information contains all necessary information defining the object. The function returns the precision in which the data was stored. This information is required for the method. var b: TVecInt; AStream: TFileStream; Precision: TPrecision; begin CreateIt(b); AStream := TFileStream.Create('C:\test.bin',fmOpenRead); try Precision := b.ReadHeader(AStream); // Read info for b b.ReadValues(AStream,Precision); // Read values of b finally AStream.Free; FreeIt(b); end; end; *) function ReadHeader(const SrcStream: TStream; Endian: TEndianness = MtxSystemEndianness): TPrecision; overload; virtual; public (* Defines internal storage precision which can be either 32, 16 or 8 bit.*) property IntPrecision: TIntPrecision read FIntPrecision write SetIntPrecision; (* Prevents change to IntPrecision if Lock = True.*) property IntPrecisionLock: boolean read FIntPrecisionLock write SetIntPrecisionLock; (* Specifies the power of two for the scale factor used by some methods.*) property ScaleFactor: integer read FScaleFactor write SetScaleFactor; end; procedure FindMask(const Dst: TMtxVecInt; const a: TMtxVecInt; const op: string; const b: integer); overload; procedure FindMask(const Dst: TMtxVecInt; const a: TMtxVecInt; const op: string; const b: TMtxVecInt); overload; (*Adds operator overloading support for Open CL clVector and clMatrix. The unit declares clVector and clMatrix types for +, -, *, / operator support. *) unit clMtxExpr; interface {$I bdsppdefs.inc} uses Math387, clMtxVec ,Windows ,Classes ,AbstractMtxVec ,MtxVec ,MtxVecInt ; {$HPPEMIT END '#include "clMtxExpr.h"'} type (*Open CL vector class with overloaded operators. Declare clVector to run computation on Open CL Be carefull to declare clVector only for local variables with short lifetime. Call the Create method for clVector, if the variable is a global variable or a variable with a longer life.If the Create method (constuctor) is called, the clVector creates its own memory object in GPU memory, otherwise object cache is used. var b, c: clVector; bv: TSingleArray; begin b := clVector(TDoubleArray.Create(1,1,1,1)); b = [1,1,1,1]; b.Scale(2); c := b*2 + Cplx(2,3); c := b*2 + 2 + 3i b.Add(c); b.CopyToArray(bv); //copy data back to host from GPU end; *) clVector = record strict private FData: TOpenCLVector; function get_Data: TOpenCLVector; function GetCaption: string; function GetComplex: boolean; function GetLength: integer; function GetTag: PointerInteger; procedure SetCaption(const Value: string); procedure SetComplex(const Value: boolean); procedure SetLength(const Value: integer); procedure SetTag(const Value: PointerInteger); function GetClFloatPrecision: TclFloatPrecision; procedure SetClFloatPrecision(const Value: TclFloatPrecision); function GetDevice: TOpenCLDevice; function GetIsSubRange: boolean; procedure CreateFromCache; private property Data: TOpenCLVector read get_Data; public (*Add left to all elements in Right and return result.*) class operator Add(const Left: TCplx; const Right: clVector): clVector; (*Add Right to all elements in Left and return result.*) class operator Add(const Left: clVector; const Right: TCplx): clVector; (*Add Left to all elements in Right and return result.*) class operator Add(const Left: double; const Right: clVector): clVector; (*Add Right to all elements in Left and return result.*) class operator Add(const Left: clVector; const Right: double): clVector; (*Add coresponding elements in Left and Right.*) class operator Add(const Left: TOpenCLMtxVec;const Right: clVector): clVector; (*Add coresponding elements in Left and Right.*) class operator Add(const Left: clVector; const Right: TOpenCLMtxVec): clVector; (*Add coresponding elements in Left and Right.*) class operator Add(const Left: clVector;const Right: clVector): clVector; (*Subtract all elements in Right from Left.*) class operator Subtract(const Left: TCplx; const Right: clVector): clVector; (*Subtract Right from all elements in Left.*) class operator Subtract(const Left: clVector; const Right: TCplx): clVector; (*Subtract all elements in Right from Left.*) class operator Subtract(const Left: double; const Right: clVector): clVector; (*Subtract Right from all elements in Left.*) class operator Subtract(const Left: clVector; const Right: double): clVector; (*Subtract coresponding elements in Right from Left.*) class operator Subtract(const Left: clVector; const Right: TOpenCLMtxVec): clVector; (*Subtract coresponding elements in Right from Left.*) class operator Subtract(const Left: TOpenCLMtxVec; const Right: clVector): clVector; (*Subtract coresponding elements in Right from Left.*) class operator Subtract(const Left: clVector; const Right: clVector): clVector; (*Multiply all elements in Left with Right.*) class operator Multiply(const Left: clVector; const Right: TCplx): clVector; (*Multiply all elements in Right with Left.*) class operator Multiply(const Left: TCplx; const Right: clVector): clVector; (*Multiply all elements in Left with Right.*) class operator Multiply(const Left: clVector; const Right: double): clVector; (*Multiply all elements in Right with Left.*) class operator Multiply(const Left: double; const Right: clVector): clVector; (*Multiply all elements in Left with corresponding elements in Right.*) class operator Multiply(const Left: clVector; const Right: TOpenCLMtxVec): clVector; (*Multiply all elements in Left with corresponding elements in Right.*) class operator Multiply(const Left: TOpenCLMtxVec; const Right: clVector): clVector; (*Multiply all elements in Left with corresponding elements in Right*) class operator Multiply(const Left: clVector; const Right: clVector): clVector; (*Divide all elements in Left with Right.*) class operator Divide(const Left: clVector; const Right: TCplx): clVector; (*Divide Left with all elements Right.*) class operator Divide(const Left: TCplx; const Right: clVector): clVector; (*Divide all elements in Left with Right.*) class operator Divide(const Left: clVector; const Right: double): clVector; (*Divide Left with all elements Right.*) class operator Divide(const Left: double; const Right: clVector): clVector; (*Divide all elements in Left with coresponding elements in Right.*) class operator Divide(const Left: clVector; const Right: TOpenCLMtxVec): clVector; (*Divide all elements in Left with coresponding elements in Right.*) class operator Divide(const Left: TOpenCLMtxVec; const Right: clVector): clVector; (*Divide all elements in Left with coresponding elements in Right.*) class operator Divide(const Left: clVector; const Right: clVector): clVector; (*Negates all values inside AValue.*) class operator Negative(const AValue: clVector): clVector; class operator Explicit(const AValue: TCplxArray): clVector; class operator Explicit(const AValue: TDoubleArray): clVector; class operator Explicit(const AValue: TSingleArray): clVector; class operator Explicit(const AValue: clVector): TDoubleArray; class operator Explicit(const AValue: clVector): TSingleArray; class operator Explicit(const AValue: TOpenCLVector): clVector; class operator Implicit(const AValue: TVec): clVector; class operator Implicit(const AValue: clVector): TOpenCLVector; class operator Implicit(const AValue: clVector): TOpenCLMtxVec; class operator Implicit(const AValue: clVector): TOpenCLBase; public procedure CopyTo(const Dst: TVec); overload; procedure CopyTo(const Dst: TVecInt); overload; procedure Copy(const Src: TVecInt); overload; procedure Copy(const Src: TVec); overload; procedure SizeToArray(var Dst: TSingleArray); overload; procedure SizeToArray(var Dst: TDoubleArray); overload; procedure SizeToArray(var Dst: TCplxArray); overload; function CopyFromArray(const Src: TSingleArray): TOpenCLMtxVec; overload; function CopyFromArray(const Src: TDoubleArray): TOpenCLMtxVec; overload; function CopyFromArray(const Src: TCplxArray): TOpenCLMtxVec; overload; function CopyCplxFromArray(const Src: TSingleArray): TOpenCLMtxVec; overload; function CopyCplxFromArray(const Src: TDoubleArray): TOpenCLMtxVec; overload; procedure CopyToArray(var Dst: TSingleArray); overload; procedure CopyToArray(var Dst: TDoubleArray); overload; procedure CopyToArray(var Dst: TCplxArray); overload; procedure AssignWithoutCopy(const Src: clVector); overload; procedure Assign(const Src: TOpenCLMtxVec); overload; (*The norm of a vector. Calculates the norm of a Vec vector and stores the results in calling vector. This functions works the same as . *) function Norm(const Vec: TOpenCLVector): TOpenCLVector; (*Defines the calling vector to have the view of the same memory as Src. Src vector's Length property may not change while any other object has it's own view of it. a.SetSubRange(b,..); This SetSubRange method must be handled with great care. Namely: * b can be freed before "a" and accessing "a" gives AV. * a can be further subranged with c and same problem occurs when b is freed before c. * If you resize b, all objects which have subranged b are no longer pointing to valid memory. * b can Subrange other objects. Similar problem as when changing the size of b. Again all objects which have subranged b are not longer pointing to valid memory. All this can lead to hard to find bugs. *) procedure SetSubRange(const Src: TOpenCLMtxVec); overload; (*Define a subvector of the Src vector starting at Index and ending at Index+Len-1.*) procedure SetSubRange(const Src: TOpenCLMtxVec; Index: integer; Len: integer = MtxVecEOA); overload; (*Defines a sub-vector. Define a subvector of the Src vector starting at BeginIndex and ending at EndIndex (inclusive). *) procedure SetSubIndex(const Src: TOpenCLMtxVec; BeginIndex, EndIndex: integer); overload; (*Automatically set to true after the SetSubIndex or SetSubRange call. This property is set to true after the or call. If IsSubRange is true then the TOpenCLMtxVec method/function will be performed on subrange of values. Use to set IsSubRange back to False and thus reset sub range to full vector length. *) property IsSubRange: boolean read GetIsSubRange; (*Resets any defined subrange. *) procedure SetFullRange; (*Defines a sub vector/matrix. The method will define a subarray starting at Index and ending at Index+Len-1. No copying will occur, only pointers will be shifted or indices adjusted. All values of the original will be preserved. An exception will be raised if an attempt is made to change the size of calling object. A sub-vector/matrix is vector/matrix which does not neccessarily have its own memory allocated. Instead it adopts the memory of the source object and all operations done on the either of the objects affect the same elements. The use of subvectors/submatrices increases CPU cache reuse, lower's memory requirements, increases application performance and improves code readability. To again obtain a view of the full vector/matrix, see *) procedure SetSubRange(Index: integer; Len: integer); overload; (*Prevents calls to . Prevents calls to method. This can be usefull guard when an object is already working on a subrange and the user would like to further subrange an already subranged object. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TOpenCLVector a,b; clMtxVec.CreateIt(out a, out b); try { a.SetIt(false, new double[] {1,2,3,4,5,6,7,8,9}); a.SetSubRange(0,2); //a = [1,2] a.DisableSubrange(); a.SetSubRange(2,2); //exception raised here b.SetSubRange(a,2,2); //but this will work a.SetFullRange(); //b is not changed, it still points to [4,5] } finally { MtxVec.FreeIt(ref a, ref b); } } } *) procedure DisableSubrange; (*Enables calls to . Enables calls to by removing the block set by . *) procedure EnableSubrange; (*Prevents calls to . Prevents calls to method. This can be usefull guard when an object is already working on a subrange and the user would like to further subrange an already subranged object. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TOpenCLVector a,b; MtxVec.CreateIt(out a, out b); try { a.SetIt(false, new double[] {1,2,3,4,5,6,7,8,9}); a.Select(0,2); //a = [1,2] a.DisableSelect(); a.Select(2,2); //exception raised here b.Select(a,2,2); //but this will work a.SelectAll(); //b is not changed, it still points to [4,5] } finally { MtxVec.FreeIt(ref a, ref b); } } } *) procedure DisableSelect; (*Enables calls to . Enables calls to by removing the block set by . *) procedure EnableSelect; (*Resets any defined selection. *) procedure SelectAll; overload; (*Selects a set of elements from the vector. The method will define a subarray starting at Index and ending at Index+Len-1. No copying will occur, only pointers will be shifted. All values of the original will be preserved. An exception will be raised if an attempt is made to change the size of the calling object after a selection has been made. A selection will behave exactly as if the object always contained only the selected values. When a selection is made from another object the source object and all operations done on either of the two objects will affect the same elements. The use of selections increases CPU cache reuse, lower's memory requirements, increases application performance and improves code readability. To again obtain a view of the full vector/matrix use the method. When selecting elements from other objects, care must be given not to use the selections after the source object has been freed: var a,b: TOpenCLVector; begin CreateIt(a,b); try a.SetIt(False,[1,2,3,4]); b.Select(a,2,2); FreeIt(a); //free the source object b.Values[0] := b.Valuess[1]; //b does not point to valid memory anymore finally FreeIt(a); end; end; *) procedure Select(Index: integer; Len: integer); overload; (*Resets the selection. This method is the same as the method. *) procedure Select; overload; (*Sets the subarray size to full size. This method is the same as the method. *) procedure SetSubRange; overload; (*Defines a subarray. The method will define a sub array starting at BeginIndex and ending at EndIndex (inclusive). All values of the original vector/matrix will be preserved. An exception will be raised if an attempt is made to change the size of calling vector/matrix. A subarray is array which does not have its own memory allocated. Instead it adopts the memory of the source object and all operations done on the either of the objects affect the same elements. The use of subarrays increases CPU cache reuse, lower's memory requirements, increases application performance and improves code readability. To again obtain a view of the full vector see *) procedure SetSubIndex(BeginIndex, EndIndex: integer); overload; procedure Adopt(const Src: TOpenCLVector); overload; (*Copy object values. Copy each of Vec elements to the calling object. Size and properties of the calling object are set implicitly to match Vec object. var a,b,c: clVector; begin a.CopyFromArray(TSingleArray.Create(1,2,3,4)); // a = [1,2,3,4] b.Copy(a); // b = [1,2,3,4] end; *) function Copy(const Vec: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Copy Vec elements [VecIndex]..[VecIndex+Len-1] in the calling object elements [Index]..[Index+Len-1]. Size and properties must be set explicitly. An exception is raised if array borders are overrun or underrun. *) function Copy(const Vec: TOpenCLMtxVec; VecIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Add each of Vec2 elements to corresponding elements in Vec1. The results are stored in the calling object. Size and properties of the calling object are set implicitly to match Vec1 and Vec2 vectors. *) function Add(const Vec1, Vec2: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Add Vec1 elements [Vec1Index]..[Vec1Index+Len-1] to Vec2 elements [Vec2Index]..[Vec2Index+Len-1]. Store the results in calling object elements [Index]..[Index+Len-1]. An exception is raised if true and array borders are overrun. *) function Add(const Vec1, Vec2: TOpenCLMtxVec; Vec1Index, Vec2Index, Index, Len: integer): TOpenCLMtxVec; overload; (*Adds Value to object elements. *) function Add(const Value: double): TOpenCLMtxVec; overload; (*Adds complex Value to all calling object complex elements.*) function Add(const Value: TCplx): TOpenCLMtxVec; overload; (*Adds Value to calling object elements [Index]..[Index+Len-1]. An exception is raised if array borders are overrun. *) function Add(const Value: double; Index, Len: integer): TOpenCLMtxVec; overload; (*Adds complex Value to calling object complex elements [Index]..[Index+Len-1]. An exception is raised if array borders are overrun. *) function Add(const Value: TCplx; Index, Len: integer): TOpenCLMtxVec; overload; (*Adds Value to the each element of the Vec object. Stores the result in the calling object. Size and properties of the calling object are set automatically. *) function Add(const Vec: TOpenCLMtxVec; const Value: double): TOpenCLMtxVec; overload; (*Adds complex Value to each element of the Vec object. Store the result to the calling object. Size property of the calling object is set automatically. property of the calling object is set to True. *) function Add(const Vec: TOpenCLMtxVec; const Value: TCplx): TOpenCLMtxVec; overload; (*Adds Value to each element of Vec object in range [VecIndex]..[VecIndex+Len-1]. Stores result to elements [Index]..[Index+Len-1] of the calling object. Size of the calling object is not changed. An exception is raised if array borders are overrun. property of the calling object is set implicitly. *) function Add(const Vec: TOpenCLMtxVec; Value: double; VecIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Adds complex Value to each elements of the Vec object in range [VecIndex]..[VecIndex+Len-1]. Stores the result to elements [Index]..[Index+Len-1] of the calling object. Size of the calling object is not changed. An exception is raised if array borders are overrun. property of the calling object is set to True. *) function Add(const Vec: TOpenCLMtxVec; const Value: TCplx; VecIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Array addition. Add each of Vec elements to corresponding elements in the calling object. *) function Add(const Vec: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Add Vec elements [VecIndex]..[VecIndex+Len-1] to calling object elements [Index]..[Index+Len-1]. An exception is raised if array borders are overrun. *) function Add(const Vec: TOpenCLMtxVec; VecIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Split complex calling object in real and imaginary part. Split calling object into real and imaginary components. Store all real components in ReVec and all imaginary components in ImVec. Size and properties of ReVec and ImVec are set implicitly to match with the calling vector. An execption is raised if calling object is not complex. var a,b,c: clVector; begin a.CopyFromArray(TSingleArray.Create(1,-2,3,4)); a.CplxToReal(b,c); end; *) procedure CplxToReal(ReVec, ImVec: TOpenCLMtxVec); overload; (*Split calling object elements [Index]..[Index+Len-1] into real and imaginary components. Store real components in ReVec elements [ReIndex]..[ReIndex+Len-1] and imaginary components in ImVec elements [ImIndex]..[ImIndex+Len-1]. Size and properties must be set explicitly. An exception is raised if array borders are overrun or underrun. *) procedure CplxToReal(ReVec, ImVec: TOpenCLMtxVec; ReIndex, ImIndex, Index, Len: integer); overload; (*Constructs a complex object from two real objects. Construct a complex object from the ReVec (real part) and the ImVec (imaginary part) objects. The results are stored in the calling object. Size and properties of the calling object are set implicitly to match ReVec and ImVec objects. An exception is raised if ReVec or ImVec property is True. var a,b,c: clVector; begin a.CopyFromArray(TSingleArray.Create(1,2,3,4)); b.CopyFromArray(TSingleArray.Create(2,2,3,4)); c.RealToCplx(a,b); end; *) function RealToCplx(ReVec, ImVec: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Construct a complex object from the ReVec elements [ReIndex]..[ReIndex+Len-1] (real part) and the ImVec elements [ImIndex]..[ImIndex+Len-1] (imaginary part). The results are stored to calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if array borders are overrun. An exception is also raised if ReVec or ImVec property is True. *) function RealToCplx(ReVec, ImVec: TOpenCLMtxVec; ReIndex, ImIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Conjugate. Conjugate all calling object elements in-place. var c: clVector; begin c.CopyFromArray(TSingleArray.Create(1,2,3,4)); // c = [1+2i, 3+4i] c.Conj; // c = [1-2i, 3-4i] end; *) function Conj: TOpenCLMtxVec; overload; (*Conjugate calling object elements [Index]..[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function Conj(Index,Len: integer): TOpenCLMtxVec; overload; (*Conjugate each of Vec elements. Store the results in the calling object. The Size and properties of the calling object are set implicitly to match Vec vector. *) function Conj(const Vec: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Conjugate Vec elements Vec[VecIndex]..Vec[VecIndex+Len-1]. Store them in the calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if array borders are overrun. *) function Conj(const Vec: TOpenCLMtxVec; VecIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Extends a real object to a complex object. Extend the calling object to complex vector. After the calling of ExtendToComplex the imaginary part becomes the same as real part if Zeros is false. If Zeros is true the imaginary part is set to zero. The use of the in-place version of the method is discouraged because it requires 3*N copy operations, while the not-in-place version requires only 2*N copy operations. var a,b: clVector; begin a.CopyFromArray(TSingleArray.Create(1,2,3,4)); b.ExtendToComplex(a,True); end; *) function ExtendToComplex(Zeros: boolean = True): TOpenCLMtxVec; overload; (*Extend Vec object to complex calling object. If Zeros is true then the calling vector imaginary part is set to zero, otherwise the calling object imaginary part is the same as calling object real part. *) function ExtendToComplex(const Src: TOpenCLMtxVec; Zeros: Boolean): TOpenCLMtxVec; overload; (*Converts the source to complex. Converts the source to complex by setting the imaginary part to either zero (zeros = True) or same as real (zeros = false). Does not set size of the calling vector. If there is not sufficient space available to store the result an exception will be raised. *) function ExtendToComplex(const Src: TOpenCLMtxVec; Zeros: Boolean; SrcIndex,DstIndex, Len: integer): TOpenCLMtxVec; overload; (*Sets angle in [-2PI,2PI]. ThetaRad within -2 and interval. Calling this function prior to passing the value to trigonometric functions can significantly improve numerical accuracy. Sine/cosine appear within many other functions especially complex versions of trigonometric functions. FixAngle method is not used implicitely within TOpenCLMtxVec methods. To achieve maximum performance make sure that the arguments passed to complex trigonometric functions are "small" or scaled down. Note The vector must be real. *) function FixAngle: TOpenCLMtxVec; overload; (*FixAngle for calling object complex elements [Index]..[Index+Len-1] in-place. An exception is raised if calling object property is True or if array borders are overrun/underrun. *) function FixAngle(Index,Len: integer): TOpenCLMtxVec; overload; (*Sets angle in [-2PI,2PI] for all Src elements. Stores the results in the calling object. Size and properties of the calling vector are set implicitly to match the Src object. *) function FixAngle(const Src: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Sets angle in [-2PI,2PI] for Src elements [SrcIndex]..[SrcIndex+Len-1] and store the results in the calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if array borders are overrun. *) function FixAngle(const Src: TOpenCLMtxVec; SrcIndex, Index,Len: integer): TOpenCLMtxVec; overload; (*Rounds towards negative infinity. Rounds all calling object elements towards negative infinity in-place. Floor(-2.8) = -3 Floor(2.8) = 2 Floor(-1.0) = -1 *) function Floor: TOpenCLMtxVec; overload; (*Rounds calling object elements [Index]..[Index+Len-1] towards negative infinity in-place. An exception is raised if array borders are overrun. *) function Floor(Index,Len: integer): TOpenCLMtxVec; overload; (*Rounds all Src object elements towards negative infinity and stores the result in the calling object. Size and properties of the calling object are adjusted automatically. *) function Floor(const Src: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Rounds Src object elements [SrcIndex]..[SrcIndex+Len-1] towards negative infinity and stores the result in the calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if array borders are overrun. *) function Floor(const Src: TOpenCLMtxVec; SrcIndex, Index,Len: integer): TOpenCLMtxVec; overload; (*A complex exponential e^(j*Omega)). Calculate the calling object complex exponential in-place. An exception is raised if calling object is complex. If object is complex, you should use the method instead. var a: clVector; begin a.CopyFromArray(TSingleArray.Create(1,2,3,4)); a.Expj; // a = [e^i, e^2i, e^3i, e^4i] end; *) function Expj: TOpenCLMtxVec; overload; (*Calculate the e^(j*Omega), a complex exponential. Omega must be a real object. If omega is complex, then use the method. *) function Expj(Omega: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Calculate the complex exponential for Omega elements [OmegaIndex]..[OmegaIndex+Len-1]. Store the results in calling object elemets [Index]..[Index+Len-1]. Size and properties of the calling vector must be set explicitly. An exception is raised if array borders are overrun or underrun. *) function Expj(Omega: TOpenCLMtxVec; OmegaIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Fractional part of values. Calculates the fractional part for all object values in-place. var a: clVector; ind: Integer; begin a.CopyFromArray(TSingleArray.Create(1,5.5,-1.6,6)); // a = [1, 5.5, -1.6, 6] a.Frac; // a = [0, 0.5, -0.6, 0] end; *) function Frac: TOpenCLMtxVec; overload; (*Calculates the fractional part for all X object values. Stores the result in calling object. Size and properties of calling object are adjusted automatically. *) function Frac(const X: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Calculates the fractional part for calling object elements [Index]..[Index+Len-1] in-place. An exception is raised if array borders are overrun or underrun. *) function Frac(Index,Len: integer): TOpenCLMtxVec; overload; (*Calculates the fractional part for X object elements [XIndex]..[XIndex+Len-1]. Stores the result in calling object elements [Index]..[Index+Len-1]. An exception is raised if array borders are overrun or underrun. *) function Frac(const X: TOpenCLMtxVec; XIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Complementary error functon of values. Calculates the complementary error function value for all object values in-place. var a: clVector; begin a.CopyFromArray(TSingleArray.Create(1,5.5,-1.6,6)); // a = [1, 5.5, -1.6, 6] a.Erfc; end; *) function Erfc: TOpenCLMtxVec; overload; (*Calculates the complementary error function value for all Src object values. Stores the result in calling object. Size and properties of calling object are adjusted automatically. *) function Erfc(const Src: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Calculates the complementary error function value for calling object elements [Index]..[Index+Len-1] in-place. An exception is raised if array borders are overrun or underrun. *) function Erfc(Index,Len: integer): TOpenCLMtxVec; overload; (*Calculates the complementary error function value for Src object elements [SrcIndex]..[SrcIndex+Len-1]. Stores the result in calling object elements [Index]..[Index+Len-1]. An exception is raised if array borders are overrun or underrun. *) function Erfc(const Src: TOpenCLMtxVec; SrcIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Error functon of values. Calculates the error function for all object values in-place. var a: clVector; ind: Integer; begin a.CopyFromArray(TSingleArray.Create(1, 5.5, -1.6, 6)); // a = [1, 5.5, -1.6, 6] a.Erf; end; *) function Erf: TOpenCLMtxVec; overload; (*Calculates the error function for all Src object values. Stores the result in calling object. Size and properties of calling object are adjusted automatically. *) function Erf(const Src: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Calculates the error function for calling object elements [Index]..[Index+Len-1] in-place. An exception is raised if array borders are overrun or underrun. *) function Erf(Index,Len: integer): TOpenCLMtxVec; overload; (*Calculates the error function for Src object elements [SrcIndex]..[SrcIndex+Len-1]. Stores the result in calling object elements [Index]..[Index+Len-1]. An exception is raised if array borders are overrun or underrun. *) function Erf(const Src: TOpenCLMtxVec; SrcIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Flips the real and imaginary part of complex numbers. Flipped real and imaginary part of complex numbers for all calling object elements in-place. The following transformation is used: a + i*b -> b + i*a *) function Flip: TOpenCLMtxVec; overload; (*Flips the real and imaginary part of complex numbers for calling object elements [Index]..[Index+Len-1] in-place. An exception is raised if array borders are overrun or underrun. *) function Flip(Index, Len: integer): TOpenCLMtxVec; overload; (*Flips the real and imaginary part of complex numbers for all X object elements. Xtore the results in the calling object. Size and properties of calling object are adjusted automatically. *) function Flip(const X: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Flips the real and imaginary part of complex numbers for X object elements [XIndex]..[XIndex+Len-1]. Store the results in the calling object elements [Index]..[Index+Len-1]. An exception is raised if array borders are overrun or underrun. *) function Flip(const X: TOpenCLMtxVec; XIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Flips the real and imaginary part of complex numbers and conjugates the complex numbers. Performs the following transformation: a + i*bi ==> b - i*a Method flips the real and imaginary part and conjugates calling object complex elements in-place. *) function FlipConj: TOpenCLMtxVec; overload; (*Flip calling object complex elements [Index]..[Index+Len-1] in-place. An exception is raised if calling object property is false or if array borders are overrun/underrun. *) function FlipConj(Index, Len: integer): TOpenCLMtxVec; overload; (*Flip all X object complex elements. Store the results in calling object. Size and property of calling object are adjusted automatically. *) function FlipConj(const X: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Flip X object complex elements [XIndex]..[XIndex+Len-1]. Store the results in calling object elements [Index]..[Index+Len-1]. An exception is raised if calling object property is false or if array borders are overrun/underrun. *) function FlipConj(const X: TOpenCLMtxVec; XIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*The Reminder after division X/Y. Calculates reminder after division according to formula: x[i]-y[i]*Trunc(x[i]/y[i]). The results will be saved to the calling vector. X and Y must be a real and have the same length. Size and properties of the calling vector are set implicitly to match the X object. var a,b,c: clVector; begin a.CopyFromArray(TSingleArray.Create(0,1,10,-1,-10)); // a = [0, 1, 10, -1, -10]; b.CopyFromArray(TSingleArray.Create(0,1,PI,-1,-PI)); // b = [0, 1, PI, -1, -PI]; c.Rem(a,b); // c = [0, 0, 0.5752, 0, -0.5752] end; *) function Rem(const X, Y: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Calculates reminder after division X/Y. Calculation uses the following formula: z[i] = x[xi]-y[yi]*Trunc(x[xi]/y[yi]), where i in [Index..Index+Len], xi in [XIndex..XIndex+Len], yi in [YIndex..YIndex+Len]. The results will be saved to the calling vector. X must be a real. An exception will be raised if array borders are overrun. *) function Rem(const X, Y: TOpenCLMtxVec; XIndex, YIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Calculates reminder after division X/Y. Reminder is calculated by using the following formula: x[i]-y*Trunc(x[i]/y). X must be a real. The results will be saved to the calling vector. Size and properties of the calling vector are set implicitly to match the X object. *) function Rem(const X: TOpenCLMtxVec; Y: double): TOpenCLMtxVec; overload; (*Calculates reminder after division X/Y. Reminder is calculated by using the following formula: x[i]-y*Trunc(x[i]/y). X must be a real. The results will be saved to the calling vector. An exception will be raised if array borders are overrun. *) function Rem(const X: TOpenCLMtxVec; Y: double; XIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Multiply object elements with Value. Multiply all calling object elements with Value in-place. This method is the same as the method overloads multiplying with vector elements with a scalar. var v: clVector; begin v.CopyFromArray(TSingleArray.Create(2,3,5)); // v = [2,3,5] v.Scale(3); // v = [6,9,15] end; *) function Scale(Factor: double): TOpenCLMtxVec; overload; (*Multipy calling object elements [Index]..[Index+Len-1] with Value in-place. An exception is raised if array borders are overrun or underrun. *) function Scale(Factor: double; Index, Len: integer): TOpenCLMtxVec; overload; (*Multiply all calling object elements with a complex Value in-place.*) function Scale(const Factor: TCplx): TOpenCLMtxVec; overload; (*Multipy calling object elements [Index]..[Index+Len-1] with complex Value in-place. An exception is raised if array borders are overrun or underrun. *) function Scale(const Factor: TCplx; Index, Len: integer): TOpenCLMtxVec; overload; (*Log base N. Log base N for all calling object elements in-place. var a: clVector; begin a.CopyFromArray(TSingleArray.Create(1,2,3,4)); // a = [1,2,3,4] a.LogN(10.0); // log base 10, the slow way a = [Log10(1), Log10(2),...] end; *) function LogN(N: double): TOpenCLMtxVec; overload; (*Calculate the log base N of calling object elements [Index]..[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function LogN(N: double; Index, Len: integer):TOpenCLMtxVec; overload; (*Calculate the log base N of all X object elements. Store the results in calling object. Size and properties of the calling object are adjusted automatically. *) function LogN(N: double; X: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Calculate the log base N of X object elements [XIndex]..[XIndex+Len-1]. The results are stored in calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object are not changed. An exception is raised if array borders are overrun. *) function LogN(N: double; X: TOpenCLMtxVec; XIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Normalize object. Normalizes Vec object by subtracting a constant Offset from Vec elements and dividing the result by constant Factor: The results are stored in calling object. Use this method if you want to do a multiply and add (scale and offset) operations in a single method call. var a,b: clVector; begin a.CopyFromArray(TSingleArray.Create(1,2,3,4)); b.Normalize(a,2,3); end; *) function Normalize(const Vec: TOpenCLMtxVec; const SubOffset, DivFactor: double): TOpenCLMtxVec; overload; (*Normalize Vec object values [VecIndex]..[VecIndex+Len-1] by subtracting a real constant SubOffset from Vec elements and dividing the result by complex constant DivFactor. Store the results in calling vector values [Index]..[Index+Len-1]. An exception is raised if Vec or calling object is complex or array borders are overrun/underrun. *) function Normalize(const Vec: TOpenCLMtxVec; const SubOffset, DivFactor: double; VecIndex,Index,Len: integer): TOpenCLMtxVec; overload; (*Normalize Vec object by subtracting a complex constant SubOffset from Vec elements and dividing the result by real constant DivFactor. Size and property of calling object are adjusted automatically. *) function Normalize(const Vec: TOpenCLMtxVec; const SubOffset: TCplx; DivFactor: double): TOpenCLMtxVec; overload; (*Normalize Vec object complex values [VecIndex]..[VecIndex+Len-1] by subtracting a complex constant SubOffset from Vec elements and dividing the result by real constant DivFactor. Store the results in calling vector complex values [Index]..[Index+Len-1]. An exception is calling object is not complex or array borders are overrun/underrun. *) function Normalize(const Vec: TOpenCLMtxVec; const SubOffset: TCplx; DivFactor: double; VecIndex,Index,Len: integer): TOpenCLMtxVec; overload; (*Raises base object elements to any power. Raises Base calling object elements to any power. The is faster, if Exponent is an integer. Real valued power can handle only positive Exponent. can handle negative exponent also. To compute a power to the negative exponent in general case or when the base is negative, use the complex version of the function. var a: clVector; begin a.CopyFromArray(TSingleArray.Create(1,2,3,4)); a.Power(1.2); end; *) function Power(Exponent: double): TOpenCLMtxVec; overload; (*Raises all calling vector elements to complex power Exponent in-place. If the calling vector is real and has negative elements, the result will be NAN at those entries. To obtain a valid result in this case, extend the calling vector to complex with method. In all real/complex combinations, the Power method will not automatically assume that a number is complex to speed up the computation. Alternatively the user can of course always convert the real numbers to complex before passing them to the Power routine. *) function Power(const Exponent: TCplx): TOpenCLMtxVec; overload; (*Raises base elements to exponent power. Raises Base value to Exponent object values powers and store the results to calling object values. Size and properties of calling object are adjusted automatically. *) function Power(const aBase: double; const Exponent: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Raises Base complex value to Exponent object values powers. Store the results to calling object values. Size and properties of calling object are adjusted automatically. *) function Power(const aBase: TCplx; const Exponent: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Raises each of the Base object elements to complex Exponent power. Size and properties of calling object are adjusted automatically. *) function Power(const aBase: TOpenCLMtxVec; const Exponent: TCplx): TOpenCLMtxVec; overload; (*Raises each of the Base object elements to real Exponent power. Size and properties of calling object are adjusted automatically. *) function Power(const aBase: TOpenCLMtxVec; const Exponent: double): TOpenCLMtxVec; overload; (*Raises each of Base object elements to corresponding power, stored in Exponenet elements. Power[i] = Base[i]^Exponent[i] Size and property of calling object are adjusted automatically. An exception is raised if Base and Exponent sizes do not match. *) function Power(const aBase, Exponent: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Raises Base object elements to Exponent object elements power. Raises Base elements to Exponent elements power. Only positive exponents can be handled if exponent object property is True. var a,b,c: clVector; begin a.CopyFromArray(TSingleArray.Create(1,2,3,4)); b.CopyFromArray(TSingleArray.Create(3,3,2,2)); c.PowerVec(a,b); // c = [1,8,9,16] end; *) function PowerVec(const aBase, Exponent: TOpenCLMtxVec): TOpenCLMtxVec; (*Elements rounded to the nearest whole number. Rounds all calling object elements to the nearest whole number. The result can be stored to an array of integers or as floating point number. *) function Round: TOpenCLMtxVec; overload; (*Round calling object elements [Index]..[Index+Len-1] in-place. An exception is raised if array borders are overrun/underrun. *) function Round(Index,Len: integer): TOpenCLMtxVec; overload; (*Round all Src object elements. Store the results in calling object elements. Size and property of calling object are adjusted automatically. *) function Round(const Src: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Round Src object elements [SrcIndex]..[SrcIndex+Len-1]. Store the results to calling object elements [Index]..[Index+Len-1]. Size and property of the calling object must be set explicitly. An exception is raised if array borders are overrun/underrun. *) function Round(const Src: TOpenCLMtxVec; SrcIndex,Index,Len: integer): TOpenCLMtxVec; overload; (*Standard deviation. Calculate the standard deviation of all calling object elements. The result is a real value. An exception is raised if calling vector Complex property is true. var a: clVector; c: double; aMean: double; begin a.CopyFromArray(TDoubleArray.Create(1,2,3,4)); Caption := FloatToSTr(a.RMS); end; *) function RMS: double; overload; (*Initialize elements to Value. Set all calling object elements to Value. If the calling object is complex then the real part is set to Value and the imaginary is set to zero. var a: clVector; begin a.Size(4,False); a.SetVal(1); // a = [1,1,1,1] end; *) function SetVal(const Value: double): TOpenCLMtxVec; overload; (*Set all calling object elements [Index]..[Index+Len-1] to real Value. If the calling object is complex then the real part is set to Value and the imaginary is set to zero. An exception is raised if array borders are overrun/underrun. *) function SetVal(const Value: double; Index, Len: integer): TOpenCLMtxVec; overload; (*Set all calling object complex elements to complex Value.*) function SetVal(const Value: TCplx): TOpenCLMtxVec; overload; (*Set calling object complex elements [Index]..[Index+Len-1] to complex Value. property of the calling object are set to true even before the call it was false. An exception is raised if calling object array borders are overrun/underrun. *) function SetVal(const Value: TCplx; Index: integer; Len: integer): TOpenCLMtxVec; overload; (*Initializes object elements to zero. *) function SetZero: TOpenCLMtxVec; overload; (*Initializes calling object elements [Index]..[Index+Len-1] to zero. An exception is raised if array borders are overrun. *) function SetZero(Index, Len: integer): TOpenCLMtxVec; overload; (*Changes elements sign. Changes all calling object elements sign (v -> -v) in-place. var a: clVector; begin a.CopyFromArray(TSingleArray.Create(1,2,-3,4)); a.Sign; // a = [-1,-2,3,-4] end; *) function Sign: TOpenCLMtxVec; overload; (*Change calling object elements [Index]..[Index+Len-1] sign in-place. An exception is raised if array borders are overrun or underrun. *) function Sign(Index,Len: integer): TOpenCLMtxVec; overload; (*Change all X object elements sign. Store the results in calling object. Size and properties of calling object are adjusted automatically. *) function Sign(const X: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Change X object elements [XIndex]..[XIndex+Len-1] sign. Store the results in callingobject elements [Index]..[Index+Len-1]. An exception is raised if array borders are overrun or underrun. *) function Sign(const X: TOpenCLMtxVec; XIndex,Index,Len: integer): TOpenCLMtxVec; overload; (* Computes signum function of calling object elements. Signum(X) is 1 for X > 0 , equal to zero for X = 0 and -1 for X < 0. *) function Sgn: TOpenCLMtxVec; overload; (* Computes signum function of calling object elements [Index..Index+Len-1]. Signum(X) is 1 for X > 0 , equal to zero for X = 0 and -1 for X < 0. *) function Sgn(Index, Len: integer): TOpenCLMtxVec; overload; (* Computes signum function from Src elements and stores the result in the calling object. Size and properties of calling object are adjusted automatically. Signum(X) is 1 for X > 0 , equal to zero for X = 0 and -1 for X < 0. *) function Sgn(const Src: TOpenCLMtxVec): TOpenCLMtxVec; overload; (* Computes signum function from Src elements [SrcIndex..SrcIndex+Len-1] and stores the result in the calling object [Index..Index+Len-1]. Size and properties of calling object are adjusted automatically. Signum(X) is 1 for X > 0 , equal to zero for X = 0 and -1 for X < 0. *) function Sgn(const Src: TOpenCLMtxVec; SrcIndex,Index,Len: integer): TOpenCLMtxVec; overload; (*Signum. Calculates the signum of all Src object elements and multiplies it with the calling object elements accordingly. Signum(X) is 1 for X > 0 , equal to zero for X = 0 and -1 for X < 0. The length of Src and of the calling object must match or an exception will be raised. Size and property of calling object are adjusted automatically. *) function SgnMul(const Src: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Sine and cosine. Calculates the sine and cosine for all calling object elements and stores the sines to SinX and cosines to CosX. Size and property of SinX and CosX are adjusted automatically. Note Use this method if you require both sine and cosine. var a: clVector; s,c: clVector; begin a.CopyFromArray(TSingleArray.Create(0,PiDiv2,PI)); a.SinCos(s,c); // s=[0,1,0], c =[1,0,-1] end; *) procedure SinCos(SinX, CosX: TOpenCLMtxVec); overload; (*Calculates the sine and cosine for calling object elements [Index]..[Index+Len-1]. stores the sines to SinX elemets [SinXIndex]..[SinXIndex+Len-1] and cosines to CosX elements [CosXIndex]..[CosXIndex+Len-1] elements. Size and property of SinX and CosX objects are not set automatically. An exception is raised if array borders are overrun/underun. *) procedure SinCos(SinX, CosX: TOpenCLMtxVec; SinXIndex, CosXIndex, Index, Len: integer); overload; (*Hyperbolic sine and cosine. Calculates the hyperbolic sine and hyperbolic cosine for all calling object elements and stores the sines to SinhX and cosines to CoshX. Size and property of SinhX and CoshX are adjusted automatically. Note Use this method if you require hyperbolic sine and hyperbolic cosine. var a: clVector; s,c: clVector; begin a.CopyFromArray(TSingleArray.Create(0,PiDiv2,PI)); a.SinhCosh(s,c); end; *) procedure SinhCosh(SinhX, CoshX: TOpenCLMtxVec); overload; (*Calculates the hyperbolic sine and hyperbolic cosine for calling object elements [Index]..[Index+Len-1]. Stores the sines to SinhX elemets [SinhIndex]..[SinhIndex+Len-1] and cosines to CoshX elements [CoshIndex]..[CoshIndex+Len-1] elements. Size and property of SinhX and CoshX objects are not set automatically. An exception is raised if array borders are overrun/underun. *) procedure SinhCosh(SinhX, CoshX: TOpenCLMtxVec; SinhIndex, CoshIndex, Index, Len: integer); overload; (*Threshold bottom operation. Perform threshold operation on all calling object values. The Value parameter is a lower bound for threshold operation. All values smaller than Value will be replaced with Value. var a: clVector; begin a.CopyFromArray(TSingleArray.Create(2,0.1,3,4)); a.ThreshBottom(0.2); // a = [2,0.2,3,4] end; *) function ThreshBottom(Value: double): TOpenCLMtxVec; overload; (*Perform the threshold operation on calling object values [Index]..[Index+Len-1]. An exception is raised if array borders are overrun/underrun. *) function ThreshBottom(Value: double; Index, Len: integer): TOpenCLMtxVec; overload; (*Perform threshold operation on all Src object values. Store the results in calling object. Size and properties of the calling object are adjusted automatically. *) function ThreshBottom(const Src: TOpenCLMtxVec; Value: double): TOpenCLMtxVec; overload; (*Perform a threshold operation on Vec elements [VecIndex]..[VecIndex+Len-1]. Store the results in the calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if array borders are overrun/underrun. *) function ThreshBottom(const Vec: TOpenCLMtxVec; Value: double; VecIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Threshold top operation. Perform threshold operation on all calling object values. The Value parameter is an upper bound for threshold operation. All values bigger than Value will be replaced with Value. var a: clVector; begin a.CopyFromArray(TSingleArray.Create(2,0.1,3,4)); a.Threshtop(0.2); // a = [0.2,0.1,0.2,0.2] end; *) function ThreshTop(Value: double): TOpenCLMtxVec; overload; (*Perfrom the threshold operation on calling object values [Index]..[Index+Len-1]. An exception is raised if array borders are overrun/underrun. *) function ThreshTop(Value: double; Index, Len: integer): TOpenCLMtxVec; overload; (*Perform threshold operation on all Src object values. Store the results in calling object. Size and properties of the calling object are adjusted automatically. *) function ThreshTop(const Src: TOpenCLMtxVec; Value: double): TOpenCLMtxVec; overload; (*Perform a threshold operation Vec elements [VecIndex]..[VecIndex+Len-1]. Store the results in the calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if array borders are overrun/underrun. *) function ThreshTop(const Vec: TOpenCLMtxVec; Value: double; VecIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Threshold less than operation. Perform operation on all calling object values. The LTValue parameter is an lower bound for threshold operation. All values less than LTLevel will be replaced with LTValue. For complex number comparation is applied with norm of complex value. var a: clVector; begin a.CopyFromArray(TSingleArray.Create(2,0.1,3,4)); a.ThresholdLT(2.3,1.5); // a = [1.5,1.5,3,4] end; *) function ThresholdLT(LTLevel, LTValue: double): TOpenCLMtxVec; overload; (*Perfrom "less than" threshold operation on the calling object values in range [Index]..[Index+Len-1]. An exception is raised if array borders are overrun/underrun. *) function ThresholdLT(LTLevel, LTValue: double; Index, Len: integer): TOpenCLMtxVec; overload; (*Perform "less than" threshold operation on all Vec object values. Store the results in calling object. Size and properties of the calling object are adjusted automatically. *) function ThresholdLT(const Vec: TOpenCLMtxVec; LTLevel, LTValue: double): TOpenCLMtxVec; overload; (*Perform "less than" threshold operation on Vec elements from range [VecIndex]..[VecIndex+Len-1]. Store the results in the calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if array borders are overrun/underrun. An exception will be raised if Vec.Complex and Complex of the calling object are not equal. *) function ThresholdLT(const Vec: TOpenCLMtxVec; LTLevel, LTValue: double; VecIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Perfrom "less than" threshold operation for complex numbers. If the calling object contains none Complex values, an exception will be raised. *) function ThresholdLT(LTLevel: double; const LTValue: TCplx): TOpenCLMtxVec; overload; (*Perfrom "less than" threshold operation for complex numbers on the calling object values in range [Index]..[Index+Len-1]. An exception is raised if array borders are overrun/underrun. If the calling object contains none Complex values, an exception will be raised. *) function ThresholdLT(LTLevel: double; const LTValue: TCplx; Index, Len: integer): TOpenCLMtxVec; overload; (*Perform "less than" threshold operation for complex numbers on all Vec object values. Store the results in calling object. Size and properties of the calling object are adjusted automatically. If Vec object contains none Complex values, an exception will be raised. *) function ThresholdLT(const Vec: TOpenCLMtxVec; LTLevel: double; const LTValue: TCplx): TOpenCLMtxVec; overload; (*Perform "less than" threshold operation for complex numbers on Vec elements from range [VecIndex]..[VecIndex+Len-1]. Store the results in the calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if array borders are overrun/underrun. If Vec object or calling object contain none Complex values, an exception will be raised. *) function ThresholdLT(const Vec: TOpenCLMtxVec; LTLevel: double; const LTValue: TCplx; VecIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Threshold greater than operation. Perform operation on all calling object values. The GTValue parameter is an upper bound for threshold operation. All values bigger than LTLevel will be replaced with GTValue. For complex number comparation is applied with norm of complex value. var a: clVector; begin a.CopyFromArray(TSingleArray.Create(2,0.1,3,4)); a.ThresholdGT(2.3,3.4); // a = [2,0.1,3.4,3.4] end; *) function ThresholdGT(GTLevel, GTValue: double): TOpenCLMtxVec; overload; (*Perfrom "greater than" threshold operation on the calling object values in range [Index]..[Index+Len-1]. An exception is raised if array borders are overrun/underrun. *) function ThresholdGT(GTLevel, GTValue: double; Index, Len: integer): TOpenCLMtxVec; overload; (*Perform "greater than" threshold operation on all Vec object values. Store the results in calling object. Size and properties of the calling object are adjusted automatically. *) function ThresholdGT(const Vec: TOpenCLMtxVec; GTLevel, GTValue: double): TOpenCLMtxVec; overload; (*Perform "greater than" threshold operation on Vec elements from range [VecIndex]..[VecIndex+Len-1]. Store the results in the calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if array borders are overrun/underrun. An exception will be raised if Vec.Complex and Complex of the calling object are not equal. *) function ThresholdGT(const Vec: TOpenCLMtxVec; GTLevel, GTValue: double; VecIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Perfrom "greater than" threshold operation for complex numbers. If the calling object contains none Complex values, an exception will be raised. *) function ThresholdGT(GTLevel: double; const GTValue: TCplx): TOpenCLMtxVec; overload; (*Perfrom "greater than" threshold operation for complex numbers on the calling object values in range [Index]..[Index+Len-1]. An exception is raised if array borders are overrun/underrun. If the calling object contains none Complex values, an exception will be raised. *) function ThresholdGT(GTLevel: double; const GTValue: TCplx; Index, Len: integer): TOpenCLMtxVec; overload; (*Perform "greater than" threshold operation for complex numbers on all Vec object values. Store the results in calling object. Size and properties of the calling object are adjusted automatically. If Vec object contains none Complex values, an exception will be raised. *) function ThresholdGT(const Vec: TOpenCLMtxVec; GTLevel: double; const GTValue: TCplx): TOpenCLMtxVec; overload; (*Perform "greater than" threshold operation for complex numbers on Vec elements from range [VecIndex]..[VecIndex+Len-1]. Store the results in the calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if array borders are overrun/underrun. If Vec object or calling object contain none Complex values, an exception will be raised. *) function ThresholdGT(const Vec: TOpenCLMtxVec; GTLevel: double; const GTValue: TCplx; VecIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Threshold greater than and less than operation. Perform operation on all calling object values. The LTValue parameter is an lower bound for threshold operation. The GTValue parameter is an upper bound for threshold operation. All values less than LTLevel will be replaced with LTValue. All values bigger than GTLevel will be replaced with GTValue. Operation is available only for none Complex values. var a: clVector; begin a.CopyFromArray(TSingleArray.Create(2,0.1,3,4)); a.ThresholdGT_LT(2.3,3.4,1,0.5); // a = [2,0.5,3.4,3.4] end; *) function ThresholdGT_LT (GTLevel, GTValue, LTLevel, LTValue: double): TOpenCLMtxVec; overload; (*Perfrom "greater than and less than" threshold operation on the calling object values in range [Index]..[Index+Len-1]. An exception is raised if array borders are overrun/underrun. An exception will be raised if the calling object contains complex numbers. *) function ThresholdGT_LT (GTLevel, GTValue, LTLevel, LTValue: double; Index, Len: integer): TOpenCLMtxVec; overload; (*Perform "greater than and less than" threshold operation on all Vec object values. Store the results in calling object. Size and properties of the calling object are adjusted automatically. An exception will be raised if Vec object contains complex numbers. *) function ThresholdGT_LT (const Vec: TOpenCLMtxVec; GTLevel, GTValue, LTLevel, LTValue: double): TOpenCLMtxVec; overload; (*Perform "greater than and less than" threshold operation on Vec elements from range [VecIndex]..[VecIndex+Len-1]. Store the results in the calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if array borders are overrun/underrun. An exception will be raised if Vec object or the calling object contain complex numbers. *) function ThresholdGT_LT(const Vec: TOpenCLMtxVec; GTLevel, GTValue, LTLevel, LTValue: double; VecIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Rounds a real number towards zero and returns the fractional part. Rounds all calling object elements towards zero to an integer and stores the result in the TruncDst object as floating point numbers. The fractional part is stored in the FracDst. *) procedure TruncAndFrac(TruncDst: TOpenCLMtxVec; FracDst: TOpenCLMtxVec); overload; (*Truncate calling object elements [Index]..[Index+Len-1] and store the results to TruncDst object elements [TruncIdx]..[TruncIdx+Len-1]. The fractional parts are saved in FracDst elements [FracIdx]..[FracIdx+Len-1]. Size and property of calling object must be set explicitly to match those of Src object. An exception is raised if array borders are overrun/underrun. *) procedure TruncAndFrac(TruncDst: TOpenCLMtxVec; FracDst: TOpenCLMtxVec; TruncIdx, FracIdx, Index, Len: integer); overload; (*Rounds a real number towards zero. Rounds all calling object elements towards zero to an integer and stores the result in the calling object again as floating point numbers. *) function Trunc: TOpenCLMtxVec; overload; (*Truncate calling object elements [Index]..[Index+Len-1] in-place. An exception is raised if array borders are overrun/underrun. *) function Trunc(Index,Len: integer): TOpenCLMtxVec; overload; (*Truncate all Src object elements. Store the results in calling object elements. Size and property of calling object are adjusted automatically. *) function Trunc(const Src: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Truncate Src object elements [SrcIndex]..[SrcIndex+Len-1]. Store the results to calling object elemenents [Index]..[Index+Len-1]. Size and property of calling object must be set explicitly to match those of Src object. An exception is raised if array borders are overrun/underrun. *) function Trunc(const Src: TOpenCLMtxVec; SrcIndex, Index,Len: integer): TOpenCLMtxVec; overload; (*The inverse of cube root 1/(v)^1/3. Calculate the inverse cube root (1/(element)^(1/3)) of all calling object elements in-place. v.CopyFromArray(TSingleArray.Create(1,8)); v.InvCbrt; // returns [1,0.5] *) function InvCbrt: TOpenCLMtxVec; overload; (*Calculate the inverse of cube root for calling object elements [Index]..[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function InvCbrt(Index, Len: integer): TOpenCLMtxVec; overload; (*Calculate the inverse of cube root for all X elements. Store the results in the calling object. Size and properties of the calling vector are set implicitly to match the X object. *) function InvCbrt(const X: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Calculate the inverse of cube root for X elements [XIndex]..[XIndex+Len-1]. Store the results in the calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if array borders are overrun. *) function InvCbrt(const X: TOpenCLMtxVec; XIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*The inverse of square root 1/(v)^1/2. Calculate the inverse square root 1/(element)^(1/2)) of all calling object elements in-place. v.CopyFromArray(TSingleArray.Create(1,16)); v.InvSqrt; // returns [1,0.25] *) function InvSqrt: TOpenCLMtxVec; overload; (*Calculate the inverse of square root for calling object elements [Index]..[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function InvSqrt(Index, Len: integer): TOpenCLMtxVec; overload; (*Calculate the inverse of square root for all X elements. Store the results in the calling object. Size and properties of the calling vector are set implicitly to match the X object. *) function InvSqrt(const X: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Calculate the inverse of square root for X elements [XIndex]..[XIndex+Len-1]. Store the results in the calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if array borders are overrun. *) function InvSqrt(const X: TOpenCLMtxVec; XIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Magnitude. Calculate the magnitude for all calling object elements in-place. This method has the same function as the method. var a: clVector; begin a.CopyFromArray(TSingleArray.Create(1,-2,3,4)); // a = [1,-2, 3,4] a.Mag; // a = [1, 2, 3,4] end; *) function Mag: TOpenCLMtxVec; overload; (*Calculate the magnitude for calling object elements [Index]..[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function Mag(Index, Len: integer): TOpenCLMtxVec; overload; (*Calculate the magnitude for all X elements. Store the results in the calling object elements. Size and properties of the calling vector are set implicitly to match Vec vector. *) function Mag(const X: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Calculate the magnitude for X elements [XIndex]..[XIndex+Len-1]. Store the results in the calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if array borders are overrun. *) function Mag(const X: TOpenCLMtxVec; XIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Multiply Vec1 elements [Vec1Index]..[Vec1Index+Len-1] with Vec2 object elements [Vec2Index]..[Vec2Index+Len-1]. Store the results in calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if array borders are overrun or underrun. *) function Mul(const Vec1, Vec2: TOpenCLMtxVec; Vec1Index, Vec2Index, Index, Len: integer): TOpenCLMtxVec; overload; (*Multiply all Vec1 elements with corresponding Vec2 elements. Store the results in calling object. Size and property of calling object are adjusted automatically to match those of Vec1 and Vec2. An exception is raised if Vec1 and Vec2 size and property do not match. *) function Mul(const Vec1, Vec2: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Vector multiplication. Multiply each of Vec elements with corresponding elements in the calling object. Size and property of the calling object are set automatically. The result is stored in the calling object. *) function Mul(const Vec: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Multiply Vec elements [VecIndex]..[VecIndex+Len-1] with calling object elements [Index]..[Index+Len-1] in-place. An exception is raised if Vec and calling object property do not match or if array borders are overrun/underrun. *) function Mul(const Vec: TOpenCLMtxVec; VecIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Multiply object elements with Value. Multiplies all calling object elements with Value in-place. var v: clVector; begin v.CopyFromArray(TSingleArray.Create(2,3,5)); // v = [2,3,5] v.Mul(3); // v = [6,9,15] end; *) function Mul(const Value: double): TOpenCLMtxVec; overload; (*Multiply all calling object elements with complex Value in-place.*) function Mul(const Value: TCplx): TOpenCLMtxVec; overload; (*Multipy calling object elements [Index]..[Index+Len-1] with Value in-place. An exception is raised if array borders are overrun or underrun. *) function Mul(const Value: double; Index, Len: integer): TOpenCLMtxVec; overload; (*Multipy calling object elements [Index]..[Index+Len-1] with complex Value in-place. An exception is raised if array borders are overrun or underrun. *) function Mul(const Value: TCplx; Index, Len: integer): TOpenCLMtxVec; overload; (*Multiply each element of Vec with Value. Store the result in the calling object. Size and properties of the calling object are adjusted automatically. *) function Mul(const Vec: TOpenCLMtxVec; const Value: double): TOpenCLMtxVec; overload; (*Multiply each element of Vec with complex Value. Store the result in the calling object. Size of the calling object is set automatically. property of the calling object is set to True. *) function Mul(const Vec: TOpenCLMtxVec; const Value: TCplx): TOpenCLMtxVec; overload; (*Multiply Vec elements [VecIndex]..[VecIndex+Len-1] with Value. Store the result in calling object elements [Index]..[Index+Len-1]. Size of the calling object is not changed. An exception is raised if array borders are overrun or underrun. propertiy of the calling object is set implicitly. *) function Mul(const Vec: TOpenCLMtxVec; const Value: double; VecIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Multiply Vec elements [VecIndex]..[VecIndex+Len-1] with complex Value. Store the result in calling object elements [Index]..[Index+Len-1]. Size of the calling object is not changed. An exception is raised if array borders are overrun or underrun. propertiy of the calling object is set to True. *) function Mul(const Vec: TOpenCLMtxVec; const Value: TCplx; VecIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Multiply elements by imaginary unit I.*) function MulI: TOpenCLMtxVec; overload; (*Multipy calling object elements [Index]..[Index+Len-1] with I in-place.*) function MulI(Index: integer; Len: integer): TOpenCLMtxVec; overload; (*Multiply X elements with I and store the result in the calling object.*) function MulI(const X: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Multipy X elements [XIndex]..[XIndex+Len-1] with I. Xtore the result in the calling object at locations [Index]..[Index+Len-1]. *) function MulI(const X: TOpenCLMtxVec; XIndex: integer; Index: integer; Len: integer): TOpenCLMtxVec; overload; (*The phase angles (spectrum) of object elements. Calculates the phase angles (spectrum) of all Vec object elements. Phase values are returned in radians and are in the range -PI,PI. Size and properties of the calling object are set implicitly to match Vec object. The phase angles are calculated from the following equation: var a,b: clVector; begin a.CopyFromArray(TSingleArray.Create(1,2,3,-4)); // a = [1 + 2i, 3 - 4i] b.PhaseSpectrum(a); // b = [arctan2(1,2), arctan2(3,-4)]; end; *) function PhaseSpectrum(const Vec: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Calculates the power spectrum from the Vec elements [VecIndex]..[VecIndex+Len-1]. Store the results in calling object elements [Index]..[Index+Len-1]. An exception is raised if array borders are overrun/underrun. *) function PhaseSpectrum(const Vec: TOpenCLMtxVec; VecIndex, Index,Len: integer): TOpenCLMtxVec; overload; (*The power spectrum from object complex values. Calculates the power spectrum from the Vec object complex values and stores the results (power spectrum) in the real calling object. Size and properties of the calling object are set implicitly to match Vec object. The spectrum elements are squares of the magnitudes of the complex input elements: var a,b: clVector; begin a.CopyFromArray(TSingleArray.Create(1,2,3,-4)); // a = [1 + 2i, 3 - 4i] b.PowerSpectrum(a); // b = [1*1 + 2*2, 3*3+(-4)*(-4)] end; *) function PowerSpectrum(const Vec: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Calculates the power spectrum from the Vec complex elements [VecIndex]..[VecIndex+Len-1]. Store the results in calling object real elements [Index]..[Index+Len-1]. An exception is raised if calling object property is true or if array borders are overrun/underrun. *) function PowerSpectrum(const Vec: TOpenCLMtxVec; VecIndex, Index,Len: integer): TOpenCLMtxVec; overload; (*Converts the polar magnitude/phase pairs to cartesian pairs. Convert all AmpltVec and PhaseVec elements (combined) from polar to cartesian form. If AmpltVec and PhaseVec size is not the same , an exeption is raised. The results are stored as complex numbers (x=Re, y=Im) in the calling object. Size and properties of the calling object are set implicitly to match AmpltVec and PhaseVec objects. var a,b,c: clVector; begin a.CopyFromArray(TSingleArray.Create(1,2,3,4)); // a = [1,2,3, 4] //magnitude b.CopyFromArray(TSingleArray.Create(1,0,1,-1)); // b = [1,0,1,-1] /phase c.PolarToCart(a,b); // result stored in c = projections to Re and Im axis end; *) function PolarToCart(AmpltVec, PhaseVec: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Convert AmpltVec elements [AIndex]..[AIndex+Len-1] and PhaseVec elements [PIndex]..[PIndex+Len-1] from polar form (radius,angle) to cartesian form (x,y). The results are stored as complex numbers (x=Re, y=Im) in the calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if array borders are overrun/underrun. *) function PolarToCart(AmpltVec, PhaseVec: TOpenCLMtxVec; AIndex, PIndex,Index, Len: integer): TOpenCLMtxVec; overload; (*Gets real part of complex object values. The method method gets the real part of a complex object Vec and stores the real results in the calling object. Size and properties of the calling object are set implicitly to match Vec object. Vec property must be true otherwise an exception is raised. var a,b: clVector; begin a.CopyFromArray(TSingleArray.Create(1,2,3,4)); // = [1+2i, 3+4i] b.RealPart(a); // b = [1,3] end; *) function RealPart(const Vec: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Gets the real part of a Vec object complex elements [VecIndex]..[VecIndex+Len-1]. Stores the results in calling object real elements [Index]..[Index+Len-1]. An exception is raised if array borders are overrun or underrun or if Vec object propety is false. *) function RealPart(const Vec: TOpenCLMtxVec; VecIndex,Index,Len: integer): TOpenCLMtxVec; overload; (*Square. Calculate the square of all caling object elements in-place. var a: clVector; begin a.CopyFromArray(TSingleArray.Create(1,2,3,4)); a.Sqr; // a=[1,4,9,16] end; *) function Sqr: TOpenCLMtxVec; overload; (*Calculate the square of calling object elements [Index]...[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function Sqr(Index, Len: integer): TOpenCLMtxVec; overload; (*Calculate the square of all X object elements. Store the results in the calling object. Size and properties of calling object are adjusted automatically. *) function Sqr(const X: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Calculate the square of X object elements [XIndex]..[XIndex+Len-1]. The results are stored in calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object are not changed. An exception is raised if array borders are overrun. *) function Sqr(const X: TOpenCLMtxVec; XIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Square root. Calculate the square root of all caling object elements in-place. var a: clVector; begin a.CopyFromArray(TSingleArray.Create(1,4,9,16)); a.Sqrt; // a= [1, 2, 3, 4] end; *) function Sqrt: TOpenCLMtxVec; overload; (*Calculate the square root of calling object elements [Index]...[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function Sqrt(Index, Len: integer): TOpenCLMtxVec; overload; (*Calculate the square root of all X object elements. Store the results in the calling object. Size and properties of the calling object are adjusted automatically. *) function Sqrt(const X: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Calculate the square root of X object elements [XIndex]..[XIndex+Len-1]. The results are stored in calling object elements [Index]..[Index+Len-1]. Size and properties of calling object are not changed. An exception is raised if array borders are overrun. *) function Sqrt(const X: TOpenCLMtxVec; XIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Sine function. Calculate the sine of all caling object elements in-place. var a: clVector; begin a.CopyFromArray(TSingleArray.Create(1,-2,3,4)); a.Sin; // Computes complex sine end; *) function Sin: TOpenCLMtxVec; overload; (*Calculate the sine of calling object elements [Index]...[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function Sin(Index: integer; Len: integer): TOpenCLMtxVec; overload; (*Calculate the sine of all X object elements and store the results in calling object. Size and properties of calling object are adjusted automatically. *) function Sin(const X: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Calculate the sine of X object elements [XIndex]...[XIndex+Len-1]. The results are stored in calling object elements [Index]...[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if array borders are overrun. *) function Sin(const X: TOpenCLMtxVec; XIndex: integer; Index: integer; Len: integer): TOpenCLMtxVec; overload; (*Cosine. Calculate the cosine of all caling object elements in-place. var a: clVector; begin a.CopyFromArray(TSingleArray.Create(1,-2,3,4)); a.Cos; // Computes complex sine end; *) function Cos: TOpenCLMtxVec; overload; (*Calculate the cosine of calling object elements [Index]...[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function Cos(Index: integer; Len: integer): TOpenCLMtxVec; overload; (*Calculate the cosine of all X object elements. Store the results in the calling object.vSize and properties of calling object are adjusted automatically. *) function Cos(const X: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Calculate the cosine of X object elements [XIndex]...[XIndex+Len-1]. The results are stored in calling object elements [Index]...[Index+Len-1]. Size and properties of calling object and the calling object must be set explicitly. An exception is raised if array borders are overrun. *) function Cos(const X: TOpenCLMtxVec; XIndex: integer; Index: integer; Len: integer): TOpenCLMtxVec; overload; (*Tangens. Calculate the tangens of all caling object elements in-place. var a: clVector; begin a.CopyFromArray(TSingleArray.Create(1,-2,3,4)); a.Tan; // Computes complex tangens end; *) function Tan: TOpenCLMtxVec; overload; (*Calculate the tangens of calling object elements [Index]...[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function Tan (Index: integer; Len: integer): TOpenCLMtxVec; overload; (*Calculate the tangens of all X object elements. Store the results in the calling object. Size and properties of calling object are adjusted automatically. *) function Tan(const X: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Calculate the tangens of X object elements [XIndex]...[XIndex+Len-1]. The results are stored in calling object elements [Index]...[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if array borders are overrun. *) function Tan(const X : TOpenCLMtxVec; XIndex: integer; Index: integer; Len: integer): TOpenCLMtxVec; overload; (*Cotangens. Calculate the cotangens of all caling object elements in-place. var a: clVector; begin a.CopyCplxFromArray(TSingleArray.Create(1,-2,3,4)); a.Cot; // Computes complex cotangens end; *) function Cot: TOpenCLMtxVec; overload; (*Calculate the cotangens of calling object elements [Index]...[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function Cot(Index, Len: integer): TOpenCLMtxVec; overload; (*Calculate the cotangens of all X object elements. Store the results in the calling object. Size and properties of calling object are adjusted automatically. *) function Cot(const X: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Calculate the cotangens of X object elements [XIndex]...[XIndex+Len-1]. The results are stored in calling object elements [Index]...[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if array borders are overrun. *) function Cot(const X: TOpenCLMtxVec; XIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Secant. Calculate the secant of all caling object elements in-place. var a: clVector; begin a.CopyCplxFromArray(TSingleArray.Create(1,-2,3,4)); a.Sec; // Computes complex secant end; *) function Sec: TOpenCLMtxVec; overload; (*Calculate the secant of calling object elements [Index]...[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function Sec(Index, Len: integer): TOpenCLMtxVec; overload; (*Calculate the secant of all X object elements. Store the results in the calling object. Size and properties of calling object are adjusted automatically. *) function Sec(const X: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Calculate the secant of X object elements [XIndex]...[XIndex+Len-1]. The results are stored in calling object elements [Index]...[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if array borders are overrun. *) function Sec(const X: TOpenCLMtxVec; XIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Cosecant. Calculate the cosecant of all caling object elements in-place. var a: clVector; begin a.CopyFromArray(TSingleArray.Create(1,-2,3,4)); // a = [1-2i, 3+4i] a.Csc; // Computes complex cosecant end; *) function Csc: TOpenCLMtxVec; overload; (*Calculate the cosecant of calling object elements [Index]...[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function Csc(Index, Len: integer): TOpenCLMtxVec; overload; (*Calculate the cosecant of all X object elements. Store the results in the calling object. Size and properties of calling object are adjusted automatically. *) function Csc(const X: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Calculate the cosecant of X object elements [XIndex]...[XIndex+Len-1]. The results are stored in calling object elements [Index]...[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if array borders are overrun. *) function Csc(const X: TOpenCLMtxVec; XIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*The inverse sine. Calculate the inverse sine of all calling object elements in-place. Values must be between -1 and 1. The return values will be in the range [0,], in radians. var a: clVector; begin a.CopyFromArray(TSingleArray.Create(1,-0.5,0.11,0.9)); a.ArcSin; end; *) function ArcSin: TOpenCLMtxVec; overload; (*Calculate the inverse sine of calling object elements [Index]...[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function ArcSin(Index, Len: integer): TOpenCLMtxVec; overload; (*Calculate the inverse sine of all X object elements. Store the results in the calling object. Size and properties of calling object are adjusted automatically. *) function ArcSin(const X: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Calculate the inverse sine of X object elements [XIndex]...[XIndex+Len-1]. The results are stored in calling object elements [Index]...[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if array borders are overrun. *) function ArcSin(const X: TOpenCLMtxVec; XIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*The inverse cosine. Calculate the inverse cosine of all calling object elements in-place. Values must be between -1 and 1. The return values will be in the range [0,], in radians. var a: clVector; begin a.CopyFromArray(TSingleArray.Create(1,-0.5,0.11,0.9)); a.ArcCos; end; *) function ArcCos: TOpenCLMtxVec; overload; (*Calculate the inverse cosine of calling object elements [Index]...[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function ArcCos(Index, Len: integer): TOpenCLMtxVec; overload; (*Calculate the inverse cosine of all X object elements. Store the results in the calling object. Size and properties of calling object are adjusted automatically. *) function ArcCos(const X: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Calculate the inverse cosine of X object elements [XIndex]...[XIndex+Len-1]. The results are stored in calling object elements [Index]...[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if array borders are overrun. *) function ArcCos(const X: TOpenCLMtxVec; XIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Inverse tangens of Y/X. Calculates the inverse tangens of Y/X, and returns an angle in the correct quadrant. The results are stored in calling object elements. Size and properties of calling object are adjusted automatically to match those of X and Y objects. An exception is raised if X and Y size and properties do not match. Note that is calculated as ArcTan2(1, X). *) function ArcTan2(Y, X: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Calculate the inverse tangens of Y/X. Calculation uses Y elements [YIndex]..[YIndex+Len-1], X elements [XIndex]..[XIndex+Len-1] and stores the results in calling object elements [Index]..[Index+Len-1]. An exception is raised if array borders are overrun. *) function ArcTan2(Y, X: TOpenCLMtxVec; YIndex, XIndex, Index: integer; Len: integer): TOpenCLMtxVec; overload; (*Inverse tangens. Calculate the inverse tangens for all calling object elements in-place. The return values are expressed in radians. var A,B: clVector; begin A.CopyCplxFromArray(TSingleArray.Create(1,0, 2,0, 2,0 4,1)); B.ArcTan(A); end; *) function ArcTan: TOpenCLMtxVec; overload; (*Calculate the inverse tangens of calling object elements [Index]...[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function ArcTan(Index, Len: integer): TOpenCLMtxVec; overload; (*Calculate the inverse tangens of all X object elements. Store the results in the calling object. Size and properties of calling object are adjusted automatically. *) function ArcTan(const X: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Calculate the inverse tangens of X object elements [XIndex]...[XIndex+Len-1]. The results are stored in calling object elements [Index]...[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if array borders are overrun. *) function ArcTan(const X: TOpenCLMtxVec; XIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Inverse cotangens. Calculate the inverse cotangens for all calling object elements in-place. The return values are expressed in radians. var A,B: clVector; begin A.CopyCplxFromArray(TSingleArray.Create(1,0, 2,0, 2,0 4,1)); B.ArcCot(A); end; *) function ArcCot: TOpenCLMtxVec; overload; (*Calculate the inverse cotangens of calling object elements [Index]...[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function ArcCot(Index, Len: integer): TOpenCLMtxVec; overload; (*Calculate the inverse cotangens of all X object elements. Store the results in the calling object. Size and properties of calling object are adjusted automatically. *) function ArcCot(const X: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Calculate the inverse cotangens of X object elements [XIndex]...[XIndex+Len-1]. The results are stored in calling object elements [Index]...[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if array borders are overrun. *) function ArcCot(const X: TOpenCLMtxVec; XIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Inverse secant. Calculate the inverse secant for all calling object elements in-place. *) function ArcSec: TOpenCLMtxVec; overload; (*Calculate the inverse secant of calling object elements [Index]...[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function ArcSec(Index, Len: integer): TOpenCLMtxVec; overload; (*Calculate the inverse secant of all X object elements and store the results in the calling object. Size and properties of calling object are adjusted automatically. *) function ArcSec(const X: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Calculate the inverse secant of X object elements [XIndex]...[XIndex+Len-1]. The results are stored in calling object elements [Index]...[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if array borders are overrun. *) function ArcSec(const X: TOpenCLMtxVec; XIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Inverse cosecant. Calculate the inverse cosecant for all calling object elements in-place. *) function ArcCsc: TOpenCLMtxVec; overload; (*Calculate the inverse cosecant of calling object elements [Index]...[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function ArcCsc(Index, Len: integer): TOpenCLMtxVec; overload; (*Calculate the inverse cosecant of all X object elements. Store the results in the calling object. Size and properties of calling object are adjusted automatically. *) function ArcCsc(const X: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Calculate the inverse cosecant of X object elements [XIndex]..[XIndex+Len-1]. The results are stored in the calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if array borders are overrun. *) function ArcCsc(const X: TOpenCLMtxVec; XIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Hyperbolic sine. Calculate the hyperbolic sine of all caling object elements in-place. var A,B: clVector; begin A.CopyFromArray(TSingleArray.Create(1,0, 2,0, 2,0 4,1)); B.Sinh(A); end; *) function Sinh: TOpenCLMtxVec; overload; (*Calculate the hyperbolic sine of calling object elements [Index]...[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function Sinh(Index, Len: integer): TOpenCLMtxVec; overload; (*Calculate the hyperbolic sine of all X object elements. Store the results in the calling object. Size and properties of calling object are adjusted automatically. *) function Sinh(const X: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Calculate the hyperbolic sine for X object elements [XIndex]..[XIndex+Len-1]. The results are stored in the calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if array borders are overrun. *) function Sinh(const X: TOpenCLMtxVec; XIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Hyperbolic cosine. Calculate the hyperbolic cosine of all caling object elements in-place. var A,B: clVector; begin A.CopyFromArray(TSingleArray.Create(1,0, 2,0, 2,0 4,1)); B.Cosh(A); end; *) function Cosh: TOpenCLMtxVec; overload; (*Calculate the hyperbolic cosine for calling object elements [Index]..[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function Cosh(Index, Len: integer): TOpenCLMtxVec; overload; (*Calculate the hyperbolic cosine for all X object elements. Store the results in the calling object. Size and properties of calling object are adjusted automatically. *) function Cosh(const X: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Calculate the hyperbolic cosine for X object elements [XIndex]..[XIndex+Len-1]. The results are stored in calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if array borders are overrun. *) function Cosh(const X: TOpenCLMtxVec; XIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Hyperbolic tangens. Calculate the hyperbolic tangens of all caling object elements in-place. var A,B: clVector; begin A.CopyFromArray(TSingleArray.Create(1,0, 2,0, 2,0 4,1)); B.Tanh(A); end; *) function Tanh: TOpenCLMtxVec; overload; (*Calculate the hyperbolic tangens for calling object elements [Index]..[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function Tanh(Index, Len: integer): TOpenCLMtxVec; overload; (*Calculate the hyperbolic tangens for all X object elements. Store the results in the calling object. Size and properties of calling object are adjusted automatically. *) function Tanh(const X: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Calculate the hyperbolic tangens for X object elements [XIndex]..[XIndex+Len-1]. The results are stored in the calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if array borders are overrun. *) function Tanh(const X: TOpenCLMtxVec; XIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Hyperbolic cotangens. Calculate the hyperbolic cotangens of all caling object elements in-place. var A,B: clVector; begin A.CopyFromArray(TSingleArray.Create(1,0, 2,0, 2,0 4,1)); B.Coth(A); end; *) function Coth: TOpenCLMtxVec; overload; (*Calculate the hyperbolic cotangens for calling object elements [Index]...[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function Coth(Index, Len: integer): TOpenCLMtxVec; overload; (*Calculate the hyperbolic cotangens for all X object elements. Store the results in the calling object. Size and properties of calling object are adjusted automatically. *) function Coth(const X: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Calculate the hyperbolic cotangens for X object elements [XIndex]..[XIndex+Len-1]. The results are stored in calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if array borders are overrun. *) function Coth(const X: TOpenCLMtxVec; XIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Hyperbolic secant. Calculate the hyperbolic secant of all caling object elements in-place. *) function Sech: TOpenCLMtxVec; overload; (*Calculate the hyperbolic secant for calling object elements [Index]...[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function Sech(Index, Len: integer): TOpenCLMtxVec; overload; (*Calculate the hyperbolic secant for all X object elements. Store the results in the calling object. Size and properties of calling object are adjusted automatically. *) function Sech(const X: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Calculate the hyperbolic secant for X object elements [XIndex]..[XIndex+Len-1]. The results are stored in calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if array borders are overrun. *) function Sech(const X: TOpenCLMtxVec; XIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Hyperbolic cosecant. Calculate the hyperbolic cosecant of all caling object elements in-place. *) function Csch: TOpenCLMtxVec; overload; (*Calculate the hyperbolic cosecant for calling object elements [Index]..[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function Csch(Index, Len: integer): TOpenCLMtxVec; overload; (*Calculate the hyperbolic cosecant for all X object elements. Store the results in the calling object. Size and properties of calling object are adjusted automatically. *) function Csch(const X: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Calculate the hyperbolic cosecant for X object elements [XIndex]..[XIndex+Len-1]. The results are stored in calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if array borders are overrun. *) function Csch(const X: TOpenCLMtxVec; XIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Absolute values. Calculate the absolute value of all calling object elemets in-place. var A,B: clVector; begin A.CopyFromArray(TSingleArray.Create(1,-2,3,4)); B.Abs(A); // B = [1,2,3,4] end; *) function Abs: TOpenCLMtxVec; overload; (*Calculate the absolute value for calling object elements [Index]..[Index+Len-1]. An exception is raised if array borders are overrun or underrun. *) function Abs(Index, Len: integer): TOpenCLMtxVec; overload; (*Calculate the absolute value for all X object and store the results in the calling object. Size and properties of calling object are adjusted automatically. *) function Abs(const X: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Calculate the absolute value of X object elements [XIndex]..[XIndex+Len-1]. Store the results in calling object elements [Index]..[Index+Len-1]. An exception is raised if array borders are overrun or underrun. *) function Abs(const X: TOpenCLMtxVec; XIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Inverse hyperbolic sine. Calculate the inverse hyperbolic sine for all caling object elements in-place. *) function ArcSinh: TOpenCLMtxVec; overload; (*Calculate the inverse hyperbolic sine for calling object elements [Index]..[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function ArcSinh(Index, Len: integer): TOpenCLMtxVec; overload; (*Calculate the inverse hyperbolic sine for all X object elements. Store the results in the calling object. Size and properties of calling object are adjusted automatically. *) function ArcSinh(const X: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Calculate the inverse hyperbolic sine for X object elements [XIndex]..[XIndex+Len-1]. The results are stored in calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if array borders are overrun. *) function ArcSinh(const X: TOpenCLMtxVec; XIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Inverse hyperbolic cosine. Calculate the inverse hyperbolic cosine for all caling object elements in-place. *) function ArcCosh: TOpenCLMtxVec; overload; (*Calculate the inverse hyperbolic cosine for calling object elements [Index]..[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function ArcCosh(Index, Len: integer): TOpenCLMtxVec; overload; (*Calculate the inverse hyperbolic cosine for all X object elements. Store the results in the calling object. Size and properties of calling object are adjusted automatically. *) function ArcCosh(const X: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Calculate the inverse hyperbolic cosine for X object elements [XIndex]..[XIndex+Len-1]. The results are stored in calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if array borders are overrun. *) function ArcCosh(const X: TOpenCLMtxVec; XIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Inverse hyperbolic tangens. Calculate the inverse hyperbolic tangens for all caling object elements in-place. *) function ArcTanh: TOpenCLMtxVec; overload; (*Calculate the inverse hyperbolic tangens for calling object elements [Index]..[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function ArcTanh(Index, Len: integer): TOpenCLMtxVec; overload; (*Calculate the inverse hyperbolic tangens for all X object elements. Store the results in the calling object. Size and properties of calling object are adjusted automatically. *) function ArcTanh(const X: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Calculate the inverse hyperbolic tangens for X object elements [XIndex]..[XIndex+Len-1]. The results are storedi n the calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if array borders are overrun. *) function ArcTanh(const X: TOpenCLMtxVec; XIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Inverse hyperbolic cotangens. Calculate the inverse hyperbolic cotangens for all caling object elements in-place. *) function ArcCoth: TOpenCLMtxVec; overload; (*Calculate the inverse hyperbolic cotangens for calling object elements [Index]..[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function ArcCoth(Index, Len: integer): TOpenCLMtxVec; overload; (*Calculate the inverser hyperbolic cotangens for all X object elements. Store the results in calling object. Size and properties of calling object are adjusted automatically. *) function ArcCoth(const X: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Calculate the inverse hyperbolic cotangens for X object elements [XIndex]..[XIndex+Len-1]. The results are stored in the calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if array borders are overrun. *) function ArcCoth(const X: TOpenCLMtxVec; XIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Inverse hyperbolic secant. Calculate the inverse hyperbolic secant for all caling object elements in-place. *) function ArcSech: TOpenCLMtxVec; overload; (*Calculate the inverse hyperbolic secant for calling object elements [Index]..[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function ArcSech(Index, Len: integer): TOpenCLMtxVec; overload; (*Calculate the inverse hyperbolic secant for all X object elements. Store the results in calling object. Size and properties of calling object are adjusted automatically. *) function ArcSech(const X: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Calculate the inverse hyperbolic secant for X object elements [XIndex]..[XIndex+Len-1]. The results are stored in calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if array borders are overrun. *) function ArcSech(const X: TOpenCLMtxVec; XIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Inverse hyperbolic cosecant. Calculate the inverse hyperbolic cosecant for all caling object elements in-place. *) function ArcCsch: TOpenCLMtxVec; overload; (*Calculate the inverse hyperbolic cosecant for calling object elements [Index]...[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function ArcCsch(Index, Len: integer): TOpenCLMtxVec; overload; (*Calculate the inverse hyperbolic cosecant for all X object elements. Store the results in calling object. Size and properties of calling object are adjusted automatically. *) function ArcCsch(const X: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Calculate the inverse hyperbolic cosecant for X object elements [XIndex]..[XIndex+Len-1]. The results are stored in calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if array borders are overrun. *) function ArcCsch(const X: TOpenCLMtxVec; XIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*The cube root. Calculate the cube root of all calling object elements in-place. var A,B: clVector; begin A.CopyFromArray(TSingleArray.Create(1,8)); B.Cbrt(A); // B = [1,2] end; *) function Cbrt: TOpenCLMtxVec; overload; (*Calculate the cube root of calling object elements [Index]..[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function Cbrt(Index, Len: integer): TOpenCLMtxVec; overload; (*Calculate the cube root of all X object elements. Store the results in calling object. Size and properties of calling object are adjusted automatically. *) function Cbrt(const X: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Calculate the cube root of X object elements [XIndex]..[XIndex+Len-1]. The results are stored in the calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if array borders are overrun. *) function Cbrt(const X: TOpenCLMtxVec; XIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Rounds towards positive infinity. Rounds all calling object elements towards positive infinity in-place. Ceil(-2.8) = -2 Ceil(2.8) = 3 Ceil(-1.0) = -1 *) function Ceil: TOpenCLMtxVec; overload; (*Rounds calling object elements [Index]..[Index+Len-1] towards positive infinity in-place. An exception is raised if array borders are overrun. *) function Ceil(Index,Len: integer): TOpenCLMtxVec; overload; (*Rounds all Src object elements towards positive infinity. Stores the result in the calling object. Size and properties of the calling object are adjusted automatically. *) function Ceil(const Src: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Rounds Src object elements [SrcIndex]..[SrcIndex+Len-1] towards positive infinity. Stores the result in the calling object elements [Index]..[Index+Len-1] Size and properties of the calling object must be set explicitly. An exception is raised if array borders are overrun. *) function Ceil(const Src: TOpenCLMtxVec; SrcIndex, Index,Len: integer): TOpenCLMtxVec; overload; (*Natural logarithm. Calculate the natural log for all calling object elements in-place. var A,B: clVector; begin A.CopyFromArray(TSingleArray.Create(1,2,3,4)); B.Ln(A); end; *) function Ln: TOpenCLMtxVec; overload; (*Calculate the natural algorithm for all X elements. Store the results in the calling object. Size and properties of the calling vector are set implicitly to match the X object. *) function Ln(const X: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Calculate the natural logarithm for calling object elements [Index]..[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function Ln(Index, Len: integer): TOpenCLMtxVec; overload; (*Calculate the natural logarithm for X elements [XIndex]..[XIndex+Len-1]. Store the results in the calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if array borders are overrun. *) function Ln(const X: TOpenCLMtxVec; XIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Log base 10. Calculate the log base 10 for all calling object elements in-place. var a: clVector; begin a.CopyFromArray(TSingleArray.Create(10,100,1000,10000)); // a = [10,100,1000,10000] a.Log10; // a = [1,2,3,4] end; *) function Log10: TOpenCLMtxVec; overload; (*Calculate the log base 10 for all X elements. Store the results in the calling object. Size and properties of the calling vector are set implicitly to match the X object. *) function Log10(const X: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Calculate the log base 10 for calling object elements [Index]..[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function Log10(Index, Len: integer): TOpenCLMtxVec; overload; (*Calculate the log base 10 for X elements [XIndex]..[XIndex+Len-1]. Store the results in the calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if array borders are overrun. *) function Log10(const X: TOpenCLMtxVec; XIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Log base 2. Calculate the log base 2 for all calling object elements in-place. var A,B: clVector; begin A.CopyFromArray(TSingleArray.Create(1,2,3,4)); B.Log2(A); end; *) function Log2: TOpenCLMtxVec; overload; (*Calculate the log base 2 for all X elements. Store the results in the calling object. Size and properties of the calling vector are set implicitly to match the X object. *) function Log2(const X: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Calculate the log base 2 for calling object elements [Index]..[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function Log2(Index, Len: integer): TOpenCLMtxVec; overload; (*Calculate the log base 2 for X elements [XIndex]..[XIndex+Len-1]. Store the results in the calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if array borders are overrun. *) function Log2(const X: TOpenCLMtxVec; XIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Exponent (e^). Calculate the exponent (e^) for all calling object elements in-place. var A,B: clVector; begin A.CopyFromArray(TSingleArray.Create(1,2,3,4)); B.Exp(A); end; *) function Exp: TOpenCLMtxVec; overload; (*Calculate the exponent (e^) for all X elements. Store the results in the calling object. Size and properties of the calling vector are set implicitly to match the X object. *) function Exp(const X: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Calculate the exponent (e^) for calling object elements [Index]..[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function Exp(Index, Len: integer): TOpenCLMtxVec; overload; (*Calculate the exponent (e^) for X elements [XIndex]..[XIndex+Len-1]. Store the results in the calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if array borders are overrun. *) function Exp(const X: TOpenCLMtxVec; XIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Exponent base 2 (2^). Calculate the exponent base 2 (2^) for all calling object elements in-place. var A,B: clVector; begin A.CopyFromArray(TSingleArray.Create(1,2,3,4)); B.Exp2(A); end; *) function Exp2: TOpenCLMtxVec; overload; (*Calculate the exponent base 2 (2^) for all X elements. Store the results in the calling object. Size and properties of the calling vector are set implicitly to match the X object. *) function Exp2(const X: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Calculate the exponent base 2 (2^) for calling object elements [Index]..[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function Exp2(Index, Len: integer): TOpenCLMtxVec; overload; (*Calculate the exponent base 2 (2^) for X elements [XIndex]..[XIndex+Len-1]. Store the results in the calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if array borders are overrun. *) function Exp2(const X: TOpenCLMtxVec; XIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Exponent base 10 (10^). Calculate the exponent base 10 (10^) for all calling object elements in-place. var A,B: clVector; begin A.CopyFromArray(TSingleArray.Create(1,2,3,4)); B.Exp10(A); // B = [10, 100, 1000, 10 000] end; *) function Exp10: TOpenCLMtxVec; overload; (*Calculate the exponent base 10 (10^) for all X elements. Store the results in the calling object. Size and properties of the calling vector are set implicitly to match the X object. *) function Exp10(const X: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Calculate the exponent base 10 (10^) for calling object elements [Index]..[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function Exp10(Index, Len: integer): TOpenCLMtxVec; overload; (*Calculate the exponent base 10 (10^) for X elements [XIndex]..[XIndex+Len-1]. Store the results in the calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if array borders are overrun. *) function Exp10(const X: TOpenCLMtxVec; XIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Gets the imaginary part of a complex object. Gets the imaginary part of a complex object Vec and stores the real results in the calling object. Size and properties of the calling object are set implicitly to match Vec object. Vec must be true otherwise the exception will be raised. var a,b: clVector; begin a.CopyCplxFromArray(TSingleArray.Create(1,2,3,4)); // a= [1+2i, 3+4i] b.ImagPart(a); // b = [2, 4] end; *) function ImagPart(const Vec: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Gets the imaginary part of complex object Vec elements [VecIndex]..[VecIndex+Len-1]. Stores the result in calling object. An exception is raised if the calling object is complex, if Vec is not complex or if array borders are overrun/underrun. *) function ImagPart(const Vec: TOpenCLMtxVec; VecIndex,Index,Len: integer): TOpenCLMtxVec; overload; (*Power (integer exponent). Calculate the power ^(Exponent) for all caling object elements using the integer parameter Exponent. For non integer exponents, the and methods can be used. var a: clVector; begin a.CopyFromArray(TSingleArray.Create(1,2,3,4)); a.IntPower(3); end; *) function IntPower(Exponent: Integer): TOpenCLMtxVec; overload; (*Calculate the power Base^(Exponent) for all Base object elements. Calclation uses the integer Exponent value and stores the results in calling object. Size and properties of calling object are adjusted automatically. *) function IntPower(const aBase: TOpenCLMtxVec; Exponent: Integer): TOpenCLMtxVec; overload; (*Inverse elements. Calculates the inverse of all calling object elements in-place without limiting inverse operation. var a,b: clVector; begin a.CopyFromArray(TSingleArray.Create(1,2,3,4)); // a = [1, 2, 3, 4] b.Inv(a); // b = [1.0, 0.5, 0.3333, 0.25] end; *) function Inv: TOpenCLMtxVec; overload; (*Calculate the inverse of calling object elements [Index]..[Index+Len-1] in-place. An exception is raised if array borders are overrun/underrun. *) function Inv(Index, Len: integer): TOpenCLMtxVec; overload; (*Calculate the inverse of all X object elements without limiting operating. Store the results in calling object. Size and property of calling object are adjusted automatically. *) function Inv(const X: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Calculate the inverse of X object elements [XIndex]..[XIndex+Len-1] without limiting operating. Store the results in calling object elements [Index]..[Index+Len-1]. An exception is raised if X and calling object property does not match or array borders are overrun/underrun. *) function Inv(const X: TOpenCLMtxVec; XIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Converts elements from cartesian to polar coordinate form. Converts all calling object elements from cartesian to polar coordinate form, storing the magnitude (radius) component of corresponding elements in the AmpltVec and the phase (angle) component of corresponding elements in the PhaseVec. If you want to use this method then the calling matrix property must be true. If this is not the case, an exception is raised. Size and properties of AmpltVec and PhaseVec are set automatically. var A,Amplt,Phase: clVector; begin A.CopyCplxFromArray(TSingleArray.Create(1,0, 2,0, 2,0 4,1)); // 4, complex matrix A.CartToPolar(Amplt,Phase); end; *) procedure CartToPolar(AmpltVec, PhaseVec: TOpenCLMtxVec); overload; (*Convert calling object elements [Index] to [Index+Len-1] from cartesian to polar form. Store the results in AmpltVec (radius values) and PhaseVec(phase values). Size and properties of the calling vector must be set explicitly. An exception is raised if array borders are overrun or underrun. *) procedure CartToPolar(AmpltVec, PhaseVec: TOpenCLMtxVec; AmpltIndex, PhaseIndex, Index, Len: integer); overload; (*Add each of Vec elements to corresponding elements in the calling object. In addition, the following formula is being used: result = result+ aScale*Vec The results are stored in the calling object. Size and properties of the calling object are set implicitly to match the Vec object. *) function AddScaled(const Vec: TOpenCLMtxVec; aScale: double): TOpenCLMtxVec; overload; (*Add each of Vec elements to corresponding elements in the calling object. In addition, the following formula is being used: result = result+ aScale*Vec The results are stored in the calling object. Size and properties of the calling object are set implicitly to match the Vec object. *) function AddScaled(const Vec: TOpenCLMtxVec; const aScale: TCplx): TOpenCLMtxVec; overload; (*Adds Vec elements [VecIndex]..[VecIndex+Len-1] to calling object elements [Index]..[Index+Len-1]. In addition, the following formula is being used: result = result+ Cplx(aScale)*Vec An exception is raised if array borders are overrun. *) function AddScaled(const Vec: TOpenCLMtxVec; aScale: double; VecIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Adds Vec elements [VecIndex]..[VecIndex+Len-1] to calling object elements [Index]..[Index+Len-1]. In addition, the following formula is being used: result = result+ aScale*Vec An exception is raised if array borders are overrun. *) function AddScaled(const Vec: TOpenCLMtxVec; const aScale: TCplx; VecIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Add a product of two vectors. Multiply Vec1 elements with coresponding Vec2 elements and add the result to the calling vector. The size of the calling vector is set implicitly. *) function AddProduct(const Vec1, Vec2: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Multiply Vec1 elements [Vec1Index]..[Vec1Index+Len-1] with Vec2 elements [Vec2Index]..[Vec2Index+Len-1] and add the results to the calling object elements [Index]..[Index+Len-1]. An exception is raised if array borders are overrun. *) function AddProduct(const Vec1, Vec2: TOpenCLMtxVec; Vec1Index, Vec2Index, Index, Len: integer): TOpenCLMtxVec; overload; (*Conjugate and multiply. Conjugate each of Vec elements and multiply them with corresponding elements in the calling object. The results are stored in the calling object. Size and properties of the calling object are set implicitly to match Vec. var a,b,c: clVector; begin a.CopyFromArray(TSingleArray.Create(1,2,3,4)); b.CopyFromArray(TSingleArray.Create(4,3,2,1)); c.ConjMul(a,b); end; *) function ConjMul(const Vec: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Conjugate Vec elements Vec[VecIndex]..Vec[VecIndex+Len-1] and multiply them with corresponding calling object elements [Index]..[Index+Len-1]. The results are stored in the calling object elements [Index]..[Index+Len-1]. Size and properties are not set. An exception is raised if array borders are overrun or underrun. *) function ConjMul(const Vec: TOpenCLMtxVec; VecIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Conjugate each of Vec2 elements and multiply them with corresponding elements in Vec1. The results are stored in the calling object. Size and properties of the calling object are set implicitly to match Vec1 and Vec2 objects. *) function ConjMul(const Vec1, Vec2: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Conjugate Vec2 elements [Vec2Index]..[Vec2Index+Len-1] and multiply them with corresponding Vec1 elements [Vec1Index]..[Vec1Index+Len-1]. The results are stored in the calling object elements [Index]..[Index+Len-1]. Size and properties of the calling vector must be set explicitly. An exception is raised if array borders are overrun. *) function ConjMul(const Vec1, Vec2: TOpenCLMtxVec; Vec1Index, Vec2Index, Index, Len: integer): TOpenCLMtxVec; overload; (*Divide each of Num elements with corresponding elements in Den. Size and property of the calling object are set automatically. The result is stored in the calling object. The result of division by zero will be the INF constant. Division of zero by zero will result in NAN. *) function Divide(Num, Den: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Divide each of calling vector elements with corresponding elements in the Vec object. Size and property of the calling object are set automatically. The result is stored in the calling object. The result of division by zero will be the INF constant. Division of zero by zero will result in NAN. *) function Divide(const Vec: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Divide calling vector elements [Index]...[Index+Len-1] with corresponding elements [VecIndex]...[VecIndex+Len-1] from the Vec object. Store the result in the claling vector. The Length of the calling vector is not changed. An exception is raised if array borders are overrun or underrun. The result of division by zero will be the INF constant. Division of zero by zero will result in NAN. *) function Divide(const Vec: TOpenCLMtxVec; VecIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Divide [NumIndex]..[NumIndex+Len-1] Num elements with [DenIndex]..[DenIndex+Len-1] elements in Den. and store result in the calling vector at positions [Index]..[Index+Len-1] and property of the calling object are not changed. An exception is raised if array borders are overrun or underrun. The result of division by zero will be the INF constant. Division of zero by zero will result in NAN. *) function Divide(Num, Den: TOpenCLMtxVec; NumIndex, DenIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Divide Value with elements of the calling object and store the result in the calling object.*) function DivideBy(Value: double): TOpenCLMtxVec; overload; (*Divide complex Value with elements of the calling object. Store the result in the calling object. *) function DivideBy(Value: TCplx): TOpenCLMtxVec; overload; (*Divide Value with elements [Index]...[Index+Len-1] from the calling object. Store the result in the calling object at position [Index]...[Index+Len-1]. An exception will be raised if array borders are overrun or underrun. *) function DivideBy(Value: double; Index, Len: integer): TOpenCLMtxVec; overload; (*Divide complex Value with elements [Index]...[Index+Len-1] from the calling object. Store the result in the calling object at position [Index]...[Index+Len-1]. Calling vector will be extended to complex, if the calling vector is real. An exception will be raised if array borders are overrun or underrun. *) function DivideBy(Value: TCplx; Index, Len: integer): TOpenCLMtxVec; overload; (*Divide Value with elements from Vec and store the result in the corresponding elements of the calling object. Size and properties of the calling object are set automatically. *) function DivideBy(Value: double; Vec: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Divide complex Value with elements from Vec and store the result in the corresponding elements of the calling object. Size of the calling object is set automatically. property of the calling object is set to True. *) function DivideBy(Value: TCplx; Vec: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Divide Value with Vec elements [VecIndex]..[VecIndes+Len-1]. Store the result in the elements [Index]..[Index+Len-1] of the calling object. Size of the calling object is not changed. An exception will be raised array borders are overrun or underrun. property of the calling object is set implicitly. *) function DivideBy(Value: double; Vec: TOpenCLMtxVec; VecIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Divide complex Value with elements [VecIndex]..[VecIndes+Len-1] from Vec. Store the result in the elements [Index]..[Index+Len-1] of the calling object. Size of the calling object is not changed. An exception will be raised array borders are overrun or underrun. property of the calling object is set to True. *) function DivideBy(Value: TCplx; Vec: TOpenCLMtxVec; VecIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Reverse vector elements. The method reverses Vec vector elements from [VecIndex].. [VecIndex+Len-1] and stores them in the calling vector from [Index]...[Index+Len-1] by using the following equation: This overload reverses calling vector elements in-place. var a: clVector; begin a.CopyFromArray(TSingleArray.Create(1,2,3,4)); a.Reverse; // a = [4,3,2,1] end; *) function Reverse(const Vec: TOpenCLMtxVec; VecIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Reverses the calling object elements [Index]..[Index+Len-1]. An exception is raised if array borders are overrun. *) function Reverse(Index, Len: integer): TOpenCLMtxVec; overload; function Reverse: TOpenCLMtxVec; overload; (*A cyclic shift on vector elements in range. Performs cyclic shift on source vector elements in specified range [Index..Index+Len] and stores them to calling vector. The number of elements to shift is specified in the Offset parameter. Offset can be any integer number, positive or negative. *) function Rotate(const Vec: TOpenCLMtxVec; Offset: integer; VecIndex,Index: integer; Len: integer = MtxVecEOA): TOpenCLMtxVec; overload; (*A shift on vector elements in range. Performs shift on source vector elements in specified range [Index..Index+Len] and stores them to calling vector. The number of elements to shift is specified in the Offset parameter. Offset can be any integer number, positive or negative. *) function Shift(const Vec: TOpenCLMtxVec; Offset: integer; VecIndex,Index: integer; Len: integer = MtxVecEOA): TOpenCLMtxVec; overload; function Shift (const Vec: TOpenCLMtxVec; Offset: integer): TOpenCLMtxVec; overload; (*Subtracts Value from object elements. Subtracts Value from all calling object elements. *) function Sub(const Value: double): TOpenCLMtxVec; overload; (*Subtracts complex Value from all calling object complex elements.*) function Sub(const Value: TCplx): TOpenCLMtxVec; overload; (*Subtracts Value from calling object elements [Index]..[Index+Len-1]. An exception is raised if array borders are overrun. *) function Sub(const Value: double; Index, Len: integer): TOpenCLMtxVec; overload; (*Subtracts complex Value from calling object complex elements [Index]..[Index+Len-1]. An exception is raised if array borders are overrun. *) function Sub(const Value: TCplx; Index, Len: integer): TOpenCLMtxVec; overload; (*Subtract real Value from Src. Store the results in calling object. Size and property of calling object are adjusted automatically. *) function Sub(const Src: TOpenCLMtxVec; const Value: double): TOpenCLMtxVec; overload; (*Subtract complex Value from Src. Store the results in calling object. Size and property of calling object are adjusted automatically. *) function Sub(const Src: TOpenCLMtxVec; const Value: TCplx): TOpenCLMtxVec; overload; (*Subtract real Value from Src elements [SrcIndex]..[SrcIndex+Len-1]. Stores the result in calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if array borders are overrun or underrun. *) function Sub(const Src: TOpenCLMtxVec; const Value: double; SrcIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Subtract complex Value from Src elements [SrcIndex]..[SrcIndex+Len-1]. Stores the result in calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if array borders are overrun or underrun. *) function Sub(const Src: TOpenCLMtxVec; const Value: TCplx; SrcIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Array subtraction. Subtract each of Vec elements from corresponding elements in the calling object. An exception is raised if Vec and calling object size and properties do not match. *) function Sub(const Vec: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Subtract Vec2 elements from Vec1 elements. Stores the results in calling object. Size and property of calling object are adjusted automatically. An exception is raised if Vec1 and Vec2 size and property do not match. *) function Sub(const Vec1, Vec2: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Subtract Vec elements [VecIndex]..[VecIndex+Len-1] from corresponding calling object elements [Index]..[Index+Len-1]. The results are stored in the calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if array borders are overrun or underrun. *) function Sub(const Vec: TOpenCLMtxVec; VecIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Subtract Vec22 elements [Vec2Index]..[Vec2Index+Len-1] from Vec1 object elements [Vec1Index]..[Vec1Index+Len-1]. Stores the results in calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if array borders are overrun or underrun. *) function Sub(const Vec1, Vec2: TOpenCLMtxVec; Vec1Index, Vec2Index, Index, Len: integer): TOpenCLMtxVec; overload; (*Subtraction from value. Subtract each of calling object elements from Value. *) function SubFrom(const Value: double): TOpenCLMtxVec; overload; (*Subtract each of calling object elements from complex Value. If the calling vector s not complex, the conversion is performed automatically in a performance efficient way. *) function SubFrom(const Value: TCplx): TOpenCLMtxVec; overload; (*Subtract elements [Index]..[Index+Len-1] from Value. Store the result in calling vector. An exception is raised if array borders are overrun or underrun. *) function SubFrom(Value: double; Index,Len: integer): TOpenCLMtxVec; overload; (*Subtract elements [Index]..[Index+Len-1] from complex Value. Store the result in calling object. If the calling vector is not complex, the conversion to complex is performed automatically in performance efficient way. An exception is raised if array borders are overrun or underrun. *) function SubFrom(const Value: TCplx; Index,Len: integer): TOpenCLMtxVec; overload; (*Substract Vec elements from Value. Stores the result in the calling object. Size and properties of calling object are adjusted automatically. *) function SubFrom(const Value: double; Vec: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Substract complex Vec elements from Value. Stores the result in the calling object. Size property of the calling object is set automatically. property of the calling object is set to True. *) function SubFrom(const Value: TCplx; Vec: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Substract Vec elements [VecIndex]..[VecIndex+Len-1] from Value. Stores the result to the calling object elements [Index]..[Index+Len-1]. Size property of the calling object is not changed. An exception is raised if array borders are overrun or underrun. property of the calling object is adjusted automatically. *) function SubFrom(const Value: double; Vec: TOpenCLMtxVec; VecIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Substract Vec elements [VecIndex]..[VecIndex+Len-1] from complex Value and store the result to the calling object elements [Index]..[Index+Len-1]. Size property of the calling object is not changed. An exception is raised if array borders are overrun or underrun. property of the calling object is set to True. *) function SubFrom(const Value: TCplx; Vec: TOpenCLMtxVec; VecIndex, Index, Len: integer): TOpenCLMtxVec; overload; procedure Size(aLength: integer; aPrecision: TclFloatPrecision; aComplex: boolean); overload; procedure Size(const Src: TOpenCLMtxVec; aComplex: boolean); overload; procedure Size(const Src: TOpenCLBase); overload; (*Calculate the difference for all Vec elements. Store the results in the calling vector. The Length of the calling vector is set to one less the length of Vec and property is set to Vec.Complex. The Length of calling vector is automatically decremented by one. *) function Difference(const Vec: TOpenCLMtxVec; Lag: Integer = 1): TOpenCLMtxVec; overload; (*Fills the calling vector with a series following linear rule. Fills the calling vector with a series following the rule: Values[k] := k (Offset is zero and Step is one). If the calling vector is complex, only the real part is set. var a: clVector; begin a.Size(5,True); a.Ramp(0,PI); a.Sin; end; which is identical to: a.Size(5,True); for i:= 0 to a.Length-1 do a[i] := sin(i*PI); *) function Ramp: TOpenCLVector; overload; (*Fills the calling vector with a series. Method follow the rule: Values[k] := Offset + k*Step. *) function Ramp(Offset, Step: TCplx): TOpenCLVector; overload; (*Fills the calling vector. Method uses the following rule: Values[k] := Offset + k*Step. If the calling vector is complex, only the real part is set. *) function Ramp(Offset, Step: double): TOpenCLVector; overload; (*Fills the calling vector elements [Index]..[Index+Len-1]. Method uses the following rule: Values[k] := Offset + k*Step. If the calling vector is complex, only the real part is set. An exception is raised if calling vector array borders are overrun. *) function Ramp(Offset,Step: double; Index,Len: integer): TOpenCLVector; overload; (*Fills the calling vector elements [Index]..[Index+Len-1]. Following the rule: Values[k] := Offset + k*Step. If the calling vector is complex, only the real part is set. An exception is raised if array borders of the calling vector are overrun. *) function Ramp(Offset, Step: TCplx; Index,Len: integer): TOpenCLVector; overload; (*The Offset is complex, but the step is real.*) function Ramp(Offset: TCplx; Step: double): TOpenCLVector; overload; (*Fills the calling vector elements [Index]..[Index+Len-1]. Following the rule: Values[k] := Offset + k*Step. The Offset is complex, but the step is real. *) function Ramp(Offset: TCplx; Step: double; Index,Len: integer): TOpenCLVector; overload; (*Inserts zeroes between consecutive vector values. Inserts zeroes between consecutive vector values. The method copies the values from Src to the calling vector and places Factor-1 zeros between consecutive values. The Length and Complex properties of the calling vector are set implicitly. Phase parameter defines the initial sample offset and must be less than Factor. var a,b: clVector; begin b.CopyFromArray(TSingleArray.Create(0,0,1,3,2)); a.UpSample(b,2); // a = [0,0,0,0,1,0,3,0,2,0] end; *) function UpSample(const Src: TOpenCLMtxVec; Factor: integer; Phase: integer = 0): TOpenCLVector; overload; function UpSample(const Src: TOpenCLMtxVec; Factor, SrcIndex, Index, Len, Phase: integer): TOpenCLMtxVec; overload; (*Downsamples vector values. The methods copies only every Factor sample from the Src vector to the calling vector. The Length and Complex properties of the calling vector are set implicitly. The phase parameter determines the initial sample offset. Phase must be less than Factor. var a,b: clVector; begin b.CopyFromArray(TSingleArray.Create(0,0,0,0,1,2,3,4,5,6)); a.DownSample(b,2); // a = [0,0,1,3,5] end; *) function DownSample(const Src: TOpenCLMtxVec; Factor: integer; Phase: integer = 0): TOpenCLVector; overload; (*Reverse all Vec elements. Store the result in the calling vector elements. The Length and Complex properties of the calling vector are set implicitly to match Vec vector. This overload reverses all vector elements. var a: clVector; begin a.CopyFromArray(TSingleArray.Create(1,2,3,4)); b.Reverse(a); // b = [4,3,2,1] end; *) function Reverse(const Vec: TOpenCLMtxVec): TOpenCLVector; overload; (*A cyclic shift on vector elements. Performs cyclic shift on vector elements. The number of elements to shift is specified in the Offset parameter. Offset can be any integer number, positive or negative. var a: clVector; begin a.CopyFromArray(TSingleArray.Create(1,2,3,4)); b.Rotate(a, 2); // b = [3,4,1,2] end; *) function Rotate(const Src: TOpenCLMtxVec; Offset: integer): TOpenCLVector; overload; (*Mean value. Calculate the mean value of all calling object elements. The result is a real value. An exception is raised if calling object property is true. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TOpenCLVector a; clMtxVec.CreateIt(out a); try { a.CopyFromArray(new double[] {1,2,3,4}); double m = a.Mean(); // 2.5 } finally { clMtxVec.FreeIt(ref a); } } } *) function Mean: double; overload; (*Returns real mean value from calling object elements [Index]..[Index+Len-1]. An exception is raised if calling object property is true or array borders are overrun. *) function Mean(Index, Len: integer): double; overload; (*Calculate the mean value from calling object elements [Index]..[Index+Len-1]. The result AMean is a real value. An exception is raised if calling object property is true or array borders are overrun/underrun. *) procedure Mean(out AMean: double; Index, Len: integer); overload; (*Same as .*) procedure Mean(out AMean: TCplx); overload; (*Same as .*) procedure Mean(out AMean: TCplx; Index, Len: integer); overload; (*Mean value. the mean value of all calling object complex elements. The result is a complex value. An exception is raised is calling object is . *) function Meanc: TCplx; overload; (*Returns complex mean value from calling object complex elements [Index]..[Index+Len-1]. An exception is raised if calling object property is or array borders are overrun/underrun. *) function Meanc(Index, Len: integer): TCplx; overload; (*Calculate the mean value from all calling object complex elements. The result AMean is a complex value. An exception is raised if calling object property is . *) procedure Meanc(out AMean: TCplx); overload; (*Calculate the mean value from calling object complex elements [Index]..[Index+Len-1]. The result AMean is a complex value. An exception is raised if calling object property is or array borders are overrun/underrun. *) procedure Meanc(out AMean: TCplx; Index, Len: integer); overload; (*Sums vector values. the sum of all calling object elements. An exception is raised if calling object property is true. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TOpenCLVector a; clMtxVec.CreateIt(out a); try { a.CopyFromArray(new double[] {1,3,-2}); doouble s = a.Sum(); // s = 2 } finally { clMtxVec.FreeIt(ref a); } } } *) function Sum: double; overload; (*Returns the sum of calling object elements [Index]..[Index+Len-1]. An exception is raised if calling object property is True or array borders are overrun/underrun. *) function Sum(Index,Len: integer): double; overload; (*Calculates the sum of calling object elements [Index]..[Index+Len-1]. Stores the result in real ASum variable. An exception is raised if calling object property is True or array borders are overrun/underrun. *) procedure Sum(out ASum: double; Index, Len: integer); overload; (*Calculates the sum of all calling object complex elements. Stores the result in complex ASum variable. An exception is raised if calling object property is False. *) procedure Sum(out ASum: TCplx); overload; (*Calculates the sum of calling object complex elements [Index]..[Index+Len-1]. Stores the result in complex ASum variable. An exception is raised if calling object property is False or array borders are overrun/underrun. *) procedure Sum(out ASum: TCplx; Index, Len: integer); overload; (*Sum (complex value). the complex sum of all calling object complex elements. An exception is raised if calling object property is False. *) function Sumc: TCplx; overload; (*Returns the complex sum of calling object complex elements [Index]..[Index+Len-1]. An exception is raised if calling object property is False or array borders are overrun/underrun. *) function Sumc(Index,Len: integer): TCplx; overload; (*Maximum value. the maximum value of all calling object elements. The result is a real value. An exception is raised is calling object is true. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TOpenCLVector a; clMtxVec.CreateIt(out a); try { a.CopyFromArray( new double[] {1,2,3,4}); double b = a.Max(); // 4.0 } finally { clMtxVec.FreeIt(ref a); } } } *) function Max: double; overload; (*Returns the maximum value from calling object elements [Index]..[Index+Len-1]. The result is a real value. An exception is raised if calling object property is true or array borders are overrun. *) function Max(Index,Len: integer): double; overload; (*Calculate the maximum value from calling object elements [Index]..[Index+Len-1]. The result AMean is a real value. An exception is raised if calling object property is true or array borders are overrun. *) procedure Max(out AMax: double; Index,Len: integer); overload; (*Calculate the maximum value of all calling object elements. The AMax parameter returns the maximum value. The AIndex parameter returns the index of maximum value. An exception is raised if calling object property is true. *) procedure Max(out AMax: double; out AIndex: integer); overload; (*Calculate the maximum value of calling object elements [Index]..[Index+Len-1]. The AMax parameter returns the maximum value. The AIndex parameter returns the index of maximum value. An exception is raised if calling object property is true or array borders are overrud/underrun. *) procedure Max(out AMax: double; out AIndex: integer; Index, Len: integer); overload; (*Same as method.*) function Max(out AMax: TCplx; Index, Len: integer): integer; overload; (*Maximum value. the maximum value of all calling object complex elements. Complex elements are first compared by the amplitude and then by the argument. An exception is raised if calling object is . *) function Maxc: TCplx; overload; (*Returns the maximum value of calling object complex elements [Index]..[Index+Len-1]. The result is a complex value. Complex elements are first compared by the amplitude and then by the argument. An exception is raised if calling object property is or array borders are overrud/underrun. *) function Maxc(Index,Len: integer): TCplx; overload; (*Calculate the maximum value of calling object complex elements [Index]..[Index+Len-1]. The AMax parameter returns complex maximum value. Returns the index of maximum value. Complex elements are first compared by the amplitude and then by the argument. The AIndex parameter returns the index of maximum value. An exception is raised if calling object property is or array borders are overrud/underrun. *) function Maxc(out AMax: TCplx; Index, Len: integer): integer; overload; (*Maximum and minimum value in a single pass. Calculates the maximum and minimum value of all calling object elements in a single pass. Maximum value is stored in AMax parameter, minimum value is stored in AMin parameter. Use this method if you require minimum AND maximum value. *) procedure MaxMin(out AMax,AMin: double); overload; (*Calculates the maximum and minimum value of calling object elements [Index]..[Index+Len-1]. Maximum value is stored in AMax parameter, minimum value is stored in AMin parameter. An exception is raised if calling object property is true or array borders are overrud/underrun. *) procedure MaxMin(out AMax,AMin: double; Index, Len: integer); overload; (*Calculates the maximum and minimum value of all calling object elements. Maximum value is returned in AMax parameter, minimum value in AMin parameter. The MaxIdx parameter returns the index of maximum value. The MinIdx parameter returns the index of minimum value. An exception is raised if calling object property is true. *) procedure MaxMin(out AMax: double; out MaxIdx: integer; out AMin: double; out MinIdx: integer); overload; (*Calculates the maximum and minimum value of calling object elements [Index]..[Index+Len-1]. Maximum value is returned in AMax parameter, minimum value in AMin parameter. The MaxIdx parameter returns the index of maximum value. The MinIdx parameter returns the index of minimum value. An exception is raised if calling object property is true or if array borders are overrun/underrun. *) procedure MaxMin(out AMax: double; out MaxIdx: integer; out AMin: double; out MinIdx: integer; Index, Len: integer); overload; (*Minimum value. The minimum value of all calling object elements. The result is a real value. An exception is raised if calling object property is true. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TOpenCLVector a; clMtxVec.CreateIt(out a); try { a.CopyFromArray( new double[] {1,2,3,4}); double b = a.Min(); // 1.0 } finally { clMtxVec.FreeIt(ref a); } } } *) function Min: double; overload; (*Calculate the minimum value from calling object elements [Index]..[Index+Len-1]. The result is a real value. An exception is raised if calling object property is true or array borders are overrun. *) function Min(Index,Len: integer): double; overload; (*Calculate the minimum value from calling object elements [Index]..[Index+Len-1]. The result AMin is a real value. An exception is raised if calling object property is true or array borders are overrun. *) procedure Min(out AMin: double; Index,Len: integer); overload; (*Calculate the minimum value of calling object elements [Index]..[Index+Len-1]. The AMax parameter returns the minimum value. The AIndex parameter returns the index of minimum value. An exception is raised if calling object property is true or array borders are overrud/underrun. *) procedure Min(out AMin: double; out AIndex: Integer; Index, Len: integer); overload; (*Calculate the minimum value of all calling object elements. The AMin parameter returns the minimum value. The AIndex parameter returns the index of minimum value. An exception is raised if calling object property is true. *) procedure Min(out AMin: double; out AIndex: integer); overload; (*Same as the method.*) function Min(out AMin: TCplx; Index, Len: integer): integer; overload; (*Minimum value. Returns the minimum value of all calling object complex elements. Complex elements are first compared by the amplitude and then by the argument. An exception is raised if calling object is . *) function Minc: TCplx; overload; (*Returns the minimum value of calling object complex elements [Index]..[Index+Len-1]. The result is a complex value. Complex elements are first compared by the amplitude and then by the argument. An exception is raised if calling object. property is or array borders are overrud/underrun. *) function Minc(Index,Len: integer): TCplx; overload; (*Calculate the minimum value of calling object complex elements [Index]..[Index+Len-1]. The AMin parameter returns complex minimum value. Returns the index of minimum value. Complex elements are first compared by the amplitude and then by the argument. An exception is raised if calling object property is or array borders are overrun/underrun. *) function Minc(out AMin: TCplx; Index, Len: integer): integer; overload; (*The C-norm. C norm: ||V-Vec||, where V is the calling vector. If the NormC is called without any parameters, the NormC calculates the norm of the calling vector. The C norm of ||V-Vec|| is defined by the formula: If RelativeError is true then the computed norm is divided by the norm of V, and the function returns the "relative error": 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.NormC(b,true); } finally { clMtxVec.FreeIt(ref a,ref b); } } } *) function NormC(const Vec: TOpenCLMtxVec; RelativeError: boolean = false): double; overload; (*Calculates the C norm ||V-Vec|| between Vec elements [VecIndex]..[VecIndex+Len-1] and calling vector elements [Index]..[Index+Len-1].*) function NormC(const Vec: TOpenCLMtxVec; VecIndex,Index,Len: integer; RelativeError: boolean = false): double; overload; (*Calculate the C-norm of calling vector. NormC = max|a[i]|, 0 < i < Length-1 .*) function NormC: double; overload; (*Calculates the C norm from calling vector elements [Index]..[Index+Len-1].*) function NormC(Index,Len: integer): double; overload; (*The L1-norm. L-1 norm, defined by: ||V-Vec||, where V is calling vector. If the NormL1 is called without any parameters, the NormL1 calculates the norm of calling vector. The L1 norm of ||V-Vec|| is defined by the formula: If RelativeError is true then the computed norm is divided by the norm of V, and the function returns the "relative error": 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.NormL1(b,true); } finally { clMtxVec.FreeIt(ref a,ref b); } } } *) function NormL1(const Vec: TOpenCLMtxVec; RelativeError: boolean = false): double; overload; (*Calculates the L1 norm ||V-Vec|| between Vec elements [VecIndex]..[VecIndex+Len-1] and calling vector elements [Index]..[Index+Len-1].*) function NormL1(const Vec: TOpenCLMtxVec; VecIndex,Index,Len: integer; RelativeError: boolean = false): double; overload; (*Calculate the L1-norm of the calling vector. L-1 norm, defined by the following equation: NormL1 = Sum(|a[i]|), 0 < i < Length-1*) function NormL1: double; overload; (*Calculates the L1 norm from calling vector elements [Index]..[Index+Len-1].*) function NormL1(Index,Len: integer): double; overload; (*The L2-norm. L2 norm, defined by ||V-Vec||, where V is calling vector. 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: If RelativeError is true then the computed norm is divided by the norm of V, and the function returns the "relative error": 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); } } } *) function NormL2(const Vec: TOpenCLMtxVec; RelativeError: boolean = False): double; overload; (*Calculates the L2 norm ||V-Vec|| between Vec elements [VecIndex]..[VecIndex+Len-1] and calling vector elements [Index]..[Index+Len-1].*) function NormL2(const Vec: TOpenCLMtxVec; VecIndex,Index,Len: integer; RelativeError: boolean = False): double; overload; (*Calculate the L2-norm of the calling vector. L2 norm, defined by: NormaL2 = ( Sum(|a[i]|^2) )^0.5 , 0 < i < Length-1 .*) function NormL2: double; overload; (*Calculates the L2 norm from calling vector elements [Index]..[Index+Len-1].*) function NormL2(Index,Len: integer): double; overload; (*Computes the sum and the sum of squared elements from the elements in the calling object.*) procedure SumAndSqrSum(out Sum, SqrSum: double); overload; (*Returns the sum and the sum of squared elements. Returns the sum and the sum of squared items from calling vector elements [Index]..[Index+Len-1]. *) procedure SumAndSqrSum(out Sum, SqrSum: double; Index, Len: integer); overload; (*Standard deviation. Calculate the standard deviation of all calling object elements. The result is a real value. An exception is raised if calling vector property is true. var a: clVector; c: double; aMean: double; begin a.CopyFromArray(TDoubleArray.Create(1,2,3,4)); Caption := FloatToSTr(a.StdDev); end; *) function StdDev: double; overload; (*Returns the standard deviation of calling object elements [Index]..[Index+Len-1]. An exception is raised if calling object property is true or if array borders are overrun/underrun. *) function StdDev(Index,Len: integer): double; overload; (*Returns the standard deviation of all calling object elements. The sum and the sum of squares of all calling object elements must be passed as parameters. An exception is raised if calling object property is true. *) function StdDev(aSum, aSumSqr: double): double; overload; (*Returns the standard deviation of calling object elements [Index]..[Index+Len-1]. The sum and the sum of squares of the coresponding elements must be passed as parameters. An exception is raised if calling object property is true or if array borders are overrun/underrun. *) function StdDev(aSum, aSumSqr: double; Index, Len: integer): double; overload; (*Elements product. the product of all calling object elements An exception is raised if calling object property is true. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TOpenCLVector a; clMtxVec.CreateIt(out a); try { a.CopyFromArray(new double[] {1,2,3,4}); double c = a.Product(); // c= 24 } finally { clMtxVec.FreeIt(ref a); } } } *) function Product: double; overload; (*Returns the product for calling object elements [Index]..[Index+Len-1]. An exception is raised if array borders are overrun or underrun. *) function Product(Index,Len: integer): double; overload; (*Calculate the product of all calling object complex elements. Store the result in complex variable X. *) procedure Product(out X: TCplx); overload; (*Calculate the product for calling object complex elements [Index]..[Index+Len-1]. Store the result in complex variable X. An exception is raised if array borders are overrun or underrun. *) procedure Product(out X: TCplx; Index,Len: integer); overload; (*Calculate the product of all calling object elements. Store the result in real variable X. *) procedure Product(out X: double); overload; (*Calculate the product for calling object elements [Index]..[Index+Len-1]. Store the result in real variable X. An exception is raised if array borders are overrun or underrun. *) procedure Product(out X: double; Index,Len: integer); overload; (*Elements product. the complex product of all calling object complext elements. An exception is raised if calling object property is false. *) function Productc: TCplx; overload; (*Returns the complex product for calling object complex elements [Index]..[Index+Len-1]. An exception is raised if array borders are overrun or underrun or if propety is false. *) function Productc(Index,Len: integer): TCplx; overload; (*Scalar product of two real arrays. 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: Both objects must be of equal size. If they are not, the method will return the dot product of the largest sub-array. 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}); b.CopyFromArray(new double[] {5,6,7,8}); double prod = a.DotProd(b); // = 1*5 + 2*6 + * 3*7 + 4*8 } finally { clMtxVec.FreeIt(ref a,ref b); } } } *) function DotProd(const Vec: TOpenCLMtxVec): double; overload; (*Returns the scalar product between Vec elements [VecIndex]..[VecIndex+Len-1] and calling object elements [Index]..[Index+Len-1]. An exception is raised if Vec and calling object property is True. An exception is raised if array borders are overrun or underrun. *) function DotProd(const Vec: TOpenCLMtxVec; VecIndex, Index, Len: integer): double; overload; procedure DotProd(DstIndex: integer; const Vec1, Vec2: TOpenCLMtxVec; Vec1Index, Vec2Index, Len: integer; const Buffer: TOpenCLMtxVec); overload; (*Scalar product of two real or complex arrays. Calculates the dot product (scalar value) of the Vec1 and Vec2 stores the result in calling vector at position DstIndex. ConjVec parameter is ignored if data is real. If ConjVec is true, the function computes: result = Vec1*conj(Vec2) The dot product is defined by the equation: Both objects must be of equal size. If they are not, the method will return the dot product of the largest sub-array. *) procedure DotProd(DstIndex: integer; const Vec1, Vec2: TOpenCLMtxVec; ConjVec: boolean; const Buffer: TOpenCLMtxVec); overload; (*Scalar product of two real arrays. Calculates the dot product (scalar value) of the calling object and Vec object and returns a real scalar value. The result is stored at specified index in the calling vector in the GPU memory. This variant of the function is non-blocking (faster), because the result does not have to be copied to the CPU memory to be used. The dot product is defined by the equation: Both objects must be of equal size. If they are not, the method will return the dot product of the largest sub-array. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TOpenCLVector a,b,c; double[] ac; clMtxVec.CreateIt(out a, out b, out c); try { a.SetIt(false, new double[] {1,2,3,4}); b.SetIt(false, new double[] {5,6,7,8}); c.DotProd(0, a, b); // c[0] = 1*5 + 2*6 + * 3*7 + 4*8 c.DotProd(1, a, b); // c[0] = 1*5 + 2*6 + * 3*7 + 4*8 c.DotProd(2, a, b); // c[0] = 1*5 + 2*6 + * 3*7 + 4*8 c.CopyToArray(ac); //ac = [70, 70, 70] } finally { clMtxVec.FreeIt(ref a,ref b, ref c); } } } *) procedure DotProd(DstIndex: integer; const Vec1, Vec2, Buffer: TOpenCLMtxVec); overload; (*Scalar product of two complex arrays. Calculates the dot product (scalar value) of the calling object and Vec object and returns a complex scalar value. An exception is raised if calling or Vec object property is false. The dot product is defined by the equation: Both objects must be of equal size. If they are not, the method will return the dot product of the largest sub-array. 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}); b.CopyFromArray(new double[] {5,6,7,8}); double prod = a.DotProdc(b); //= (1+2i)*(5+6i)+(3+4i)*(7+8i) } finally { clMtxVec.FreeIt(ref a,ref b); } } } *) function DotProdc(const Vec: TOpenCLMtxVec): TCplx; overload; (*Returns the scalar product between Vec (complex) elements [VecIndex]..[VecIndex+Len-1] and calling object (complex) elements [Index]..[Index+Len-1]. An exception is raised if Vec and calling object property is False. An exception is raised if array borders are overrun or underrun. *) function DotProdc(const Vec: TOpenCLMtxVec; VecIndex, Index, Len: integer): TCplx; overload; (*Returns the scalar product between Vec and calling object complex elements. If ConjVec is True, scalar product between calling object and conjugated Vec object elements is calculated. An exception is raised if Vec and calling object property is False. *) function DotProdc(const Vec: TOpenCLMtxVec; ConjVec: boolean): TCplx; overload; (*Returns the scalar product between Vec (complex) elements [VecIndex]..[VecIndex+Len-1] and calling object (complex) elements [Index]..[Index+Len-1]. If ConjVec is True, scalar product between calling object and conjugated Vec object elements is calculated. An exception is raised if Vec and calling object property is False. An exception is raised if array borders are overrun or underrun. *) function DotProdc(const Vec: TOpenCLMtxVec; ConjVec: boolean; VecIndex, Index, Len: integer): TCplx; overload; property Tag: PointerInteger read GetTag write SetTag; property Caption: string read GetCaption write SetCaption; property Length: integer read GetLength write SetLength; property Complex: boolean read GetComplex write SetComplex; property FloatPrecision: TclFloatPrecision read GetClFloatPrecision write SetClFloatPrecision; (*Returns the device on which we allocated memory for this object. *) property Device: TOpenCLDevice read GetDevice; constructor Create(aLength: integer; aPrecision: TclFloatPrecision; aComplex: boolean; IsCached: boolean = true); overload; constructor Create(TargetDevice: TOpenCLDevice; IsCached: boolean = true); overload; constructor Create(DeviceSource: TOpenCLMtxVec; IsCached: boolean = true); overload; constructor Create(IsCached: boolean); overload; end; (*Open CL Matrix class with overloaded operators. Declare clMatrix to run computation on Open CL Be carefull to declare clMatrix only for local variables with short lifetime. Call the Create method for clMatrix, if the variable is a global variable or a variable with a longer life. If the Create method (constuctor) is called, the clMatrix creates its own memory object in GPU memory, otherwise object cache is used. *) clMatrix = record strict private FData: TOpenCLMatrix; function get_Data: TOpenCLMatrix; function GetCaption: string; function GetComplex: boolean; function GetLength: integer; function GetTag: PointerInteger; procedure SetCaption(const Value: string); procedure SetComplex(const Value: boolean); procedure SetLength(const Value: integer); procedure SetTag(const Value: PointerInteger); function GetFloatPrecision: TCLFloatPrecision; procedure SetFloatPrecision(const Value: TCLFloatPrecision); function GetIsSubRange: boolean; procedure CreateFromCache; function GetCols: integer; function GetRows: integer; procedure SetRows(const Value: integer); procedure SetCols(const Value: integer); private property Data: TOpenCLMatrix read get_Data; public (*Add left to all elements in Right and return result.*) class operator Add(const Left: TCplx; const Right: clMatrix): clMatrix; (*Add Right to all elements in Left and return result.*) class operator Add(const Left: clMatrix; const Right: TCplx): clMatrix; (*Add Left to all elements in Right and return result.*) class operator Add(const Left: double;const Right: clMatrix): clMatrix; (*Add Right to all elements in Left and return result.*) class operator Add(const Left: clMatrix; const Right: double): clMatrix; (*Add coresponding elements in Left and Right.*) class operator Add(const Left: TOpenCLMtxVec;const Right: clMatrix): clMatrix; (*Add coresponding elements in Left and Right.*) class operator Add(const Left: clMatrix; const Right: TOpenCLMtxVec): clMatrix; (*Add coresponding elements in Left and Right.*) class operator Add(const Left: clMatrix;const Right: clMatrix): clMatrix; (*Subtract all elements in Right from Left.*) class operator Subtract(const Left: TCplx; const Right: clMatrix): clMatrix; (*Subtract Right from all elements in Left.*) class operator Subtract(const Left: clMatrix; const Right: TCplx): clMatrix; (*Subtract all elements in Right from Left.*) class operator Subtract(const Left: double; const Right: clMatrix): clMatrix; (*Subtract Right from all elements in Left.*) class operator Subtract(const Left: clMatrix; const Right: double): clMatrix; (*Subtract coresponding elements in Right from Left.*) class operator Subtract(const Left: clMatrix; const Right: TOpenCLMtxVec): clMatrix; (*Subtract coresponding elements in Right from Left.*) class operator Subtract(const Left: TOpenCLMtxVec; const Right: clMatrix): clMatrix; (*Subtract coresponding elements in Right from Left.*) class operator Subtract(const Left: clMatrix;const Right: clMatrix): clMatrix; (*Multiply all elements in Left with Right.*) class operator Multiply(const Left: clMatrix; const Right: TCplx): clMatrix; (*Multiply all elements in Right with Left.*) class operator Multiply(const Left: TCplx; const Right: clMatrix): clMatrix; (*Multiply all elements in Left with Right.*) class operator Multiply(const Left: clMatrix; Right: double): clMatrix; (*Multiply all elements in Right with Left.*) class operator Multiply(Left: double; const Right: clMatrix): clMatrix; (*Multiply all elements in Left with corresponding elements in Right.*) class operator Multiply(const Left: clMatrix; Right: TOpenCLMtxVec): clMatrix; (*Multiply all elements in Left with corresponding elements in Right.*) class operator Multiply(Left: TOpenCLMtxVec; const Right: clMatrix): clMatrix; (*Multiply all elements in Left with corresponding elements in Right*) class operator Multiply(const Left: clMatrix; const Right: clMatrix): clMatrix; (*Multiplies Left with Right and returns result. *) class operator Multiply(const Left: clMatrix; const Right: clVector): clMatrix; (*Multiplies Left with Right and returns result. *) class operator Multiply(const Left: clVector; const Right: clMatrix): clMatrix; (*Divide all elements in Left with Right.*) class operator Divide(const Left: clMatrix; const Right: TCplx): clMatrix; (*Divide Left with all elements Right.*) class operator Divide(const Left: TCplx; const Right: clMatrix): clMatrix; (*Divide all elements in Left with Right.*) class operator Divide(const Left: clMatrix; const Right: double): clMatrix; (*Divide Left with all elements Right.*) class operator Divide(const Left: double; const Right: clMatrix): clMatrix; (*Divide all elements in Left with coresponding elements in Right.*) class operator Divide(const Left: clMatrix; const Right: TOpenCLMtxVec): clMatrix; (*Divide all elements in Left with coresponding elements in Right.*) class operator Divide(const Left: TOpenCLMtxVec; const Right: clMatrix): clMatrix; (*Divide all elements in Left with coresponding elements in Right.*) class operator Divide(const Left: clMatrix; const Right: clMatrix): clMatrix; (*Negates all values inside AValue.*) class operator Negative(const AValue: clMatrix): clMatrix; class operator Implicit(const AValue: clMatrix): TOpenCLMtxVec; class operator Implicit(const AValue: clMatrix): TOpenCLMatrix; class operator Explicit(const AValue: clMatrix): TDoubleArray; class operator Explicit(const AValue: clMatrix): TCplxArray; class operator Explicit(const AValue: clMatrix): TSingleArray; public procedure CopyTo(Dst: TMtx); overload; procedure CopyTo(Dst: TVec); overload; procedure CopyTo(Dst: TMtxInt); overload; procedure CopyTo(Dst: TVecInt); overload; procedure Copy(const Src: TMtxInt); overload; procedure Copy(const Src: TVecInt); overload; procedure Copy(const Src: TMtx); overload; procedure Copy(const Src: TVec); overload; procedure SizeToArray(var Dst: TSingleArray); overload; procedure SizeToArray(var Dst: TDoubleArray); overload; procedure SizeToArray(var Dst: TCplxArray); overload; function CopyFromArray(aRows, aCols: integer; const Src: TSingleArray): TOpenCLMtxVec; overload; function CopyFromArray(aRows, aCols: integer; const Src: TDoubleArray): TOpenCLMtxVec; overload; function CopyFromArray(aRows, aCols: integer; const Src: TCplxArray): TOpenCLMtxVec; overload; function CopyCplxFromArray(aRows, aCols: integer; const Src: TSingleArray): TOpenCLMtxVec; overload; function CopyCplxFromArray(aRows, aCols: integer; const Src: TDoubleArray): TOpenCLMtxVec; overload; function CopyFromArray(const Src: TSingleArray): TOpenCLMtxVec; overload; function CopyFromArray(const Src: TCplxArray): TOpenCLMtxVec; overload; function CopyFromArray(const Src: TDoubleArray): TOpenCLMtxVec; overload; function CopyToArray(var Dst: TSingleArray): TOpenCLMtxVec; overload; function CopyToArray(var Dst: TDoubleArray): TOpenCLMtxVec; overload; function CopyToArray(var Dst: TCplxArray): TOpenCLMtxVec; overload; procedure AssignWithoutCopy(const Src: clMatrix); overload; procedure Assign(const Src: TOpenCLMatrix); overload; (*Automatically set to true after the SetSubIndex or SetSubRange call. This property is set to true after the or call. If IsSubRange is true then the TOpenCLMtxVec method/function will be performed on subrange of values. Use to set IsSubRange back to False and thus reset sub range to full vector length. *) property IsSubRange: boolean read GetIsSubRange; (*Resets any defined subrange. *) procedure SetFullRange; (*Defines a sub vector/matrix. The method will define a subarray starting at Index and ending at Index+Len-1. No copying will occur, only pointers will be shifted or indices adjusted. All values of the original will be preserved. An exception will be raised if an attempt is made to change the size of calling object. A sub-vector/matrix is vector/matrix which does not neccessarily have its own memory allocated. Instead it adopts the memory of the source object and all operations done on the either of the objects affect the same elements. The use of subvectors/submatrices increases CPU cache reuse, lower's memory requirements, increases application performance and improves code readability. To again obtain a view of the full vector/matrix, see *) procedure SetSubRange(Index: integer; Len: integer); overload; (*Prevents calls to . Prevents calls to method. This can be usefull guard when an object is already working on a subrange and the user would like to further subrange an already subranged object. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TOpenCLVector a,b; clMtxVec.CreateIt(out a, out b); try { a.SetIt(false, new double[] {1,2,3,4,5,6,7,8,9}); a.SetSubRange(0,2); //a = [1,2] a.DisableSubrange(); a.SetSubRange(2,2); //exception raised here b.SetSubRange(a,2,2); //but this will work a.SetFullRange(); //b is not changed, it still points to [4,5] } finally { MtxVec.FreeIt(ref a, ref b); } } } *) procedure DisableSubrange; (*Enables calls to . Enables calls to by removing the block set by . *) procedure EnableSubrange; (*Prevents calls to . Prevents calls to method. This can be usefull guard when an object is already working on a subrange and the user would like to further subrange an already subranged object. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TOpenCLVector a,b; MtxVec.CreateIt(out a, out b); try { a.SetIt(false, new double[] {1,2,3,4,5,6,7,8,9}); a.Select(0,2); //a = [1,2] a.DisableSelect(); a.Select(2,2); //exception raised here b.Select(a,2,2); //but this will work a.SelectAll(); //b is not changed, it still points to [4,5] } finally { MtxVec.FreeIt(ref a, ref b); } } } *) procedure DisableSelect; (*Enables calls to . Enables calls to by removing the block set by . *) procedure EnableSelect; (*Resets any defined selection. *) procedure SelectAll; overload; (*Selects a set of elements from the vector. The method will define a subarray starting at Index and ending at Index+Len-1. No copying will occur, only pointers will be shifted. All values of the original will be preserved. An exception will be raised if an attempt is made to change the size of the calling object after a selection has been made. A selection will behave exactly as if the object always contained only the selected values. When a selection is made from another object the source object and all operations done on either of the two objects will affect the same elements. The use of selections increases CPU cache reuse, lower's memory requirements, increases application performance and improves code readability. To again obtain a view of the full vector/matrix use the method. When selecting elements from other objects, care must be given not to use the selections after the source object has been freed: var a,b: TOpenCLVector; begin CreateIt(a,b); try a.SetIt(False,[1,2,3,4]); b.Select(a,2,2); FreeIt(a); //free the source object b.Values[0] := b.Valuess[1]; //b does not point to valid memory anymore finally FreeIt(a); end; end; *) procedure Select(Index: integer; Len: integer); overload; (*Resets the selection. This method is the same as the method. *) procedure Select; overload; (*Sets the subarray size to full size. This method is the same as the method. *) procedure SetSubRange; overload; (*Defines a subarray. The method will define a sub array starting at BeginIndex and ending at EndIndex (inclusive). All values of the original vector/matrix will be preserved. An exception will be raised if an attempt is made to change the size of calling vector/matrix. A subarray is array which does not have its own memory allocated. Instead it adopts the memory of the source object and all operations done on the either of the objects affect the same elements. The use of subarrays increases CPU cache reuse, lower's memory requirements, increases application performance and improves code readability. To again obtain a view of the full vector see *) procedure SetSubIndex(BeginIndex, EndIndex: integer); overload; (*Matrix array multiplication. Multiplies elements in Mtx matrix with the elements in the calling matrix (array multiplication) and stores the results in calling matrix. The , and Complex properties of both matrices must match, otherwise an exception is raised. var A,B,C: clMatrix; begin A.CopyFromArray(2,2,TSingleArray.Create(1,2, 2,4)); B.CopyFromArray(2,2,TSingleArray.Create(1,2, 2,4)); C.MulElem(A,B); // C becomes: // [1, 4, // 4,16] end; *) function MulElem(Mtx: TOpenCLMatrix): TOpenCLMatrix; overload; (*Multiplies elements in Mtx1 matrix with the elements in Mtx2 matrix (array multiplication) and stores the results in calling matrix. The , and Complex properties of calling matrix are set implicitly to match those of Mtx1 and Mtx2 matrices. Mtx1 and Mtx2 Rows, Cols, and Complex properties must be the same, otherwise an excetion is raised. raised. *) function MulElem(Mtx1, Mtx2: TOpenCLMatrix): TOpenCLMatrix; overload; (*The inverse of clMatrix elements. Calculates the inverse of all clMatrix elements in place. The computation occurs after first limiting the magnitude of each elements by the lower bound of Treshhold. The limiting operation is performed to avoid division by zero. Since Treshold represents a magnitude, it is always real and must always be positive. For complex versions, the magnitude of the input is limited, but the phase remains unchanged. Zero-valued input is assumed to have zero phase. To bypass the limiting operation set the Threshold to zero. var A: clMatrix; begin A.CopyFromArray(2,2,TSingleArray.Create(1,2, 2,4)); // 2x2, not complex clMatrix A.InvElem(1.0e-7); end; *) function InvElem(): TOpenCLMatrix; overload; function InvElem(const X: TOpenCLMtxVec): TOpenCLMatrix; overload; procedure Adopt(const Src: TOpenCLMatrix); overload; (*Copy object values. Copy each of Vec elements to the calling object. Size and properties of the calling object are set implicitly to match Vec object. var a,b,c: clMatrix; begin a.CopyFromArray(2,2,TSingleArray.Create(1,2,3,4)); // a = [1,2,3,4] b.Copy(a); // b = [1,2,3,4] end; *) function Copy(const Vec: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Copy Vec elements [VecIndex]..[VecIndex+Len-1] in the calling object elements [Index]..[Index+Len-1]. Size and properties must be set explicitly. An exception is raised if array borders are overrun or underrun. *) function Copy(const Vec: TOpenCLMtxVec; VecIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Add each of Vec2 elements to corresponding elements in Vec1. The results are stored in the calling object. Size and properties of the calling object are set implicitly to match Vec1 and Vec2 vectors. *) function Add(const Vec1, Vec2: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Add Vec1 elements [Vec1Index]..[Vec1Index+Len-1] to Vec2 elements [Vec2Index]..[Vec2Index+Len-1]. Store the results in calling object elements [Index]..[Index+Len-1]. An exception is raised if array borders are overrun. *) function Add(const Vec1, Vec2: TOpenCLMtxVec; Vec1Index, Vec2Index, Index, Len: integer): TOpenCLMtxVec; overload; (*Adds Value to object elements. *) function Add(Value: double): TOpenCLMtxVec; overload; (*Adds complex Value to all calling object complex elements.*) function Add(Value: TCplx): TOpenCLMtxVec; overload; (*Adds Value to calling object elements [Index]..[Index+Len-1]. An exception is raised if array borders are overrun. *) function Add(Value: double; Index, Len: integer): TOpenCLMtxVec; overload; (*Adds complex Value to calling object complex elements [Index]..[Index+Len-1]. An exception is raised if array borders are overrun. *) function Add(Value: TCplx; Index, Len: integer): TOpenCLMtxVec; overload; (*Adds Value to the each element of the Vec object. Stores the result in the calling object. Size and properties of the calling object are set automatically. *) function Add(const Vec: TOpenCLMtxVec; Value: double): TOpenCLMtxVec; overload; (*Adds complex Value to each element of the Vec object. Store the result to the calling object. Size property of the calling object is set automatically. property of the calling object is set to True. *) function Add(const Vec: TOpenCLMtxVec; Value: TCplx): TOpenCLMtxVec; overload; (*Adds Value to each element of Vec object in range [VecIndex]..[VecIndex+Len-1]. Stores result to elements [Index]..[Index+Len-1] of the calling object. Size of the calling object is not changed. An exception is raised if array borders are overrun. property of the calling object is set implicitly. *) function Add(const Vec: TOpenCLMtxVec; Value: double; VecIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Adds complex Value to each elements of the Vec object in range [VecIndex]..[VecIndex+Len-1]. Stores the result to elements [Index]..[Index+Len-1] of the calling object. Size of the calling object is not changed. An exception is raised if array borders are overrun. property of the calling object is set to True. *) function Add(const Vec: TOpenCLMtxVec; Value: TCplx; VecIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Array addition. Add each of Vec elements to corresponding elements in the calling object. *) function Add(const Vec: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Add Vec elements [VecIndex]..[VecIndex+Len-1] to calling object elements [Index]..[Index+Len-1]. An exception is raised if array borders are overrun. *) function Add(const Vec: TOpenCLMtxVec; VecIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Split complex calling object in real and imaginary part. Split calling object into real and imaginary components. Store all real components in ReVec and all imaginary components in ImVec. Size and properties of ReVec and ImVec are set implicitly to match with the calling vector. An execption is raised if calling object is not complex. var a,b,c: clMatrix; begin a.CopyFromArray(2,2,TSingleArray.Create(1,-2,3,4)); a.CplxToReal(b,c); end; *) procedure CplxToReal(ReVec, ImVec: TOpenCLMtxVec); overload; (*Split calling object elements [Index]..[Index+Len-1] into real and imaginary components. Store real components in ReVec elements [ReIndex]..[ReIndex+Len-1] and imaginary components in ImVec elements [ImIndex]..[ImIndex+Len-1]. Size and properties must be set explicitly. An exception is raised if array borders are overrun or underrun. *) procedure CplxToReal(ReVec, ImVec: TOpenCLMtxVec; ReIndex, ImIndex, Index, Len: integer); overload; (*Constructs a complex object from two real objects. Construct a complex object from the ReVec (real part) and the ImVec (imaginary part) objects. The results are stored in the calling object. Size and properties of the calling object are set implicitly to match ReVec and ImVec objects. An exception is raised if ReVec or ImVec property is True. var a,b,c: clMatrix; begin a.CopyFromArray(2,2,TSingleArray.Create(1,2,3,4)); b.CopyFromArray(2,2,TSingleArray.Create(2,2,3,4)); c.RealToCplx(a,b); end; *) function RealToCplx(ReVec, ImVec: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Construct a complex object from the ReVec elements [ReIndex]..[ReIndex+Len-1] (real part) and the ImVec elements [ImIndex]..[ImIndex+Len-1] (imaginary part). The results are stored to calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if array borders are overrun. An exception is also raised if ReVec or ImVec property is True. *) function RealToCplx(ReVec, ImVec: TOpenCLMtxVec; ReIndex, ImIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Conjugate. Conjugate all calling object elements in-place. var c: clMatrix; begin c.CopyFromArray(2,2,TSingleArray.Create(1,2,3,4)); // c = [1+2i, 3+4i] c.Conj; // c = [1-2i, 3-4i] end; *) function Conj: TOpenCLMtxVec; overload; (*Conjugate calling object elements [Index]..[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function Conj(Index,Len: integer): TOpenCLMtxVec; overload; (*Conjugate each of Vec elements. Store the results in the calling object. The Size and properties of the calling object are set implicitly to match Vec vector. *) function Conj(const Vec: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Conjugate Vec elements Vec[VecIndex]..Vec[VecIndex+Len-1]. Store them in the calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if array borders are overrun. *) function Conj(const Vec: TOpenCLMtxVec; VecIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Extend Vec object to complex calling object. If Zeros is true then the calling vector imaginary part is set to zero, otherwise the calling object imaginary part is the same as calling object real part. var a,b: clMatrix; begin a.CopyFromArray(2,2, TSingleArray.Create(1,2,3,4)); b.ExtendToComplex(a,True); end; *) function ExtendToComplex(const Src: TOpenCLMtxVec; Zeros: Boolean): TOpenCLMtxVec; overload; (*Converts the source to complex. Converts the source to complex by setting the imaginary part to either zero (zeros = True) or same as real (zeros = false). Does not set size of the calling vector. If there is not sufficient space available to store the result an exception will be raised. *) function ExtendToComplex(const Src: TOpenCLMtxVec; Zeros: Boolean; SrcIndex,DstIndex, Len: integer): TOpenCLMtxVec; overload; (*Sets angle in [-2PI,2PI]. ThetaRad within -2 and interval. Calling this function prior to passing the value to trigonometric functions can significantly improve numerical accuracy. Sine/cosine appear within many other functions especially complex versions of trigonometric functions. FixAngle method is not used implicitely within TOpenCLMtxVec methods. To achieve maximum performance make sure that the arguments passed to complex trigonometric functions are "small" or scaled down. Note The vector must be real. *) function FixAngle: TOpenCLMtxVec; overload; (*FixAngle for calling object complex elements [Index]..[Index+Len-1] in-place. An exception is raised if calling object property is True or if array borders are overrun/underrun. *) function FixAngle(Index,Len: integer): TOpenCLMtxVec; overload; (*Sets angle in [-2PI,2PI] for all Src elements. Stores the results in the calling object. Size and properties of the calling vector are set implicitly to match the Src object. *) function FixAngle(const Src: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Sets angle in [-2PI,2PI] for Src elements [SrcIndex]..[SrcIndex+Len-1] and store the results in the calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if array borders are overrun. *) function FixAngle(const Src: TOpenCLMtxVec; SrcIndex, Index,Len: integer): TOpenCLMtxVec; overload; (*Rounds towards negative infinity. Rounds all calling object elements towards negative infinity in-place. Floor(-2.8) = -3 Floor(2.8) = 2 Floor(-1.0) = -1 *) function Floor: TOpenCLMtxVec; overload; (*Rounds calling object elements [Index]..[Index+Len-1] towards negative infinity in-place. An exception is raised if array borders are overrun. *) function Floor(Index,Len: integer): TOpenCLMtxVec; overload; (*Rounds all Src object elements towards negative infinity and stores the result in the calling object. Size and properties of the calling object are adjusted automatically. *) function Floor(const Src: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Rounds Src object elements [SrcIndex]..[SrcIndex+Len-1] towards negative infinity and stores the result in the calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if array borders are overrun. *) function Floor(const Src: TOpenCLMtxVec; SrcIndex, Index,Len: integer): TOpenCLMtxVec; overload; (*A complex exponential e^(j*Omega)). Calculate the calling object complex exponential in-place. An exception is raised if calling object is complex. If object is complex, you should use the method instead. var a: clMatrix; begin a.CopyFromArray(2,2,TSingleArray.Create(1,2,3,4)); a.Expj; // a = [e^i, e^2i, e^3i, e^4i] end; *) function Expj: TOpenCLMtxVec; overload; (*Calculate the e^(j*Omega), a complex exponential. Omega must be a real object. If omega is complex, then use the method. *) function Expj(Omega: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Calculate the complex exponential for Omega elements [OmegaIndex]..[OmegaIndex+Len-1]. Store the results in calling object elemets [Index]..[Index+Len-1]. Size and properties of the calling vector must be set explicitly. An exception is raised if array borders are overrun or underrun. *) function Expj(Omega: TOpenCLMtxVec; OmegaIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Fractional part of values. Calculates the fractional part for all object values in-place. var a: clMatrix; ind: Integer; begin a.CopyFromArray(2,2,TSingleArray.Create(1,5.5,-1.6,6)); // a = [1, 5.5, -1.6, 6] a.Frac; // a = [0, 0.5, -0.6, 0] finally a.Free; end; end; *) function Frac: TOpenCLMtxVec; overload; (*Calculates the fractional part for all X object values. Stores the result in calling object. Size and properties of calling object are adjusted automatically. *) function Frac(const X: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Calculates the fractional part for calling object elements [Index]..[Index+Len-1] in-place. An exception is raised if array borders are overrun or underrun. *) function Frac(Index,Len: integer): TOpenCLMtxVec; overload; (*Calculates the fractional part for X object elements [XIndex]..[XIndex+Len-1]. Stores the result in calling object elements [Index]..[Index+Len-1]. An exception is raised if array borders are overrun or underrun. *) function Frac(const X: TOpenCLMtxVec; XIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Complementary error functon of values. Calculates the complementary error function value for all object values in-place. var a: clMatrix; begin a.CopyFromArray(2,2,TSingleArray.Create(1,5.5,-1.6,6)); // a = [1, 5.5, -1.6, 6] a.Erfc; end; *) function Erfc: TOpenCLMtxVec; overload; (*Calculates the complementary error function value for all Src object values. Stores the result in calling object. Size and properties of calling object are adjusted automatically. *) function Erfc(const Src: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Calculates the complementary error function value for calling object elements [Index]..[Index+Len-1] in-place. An exception is raised if array borders are overrun or underrun. *) function Erfc(Index,Len: integer): TOpenCLMtxVec; overload; (*Calculates the complementary error function value for Src object elements [SrcIndex]..[SrcIndex+Len-1]. Stores the result in calling object elements [Index]..[Index+Len-1]. An exception is raised if array borders are overrun or underrun. *) function Erfc(const Src: TOpenCLMtxVec; SrcIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Error functon of values. Calculates the error function for all object values in-place. var a: clMatrix; ind: Integer; begin a.CopyFromArray(2,2,TSingleArray.Create(1, 5.5, -1.6, 6)); // a = [1, 5.5, -1.6, 6] a.Erf; end; *) function Erf: TOpenCLMtxVec; overload; (*Calculates the error function for all Src object values. Stores the result in calling object. Size and properties of calling object are adjusted automatically. *) function Erf(const Src: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Calculates the error function for calling object elements [Index]..[Index+Len-1] in-place. An exception is raised if array borders are overrun or underrun. *) function Erf(Index,Len: integer): TOpenCLMtxVec; overload; (*Calculates the error function for Src object elements [SrcIndex]..[SrcIndex+Len-1]. Stores the result in calling object elements [Index]..[Index+Len-1]. An exception is raised if array borders are overrun or underrun. *) function Erf(const Src: TOpenCLMtxVec; SrcIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Flips the real and imaginary part of complex numbers. Flipped real and imaginary part of complex numbers for all calling object elements in-place. The following transformation is used: a + i*b -> b + i*a *) function Flip: TOpenCLMtxVec; overload; (*Flips the real and imaginary part of complex numbers for calling object elements [Index]..[Index+Len-1] in-place. An exception is raised if array borders are overrun or underrun. *) function Flip(Index, Len: integer): TOpenCLMtxVec; overload; (*Flips the real and imaginary part of complex numbers for all X object elements. Xtore the results in the calling object. Size and properties of calling object are adjusted automatically. *) function Flip(const X: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Flips the real and imaginary part of complex numbers for X object elements [XIndex]..[XIndex+Len-1]. Store the results in the calling object elements [Index]..[Index+Len-1]. An exception is raised if array borders are overrun or underrun. *) function Flip(const X: TOpenCLMtxVec; XIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Flips the real and imaginary part of complex numbers and conjugates the complex numbers. Performs the following transformation: a + i*bi ==> b - i*a Method flips the real and imaginary part and conjugates calling object complex elements in-place. *) function FlipConj: TOpenCLMtxVec; overload; (*Flip calling object complex elements [Index]..[Index+Len-1] in-place. An exception is raised if calling object property is false or if array borders are overrun/underrun. *) function FlipConj(Index, Len: integer): TOpenCLMtxVec; overload; (*Flip all X object complex elements. Store the results in calling object. Size and property of calling object are adjusted automatically. *) function FlipConj(const X: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Flip X object complex elements [XIndex]..[XIndex+Len-1]. Store the results in calling object elements [Index]..[Index+Len-1]. An exception is raised if calling object property is false or if array borders are overrun/underrun. *) function FlipConj(const X: TOpenCLMtxVec; XIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*The Reminder after division X/Y. Calculates reminder after division according to formula: x[i]-y[i]*Trunc(x[i]/y[i]). The results will be saved to the calling vector. X and Y must be a real and have the same length. Size and properties of the calling vector are set implicitly to match the X object. var a,b,c: clMatrix; begin a.CopyFromArray(2,2,TSingleArray.Create(0,1,10,-1,-10)); // a = [0, 1, 10, -1]; b.CopyFromArray(2,2,TSingleArray.Create(0,1,PI,-1,-PI)); // b = [0, 1, PI, -1]; c.Rem(a,b); // c = [0, 0, 0.5752, 0] end; *) function Rem(const X, Y: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Calculates reminder after division X/Y. Calculation uses the following formula: z[i] = x[xi]-y[yi]*Trunc(x[xi]/y[yi]), where i in [Index..Index+Len], xi in [XIndex..XIndex+Len], yi in [YIndex..YIndex+Len]. The results will be saved to the calling vector. X must be a real. An exception will be raised if array borders are overrun. *) function Rem(const X, Y: TOpenCLMtxVec; XIndex, YIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Calculates reminder after division X/Y. Reminder is calculated by using the following formula: x[i]-y*Trunc(x[i]/y). X must be a real. The results will be saved to the calling vector. Size and properties of the calling vector are set implicitly to match the X object. *) function Rem(const X: TOpenCLMtxVec; Y: double): TOpenCLMtxVec; overload; (*Calculates reminder after division X/Y. Reminder is calculated by using the following formula: x[i]-y*Trunc(x[i]/y). X must be a real. The results will be saved to the calling vector. An exception will be raised if array borders are overrun. *) function Rem(const X: TOpenCLMtxVec; Y: double; XIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Multiply object elements with Value. Multiply all calling object elements with Value in-place. This method is the same as the method overloads multiplying with vector elements with a scalar. var v: clMatrix; begin v.CopyFromArray(2,2,TSingleArray.Create(2,3,5)); // v = [2,3,5] v.Scale(3); // v = [6,9,15] end; *) function Scale(Factor: double): TOpenCLMtxVec; overload; (*Multipy calling object elements [Index]..[Index+Len-1] with Value in-place. An exception is raised if array borders are overrun or underrun. *) function Scale(Factor: double; Index, Len: integer): TOpenCLMtxVec; overload; (*Multiply all calling object elements with a complex Value in-place.*) function Scale(Factor: TCplx): TOpenCLMtxVec; overload; (*Multipy calling object elements [Index]..[Index+Len-1] with complex Value in-place. An exception is raised if array borders are overrun or underrun. *) function Scale(Factor: TCplx; Index, Len: integer): TOpenCLMtxVec; overload; (*Log base N. Log base N for all calling object elements in-place. var a: clMatrix; begin a.CopyFromArray(2,2,TSingleArray.Create(1,2,3,4)); // a = [1,2,3,4] a.LogN(10.0); // log base 10, the slow way a = [Log10(1), Log10(2),...] end; *) function LogN(N: double): TOpenCLMtxVec; overload; (*Calculate the log base N of calling object elements [Index]..[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function LogN(N: double; Index, Len: integer):TOpenCLMtxVec; overload; (*Calculate the log base N of all X object elements. Store the results in calling object. Size and properties of the calling object are adjusted automatically. *) function LogN(N: double; X: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Calculate the log base N of X object elements [XIndex]..[XIndex+Len-1]. The results are stored in calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object are not changed. An exception is raised if array borders are overrun. *) function LogN(N: double; X: TOpenCLMtxVec; XIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Normalize object. Normalizes Vec object by subtracting a constant Offset from Vec elements and dividing the result by constant Factor: The results are stored in calling object. Use this method if you want to do a multiply and add (scale and offset) operations in a single method call. var a,b: clMatrix; begin a.CopyFromArray(2,2,TSingleArray.Create(1,2,3,4)); b.Normalize(a,2,3); end; *) function Normalize(const Vec: TOpenCLMtxVec; SubOffset, DivFactor: double): TOpenCLMtxVec; overload; (*Normalize Vec object values [VecIndex]..[VecIndex+Len-1] by subtracting a real constant SubOffset from Vec elements and dividing the result by complex constant DivFactor. Store the results in calling vector values [Index]..[Index+Len-1]. An exception is raised if Vec or calling object is complex or array borders are overrun/underrun. *) function Normalize(const Vec: TOpenCLMtxVec; SubOffset, DivFactor: double; VecIndex,Index,Len: integer): TOpenCLMtxVec; overload; (*Normalize Vec object by subtracting a complex constant SubOffset from Vec elements and dividing the result by real constant DivFactor. Size and property of calling object are adjusted automatically. *) function Normalize(const Vec: TOpenCLMtxVec; SubOffset: TCplx; DivFactor: double): TOpenCLMtxVec; overload; (*Normalize Vec object complex values [VecIndex]..[VecIndex+Len-1] by subtracting a complex constant SubOffset from Vec elements and dividing the result by real constant DivFactor. Store the results in calling vector complex values [Index]..[Index+Len-1]. An exception is calling object is not complex or array borders are overrun/underrun. *) function Normalize(const Vec: TOpenCLMtxVec; SubOffset: TCplx; DivFactor: double; VecIndex,Index,Len: integer): TOpenCLMtxVec; overload; (*Raises base object elements to any power. Raises Base calling object elements to any power. The is faster, if Exponent is an integer. Real valued power can handle only positive Exponent. can handle negative exponent also. To compute a power to the negative exponent in general case or when the base is negative, use the complex version of the function. var a: clMatrix; begin a.CopyFromArray(2,2,TSingleArray.Create(1,2,3,4)); a.Power(1.2); end; *) function Power(Exponent: double): TOpenCLMtxVec; overload; (*Raises all calling vector elements to complex power Exponent in-place. If the calling vector is real and has negative elements, the result will be NAN at those entries. To obtain a valid result in this case, extend the calling vector to complex with method. In all real/complex combinations, the Power method will not automatically assume that a number is complex to speed up the computation. Alternatively the user can of course always convert the real numbers to complex before passing them to the Power routine. *) function Power(Exponent: TCplx): TOpenCLMtxVec; overload; (*Raises base elements to exponent power. Raises Base value to Exponent object values powers and store the results to calling object values. Size and properties of calling object are adjusted automatically. *) function Power(const aBase: double; Exponent: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Raises Base complex value to Exponent object values powers. Store the results to calling object values. Size and properties of calling object are adjusted automatically. *) function Power(const aBase: TCplx; Exponent: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Raises each of the Base object elements to complex Exponent power. Size and properties of calling object are adjusted automatically. *) function Power(const aBase: TOpenCLMtxVec; Exponent: TCplx): TOpenCLMtxVec; overload; (*Raises each of the Base object elements to real Exponent power. Size and properties of calling object are adjusted automatically. *) function Power(const aBase: TOpenCLMtxVec; Exponent: double): TOpenCLMtxVec; overload; (*Raises each of Base object elements to corresponding power, stored in Exponenet elements. Power[i] = Base[i]^Exponent[i] Size and property of calling object are adjusted automatically. An exception is raised if Base and Exponent sizes do not match. *) function Power(const aBase, Exponent: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Raises Base object elements to Exponent object elements power. Raises Base elements to Exponent elements power. Only positive exponents can be handled if exponent object property is True. var a,b,c: clMatrix; begin a.CopyFromArray(2,2,TSingleArray.Create(1,2,3,4)); b.CopyFromArray(2,2,TSingleArray.Create(3,3,2,2)); c.PowerVec(a,b); // c = [1,8,9,16] end; *) function PowerVec(const Base, Exponent: TOpenCLMtxVec): TOpenCLMtxVec; (*Standard deviation. Calculate the standard deviation of all calling object elements. The result is a real value. An exception is raised if calling vector Complex property is true. var a: clVector; c: double; aMean: double; begin a.CopyFromArray(TDoubleArray.Create(1,2,3,4)); Caption := FloatToSTr(a.RMS); end; *) function RMS: double; overload; (*Elements rounded to the nearest whole number. Rounds all calling object elements to the nearest whole number. The result can be stored to an array of integers or as floating point number. *) function Round: TOpenCLMtxVec; overload; (*Round calling object elements [Index]..[Index+Len-1] in-place. An exception is raised if array borders are overrun/underrun. *) function Round(Index,Len: integer): TOpenCLMtxVec; overload; (*Round all Src object elements. Store the results in calling object elements. Size and property of calling object are adjusted automatically. *) function Round(const Src: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Round Src object elements [SrcIndex]..[SrcIndex+Len-1]. Store the results to calling object elements [Index]..[Index+Len-1]. Size and property of the calling object must be set explicitly. An exception is raised if array borders are overrun/underrun. *) function Round(const Src: TOpenCLMtxVec; SrcIndex,Index,Len: integer): TOpenCLMtxVec; overload; (*Initialize elements to Value. Set all calling object elements to Value. If the calling object is complex then the real part is set to Value and the imaginary is set to zero. var a: clMatrix; begin a.Size(4,False); a.SetVal(1); // a = [1,1,1,1] end; *) function SetVal(Value: double): TOpenCLMtxVec; overload; (*Set all calling object elements [Index]..[Index+Len-1] to real Value. If the calling object is complex then the real part is set to Value and the imaginary is set to zero. An exception is raised if array borders are overrun/underrun. *) function SetVal(Value: double; Index, Len: integer): TOpenCLMtxVec; overload; (*Set all calling object complex elements to complex Value.*) function SetVal(Value: TCplx): TOpenCLMtxVec; overload; (*Set calling object complex elements [Index]..[Index+Len-1] to complex Value. property of the calling object are set to true even before the call it was false. An exception is raised if calling object array borders are overrun/underrun. *) function SetVal(Value: TCplx; Index: integer; Len: integer): TOpenCLMtxVec; overload; (*Initializes object elements to zero. *) function SetZero: TOpenCLMtxVec; overload; (*Initializes calling object elements [Index]..[Index+Len-1] to zero. An exception is raised if array borders are overrun. *) function SetZero(Index, Len: integer): TOpenCLMtxVec; overload; (*Changes elements sign. Changes all calling object elements sign (v -> -v) in-place. var a: clMatrix; begin a.CopyFromArray(2,2,TSingleArray.Create(1,2,-3,4)); a.Sign; // a = [-1,-2,3,-4] end; *) function Sign: TOpenCLMtxVec; overload; (*Change calling object elements [Index]..[Index+Len-1] sign in-place. An exception is raised if array borders are overrun or underrun. *) function Sign(Index,Len: integer): TOpenCLMtxVec; overload; (*Change all X object elements sign. Store the results in calling object. Size and properties of calling object are adjusted automatically. *) function Sign(const X: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Change X object elements [XIndex]..[XIndex+Len-1] sign. Store the results in callingobject elements [Index]..[Index+Len-1]. An exception is raised if array borders are overrun or underrun. *) function Sign(const X: TOpenCLMtxVec; XIndex,Index,Len: integer): TOpenCLMtxVec; overload; (* Computes signum function of calling object elements. Signum(X) is 1 for X > 0 , equal to zero for X = 0 and -1 for X < 0. *) function Sgn: TOpenCLMtxVec; overload; (* Computes signum function of calling object elements [Index..Index+Len-1]. Signum(X) is 1 for X > 0 , equal to zero for X = 0 and -1 for X < 0. *) function Sgn(Index, Len: integer): TOpenCLMtxVec; overload; (* Computes signum function from Src elements and stores the result in the calling object. Size and properties of calling object are adjusted automatically. Signum(X) is 1 for X > 0 , equal to zero for X = 0 and -1 for X < 0. *) function Sgn(const Src: TOpenCLMtxVec): TOpenCLMtxVec; overload; (* Computes signum function from Src elements [SrcIndex..SrcIndex+Len-1] and stores the result in the calling object [Index..Index+Len-1]. Size and properties of calling object are adjusted automatically. Signum(X) is 1 for X > 0 , equal to zero for X = 0 and -1 for X < 0. *) function Sgn(const Src: TOpenCLMtxVec; SrcIndex,Index,Len: integer): TOpenCLMtxVec; overload; (*Signum. Calculates the signum of all Src object elements and multiplies it with the calling object elements accordingly. Signum(X) is 1 for X > 0 , equal to zero for X = 0 and -1 for X < 0. The length of Src and of the calling object must match or an exception will be raised. Size and property of calling object are adjusted automatically. *) function SgnMul(const Src: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Sine and cosine. Calculates the sine and cosine for all calling object elements and stores the sines to SinX and cosines to CosX. Size and property of SinX and CosX are adjusted automatically. Note Use this method if you require both sine and cosine. var a: clMatrix; s,c: clMatrix; begin a.CopyFromArray(2,2,TSingleArray.Create(0,PiDiv2,PI,0)); a.SinCos(s,c); // s=[0,1,0,0], c =[1,0,-1,1] end; *) procedure SinCos(SinX, CosX: TOpenCLMtxVec); overload; (*Calculates the sine and cosine for calling object elements [Index]..[Index+Len-1]. stores the sines to SinX elemets [SinXIndex]..[SinXIndex+Len-1] and cosines to CosX elements [CosXIndex]..[CosXIndex+Len-1] elements. Size and property of SinX and CosX objects are not set automatically. An exception is raised if array borders are overrun/underun. *) procedure SinCos(SinX, CosX: TOpenCLMtxVec; SinXIndex, CosXIndex, Index, Len: integer); overload; (*Hyperbolic sine and cosine. Calculates the hyperbolic sine and hyperbolic cosine for all calling object elements and stores the sines to SinhX and cosines to CoshX. Size and property of SinhX and CoshX are adjusted automatically. Note Use this method if you require hyperbolic sine and hyperbolic cosine. var a: clMatrix; s,c: clMatrix; begin a.CopyFromArray(2,2,TSingleArray.Create(0,PiDiv2,PI,0)); a.SinhCosh(s,c); end; *) procedure SinhCosh(SinhX, CoshX: TOpenCLMtxVec); overload; (*Calculates the hyperbolic sine and hyperbolic cosine for calling object elements [Index]..[Index+Len-1]. Stores the sines to SinhX elemets [SinhIndex]..[SinhIndex+Len-1] and cosines to CoshX elements [CoshIndex]..[CoshIndex+Len-1] elements. Size and property of SinhX and CoshX objects are not set automatically. An exception is raised if array borders are overrun/underun. *) procedure SinhCosh(SinhX, CoshX: TOpenCLMtxVec; SinhIndex, CoshIndex, Index, Len: integer); overload; (*Threshold bottom operation. Perform threshold operation on all calling object values. The Value parameter is a lower bound for threshold operation. All values smaller than Value will be replaced with Value. var a: clMatrix; begin a.CopyFromArray(2,2,TSingleArray.Create(2,0.1,3,4)); a.ThreshBottom(0.2); // a = [2,0.2,3,4] end; *) function ThreshBottom(Value: double): TOpenCLMtxVec; overload; (*Perform the threshold operation on calling object values [Index]..[Index+Len-1]. An exception is raised if array borders are overrun/underrun. *) function ThreshBottom(Value: double; Index, Len: integer): TOpenCLMtxVec; overload; (*Perform threshold operation on all Src object values. Store the results in calling object. Size and properties of the calling object are adjusted automatically. *) function ThreshBottom(const Src: TOpenCLMtxVec; Value: double): TOpenCLMtxVec; overload; (*Perform a threshold operation on Vec elements [VecIndex]..[VecIndex+Len-1]. Store the results in the calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if array borders are overrun/underrun. *) function ThreshBottom(const Vec: TOpenCLMtxVec; Value: double; VecIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Threshold top operation. Perform threshold operation on all calling object values. The Value parameter is an upper bound for threshold operation. All values bigger than Value will be replaced with Value. var a: clMatrix; begin a.CopyFromArray(2,2,TSingleArray.Create(2,0.1,3,4)); a.Threshtop(0.2); // a = [0.2,0.1,0.2,0.2] end; *) function ThreshTop(Value: double): TOpenCLMtxVec; overload; (*Perfrom the threshold operation on calling object values [Index]..[Index+Len-1]. An exception is raised if array borders are overrun/underrun. *) function ThreshTop(Value: double; Index, Len: integer): TOpenCLMtxVec; overload; (*Perform threshold operation on all Src object values. Store the results in calling object. Size and properties of the calling object are adjusted automatically. *) function ThreshTop(const Src: TOpenCLMtxVec; Value: double): TOpenCLMtxVec; overload; (*Perform a threshold operation Vec elements [VecIndex]..[VecIndex+Len-1]. Store the results in the calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if array borders are overrun/underrun. *) function ThreshTop(const Vec: TOpenCLMtxVec; Value: double; VecIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Threshold less than operation. Perform operation on all calling object values. The LTValue parameter is an lower bound for threshold operation. All values less than LTLevel will be replaced with LTValue. For complex number comparation is applied with norm of complex value. var a: clMatrix; begin a.CopyFromArray(2,2,TSingleArray.Create(2,0.1,3,4)); a.ThresholdLT(2.3,1.5); // a = [1.5,1.5,3,4] end; *) function ThresholdLT(LTLevel, LTValue: double): TOpenCLMtxVec; overload; (*Perfrom "less than" threshold operation on the calling object values in range [Index]..[Index+Len-1]. An exception is raised if array borders are overrun/underrun. *) function ThresholdLT(LTLevel, LTValue: double; Index, Len: integer): TOpenCLMtxVec; overload; (*Perform "less than" threshold operation on all Vec object values. Store the results in calling object. Size and properties of the calling object are adjusted automatically. *) function ThresholdLT(const Vec: TOpenCLMtxVec; LTLevel, LTValue: double): TOpenCLMtxVec; overload; (*Perform "less than" threshold operation on Vec elements from range [VecIndex]..[VecIndex+Len-1]. Store the results in the calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if array borders are overrun/underrun. An exception will be raised if Vec.Complex and Complex of the calling object are not equal. *) function ThresholdLT(const Vec: TOpenCLMtxVec; LTLevel, LTValue: double; VecIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Perfrom "less than" threshold operation for complex numbers. If the calling object contains none Complex values, an exception will be raised. *) function ThresholdLT(LTLevel: double; LTValue: TCplx): TOpenCLMtxVec; overload; (*Perfrom "less than" threshold operation for complex numbers on the calling object values in range [Index]..[Index+Len-1]. An exception is raised if array borders are overrun/underrun. If the calling object contains none Complex values, an exception will be raised. *) function ThresholdLT(LTLevel: double; LTValue: TCplx; Index, Len: integer): TOpenCLMtxVec; overload; (*Perform "less than" threshold operation for complex numbers on all Vec object values. Store the results in calling object. Size and properties of the calling object are adjusted automatically. If Vec object contains none Complex values, an exception will be raised. *) function ThresholdLT(const Vec: TOpenCLMtxVec; LTLevel: double; LTValue: TCplx): TOpenCLMtxVec; overload; (*Perform "less than" threshold operation for complex numbers on Vec elements from range [VecIndex]..[VecIndex+Len-1]. Store the results in the calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if array borders are overrun/underrun. If Vec object or calling object contain none Complex values, an exception will be raised. *) function ThresholdLT(const Vec: TOpenCLMtxVec; LTLevel: double; LTValue: TCplx; VecIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Threshold greater than operation. Perform operation on all calling object values. The GTValue parameter is an upper bound for threshold operation. All values bigger than LTLevel will be replaced with GTValue. For complex number comparation is applied with norm of complex value. var a: clMatrix; begin a.CopyFromArray(2,2,TSingleArray.Create(2,0.1,3,4)); a.ThresholdGT(2.3,3.4); // a = [2,0.1,3.4,3.4] end; *) function ThresholdGT(GTLevel, GTValue: double): TOpenCLMtxVec; overload; (*Perfrom "greater than" threshold operation on the calling object values in range [Index]..[Index+Len-1]. An exception is raised if array borders are overrun/underrun. *) function ThresholdGT(GTLevel, GTValue: double; Index, Len: integer): TOpenCLMtxVec; overload; (*Perform "greater than" threshold operation on all Vec object values. Store the results in calling object. Size and properties of the calling object are adjusted automatically. *) function ThresholdGT(const Vec: TOpenCLMtxVec; GTLevel, GTValue: double): TOpenCLMtxVec; overload; (*Perform "greater than" threshold operation on Vec elements from range [VecIndex]..[VecIndex+Len-1]. Store the results in the calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if array borders are overrun/underrun. An exception will be raised if Vec.Complex and Complex of the calling object are not equal. *) function ThresholdGT(const Vec: TOpenCLMtxVec; GTLevel, GTValue: double; VecIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Perfrom "greater than" threshold operation for complex numbers. If the calling object contains none Complex values, an exception will be raised. *) function ThresholdGT(GTLevel: double; GTValue: TCplx): TOpenCLMtxVec; overload; (*Perfrom "greater than" threshold operation for complex numbers on the calling object values in range [Index]..[Index+Len-1]. An exception is raised if array borders are overrun/underrun. If the calling object contains none Complex values, an exception will be raised. *) function ThresholdGT(GTLevel: double; GTValue: TCplx; Index, Len: integer): TOpenCLMtxVec; overload; (*Perform "greater than" threshold operation for complex numbers on all Vec object values. Store the results in calling object. Size and properties of the calling object are adjusted automatically. If Vec object contains none Complex values, an exception will be raised. *) function ThresholdGT(const Vec: TOpenCLMtxVec; GTLevel: double; GTValue: TCplx): TOpenCLMtxVec; overload; (*Perform "greater than" threshold operation for complex numbers on Vec elements from range [VecIndex]..[VecIndex+Len-1]. Store the results in the calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if array borders are overrun/underrun. If Vec object or calling object contain none Complex values, an exception will be raised. *) function ThresholdGT(const Vec: TOpenCLMtxVec; GTLevel: double; GTValue: TCplx; VecIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Threshold greater than and less than operation. Perform operation on all calling object values. The LTValue parameter is an lower bound for threshold operation. The GTValue parameter is an upper bound for threshold operation. All values less than LTLevel will be replaced with LTValue. All values bigger than GTLevel will be replaced with GTValue. Operation is available only for none Complex values. var a: clMatrix; begin a.CopyFromArray(2,2,TSingleArray.Create(2,0.1,3,4)); a.ThresholdGT_LT(2.3,3.4,1,0.5); // a = [2,0.5,3.4,3.4] end; *) function ThresholdGT_LT (GTLevel, GTValue, LTLevel, LTValue: double): TOpenCLMtxVec; overload; (*Perfrom "greater than and less than" threshold operation on the calling object values in range [Index]..[Index+Len-1]. An exception is raised if array borders are overrun/underrun. An exception will be raised if the calling object contains complex numbers. *) function ThresholdGT_LT (GTLevel, GTValue, LTLevel, LTValue: double; Index, Len: integer): TOpenCLMtxVec; overload; (*Perform "greater than and less than" threshold operation on all Vec object values. Store the results in calling object. Size and properties of the calling object are adjusted automatically. An exception will be raised if Vec object contains complex numbers. *) function ThresholdGT_LT (const Vec: TOpenCLMtxVec; GTLevel, GTValue, LTLevel, LTValue: double): TOpenCLMtxVec; overload; (*Perform "greater than and less than" threshold operation on Vec elements from range [VecIndex]..[VecIndex+Len-1]. Store the results in the calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if array borders are overrun/underrun. An exception will be raised if Vec object or the calling object contain complex numbers. *) function ThresholdGT_LT(const Vec: TOpenCLMtxVec; GTLevel, GTValue, LTLevel, LTValue: double; VecIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Rounds a real number towards zero and returns the fractional part. Rounds all calling object elements towards zero to an integer and stores the result in the TruncDst object as floating point numbers. The fractional part is stored in the FracDst. *) procedure TruncAndFrac(TruncDst: TOpenCLMtxVec; FracDst: TOpenCLMtxVec); overload; (*Truncate calling object elements [Index]..[Index+Len-1] and store the results to TruncDst object elements [TruncIdx]..[TruncIdx+Len-1]. The fractional parts are saved in FracDst elements [FracIdx]..[FracIdx+Len-1]. Size and property of calling object must be set explicitly to match those of Src object. An exception is raised if array borders are overrun/underrun. *) procedure TruncAndFrac(TruncDst: TOpenCLMtxVec; FracDst: TOpenCLMtxVec; TruncIdx, FracIdx, Index, Len: integer); overload; (*Rounds a real number towards zero. Rounds all calling object elements towards zero to an integer and stores the result in the calling object again as floating point numbers. *) function Trunc: TOpenCLMtxVec; overload; (*Truncate calling object elements [Index]..[Index+Len-1] in-place. An exception is raised if array borders are overrun/underrun. *) function Trunc(Index,Len: integer): TOpenCLMtxVec; overload; (*Truncate all Src object elements. Store the results in calling object elements. Size and property of calling object are adjusted automatically. *) function Trunc(const Src: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Truncate Src object elements [SrcIndex]..[SrcIndex+Len-1]. Store the results to calling object elemenents [Index]..[Index+Len-1]. Size and property of calling object must be set explicitly to match those of Src object. An exception is raised if array borders are overrun/underrun. *) function Trunc(const Src: TOpenCLMtxVec; SrcIndex, Index,Len: integer): TOpenCLMtxVec; overload; (*The inverse of cube root 1/(v)^1/3. Calculate the inverse cube root (1/(element)^(1/3)) of all calling object elements in-place. v.CopyFromArray(2,1,TSingleArray.Create(1,8)); v.InvCbrt; // returns [1,0.5] *) function InvCbrt: TOpenCLMtxVec; overload; (*Calculate the inverse of cube root for calling object elements [Index]..[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function InvCbrt(Index, Len: integer): TOpenCLMtxVec; overload; (*Calculate the inverse of cube root for all X elements. Store the results in the calling object. Size and properties of the calling vector are set implicitly to match the X object. *) function InvCbrt(const X: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Calculate the inverse of cube root for X elements [XIndex]..[XIndex+Len-1]. Store the results in the calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if array borders are overrun. *) function InvCbrt(const X: TOpenCLMtxVec; XIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*The inverse of square root 1/(v)^1/2. Calculate the inverse square root 1/(element)^(1/2)) of all calling object elements in-place. v.CopyFromArray(2,1,TSingleArray.Create(1,16)); v.InvSqrt; // returns [1,0.25] *) function InvSqrt: TOpenCLMtxVec; overload; (*Calculate the inverse of square root for calling object elements [Index]..[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function InvSqrt(Index, Len: integer): TOpenCLMtxVec; overload; (*Calculate the inverse of square root for all X elements. Store the results in the calling object. Size and properties of the calling vector are set implicitly to match the X object. *) function InvSqrt(const X: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Calculate the inverse of square root for X elements [XIndex]..[XIndex+Len-1]. Store the results in the calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if array borders are overrun. *) function InvSqrt(const X: TOpenCLMtxVec; XIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Magnitude. Calculate the magnitude for all calling object elements in-place. This method has the same function as the method. var a: clMatrix; begin a.CopyFromArray(2,2,TSingleArray.Create(1,-2,3,4)); // a = [1,-2, 3,4] a.Mag; // a = [1, 2, 3,4] end; *) function Mag: TOpenCLMtxVec; overload; (*Calculate the magnitude for calling object elements [Index]..[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function Mag(Index, Len: integer): TOpenCLMtxVec; overload; (*Calculate the magnitude for all X elements. Store the results in the calling object elements. Size and properties of the calling vector are set implicitly to match Vec vector. *) function Mag(const X: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Calculate the magnitude for X elements [XIndex]..[XIndex+Len-1]. Store the results in the calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if array borders are overrun. *) function Mag(const X: TOpenCLMtxVec; XIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Multiply all Vec1 elements with corresponding Vec2 elements. Store the results in calling object. Size and property of calling object are adjusted automatically to match those of Vec1 and Vec2. An exception is raised if Vec1 and Vec2 size and property do not match. *) function Mul(const Vec1, Vec2: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Multiply Vec1 elements [Vec1Index]..[Vec1Index+Len-1] with Vec2 object elements [Vec2Index]..[Vec2Index+Len-1]. Store the results in calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if and array borders are overrun or underrun. *) function Mul(const Vec1, Vec2: TOpenCLMtxVec; Vec1Index, Vec2Index, Index, Len: integer): TOpenCLMtxVec; overload; (*Vector multiplication. Multiply each of Vec elements with corresponding elements in the calling object. Size and property of the calling object are set automatically. The result is stored in the calling object. *) function Mul(const Vec: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Multiply Vec elements [VecIndex]..[VecIndex+Len-1] with calling object elements [Index]..[Index+Len-1] in-place. An exception is raised if Vec and calling object property do not match or if array borders are overrun/underrun. *) function Mul(const Vec: TOpenCLMtxVec; VecIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Multiply object elements with Value. Multiplies all calling object elements with Value in-place. var v: clMatrix; begin v.CopyFromArray(3,1,TSingleArray.Create(2,3,5)); // v = [2,3,5] v.Mul(3); // v = [6,9,15] end; *) function Mul(Value: double): TOpenCLMtxVec; overload; (*Multiply all calling object elements with complex Value in-place.*) function Mul(Value: TCplx): TOpenCLMtxVec; overload; (*Multipy calling object elements [Index]..[Index+Len-1] with Value in-place. An exception is raised if array borders are overrun or underrun. *) function Mul(Value: double; Index, Len: integer): TOpenCLMtxVec; overload; (*Multipy calling object elements [Index]..[Index+Len-1] with complex Value in-place. An exception is raised if array borders are overrun or underrun. *) function Mul(Value: TCplx; Index, Len: integer): TOpenCLMtxVec; overload; (*Multiply each element of Vec with Value. Store the result in the calling object. Size and properties of the calling object are adjusted automatically. *) function Mul(const Vec: TOpenCLMtxVec; Value: double): TOpenCLMtxVec; overload; (*Multiply each element of Vec with complex Value. Store the result in the calling object. Size of the calling object is set automatically. property of the calling object is set to True. *) function Mul(const Vec: TOpenCLMtxVec; Value: TCplx): TOpenCLMtxVec; overload; (*Multiply Vec elements [VecIndex]..[VecIndex+Len-1] with Value. Store the result in calling object elements [Index]..[Index+Len-1]. Size of the calling object is not changed. An exception is raised if array borders are overrun or underrun. propertiy of the calling object is set implicitly. *) function Mul(const Vec: TOpenCLMtxVec; Value: double; VecIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Multiply Vec elements [VecIndex]..[VecIndex+Len-1] with complex Value. Store the result in calling object elements [Index]..[Index+Len-1]. Size of the calling object is not changed. An exception is raised if array borders are overrun or underrun. propertiy of the calling object is set to True. *) function Mul(const Vec: TOpenCLMtxVec; Value: TCplx; VecIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Multiply elements by imaginary unit I.*) function MulI: TOpenCLMtxVec; overload; (*Multipy calling object elements [Index]..[Index+Len-1] with I in-place.*) function MulI(Index: integer; Len: integer): TOpenCLMtxVec; overload; (*Multiply X elements with I and store the result in the calling object.*) function MulI(const X: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Multipy X elements [XIndex]..[XIndex+Len-1] with I. Xtore the result in the calling object at locations [Index]..[Index+Len-1]. *) function MulI(const X: TOpenCLMtxVec; XIndex: integer; Index: integer; Len: integer): TOpenCLMtxVec; overload; (*The phase angles (spectrum) of object elements. Calculates the phase angles (spectrum) of all Vec object elements. Phase values are returned in radians and are in the range -PI,PI. Size and properties of the calling object are set implicitly to match Vec object. The phase angles are calculated from the following equation: var a,b: clMatrix; begin a.CopyCplxFromArray(1,2,TSingleArray.Create(1,2,3,-4)); // a = [1 + 2i, 3 - 4i] b.PhaseSpectrum(a); // b = [arctan2(1,2), arctan2(3,-4)]; end; *) function PhaseSpectrum(const Vec: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Calculates the power spectrum from the Vec elements [VecIndex]..[VecIndex+Len-1]. Store the results in calling object elements [Index]..[Index+Len-1]. An exception is raised if array borders are overrun/underrun. *) function PhaseSpectrum(const Vec: TOpenCLMtxVec; VecIndex, Index,Len: integer): TOpenCLMtxVec; overload; (*The power spectrum from object complex values. Calculates the power spectrum from the Vec object complex values and stores the results (power spectrum) in the real calling object. Size and properties of the calling object are set implicitly to match Vec object. The spectrum elements are squares of the magnitudes of the complex input elements: var a,b: clMatrix; begin a.CopyCplxFromArray(1,2,TSingleArray.Create(1,2,3,-4)); // a = [1 + 2i, 3 - 4i] b.PowerSpectrum(a); // b = [1*1 + 2*2, 3*3+(-4)*(-4)] end; *) function PowerSpectrum(const Vec: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Calculates the power spectrum from the Vec complex elements [VecIndex]..[VecIndex+Len-1]. Store the results in calling object real elements [Index]..[Index+Len-1]. An exception is raised if calling object property is true or if array borders are overrun/underrun. *) function PowerSpectrum(const Vec: TOpenCLMtxVec; VecIndex, Index,Len: integer): TOpenCLMtxVec; overload; (*Converts the polar magnitude/phase pairs to cartesian pairs. Convert all AmpltVec and PhaseVec elements (combined) from polar to cartesian form. If AmpltVec and PhaseVec size is not the same , an exeption is raised. The results are stored as complex numbers (x=Re, y=Im) in the calling object. Size and properties of the calling object are set implicitly to match AmpltVec and PhaseVec objects. var a,b,c: clMatrix; begin a.CopyFromArray(2,2,TSingleArray.Create(1,2,3,4)); // a = [1,2,3, 4] //magnitude b.CopyFromArray(2,2,TSingleArray.Create(1,0,1,-1)); // b = [1,0,1,-1] /phase c.PolarToCart(a,b); // result stored in c = projections to Re and Im axis end; *) function PolarToCart(AmpltVec, PhaseVec: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Convert AmpltVec elements [AIndex]..[AIndex+Len-1] and PhaseVec elements [PIndex]..[PIndex+Len-1] from polar form (radius,angle) to cartesian form (x,y). The results are stored as complex numbers (x=Re, y=Im) in the calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if array borders are overrun/underrun. *) function PolarToCart(AmpltVec, PhaseVec: TOpenCLMtxVec; AIndex, PIndex,Index, Len: integer): TOpenCLMtxVec; overload; (*Gets real part of complex object values. The method method gets the real part of a complex object Vec and stores the real results in the calling object. Size and properties of the calling object are set implicitly to match Vec object. Vec property must be true otherwise an exception is raised. var a,b: clMatrix; begin a.CopyCplxFromArray(1,2,TSingleArray.Create(1,2,3,4)); // = [1+2i, 3+4i] b.RealPart(a); // b = [1,3] end; *) function RealPart(const Vec: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Gets the real part of a Vec object complex elements [VecIndex]..[VecIndex+Len-1]. Stores the results in calling object real elements [Index]..[Index+Len-1]. An exception is raised if array borders are overrun or underrun or if Vec object propety is false. *) function RealPart(const Vec: TOpenCLMtxVec; VecIndex,Index,Len: integer): TOpenCLMtxVec; overload; (*Square. Calculate the square of all caling object elements in-place. var a: clMatrix; begin a.CopyFromArray(TSingleArray.Create(1,2,3,4)); a.Sqr; // a=[1,4,9,16] end; *) function Sqr: TOpenCLMtxVec; overload; (*Calculate the square of calling object elements [Index]...[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function Sqr(Index, Len: integer): TOpenCLMtxVec; overload; (*Calculate the square of all X object elements. Store the results in the calling object. Size and properties of calling object are adjusted automatically. *) function Sqr(const X: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Calculate the square of X object elements [XIndex]..[XIndex+Len-1]. The results are stored in calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object are not changed. An exception is raised if array borders are overrun. *) function Sqr(const X: TOpenCLMtxVec; XIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Square root. Calculate the square root of all caling object elements in-place. var a: clMatrix; begin a.CopyFromArray(2,2,TSingleArray.Create(1,4,9,16)); a.Sqrt; // a= [1, 2, 3, 4] end; *) function Sqrt: TOpenCLMtxVec; overload; (*Calculate the square root of calling object elements [Index]...[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function Sqrt(Index, Len: integer): TOpenCLMtxVec; overload; (*Calculate the square root of all X object elements. Store the results in the calling object. Size and properties of the calling object are adjusted automatically. *) function Sqrt(const X: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Calculate the square root of X object elements [XIndex]..[XIndex+Len-1]. The results are stored in calling object elements [Index]..[Index+Len-1]. Size and properties of calling object are not changed. An exception is raised if array borders are overrun. *) function Sqrt(const X: TOpenCLMtxVec; XIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Sine function. Calculate the sine of all caling object elements in-place. var a: clMatrix; begin a.CopyFromArray(2,2,TSingleArray.Create(1,-2,3,4)); a.Sin; // Computes complex sine end; *) function Sin: TOpenCLMtxVec; overload; (*Calculate the sine of calling object elements [Index]...[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function Sin(Index: integer; Len: integer): TOpenCLMtxVec; overload; (*Calculate the sine of all X object elements and store the results in calling object. Size and properties of calling object are adjusted automatically. *) function Sin(const X: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Calculate the sine of X object elements [XIndex]...[XIndex+Len-1]. The results are stored in calling object elements [Index]...[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if array borders are overrun. *) function Sin(const X: TOpenCLMtxVec; XIndex: integer; Index: integer; Len: integer): TOpenCLMtxVec; overload; (*Cosine. Calculate the cosine of all caling object elements in-place. var a: clMatrix; begin a.CopyFromArray(2,2,TSingleArray.Create(1,-2,3,4)); a.Cos; // Computes complex sine end; *) function Cos: TOpenCLMtxVec; overload; (*Calculate the cosine of calling object elements [Index]...[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function Cos(Index: integer; Len: integer): TOpenCLMtxVec; overload; (*Calculate the cosine of all X object elements. Store the results in the calling object.vSize and properties of calling object are adjusted automatically. *) function Cos(const X: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Calculate the cosine of X object elements [XIndex]...[XIndex+Len-1]. The results are stored in calling object elements [Index]...[Index+Len-1]. Size and properties of calling object and the calling object must be set explicitly. An exception is raised if array borders are overrun. *) function Cos(const X: TOpenCLMtxVec; XIndex: integer; Index: integer; Len: integer): TOpenCLMtxVec; overload; (*Tangens. Calculate the tangens of all caling object elements in-place. var a: clMatrix; begin a.CopyFromArray(2,2,TSingleArray.Create(1,-2,3,4)); a.Tan; // Computes complex tangens end; *) function Tan: TOpenCLMtxVec; overload; (*Calculate the tangens of calling object elements [Index]...[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function Tan (Index: integer; Len: integer): TOpenCLMtxVec; overload; (*Calculate the tangens of all X object elements. Store the results in the calling object. Size and properties of calling object are adjusted automatically. *) function Tan(const X: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Calculate the tangens of X object elements [XIndex]...[XIndex+Len-1]. The results are stored in calling object elements [Index]...[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if array borders are overrun. *) function Tan(const X : TOpenCLMtxVec; XIndex: integer; Index: integer; Len: integer): TOpenCLMtxVec; overload; (*Cotangens. Calculate the cotangens of all caling object elements in-place. var a: clMatrix; begin a.CopyFromArray(2,2,TSingleArray.Create(1,-2,3,4)); a.Cot; // Computes complex cotangens end; *) function Cot: TOpenCLMtxVec; overload; (*Calculate the cotangens of calling object elements [Index]...[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function Cot(Index, Len: integer): TOpenCLMtxVec; overload; (*Calculate the cotangens of all X object elements. Store the results in the calling object. Size and properties of calling object are adjusted automatically. *) function Cot(const X: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Calculate the cotangens of X object elements [XIndex]...[XIndex+Len-1]. The results are stored in calling object elements [Index]...[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if array borders are overrun. *) function Cot(const X: TOpenCLMtxVec; XIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Secant. Calculate the secant of all caling object elements in-place. var a: clMatrix; begin a.CopyFromArray(2,2,TSingleArray.Create(1,-2,3,4)); a.Sec; // Computes complex secant end; *) function Sec: TOpenCLMtxVec; overload; (*Calculate the secant of calling object elements [Index]...[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function Sec(Index, Len: integer): TOpenCLMtxVec; overload; (*Calculate the secant of all X object elements. Store the results in the calling object. Size and properties of calling object are adjusted automatically. *) function Sec(const X: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Calculate the secant of X object elements [XIndex]...[XIndex+Len-1]. The results are stored in calling object elements [Index]...[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if array borders are overrun. *) function Sec(const X: TOpenCLMtxVec; XIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Cosecant. Calculate the cosecant of all caling object elements in-place. var a: clMatrix; begin a.CopyFromArray(2,2,TSingleArray.Create(1,-2,3,4)); // a = [1-2i, 3+4i] a.Csc; // Computes complex cosecant end; *) function Csc: TOpenCLMtxVec; overload; (*Calculate the cosecant of calling object elements [Index]...[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function Csc(Index, Len: integer): TOpenCLMtxVec; overload; (*Calculate the cosecant of all X object elements. Store the results in the calling object. Size and properties of calling object are adjusted automatically. *) function Csc(const X: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Calculate the cosecant of X object elements [XIndex]...[XIndex+Len-1]. The results are stored in calling object elements [Index]...[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if array borders are overrun. *) function Csc(const X: TOpenCLMtxVec; XIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*The inverse sine. Calculate the inverse sine of all calling object elements in-place. Values must be between -1 and 1. The return values will be in the range [0,], in radians. var a: clMatrix; begin a.CopyFromArray(2,2,TSingleArray.Create(1,-0.5,0.11,0.9)); a.ArcSin; end; *) function ArcSin: TOpenCLMtxVec; overload; (*Calculate the inverse sine of calling object elements [Index]...[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function ArcSin(Index, Len: integer): TOpenCLMtxVec; overload; (*Calculate the inverse sine of all X object elements. Store the results in the calling object. Size and properties of calling object are adjusted automatically. *) function ArcSin(const X: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Calculate the inverse sine of X object elements [XIndex]...[XIndex+Len-1]. The results are stored in calling object elements [Index]...[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if array borders are overrun. *) function ArcSin(const X: TOpenCLMtxVec; XIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*The inverse cosine. Calculate the inverse cosine of all calling object elements in-place. Values must be between -1 and 1. The return values will be in the range [0,], in radians. var a: clMatrix; begin a.CopyFromArray(2,2,TSingleArray.Create(1,-0.5,0.11,0.9)); a.ArcCos; end; *) function ArcCos: TOpenCLMtxVec; overload; (*Calculate the inverse cosine of calling object elements [Index]...[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function ArcCos(Index, Len: integer): TOpenCLMtxVec; overload; (*Calculate the inverse cosine of all X object elements. Store the results in the calling object. Size and properties of calling object are adjusted automatically. *) function ArcCos(const X: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Calculate the inverse cosine of X object elements [XIndex]...[XIndex+Len-1]. The results are stored in calling object elements [Index]...[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if array borders are overrun. *) function ArcCos(const X: TOpenCLMtxVec; XIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Inverse tangens of Y/X. Calculates the inverse tangens of Y/X, and returns an angle in the correct quadrant. The results are stored in calling object elements. Size and properties of calling object are adjusted automatically to match those of X and Y objects. An exception is raised if X and Y size and properties do not match. Note that is calculated as ArcTan2(1, X). *) function ArcTan2(Y, X: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Calculate the inverse tangens of Y/X. Calculation uses Y elements [YIndex]..[YIndex+Len-1], X elements [XIndex]..[XIndex+Len-1] and stores the results in calling object elements [Index]..[Index+Len-1]. An exception is raised if array borders are overrun. *) function ArcTan2(Y, X: TOpenCLMtxVec; YIndex, XIndex, Index: integer; Len: integer): TOpenCLMtxVec; overload; (*Inverse tangens. Calculate the inverse tangens for all calling object elements in-place. The return values are expressed in radians. var A,B: clMatrix; begin A.CopyCplxFromArray(2,2,TSingleArray.Create(1,0, 2,0 2,0 4,1)); // 2x2, complex matrix B.ArcTan(A); end; *) function ArcTan: TOpenCLMtxVec; overload; (*Calculate the inverse tangens of calling object elements [Index]...[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function ArcTan(Index, Len: integer): TOpenCLMtxVec; overload; (*Calculate the inverse tangens of all X object elements. Store the results in the calling object. Size and properties of calling object are adjusted automatically. *) function ArcTan(const X: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Calculate the inverse tangens of X object elements [XIndex]...[XIndex+Len-1]. The results are stored in calling object elements [Index]...[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if array borders are overrun. *) function ArcTan(const X: TOpenCLMtxVec; XIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Inverse cotangens. Calculate the inverse cotangens for all calling object elements in-place. The return values are expressed in radians. var A,B: clMatrix; begin A.CopyCplxFromArray(2,2,TSingleArray.Create(1,0, 2,0 2,0 4,1)); // 2x2, complex matrix B.ArcCot(A); end; *) function ArcCot: TOpenCLMtxVec; overload; (*Calculate the inverse cotangens of calling object elements [Index]...[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function ArcCot(Index, Len: integer): TOpenCLMtxVec; overload; (*Calculate the inverse cotangens of all X object elements. Store the results in the calling object. Size and properties of calling object are adjusted automatically. *) function ArcCot(const X: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Calculate the inverse cotangens of X object elements [XIndex]...[XIndex+Len-1]. The results are stored in calling object elements [Index]...[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if array borders are overrun. *) function ArcCot(const X: TOpenCLMtxVec; XIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Inverse secant. Calculate the inverse secant for all calling object elements in-place. *) function ArcSec: TOpenCLMtxVec; overload; (*Calculate the inverse secant of calling object elements [Index]...[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function ArcSec(Index, Len: integer): TOpenCLMtxVec; overload; (*Calculate the inverse secant of all X object elements and store the results in the calling object. Size and properties of calling object are adjusted automatically. *) function ArcSec(const X: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Calculate the inverse secant of X object elements [XIndex]...[XIndex+Len-1]. The results are stored in calling object elements [Index]...[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if array borders are overrun. *) function ArcSec(const X: TOpenCLMtxVec; XIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Inverse cosecant. Calculate the inverse cosecant for all calling object elements in-place. *) function ArcCsc: TOpenCLMtxVec; overload; (*Calculate the inverse cosecant of calling object elements [Index]...[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function ArcCsc(Index, Len: integer): TOpenCLMtxVec; overload; (*Calculate the inverse cosecant of all X object elements. Store the results in the calling object. Size and properties of calling object are adjusted automatically. *) function ArcCsc(const X: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Calculate the inverse cosecant of X object elements [XIndex]..[XIndex+Len-1]. The results are stored in the calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if array borders are overrun. *) function ArcCsc(const X: TOpenCLMtxVec; XIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Hyperbolic sine. Calculate the hyperbolic sine of all caling object elements in-place. var a: clMatrix; begin a.CopyFromArray(2,2,TSingleArray.Create(1, 1.5, 2, 0.3)); a.Sinh; end; *) function Sinh: TOpenCLMtxVec; overload; (*Calculate the hyperbolic sine of calling object elements [Index]...[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function Sinh(Index, Len: integer): TOpenCLMtxVec; overload; (*Calculate the hyperbolic sine of all X object elements. Store the results in the calling object. Size and properties of calling object are adjusted automatically. *) function Sinh(const X: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Calculate the hyperbolic sine for X object elements [XIndex]..[XIndex+Len-1]. The results are stored in the calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if array borders are overrun. *) function Sinh(const X: TOpenCLMtxVec; XIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Hyperbolic cosine. Calculate the hyperbolic cosine of all caling object elements in-place. var a: clMatrix; begin a.CopyFromArray(2,2,TSingleArray.Create(1,1.5,2,0.3)); a.Cosh; end; *) function Cosh: TOpenCLMtxVec; overload; (*Calculate the hyperbolic cosine for calling object elements [Index]..[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function Cosh(Index, Len: integer): TOpenCLMtxVec; overload; (*Calculate the hyperbolic cosine for all X object elements. Store the results in the calling object. Size and properties of calling object are adjusted automatically. *) function Cosh(const X: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Calculate the hyperbolic cosine for X object elements [XIndex]..[XIndex+Len-1]. The results are stored in calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if array borders are overrun. *) function Cosh(const X: TOpenCLMtxVec; XIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Hyperbolic tangens. Calculate the hyperbolic tangens of all caling object elements in-place. var a: clMatrix; begin a.CopyFromArray(2,2,TSingleArray.Create(1,1.5,2,0.3)); a.Tanh; end; *) function Tanh: TOpenCLMtxVec; overload; (*Calculate the hyperbolic tangens for calling object elements [Index]..[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function Tanh(Index, Len: integer): TOpenCLMtxVec; overload; (*Calculate the hyperbolic tangens for all X object elements. Store the results in the calling object. Size and properties of calling object are adjusted automatically. *) function Tanh(const X: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Calculate the hyperbolic tangens for X object elements [XIndex]..[XIndex+Len-1]. The results are stored in the calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if array borders are overrun. *) function Tanh(const X: TOpenCLMtxVec; XIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Hyperbolic cotangens. Calculate the hyperbolic cotangens of all caling object elements in-place. var a: clMatrix; begin a.CopyFromArray(2,2,TSingleArray.Create(1,1.5,2,0.3)); a.Coth; end; *) function Coth: TOpenCLMtxVec; overload; (*Calculate the hyperbolic cotangens for calling object elements [Index]...[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function Coth(Index, Len: integer): TOpenCLMtxVec; overload; (*Calculate the hyperbolic cotangens for all X object elements. Store the results in the calling object. Size and properties of calling object are adjusted automatically. *) function Coth(const X: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Calculate the hyperbolic cotangens for X object elements [XIndex]..[XIndex+Len-1]. The results are stored in calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if array borders are overrun. *) function Coth(const X: TOpenCLMtxVec; XIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Hyperbolic secant. Calculate the hyperbolic secant of all caling object elements in-place. *) function Sech: TOpenCLMtxVec; overload; (*Calculate the hyperbolic secant for calling object elements [Index]...[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function Sech(Index, Len: integer): TOpenCLMtxVec; overload; (*Calculate the hyperbolic secant for all X object elements. Store the results in the calling object. Size and properties of calling object are adjusted automatically. *) function Sech(const X: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Calculate the hyperbolic secant for X object elements [XIndex]..[XIndex+Len-1]. The results are stored in calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if array borders are overrun. *) function Sech(const X: TOpenCLMtxVec; XIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Hyperbolic cosecant. Calculate the hyperbolic cosecant of all caling object elements in-place. *) function Csch: TOpenCLMtxVec; overload; (*Calculate the hyperbolic cosecant for calling object elements [Index]..[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function Csch(Index, Len: integer): TOpenCLMtxVec; overload; (*Calculate the hyperbolic cosecant for all X object elements. Store the results in the calling object. Size and properties of calling object are adjusted automatically. *) function Csch(const X: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Calculate the hyperbolic cosecant for X object elements [XIndex]..[XIndex+Len-1]. The results are stored in calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if array borders are overrun. *) function Csch(const X: TOpenCLMtxVec; XIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Absolute values. Calculate the absolute value of all calling object elemets in-place. var a: clMatrix; begin a.CopyFromArray(2,2,TSingleArray.Create(1,-2,3,4)); a.Abs; end; *) function Abs: TOpenCLMtxVec; overload; (*Calculate the absolute value for calling object elements [Index]..[Index+Len-1]. An exception is raised if array borders are overrun or underrun. *) function Abs(Index, Len: integer): TOpenCLMtxVec; overload; (*Calculate the absolute value for all X object and store the results in the calling object. Size and properties of calling object are adjusted automatically. *) function Abs(const X: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Calculate the absolute value of X object elements [XIndex]..[XIndex+Len-1]. Store the results in calling object elements [Index]..[Index+Len-1]. An exception is raised if array borders are overrun or underrun. *) function Abs(const X: TOpenCLMtxVec; XIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Inverse hyperbolic sine. Calculate the inverse hyperbolic sine for all caling object elements in-place. *) function ArcSinh: TOpenCLMtxVec; overload; (*Calculate the inverse hyperbolic sine for calling object elements [Index]..[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function ArcSinh(Index, Len: integer): TOpenCLMtxVec; overload; (*Calculate the inverse hyperbolic sine for all X object elements. Store the results in the calling object. Size and properties of calling object are adjusted automatically. *) function ArcSinh(const X: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Calculate the inverse hyperbolic sine for X object elements [XIndex]..[XIndex+Len-1]. The results are stored in calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if array borders are overrun. *) function ArcSinh(const X: TOpenCLMtxVec; XIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Inverse hyperbolic cosine. Calculate the inverse hyperbolic cosine for all caling object elements in-place. *) function ArcCosh: TOpenCLMtxVec; overload; (*Calculate the inverse hyperbolic cosine for calling object elements [Index]..[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function ArcCosh(Index, Len: integer): TOpenCLMtxVec; overload; (*Calculate the inverse hyperbolic cosine for all X object elements. Store the results in the calling object. Size and properties of calling object are adjusted automatically. *) function ArcCosh(const X: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Calculate the inverse hyperbolic cosine for X object elements [XIndex]..[XIndex+Len-1]. The results are stored in calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if array borders are overrun. *) function ArcCosh(const X: TOpenCLMtxVec; XIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Inverse hyperbolic tangens. Calculate the inverse hyperbolic tangens for all caling object elements in-place. *) function ArcTanh: TOpenCLMtxVec; overload; (*Calculate the inverse hyperbolic tangens for calling object elements [Index]..[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function ArcTanh(Index, Len: integer): TOpenCLMtxVec; overload; (*Calculate the inverse hyperbolic tangens for all X object elements. Store the results in the calling object. Size and properties of calling object are adjusted automatically. *) function ArcTanh(const X: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Calculate the inverse hyperbolic tangens for X object elements [XIndex]..[XIndex+Len-1]. The results are storedi n the calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if array borders are overrun. *) function ArcTanh(const X: TOpenCLMtxVec; XIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Inverse hyperbolic cotangens. Calculate the inverse hyperbolic cotangens for all caling object elements in-place. *) function ArcCoth: TOpenCLMtxVec; overload; (*Calculate the inverse hyperbolic cotangens for calling object elements [Index]..[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function ArcCoth(Index, Len: integer): TOpenCLMtxVec; overload; (*Calculate the inverser hyperbolic cotangens for all X object elements. Store the results in calling object. Size and properties of calling object are adjusted automatically. *) function ArcCoth(const X: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Calculate the inverse hyperbolic cotangens for X object elements [XIndex]..[XIndex+Len-1]. The results are stored in the calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if array borders are overrun. *) function ArcCoth(const X: TOpenCLMtxVec; XIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Inverse hyperbolic secant. Calculate the inverse hyperbolic secant for all caling object elements in-place. *) function ArcSech: TOpenCLMtxVec; overload; (*Calculate the inverse hyperbolic secant for calling object elements [Index]..[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function ArcSech(Index, Len: integer): TOpenCLMtxVec; overload; (*Calculate the inverse hyperbolic secant for all X object elements. Store the results in calling object. Size and properties of calling object are adjusted automatically. *) function ArcSech(const X: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Calculate the inverse hyperbolic secant for X object elements [XIndex]..[XIndex+Len-1]. The results are stored in calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if array borders are overrun. *) function ArcSech(const X: TOpenCLMtxVec; XIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Inverse hyperbolic cosecant. Calculate the inverse hyperbolic cosecant for all caling object elements in-place. *) function ArcCsch: TOpenCLMtxVec; overload; (*Calculate the inverse hyperbolic cosecant for calling object elements [Index]...[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function ArcCsch(Index, Len: integer): TOpenCLMtxVec; overload; (*Calculate the inverse hyperbolic cosecant for all X object elements. Store the results in calling object. Size and properties of calling object are adjusted automatically. *) function ArcCsch(const X: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Calculate the inverse hyperbolic cosecant for X object elements [XIndex]..[XIndex+Len-1]. The results are stored in calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if array borders are overrun. *) function ArcCsch(const X: TOpenCLMtxVec; XIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*The cube root. Calculate the cube root of all calling object elements in-place. v.CopyFromArray(1,2,TSingleArray.Create(1,8)); v.Cbrt; // v = [1,2] *) function Cbrt: TOpenCLMtxVec; overload; (*Calculate the cube root of calling object elements [Index]..[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function Cbrt(Index, Len: integer): TOpenCLMtxVec; overload; (*Calculate the cube root of all X object elements. Store the results in calling object. Size and properties of calling object are adjusted automatically. *) function Cbrt(const X: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Calculate the cube root of X object elements [XIndex]..[XIndex+Len-1]. The results are stored in the calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if array borders are overrun. *) function Cbrt(const X: TOpenCLMtxVec; XIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Rounds towards positive infinity. Rounds all calling object elements towards positive infinity in-place. Ceil(-2.8) = -2 Ceil(2.8) = 3 Ceil(-1.0) = -1 *) function Ceil: TOpenCLMtxVec; overload; (*Rounds calling object elements [Index]..[Index+Len-1] towards positive infinity in-place. An exception is raised if array borders are overrun. *) function Ceil(Index,Len: integer): TOpenCLMtxVec; overload; (*Rounds all Src object elements towards positive infinity. Stores the result in the calling object. Size and properties of the calling object are adjusted automatically. *) function Ceil(const Src: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Rounds Src object elements [SrcIndex]..[SrcIndex+Len-1] towards positive infinity. Stores the result in the calling object elements [Index]..[Index+Len-1] Size and properties of the calling object must be set explicitly. An exception is raised if array borders are overrun. *) function Ceil(const Src: TOpenCLMtxVec; SrcIndex, Index,Len: integer): TOpenCLMtxVec; overload; (*Natural logarithm. Calculate the natural log for all calling object elements in-place. var a: clMatrix; begin a.CopyFromArray(2,2,TSingleArray.Create(1,2,3,4)); a.Ln; end; *) function Ln: TOpenCLMtxVec; overload; (*Calculate the natural algorithm for all X elements. Store the results in the calling object. Size and properties of the calling vector are set implicitly to match the X object. *) function Ln(const X: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Calculate the natural logarithm for calling object elements [Index]..[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function Ln(Index, Len: integer): TOpenCLMtxVec; overload; (*Calculate the natural logarithm for X elements [XIndex]..[XIndex+Len-1]. Store the results in the calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if array borders are overrun. *) function Ln(const X: TOpenCLMtxVec; XIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Log base 10. Calculate the log base 10 for all calling object elements in-place. var a: clMatrix; begin a.CopyFromArray(2,2,TSingleArray.Create(10,100,1000,10000)); // a = [10,100,1000,10000] a.Log10; // a = [1,2,3,4] end; *) function Log10: TOpenCLMtxVec; overload; (*Calculate the log base 10 for all X elements. Store the results in the calling object. Size and properties of the calling vector are set implicitly to match the X object. *) function Log10(const X: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Calculate the log base 10 for calling object elements [Index]..[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function Log10(Index, Len: integer): TOpenCLMtxVec; overload; (*Calculate the log base 10 for X elements [XIndex]..[XIndex+Len-1]. Store the results in the calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if array borders are overrun. *) function Log10(const X: TOpenCLMtxVec; XIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Log base 2. Calculate the log base 2 for all calling object elements in-place. var a: clMatrix; begin a.CopyFromArray(2,2,TSingleArray.Create(1,2,4,8)); a.Log2; end; *) function Log2: TOpenCLMtxVec; overload; (*Calculate the log base 2 for all X elements. Store the results in the calling object. Size and properties of the calling vector are set implicitly to match the X object. *) function Log2(const X: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Calculate the log base 2 for calling object elements [Index]..[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function Log2(Index, Len: integer): TOpenCLMtxVec; overload; (*Calculate the log base 2 for X elements [XIndex]..[XIndex+Len-1]. Store the results in the calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if array borders are overrun. *) function Log2(const X: TOpenCLMtxVec; XIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Exponent (e^). Calculate the exponent (e^) for all calling object elements in-place. var a: clMatrix; begin a.CopyFromArray(2,2,TSingleArray.Create(1,2,3,4)); a.Exp; end; *) function Exp: TOpenCLMtxVec; overload; (*Calculate the exponent (e^) for all X elements. Store the results in the calling object. Size and properties of the calling vector are set implicitly to match the X object. *) function Exp(const X: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Calculate the exponent (e^) for calling object elements [Index]..[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function Exp(Index, Len: integer): TOpenCLMtxVec; overload; (*Calculate the exponent (e^) for X elements [XIndex]..[XIndex+Len-1]. Store the results in the calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if array borders are overrun. *) function Exp(const X: TOpenCLMtxVec; XIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Exponent base 2 (2^). Calculate the exponent base 2 (2^) for all calling object elements in-place. var a: clMatrix; begin a.CopyFromArray(2,2,TSingleArray.Create(1,2,3,4)); // a = [1,2,3,4] a.Exp2; // a = [1,4,9,16] end; *) function Exp2: TOpenCLMtxVec; overload; (*Calculate the exponent base 2 (2^) for all X elements. Store the results in the calling object. Size and properties of the calling vector are set implicitly to match the X object. *) function Exp2(const X: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Calculate the exponent base 2 (2^) for calling object elements [Index]..[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function Exp2(Index, Len: integer): TOpenCLMtxVec; overload; (*Calculate the exponent base 2 (2^) for X elements [XIndex]..[XIndex+Len-1]. Store the results in the calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if array borders are overrun. *) function Exp2(const X: TOpenCLMtxVec; XIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Exponent base 10 (10^). Calculate the exponent base 10 (10^) for all calling object elements in-place. var a: clMatrix; begin a.CopyFromArray(2,2,TSingleArray.Create(1,2,3,4)); // a = [1,2,3,4] a.Exp10; // a = [10,100,1000,10000] end; *) function Exp10: TOpenCLMtxVec; overload; (*Calculate the exponent base 10 (10^) for all X elements. Store the results in the calling object. Size and properties of the calling vector are set implicitly to match the X object. *) function Exp10(const X: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Calculate the exponent base 10 (10^) for calling object elements [Index]..[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function Exp10(Index, Len: integer): TOpenCLMtxVec; overload; (*Calculate the exponent base 10 (10^) for X elements [XIndex]..[XIndex+Len-1]. Store the results in the calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if array borders are overrun. *) function Exp10(const X: TOpenCLMtxVec; XIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Gets the imaginary part of a complex object. Gets the imaginary part of a complex object Vec and stores the real results in the calling object. Size and properties of the calling object are set implicitly to match Vec object. Vec must be true otherwise the exception will be raised. var a,b: clMatrix; begin a.CopyFromArray(2,2,TSingleArray.Create(1,2,3,4)); // a= [1+2i, 3+4i] b.ImagPart(a); // b = [2, 4] end; *) function ImagPart(const Vec: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Gets the imaginary part of complex object Vec elements [VecIndex]..[VecIndex+Len-1]. Stores the result in calling object. An exception is raised if the calling object is complex, if Vec is not complex or if array borders are overrun/underrun. *) function ImagPart(const Vec: TOpenCLMtxVec; VecIndex,Index,Len: integer): TOpenCLMtxVec; overload; (*Power (integer exponent). Calculate the power ^(Exponent) for all caling object elements using the integer parameter Exponent. For non integer exponents, the and methods can be used. var a: clMatrix; begin a.CopyFromArray(2,2,TSingleArray.Create(1,2,3,4)); a.IntPower(3); end; *) function IntPower(Exponent: Integer): TOpenCLMtxVec; overload; (*Calculate the power Base^(Exponent) for all Base object elements. Calclation uses the integer Exponent value and stores the results in calling object. Size and properties of calling object are adjusted automatically. *) function IntPower(const Base: TOpenCLMtxVec; Exponent: Integer): TOpenCLMtxVec; overload; (*Calculate the inverse of calling object elements [Index]..[Index+Len-1] in-place. An exception is raised if array borders are overrun/underrun. *) function Inv(Index, Len: integer): TOpenCLMtxVec; overload; (*Calculate the inverse of X object elements [XIndex]..[XIndex+Len-1] without limiting operating. Store the results in calling object elements [Index]..[Index+Len-1]. An exception is raised if X and calling object property does not match or array borders are overrun/underrun. *) function Inv(const X: TOpenCLMtxVec; XIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Converts elements from cartesian to polar coordinate form. Converts all calling object elements from cartesian to polar coordinate form, storing the magnitude (radius) component of corresponding elements in the AmpltVec and the phase (angle) component of corresponding elements in the PhaseVec. If you want to use this method then the calling matrix property must be true. If this is not the case, an exception is raised. Size and properties of AmpltVec and PhaseVec are set automatically. var A,Amplt,Phase: clMatrix; begin A.CopyCplxFromArray(2,2,TSingleArray.Create(1,0, 2,0 2,0 4,1)); // 2x2, complex matrix A.CartToPolar(Amplt, Phase); end; *) procedure CartToPolar(AmpltVec, PhaseVec: TOpenCLMtxVec); overload; (*Convert calling object elements [Index] to [Index+Len-1] from cartesian to polar form. Store the results in AmpltVec (radius values) and PhaseVec(phase values). Size and properties of the calling vector must be set explicitly. An exception is raised if array borders are overrun or underrun. *) procedure CartToPolar(AmpltVec, PhaseVec: TOpenCLMtxVec; AmpltIndex, PhaseIndex, Index, Len: integer); overload; (*Add each of Vec elements to corresponding elements in the calling object. In addition, the following formula is being used: result = result+ aScale*Vec The results are stored in the calling object. Size and properties of the calling object are set implicitly to match the Vec object. *) function AddScaled(const Vec: TOpenCLMtxVec; aScale: double): TOpenCLMtxVec; overload; (*Add each of Vec elements to corresponding elements in the calling object. In addition, the following formula is being used: result = result+ aScale*Vec The results are stored in the calling object. Size and properties of the calling object are set implicitly to match the Vec object. *) function AddScaled(const Vec: TOpenCLMtxVec; aScale: TCplx): TOpenCLMtxVec; overload; (*Adds Vec elements [VecIndex]..[VecIndex+Len-1] to calling object elements [Index]..[Index+Len-1]. In addition, the following formula is being used: result = result+ Cplx(aScale)*Vec An exception is raised if array borders are overrun. *) function AddScaled(const Vec: TOpenCLMtxVec; aScale: double; VecIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Adds Vec elements [VecIndex]..[VecIndex+Len-1] to calling object elements [Index]..[Index+Len-1]. In addition, the following formula is being used: result = result+ aScale*Vec An exception is raised if array borders are overrun. *) function AddScaled(const Vec: TOpenCLMtxVec; aScale: TCplx; VecIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Add a product of two vectors. Multiply Vec1 elements with coresponding Vec2 elements and add the result to the calling vector. The size of the calling vector is set implicitly. *) function AddProduct(const Vec1, Vec2: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Multiply Vec1 elements [Vec1Index]..[Vec1Index+Len-1] with Vec2 elements [Vec2Index]..[Vec2Index+Len-1] and add the results to the calling object elements [Index]..[Index+Len-1]. An exception is raised if array borders are overrun. *) function AddProduct(const Vec1, Vec2: TOpenCLMtxVec; Vec1Index, Vec2Index, Index, Len: integer): TOpenCLMtxVec; overload; (*Conjugate and multiply. Conjugate each of Vec elements and multiply them with corresponding elements in the calling object. The results are stored in the calling object. Size and properties of the calling object are set implicitly to match Vec. var a,b,c: clMatrix; begin a.CopyCplxFromArray(2,2, TSingleArray.Create(1,2,3,4)); b.CopyCplxFromArray(2,2, TSingleArray.Create(4,3,2,1)); c.ConjMul(a,b); end; *) function ConjMul(const Vec: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Conjugate Vec elements Vec[VecIndex]..Vec[VecIndex+Len-1] and multiply them with corresponding calling object elements [Index]..[Index+Len-1]. The results are stored in the calling object elements [Index]..[Index+Len-1]. Size and properties are not set. An exception is raised if array borders are overrun or underrun. *) function ConjMul(const Vec: TOpenCLMtxVec; VecIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Conjugate each of Vec2 elements and multiply them with corresponding elements in Vec1. The results are stored in the calling object. Size and properties of the calling object are set implicitly to match Vec1 and Vec2 objects. *) function ConjMul(const Vec1, Vec2: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Conjugate Vec2 elements [Vec2Index]..[Vec2Index+Len-1] and multiply them with corresponding Vec1 elements [Vec1Index]..[Vec1Index+Len-1]. The results are stored in the calling object elements [Index]..[Index+Len-1]. Size and properties of the calling vector must be set explicitly. An exception is raised if array borders are overrun. *) function ConjMul(const Vec1, Vec2: TOpenCLMtxVec; Vec1Index, Vec2Index, Index, Len: integer): TOpenCLMtxVec; overload; (*Divide each of Num elements with corresponding elements in Den. Size and property of the calling object are set automatically. The result is stored in the calling object. The result of division by zero will be the INF constant. Division of zero by zero will result in NAN. *) function Divide(Num, Den: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Divide each of calling vector elements with corresponding elements in the Vec object. Size and property of the calling object are set automatically. The result is stored in the calling object. The result of division by zero will be the INF constant. Division of zero by zero will result in NAN. *) function Divide(const Vec: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Divide calling vector elements [Index]...[Index+Len-1] with corresponding elements [VecIndex]...[VecIndex+Len-1] from the Vec object. Store the result in the claling vector. The Length of the calling vector is not changed. An exception is raised if array borders are overrun or underrun. The result of division by zero will be the INF constant. Division of zero by zero will result in NAN. *) function Divide(const Vec: TOpenCLMtxVec; VecIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Divide [NumIndex]..[NumIndex+Len-1] Num elements with [DenIndex]..[DenIndex+Len-1] elements in Den. and store result in the calling vector at positions [Index]..[Index+Len-1] and property of the calling object are not changed. An exception is raised if array borders are overrun or underrun. The result of division by zero will be the INF constant. Division of zero by zero will result in NAN. *) function Divide(Num, Den: TOpenCLMtxVec; NumIndex, DenIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Divide Value with elements of the calling object and store the result in the calling object.*) function DivideBy(Value: double): TOpenCLMtxVec; overload; (*Divide complex Value with elements of the calling object. Store the result in the calling object. *) function DivideBy(Value: TCplx): TOpenCLMtxVec; overload; (*Divide Value with elements [Index]...[Index+Len-1] from the calling object. Store the result in the calling object at position [Index]...[Index+Len-1]. An exception will be raised if array borders are overrun or underrun. *) function DivideBy(Value: double; Index, Len: integer): TOpenCLMtxVec; overload; (*Divide complex Value with elements [Index]...[Index+Len-1] from the calling object. Store the result in the calling object at position [Index]...[Index+Len-1]. Calling vector will be extended to complex, if the calling vector is real. An exception will be raised if array borders are overrun or underrun. *) function DivideBy(Value: TCplx; Index, Len: integer): TOpenCLMtxVec; overload; (*Divide Value with elements from Vec and store the result in the corresponding elements of the calling object. Size and properties of the calling object are set automatically. *) function DivideBy(Value: double; Vec: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Divide complex Value with elements from Vec and store the result in the corresponding elements of the calling object. Size of the calling object is set automatically. property of the calling object is set to True. *) function DivideBy(Value: TCplx; Vec: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Divide Value with Vec elements [VecIndex]..[VecIndes+Len-1]. Store the result in the elements [Index]..[Index+Len-1] of the calling object. Size of the calling object is not changed. An exception will be raised array borders are overrun or underrun. property of the calling object is set implicitly. *) function DivideBy(Value: double; Vec: TOpenCLMtxVec; VecIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Divide complex Value with elements [VecIndex]..[VecIndes+Len-1] from Vec. Store the result in the elements [Index]..[Index+Len-1] of the calling object. Size of the calling object is not changed. An exception will be raised array borders are overrun or underrun. property of the calling object is set to True. *) function DivideBy(Value: TCplx; Vec: TOpenCLMtxVec; VecIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Reverse vector elements. The method reverses Vec vector elements from [VecIndex].. [VecIndex+Len-1] and stores them in the calling vector from [Index]...[Index+Len-1] by using the following equation: This overload reverses calling vector elements in-place. var a: clMatrix; begin a.CopyFromArray(2,2, TSingleArray.Create(1,2,3,4)); a.Reverse; // a = [4,3,2,1] end; *) function Reverse(const Vec: TOpenCLMtxVec; VecIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Reverses the calling object elements [Index]..[Index+Len-1]. An exception is raised if array borders are overrun. *) function Reverse(Index, Len: integer): TOpenCLMtxVec; overload; (*A cyclic shift on vector elements in range. Performs cyclic shift on source vector elements in specified range [Index..Index+Len] and stores them to calling vector. The number of elements to shift is specified in the Offset parameter. Offset can be any integer number, positive or negative. *) function Rotate(const Vec: TOpenCLMtxVec; Offset: integer; VecIndex,Index: integer; Len: integer = MtxVecEOA): TOpenCLMtxVec; overload; (*A shift on vector elements in range. Performs shift on source vector elements in specified range [Index..Index+Len] and stores them to calling vector. The number of elements to shift is specified in the Offset parameter. Offset can be any integer number, positive or negative. *) function Shift(const Vec: TOpenCLMtxVec; Offset: integer; VecIndex,Index: integer; Len: integer = MtxVecEOA): TOpenCLMtxVec; overload; (*Subtracts Value from object elements. Subtracts Value from all calling object elements. *) function Sub(Value: double): TOpenCLMtxVec; overload; (*Subtracts complex Value from all calling object complex elements.*) function Sub(Value: TCplx): TOpenCLMtxVec; overload; (*Subtracts Value from calling object elements [Index]..[Index+Len-1]. An exception is raised if array borders are overrun. *) function Sub(Value: double; Index, Len: integer): TOpenCLMtxVec; overload; (*Subtracts complex Value from calling object complex elements [Index]..[Index+Len-1]. An exception is raised if array borders are overrun. *) function Sub(Value: TCplx; Index, Len: integer): TOpenCLMtxVec; overload; (*Subtract real Value from Src. Store the results in calling object. Size and property of calling object are adjusted automatically. *) function Sub(const Src: TOpenCLMtxVec; Value: double): TOpenCLMtxVec; overload; (*Subtract complex Value from Src. Store the results in calling object. Size and property of calling object are adjusted automatically. *) function Sub(const Src: TOpenCLMtxVec; Value: TCplx): TOpenCLMtxVec; overload; (*Subtract real Value from Src elements [SrcIndex]..[SrcIndex+Len-1]. Stores the result in calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if array borders are overrun or underrun. *) function Sub(const Src: TOpenCLMtxVec; Value: double; SrcIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Subtract complex Value from Src elements [SrcIndex]..[SrcIndex+Len-1]. Stores the result in calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if array borders are overrun or underrun. *) function Sub(const Src: TOpenCLMtxVec; Value: TCplx; SrcIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Array subtraction. Subtract each of Vec elements from corresponding elements in the calling object. An exception is raised if Vec and calling object size and properties do not match. *) function Sub(const Vec: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Subtract Vec2 elements from Vec1 elements. Stores the results in calling object. Size and property of calling object are adjusted automatically. An exception is raised if Vec1 and Vec2 size and property do not match. *) function Sub(const Vec1, Vec2: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Subtract Vec elements [VecIndex]..[VecIndex+Len-1] from corresponding calling object elements [Index]..[Index+Len-1]. The results are stored in the calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if array borders are overrun or underrun. *) function Sub(const Vec: TOpenCLMtxVec; VecIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Subtract Vec22 elements [Vec2Index]..[Vec2Index+Len-1] from Vec1 object elements [Vec1Index]..[Vec1Index+Len-1]. Stores the results in calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if array borders are overrun or underrun. *) function Sub(const Vec1, Vec2: TOpenCLMtxVec; Vec1Index, Vec2Index, Index, Len: integer): TOpenCLMtxVec; overload; (*Subtraction from value. Subtract each of calling object elements from Value. *) function SubFrom(Value: double): TOpenCLMtxVec; overload; (*Subtract each of calling object elements from complex Value. If the calling vector s not complex, the conversion is performed automatically in a performance efficient way. *) function SubFrom(Value: TCplx): TOpenCLMtxVec; overload; (*Subtract elements [Index]..[Index+Len-1] from Value. Store the result in calling vector. An exception is raised if array borders are overrun or underrun. *) function SubFrom(Value: double; Index,Len: integer): TOpenCLMtxVec; overload; (*Subtract elements [Index]..[Index+Len-1] from complex Value. Store the result in calling object. If the calling vector is not complex, the conversion to complex is performed automatically in performance efficient way. An exception is raised if array borders are overrun or underrun. *) function SubFrom(Value: TCplx; Index,Len: integer): TOpenCLMtxVec; overload; (*Substract Vec elements from Value. Stores the result in the calling object. Size and properties of calling object are adjusted automatically. *) function SubFrom(Value: double; Vec: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Substract complex Vec elements from Value. Stores the result in the calling object. Size property of the calling object is set automatically. property of the calling object is set to True. *) function SubFrom(Value: TCplx; Vec: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Substract Vec elements [VecIndex]..[VecIndex+Len-1] from Value. Stores the result to the calling object elements [Index]..[Index+Len-1]. Size property of the calling object is not changed. An exception is raised if array borders are overrun or underrun. property of the calling object is adjusted automatically. *) function SubFrom(Value: double; Vec: TOpenCLMtxVec; VecIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Substract Vec elements [VecIndex]..[VecIndex+Len-1] from complex Value and store the result to the calling object elements [Index]..[Index+Len-1]. Size property of the calling object is not changed. An exception is raised if array borders are overrun or underrun. property of the calling object is set to True. *) function SubFrom(Value: TCplx; Vec: TOpenCLMtxVec; VecIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Mean value. Calculate the mean value of all calling object elements. The result is a real value. An exception is raised if calling object property is true. var a: clMatrix; b: double; begin a.Size(2,2, clFloat, false); a.CopyFromArray(TDoubleArray.Create(1,2,3,4)); b := a.Mean; // b = 2.5 end; *) function Mean: double; overload; (*Returns real mean value from calling object elements [Index]..[Index+Len-1]. An exception is raised if calling object property is true or array borders are overrun. *) function Mean(Index, Len: integer): double; overload; (*Calculate the mean value from calling object elements [Index]..[Index+Len-1]. The result AMean is a real value. An exception is raised if calling object property is true or array borders are overrun/underrun. *) procedure Mean(out AMean: double; Index, Len: integer); overload; (*Same as .*) procedure Mean(out AMean: TCplx); overload; (*Same as .*) procedure Mean(out AMean: TCplx; Index, Len: integer); overload; (*Mean value. the mean value of all calling object complex elements. The result is a complex value. An exception is raised is calling object is . *) function Meanc: TCplx; overload; (*Returns complex mean value from calling object complex elements [Index]..[Index+Len-1]. An exception is raised if calling object property is or array borders are overrun/underrun. *) function Meanc(Index, Len: integer): TCplx; overload; (*Calculate the mean value from all calling object complex elements. The result AMean is a complex value. An exception is raised if calling object property is . *) procedure Meanc(out AMean: TCplx); overload; (*Calculate the mean value from calling object complex elements [Index]..[Index+Len-1]. The result AMean is a complex value. An exception is raised if calling object property is or array borders are overrun/underrun. *) procedure Meanc(out AMean: TCplx; Index, Len: integer); overload; (*Sums vector values. the sum of all calling object elements. An exception is raised if calling object property is true. var a: clMatrix; b: double; begin a.Size(2,2, clFloat, false); a.CopyFromArray(TDoubleArray.Create(1,2,3,4)); b := a.Sum; // b = 10 end; *) function Sum: double; overload; (*Returns the sum of calling object elements [Index]..[Index+Len-1]. An exception is raised if calling object property is True or array borders are overrun/underrun. *) function Sum(Index,Len: integer): double; overload; (*Calculates the sum of calling object elements [Index]..[Index+Len-1]. Stores the result in real ASum variable. An exception is raised if calling object property is True or array borders are overrun/underrun. *) procedure Sum(out ASum: double; Index, Len: integer); overload; (*Calculates the sum of all calling object complex elements. Stores the result in complex ASum variable. An exception is raised if calling object property is False. *) procedure Sum(out ASum: TCplx); overload; (*Calculates the sum of calling object complex elements [Index]..[Index+Len-1]. Stores the result in complex ASum variable. An exception is raised if calling object property is False or array borders are overrun/underrun. *) procedure Sum(out ASum: TCplx; Index, Len: integer); overload; (*Sum (complex value). the complex sum of all calling object complex elements. An exception is raised if calling object property is False. *) function Sumc: TCplx; overload; (*Returns the complex sum of calling object complex elements [Index]..[Index+Len-1]. An exception is raised if calling object property is False or array borders are overrun/underrun. *) function Sumc(Index,Len: integer): TCplx; overload; (*Maximum value. the maximum value of all calling object elements. The result is a real value. An exception is raised is calling object is true. var a: clMatrix; b: double; begin a.Size(2,2, TclFloatPrecision.clFloat, false); a.CopyFromArray(TDoubleArray.Create(1,2,3,4)); b := a.Max; // b = 4 end; *) function Max: double; overload; (*Returns the maximum value from calling object elements [Index]..[Index+Len-1]. The result is a real value. An exception is raised if calling object property is true or array borders are overrun. *) function Max(Index,Len: integer): double; overload; (*Calculate the maximum value from calling object elements [Index]..[Index+Len-1]. The result AMean is a real value. An exception is raised if calling object property is true or array borders are overrun. *) procedure Max(out AMax: double; Index,Len: integer); overload; (*Calculate the maximum value of all calling object elements. The AMax parameter returns the maximum value. The AIndex parameter returns the index of maximum value. An exception is raised if calling object property is true. *) procedure Max(out AMax: double; out AIndex: integer); overload; (*Calculate the maximum value of calling object elements [Index]..[Index+Len-1]. The AMax parameter returns the maximum value. The AIndex parameter returns the index of maximum value. An exception is raised if calling object property is true or array borders are overrud/underrun. *) procedure Max(out AMax: double; out AIndex: integer; Index, Len: integer); overload; (*Same as method.*) function Max(out AMax: TCplx; Index, Len: integer): integer; overload; (*Maximum value. the maximum value of all calling object complex elements. Complex elements are first compared by the amplitude and then by the argument. An exception is raised if calling object is . *) function Maxc: TCplx; overload; (*Returns the maximum value of calling object complex elements [Index]..[Index+Len-1]. The result is a complex value. Complex elements are first compared by the amplitude and then by the argument. An exception is raised if calling object property is or array borders are overrud/underrun. *) function Maxc(Index,Len: integer): TCplx; overload; (*Calculate the maximum value of calling object complex elements [Index]..[Index+Len-1]. The AMax parameter returns complex maximum value. Returns the index of maximum value. Complex elements are first compared by the amplitude and then by the argument. The AIndex parameter returns the index of maximum value. An exception is raised if calling object property is or array borders are overrud/underrun. *) function Maxc(out AMax: TCplx; Index, Len: integer): integer; overload; (*Maximum and minimum value in a single pass. Calculates the maximum and minimum value of all calling object elements in a single pass. Maximum value is stored in AMax parameter, minimum value is stored in AMin parameter. Use this method if you require minimum AND maximum value. *) procedure MaxMin(out AMax,AMin: double); overload; (*Calculates the maximum and minimum value of calling object elements [Index]..[Index+Len-1]. Maximum value is stored in AMax parameter, minimum value is stored in AMin parameter. An exception is raised if calling object property is true or array borders are overrud/underrun. *) procedure MaxMin(out AMax,AMin: double; Index, Len: integer); overload; (*Calculates the maximum and minimum value of all calling object elements. Maximum value is returned in AMax parameter, minimum value in AMin parameter. The MaxIdx parameter returns the index of maximum value. The MinIdx parameter returns the index of minimum value. An exception is raised if calling object property is true. *) procedure MaxMin(out AMax: double; out MaxIdx: integer; out AMin: double; out MinIdx: integer); overload; (*Calculates the maximum and minimum value of calling object elements [Index]..[Index+Len-1]. Maximum value is returned in AMax parameter, minimum value in AMin parameter. The MaxIdx parameter returns the index of maximum value. The MinIdx parameter returns the index of minimum value. An exception is raised if calling object property is true or if array borders are overrun/underrun. *) procedure MaxMin(out AMax: double; out MaxIdx: integer; out AMin: double; out MinIdx: integer; Index, Len: integer); overload; (*Minimum value. The minimum value of all calling object elements. The result is a real value. An exception is raised if calling object property is true. var a: clMatrix; b: double; begin a.Size(2,2, clFloat, false); a.CopyFromArray(TDoubleArray.Create(1,2,3,4)); b := a.Min; // b = 1 end; *) function Min: double; overload; (*Calculate the minimum value from calling object elements [Index]..[Index+Len-1]. The result is a real value. An exception is raised if calling object property is true or array borders are overrun. *) function Min(Index,Len: integer): double; overload; (*Calculate the minimum value from calling object elements [Index]..[Index+Len-1]. The result AMin is a real value. An exception is raised if calling object property is true or array borders are overrun. *) procedure Min(out AMin: double; Index,Len: integer); overload; (*Calculate the minimum value of calling object elements [Index]..[Index+Len-1]. The AMax parameter returns the minimum value. The AIndex parameter returns the index of minimum value. An exception is raised if calling object property is true or array borders are overrud/underrun. *) procedure Min(out AMin: double; out AIndex: Integer; Index, Len: integer); overload; (*Calculate the minimum value of all calling object elements. The AMin parameter returns the minimum value. The AIndex parameter returns the index of minimum value. An exception is raised if calling object property is true. *) procedure Min(out AMin: double; out AIndex: integer); overload; (*Same as the method.*) function Min(out AMin: TCplx; Index, Len: integer): integer; overload; (*Minimum value. Returns the minimum value of all calling object complex elements. Complex elements are first compared by the amplitude and then by the argument. An exception is raised if calling object is . *) function Minc: TCplx; overload; (*Returns the minimum value of calling object complex elements [Index]..[Index+Len-1]. The result is a complex value. Complex elements are first compared by the amplitude and then by the argument. An exception is raised if calling object. property is or array borders are overrud/underrun. *) function Minc(Index,Len: integer): TCplx; overload; (*Calculate the minimum value of calling object complex elements [Index]..[Index+Len-1]. The AMin parameter returns complex minimum value. Returns the index of minimum value. Complex elements are first compared by the amplitude and then by the argument. An exception is raised if calling object property is or array borders are overrun/underrun. *) function Minc(out AMin: TCplx; Index, Len: integer): integer; overload; (*The C-norm. C norm: ||V-Vec||, where V is the calling vector. If the NormC is called without any parameters, the NormC calculates the norm of the calling vector. The C norm of ||V-Vec|| is defined by the formula: If RelativeError is true then the computed norm is divided by the norm of V, and the function returns the "relative error": using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { 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 c = a.NormC(b,true); } finally { clMtxVec.FreeIt(out a, out b); } } } *) function NormC(const Vec: TOpenCLMtxVec; RelativeError: boolean = false): double; overload; (*Calculates the C norm ||V-Vec|| between Vec elements [VecIndex]..[VecIndex+Len-1] and calling vector elements [Index]..[Index+Len-1].*) function NormC(const Vec: TOpenCLMtxVec; VecIndex,Index,Len: integer; RelativeError: boolean = false): double; overload; (*Calculate the C-norm of calling vector. NormC = max|a[i]|, 0 < i < Length-1 .*) function NormC: double; overload; (*Calculates the C norm from calling vector elements [Index]..[Index+Len-1].*) function NormC(Index,Len: integer): double; overload; (*The L1-norm. L-1 norm, defined by: ||V-Vec||, where V is calling vector. If the NormL1 is called without any parameters, the NormL1 calculates the norm of calling vector. The L1 norm of ||V-Vec|| is defined by the formula: If RelativeError is true then the computed norm is divided by the norm of V, and the function returns the "relative error": using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { 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 c = a.NormL1(b,true); } finally { clMtxVec.FreeIt(ref a,ref b); } } } *) function NormL1(const Vec: TOpenCLMtxVec; RelativeError: boolean = false): double; overload; (*Calculates the L1 norm ||V-Vec|| between Vec elements [VecIndex]..[VecIndex+Len-1] and calling vector elements [Index]..[Index+Len-1].*) function NormL1(const Vec: TOpenCLMtxVec; VecIndex,Index,Len: integer; RelativeError: boolean = false): double; overload; (*Calculate the L1-norm of the calling vector. L-1 norm, defined by the following equation: NormL1 = Sum(|a[i]|), 0 < i < Length-1*) function NormL1: double; overload; (*Calculates the L1 norm from calling vector elements [Index]..[Index+Len-1].*) function NormL1(Index,Len: integer): double; overload; (*The L2-norm. L2 norm, defined by ||V-Vec||, where V is calling vector. 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: If RelativeError is true then the computed norm is divided by the norm of V, and the function returns the "relative error": 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 c = a.NormL2(b,true); } finally { clMtxVec.FreeIt(ref a,ref b); } } } *) function NormL2(const Vec: TOpenCLMtxVec; RelativeError: boolean = False): double; overload; (*Calculates the L2 norm ||V-Vec|| between Vec elements [VecIndex]..[VecIndex+Len-1] and calling vector elements [Index]..[Index+Len-1].*) function NormL2(const Vec: TOpenCLMtxVec; VecIndex,Index,Len: integer; RelativeError: boolean = False): double; overload; (*Calculate the L2-norm of the calling vector. L2 norm, defined by: NormaL2 = ( Sum(|a[i]|^2) )^0.5 , 0 < i < Length-1 .*) function NormL2: double; overload; (*Calculates the L2 norm from calling vector elements [Index]..[Index+Len-1].*) function NormL2(Index,Len: integer): double; overload; (*Computes the sum and the sum of squared elements from the elements in the calling object.*) procedure SumAndSqrSum(out Sum, SqrSum: double); overload; (*Returns the sum and the sum of squared elements. Returns the sum and the sum of squared items from calling vector elements [Index]..[Index+Len-1]. *) procedure SumAndSqrSum(out Sum, SqrSum: double; Index, Len: integer); overload; (*Standard deviation. Calculate the standard deviation of all calling object elements. The result is a real value. An exception is raised if calling vector property is true. var a: clMatrix; c: double; aMean: double; begin a.Size(2,2, clFloat, false); a.CopyFromArray(TDoubleArray.Create(1,2,3,4)); Caption := FloatToSTr(a.StdDev); end; *) function StdDev: double; overload; (*Returns the standard deviation of calling object elements [Index]..[Index+Len-1]. An exception is raised if calling object property is true or if array borders are overrun/underrun. *) function StdDev(Index,Len: integer): double; overload; (*Returns the standard deviation of all calling object elements. The sum and the sum of squares of all calling object elements must be passed as parameters. An exception is raised if calling object property is true. *) function StdDev(aSum, aSumSqr: double): double; overload; (*Returns the standard deviation of calling object elements [Index]..[Index+Len-1]. The sum and the sum of squares of the coresponding elements must be passed as parameters. An exception is raised if calling object property is true or if array borders are overrun/underrun. *) function StdDev(aSum, aSumSqr: double; Index, Len: integer): double; overload; (*Elements product. the product of all calling object elements An exception is raised if calling object property is true. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { clMtxVec.TOpenCLMatrix a; clMtxVec.CreateIt(out a); try { a.CopyFromArray(new double[] {1,2,3,4}); double c = a.Product(); // c= 24 } finally { clMtxVec.FreeIt(ref a); } } } *) function Product: double; overload; (*Returns the product for calling object elements [Index]..[Index+Len-1]. An exception is raised if array borders are overrun or underrun. *) function Product(Index,Len: integer): double; overload; (*Calculate the product of all calling object complex elements. Store the result in complex variable X. *) procedure Product(out X: TCplx); overload; (*Calculate the product for calling object complex elements [Index]..[Index+Len-1]. Store the result in complex variable X. An exception is raised if array borders are overrun or underrun. *) procedure Product(out X: TCplx; Index,Len: integer); overload; (*Calculate the product of all calling object elements. Store the result in real variable X. *) procedure Product(out X: double); overload; (*Calculate the product for calling object elements [Index]..[Index+Len-1]. Store the result in real variable X. An exception is raised if array borders are overrun or underrun. *) procedure Product(out X: double; Index,Len: integer); overload; (*Elements product. the complex product of all calling object complext elements. An exception is raised if calling object property is false. *) function Productc: TCplx; overload; (*Returns the complex product for calling object complex elements [Index]..[Index+Len-1]. An exception is raised if array borders are overrun or underrun or if propety is false. *) function Productc(Index,Len: integer): TCplx; overload; (*Scalar product of two real arrays. 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: Both objects must be of equal size. If they are not, the method will return the dot product of the largest sub-array. 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); } } } *) function DotProd(const Vec: TOpenCLMtxVec): double; overload; (*Returns the scalar product between Vec elements [VecIndex]..[VecIndex+Len-1] and calling object elements [Index]..[Index+Len-1]. An exception is raised if Vec and calling object property is True. An exception is raised if array borders are overrun or underrun. *) function DotProd(const Vec: TOpenCLMtxVec; VecIndex, Index, Len: integer): double; overload; (*Scalar product of two complex arrays. Calculates the dot product (scalar value) of the calling object and Vec object and returns a complex scalar value. An exception is raised if calling or Vec object property is false. The dot product is defined by the equation: Both objects must be of equal size. If they are not, the method will return the dot product of the largest sub-array. 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.DotProdc(b); //= (1+2i)*(5+6i)+(3+4i)*(7+8i) } finally { clMtxVec.FreeIt(ref a,ref b); } } } *) function DotProdc(const Vec: TOpenCLMtxVec): TCplx; overload; (*Returns the scalar product between Vec (complex) elements [VecIndex]..[VecIndex+Len-1] and calling object (complex) elements [Index]..[Index+Len-1]. An exception is raised if Vec and calling object property is False. An exception is raised if array borders are overrun or underrun. *) function DotProdc(const Vec: TOpenCLMtxVec; VecIndex, Index, Len: integer): TCplx; overload; (*Returns the scalar product between Vec and calling object complex elements. If ConjVec is True, scalar product between calling object and conjugated Vec object elements is calculated. An exception is raised if Vec and calling object property is False. *) function DotProdc(const Vec: TOpenCLMtxVec; ConjVec: boolean): TCplx; overload; (*Returns the scalar product between Vec (complex) elements [VecIndex]..[VecIndex+Len-1] and calling object (complex) elements [Index]..[Index+Len-1]. If ConjVec is True, scalar product between calling object and conjugated Vec object elements is calculated. An exception is raised if Vec and calling object property is False. An exception is raised if array borders are overrun or underrun. *) function DotProdc(const Vec: TOpenCLMtxVec; ConjVec: boolean; VecIndex, Index, Len: integer): TCplx; overload; (*Converts the content of the matrix Values array to a list of strings. Convert all elements of the calling matrix to strings with formating real parts with ReFormat, imaginary parts with ImFormat, using the text delimiter Delimiter and store them in aList, by using the Add method of TStrings object. Performance note: This routine will be exceedingly slow, if TRichEdit.Lines or TMemo.Lines are passed as a parameter for dstList. Use TStringList or StringList types and then call TMemo.Lines.AddStrings(yourList) for best results. procedure TForm1.Button1Click(Sender: TObject); var a,b: TOpenCLMatrix; begin CreateIt(a,b); try a.SetIt(2,2,False,[1,2,3,4]); a.Cos; b.Size(a); b.SetVal(1); a.Add(b); Richedit1.Clear; Memo1.Clear; a.ValuesToStrings(Richedit1.Lines); b.ValuesToStrings(Richedit1.Lines); a.ValuesToStrings(Memo1.Lines); b.ValuesToStrings(Memo1.Lines); Memo1.Lines.SaveToFile('C:\Test.txt'); Memo1.Lines.LoadFromFile('C:\Test.txt'); finally FreeIt(a,b); end; end; *) procedure ValuesToStrings(dstList: TStrings; const Delimiter: string = kTab; const ReFormat: string = ' 0.######;-0.#######'; const ImFormat: string = '+0.######i;-0.######i'); overload; (*nvert calling matrix elements, starting with [Row,Col] and converting Len elements to strings. Vormating real parts with ReFormat, imaginary parts with ImFormat, using the text delimiter Delimiter and store them in aList starting at ListIndex. If aList is not large enough, the method will use the Add method of aList object. *) procedure ValuesToStrings(dstList: TStrings; ListIndex,Row,Col,RowCount,ColCount: integer; Delimiter: string = kTab; const ReFormat: string = ' 0.######;-0.######'; const ImFormat: string = '+0.######i;-0.######i'); overload; (*Converts all calling matrix elements to string.*) procedure ValuesToText(out Text: String; Delimiter: string = kTab; const ReFormat: string = ' 0.######;-0.#######'; const ImFormat: string = '+0.######i;-0.######i');overload; (*Converts Row..Col to Row+RowCount..Col+ColCount matrix elements to string.*) procedure ValuesToText(out Text: String; Row,Col,RowCount,ColCount: integer; Delimiter: string = kTab; const ReFormat: string = ' 0.######;-0.######'; const ImFormat: string = '+0.######i;-0.######i'); overload; function Size(aRows, aCols: integer; aPrecision: TclFloatPrecision; aComplex: boolean): TOpenCLMatrix; overload; function Size(ARows, ACols: integer; aPrecision: TclFloatPrecision): TOpenCLMtxVec; overload; function Size(const Src: TOpenCLMtxVec; aComplex: boolean): TOpenCLMtxVec; overload; function Size(const Src: TOpenCLBase): TOpenCLMtxVec; overload; property FloatPrecision: TCLFloatPrecision read GetFloatPrecision write SetFloatPrecision; property Tag: PointerInteger read GetTag write SetTag; property Caption: string read GetCaption write SetCaption; property Length: integer read GetLength write SetLength; property Complex: boolean read GetComplex write SetComplex; property Rows: integer read GetRows write SetRows; property Cols: integer read GetCols write SetCols; constructor Create(TargetDevice: TOpenCLDevice; IsCached: boolean = true); overload; constructor Create(DeviceSource: TOpenCLMtxVec; IsCached: boolean = true); overload; constructor Create(aRows, aCols: integer; aPrecision: TclFloatPrecision; aComplex: boolean; IsCached: boolean = true); overload; constructor Create(IsCached: boolean); overload; end; (*Open CL single value class with overloaded operators. Copying data from and to (from CPU separate) GPU memory can cause long delays even if that data is short. Sometimes it makes sense to keep even single value variables (scalars) in the GPU memory. Use this object to avoid copying individual values from GPU to CPU memory and reuse the scalars directly. *) clValue = record strict private FData: TOpenCLValue; function get_Data: TOpenCLValue; function GetCaption: string; function GetComplex: boolean; function GetTag: PointerInteger; procedure SetCaption(const Value: string); procedure SetComplex(const Value: boolean); procedure SetTag(const Value: PointerInteger); function GetClFloatPrecision: TclFloatPrecision; procedure SetClFloatPrecision(const Value: TclFloatPrecision); function GetDevice: TOpenCLDevice; procedure CreateFromCache; property Data: TOpenclValue read get_Data; public (*Add left to aRight and return result.*) class operator Add(const Left: TCplx; const Right: clValue): clValue; (*Add Right to Left and return result.*) class operator Add(const Left: clValue; const Right: TCplx): clValue; (*Add Left to Right and return result.*) class operator Add(Left: double;const Right: clValue): clValue; (*Add Right to Left and return result.*) class operator Add(const Left: clValue; Right: double): clValue; (*Add Left and Right.*) class operator Add(Left: TOpenCLValue;const Right: clValue): clValue; (*Add Left and Right.*) class operator Add(const Left: clValue; Right: TOpenCLValue): clValue; (*Add Left and Right.*) class operator Add(const Left: clValue;const Right: clValue): clValue; (*Subtract Right from Left.*) class operator Subtract(const Left: TCplx; const Right: clValue): clValue; (*Subtract Right from Left.*) class operator Subtract(const Left: clValue; const Right: TCplx): clValue; (*Subtract Right from Left.*) class operator Subtract(Left: double; const Right: clValue): clValue; (*Subtract Right from Left.*) class operator Subtract(const Left: clValue; Right: double): clValue; (*Subtract Right from Left.*) class operator Subtract(const Left: clValue; Right: TOpenCLValue): clValue; (*Subtract Right from Left.*) class operator Subtract(Left: TOpenCLValue; const Right: clValue): clValue; (*Subtract Right from Left.*) class operator Subtract(const Left: clValue;const Right: clValue): clValue; (*Multiply Left with Right.*) class operator Multiply(const Left: clValue; const Right: TCplx): clValue; (*Multiply Right with Left.*) class operator Multiply(const Left: TCplx; const Right: clValue): clValue; (*Multiply Left with Right.*) class operator Multiply(const Left: clValue; Right: double): clValue; (*Multiply Right with Left.*) class operator Multiply(Left: double; const Right: clValue): clValue; (*Multiply Left with Right.*) class operator Multiply(const Left: clValue; Right: TOpenCLValue): clValue; (*Multiply Left with Right.*) class operator Multiply(Left: TOpenCLValue; const Right: clValue): clValue; (*Multiply Left with Right*) class operator Multiply(const Left: clValue; const Right: clValue): clValue; (*Divide Left with Right.*) class operator Divide(const Left: clValue; const Right: TCplx): clValue; (*Divide Left with Right.*) class operator Divide(const Left: TCplx; const Right: clValue): clValue; (*Divide Left with Right.*) class operator Divide(const Left: clValue; Right: double): clValue; (*Divide Left with Right.*) class operator Divide(Left: double; const Right: clValue): clValue; (*Divide Left with Right.*) class operator Divide(const Left: clValue; Right: TOpenCLValue): clValue; (*Divide Left with Right.*) class operator Divide(Left: TOpenCLValue; const Right: clValue): clValue; (*Divide Left with Right.*) class operator Divide(const Left: clValue; const Right: clValue): clValue; (*Negates value inside AValue.*) class operator Negative(const AValue: clValue): clValue; class operator Explicit(const AValue: TCplx): clValue; class operator Explicit(const AValue: double): clValue; class operator Explicit(const AValue: clValue): TCplx; class operator Explicit(const AValue: clValue): double; class operator Explicit(const AValue: TOpenclValue): clValue; class operator Implicit(const AValue: clValue): TOpenCLValue; class operator Implicit(const AValue: clValue): TOpenCLBase; public (*Obtains the precision (single or double) from Src and sets Complex property to aComplex.*) function Size(const Src: TOpenCLBase; aComplex: boolean): TOpenCLBase; overload; (*Specify the precision (single or double) and if the value is to be complex or real.*) procedure Size(aPrecision: TclFloatPrecision; aComplex: boolean); overload; (*Copy object value. Copy value from Src elements to the calling object. Precision and properties of the calling object are set implicitly to match Src object. var a,b: clValue; begin a.Copy(2); b.Copy(a); // b = [1,2,3,4] end; *) function Copy(const Src: TOpenCLValue): TOpenCLValue; overload; (*Copy object value from CPU to GPU memory.*) function Copy(const Value: double): TOpenCLValue; overload; (*Copy object value from CPU to GPU memory.*) function Copy(const Value: TCplx): TOpenCLValue; overload; (*Copy object value from GPU to CPU memory.*) function Copy: double; overload; (*Copy object value from GPU to CPU memory.*) function Copyc: TCplx; overload; (*Add values in Src1 and Src2. The result is stored in the calling object. and properties of the calling object are set implicitly to match Src1 and Src2. *) function Add(const Src1, Src2: TOpenCLValue): TOpenCLValue; overload; (*Add values in Src1 and Src2. The result is stored in the calling object. and properties of the calling object are set implicitly to match Vec and Value. *) function Add(const Vec: TOpenCLValue; Value: double): TOpenCLValue; overload; (*Add values in Src1 and Src2. The result is stored in the calling object. and properties of the calling object are set implicitly to match Vec and Value. *) function Add(const Vec: TOpenCLValue; Value: TCplx): TOpenCLValue; overload; (*Split complex value in real and imaginary part. Split calling objects value into real and imaginary components. Store the real component in ReVec and imaginary component in ImVec. FloatPrecision and properties of ReVec and ImVec are set implicitly to match with the calling value object. An execption is raised, if the calling object is not complex. var a,b,c: clValue; begin a.Copy(Cplx(3,4)); // a= [1-2i, 3+4i] a.CplxToReal(b,c); // b = 3, c = 4 end; *) procedure CplxToReal(ReVec, ImVec: TOpenCLValue); overload; (*Constructs a complex object from two real objects. Construct a complex object from the ReVec (real part) and the ImVec (imaginary part) objects. The results are stored in the calling object. Size and properties of the calling object are set implicitly to match ReVec and ImVec objects. An exception is raised if ReVec or ImVec property is True. var a,b,c: clValue; begin a.Copy(3); b.Copy(4); c.RealToCplx(a,b); //c =3+4i; end; *) function RealToCplx(ReVec, ImVec: TOpenCLValue): TOpenCLValue; overload; (*Conjugate. Conjugate calling object value. var c: clValue; begin d.Copy(Cplx(2,3)); c.Conj(d); // d = 2-3i end; *) function Conj(const Vec: TOpenCLValue): TOpenCLValue; overload; (*Sets angle in [-2PI,2PI]. ThetaRad within -2 and interval. Calling this function prior to passing the value to trigonometric functions can significantly improve numerical accuracy. Sine/cosine appear within many other functions especially complex versions of trigonometric functions. FixAngle method is not used implicitely within TOpenCLValue methods. To achieve maximum performance make sure that the arguments passed to complex trigonometric functions are "small" or scaled down. This is where "FixAngle" can help. Note The vector must be real. *) function FixAngle(const Src: TOpenCLValue): TOpenCLValue; overload; (*Rounds Src object value towards negative infinity and stores the result in the calling object. FloatPrecision and properties of the calling object are adjusted automatically. *) function Floor(const Src: TOpenCLValue): TOpenCLValue; overload; (*A complex exponential e^(j*Omega)). Calculate the calling object complex exponential in-place. An exception is raised if calling object is complex. If object is complex, you should use the method instead. var a: clValue; begin b.Copy(2); a.Expj(b); // a = e^(2i) end; *) function Expj(Omega: TOpenCLValue): TOpenCLValue; overload; (*Fractional part of values. Calculates the fractional part for all object values in-place. var a,b: clValue; begin b.Copy(2.3); a.Frac(b); // a = 0.3 end; *) function Frac(const X: TOpenCLValue): TOpenCLValue; overload; (*Complementary error functon of value. Calculates the complementary error function value for object value. var a,b: clValue; begin b.Copy(2.3); a.Erfc(b); // a = Erfc(2.3) end; *) function Erfc(const Src: TOpenCLValue): TOpenCLValue; overload; (*Error function of value. Calculates the error function for object value. var a,b: clValue; begin b.Copy(2.3); a.Erf(b); // a = Erf(2.3) end; *) function Erf(const Src: TOpenCLValue): TOpenCLValue; overload; (*Flips the real and imaginary part of complex number. Performs the following transformation: a + i*bi ==> b + i*a Method flips the real and imaginary part of complex number X and stores the result in the calling object. *) function Flip(const X: TOpenCLValue): TOpenCLValue; overload; (*Flips the real and imaginary part and conjugates the complex number. Performs the following transformation: a + i*bi ==> b - i*a Method flips the real and imaginary part and conjugates calling objects complex value. *) function FlipConj(const X: TOpenCLValue): TOpenCLValue; overload; (*The Reminder after division X/Y. Calculates reminder after division according to formula: x[i]-y[i]*Trunc(x[i]/y[i]). The results will be saved to the calling object. var a,b,c: clValue; begin a.Copy(4); b.Copy(3); c.Rem(a,b); // c = Rem(4,3) end; *) function Rem(const X, Y: TOpenCLValue): TOpenCLValue; overload; (*Log base N. Computes Log with base N. var a,b: clValue; begin b.Copy(2.3); a.LogN(4, b); // // a = LogN(4, 2.3) end; *) function LogN(N: double; X: TOpenCLValue): TOpenCLValue; overload; (*Raises base object elements to any power. Raises Base calling object elements to any power. The is faster, if Exponent is an integer. Real valued power can handle only positive Exponent. can handle negative exponent also. To compute a power to the negative exponent in general case or when the base is negative, use the complex version of the function. var a,b: clValue; begin b.Copy(2.3); c.Copy(4); a.Power(b, c); // // a = b^c end; *) function Power(const Base, Exponent: TOpenCLValue): TOpenCLValue; overload; function Power(const Base: double; Exponent: TOpenCLValue): TOpenCLValue; overload; function Power(const Base: TCplx; Exponent: TOpenCLValue): TOpenCLValue; overload; function Power(const Base: TOpenCLValue; Exponent: double): TOpenCLValue; overload; function Power(const Base: TOpenCLValue; Exponent: TCplx): TOpenCLValue; overload; (*Rounds Src value. Stores the result in the calling object. *) function Round(const Src: TOpenCLValue): TOpenCLValue; overload; (* Computes signum function from Src value and stores the result in the calling object. Size and properties of calling object are adjusted automatically. Signum(X) is 1 for X > 0 , equal to zero for X = 0 and -1 for X < 0. *) function Sgn(const Src: TOpenCLValue): TOpenCLValue; overload; (*Signum. Calculates the signum of Src object value and multiplies it with the calling object value. Signum(const X) is 1 for X > 0 , equal to zero for X = 0 and -1 for X < 0. The length of Src and of the calling object must match or an exception will be raised. Size and property of calling object are adjusted automatically. *) function SgnMul(const Src: TOpenCLValue): TOpenCLValue; overload; (*Sine and cosine. Calculates the sine and cosine for calling object value and stores the sine to SinX and cosine to CosX. Note Use this method if you require both sine and cosine. var a, s,c: clValue; begin a.Copy(0); a.SinCos(s,c); // s=[0], c =[1] end; *) procedure SinCos(SinX, CosX: TOpenCLValue); overload; (*Hyperbolic sine and cosine. Calculates the hyperbolic sine and hyperbolic cosine for calling object value and stores the sine to SinhX and cosine to CoshX. FloatPrecision and property of SinhX and CoshX are adjusted automatically. Note Use this method if you require hyperbolic sine and hyperbolic cosine. var a, s, c: clValue; begin a.Copy(0); a.SinhCosh(s,c); end; *) procedure SinhCosh(SinhX, CoshX: TOpenCLValue); overload; (*Threshold bottom operation. Perform threshold operation on Src object value. The Value parameter is a lower bound for threshold operation. A value smaller than Value will be replaced with Value and stored in to the calling object. var a,b: clValue; begin b.Copy(0.1); a.ThreshBottom(b, 0.2); // a = [0.2] end; *) function ThreshBottom(const Src: TOpenCLValue; Value: double): TOpenCLValue; overload; (*Threshold top operation. Perform threshold operation on Src object value. The Value parameter is an upper bound for threshold operation. All values bigger than Value will be replaced with Value. var a,b: clValue; begin b.Copy(3); a.ThreshTop(b, 0.2); // a = [0.2] end; *) function ThreshTop(const Src: TOpenCLValue; Value: double): TOpenCLValue; overload; (*Threshold less than operation. Perform operation on Src object value. The LTValue parameter is an lower bound for threshold operation. Value less than LTLevel will be replaced with LTValue. For complex number comparison is applied with the norm of the complex value. var a: clValue; begin b.Copy(2)); a.ThresholdLT(b, 2.3,1.5); // a = [1.5] end; *) function ThresholdLT(const Vec: TOpenCLValue; LTLevel, LTValue: double): TOpenCLValue; overload; (*Perform "less than" threshold operation for Vec object complex number. Stores the result in the calling object. FloatPrecision and properties of the calling object are adjusted automatically. If Vec.Complex is false, an exception will be raised. *) function ThresholdLT(const Vec: TOpenCLValue; LTLevel: double; LTValue: TCplx): TOpenCLValue; overload; (*Threshold greater than operation. Perform operation on Vec object value. The GTValue parameter is an upper bound for threshold operation. Value bigger than LTLevel will be replaced with GTValue. For a complex number the comparison is applied with the norm of the complex value. var a: clValue; begin b.Copy(2); a.ThresholdGT(b, 1.3,1.5); // a = [1.5] end; *) function ThresholdGT(const Vec: TOpenCLValue; GTLevel, GTValue: double): TOpenCLValue; overload; (*Perform "greater than" threshold operation vor complex number stored in Vec object. Store the result in the calling object. FloatPrecision and properties of the calling object are adjusted automatically. If Vec object value is not Complex, an exception will be raised. *) function ThresholdGT(const Vec: TOpenCLValue; GTLevel: double; GTValue: TCplx): TOpenCLValue; overload; (*Threshold greater than and less than operation. Perform operation on Vec value. The LTValue parameter is an lower bound for threshold operation. The GTValue parameter is an upper bound for threshold operation. Values less than LTLevel will be replaced with LTValue. Value bigger than GTLevel will be replaced with GTValue. Operation is available only for none Complex values. var a,b: clValue; begin b.Copy(3); a.ThresholdGT_LT(b, 2.3,3.4,1,0.5); // a = [3.4] end; *) function ThresholdGT_LT (const Vec: TOpenCLValue; GTLevel, GTValue, LTLevel, LTValue: double): TOpenCLValue; overload; (*Rounds a real number towards zero and returns the fractional part. Rounds calling object value towards zero to an integer and stores the result in the TruncDst object as a floating point number. The fractional part is stored in the FracDst. *) procedure TruncAndFrac(TruncDst: TOpenCLValue; FracDst: TOpenCLValue); overload; (*Truncate Src object value. Store the result in the calling object. FloatPrecision and property of calling object are adjusted automatically. *) function Trunc(const Src: TOpenCLValue): TOpenCLValue; overload; (*The inverse of cube root 1/(v)^1/3. Calculate the inverse cube root (1/(element)^(1/3)) of the X. var a,b: clValue; begin b.Copy(2.3); a.InvCbrt(b); // a = 2.3^(1/3) end; *) function InvCbrt(const X: TOpenCLValue): TOpenCLValue; overload; (*The inverse of square root 1/(v)^1/2. Calculate the inverse square root 1/(element)^(1/2)) of X. var a,b: clValue; begin b.Copy(2.3); a.InvCbrt(b); // a = 2.3^(1/3) end; *) function InvSqrt(const X: TOpenCLValue): TOpenCLValue; overload; (*Magnitude. Calculate the magnitude for X. This method has the same function as the method. var a,b: clValue; begin b.Copy(Cplx(2,3)); a.Mag(b); end; *) function Mag(const X: TOpenCLValue): TOpenCLValue; overload; (*Multiply Src1 with Src2. Stores the result in the calling object. FloatPrecision and property of calling object are adjusted automatically to match those of Src1 and Src2. An exception is raised if Src1 and Src2 size and property do not match. *) function Mul(const Src1, Src2: TOpenCLValue): TOpenCLValue; overload; (*Multiply each element of Vec with Value. Store the result in the calling object. Size and properties of the calling object are adjusted automatically. *) function Mul(const Vec: TOpenCLValue; Value: double): TOpenCLValue; overload; (*Multiply Src with complex Value. Store the result in the calling object. Size of the calling object is set automatically. property of the calling object is set to True. *) function Mul(const Vec: TOpenCLValue; Value: TCplx): TOpenCLValue; overload; (*Multiply X with 1i and store the result in the calling object.*) function MulI(const X: TOpenCLValue): TOpenCLValue; overload; (*Converts the polar magnitude/phase pair to cartesian pair. Convert AmpltVec and PhaseVec elements (combined) from polar to cartesian form. The result is stored as a complex number (x=Re, y=Im) in the calling object. FloatPrecision and properties of the calling object are set implicitly to match AmpltVec and PhaseVec objects. var a,b,c: clValue; begin a.Copy(2); // a = [2] //magnitude b.Copy(3); // b = [1] //phase c.PolarToCart(a,b); // result stored in c = projections to Re and Im axis end; *) function PolarToCart(AmpltVec, PhaseVec: TOpenCLValue): TOpenCLValue; overload; (*Gets real part of complex object value. The method method gets the real part of a complex object Vec and stores the real result in the calling object. FloatPrecision and properties of the calling object are set implicitly to match Vec object. Vec property must be true otherwise an exception is raised. var a,b: clValue; begin a.Copy(Cplx(2,3)); // = [2+3i] b.RealPart(a); // b = [2] end; *) function RealPart(const Vec: TOpenCLValue): TOpenCLValue; overload; (*Square. Calculate the square of X. var a, b: clValue; begin b.Copy(2); a.Sqr(b); // a=[4] end; *) function Sqr(const X: TOpenCLValue): TOpenCLValue; overload; (*Square root. Calculate the square root of X. var a,b: clValue; begin b.Copy(4); a.Sqrt(b); // a=[2] end; *) function Sqrt(const X: TOpenCLValue): TOpenCLValue; overload; (*Sine function. Calculate the sine of X. var a,b: clValue; begin b.Copy(4); a.Sin(b); end; *) function Sin(const X: TOpenCLValue): TOpenCLValue; overload; (*Sine function. Calculate the cosine of X. var a,b: clValue; begin b.Copy(4); a.Cos(b); end; *) function Cos(const X: TOpenCLValue): TOpenCLValue; overload; (*Tangens. Calculate the tangens of X. var a,b: clValue; begin b.Copy(4); a.Tan(b); end; *) function Tan(const X: TOpenCLValue): TOpenCLValue; overload; (*Cotangens. Calculate the cotangens of x. var a,b: clValue; begin b.Copy(4); a.Cot(b); end; *) function Cot(const X: TOpenCLValue): TOpenCLValue; overload; (*Secant. Calculate the secant of X. var a,b: clValue; begin b.Copy(4); a.Sec(b); end; *) function Sec(const X: TOpenCLValue): TOpenCLValue; overload; (*Cosecant. Calculate the cosecant of X. var a,b: clValue; begin b.Copy(4); a.Csc(b); end; *) function Csc(const X: TOpenCLValue): TOpenCLValue; overload; (*The inverse sine. Calculate the inverse sine of X. Values must be between -1 and 1. The return values will be in the range [0,], in radians. var a,b: clValue; begin b.Copy(4); a.ArcSin(b); end; *) function ArcSin(const X: TOpenCLValue): TOpenCLValue; overload; (*The inverse cosine. Calculate the inverse cosine of X. Values must be between -1 and 1. The return values will be in the range [0,], in radians. var a,b: clValue; begin b.Copy(4); a.ArcCos(b); end; *) function ArcCos(const X: TOpenCLValue): TOpenCLValue; overload; (*Inverse tangens of Y/X. Calculates the inverse tangens of Y/X, and returns an angle in the correct quadrant. The results are stored in calling object. The values of X and Y must be between -2* and 2*. If they are not, consider adjusting the angle by calling the routine. In addition, the value of X can't be 0. The result will fall in the range from -2 and + radians. Note that is calculated as ArcTan2(1, X). *) function ArcTan2(Y, X: TOpenCLValue): TOpenCLValue; overload; (*Inverse tangens. Calculate the inverse tangens for X. The return values are expressed in radians. var a,b: clValue; begin b.Copy(0.5); a.ArcTan(b); end; *) function ArcTan(const X: TOpenCLValue): TOpenCLValue; overload; (*Inverse cotangens. Calculate the inverse cotangens for X. The returned value is expressed in radians. var a,b: clValue; begin b.Copy(0.5); a.ArcCot(b); end; *) function ArcCot(const X: TOpenCLValue): TOpenCLValue; overload; (*Calculate the inverse secant of X and stores the results in the calling object. FloatPrecision and properties of the calling object are adjusted automatically. *) function ArcSec(const X: TOpenCLValue): TOpenCLValue; overload; (*Calculate the inverse cosecant of X. Store the results in the calling object. *) function ArcCsc(const X: TOpenCLValue): TOpenCLValue; overload; (*Hyperbolic sine. Calculate the hyperbolic sine of X. var a,b: clValue; begin b.Copy(0.5); a.Sinh(b); end; *) function Sinh(const X: TOpenCLValue): TOpenCLValue; overload; (*Hyperbolic cosine. Calculate the hyperbolic cosine of all caling object elements in-place. var a,b: clValue; begin b.Copy(0.5); a.Cosh(b); end; *) function Cosh(const X: TOpenCLValue): TOpenCLValue; overload; (*Hyperbolic tangens. Calculate the hyperbolic tangens of X. var a,b: clValue; begin b.Copy(0.5); a.Tanh(b); end; *) function Tanh(const X: TOpenCLValue): TOpenCLValue; overload; (*Hyperbolic cotangens. Calculate the hyperbolic cotangens of X. var a,b: clValue; begin b.Copy(0.5); a.Coth(b); end; *) function Coth(const X: TOpenCLValue): TOpenCLValue; overload; (*Calculate the hyperbolic secant of X. Store the results in the calling object. FloatPrecision and properties of the calling object are adjusted automatically. *) function Sech(const X: TOpenCLValue): TOpenCLValue; overload; (*Calculate the hyperbolic cosecant of X. Store the results in the calling object. FloatPrecision and properties of calling object are adjusted automatically. *) function Csch(const X: TOpenCLValue): TOpenCLValue; overload; (*Absolute values of X. Calculate the absolute value of X. var a,b: clValue; begin b.Copy(-0.5); a.Abs(b); end; *) function Abs(const X: TOpenCLValue): TOpenCLValue; overload; (*Calculate the inverse hyperbolic sine of X. Store the result in the calling object. FloatPrecision and properties of calling object are adjusted automatically. *) function ArcSinh(const X: TOpenCLValue): TOpenCLValue; overload; (*Calculate the inverse hyperbolic cosine of X. Store the result in the calling object. FloatPrecision and properties of calling object are adjusted automatically. *) function ArcCosh(const X: TOpenCLValue): TOpenCLValue; overload; (*Calculate the inverse hyperbolic tangens of X. Store the result in the calling object. FloatPrecision and properties of calling object are adjusted automatically. *) function ArcTanh(const X: TOpenCLValue): TOpenCLValue; overload; (*Calculate the inverser hyperbolic cotangens of X. Store the result in calling object. FloatPrecision and properties of calling object are adjusted automatically. *) function ArcCoth(const X: TOpenCLValue): TOpenCLValue; overload; (*Calculate the inverse hyperbolic secant of X. Store the result in calling object. FloatPrecision and properties of calling object are adjusted automatically. *) function ArcSech(const X: TOpenCLValue): TOpenCLValue; overload; (*Calculate the inverse hyperbolic cosecant of X. Store the result in calling object. FloatPrecision and properties of calling object are adjusted automatically. *) function ArcCsch(const X: TOpenCLValue): TOpenCLValue; overload; (*The cube root. Calculate the cube root of X. var a,b: clValue; begin b.Copy(8); a.Cbrt(b); end; *) function Cbrt(const X: TOpenCLValue): TOpenCLValue; overload; (*Rounds towards positive infinity. Rounds towards positive infinity in-place. Ceil(-2.8) = -2 Ceil(2.8) = 3 Ceil(-1.0) = -1 *) function Ceil(const Src: TOpenCLValue): TOpenCLValue; overload; (*Natural logarithm. Calculate the natural log of X. var a,b: clValue; begin b.Copy(8); a.Ln(b); end; *) function Ln(const X: TOpenCLValue): TOpenCLValue; overload; (*Log base 10. Calculate the log base 10 of X. var a,b: clValue; begin b.Copy(8); a.Log10(b); end; *) function Log10(const X: TOpenCLValue): TOpenCLValue; overload; (*Log base 2. Calculate the log base 2 of X. var a,b: clValue; begin b.Copy(8); a.Log2(b); end; *) function Log2(const X: TOpenCLValue): TOpenCLValue; overload; (*Exponent (e^). Calculate the exponent e^X. var a,b: clValue; begin b.Copy(8); a.Exp(b); end; *) function Exp(const X: TOpenCLValue): TOpenCLValue; overload; (*Exponent base 2 (2^X). Calculate the exponent base 2 (2^X). var a,b: clValue; begin b.Copy(8); a.Exp2(b); end; *) function Exp2(const X: TOpenCLValue): TOpenCLValue; overload; (*Exponent base 10 (10^X). Calculate the exponent base 10 (10^X). var a,b: clValue; begin b.Copy(8); a.Exp10(b); end; *) function Exp10(const X: TOpenCLValue): TOpenCLValue; overload; (*Gets the imaginary part of a complex object. Gets the imaginary part of a complex object Vec and stores the real result in the calling object. FloatPrecision and properties of the calling object are set implicitly to match Vec object. Vec must be true otherwise an exception will be raised. var a,b: clValue; begin b.Copy(Cplx(8)); a.ImagPart(b); // a = 0 end; *) function ImagPart(const Vec: TOpenCLValue): TOpenCLValue; overload; (*Power (integer exponent). Calculate the power Base^Exponent. For non integer exponents, the method can be used. var a,b: clValue; begin b.Copy(8); a.IntPower(b, 2); end; *) function IntPower(const aBase: TOpenCLValue; Exponent: Integer): TOpenCLValue; overload; (*Inverse (1/x). Calculates the inverse of X. var a,b: clValue; begin b.Copy(8); a.Inv(b); // a = 1/8 end; *) function Inv(const X: TOpenCLValue): TOpenCLValue; overload; (*Converts value from cartesian to polar coordinate form. Converts calling object value from cartesian to polar coordinate form, storing the magnitude (radius) component in the AmpltVec and the phase (angle) component in the PhaseVec. If you want to use this method then the calling objects property must be true. If this is not the case, an exception is raised. FloatPrecision and properties of AmpltVec and PhaseVec are set automatically. *) procedure CartToPolar(AmpltVec, PhaseVec: TOpenCLValue); overload; (*Divide Num with Den. The result is stored in the calling object. The result of division by zero will be the INF constant. Division of zero by zero will result in NAN. *) function Divide(Num, Den: TOpenCLValue): TOpenCLValue; overload; (*Divide Value with Vec and store the result in the calling object.*) function DivideBy(Value: double; Vec: TOpenCLValue): TOpenCLValue; overload; (*Divide complex Value with Vec and store the result in the calling object. Size of the calling object is set automatically. *) function DivideBy(Value: TCplx; Vec: TOpenCLValue): TOpenCLValue; overload; (*Subtract real Value from Src. Store the result in calling object. *) function Sub(const Src: TOpenCLValue; Value: double): TOpenCLValue; overload; (*Subtract complex Value from Src. Store the results in calling object. Size and property of calling object are adjusted automatically. *) function Sub(const Src: TOpenCLValue; Value: TCplx): TOpenCLValue; overload; (*Computes Vec1 - Vec2. Stores the result in the calling object. FloatPrecision and property of the calling object are adjusted automatically. An exception is raised if Vec1 and Vec2 FloatPrecision and properties do not match. *) function Sub(const Vec1, Vec2: TOpenCLValue): TOpenCLValue; overload; (*Substract Vec elements from Value. Stores the result in the calling object. FloatPrecision and properties of the calling object are adjusted automatically. *) function SubFrom(Value: double; Vec: TOpenCLValue): TOpenCLValue; overload; (*Substract complex Vec elements from Value. Stores the result in the calling object. FloatPrecision property of the calling object is set automatically. property of the calling object is set to True. *) function SubFrom(Value: TCplx; Vec: TOpenCLValue): TOpenCLValue; overload; (*Returns the device on which we allocated memory for this object. *) property Device: TOpenCLDevice read GetDevice; property FloatPrecision: TCLFloatPrecision read GetclFloatPrecision write SetclFloatPrecision; property Tag: PointerInteger read GetTag write SetTag; property Caption: string read GetCaption write SetCaption; property Complex: boolean read GetComplex write SetComplex; end; (*Subrange the source clVector. Internally calls *) function Select(const Src: TOpenCLVector; StartIndex, Step, StopIndex: integer): clVector; overload; (*Subrange the source clVector without copy operation. Internally calls *) function Select(const Src: TOpenCLVector; StartIndex, StopIndex: integer): clVector; overload; (*Subrange the source clMatrix and return a clVector. Internally calls *) function Select(const Src: TOpenCLMatrix; StartIndex, Step, StopIndex: integer): clVector; overload; (*Subrange the source clMatrix and return a clVector without copy operation. Internally calls *) function Select(const Src: TOpenCLMatrix; StartIndex, StopIndex: integer): clVector; overload; (*Compute the sin function from the source and return the result. Internally calls *) function Sin(const X: TOpenCLVector): clVector; overload; (*Compute the sin function from the source and return the result. Internally calls *) function Sin(const X: TOpenCLMatrix): clMatrix; overload; (*Compute the cos function from the source and return the result. Internally calls *) function Cos(const X: TOpenCLVector): clVector; overload; (*Compute the cos function from the source and return the result. Internally calls *) function Cos(const X: TOpenCLMatrix): clMatrix; overload; (*Compute the Tan function from the source and return the result. Internally calls *) function Tan(const X: TOpenCLVector): clVector; overload; (*Compute the Tan function from the source and return the result. Internally calls *) function Tan(const X: TOpenCLMatrix): clMatrix; overload; (*Compute the Cot function from the source and return the result. Internally calls *) function Cot(const X: TOpenCLVector): clVector; overload; (*Compute the Cot function from the source and return the result. Internally calls *) function Cot(const X: TOpenCLMatrix): clMatrix; overload; (*Compute the Sec function from the source and return the result. Internally calls *) function Sec(const X: TOpenCLVector): clVector; overload; (*Compute the Sec function from the source and return the result. Internally calls *) function Sec(const X: TOpenCLMatrix): clMatrix; overload; (*Compute the Csc function from the source and return the result. Internally calls *) function Csc(const X: TOpenCLVector): clVector; overload; (*Compute the Csc function from the source and return the result. Internally calls *) function Csc(const X: TOpenCLMatrix): clMatrix; overload; (*Compute the ArcSin function from the source and return the result. Internally calls *) function ArcSin(const X: TOpenCLVector): clVector; overload; (*Compute the ArcSin function from the source and return the result. Internally calls *) function ArcSin(const X: TOpenCLMatrix): clMatrix; overload; (*Compute the ArcCos function from the source and return the result. Internally calls *) function ArcCos(const X: TOpenCLVector): clVector; overload; (*Compute the ArcCos function from the source and return the result. Internally calls *) function ArcCos(const X: TOpenCLMatrix): clMatrix; overload; (*Compute the ArcTan function from the source and return the result. Internally calls *) function ArcTan(const X: TOpenCLVector): clVector; overload; (*Compute the ArcTan function from the source and return the result. Internally calls *) function ArcTan(const X: TOpenCLMatrix): clMatrix; overload; (*Compute the ArcTan2 function from X and Y and return the result. Internally calls *) function ArcTan2(Y,X: TOpenCLVector): clVector; overload; (*Compute the ArcTan2 function from X and Y and return the result. Internally calls *) function ArcTan2(Y,X: TOpenCLMatrix): clMatrix; overload; (*Compute the ArcCot function from the source and return the result. Internally calls *) function ArcCot(const X: TOpenCLVector): clVector; overload; (*Compute the ArcCot function from the source and return the result. Internally calls *) function ArcCot(const X: TOpenCLMatrix): clMatrix; overload; (*Compute the ArcSec function from the source and return the result. Internally calls *) function ArcSec(const X: TOpenCLVector): clVector; overload; (*Compute the ArcSec function from the source and return the result. Internally calls *) function ArcSec(const X: TOpenCLMatrix): clMatrix; overload; (*Compute the ArcCsc function from the source and return the result. Internally calls *) function ArcCsc(const X: TOpenCLVector): clVector; overload; (*Compute the ArcCsc function from the source and return the result. Internally calls *) function ArcCsc(const X: TOpenCLMatrix): clMatrix; overload; (*Compute the Sinh function from the source and return the result. Internally calls *) function Sinh(const X: TOpenCLVector): clVector; overload; (*Compute the Sinh function from the source and return the result. Internally calls *) function Sinh(const X: TOpenCLMatrix): clMatrix; overload; (*Compute the Cosh function from the source and return the result. Internally calls *) function Cosh(const X: TOpenCLVector): clVector; overload; (*Compute the Cosh function from the source and return the result. Internally calls *) function Cosh(const X: TOpenCLMatrix): clMatrix; overload; (*Compute the Tanh function from the source and return the result. Internally calls *) function Tanh(const X: TOpenCLVector): clVector; overload; (*Compute the Tanh function from the source and return the result. Internally calls *) function Tanh(const X: TOpenCLMatrix): clMatrix; overload; (*Compute the Coth function from the source and return the result. Internally calls *) function Coth(const X: TOpenCLVector): clVector; overload; (*Compute the Coth function from the source and return the result. Internally calls *) function Coth(const X: TOpenCLMatrix): clMatrix; overload; (*Compute the Sech function from the source and return the result. Internally calls *) function Sech(const X: TOpenCLVector): clVector; overload; (*Compute the Sech function from the source and return the result. Internally calls *) function Sech(const X: TOpenCLMatrix): clMatrix; overload; (*Compute the Csch function from the source and return the result. Internally calls *) function Csch(const X: TOpenCLVector): clVector; overload; (*Compute the Csch function from the source and return the result. Internally calls *) function Csch(const X: TOpenCLMatrix): clMatrix; overload; (*Compute the ArcSinh function from the source and return the result. Internally calls *) function ArcSinh(const X: TOpenCLVector): clVector; overload; (*Compute the ArcSinh function from the source and return the result. Internally calls *) function ArcSinh(const X: TOpenCLMatrix): clMatrix; overload; (*Compute the ArcCosh function from the source and return the result. Internally calls *) function ArcCosh(const X: TOpenCLVector): clVector; overload; (*Compute the ArcCosh function from the source and return the result. Internally calls *) function ArcCosh(const X: TOpenCLMatrix): clMatrix; overload; (*Compute the ArcTanh function from the source and return the result. Internally calls *) function ArcTanh(const X: TOpenCLVector): clVector; overload; (*Compute the ArcTanh function from the source and return the result. Internally calls *) function ArcTanh(const X: TOpenCLMatrix): clMatrix; overload; (*Compute the ArcCoth function from the source and return the result. Internally calls *) function ArcCoth(const X: TOpenCLVector): clVector; overload; (*Compute the ArcCoth function from the source and return the result. Internally calls *) function ArcCoth(const X: TOpenCLMatrix): clMatrix; overload; (*Compute the ArcSech function from the source and return the result. Internally calls *) function ArcSech(const X: TOpenCLVector): clVector; overload; (*Compute the ArcSech function from the source and return the result. Internally calls *) function ArcSech(const X: TOpenCLMatrix): clMatrix; overload; (*Compute the ArcCsch function from the source and return the result. Internally calls *) function ArcCsch(const X: TOpenCLVector): clVector; overload; (*Compute the ArcCsch function from the source and return the result. Internally calls *) function ArcCsch(const X: TOpenCLMatrix): clMatrix; overload; (*Compute the Abs function from the source and return the result. Internally calls *) function Abs(const X: TOpenCLVector): clVector; overload; (*Compute the Abs function from the source and return the result. Internally calls *) function Abs(const X: TOpenCLMatrix): clMatrix; overload; (*Compute the Cbrt function from the source and return the result. Internally calls *) function Cbrt(const X: TOpenCLVector): clVector; overload; (*Compute the Cbrt function from the source and return the result. Internally calls *) function Cbrt(const X: TOpenCLMatrix): clMatrix; overload; (*Compute the Ceil function from the source and return the result. Internally calls *) function Ceil(const X: TOpenCLVector): clVector; overload; (*Compute the Ceil function from the source and return the result. Internally calls *) function Ceil(const X: TOpenCLMatrix): clMatrix; overload; (*Compute the Ln function from the source and return the result. Internally calls *) function Ln(const X: TOpenCLVector): clVector; overload; (*Compute the Ln function from the source and return the result. Internally calls *) function Ln(const X: TOpenCLMatrix): clMatrix; overload; (*Compute the Log10 function from the source and return the result. Internally calls *) function Log10(const X: TOpenCLVector): clVector; overload; (*Compute the Log10 function from the source and return the result. Internally calls *) function Log10(const X: TOpenCLMatrix): clMatrix; overload; (*Compute the Log2 function from the source and return the result. Internally calls *) function Log2(const X: TOpenCLVector): clVector; overload; (*Compute the Log2 function from the source and return the result. Internally calls *) function Log2(const X: TOpenCLMatrix): clMatrix; overload; (*Compute the Exp function from the source and return the result. Internally calls *) function Exp(const X: TOpenCLVector): clVector; overload; (*Compute the Exp function from the source and return the result. Internally calls *) function Exp(const X: TOpenCLMatrix): clMatrix; overload; (*Compute the Exp2 function from the source and return the result. Internally calls *) function Exp2(const X: TOpenCLVector): clVector; overload; (*Compute the Exp2 function from the source and return the result. Internally calls *) function Exp2(const X: TOpenCLMatrix): clMatrix; overload; (*Compute the Exp10 function from the source and return the result. Internally calls *) function Exp10(const X: TOpenCLVector): clVector; overload; (*Compute the Exp10 function from the source and return the result. Internally calls *) function Exp10(const X: TOpenCLMatrix): clMatrix; overload; (*Returns the imaginary part of the source. Internally calls *) function ImagPart(const X: TOpenCLVector): clVector; overload; (*Returns the imaginary part of the source. Internally calls *) function Imag(const X: TOpenCLVector): clVector; overload; (*Returns the imaginary part of the source. Internally calls *) function ImagPart(const X: TOpenCLMatrix): clMatrix; overload; (*Returns the imaginary part of the source. Internally calls *) function Imag(const X: TOpenCLMatrix): clMatrix; overload; (*Compute the integer power function. Internally calls *) function IntPower(const Base: TOpenCLVector; Exponent: integer): clVector; overload; (*Compute the integer power function. Internally calls *) function IntPower(const Base: TOpenCLMatrix; Exponent: integer): clMatrix; overload; (*Compute 1/X. Internally calls *) function Inv(const X: TOpenCLVector): clVector; overload; (*Compute 1/X. Internally calls *) function Inv(const X: TOpenCLMatrix): clMatrix; overload; (*Compute (1/X)^2. Internally calls *) function InvSqrt(const X: TOpenCLVector): clVector; overload; (*Compute (1/X)^2. Internally calls *) function InvSqrt(const X: TOpenCLMatrix): clMatrix; overload; (*Compute (1/X)^2. Internally calls *) function InvCbrt(const X: TOpenCLVector): clVector; overload; (*Compute (1/X)^2. Internally calls *) function InvCbrt(const X: TOpenCLMatrix): clMatrix; overload; (*Return complex conjugate of the source. Internally calls *) function Conj(const X: TOpenCLVector): clVector; overload; (*Return complex conjugate of the source. Internally calls *) function Conj(const X: TOpenCLMatrix): clMatrix; overload; (*Extend the source to complex numbers. Internally calls *) function ExtendToComplex(const X: TOpenCLVector; Zeros: boolean = true): clVector; overload; (*Extend the source to complex numbers. Internally calls *) function ExtendToComplex(const X: TOpenCLMatrix; Zeros: boolean = true): clMatrix; overload; (*Make the angle fit within +/- PI. Internally calls *) function FixAngle(const X: TOpenCLVector): clVector; overload; (*Make the angle fit within +/- PI. Internally calls *) function FixAngle(const X: TOpenCLMatrix): clMatrix; overload; (*Compute the floor function from the source. Internally calls *) function Floor(const X: TOpenCLVector): clVector; overload; (*Compute the floor function from the source. Internally calls *) function Floor(const X: TOpenCLMatrix): clMatrix; overload; (*Computes the e^xj function from the source. Internally calls *) function Expj(const X: TOpenCLVector): clVector; overload; (*Computes the e^xj function from the source. Internally calls *) function Expj(const X: TOpenCLMatrix): clMatrix; overload; (*Return the fractional part of a real number in the source. Internally calls *) function Frac(const X: TOpenCLVector): clVector; overload; (*Return the fractional part of a real number in the source. Internally calls *) function Frac(const X: TOpenCLMatrix): clMatrix; overload; (*Exchange the real and imaginary parts of complex numbers. Internally calls *) function Flip(const X: TOpenCLVector): clVector; overload; (*Exchange the real and imaginary parts of complex numbers. Internally calls *) function Flip(const X: TOpenCLMatrix): clMatrix; overload; (*Exchange the real and imaginary parts of complex numbers and conjugate. Internally calls *) function FlipConj(const X: TOpenCLVector): clVector; overload; (*Exchange the real and imaginary parts of complex numbers and conjugate. Internally calls *) function FlipConj(const X: TOpenCLMatrix): clMatrix; overload; (*Return reminder after divison of X by Y. Internally calls *) function Rem(const X,Y: TOpenCLVector): clVector; overload; (*Return reminder after divison of X by Y. Internally calls *) function Rem(const X,Y: TOpenCLMatrix): clMatrix; overload; (*Compute magnitude from the source. Internally calls *) function Mag(const X: TOpenCLVector): clVector; overload; (*Compute magnitude from the source. Internally calls *) function Mag(const X: TOpenCLMatrix): clMatrix; overload; (*Compute X^2 from the source. Internally calls *) function Sqr(const X: TOpenCLVector): clVector; overload; (*Compute X^2 from the source. Internally calls *) function Sqr(const X: TOpenCLMatrix): clMatrix; overload; (*Compute X^2 from the source. Internally calls *) function Sqrt(const X: TOpenCLVector): clVector; overload; (*Compute X^2 from the source. Internally calls *) function Sqrt(const X: TOpenCLMatrix): clMatrix; overload; (*Compute X^2 from the source. Internally calls *) function LogN(const X: TOpenCLVector; N: double): clVector; overload; (*Compute X^2 from the source. Internally calls *) function LogN(const X: TOpenCLMatrix; N: double): clMatrix; overload; (*Multiply the source with 1i complex number. Internally calls *) function MulI(const X: TOpenCLVector): clVector; overload; (*Multiply the source with 1i complex number. Internally calls *) function MulI(const X: TOpenCLMatrix): clMatrix; overload; (*Compute (X + Offset)/Factor Internally calls *) function Normalize(const X: TOpenCLVector; Offset, Factor: double): clVector; overload; (*Compute (X + Offset)/Factor Internally calls *) function Normalize(const X: TOpenCLVector; Offset: TCplx; Factor: double): clVector; overload; (*Compute (X + Offset)/Factor Internally calls *) function Normalize(const X: TOpenCLMatrix; Offset, Factor: double): clMatrix; overload; (*Compute (X + Offset)/Factor Internally calls *) function Normalize(const X: TOpenCLMatrix; Offset: TCplx; Factor: double): clMatrix; overload; (*Compute the power function. Internally calls *) function Power(const Base: TOpenCLVector; const Exponent: double): clVector; overload; (*Compute the power function. Internally calls *) function Power(const Base: TOpenCLMatrix; const Exponent: double): clMatrix; overload; (*Compute the power function. Internally calls *) function Power(const Base: double; const Exponent: TOpenCLVector): clVector; overload; (*Compute the power function. Internally calls *) function Power(const Base: double; const Exponent: TOpenCLMatrix): clMatrix; overload; (*Compute the power function. Internally calls *) function Power(const Base: TCplx; const Exponent: TOpenCLVector): clVector; overload; (*Compute the power function. Internally calls *) function Power(const Base: TCplx; const Exponent: TOpenCLMatrix): clMatrix; overload; (*Compute the power function. Internally calls *) function Power(const Base: TOpenCLVector; const Exponent: TOpenCLVector): clVector; overload; function Power(const Base: TOpenCLMatrix; const Exponent: TOpenCLMatrix): clMatrix; overload; (*Compute the power function. Internally calls *) function Power(const Base: TOpenCLVector; const Exponent: TCplx): clVector; overload; (*Compute the power function. Internally calls *) function Power(const Base: TOpenCLMatrix; const Exponent: TCplx): clMatrix; overload; (*Compute the phase spectrum. Internally calls *) function PhaseSpectrum(const X: TOpenCLVector): clVector; overload; (*Compute the phase spectrum from the complex source data. Internally calls *) function PhaseSpectrum(const X: TOpenCLMatrix): clMatrix; overload; (*Compute the phase from the complex source data. Internally calls *) function Phase(const X: TOpenCLVector): clVector; overload; (*Compute the phase from the complex source data. Internally calls *) function Phase(const X: TOpenCLMatrix): clMatrix; overload; (*Compute the power spectrum from the complex source data. Internally calls *) function PowerSpectrum(const X: TOpenCLVector): clVector; overload; (*Compute the power spectrum from the complex source data. Internally calls *) function PowerSpectrum(const X: TOpenCLMatrix): clMatrix; overload; (*Returns the product of all elements in the source data. Internally calls *) function Product(const X: TOpenCLVector): double; overload; (*Returns the product of all elements in the source data. Internally calls *) function Product(const X: TOpenCLMatrix): double; overload; (*Returns the product of all elements in the source data. Internally calls *) function Productc(const X: TOpenCLVector): TCplx; overload; (*Returns the product of all elements in the source data. Internally calls *) function Productc(const X: TOpenCLMatrix): TCplx; overload; (*Rounds values to the closest integer. Internally calls *) function Round(const X: TOpenCLVector): clVector; overload; (*Rounds values to the closest integer. Internally calls *) function Round(const X: TOpenCLMatrix): clMatrix; overload; (*Returns the real part of the complex number. Internally calls *) function RealPart(const X: TOpenCLVector): clVector; overload; (*Returns the real part of the complex number. Internally calls *) function RealPart(const X: TOpenCLMatrix): clMatrix; overload; (*Returns the real part of the complex number. Internally calls *) function Real(const X: TOpenCLVector): clVector; overload; (*Returns the real part of the complex number. Internally calls *) function Real(const X: TOpenCLMatrix): clMatrix; overload; (*Compute the RMS from the source data. Internally calls *) function RMS(const X: TOpenCLVector): double; overload; (*Compute the RMS from the source data. Internally calls *) function RMS(const X: TOpenCLMatrix): double; overload; (*Change the sign of the source data. Internally calls *) function Sign(const X: TOpenCLVector): clVector; overload; (*Change the sign of the source data. Internally calls *) function Sign(const X: TOpenCLMatrix): clMatrix; overload; (*Compute the standard deviation from the source data. Internally calls *) function StdDev(const X: TOpenCLVector): double; overload; (*Compute the standard deviation from the source data. Internally calls *) function StdDev(const X: TOpenCLMatrix): double; overload; (*Returns the sum of elements in the source data. Internally calls *) function Sum(const X: TOpenCLVector): double; overload; (*Returns the sum of elements in the source data. Internally calls *) function Sum(const X: TOpenCLMatrix): double; overload; (*Returns the sum of elements in the source data. Internally calls *) function Sumc(const X: TOpenCLVector): TCplx; overload; (*Returns the sum of elements in the source data. Internally calls *) function Sumc(const X: TOpenCLMatrix): TCplx; overload; (*Rounds values towards to zero to integer. Internally calls *) function Trunc(const X: TOpenCLVector): clVector; overload; (*Rounds values towards zero to integer. Internally calls *) function Trunc(const X: TOpenCLMatrix): clMatrix; overload; (*Limit the smallest value in the source data. Internally calls *) function ThreshBottom(const X: TOpenCLVector; Value: double): clVector; overload; (*Limit the smallest value in the source data. Internally calls *) function ThreshBottom(const X: TOpenCLMatrix; Value: double): clMatrix; overload; (*Limit the largest value in the source data. Internally calls *) function ThreshTop(const X: TOpenCLVector; Value: double): clVector; overload; (*Limit the largest value in the source data. Internally calls *) function ThreshTop(const X: TOpenCLMatrix; Value: double): clMatrix; overload; (*Computes X + Y*Ascale Internally calls *) function AddScaled(const X,Y: TOpenCLVector; aScale: double): clVector; overload; (*Computes X + Y*Ascale Internally calls *) function AddScaled(const X,Y: TOpenCLMatrix; aScale: double): clMatrix; overload; (*Computes X + Y*Ascale Internally calls *) function AddScaled(const X,Y: TOpenCLVector; aScale: TCplx): clVector; overload; (*Computes X + Y*Ascale Internally calls *) function AddScaled(const X,Y: TOpenCLMatrix; aScale: TCplx): clMatrix; overload; (*Computes X + Y*Z Internally calls *) function AddProduct(const X, Y, Z: TOpenCLVector): clVector; overload; (*Computes X + Y*Z Internally calls *) function AddProduct(const X, Y, Z: TOpenCLMatrix): clMatrix; overload; (*Conjugate Y and multiply with X Internally calls *) function ConjMul(const X, Y: TOpenCLVector): clVector; overload; (*Conjugate Y and multiply with X Internally calls *) function ConjMul(const X, Y: TOpenCLMatrix): clMatrix; overload; (*Returns the difference of consecutive elements of the source data. Internally calls *) function Difference(const X: TOpenCLVector): clVector; overload; (*Returns the dot product: sum(X*Y). Internally calls *) function DotProd(const X,Y: TOpenCLVector): double; overload; (*Returns the dot product: sum(X*Y). Internally calls *) function DotProdc(const X,Y: TOpenCLVector; ConjY: boolean = false): TCplx; overload; (*Returns the maximum of the source data. Internally calls *) function Max(const X: TOpenCLVector): double; overload; (*Returns the maximum of the source data. Internally calls *) function Max(const X: TOpenCLMatrix): double; overload; (*Returns the minimum of the source data. Internally calls *) function Min(const X: TOpenCLVector): double; overload; (*Returns the minimum of the source data. Internally calls *) function Min(const X: TOpenCLMatrix): double; overload; (*Returns the maximum of the source data. Internally calls *) function Maxc(const X: TOpenCLVector): TCplx; overload; (*Returns the maximum of the source data. Internally calls *) function Maxc(const X: TOpenCLMatrix): TCplx; overload; (*Returns the minimum of the source data. Internally calls *) function Minc(const X: TOpenCLVector): TCplx; overload; (*Returns the minimum of the source data. Internally calls *) function Minc(const X: TOpenCLMatrix): TCplx; overload; (*Returns the average value of the source data. Internally calls *) function Mean(const X: TOpenCLVector): double; overload; (*Returns the average value of the source data. Internally calls *) function Mean(const X: TOpenCLMatrix): double; overload; (*Returns the average value of the source data. Internally calls *) function Meanc(const X: TOpenCLVector): TCplx; overload; (*Returns the average value of the source data. Internally calls *) function Meanc(const X: TOpenCLMatrix): TCplx; overload; (*Computes the C Norm between X and Y. Internally calls *) function NormC(const X,Y: TOpenCLVector; RelativeError: boolean = False): double; overload; (*Computes the C Norm for the source data X. Internally calls *) function NormC(const X: TOpenCLVector): double; overload; (*Computes the C Norm between X and Y. Internally calls *) function NormC(const X,Y: TOpenCLMatrix; RelativeError: boolean = False): double; overload; (*Computes the C Norm for the source data X. Internally calls *) function NormC(const X: TOpenCLMatrix): double; overload; (*Computes the L1 Norm between X and Y. Internally calls *) function NormL1(const X,Y: TOpenCLVector; RelativeError: boolean = False): double; overload; (*Computes the L1 Norm for X. Internally calls *) function NormL1(const X: TOpenCLVector): double; overload; (*Computes the L1 Norm between X and Y. Internally calls *) function NormL1(const X,Y: TOpenCLMatrix; RelativeError: boolean = False): double; overload; (*Computes the L1 Norm for X. Internally calls *) function NormL1(const X: TOpenCLMatrix): double; overload; (*Computes the L1 Norm between X and Y. Internally calls *) function NormL2(const X,Y: TOpenCLVector; RelativeError: boolean = False): double; overload; (*Computes the L2 Norm for X. Internally calls *) function NormL2(const X: TOpenCLVector): double; overload; (*Computes the L1 Norm between X and Y. Internally calls *) function NormL2(const X,Y: TOpenCLMatrix; RelativeError: boolean = False): double; overload; (*Computes the L2 Norm for X. Internally calls *) function NormL2(const X: TOpenCLMatrix): double; overload; (*Reverses the content of the source data. Internally calls *) function Reverse(const X: TOpenCLVector): clVector; overload; (*Rotates the content of the source data by Offset. Internally calls *) function Rotate(const X: TOpenCLVector; Offset: integer): clVector; overload; (*Shifts the content of the source data X by Offset left or right. Internally calls *) function Shift(const X: TOpenCLVector; Offset: integer): clVector; overload; (*Returns the sum of squares of the source data. *) function SumOfSquares(const X: TOpenCLVector): double; overload; (*Returns the sum of squares of the source data. *) function SumOfSquares(const X: TOpenCLMatrix): double; overload; (*Reduces the sampling frequency without filtering. Internally calls *) function DownSample(const Src: TOpenCLVector; Factor: integer; Phase: integer = 0): clVector; overload; (*Reduces the sampling frequency without filtering. Internally calls *) function DownSample(const Src: TOpenCLMatrix; Factor: integer; Phase: integer = 0): clVector; overload; (*Returns a clVector of [0, 1, .., Len-1] numbers. Internally calls *) function Ramp(Len: integer; aPrecision: TclFloatPrecision = clFloat): clVector; overload; (*Returns a clVector of [Offset, Offset+Step, .., Offset+(Len-1)*Step] numbers. Internally calls *) function Ramp(Len: integer; Offset, Step: TCplx; aPrecision: TclFloatPrecision = clFloat): clVector; overload; (*Returns a clVector of [Offset, Offset+Step, .., Offset+(Len-1)*Step] numbers. Internally calls *) function Ramp(Len: integer; Offset, Step: double; aPrecision: TclFloatPrecision = clFloat): clVector; overload; (*Returns a clVector of [Offset, Offset+Step, .., Offset+(Len-1)*Step] numbers. Internally calls *) function Ramp(Len: integer; Offset: TCplx; Step: double; aPrecision: TclFloatPrecision = clFloat): clVector; overload; (*Increase sampling frequency without filtering. Internally calls *) function UpSample(const Src: TOpenCLMatrix; Factor: integer; Phase: integer = 0): clVector; overload; (*Increase sampling frequency without filtering. Internally calls *) function UpSample(const Src: TOpenCLVector; Factor: integer; Phase: integer = 0): clVector; overload; (*Computes the Norm from source data. Internally calls *) function Norm(const Vec: TOpenCLVector): clVector; (*Compute the sin function from the source and return the result. Internally calls *) function Sin(const X: TOpenCLValue): clValue; overload; (*Compute the cos function from the source and return the result. Internally calls *) function Cos(const X: TOpenCLValue): clValue; overload; (*Compute the Tan function from the source and return the result. Internally calls *) function Tan(const X: TOpenCLValue): clValue; overload; (*Compute the Cot function from the source and return the result. Internally calls *) function Cot(const X: TOpenCLValue): clValue; overload; (*Compute the Sec function from the source and return the result. Internally calls *) function Sec(const X: TOpenCLValue): clValue; overload; (*Compute the Csc function from the source and return the result. Internally calls *) function Csc(const X: TOpenCLValue): clValue; overload; (*Compute the ArcSin function from the source and return the result. Internally calls *) function ArcSin(const X: TOpenCLValue): clValue; overload; (*Compute the ArcCos function from the source and return the result. Internally calls *) function ArcCos(const X: TOpenCLValue): clValue; overload; (*Compute the ArcTan function from the source and return the result. Internally calls *) function ArcTan(const X: TOpenCLValue): clValue; overload; (*Compute the ArcTan2 function from X and Y and return the result. Internally calls *) function ArcTan2(Y,X: TOpenCLValue): clValue; overload; (*Compute the ArcCot function from the source and return the result. Internally calls *) function ArcCot(const X: TOpenCLValue): clValue; overload; (*Compute the ArcSec function from the source and return the result. Internally calls *) function ArcSec(const X: TOpenCLValue): clValue; overload; (*Compute the ArcCsc function from the source and return the result. Internally calls *) function ArcCsc(const X: TOpenCLValue): clValue; overload; (*Compute the Sinh function from the source and return the result. Internally calls *) function Sinh(const X: TOpenCLValue): clValue; overload; (*Compute the Cosh function from the source and return the result. Internally calls *) function Cosh(const X: TOpenCLValue): clValue; overload; (*Compute the Tanh function from the source and return the result. Internally calls *) function Tanh(const X: TOpenCLValue): clValue; overload; (*Compute the Coth function from the source and return the result. Internally calls *) function Coth(const X: TOpenCLValue): clValue; overload; (*Compute the Sech function from the source and return the result. Internally calls *) function Sech(const X: TOpenCLValue): clValue; overload; (*Compute the Csch function from the source and return the result. Internally calls *) function Csch(const X: TOpenCLValue): clValue; overload; (*Compute the ArcSinh function from the source and return the result. Internally calls *) function ArcSinh(const X: TOpenCLValue): clValue; overload; (*Compute the ArcCosh function from the source and return the result. Internally calls *) function ArcCosh(const X: TOpenCLValue): clValue; overload; (*Compute the ArcTanh function from the source and return the result. Internally calls *) function ArcTanh(const X: TOpenCLValue): clValue; overload; (*Compute the ArcCoth function from the source and return the result. Internally calls *) function ArcCoth(const X: TOpenCLValue): clValue; overload; (*Compute the ArcSech function from the source and return the result. Internally calls *) function ArcSech(const X: TOpenCLValue): clValue; overload; (*Compute the ArcCsch function from the source and return the result. Internally calls *) function ArcCsch(const X: TOpenCLValue): clValue; overload; (*Compute the Abs function from the source and return the result. Internally calls *) function Abs(const X: TOpenCLValue): clValue; overload; (*Compute the Cbrt function from the source and return the result. Internally calls *) function Cbrt(const X: TOpenCLValue): clValue; overload; (*Compute the Ceil function from the source and return the result. Internally calls *) function Ceil(const X: TOpenCLValue): clValue; overload; (*Compute the Ln function from the source and return the result. Internally calls *) function Ln(const X: TOpenCLValue): clValue; overload; (*Compute the Log10 function from the source and return the result. Internally calls *) function Log10(const X: TOpenCLValue): clValue; overload; (*Compute the Log2 function from the source and return the result. Internally calls *) function Log2(const X: TOpenCLValue): clValue; overload; (*Compute the Exp function from the source and return the result. Internally calls *) function Exp(const X: TOpenCLValue): clValue; overload; (*Compute the Exp2 function from the source and return the result. Internally calls *) function Exp2(const X: TOpenCLValue): clValue; overload; (*Compute the Exp10 function from the source and return the result. Internally calls *) function Exp10(const X: TOpenCLValue): clValue; overload; (*Returns the imaginary part of the source. Internally calls *) function ImagPart(const X: TOpenCLValue): clValue; overload; (*Returns the imaginary part of the source. Internally calls *) function Imag(const X: TOpenCLValue): clValue; overload; (*Compute the integer power function. Internally calls *) function IntPower(const Base: TOpenCLValue; Exponent: integer): clValue; overload; (*Compute 1/X. Internally calls *) function Inv(const X: TOpenCLValue): clValue; overload; (*Compute (1/X)^2. Internally calls *) function InvSqrt(const X: TOpenCLValue): clValue; overload; (*Compute (1/X)^2. Internally calls *) function InvCbrt(const X: TOpenCLValue): clValue; overload; (*Return complex conjugate of the source. Internally calls *) function Conj(const X: TOpenCLValue): clValue; overload; (*Make the angle fit within +/- PI. Internally calls *) function FixAngle(const X: TOpenCLValue): clValue; overload; (*Compute the floor function from the source. Internally calls *) function Floor(const X: TOpenCLValue): clValue; overload; (*Computes the e^xj function from the source. Internally calls *) function Expj(const X: TOpenCLValue): clValue; overload; (*Return the fractional part of a real number in the source. Internally calls *) function Frac(const X: TOpenCLValue): clValue; overload; (*Exchange the real and imaginary parts of complex numbers. Internally calls *) function Flip(const X: TOpenCLValue): clValue; overload; (*Exchange the real and imaginary parts of complex numbers and conjugate. Internally calls *) function FlipConj(const X: TOpenCLValue): clValue; overload; (*Return reminder after divison of X by Y. Internally calls *) function Rem(const X,Y: TOpenCLValue): clValue; overload; (*Compute magnitude from the source. Internally calls *) function Mag(const X: TOpenCLValue): clValue; overload; (*Compute X^2 from the source. Internally calls *) function Sqr(const X: TOpenCLValue): clValue; overload; (*Compute X^2 from the source. Internally calls *) function Sqrt(const X: TOpenCLValue): clValue; overload; (*Compute X^2 from the source. Internally calls *) function LogN(const X: TOpenCLValue; N: double): clValue; overload; (*Multiply the source with 1i complex number. Internally calls *) function MulI(const X: TOpenCLValue): clValue; overload; (*Compute the power function. Internally calls *) function Power(const Base: TOpenCLValue; const Exponent: double): clValue; overload; (*Compute the power function. Internally calls *) function Power(const Base: double; const Exponent: TOpenCLValue): clValue; overload; (*Compute the power function. Internally calls *) function Power(const Base: TCplx; const Exponent: TOpenCLValue): clValue; overload; (*Compute the power function. Internally calls *) function Power(const Base: TOpenCLValue; const Exponent: TOpenCLValue): clValue; overload; (*Compute the power function. Internally calls *) function Power(const Base: TOpenCLValue; const Exponent: TCplx): clValue; overload; (*Rounds values to the closest integer. Internally calls *) function Round(const X: TOpenCLValue): clValue; overload; (*Returns the real part of the complex number. Internally calls *) function RealPart(const X: TOpenCLValue): clValue; overload; (*Returns the real part of the complex number. Internally calls *) function Real(const X: TOpenCLValue): clValue; overload; (*Change the sign of the source data. Internally calls *) function Sign(const X: TOpenCLValue): clValue; overload; (*Rounds values towards to zero to integer. Internally calls *) function Trunc(const X: TOpenCLValue): clValue; overload; (*Limit the smallest value in the source data. Internally calls *) function ThreshBottom(const X: TOpenCLValue; Value: double): clValue; overload; (*Limit the largest value in the source data. Internally calls *) function ThreshTop(const X: TOpenCLValue; Value: double): clValue; overload; function Sgn(const Src: TOpenCLVector): clVector; overload; function Sgn(const Src: TOpenCLMatrix): clMatrix; overload; (*Implements objects for use of Open CL. The unit declares TOpenCLVector and TOpenCLMatrix types and object wrappers for the most of the Open CL driver features. *) unit clMtxVec; interface {$DEFINE STDCALL} {$INCLUDE 'bdsppdefs.inc'} {$WARN SYMBOL_DEPRECATED OFF} uses OpenCL_Dynamic, Math387 ,Types ,ZLib ,Classes ,SysUtils ,SyncObjs ,Dialogs ,Forms ,StringVar ,MtxVec, AbstractMtxVec, MtxVecBase, AbstractMtxVecInt, MtxVecInt ,Windows ,ShlObj ; const (* Text identifying the NVIDIA platform. Use this constant to compare against the property. *) NVIDIA_PLATFORM = 'NVIDIA CUDA'; (* Text identifying the AMD platform. Use this constant to compare against the property. *) AMD_PLATFORM = 'AMD Accelerated Parallel Processing'; (* Text identifying the INTEL platform. Use this constant to compare against the property. *) INTEL_PLATFORM = 'Intel(R) OpenCL'; (* Resource id for loading CPU optimized double precision kernels. Use this constant as a parameter to the method. *) DEW_1D_KERNELS_CPU_DOUBLE = 12386; (* Resource id for loading CPU optimized single precision kernels. Use this constant as a parameter to the method. *) DEW_1D_KERNELS_CPU_SINGLE = 12387; (* Resource id for loading GPU optimized double precision kernels. Use this constant as a parameter to the method. *) DEW_1D_KERNELS_GPU_DOUBLE = 12388; (* Resource id for loading GPU optimized single precision kernels. Use this constant as a parameter to the method. *) DEW_1D_KERNELS_GPU_SINGLE = 12389; (* Resource id for loading CPU optimized double precision kernels. Use this constant as a parameter to the method. *) DEW_1D_KERNELS_CPU_DOUBLE_STR = 'DEW_1D_KERNELS_CPU_DOUBLE'; (* Resource id for loading CPU optimized single precision kernels. Use this constant as a parameter to the method. *) DEW_1D_KERNELS_CPU_SINGLE_STR = 'DEW_1D_KERNELS_CPU_SINGLE'; (* Resource id for loading GPU optimized double precision kernels. Use this constant as a parameter to the method. *) DEW_1D_KERNELS_GPU_DOUBLE_STR = 'DEW_1D_KERNELS_GPU_DOUBLE'; (* Resource id for loading GPU optimized single precision kernels. Use this constant as a parameter to the method. *) DEW_1D_KERNELS_GPU_SINGLE_STR = 'DEW_1D_KERNELS_GPU_SINGLE'; OPENCL_BLOCKLEN = 128; type TLocalMemType = (lmtGlobal, lmtLocal); (* Specifies the precision to be used for Open CL computation. *) TclFloatPrecision = (clFloat, clDouble); (* Contains additional device information for NVIDIA devices. *) TNVDeviceInfo = class strict private FKernelExecTimeout: boolean; FComputeCapabilityMajor: integer; FComputeCapabilityMinor: integer; FWarpSize: integer; FGPUOverlap: boolean; FRegistersPerBlock: integer; FIntegratedMemory: boolean; private (* Internal use only. *) procedure Update(DeviceID: cl_device_id); public (* Compute capability equal to 2 implies a Fermi GPU. *) property ComputeCapabilityMajor: integer read FComputeCapabilityMajor; (* Compute capability version x in y.x Compute capability of at least 1.3 is required to allow execution of double precision code. *) property ComputeCapabilityMinor: integer read FComputeCapabilityMinor; (*Returns number of registers available per compute block. Typically 8192. *) property RegistersPerBlock: integer read FRegistersPerBlock; (* Returns the size of the warp. Typically 32. *) property WarpSize: integer read FWarpSize; (* Specifies if device supports overlapping copy and compute operations. With devices 1.2 and later, it is possible to overlap kernel execution on the device with data transfers between the host and the device. With devices 2.0 and later two independent copy engines are capable of simultaneous copy in two directions concurrent with device computation. In order to overlap computation and copy operations at least two command queues need to be created for the device and device must support multiple command queues. *) property GPUOverlap: boolean read FGPUOverlap; (* Returns true if Kernel execution can timeout. *) property KernelExecTimeout: boolean read FKernelExecTimeout; (* Returns true if GPU has integrated memory (not Host shared). *) property IntegratedMemory: boolean read FIntegratedMemory; end; (* Contains additional device information for AMD devices. *) TAMDDeviceInfo = class strict private FMediaOps: boolean; FOpenVideo: boolean; FEventCallback: boolean; FFP64: boolean; FPrintf: boolean; private (* Internal use only. *) procedure Update(const Extensions: TStrings); public (* Returns true if the device is capable of double precision processing. To actually enable support for double precision you need to include: #pragma OPENCL EXTENSION cl_amd_fp64 : enable In the source code header. *) property FP64: boolean read FFP64; (* Returns true, if the device provides the ability to register event callbacks for states other than cl_complete (cl_queued, cl_submitted, cl_running). Event callbacks are enabled by default, if available. *) property EventCallback: boolean read FEventCallback; (* Returns true if the device supports custom AMD media functions. The functions are: amd_pack, amd_unpack0, amd_unpack1, amd_unpack2, amd_unpack3, amd_bitalign, amd_lerp,... To enable support for this commands include: #pragma OPENCL EXTENSION cl_amd_media_ops : enable In the source code header. *) property MediaOps: boolean read FMediaOps; (* Returns true if the device supports hardware fixed-function video compression. To enable support for this feature include: #pragma OPENCL EXTENSION cl_amd_open_video : enable In the source code header. *) property OpenVideo: boolean read FOpenVideo; (* Returns true if the device supports printf command. To enable support for this feature include: #pragma OPENCL EXTENSION cl_amd_printf : enable In the source code header. *) property Printf: boolean read FPrintf; end; (* Contains device information specific to floating point math. *) TFPInfo = class strict private FInfNan: boolean; FRoundToZero: boolean; FFusedMA: boolean; FDenorms: boolean; FRoundToInf: boolean; FRoundToNearest: boolean; private procedure Update(const Src: UInt64); public (* Device supports denormals. *) property Denorms: boolean read FDenorms; (* Device supports INF and NAN numbers. *) property InfNan: boolean read FInfNan; (* Device supports round to nearest integer. *) property RoundToNearest: boolean read FRoundToNearest; (* Device supports round to towards zero. *) property RoundToZero: boolean read FRoundToZero; (* Device supports round to infinity. *) property RoundToInf: boolean read FRoundToInf; (* Device supports fused multiply and add instruction. *) property FusedMA: boolean read FFusedMA; end; TOpenCLPlatform = class; TOpenCLCache = class; TOpenCLKernelList = class; TOpenCLProgramList = class; TOpenCLCommandQueueList = class; TOpenCLCommandQueue = class; (* Stores data and information associated with the Open CL computing device. The object holds all information describing the properties of the device, programs, command queues and cache (buffer objects). To use the device we first define the size of the Cache and load the Programs. Then we can access Kernels which can be enqueued to Command queues. *) TOpenCLDevice = class strict private FName: string; FVendor: string; FVendorID: PointerInteger; FDeviceVersion: string; FOpenCLVersion: integer; FDriverVersion: string; FPreferredVectorWidthFloat: integer; FQueueOutOfOrderExec: boolean; FPreferredVectorWidthShort: integer; FImage3DMaxDepth: integer; FExtensions: TStringList; FMaxConstantBufferSize: Int64; FQueueProfiling: boolean; FMaxWorkItemDimensions: integer; FIsDefault: boolean; FIsAccType: boolean; FImage2DMaxHeight: integer; FImageSupport: boolean; FImage3DMaxHeight: integer; FErrorCorrectionSupport: boolean; FMaxClockFrequency: integer; FMaxWorkGroupSize: integer; FMaxComputeUnits: integer; FMaxReadImageArgs: integer; FPreferredVectorWidthDouble: integer; FIsCpuType: boolean; FLocalMemType: TLocalMemType; FLocalMemSize: Int64; FNVInfo: TNVDeviceInfo; FMaxWriteImageArgs: integer; FMaxMemAllocSize: Int64; FIsGpuType: boolean; FPreferredVectorWidthInt: integer; FAddressBits: integer; FImage2DMaxWidth: integer; FImage3DMaxWidth: integer; FPreferredVectorWidthChar: integer; FGlobalMemSize: Int64; FPreferredVectorWidthLong: integer; FMaxWorkItemSizes: array [0..2] of integer; fDeviceID: cl_device_id; FAvailable: boolean; FCompilerAvailable: boolean; FExecutionCapabilityNative: boolean; FGLobalMemCacheSize: Int64; FGlobalMemCachelineSize: integer; FMaxParameterSize: integer; FMaxSamplers: integer; FMinDataTypeAlignSize: integer; FMemBaseAddrAlign: integer; FDeviceProfile: string; FProfilingTimerResolution: integer; FFPSingleInfo: TFPInfo; FFP64: boolean; FFP16: boolean; FAMDInfo: TAMDDeviceInfo; FFPDoubleInfo: TFPInfo; FFPHalfInfo: TFPInfo; FByteAddressableStore: boolean; FGLSharing: boolean; FD3D10Sharing: boolean; fCommandQueue: TOpenCLCommandQueueList; fPlatform: TOpenCLPlatform; FCache: TOpenCLCache; FIsDebugging: boolean; fKernels: TOpenCLKernelList; FMappedCopy: boolean; fPrograms: TOpenCLProgramList; FNativeCPU: boolean; fQueueImmediateExecution: boolean; procedure SetNVInfo(const Value: TNVDeviceInfo); procedure SetFPSingleInfo(const Value: TFPInfo); procedure SetAMDInfo(const Value: TAMDDeviceInfo); procedure SetFPDoubleInfo(const Value: TFPInfo); procedure SetFPHalfInfo(const Value: TFPInfo); procedure SetCache(const Value: TOpenCLCache); procedure SetIsDebugging(const Value: boolean); procedure SetMappedCopy(const Value: boolean); procedure SetNativeCPU(const Value: boolean); function GetDeviceIndex: integer; function GetPlatformIndex: integer; protected property MappedCopy: boolean read FMappedCopy write SetMappedCopy; procedure Update; public (*Maximum number of work-items that can be specified in each dimension of the work-group. Returns n entries, where n is the value of . *) function GetMaxWorkItemSizes(Idx: integer): integer; (* Returns the platform of the device. *) property DevicePlatform: TOpenCLPlatform read fPlatform; (* Returns the index of the device in the list of devices for the platform. *) property DeviceIndex: integer read GetDeviceIndex; (* Returns the index of the platform in the list of platforms. *) property PlatformIndex: integer read GetPlatformIndex; (* The kernel list holds the list of kernels (Open CL functions) that are available. Kernel list is populated when a Program is loaded. Multiple programs can be loaded and all will have their Kernels added to this one list. When a program is deleted corresponding kernels will also be removed from this list. The desired Kernel is searched for with the help of the Locate method. *) property Kernels: TOpenCLKernelList read fKernels; (* The program list holds the list of compiled Open CL programs. To add a new program call the Add method. Then load the desired program using the . The programs loaded will be compiled on the first load and have binaries stored for subsequent faster loads. Programs can be loaded from resource, from text files or directly from a list of strings. All kernels (Open CL functions) contained in the loaded programs will be automatically added to the list of . *) property Programs: TOpenCLProgramList read fPrograms; (* The Cache object holds a list of and objects. The list of objects is used to prevent frequent memory allocation/deallocation and to increase memory reuse. *) property Cache: TOpenCLCache read FCache write SetCache; (* The list of available command queues. There is always at least one queue. Each time a function is to be called, the corresponding OpenCL kernels needs to be added to queue associated with the device. This object contains a list of queues to which we can enqueue our Kernels. For some devices only one queue is allowed. By default one queue is created when the object is initialized. Multiple queues can be useful when there is a need to achieve overlap between data copy and data compute. While one queue is running computation on the device, the other can be busy copying data from or to the device. All Kernels enqueued to all command queues on the given device share the Cache of that device. Only one queue can be associated with one thread. The associated threads will swift through all code submitting possibly many hundreds of Kernels to the queues and will then block on the line where the resulting data is to be copied from the device until that data will be ready. While debugging however, the queues will block on every breakpoint or step to allow inspection of the data being processed. When not debugging the threads will reach end of program long before the actual computation on the device will finish and will wait there for the device finish as well and to return desired results. *) property CommandQueue: TOpenCLCommandQueueList read fCommandQueue; property IsDebugging: boolean read FIsDebugging write SetIsDebugging; (* Returns the Device ID assigned to the device by Open CL driver. Use this value when you need to refer to this device when calling Open CL functions. *) property DeviceID: cl_device_id read FDeviceID; (* Returns true, if the device is available for use. *) property Available: boolean read FAvailable; (* Returns true, if the Open CL driver has a compiler included. This is always true at least for Windows OS based computers. *) property CompilerAvailable: boolean read FCompilerAvailable; (* Returns true, if the driver can execute native (not Open CL) kernels. *) property ExecutionCapabilityNative: boolean read FExecutionCapabilityNative; (* Returns global memory cache size in KBytes. *) property GLobalMemCacheSize: Int64 read FGLobalMemCacheSize; (* Returns global memory cache line size in Bytes. *) property GlobalMemCachelineSize: integer read FGlobalMemCachelineSize; (* Returns maximum size of the parameter in bytes. Max size in bytes of the arguments that can be passed to a kernel. The minimum value is 256 bytes. *) property MaxParameterSize: integer read FMaxParameterSize; (* Maximum number of samplers that can be used in a kernel. The minimum value is 8 if is true. *) property MaxSamplers: integer read FMaxSamplers; (* Minimum data alignment size. The minimum value is the size (in bytes) of the largest OpenCL builtin data type supported by the device (long16 in FULL profile, long16 or int16 in EMBEDDED profile). *) property MinDataTypeAlignSize: integer read fMinDataTypeAlignSize; (* Allignment in bits of memory buffers. The minimum value is the size (in bits) of the largest OpenCL built-in data type supported by the device (long16 in FULL profile, long16 or int16 in EMBEDDED profile). *) property MemBaseAddrAlign: integer read FMemBaseAddrAlign; (* OpenCL profile string. Returns the profile name supported by the device. The profile name returned can be one of the following strings: FULL_PROFILE – if the device supports the OpenCL specification (functionality defined as part of the core specification and does not require any extensions to be supported). EMBEDDED_PROFILE - if the device supports the OpenCL embedded profile. *) property DeviceProfile: string read FDeviceProfile; (* Describes the resolution of device timer. This is measured in nanoseconds. *) property ProfilingTimerResolution: integer read FProfilingTimerResolution; (* Returns the name of the device. *) property Name: string read FName; (* Returns the name of the Vendor. *) property Vendor: string read FVendor; (* Returns the value of the Vendor ID. *) property VendorID: PointerInteger read FVendorID; (* Returns Open CL Version. The first numeral is the major version and the second number represents the minor version. *) property OpenCLVersion: integer read FOpenCLVersion; (*Returns the device version. *) property DeviceVersion: string read FDeviceVersion; (*Returns the Open CL driver version. The form returned is major_number.minor_number *) property DriverVersion: string read FDriverVersion; (*Returns true if the device is of CPU type. *) property IsCpuType: boolean read FIsCpuType; (*Returns true if the device is of GPU type. *) property IsGpuType: boolean read FIsGpuType; (*Returns true if the device is of Accelerator type. *) property IsAccType: boolean read FIsAccType; (*Returns true if the device is of the default type. *) property IsDefault: boolean read FIsDefault; (*Returns the number of parallel compute units on the OpenCL device. A work-group executes on a single compute unit. The minimum value is 1. *) property MaxComputeUnits: integer read FMaxComputeUnits; (*Maximum dimensions that specify the global and local work-item IDs used by the data parallel execution model. The minimum value is 3. *) property MaxWorkItemDimensions: integer read FMaxWorkItemDimensions; (* Maximum number of work-items in a work-group executing a kernel on a single compute unit, using the data parallel execution model. *) property MaxWorkGroupSize: integer read FMaxWorkGroupSize; (* Maximum configured clock frequency of the device in MHz. *) property MaxClockFrequency: integer read FMaxClockFrequency; (* The default compute device address space size specified as an unsigned integer value in bits. Currently supported values are 32 or 64 bits. *) property AddressBits: integer read FAddressBits; (* Max size of memory object allocation in KBytes. The minimum value is max(1/4th of , 128*1024) *) property MaxMemAllocSize: Int64 read FMaxMemAllocSize; (* Size of global device memory in KBytes. *) property GlobalMemSize: Int64 read FGlobalMemSize; (* Returns true, if global memory uses ECC. Is true if the device implements error correction for all accesses to compute device memory (global and constant). Is false if the device does not implement such error correction. *) property ErrorCorrectionSupport: boolean read FErrorCorrectionSupport; (* Returns lmtLocal, if dedicated local memory storage is available. Returns lmtGlobal oterwhise. *) property LocalMemType: TLocalMemType read FLocalMemType; (* Returns the size of local memory (if present) in Bytes. The minimum value is 32KBytes. *) property LocalMemSize: Int64 read FLocalMemSize; (* Returns the size of constant memory in Bytes. The minimum value is 64 KB. *) property MaxConstantBufferSize: Int64 read FMaxConstantBufferSize; (* If true, the commands queued in the command-queue can be executed within the callers thread when the clEnqueue* is called. *) property QueueImmediateExecution: boolean read fQueueImmediateExecution; (* If true, the commands queued in the command-queue can be executed in-order or out-oforder. *) property QueueOutOfOrderExec: boolean read FQueueOutOfOrderExec; (* If true, command queues support profiling. *) property QueueProfiling: boolean read FQueueProfiling; (* Returns true, if immages are supported by the device. *) property ImageSupport: boolean read FImageSupport; (* Max number of simultaneous image objects that can be read by a kernel. The minimum value is 128, if is true. *) property MaxReadImageArgs: integer read FMaxReadImageArgs; (* Max number of simultaneous image objects that can be written by a kernel. The minimum value is 8, if is true. *) property MaxWriteImageArgs: integer read FMaxWriteImageArgs; (* Max width of 2D image in pixels. The minimum value is 8192, if is true. *) property Image2DMaxWidth: integer read FImage2DMaxWidth; (* Max height of 2D image in pixels. The minimum value is 8192, if is true. *) property Image2DMaxHeight: integer read FImage2DMaxHeight; (* Max width of 3D image in pixels. The minimum value is 2048, if is true. *) property Image3DMaxWidth: integer read FImage3DMaxWidth; (* Max height of 3D image in pixels. The minimum value is 2048, if is true. *) property Image3DMaxHeight: integer read FImage3DMaxHeight; (* Max depth of 3D image in pixels. The minimum value is 2048, if is true. *) property Image3DMaxDepth: integer read FImage3DMaxDepth; (* Holds a list of extension names supported by the device. The list of extension names returned can be vendor supported extension names and one or more of the following Khronos approved extension names: cl_khr_fp64 cl_khr_int64_base_atomics cl_khr_int64_extended_atomics cl_khr_fp16 cl_khr_gl_sharing cl_khr_gl_event cl_khr_d3d10_sharing The following approved Khronos extension names must be returned by all device that support OpenCL C 1.1: cl_khr_global_int32_base_atomics cl_khr_global_int32_extended_atomics cl_khr_local_int32_base_atomics cl_khr_local_int32_extended_atomics cl_khr_byte_addressable_store *) property Extensions: TStringList read FExtensions; (* Holds NVidia specific device information. *) property NVInfo: TNVDeviceInfo read FNVInfo write SetNVInfo; (* Holds AMD specific device information. *) property AMDInfo: TAMDDeviceInfo read FAMDInfo write SetAMDInfo; (* Holds information about single precision floating point math. *) property FPSingleInfo: TFPInfo read FFPSingleInfo write SetFPSingleInfo; (* Returns true if 64bit double precision floating point math is supported on the device. Contains result of checking for the corresponding extension. *) property FP64: boolean read FFP64; (* Returns true if 16bit half precision floating point math is supported on the device. Contains result of checking for the corresponding extension. *) property FP16: boolean read FFP16; (* Holds information about double precision floating point math. *) property FPDoubleInfo: TFPInfo read FFPDoubleInfo write SetFPDoubleInfo; (* Holds information about half precision floating point math. *) property FPHalfInfo: TFPInfo read FFPHalfInfo write SetFPHalfInfo; (* Returns true for Open CL v1.1. *) property ByteAddressableStore: boolean read FByteAddressableStore; (* Creating CL context from a GL context or share group is supported, if this property returns true. *) property GLSharing: boolean read FGLSharing; (* If true then interoperability between OpenCL and Direct3D 10 is supported. *) property D3D10Sharing: boolean read FD3D10Sharing; (* Returns preffered vector width for Open CL char type. *) property PreferredVectorWidthChar: integer read FPreferredVectorWidthChar; (* Returns preffered vector width for Open CL short type. *) property PreferredVectorWidthShort: integer read FPreferredVectorWidthShort; (* Returns preffered vector width for Open CL int type. *) property PreferredVectorWidthInt: integer read FPreferredVectorWidthInt; (* Returns preffered vector width for Open CL long type. *) property PreferredVectorWidthLong: integer read FPreferredVectorWidthLong; (* Returns preffered vector width for Open CL float type. *) property PreferredVectorWidthFloat: integer read FPreferredVectorWidthFloat; (* Returns preffered vector width for Open CL double type. *) property PreferredVectorWidthDouble: integer read FPreferredVectorWidthDouble; (*If true, application will run optimal CPU code without Open CL when this device will be the target . Set this property to true to run native MtxVec code using Intel IPP and Intel MKL libraries instead of submitting kernels to the Open CL driver. *) property NativeCPU: boolean read FNativeCPU write SetNativeCPU; constructor Create(aPlatform: TOpenCLPlatform; clDeviceID: cl_device_id); virtual; destructor Destroy; override; end; TOpenCLPlatform = class strict private FName: string; FVersion: string; FVendor: string; FProfile: string; fExtensions: TStringList; fContext: pcl_context; fBinaryPath: string; fPlatformID: cl_platform_id; aList: TObjectsList; procedure UpdateDevices; function GetDevice(i: integer): TOpenCLDevice; procedure SetDevice(i: integer; const Value: TOpenCLDevice); function GetCount: integer; protected procedure Update; public (*Array property gives access to individual devices available on the platform. *) property Device[i: integer]: TOpenCLDevice read GetDevice write SetDevice; default; (*Returns the number of devices available on the platform.*) property Count: integer read GetCount; (*Returns the name of the platform. You can use the following constants to compare against: NVIDIA_PLATFORM AMD_PLATFORM INTEL_PLATFORM *) property Name: string read FName; (*Returns platform version*) property Version: string read fVersion; (*Returns vendor name*) property Vendor: string read fVendor; (*Returns platform ID as assigned to be the Open CL driver. *) property PlatformID: cl_platform_id read fPlatformID; (*Returns the profile which can be either FULL_PROFILE or EMBEDDED_PROFILE. *) property Profile: string read FProfile; (*Contains a list of Open CL extensions supported by all devices on the platform. *) property Extensions: TStringList read FExtensions; (*Returns the Open CL context shared by all devices on the platform. *) property Context: pcl_context read fContext; (*Returns the path to the Open CL binary. *) property BinaryPath: string read fBinaryPath; (*All queues on all devices of this platform will be disassociated with any previosuly used threads. *) procedure UnMarkThreads; constructor Create(platform_ID: cl_platform_id); destructor Destroy; override; end; (*Holds the list of all available platforms on the computer. Each platform requires a driver. When using graphics cards, Open CL driver is installed together with the cards driver. Open CL drivers for Intel CPU's and AMD CPU's need to be downloaded separately. *) TOpenCLPlatformList = class strict private fIgnoreIntel: boolean; aList: TObjectsList; function GetPlatform(i: integer): TOpenCLPlatform; procedure SetPlatform(i: integer; const Value: TOpenCLPlatform); function GetCount: integer; public (*Set this property to true to avoid loading Intel Open CL code. Intel Open CL compilers excessively slow build procedure can cause minutes of delay during app startup when loading hundreds of kernels. This can speed up the method LoadProgramsForDevices for example. *) property IgnoreIntel: boolean read fIgnoreIntel write fIgnoreIntel; (*Array property gives access to individual platforms available on the computer. *) property Platforms[i: integer]: TOpenCLPlatform read GetPlatform write SetPlatform; default; (*Returns the number of platforms available on the computer.*) property Count: integer read GetCount; (*Store a list of source files to the resource file and use ResID for identification. Once the files are stored in the .res file, you can embedd the resource in to your application by adding {$R ResFileName} to your source file. The source files are automatically encrypted. *) procedure SaveSourceFileToRes(const ResFileName: string; ResID: Word; const SourceFiles: TStringList); overload; (*Store a source code to the resource file and use ResID for identification. Once the files are stored in the .res file, you can embedd the resource in to your application by adding {$R ResFileName} to your source file. The source code is automatically encrypted. *) procedure SaveSourceCodeToRes(const ResFileName: string; ResID: Word; const SourceCode: TStringList); overload; (*Store a list of source files to the resource file and use ResName for identification. Once the files are stored in the .res file, you can embedd the resource in to your application by adding {$R ResFileName} to your source file. The source files are automatically encrypted. *) procedure SaveSourceFileToRC(const ResFileName: string; const ResName: string; const SourceFiles: TStringList); overload; (*Store a source code to the resource file and use ResName for identification. Once the files are stored in the .res file, you can embedd the resource in to your application by adding {$R ResFileName} to your source file. The source code is automatically encrypted. *) procedure SaveSourceCodeToRC(const ResFileName: string; const ResName: string; const SourceCode: TStringList); overload; (*Delete all and precompiled binaries. *) procedure ClearPrecompiledBinaries; (*All queues on all platforms and devices will be disassociated with any previosuly used threads. *) procedure UnMarkThreads; (* Recreates the resource files from the default Open CL sources shipped with the product. *) procedure SaveDefaultToRes(const SrcFilePath: string); (* Recreates the resource files from the default Open CL sources shipped with the product. *) procedure SaveDefaultToRC(const SrcFilePath: string); (* Loads kernels for all devices in both single and double precision. The method will load all available kernels included with Cougar Open CL applicable to each device. Both single and double precision with CPU versions for CPU devices and GPU versions for GPU devices are supported. All kernels will be rebuilt unconditionally, if the Rebuild flag is true. Kernels will be rebuilt in either case if driver or hardware change is detected. *) procedure LoadProgramsForDevices(CPUSingle, CPUDouble, GPUSingle, GPUDouble: boolean; Rebuild: boolean = false); (* Returns the first found GPU device starting at first platform. If there is no GPU device found, the function returns nil. *) function GetFirstGPUDevice: TOpenCLDevice; (*The function will measure time of running LoadFunction on all devices and will return the fastest device. The command queue on the fastest is marked automatically. For each device the function will be called twice and should therefore have a meaningfull computational load. The first call is for warming up the cache and waking up the device from low power mode. The second call is timed. *) function AutoDeviceSelect(LoadFunction: TMtxNotifyEvent; CacheItemCount: integer; CacheItemLength: integer): TOpenCLDevice; (* Unloads the compiler(s), if this is supported by the driver(s). If needed in the future, the compilers will be reloaded again automatically. *) procedure UnLoadCompiler; constructor Create; virtual; destructor Destroy; override; end; (*Provides method to load Open CL programs either from resource, source or files. The object also caches compiled binaries for faster load times. It makes sense to use at least two programs when developing applications. One can contain already tested (larger) code and the second one is shorter and rebuilt on every restart. *) TOpenCLProgram = class strict private FBuildLog: TStringList; procedure SetBuildLog(const Value: TStringList); protected fCLProgram: pcl_program; fDevice: TOpenCLDevice; SourceFiles: TLocalAnsiStringArray; SourceFileLengths: TSize_tArray; procedure SaveProgramBinaries(const aBinaryFileName: string); overload; procedure CreateProgramWithBinaries(const aBinaryFileName: string); overload; procedure LoadCodeFromFile(const SourceFiles: TStringList; const SourceCode: TStringList); overload; procedure LoadCodeFromRes(const ResName: string; const SourceCode: TStringList); overload; procedure CreateProgramWithSourceCode(const SourceCode: TStrings; const SourceHeader: string); procedure BuildProgram(BuildOptions: string); function CleanEOL(const aStr: string): string; protected procedure CreateKernels; public property BuildLog: TStringList read FBuildLog write SetBuildLog; (* Returns the Device associated with the program. *) property Device: TOpenCLDevice read fDevice; (* Returns the Open CL program object. *) property clProgram: pcl_program read fCLProgram; (* Loads programs stored in SrcFileNames, adds SourceHeader, sets BuildOptions and compiles. If the program to be build is already found, the binary version is loaded directly saving valuable startup time for future runs. Set RebuildAlways to True to request unconditial recompile. When a driver change or hardware change is detected the programs will be automatically rebuild ignoring the value of RebuildAlways. All Kernels in the Open CL source code are automatically added to the list. *) procedure LoadProgram(const SrcFileNames: TStringList; const SourceHeader, BuildOptions: string; RebuildAlways: boolean = false); overload; (* Loads programs stored in the resource defined with ResName, adds SourceHeader, sets BuildOptions and compiles. If the program to be build is already found, the binary version is loaded directly saving valuable startup time for future runs. Set RebuildAlways to True to request unconditial recompile. When a driver change or hardware change is detected the programs will be automatically rebuild ignoring the value of RebuildAlways. All Kernels in the Open CL source code are automatically added to the list. *) procedure LoadProgram(const ResName: String; const SourceHeader, BuildOptions: string; RebuildAlways: boolean = false); overload; (* Loads programs stored in the SourceCode, adds SourceHeader, sets BuildOptions and compiles. If the program to be build is already found, the binary version is loaded directly saving valuable startup time for future runs. aBinFileName identifies the name of the binary file in which the compiler will save the result. Set RebuildAlways to True to request unconditial recompile. All Kernels in the Open CL source code are automatically added to the list. *) procedure LoadProgram(const aBinFileName: string; const SourceCode: TStrings; const SourceHeader, BuildOptions: string; RebuildAlways: boolean = false); overload; (* Returns the path and name of the compiled binary when the source code comes from a file. *) function BinaryFileName(const SrcFileName: string): string; overload; (* Returns the path and name of the compiled binary when the source code comes from an embedded resource. *) function BinaryFileNameRes(const ResName: string): string; overload; constructor Create(const aDevice: TOpenCLDevice); overload; virtual; destructor Destroy; override; end; (* Stores a list of Open CL programs. *) TOpenCLProgramList = class strict private fDevice: TOpenCLDevice; aList: TObjectsList; function GetItem(i: integer): TOpenCLProgram; procedure SetItem(i: integer; const Value: TOpenCLProgram); function GetCount: integer; public (*Array property gives access to individual programs available on the device. *) property Item[i: integer]: TOpenCLProgram read GetItem write SetItem; default; (*Returns the number of programs already added.*) property Count: integer read GetCount; (*Call this method to add a new program. After the program object has been created use the to load the actual source code or precompiled binary. *) function Add: TOpenCLProgram; (* Delete Open CL program from the list of programs. The related Kernels will also be removed from the *) procedure Delete(ItemIdx: integer); constructor Create(const aDevice: TOpenCLDevice); virtual; destructor Destroy; override; end; (* Open CL Kernels are added automatically to list when a program is loaded. *) TOpenCLKernel = class strict private FKernel: cl_kernel; fDevice: TOpenCLDevice; fProgram: TOpenCLProgram; fName: string; FWorkGroupSize: integer; fLocalMemorySize: integer; fCompileWorkGroupSize: TSize_tArray; fSetArg: TBooleanArray; FArgCount: integer; procedure UpdateInfo; procedure SetArgCount(const Value: integer); procedure SetArgIndex(argIndex: integer); public (* Returns the work-group size specified in the source code. In the source code we can specify the recommended work group size with the __attribute__((reqd_work_group_size(X, Y, Z))) qualifier. *) function GetCompileWorkGroupSize(i: integer): integer; (*Returns the Program for which the kernel was created.*) property CLProgram: TOpenCLProgram read fProgram; (*Returns the Open CL kernel object.*) property Kernel: cl_kernel read FKernel; (*Returns the number of arguments of the Kernel (function parameter count).*) property ArgCount: integer read FArgCount write SetArgCount; (*Returns the Open CL kernel object.*) property Name: string read fName; (*Returns the maximum size of the Work Group for this Kernel. The OpenCL implementation uses the resource requirements of the kernel (register usage etc.) to determine what this workgroup size should be. *) property WorkGroupSize: integer read FWorkGroupSize; (*Returns the amount of local memory in bytes being used by a kernel. This includes local memory that may be needed by an implementation to execute the kernel, variables declared inside the kernel with the __local address qualifier and local memory to be allocated for arguments to the kernel declared as pointers with the __local address qualifier and whose size is specified with clSetKernelArg. *) property LocalMemorySize: integer read fLocalMemorySize; (*Updates the value of to reflect changes caused with calls to clSetKernelArg.*) procedure UpdateLocalMemoryInfo; (*Sets the Kernel (Open CL function) parameter at argIndex to Value.*) procedure SetArgInt32(argIndex, Value: integer); (*Sets the Kernel (Open CL function) parameter at argIndex to Value.*) procedure SetArgBuffer(argIndex: integer; Value: pcl_mem); (*Sets the Kernel (Open CL function) parameter at argIndex to Value.*) procedure SetArgDouble(argIndex: integer; Value: double); (*Sets the Kernel (Open CL function) parameter at argIndex to Value.*) procedure SetArgSingle(argIndex: integer; Value: single); (*Sets the Kernel (Open CL function) parameter at argIndex to Value.*) procedure SetArgByte(argIndex: integer; Value: Byte); (*Sets the Kernel (Open CL function) parameter at argIndex to Value.*) procedure SetArgSmallInt(argIndex: integer; Value: SmallInt); (*Sets the Kernel (Open CL function) parameter at argIndex to Value.*) procedure SetArgSample(argIndex: integer; Value: double; Precision: TclFloatPrecision); (*Sets the Kernel (Open CL function) parameter at argIndex to local memory size associated with the queue. The amount of local memory associated with the queue is specified by the TOpenCLcommandQueue property. The total amount of local memory allocated across all queues running on the same device may not exceed total available local memory as reported by TOpenCLDevice.LocalMemSize. The guaranteed minimum available memory for LocalMemSize is 32kBytes. The reported memory is in Bytes. The amount of local memory associated with the queue also may not be less than the minimum required by the kernel (if specified). *) procedure SetArgLocalMem(argIndex: integer; const CmdQueue: TOpenCLCommandQueue); overload; (*Sets the Kernel (Open CL function) parameter at argIndex to local memory size associated with the queue. The memory size assigned is equal to SamplesLength*ElemSize. *) procedure SetArgLocalMem(argIndex: integer; const CmdQueue: TOpenCLCommandQueue; SamplesLength: integer; aElemSize: integer); overload; (*Submits the Kernel to cmdQueue for computation with specified WorkSize. Setting CPUAdjust to true will reduce WorkSize by factor OPENCL_BLOCKLEN and assume presence of kernel internal for-loops. Kernel internal for-loops can significantly speed up execution of the kernel on CPU devices lowering the function call overhead. The CPUAdjust parameter is used only if the device is of CPU type. The for-loop pattern expected inside the kernel looks like this: size_t i = get_global_id(0); size_t tIdx = i*BLOCK_LEN; size_t tIdxLen = tIdx + BLOCK_LEN; if (tIdxLen > Length) tIdxLen = Length; for (i = tIdx; i < tIdxLen; i++) { } where BLOCK_LEN matches OPENCL_BLOCKLEN. *) procedure Enqueue(const cmdQueue: TOpenCLCommandQueue; WorkSize: integer; CPUAdjust: boolean = true); overload; (*Submits the Kernel to cmdQueue for computation with specified WorkSize and LocalSize. When specified explicitely the (WorkSize mod LocalSize) is required to be zero. Setting CPUAdjust to true will reduce WorkSize by factor OPENCL_BLOCKLEN and assume presence of kernel internal for-loops. Kernel internal for-loops can significantly speed up execution of the kernel on CPU devices lowering the function call overhead. Kernel internal for-loops in GPU devices cause large performance penalties. The CPUAdjust parameter should be used only if the device is of CPU type. LocalSize is also called workgroup size. The for-loop pattern expected inside the kernel looks like this: size_t i = get_global_id(0); size_t tIdx = i*BLOCK_LEN; size_t tIdxLen = tIdx + BLOCK_LEN; if (tIdxLen > Length) tIdxLen = Length; for (i = tIdx; i < tIdxLen; i++) { } where BLOCK_LEN matches OPENCL_BLOCKLEN. *) procedure Enqueue(const cmdQueue: TOpenCLCommandQueue; WorkSize, LocalSize: integer; CPUAdjust: boolean = true); overload; procedure Enqueue(const cmdQueue: TOpenCLCommandQueue; const WorkSizeOffsets, WorkSizes, LocalSizes: array of integer; CPUAdjust: boolean); overload; (*Resets the kernel parameter setting process. The TOpenCLKernel object tracks which parameters were already set and which not yet. An attempt to submitt the kernel for computation without having all its parameters set will raise an exception. *) procedure ResetArgs; constructor Create(const KernelName: string; const aProgram: TOpenCLProgram); overload; virtual; constructor Create(aKernel: cl_kernel; const aProgram: TOpenCLProgram); overload; virtual; destructor Destroy; override; end; (* Stores a list of Open CL Kernels. *) TOpenCLKernelList = class strict private fDevice: TOpenCLDevice; aList: TStringList; function GetItem(i: integer): TOpenCLKernel; procedure SetItem(i: integer; const Value: TOpenCLKernel); function GetCount: integer; protected procedure Sort; procedure Add(aKernel: cl_kernel; const aProgram: TOpenCLProgram); public (*Array property gives access to Kernels programs available on the device. *) property Item[i: integer]: TOpenCLKernel read GetItem write SetItem; default; (*Returns the number of Kernels already added.*) property Count: integer read GetCount; (*Searches for and returns the kernel with KernelName. The function will raise an exception, if the Kernel is not found. *) function Locate(const KernelName: string): TOpenCLKernel; (*Searches for and returns the index of the kernel with KernelName. Returns true, if the kernel with KernelName exists and the Idx parameter will contain the index in the list on the output. *) function Find(const KernelName: string; var Idx: integer): boolean; (*Deletes and frees all kernels from the list.*) procedure Clear; (*Deletes and frees the Kernel at index specified from the list.*) procedure Delete(i: integer); constructor Create(const aDevice: TOpenCLDevice); virtual; destructor Destroy; override; end; TJobThread = class; TEventThread = class(TThread) protected Trigger: integer; JobThread: TJobThread; procedure Execute; override; public destructor Destroy; override; end; TOnClExecuteEvent = procedure(const cmdQueue: TOpenCLCommandQueue; JobIndex: integer) of object; TJobThread = class strict private FOnExecute: TOnClExecuteEvent; FJobIndex: integer; Thread: TEventThread; fCommandQueue: TOpenCLCommandQueue; procedure SetJobIndex(const Value: integer); procedure SetOnExecute(const Value: TOnClExecuteEvent); protected fExceptionMessage: string; public (* Contains the exception message (if triggered) while the OnExecute was called. *) property ExceptionMessage: string read fExceptionMessage; (* Returns the Open CL command queue associated with the thread. *) property CommandQueue: TOpenCLCommandQueue read fCommandQueue; (* Specifies the JobIndex passed to the threaded function as a parameter. Use this JobIndex to partition the jobs between mulitple devices. *) property JobIndex: integer read FJobIndex write SetJobIndex; (* Threaded event function. The event of specified type assigned to this property will be called each time the Start method is called. While this event is no running the Sleeping function will be returning true. Internally no thread will be created until the first assignment is made. *) property OnExecute: TOnClExecuteEvent read FOnExecute write SetOnExecute; (* Call Start to launch the thread and call the function assigned to OnExecute event from within the thread. The maximum start time is 1ms. *) procedure Start; (* Sleeping will return true, if event assigned to OnExecute event is not running. *) function Sleeping: boolean; constructor Create(const cmdQueue: TOpenClCommandQueue); virtual; destructor Destroy; override; end; (* Every Open CL function that we want to compute needs to be submitted to the command queue. Device can have multiple command queues if supported. *) TOpenCLCommandQueue = class strict private fJobThread: TJobThread; fDevice: TOpenCLDevice; fCommandQueue: pcl_command_queue; FImmediateExecution: boolean; FLocalMemorySize: integer; cs: TCriticalSection; procedure CreateCommandQue(aContext: pcl_context); procedure SetCommandQueueOutOfOrder(const Value: boolean); procedure SetCommandQueueProfiling(const Value: boolean); procedure SetImmediateExecution(const Value: boolean); procedure SetLocalMemorySize(const Value: integer); protected fQueueLength: integer; strict protected fThreadID: TThreadID; FCommandQueueProfiling: boolean; FCommandQueueOutOfOrder: boolean; public property QueueLength: integer read fQueueLength; property LocalMemorySize: integer read FLocalMemorySize write SetLocalMemorySize; property JobThread: TJobThread read fJobThread; property Device: TOpenCLDevice read FDevice; (* Returns the Open CL command queue object. *) property clCommandQueue: pcl_command_queue read fCommandQueue; (* Set this property to true, if you would like to have commands executed out of order. Cosecutive kernels submitted to this queue will not finish in the order in which they were started, if this property is set to true. The driver in this case allowed to optimize the order of execution to achieve highest performance on the device. And exception will be raised if this property is set to true and device does not support this feature. See for more information. *) property OutOfOrder: boolean read FCommandQueueOutOfOrder write SetCommandQueueOutOfOrder; (* If set to True, the Intel Open CL driver will execute all kernels within the callers thread. This feature was introduced first with Intel Open CL v1.5. If True, the calls to clEnqueue* will be blocking calls and the kernels will execute within the callers thread reducing the call overhead by a large margin. The ImmediateExecution should typically be paired with OutOfOrder set to True to allow multiple threads calling kernels without blocking each other. *) property ImmediateExecution: boolean read FImmediateExecution write SetImmediateExecution; (* Set this property to true, to enable command queue profiling. *) property Profiling: boolean read FCommandQueueProfiling write SetCommandQueueProfiling; (* Calling this method will block the calling thread until all Kernels (Open CL functions) submitted for execution to this queue have finished. *) procedure Finish; (* Associates the thread from which this method was called with the command queue. *) procedure MarkThread; (* Disssociates the command queue from any threads. *) procedure UnmarkThread; (* Returns true if, the command queue is associated with the thread with ThreadID. *) function IsMarkedThread(ThreadID: TThreadID): boolean; (* Users critical section Enter point. Provides access to ready to use critical section to control access to this object. *) procedure Enter; (* Users critical section TryEnter point. Provides access to ready to use critical section to control access to this object. *) function TryEnter: boolean; (* Users critical section Leave point. Provides access to ready to use critical section to control access to this object. *) procedure Leave; constructor Create(const aDevice: TOpenCLDevice); virtual; destructor Destroy; override; end; (* Stores a list of Open CL queues. *) TOpenCLCommandQueueList = class strict private fDevice: TOpenCLDevice; aList: TObjectsList; function GetItem(i: integer): TOpenCLCommandQueue; procedure SetItem(i: integer; const Value: TOpenCLCommandQueue); function GetCount: integer; public (*Array property gives access to command queues available for the device. *) property Item[i: integer]: TOpenCLCommandQueue read GetItem write SetItem; default; (*Returns the number of command queues already added.*) property Count: integer read GetCount; (*Add a new command queue.*) function Add: TOpenCLCommandQueue; (*Deletes and frees the command queue at index specified from the list.*) procedure Delete(ItemIdx: integer); (*Unmarks associated threads from all command queues.*) procedure UnMarkThreads; (*Searches for and returns the command queue which is associated with thread which has identified with aThreadID. The function will raise an exception, if the queue cannot be found. *) function Locate(aThreadID: TThreadID): TOpenCLCommandQueue; constructor Create(const aDevice: TOpenCLDevice); virtual; destructor Destroy; override; end; TOpenCLMtxVec = class; TOpenCLBase = class private IsUsed: boolean; BlockId: integer; strict protected fLength: integer; FCaption: string; FTag: PointerInteger; FDevice: TOpenCLDevice; fAllowSubRange: boolean; SLength: integer; SComplex: boolean; SBlockID: integer; fDebuggerMarker: integer; FFloatPrecision: TCLFloatPrecision; procedure SetCaption(const Value: string); procedure SetTag(const Value: PointerInteger); procedure FreeToCache; virtual; function ElemSize: Int64; virtual; function GetCaption: string; function GetLength: integer; function GetTag: PointerInteger; function GetCommandQueue: TOpenCLCommandQueue; procedure SetFloatPrecision(const Value: TCLFloatPrecision); function PrecisionKernel(const KernelName: string): string; function GetComplex: boolean; function GetFloatPrecision: TCLFloatPrecision; function Copy(const Vec: TOpenCLBase; VecIndex, Index, Len: integer): TOpenCLBase; overload; function Mul(const Vec: TOpenCLBase; const Value: double; VecIndex, Index, Len: integer): TOpenCLBase; overload; function Mul(const Vec: TOpenCLBase; const Value: TCplx; VecIndex, Index, Len: integer): TOpenCLBase; overload; function Mul(const Vec: TOpenCLBase; VecIndex, Index, Len: integer): TOpenCLBase; overload; function Mul(const Vec1, Vec2: TOpenCLBase; Vec1Index, Vec2Index, Index, Len: integer): TOpenCLBase; overload; function Add(const Vec: TOpenCLBase; const Value: double; VecIndex, Index, Len: integer): TOpenCLBase; overload; function Add(const Vec: TOpenCLBase; const Value: TCplx; VecIndex, Index, Len: integer): TOpenCLBase; overload; function Abs(const X: TOpenCLBase; XIndex, Index, Len: integer): TOpenCLBase; overload; function Add(const Vec1, Vec2: TOpenCLBase; Vec1Index, Vec2Index, Index, Len: integer): TOpenCLBase; overload; function MulI(const X: TOpenCLBase; XIndex, Index, Len: integer): TOpenCLBase; overload; function ConjMul(const Vec1, Vec2: TOpenCLBase; Vec1Index, Vec2Index, Index, Len: integer): TOpenCLBase; overload; function Divide(const Num, Den: TOpenCLBase; NumIndex, DenIndex, Index, Len: integer): TOpenCLBase; overload; function DivideBy(const Value: double; const Vec: TOpenCLBase; VecIndex, Index, Len: integer): TOpenCLBase; overload; function DivideBy(const Value: TCplx; const Vec: TOpenCLBase; VecIndex, Index, Len: integer): TOpenCLBase; overload; function Sin(const X: TOpenCLBase; XIndex, Index, Len: integer): TOpenCLBase; overload; function Cos(const X: TOpenCLBase; XIndex, Index, Len: integer): TOpenCLBase; overload; function Tan(const X: TOpenCLBase; XIndex, Index, Len: integer): TOpenCLBase; overload; function Cot(const X: TOpenCLBase; XIndex, Index, Len: integer): TOpenCLBase; overload; function Sec(const X: TOpenCLBase; XIndex, Index, Len: integer): TOpenCLBase; overload; function Csc(const X: TOpenCLBase; XIndex, Index, Len: integer): TOpenCLBase; overload; function ArcSin(const X: TOpenCLBase; XIndex, Index, Len: integer): TOpenCLBase; overload; function ArcCos(const X: TOpenCLBase; XIndex, Index, Len: integer): TOpenCLBase; overload; function ArcTan2(const Y, X: TOpenCLBase; YIndex, XIndex, Index, Len: integer): TOpenCLBase; overload; function ArcTan(const X: TOpenCLBase; XIndex, Index, Len: integer): TOpenCLBase; overload; function ArcCot(const X: TOpenCLBase; XIndex, Index, Len: integer): TOpenCLBase; overload; function ArcSec(const X: TOpenCLBase; XIndex, Index, Len: integer): TOpenCLBase; overload; function ArcCsc(const X: TOpenCLBase; XIndex, Index, Len: integer): TOpenCLBase; overload; function Sinh(const X: TOpenCLBase; XIndex, Index, Len: integer): TOpenCLBase; overload; function Cosh(const X: TOpenCLBase; XIndex, Index, Len: integer): TOpenCLBase; overload; function Tanh(const X: TOpenCLBase; XIndex, Index, Len: integer): TOpenCLBase; overload; function Coth(const X: TOpenCLBase; XIndex, Index, Len: integer): TOpenCLBase; overload; function Sech(const X: TOpenCLBase; XIndex, Index, Len: integer): TOpenCLBase; overload; function Csch(const X: TOpenCLBase; XIndex, Index, Len: integer): TOpenCLBase; overload; function ArcSinh(const X: TOpenCLBase; XIndex, Index, Len: integer): TOpenCLBase; overload; function ArcCosh(const X: TOpenCLBase; XIndex, Index, Len: integer): TOpenCLBase; overload; function ArcTanh(const X: TOpenCLBase; XIndex, Index, Len: integer): TOpenCLBase; overload; function ArcCoth(const X: TOpenCLBase; XIndex, Index, Len: integer): TOpenCLBase; overload; function ArcSech(const X: TOpenCLBase; XIndex, Index, Len: integer): TOpenCLBase; overload; function ArcCsch(const X: TOpenCLBase; XIndex, Index, Len: integer): TOpenCLBase; overload; procedure CplxToReal(const ReVec, ImVec: TOpenCLBase; ReIndex, ImIndex, Index, Len: integer); overload; function RealToCplx(const ReVec, ImVec: TOpenCLBase; ReIndex, ImIndex, Index, Len: integer): TOpenCLBase; overload; function PolarToCart(const AmpltVec, PhaseVec: TOpenCLBase; aIndex, PIndex, Index, Len: integer): TOpenCLBase; overload; procedure CartToPolar(const AmpltVec, PhaseVec: TOpenCLBase; AmpltIndex, PhaseIndex, Index, Len: integer); overload; function RealPart(const Vec: TOpenCLBase; VecIndex, Index, Len: integer): TOpenCLBase; overload; function Exp(const X: TOpenCLBase; XIndex, Index, Len: integer): TOpenCLBase; overload; function Exp10(const X: TOpenCLBase; XIndex, Index, Len: integer): TOpenCLBase; overload; function Exp2(const X: TOpenCLBase; XIndex, Index, Len: integer): TOpenCLBase; overload; function ImagPart(const Vec: TOpenCLBase; VecIndex, Index, Len: integer): TOpenCLBase; overload; function IntPower(const aBase: TOpenCLBase; Exponent: Integer): TOpenCLBase; overload; function Inv(const X: TOpenCLBase; XIndex, Index, Len: integer): TOpenCLBase; overload; function InvCbrt(const X: TOpenCLBase; XIndex, Index, Len: integer): TOpenCLBase; overload; function Ln(const X: TOpenCLBase; XIndex, Index, Len: integer): TOpenCLBase; overload; function Log10(const X: TOpenCLBase; XIndex, Index, Len: integer): TOpenCLBase; overload; function Log2(const X: TOpenCLBase; XIndex, Index, Len: integer): TOpenCLBase; overload; function Cbrt(const X: TOpenCLBase; XIndex, Index, Len: integer): TOpenCLBase; overload; function Ceil(const Src: TOpenCLBase; SrcIndex, Index, Len: integer): TOpenCLBase; overload; function InvSqrt(const X: TOpenCLBase; XIndex, Index, Len: integer): TOpenCLBase; overload; function Sqr(const X: TOpenCLBase; XIndex, Index, Len: integer): TOpenCLBase; overload; function Sqrt(const X: TOpenCLBase; XIndex, Index, Len: integer): TOpenCLBase; overload; function Sub(const Vec: TOpenCLBase; VecIndex, Index, Len: integer): TOpenCLBase; overload; function Sub(const Vec1, Vec2: TOpenCLBase; Vec1Index, Vec2Index, Index, Len: integer): TOpenCLBase; overload; function SubFrom(const Value: double; const Vec: TOpenCLBase; VecIndex, Index, Len: integer): TOpenCLBase; overload; function SubFrom(const Value: TCplx; const Vec: TOpenCLBase; VecIndex, Index, Len: integer): TOpenCLBase; overload; function Conj(const Vec: TOpenCLBase; VecIndex, Index, Len: integer): TOpenCLBase; overload; function FixAngle(const Src: TOpenCLBase; SrcIndex, Index, Len: integer): TOpenCLBase; overload; function Floor(const Src: TOpenCLBase; SrcIndex, Index, Len: integer): TOpenCLBase; overload; function Expj(const Omega: TOpenCLBase; OmegaIndex, Index, Len: integer): TOpenCLBase; overload; function Frac(const X: TOpenCLBase; XIndex, Index, Len: integer): TOpenCLBase; overload; function Erf(const Src: TOpenCLBase; SrcIndex, Index, Len: integer): TOpenCLBase; overload; function Erfc(const Src: TOpenCLBase; SrcIndex, Index, Len: integer): TOpenCLBase; overload; function Flip(const X: TOpenCLBase; XIndex, Index, Len: integer): TOpenCLBase; overload; function FlipConj(const X: TOpenCLBase; XIndex, Index, Len: integer): TOpenCLBase; overload; function Rem(const X, Y: TOpenCLBase; XIndex, YIndex, Index, Len: integer): TOpenCLBase; overload; function Rem(const X: TOpenCLBase; const Y: double; XIndex, Index, Len: integer): TOpenCLBase; overload; function LogN(const N: double; const X: TOpenCLBase; XIndex, Index, Len: integer): TOpenCLBase; overload; function Power(const Base: double; const Exponent: TOpenCLBase): TOpenCLBase; overload; function Power(const Base: TCplx; const Exponent: TOpenCLBase): TOpenCLBase; overload; function Power(const Base: TOpenCLBase; const Exponent: double): TOpenCLBase; overload; function Power(const Base: TOpenCLBase; const Exponent: TCplx): TOpenCLBase; overload; function PowerVec(const Base, Exponent: TOpenCLBase): TOpenCLBase; overload; function Round(const Src: TOpenCLBase; SrcIndex, Index, Len: integer): TOpenCLBase; overload; function Trunc(const Src: TOpenCLBase; SrcIndex, Index, Len: integer): TOpenCLBase; overload; function SetVal(const Value: TCplx; Index, Len: integer): TOpenCLBase; overload; function SetVal(const Value: double; Index, Len: integer): TOpenCLBase; overload; function ExtendToComplex(const Src: TOpenCLBase; Zeros: Boolean; SrcIndex, DstIndex, Len: integer): TOpenCLBase; overload; function Sgn(const Src: TOpenCLBase; SrcIndex, Index, Len: integer): TOpenCLBase; overload; procedure SinCos(const SinX, CosX: TOpenCLBase; SinXIndex, CosXIndex, Index, Len: integer); overload; procedure SinhCosh(const SinhX, CoshX: TOpenCLBase; SinhIndex, CoshIndex, Index, Len: integer); overload; function ThreshBottom(const Vec: TOpenCLBase; const Value: double; VecIndex, Index, Len: integer): TOpenCLBase; overload; function ThreshTop(const Vec: TOpenCLBase; const Value: double; VecIndex, Index, Len: integer): TOpenCLBase; overload; function ThresholdLT(const Vec: TOpenCLBase; const LTLevel, LTValue: double; VecIndex, Index, Len: integer): TOpenCLBase; overload; function ThresholdLT(const Vec: TOpenCLBase; const LTLevel: double; const LTValue: TCplx; VecIndex, Index, Len: integer): TOpenCLBase; overload; function ThresholdGT(const Vec: TOpenCLBase; const GTLevel, GTValue: double; VecIndex, Index, Len: integer): TOpenCLBase; overload; function ThresholdGT(const Vec: TOpenCLBase; const GTLevel: double; const GTValue: TCplx; VecIndex, Index, Len: integer): TOpenCLBase; overload; function ThresholdGT_LT(const Vec: TOpenCLBase; const GTLevel, GTValue, LTLevel, LTValue: double; VecIndex, Index, Len: integer): TOpenCLBase; overload; procedure TruncAndFrac(const TruncDst, FracDst: TOpenCLBase; TruncIdx, FracIdx, Index, Len: integer); overload; function SgnMul(const Src: TOpenCLBase): TOpenCLBase; overload; public procedure CopyToArray(var Dst: TCplxArray; Index, Len: integer); overload; procedure CopyToArray(var Dst: TSCplxArray; Index, Len: integer); overload; procedure CopyToArray(var Dst: TDoubleArray; Index, Len: integer); overload; procedure CopyToArray(var Dst: TSingleArray; Index, Len: integer); overload; (*Copies array content. Copies Len elements from the Src array and stores them in the calling object starting at location Index. The value of the Complex property and size of the calling objects are not modified. *) procedure CopyFromArray(const Src: TDoubleArray; Index, Len: integer); overload; (*Copies array content. Copies Len elements from the Src array and stores them in the calling object starting at location Index. The value of the Complex property and size of the calling objects are not modified. *) procedure CopyFromArray(const Src: TCplxArray; Index, Len: integer); overload; procedure SizeToArray(var Dst: TSCplxArray; Len: integer); overload; (*Sets the size of the array to match the size of the object. SizeToArray considers both Complex and Length properties when setting the size of the array. *) procedure SizeToArray(var Dst: TSingleArray); overload; (*Sets the size of the array to match the size of the object. SizeToArray considers both Complex and Length properties when setting the size of the array. *) procedure SizeToArray(var Dst: TDoubleArray); overload; (*Sets the size of the array to match the size of the object. SizeToArray considers both Complex and Length properties when setting the size of the array. *) procedure SizeToArray(var Dst: TCplxArray); overload; (*Sets the size of the array to match the size of the object. SizeToArray considers both Complex and Length properties when setting the size of the array. *) procedure SizeToArray(var Dst: TIntegerArray); overload; (*Sets the size of the array considering the value of the Complex property. SizeToArray considers the value of the Complex property and of the Len parameter when setting the size of the array. *) procedure SizeToArray(var Dst: TIntegerArray; Len: integer); overload; (*Sets the size of the array considering the value of the Complex property. SizeToArray considers the value of the Complex property and of the Len parameter when setting the size of the array. *) procedure SizeToArray(var Dst: TSingleArray; Len: integer); overload; (*Sets the size of the array considering the value of the Complex property. SizeToArray considers the value of the Complex property and of the Len parameter when setting the size of the array. *) procedure SizeToArray(var Dst: TDoubleArray; Len: integer); overload; (*Sets the size of the array considering the value of the Complex property. SizeToArray considers the value of the Complex property and of the Len parameter when setting the size of the array. *) procedure SizeToArray(var Dst: TCplxArray; Len: integer); overload; strict protected fIsSubRange: boolean; fComplex: boolean; fMemBuffer: pcl_mem; procedure SetLength(const Value: integer); overload; virtual; procedure DebugCheck; procedure InitData; virtual; function GetRealValues: string; virtual; function GetComplexValues: string; virtual; procedure ValidateParams2(const X: TOpenCLBase; const XIndex, Index: integer; var Len: integer); overload; procedure ValidateParams(const X1, X2: TOpenCLBase; const xIndex1, xIndex2, Index: integer; var Len: integer); overload; procedure ValidateParams(const X: TOpenCLBase; const XIndex, Index: integer; var Len: integer); overload; procedure ValidateParamsPR(const X1, X2: TOpenCLBase; const xIndex1, xIndex2, Index: integer; var Len: integer); overload; procedure EnqueueKernel(const KernelName: string; Value: double; Index, Len: integer); overload; procedure EnqueueKernel(const KernelName: string; const Value: TCplx; Index, Len: integer); overload; procedure EnqueueKernel(const KernelName: string; Index, Len: integer); overload; procedure EnqueueKernel(const KernelName: string; const Vec: TOpenCLBase; Value: double; VecIndex, Index, Len: integer); overload; procedure EnqueueKernel(const KernelName: string; const Vec: TOpenCLBase; const Value: TCplx; VecIndex, Index, Len: integer); overload; procedure EnqueueKernel(const KernelName: string; const Vec: TOpenCLBase; Value, VecIndex, Index, Len: integer); overload; procedure EnqueueKernel(const KernelName: string; const Vec1, Vec2: TOpenCLBase; Vec1Index, Vec2Index, Index, Len: integer); overload; procedure EnqueueKernel(const KernelName: string; const Vec: TOpenCLBase; VecIndex, Index, Len: integer); overload; procedure EnqueueKernel(const KernelName: string; Value, Index, Len: integer); overload; procedure EnqueueKernel(const KernelName: string; const Vec: TOpenCLBase; Value1, Value2: double; VecIndex, Index, Len: integer); overload; procedure EnqueueKernel(const KernelName: string; Value1, Value2: double; Index, Len: integer); overload; procedure EnqueueUpSampleKernel(const KernelName: string; const Vec: TOpenCLBase; VecIndex, Index, Len: integer; Factor, Phase: integer); overload; procedure SetArg(const aKernel: TOpenCLKernel; argIndex: integer; const Vec: TOpenCLBase; VecIndex: integer); overload; procedure MemRealloc(aLength: integer; aPrecision: TclFloatPrecision; aComplex: boolean); overload; procedure EnqueueKernel(const KernelName: string; Value1: double; const Value2: TCplx; Index, Len: integer); overload; procedure EnqueueKernel(const KernelName: string; const Vec: TOpenCLBase; Value1: double; const Value2: TCplx; VecIndex, Index, Len: integer); overload; procedure EnqueueKernel(const KernelName: string; const Vec: TOpenCLBase; Value1, Value2, Value3, Value4: double; VecIndex, Index, Len: integer); overload; procedure EnqueueKernel(const KernelName: string; Value1, Value2, Value3, Value4: double; Index, Len: integer); overload; procedure EnqueueKernel(const KernelName: string; const Vec: TOpenCLBase; const Value1, Value2: TCplx; VecIndex, Index, Len: integer); overload; procedure EnqueueKernel(const KernelName: string; const Vec: TOpenCLBase; const Value1: TCplx; Value2: double; VecIndex, Index, Len: integer); overload; procedure EnqueueKernel(const KernelName: string; Value: double; const Vec: TOpenCLBase; VecIndex, Index, Len: integer); overload; procedure EnqueueKernel(const KernelName: string; const Value: TCplx; const Vec: TOpenCLBase; VecIndex, Index, Len: integer); overload; procedure EnqueueKernel(const KernelName: string; const Value1, Value2: TCplx; Index, Len: integer); overload; procedure InternalCopyTo(Dst: TDenseMtxVec);overload; virtual; procedure InternalCopyTo(Dst: TMtxVecInt);overload; virtual; function GetSData: PCL_mem; virtual; procedure SetComplex(const Value: boolean); procedure DoSetComplex(Value: boolean); virtual; protected fData: TDenseMtxVec; protected fCacheIndex: integer; FDataOffset: integer; function DebugUpdate: integer; virtual; public procedure Size(aLength: integer; aPrecision: TclFloatPrecision; aComplex: boolean); overload; virtual; procedure Reset; virtual; property RealValues: string read GetRealValues; property ComplexValues: string read GetComplexValues; function LocateCommandQueue: TOpenCLCommandQueue; (*Set this property to indicate that object data values are to be treated complex. Read this property to determine, if the object stores real or complex data. *) property Complex: boolean read GetComplex write SetComplex; (*Returns the queue on the Device on which we will run functions using this object. *) property CmdQueue: TOpenCLCommandQueue read GetCommandQueue; (*Returns the device on which we allocated memory for this object. *) property Device: TOpenCLDevice read FDevice; (*Allows storing optional information. *) property Tag: PointerInteger read GetTag write SetTag; (*Stores optional label. *) property Caption: string read GetCaption write SetCaption; (* Defines the length in number of elements (single or double precision) of the memory allocated. *) property Length: integer read GetLength write SetLength; (*The calling thread will block until the command queue using this object has finished. *) procedure Finish; (*Sets the calling object to match the size of the Src object. *) procedure Size(const Src: TOpenCLBase); overload; virtual; (*Sets the calling object to match the size of the Src object, and changes Complex to aComplex if needed. *) function Size(const Src: TOpenCLBase; aComplex: boolean): TOpenCLBase; overload; virtual; property FloatPrecision: TCLFloatPrecision read GetFloatPrecision write SetFloatPrecision; (*Returns the index offest in to the buffer. Returns the index offset in to the buffer at which real values for the this object start. *) function SDataIndex(aIndex: integer): PointerInteger; virtual; (*Returns the index offest in to the buffer. Returns the index offset in to the buffer at which complex values for the this object start. *) function CDataIndex(aIndex: integer): PointerInteger; virtual; procedure CopyTo(Dst: TVec); overload; procedure CopyTo(Dst: TVecInt); overload; (*Returns Open CL buffer reference. Returns the real Open CL buffer used by the object. Multiple objects may be using the same buffer. *) property SData: PCL_mem read GetSData; (*Returns Open CL buffer reference. Returns complex Open CL buffer used by the object. Multiple objects may be using the same buffer. *) property CData: PCL_mem read GetSData; procedure ValidateParams(const Index: integer; var Len: integer); overload; constructor Create(aDevice: TOpenCLDevice); virtual; destructor Destroy; override; end; TOpenCLMtxVec = class(TOpenCLBase) strict protected function GetNumGroups(Len: integer): integer; procedure ValidateRealIndexLen(const Index, RealSrcLen: integer); overload; procedure ValidateCplxArrayIndexes(const SrcIndex, SrcLen, Index: integer; var Len: integer); overload; procedure ValidateRealArrayIndexes(const SrcIndex, SrcLen, Index: integer; var Len: integer); overload; procedure SetLength(const Value: integer); overload; override; procedure InternalEnqueuePRKernel(const aKernel: TOpenCLKernel; const aCmdQueue: TOpenCLCommandQueue; GroupBufferLength: integer); overload; procedure EnqueuePRKernel(const KernelName: string; const Vec: TOpenCLMtxVec; VecIndex, Index, Len: integer; const GroupBuffer: TOpenCLMtxVec); overload; procedure EnqueuePRKernel(const KernelName: string; const Vec: TOpenCLMtxVec; ConjVec: boolean; VecIndex, Index, Len: integer; const GroupBuffer: TOpenCLMtxVec); overload; procedure EnqueuePRKernel2(const KernelName: string; const Vec: TOpenCLMtxVec; VecIndex, Index, Len: integer; const GroupBuffer: TOpenCLMtxVec); overload; procedure EnqueuePRKernel2(const KernelName: string; Index, Len: integer; const GroupBuffer0, GroupBuffer1: TOpenCLMtxVec); overload; procedure EnqueuePRKernel2(const KernelName: string; Index, Len: integer; const GroupBuffer: TOpenCLMtxVec); overload; procedure EnqueuePRKernel3(const KernelName: string; Index, Len: integer; const GroupBuffer0, GroupBuffer1: TOpenCLMtxVec); overload; procedure EnqueuePRKernel3(const KernelName: string; Index, Len: integer; const GroupBuffer: TOpenCLMtxVec); overload; procedure EnqueuePRKernel(const KernelName: string; Index, Len: integer; const GroupBuffer: TOpenCLMtxVec); overload; procedure EnqueuePRKernel(const KernelName: string; Index, Len: integer; const GroupBuffer0, GroupBuffer1: TOpenCLMtxVec); overload; procedure EnqueuePRKernel(const KernelName: string; const Vec1, Vec2: TOpenCLMtxVec; Vec1Index, Vec2Index, Index, Len: integer; const GroupBuffer: TOpenCLMtxVec); overload; procedure EnqueuePRKernel(const KernelName: string; const Vec1, Vec2: TOpenCLMtxVec; Vec1Index, Vec2Index, Len: integer; const GroupBuffer: TOpenCLMtxVec); overload; procedure EnqueueReverseKernel(KernelName: string; Index, Len: integer); overload; procedure EnqueueGroupKernel(const KernelName: string); overload; public constructor Create(aDevice: TOpenCLDevice); override; procedure Size(aLength: integer; aPrecision: TclFloatPrecision; aComplex: boolean); overload; override; (*Automatically set to true after the SetSubIndex or SetSubRange call. This property is set to true after the or call. If IsSubRange is true then the TOpenCLMtxVec method/function will be performed on subrange of values. Use to set IsSubRange back to False and thus reset sub range to full vector length. *) property IsSubRange: boolean read fIsSubRange; (*Resets any defined subrange. *) procedure SetFullRange; virtual; (*Defines a sub vector/matrix. The method will define a subarray starting at Index and ending at Index+Len-1. No copying will occur, only pointers will be shifted or indices adjusted. All values of the original will be preserved. An exception will be raised if an attempt is made to change the size of calling object. A sub-vector/matrix is vector/matrix which does not neccessarily have its own memory allocated. Instead it adopts the memory of the source object and all operations done on the either of the objects affect the same elements. The use of subvectors/submatrices increases CPU cache reuse, lower's memory requirements, increases application performance and improves code readability. To again obtain a view of the full vector/matrix, see *) procedure SetSubRange(Index: integer; Len: integer); overload; virtual; (*Prevents calls to . Prevents calls to method. This can be usefull guard when an object is already working on a subrange and the user would like to further subrange an already subranged object. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TOpenCLVector a,b; clMtxVec.CreateIt(out a, out b); try { a.SetIt(false, new double[] {1,2,3,4,5,6,7,8,9}); a.SetSubRange(0,2); //a = [1,2] a.DisableSubrange(); a.SetSubRange(2,2); //exception raised here b.SetSubRange(a,2,2); //but this will work a.SetFullRange(); //b is not changed, it still points to [4,5] } finally { MtxVec.FreeIt(ref a, ref b); } } } *) procedure DisableSubrange; (*Enables calls to . Enables calls to by removing the block set by . *) procedure EnableSubrange; (*Prevents calls to . Prevents calls to method. This can be usefull guard when an object is already working on a subrange and the user would like to further subrange an already subranged object. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TOpenCLVector a,b; MtxVec.CreateIt(out a, out b); try { a.SetIt(false, new double[] {1,2,3,4,5,6,7,8,9}); a.Select(0,2); //a = [1,2] a.DisableSelect(); a.Select(2,2); //exception raised here b.Select(a,2,2); //but this will work a.SelectAll(); //b is not changed, it still points to [4,5] } finally { MtxVec.FreeIt(ref a, ref b); } } } *) procedure DisableSelect; (*Enables calls to . Enables calls to by removing the block set by . *) procedure EnableSelect; (*Resets any defined selection. *) procedure SelectAll; overload; (*Selects a set of elements from the vector. The method will define a subarray starting at Index and ending at Index+Len-1. No copying will occur, only pointers will be shifted. All values of the original will be preserved. An exception will be raised if an attempt is made to change the size of the calling object after a selection has been made. A selection will behave exactly as if the object always contained only the selected values. When a selection is made from another object the source object and all operations done on either of the two objects will affect the same elements. The use of selections increases CPU cache reuse, lower's memory requirements, increases application performance and improves code readability. To again obtain a view of the full vector/matrix use the method. When selecting elements from other objects, care must be given not to use the selections after the source object has been freed: var a,b: TOpenCLVector; begin CreateIt(a,b); try a.SetIt(False,[1,2,3,4]); b.Select(a,2,2); FreeIt(a); //free the source object b.Values[0] := b.Valuess[1]; //b does not point to valid memory anymore finally FreeIt(a); end; end; *) procedure Select(Index: integer; Len: integer); overload; (*Resets the selection. This method is the same as the method. *) procedure Select; overload; (*Sets the subarray size to full size. This method is the same as the method. *) procedure SetSubRange; overload; (*Defines a subarray. The method will define a sub array starting at BeginIndex and ending at EndIndex (inclusive). All values of the original vector/matrix will be preserved. An exception will be raised if an attempt is made to change the size of calling vector/matrix. A subarray is array which does not have its own memory allocated. Instead it adopts the memory of the source object and all operations done on the either of the objects affect the same elements. The use of subarrays increases CPU cache reuse, lower's memory requirements, increases application performance and improves code readability. To again obtain a view of the full vector see *) procedure SetSubIndex(BeginIndex, EndIndex: integer); overload; (*Copies array content. Copies Len elements from the Src array and stores them in the calling object starting at location Index. The value of the Complex property and size of the calling objects are not modified. *) procedure CopyFromArray(const Src: TSingleArray; Index, Len: integer); overload; (*Copies array content. Sets the size of the object to match the size of the Src array and copies the contents in to the calling object. *) procedure CopyFromArray(const Src: TSingleArray); overload; (*Copies array content. Sets the size of the object to match the size of the Src array and copies the contents in to the calling object. *) procedure CopyFromArray(const Src: TDoubleArray); overload; (*Copies array content. Sets the size of the object to match the size of the Src array and copies the contents in to the calling object. *) procedure CopyFromArray(const Src: TCplxArray); overload; (*Copies array content. Copies Len complex elements from the Src array and stores them in the complex calling object starting at location Index. The value of the Complex property and size of the calling objects are not modified. *) function CopyCplxFromArray(const Src: TSingleArray; Index, Len: integer): TOpenCLMtxVec; overload; (*Copies array content. Sets the size of the object to match the size of the Src array and copies the contents in to the calling object. The complex property is set to True. *) function CopyCplxFromArray(const Src: TSingleArray): TOpenCLMtxVec; overload; (*Copies array content. Copies Len complex elements from the Src array and stores them in the complex calling object starting at location Index. The value of the Complex property and size of the calling objects are not modified. *) function CopyCplxFromArray(const Src: TDoubleArray; Index, Len: integer): TOpenCLMtxVec; overload; (*Copies array content. Sets the size of the object to match the size of the Src array and copies the contents in to the calling object. The complex property is set to True. *) function CopyCplxFromArray(const Src: TDoubleArray): TOpenCLMtxVec; overload; (*Copies calling object data to array. Copies Length elements from the calling object to Dst array. The size of the Dst array is set to Length or Length*2, if the Complex is true. *) procedure CopyToArray(var Dst: TSingleArray); overload; (*Copies calling object data to array. Copies Length elements from the calling object to Dst array. The size of the Dst array is set to Length or Length*2, if the Complex is true. *) procedure CopyToArray(var Dst: TDoubleArray); overload; (*Copies calling object data to array. Copies Length elements from the calling object to Dst array. The size of the Dst array is set to Length or Length/2, if the Complex is false. *) procedure CopyToArray(var Dst: TCplxArray); overload; (*Copies calling object data to array. Copies Length elements from the calling object to Dst array. The size of the Dst array is set to Length or Length*2, if the Complex is true. *) procedure CopyToArray(var Dst: TIntegerArray); overload; (*Copies calling object data to array. Copies Len elements from the calling object starting at Index to Dst array. The size of the Dst array is set to Len or Len*2, if the Complex is true. *) procedure CopyToArray(var Dst: TIntegerArray; Index, Len: integer); overload; procedure Copy(const Src: TDenseMtxVec); overload; virtual; procedure Copy(const Src: TMtxVecInt); overload; virtual; (*Copy object values. Copy each of Vec elements to the calling object. Size and Complex properties of the calling object are set implicitly to match Vec object. var a,b: TOpenCLVector; begin a.CopyCplxFromArray(TSingleArray.Create(1,2,3,4)); // a = [1+2i,3+4i] b.Copy(a); // b = [1,2,3,4] end; *) function Copy(const Src: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Copy Vec elements [VecIndex]..[VecIndex+Len-1] in the calling object elements [Index]..[Index+Len-1]. Size and Complex properties must be set explicitly. An exception is raised if array borders are overrun or underrun. *) function Copy(const Vec: TOpenCLMtxVec; VecIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Add each of Vec2 elements to corresponding elements in Vec1. The results are stored in the calling object. Size and Complex properties of the calling object are set implicitly to match Vec1 and Vec2 vectors. *) function Add(const Src1, Src2: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Add Vec1 elements [Vec1Index]..[Vec1Index+Len-1] to Vec2 elements [Vec2Index]..[Vec2Index+Len-1]. Store the results in calling object elements [Index]..[Index+Len-1]. An exception is raised array borders are overrun. *) function Add(const Vec1, Vec2: TOpenCLMtxVec; Vec1Index, Vec2Index, Index, Len: integer): TOpenCLMtxVec; overload; (*Adds Value to object elements. *) function Add(const Value: double): TOpenCLMtxVec; overload; (*Adds complex Value to all calling object complex elements.*) function Add(const Value: TCplx): TOpenCLMtxVec; overload; (*Adds Value to calling object elements [Index]..[Index+Len-1]. An exception is raised if array borders are overrun. *) function Add(const Value: double; Index, Len: integer): TOpenCLMtxVec; overload; (*Adds complex Value to calling object complex elements [Index]..[Index+Len-1]. An exception is raised if array borders are overrun. *) function Add(const Value: TCplx; Index, Len: integer): TOpenCLMtxVec; overload; (*Adds Value to the each element of the Vec object. Stores the result in the calling object. Size and Complex properties of the calling object are set automatically. *) function Add(const Vec: TOpenCLMtxVec; const Value: double): TOpenCLMtxVec; overload; (*Adds complex Value to each element of the Vec object. Store the result to the calling object. Size property of the calling object is set automatically. Complex property of the calling object is set to True. *) function Add(const Vec: TOpenCLMtxVec; const Value: TCplx): TOpenCLMtxVec; overload; (*Adds Value to each element of Vec object in range [VecIndex]..[VecIndex+Len-1]. Stores result to elements [Index]..[Index+Len-1] of the calling object. Size of the calling object is not changed. An exception is raised if array borders are overrun. Complex property of the calling object is set implicitly. *) function Add(const Vec: TOpenCLMtxVec; const Value: double; VecIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Adds complex Value to each elements of the Vec object in range [VecIndex]..[VecIndex+Len-1]. Stores the result to elements [Index]..[Index+Len-1] of the calling object. Size of the calling object is not changed. An exception is raised if array borders are overrun. Complex property of the calling object is set to True. *) function Add(const Vec: TOpenCLMtxVec; const Value: TCplx; VecIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Array addition. Add each of Vec elements to corresponding elements in the calling object. *) function Add(const Vec: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Add Vec elements [VecIndex]..[VecIndex+Len-1] to calling object elements [Index]..[Index+Len-1]. An exception is raised array borders are overrun. *) function Add(const Vec: TOpenCLMtxVec; VecIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Split complex calling object in real and imaginary part. Split calling object into real and imaginary components. Store all real components in ReVec and all imaginary components in ImVec. Size and Complex properties of ReVec and ImVec are set implicitly to match with the calling vector. An execption is raised if calling object is not complex. var a,b,c: clVector; begin a.CopyCplxFromArray(TSingleArray.Create(1,-2,3,4)); // a= [1-2i, 3+4i] a.CplxToReal(b,c); // b = [1, 3], c = [-2, 4] end; *) procedure CplxToReal(const ReVec, ImVec: TOpenCLMtxVec); overload; (*Split calling object elements [Index]..[Index+Len-1] into real and imaginary components. Store real components in ReVec elements [ReIndex]..[ReIndex+Len-1] and imaginary components in ImVec elements [ImIndex]..[ImIndex+Len-1]. Size and Complex properties must be set explicitly. An exception is raised if array borders are overrun or underrun. *) procedure CplxToReal(const ReVec, ImVec: TOpenCLMtxVec; ReIndex, ImIndex, Index, Len: integer); overload; (*Constructs a complex object from two real objects. Construct a complex object from the ReVec (real part) and the ImVec (imaginary part) objects. The results are stored in the calling object. Size and Complex properties of the calling object are set implicitly to match ReVec and ImVec objects. An exception is raised if ReVec or ImVec Complex property is True. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TOpenCLVector a,b,c; clMtxVec.CreateIt(out a, out b, out c); try { a.CopyCplxFromArray( new double[] {1,2, 3,4}); // 1+2i ; 3+4i b.CopyCplxFromArray( new double[] {2,2,3,4}); // 2+2i ; 3+4i c.RealToCplx(a,b); } finally { clMtxVec.FreeIt(ref a, ref b, ref c); } } } *) function RealToCplx(const ReVec, ImVec: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Construct a complex object from the ReVec elements [ReIndex]..[ReIndex+Len-1] (real part) and the ImVec elements [ImIndex]..[ImIndex+Len-1] (imaginary part). The results are stored to calling object elements [Index]..[Index+Len-1]. Size and Complex properties of the calling object must be set explicitly. An exception is raised if array borders are overrun. An exception is also raised if ReVec or ImVec Complex property is True. *) function RealToCplx(const ReVec, ImVec: TOpenCLMtxVec; ReIndex, ImIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Conjugate. Conjugate all calling object elements in-place. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TOpenCLVector a; clMtxVec.CreateIt(out a); try { a.CopyCplxFromArray( new double[] {1,-2,3,4}); a.Conj(); } finally { clMtxVec.FreeIt(ref a); } } } *) function Conj: TOpenCLMtxVec; overload; (*Conjugate calling object elements [Index]..[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function Conj(Index,Len: integer): TOpenCLMtxVec; overload; (*Conjugate each of Vec elements. Store the results in the calling object. The Size and Complex properties of the calling object are set implicitly to match Vec vector. *) function Conj(const Vec: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Conjugate Vec elements Vec[VecIndex]..Vec[VecIndex+Len-1]. Store them in the calling object elements [Index]..[Index+Len-1]. Size and Complex properties of the calling object must be set explicitly. An exception is raised if array borders are overrun. *) function Conj(const Vec: TOpenCLMtxVec; VecIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Extends a real object to a complex object. Extend the calling object to complex vector. After the calling of ExtendToComplex the imaginary part becomes the same as real part if Zeros is false. If Zeros is true the imaginary part is set to zero. The use of the in-place version of the method is discouraged because it requires 3*N copy operations, while the not-in-place version requires only 2*N copy operations. 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}); b.ExtendToComplex(a,true); } finally { clMtxVec.FreeIt(ref a, ref b); } } } *) function ExtendToComplex(Zeros: boolean = True): TOpenCLMtxVec; overload; (*Extend Vec object to complex calling object. If Zeros is true then the calling vector imaginary part is set to zero, otherwise the calling object imaginary part is the same as calling object real part. *) function ExtendToComplex(const Src: TOpenCLMtxVec; Zeros: Boolean): TOpenCLMtxVec; overload; (*Converts the source to complex. Converts the source to complex by setting the imaginary part to either zero (zeros = True) or same as real (zeros = false). Does not set size of the calling vector. If there is not sufficient space available to store the result an exception will be raised. *) function ExtendToComplex(const Src: TOpenCLMtxVec; Zeros: Boolean; SrcIndex,DstIndex, Len: integer): TOpenCLMtxVec; overload; (*Sets angle in [-2PI,2PI]. ThetaRad within -2 and interval. Calling this function prior to passing the value to trigonometric functions can significantly improve numerical accuracy. Sine/cosine appear within many other functions especially complex versions of trigonometric functions. FixAngle method is not used implicitely within TOpenCLMtxVec methods. To achieve maximum performance make sure that the arguments passed to complex trigonometric functions are "small" or scaled down. Note The vector must be real. *) function FixAngle: TOpenCLMtxVec; overload; (*FixAngle for calling object complex elements [Index]..[Index+Len-1] in-place. An exception is raised if calling object Complex property is True or if array borders are overrun/underrun. *) function FixAngle(Index,Len: integer): TOpenCLMtxVec; overload; (*Sets angle in [-2PI,2PI] for all Src elements. Stores the results in the calling object. Size and Complex properties of the calling vector are set implicitly to match the Src object. *) function FixAngle(const Src: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Sets angle in [-2PI,2PI] for Src elements [SrcIndex]..[SrcIndex+Len-1] and store the results in the calling object elements [Index]..[Index+Len-1]. Size and Complex properties of the calling object must be set explicitly. An exception is raised if array borders are overrun. *) function FixAngle(const Src: TOpenCLMtxVec; SrcIndex, Index,Len: integer): TOpenCLMtxVec; overload; (*Rounds towards negative infinity. Rounds all calling object elements towards negative infinity in-place. Floor(-2.8) = -3 Floor(2.8) = 2 Floor(-1.0) = -1 *) function Floor: TOpenCLMtxVec; overload; (*Rounds calling object elements [Index]..[Index+Len-1] towards negative infinity in-place. An exception is raised if array borders are overrun. *) function Floor(Index,Len: integer): TOpenCLMtxVec; overload; (*Rounds all Src object elements towards negative infinity and stores the result in the calling object. Size and Complex properties of the calling object are adjusted automatically. *) function Floor(const Src: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Rounds Src object elements [SrcIndex]..[SrcIndex+Len-1] towards negative infinity and stores the result in the calling object elements [Index]..[Index+Len-1]. Size and Complex properties of the calling object must be set explicitly. An exception is raised if array borders are overrun. *) function Floor(const Src: TOpenCLMtxVec; SrcIndex, Index,Len: integer): TOpenCLMtxVec; overload; (*A complex exponential e^(j*Omega)). Calculate the calling object complex exponential in-place. An exception is raised if calling object is complex. If object is complex, you should use the method instead. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TOpenCLVector a; clMtxVec.CreateIt(out a); try { a.CopyFromArray( new double[] {1,2,3,4}); a.Expj(); } finally { clMtxVec.FreeIt(ref a); } } } *) function Expj: TOpenCLMtxVec; overload; (*Calculate the e^(j*Omega), a complex exponential. Omega must be a real object. If omega is complex, then use the method. *) function Expj(const Omega: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Calculate the complex exponential for Omega elements [OmegaIndex]..[OmegaIndex+Len-1]. Store the results in calling object elemets [Index]..[Index+Len-1]. Size and Complex properties of the calling vector must be set explicitly. An exception is raised if array borders are overrun or underrun. *) function Expj(const Omega: TOpenCLMtxVec; OmegaIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Fractional part of values. Calculates the fractional part for all object values in-place. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TOpenCLVector a; clMtxVec.CreateIt(out a); try { a.CopyFromArray( new double[] {1,5.5,-1.6,6}); a.Frac(); // a = [0, 0.5, -0.6, 0] } finally { clMtxVec.FreeIt(ref a); } } } *) function Frac: TOpenCLMtxVec; overload; (*Calculates the fractional part for all X object values. Stores the result in calling object. Size and Complex properties of calling object are adjusted automatically. *) function Frac(const X: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Calculates the fractional part for calling object elements [Index]..[Index+Len-1] in-place. An exception is raised if array borders are overrun or underrun. *) function Frac(Index,Len: integer): TOpenCLMtxVec; overload; (*Calculates the fractional part for X object elements [XIndex]..[XIndex+Len-1]. Stores the result in calling object elements [Index]..[Index+Len-1]. An exception is raised if array borders are overrun or underrun. *) function Frac(const X: TOpenCLMtxVec; XIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Complementary error functon of values. Calculates the complementary error function value for all object values in-place. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TOpenCLVector a; clMtxVec.CreateIt(out a); try { a.CopyFromArray( new double[] {1,5.5,-1.6,6}); a.Erfc(); } finally { clMtxVec.FreeIt(ref a); } } } *) function Erfc: TOpenCLMtxVec; overload; (*Calculates the complementary error function value for all Src object values. Stores the result in calling object. Size and Complex properties of calling object are adjusted automatically. *) function Erfc(const Src: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Calculates the complementary error function value for calling object elements [Index]..[Index+Len-1] in-place. An exception is raised if array borders are overrun or underrun. *) function Erfc(Index,Len: integer): TOpenCLMtxVec; overload; (*Calculates the complementary error function value for Src object elements [SrcIndex]..[SrcIndex+Len-1]. Stores the result in calling object elements [Index]..[Index+Len-1]. An exception is raised if array borders are overrun or underrun. *) function Erfc(const Src: TOpenCLMtxVec; SrcIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Error functon of values. Calculates the error function for all object values in-place. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TOpenCLVector a; clMtxVec.CreateIt(out a); try { a.CopyFromArray( new double[] {1, 5.5, -1.6, 6}); a.Erf(); } finally { clMtxVec.FreeIt(ref a); } } } *) function Erf: TOpenCLMtxVec; overload; (*Calculates the error function for all Src object values. Stores the result in calling object. Size and Complex properties of calling object are adjusted automatically. *) function Erf(const Src: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Calculates the error function for calling object elements [Index]..[Index+Len-1] in-place. An exception is raised if array borders are overrun or underrun. *) function Erf(Index,Len: integer): TOpenCLMtxVec; overload; (*Calculates the error function for Src object elements [SrcIndex]..[SrcIndex+Len-1]. Stores the result in calling object elements [Index]..[Index+Len-1]. An exception is raised if array borders are overrun or underrun. *) function Erf(const Src: TOpenCLMtxVec; SrcIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Flips the real and imaginary part of complex numbers. Flipped real and imaginary part of complex numbers for all calling object elements in-place. The following transformation is used: a + i*b -> b + i*a *) function Flip: TOpenCLMtxVec; overload; (*Flips the real and imaginary part of complex numbers for calling object elements [Index]..[Index+Len-1] in-place. An exception is raised if array borders are overrun or underrun. *) function Flip(Index, Len: integer): TOpenCLMtxVec; overload; (*Flips the real and imaginary part of complex numbers for all X object elements. Xtore the results in the calling object. Size and Complex properties of calling object are adjusted automatically. *) function Flip(const X: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Flips the real and imaginary part of complex numbers for X object elements [XIndex]..[XIndex+Len-1]. Store the results in the calling object elements [Index]..[Index+Len-1]. An exception is raised if array borders are overrun or underrun. *) function Flip(const X: TOpenCLMtxVec; XIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Flips the real and imaginary part of complex numbers and conjugates the complex numbers. Performs the following transformation: a + i*bi ==> b - i*a Method flips the real and imaginary part and conjugates calling object complex elements in-place. *) function FlipConj: TOpenCLMtxVec; overload; (*Flip calling object complex elements [Index]..[Index+Len-1] in-place. An exception is raised if calling object Complex property is false or if array borders are overrun/underrun. *) function FlipConj(Index, Len: integer): TOpenCLMtxVec; overload; (*Flip all X object complex elements. Store the results in calling object. Size and Complex property of calling object are adjusted automatically. *) function FlipConj(const X: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Flip X object complex elements [XIndex]..[XIndex+Len-1]. Store the results in calling object elements [Index]..[Index+Len-1]. An exception is raised if calling object Complex property is false or if array borders are overrun/underrun. *) function FlipConj(const X: TOpenCLMtxVec; XIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*The Reminder after division X/Y. Calculates reminder after division according to formula: x[i]-y[i]*Trunc(x[i]/y[i]). The results will be saved to the calling vector. X and Y must be a real and have the same length. Size and Complex properties of the calling vector are set implicitly to match the X object. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TOpenCLVector a,b,c; clMtxVec.CreateIt(out a, out b, out c); try { a.CopyFromArray( new double[] {0,1,10,-1,-10}); // a = [0, 1, 10, -1, -10]; b.CopyFromArray(new double[],{0,1,System.Math.PI,-1,-System.Math.PI}); // b = [0, 1, PI, -1, -PI]; c.Rem(a,b); // c = [0, 0, 0.5752, 0, -0.5752] } finally { clMtxVec.FreeIt(ref a,ref b,ref c); } } } *) function Rem(const X, Y: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Calculates reminder after division X/Y. Calculation uses the following formula: z[i] = x[xi]-y[yi]*Trunc(x[xi]/y[yi]), where i in [Index..Index+Len], xi in [XIndex..XIndex+Len], yi in [YIndex..YIndex+Len]. The results will be saved to the calling vector. X must be a real. An exception will be raised if array borders are overrun. *) function Rem(const X, Y: TOpenCLMtxVec; XIndex, YIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Calculates reminder after division X/Y. Reminder is calculated by using the following formula: x[i]-y*Trunc(x[i]/y). X must be a real. The results will be saved to the calling vector. Size and Complex properties of the calling vector are set implicitly to match the X object. *) function Rem(const X: TOpenCLMtxVec; const Y: double): TOpenCLMtxVec; overload; (*Calculates reminder after division X/Y. Reminder is calculated by using the following formula: x[i]-y*Trunc(x[i]/y). X must be a real. The results will be saved to the calling vector. An exception will be raised if array borders are overrun. *) function Rem(const X: TOpenCLMtxVec; const Y: double; XIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Multiply object elements with Value. Multiply all calling object elements with Value in-place. This method is the same as the method overloads multiplying with vector elements with a scalar. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TOpenCLVector a; MtxVec.CreateIt(out a); try { a.CopyFromArray( new double[] {2,3,5}); // a = [2,3,5] a.Scale(3); // a = [6,9,15] } finally { MtxVec.FreeIt(ref a); } } } *) function Scale(const Factor: double): TOpenCLMtxVec; overload; (*Multipy calling object elements [Index]..[Index+Len-1] with Value in-place. An exception is raised if array borders are overrun or underrun. *) function Scale(const Factor: double; Index, Len: integer): TOpenCLMtxVec; overload; (*Multiply all calling object elements with a complex Value in-place.*) function Scale(const Factor: TCplx): TOpenCLMtxVec; overload; (*Multipy calling object elements [Index]..[Index+Len-1] with complex Value in-place. An exception is raised if array borders are overrun or underrun. *) function Scale(const Factor: TCplx; Index, Len: integer): TOpenCLMtxVec; overload; (*Log base N. Log base N for all calling object elements in-place. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TOpenCLVector a; clMtxVec.CreateIt(out a); try { a.CopyCplxFromArray(new double[] {1,2,3,4}); a.LogN(10.0); // log base 10, the slow way a = [Log10(1), Log10(2),...] } finally { clMtxVec.FreeIt(ref a); } } } *) function LogN(const N: double): TOpenCLMtxVec; overload; (*Calculate the log base N of calling object elements [Index]..[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function LogN(const N: double; Index, Len: integer):TOpenCLMtxVec; overload; (*Calculate the log base N of all X object elements. Store the results in calling object. Size and Complex properties of the calling object are adjusted automatically. *) function LogN(const N: double; const X: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Calculate the log base N of X object elements [XIndex]..[XIndex+Len-1]. The results are stored in calling object elements [Index]..[Index+Len-1]. Size and Complex properties of the calling object are not changed. An exception is raised if array borders are overrun. *) function LogN(const N: double; const X: TOpenCLMtxVec; XIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Normalize object. Normalizes Vec object by subtracting a constant Offset from Vec elements and dividing the result by constant Factor: The results are stored in calling object. Use this method if you want to do a multiply and add (scale and offset) operations in a single method call. 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 = [1,2,3,4] b.Normalize(a,2,3); } finally { clMtxVec.FreeIt(ref a, ref b); } } } *) function Normalize(const Vec: TOpenCLMtxVec; const SubOffset, DivFactor: double): TOpenCLMtxVec; overload; (*Normalize Vec object values [VecIndex]..[VecIndex+Len-1] by subtracting a real constant SubOffset from Vec elements and dividing the result by complex constant DivFactor. Store the results in calling vector values [Index]..[Index+Len-1]. An exception is raised if Vec or calling object is complex or array borders are overrun/underrun. *) function Normalize(const Vec: TOpenCLMtxVec; const SubOffset, DivFactor: double; VecIndex,Index,Len: integer): TOpenCLMtxVec; overload; (*Normalize Vec object by subtracting a complex constant SubOffset from Vec elements and dividing the result by real constant DivFactor. Size and Complex property of calling object are adjusted automatically. *) function Normalize(const Vec: TOpenCLMtxVec; const SubOffset: TCplx; const DivFactor: double): TOpenCLMtxVec; overload; (*Normalize Vec object complex values [VecIndex]..[VecIndex+Len-1] by subtracting a complex constant SubOffset from Vec elements and dividing the result by real constant DivFactor. Store the results in calling vector complex values [Index]..[Index+Len-1]. An exception is calling object is not complex or array borders are overrun/underrun. *) function Normalize(const Vec: TOpenCLMtxVec; const SubOffset: TCplx; const DivFactor: double; VecIndex,Index,Len: integer): TOpenCLMtxVec; overload; (*Raises base object elements to any power. Raises Base calling object elements to any power. The is faster, if Exponent is an integer. Real valued power can handle only positive Exponent. can handle negative exponent also. To compute a power to the negative exponent in general case or when the base is negative, use the complex version of the function. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TOpenCLVector a; clMtxVec.CreateIt(out a); try { a.CopyFromArray( new double[] {1,2,3,4}); // a = [1,2,3, 4] //magnitude a.Power(1.2); } finally { clMtxVec.FreeIt(ref a); } } } *) function Power(const Exponent: double): TOpenCLMtxVec; overload; (*Raises all calling vector elements to complex power Exponent in-place. If the calling vector is real and has negative elements, the result will be NAN at those entries. To obtain a valid result in this case, extend the calling vector to complex with method. In all real/complex combinations, the Power method will not automatically assume that a number is complex to speed up the computation. Alternatively the user can of course always convert the real numbers to complex before passing them to the Power routine. *) function Power(const Exponent: TCplx): TOpenCLMtxVec; overload; (*Raises base elements to exponent power. Raises Base value to Exponent object values powers and store the results to calling object values. Size and Complex properties of calling object are adjusted automatically. *) function Power(const Base: double; const Exponent: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Raises Base complex value to Exponent object values powers. Store the results to calling object values. Size and Complex properties of calling object are adjusted automatically. *) function Power(const Base: TCplx; const Exponent: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Raises each of the Base object elements to complex Exponent power. Size and Complex properties of calling object are adjusted automatically. *) function Power(const Base: TOpenCLMtxVec; const Exponent: TCplx): TOpenCLMtxVec; overload; (*Raises each of the Base object elements to real Exponent power. Size and Complex properties of calling object are adjusted automatically. *) function Power(const Base: TOpenCLMtxVec; const Exponent: double): TOpenCLMtxVec; overload; (*Raises each of Base object elements to corresponding power, stored in Exponenet elements. Power[i] = Base[i]^Exponent[i] Size and Complex property of calling object are adjusted automatically. An exception is raised if Base and Exponent sizes do not match. *) function Power(const Base, Exponent: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Raises Base object elements to Exponent object elements power. Raises Base elements to Exponent elements power. Only positive exponents can be handled if exponent object Complex property is True. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TVec a,b,c; MtxVec.CreateIt(out a, out b, out c); try { a.CopyCplxFromArray( new double[] {1,2,3,4}); b.CopyCplxFromArray( new double[] {3,2,2,2}); c.PowerVec(a,b); } finally { MtxVec.FreeIt(ref a, ref b, ref c); } } } *) function PowerVec(const Base, Exponent: TOpenCLMtxVec): TOpenCLMtxVec; (*Elements rounded to the nearest whole number. Rounds all calling object elements to the nearest whole number. The result can be stored to an array of integers or as floating point number. *) function Round: TOpenCLMtxVec; overload; (*Round calling object elements [Index]..[Index+Len-1] in-place. An exception is raised if array borders are overrun/underrun. *) function Round(Index,Len: integer): TOpenCLMtxVec; overload; (*Round all Src object elements. Store the results in calling object elements. Size and Complex property of calling object are adjusted automatically. *) function Round(const Src: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Round Src object elements [SrcIndex]..[SrcIndex+Len-1]. Store the results to calling object elements [Index]..[Index+Len-1]. Size and Complex property of the calling object must be set explicitly. An exception is raised if array borders are overrun/underrun. *) function Round(const Src: TOpenCLMtxVec; SrcIndex,Index,Len: integer): TOpenCLMtxVec; overload; (*Initialize elements to Value. Set all calling object elements to Value. If the calling object is complex then the real part is set to Value and the imaginary is set to zero. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TOpenCLVector a; clMtxVec.CreateIt(out a); try { a.Size(false, clFloat, 4); a.SetVal(1); } finally { clMtxVec.FreeIt(ref a); } } } *) function SetVal(const Value: double): TOpenCLMtxVec; overload; (*Set all calling object elements [Index]..[Index+Len-1] to real Value. If the calling object is complex then the real part is set to Value and the imaginary is set to zero. An exception is raised if array borders are overrun/underrun. *) function SetVal(const Value: double; Index, Len: integer): TOpenCLMtxVec; reintroduce; overload; (*Set all calling object complex elements to complex Value.*) function SetVal(const Value: TCplx): TOpenCLMtxVec; overload; (*Set calling object complex elements [Index]..[Index+Len-1] to complex Value. Complex property of the calling object are set to true even before the call it was false. An exception is raised if calling object array borders are overrun/underrun. *) function SetVal(const Value: TCplx; Index: integer; Len: integer): TOpenCLMtxVec; reintroduce; overload; (*Initializes object elements to zero. *) function SetZero: TOpenCLMtxVec; overload; (*Initializes calling object elements [Index]..[Index+Len-1] to zero. An exception is raised if array borders are overrun. *) function SetZero(Index, Len: integer): TOpenCLMtxVec; overload; (*Changes elements sign. Changes all calling object elements sign (v -> -v) in-place. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TOpenCLVector a; clMtxVec.CreateIt(out a); try { a.CopyFromArray( new double[] {-1,2,-3,4); a.Sign(); // a = 1,-2, 3, -4 } finally { clMtxVec.FreeIt(ref a); } } } *) function Sign: TOpenCLMtxVec; overload; (*Change calling object elements [Index]..[Index+Len-1] sign in-place. An exception is raised if array borders are overrun or underrun. *) function Sign(Index,Len: integer): TOpenCLMtxVec; overload; (*Change all X object elements sign. Store the results in calling object. Size and Complex properties of calling object are adjusted automatically. *) function Sign(const X: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Change X object elements [XIndex]..[XIndex+Len-1] sign. Store the results in callingobject elements [Index]..[Index+Len-1]. An exception is raised if array borders are overrun or underrun. *) function Sign(const X: TOpenCLMtxVec; XIndex,Index,Len: integer): TOpenCLMtxVec; overload; (* Computes signum function of calling object elements. Signum(X) is 1 for X > 0 , equal to zero for X = 0 and -1 for X < 0. *) function Sgn: TOpenCLMtxVec; overload; (* Computes signum function of calling object elements [Index..Index+Len-1]. Signum(X) is 1 for X > 0 , equal to zero for X = 0 and -1 for X < 0. *) function Sgn(Index, Len: integer): TOpenCLMtxVec; overload; (* Computes signum function from Src elements and stores the result in the calling object. Size and Complex properties of calling object are adjusted automatically. Signum(X) is 1 for X > 0 , equal to zero for X = 0 and -1 for X < 0. *) function Sgn(const Src: TOpenCLMtxVec): TOpenCLMtxVec; overload; (* Computes signum function from Src elements [SrcIndex..SrcIndex+Len-1] and stores the result in the calling object [Index..Index+Len-1]. Size and Complex properties of calling object are adjusted automatically. Signum(X) is 1 for X > 0 , equal to zero for X = 0 and -1 for X < 0. *) function Sgn(const Src: TOpenCLMtxVec; SrcIndex,Index,Len: integer): TOpenCLMtxVec; overload; (*Signum. Calculates the signum of all Src object elements and multiplies it with the calling object elements accordingly. Signum(X) is 1 for X > 0 , equal to zero for X = 0 and -1 for X < 0. The length of Src and of the calling object must match or an exception will be raised. Size and Complex property of calling object are adjusted automatically. *) function SgnMul(const Src: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Sine and cosine. Calculates the sine and cosine for all calling object elements and stores the sines to SinX and cosines to CosX. Size and Complex property of SinX and CosX are adjusted automatically. Note Use this method if you require both sine and cosine. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TOpenCLVector a,s,v; clMtxVec.CreateIt(out a, out s, out c); try { a.CopyFromArray( new double[] {0,Math387.PIDIV2,Math387.PI); a.SinCos(s,c); // s=[0,1,0], c =[1,0,-1] } finally { MtxVec.FreeIt(ref a, ref s, ref c); } } } *) procedure SinCos(const SinX, CosX: TOpenCLMtxVec); overload; (*Calculates the sine and cosine for calling object elements [Index]..[Index+Len-1]. stores the sines to SinX elemets [SinXIndex]..[SinXIndex+Len-1] and cosines to CosX elements [CosXIndex]..[CosXIndex+Len-1] elements. Size and Complex property of SinX and CosX objects are not set automatically. An exception is raised if array borders are overrun/underun. *) procedure SinCos(const SinX, CosX: TOpenCLMtxVec; SinXIndex, CosXIndex, Index, Len: integer); overload; (*Hyperbolic sine and cosine. Calculates the hyperbolic sine and hyperbolic cosine for all calling object elements and stores the sines to SinhX and cosines to CoshX. Size and Complex property of SinhX and CoshX are adjusted automatically. Note Use this method if you require hyperbolic sine and hyperbolic cosine. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TOpenCLVector a,s,v; clMtxVec.CreateIt(out a, out s, out c); try { a.CopyFromArray( new double[] {0,Math387.PIDIV2,Math387.PI); a.SinhCosh(s,c); } finally { clMtxVec.FreeIt(ref a, ref s, ref c); } } } *) procedure SinhCosh(const SinhX, CoshX: TOpenCLMtxVec); overload; (*Calculates the hyperbolic sine and hyperbolic cosine for calling object elements [Index]..[Index+Len-1]. Stores the sines to SinhX elemets [SinhIndex]..[SinhIndex+Len-1] and cosines to CoshX elements [CoshIndex]..[CoshIndex+Len-1] elements. Size and Complex property of SinhX and CoshX objects are not set automatically. An exception is raised if array borders are overrun/underun. *) procedure SinhCosh(const SinhX, CoshX: TOpenCLMtxVec; SinhIndex, CoshIndex, Index, Len: integer); overload; (*Threshold bottom operation. Perform threshold operation on all calling object values. The Value parameter is a lower bound for threshold operation. All values smaller than Value will be replaced with Value. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TOpenCLVector a; clMtxVec.CreateIt(out a); try { a.CopyFromArray( new double[] {2, 0.1, 3, 4}); a.ThreshBottom(0.2); // a = [2,0.2,3,4] } finally { clMtxVec.FreeIt(ref a); } } } *) function ThreshBottom(const Value: double): TOpenCLMtxVec; overload; (*Perform the threshold operation on calling object values [Index]..[Index+Len-1]. An exception is raised if array borders are overrun/underrun. *) function ThreshBottom(const Value: double; Index, Len: integer): TOpenCLMtxVec; overload; (*Perform threshold operation on all Src object values. Store the results in calling object. Size and Complex properties of the calling object are adjusted automatically. *) function ThreshBottom(const Src: TOpenCLMtxVec; const Value: double): TOpenCLMtxVec; overload; (*Perform a threshold operation on Vec elements [VecIndex]..[VecIndex+Len-1]. Store the results in the calling object elements [Index]..[Index+Len-1]. Size and Complex properties of the calling object must be set explicitly. An exception is raised if array borders are overrun/underrun. *) function ThreshBottom(const Vec: TOpenCLMtxVec; const Value: double; VecIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Threshold top operation. Perform threshold operation on all calling object values. The Value parameter is an upper bound for threshold operation. All values bigger than Value will be replaced with Value. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TOpenCLVector a; clMtxVec.CreateIt(out a); try { a.CopyFromArray( new double[] {2, 0.1, 3, 4}); a.ThreshTop(0.2); // a = [0.2, 0.1, 0.2, 0.2] } finally { clMtxVec.FreeIt(ref a); } } } *) function ThreshTop(const Value: double): TOpenCLMtxVec; overload; (*Perfrom the threshold operation on calling object values [Index]..[Index+Len-1]. An exception is raised if array borders are overrun/underrun. *) function ThreshTop(const Value: double; Index, Len: integer): TOpenCLMtxVec; overload; (*Perform threshold operation on all Src object values. Store the results in calling object. Size and Complex properties of the calling object are adjusted automatically. *) function ThreshTop(const Src: TOpenCLMtxVec; const Value: double): TOpenCLMtxVec; overload; (*Perform a threshold operation Vec elements [VecIndex]..[VecIndex+Len-1]. Store the results in the calling object elements [Index]..[Index+Len-1]. Size and Complex properties of the calling object must be set explicitly. An exception is raised if array borders are overrun/underrun. *) function ThreshTop(const Vec: TOpenCLMtxVec; const Value: double; VecIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Threshold less than operation. Perform operation on all calling object values. The LTValue parameter is an lower bound for threshold operation. All values less than LTLevel will be replaced with LTValue. For complex number comparation is applied with norm of complex value. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TOpenCLVector a; clMtxVec.CreateIt(out a); try { a.CopyFromArray( new double[] {2, 0.1, 3, 4}); a.ThresholdLT(2.3,1.5); // a = [1.5,1.5,3,4] } finally { clMtxVec.FreeIt(ref a); } } } *) function ThresholdLT(const LTLevel, LTValue: double): TOpenCLMtxVec; overload; (*Perfrom "less than" threshold operation on the calling object values in range [Index]..[Index+Len-1]. An exception is raised if array borders are overrun/underrun. *) function ThresholdLT(const LTLevel, LTValue: double; Index, Len: integer): TOpenCLMtxVec; overload; (*Perform "less than" threshold operation on all Vec object values. Store the results in calling object. Size and Complex properties of the calling object are adjusted automatically. *) function ThresholdLT(const Vec: TOpenCLMtxVec; const LTLevel, LTValue: double): TOpenCLMtxVec; overload; (*Perform "less than" threshold operation on Vec elements from range [VecIndex]..[VecIndex+Len-1]. Store the results in the calling object elements [Index]..[Index+Len-1]. Size and Complex properties of the calling object must be set explicitly. An exception is raised if array borders are overrun/underrun. An exception will be raised if Vec.Complex and Complex of the calling object are not equal. *) function ThresholdLT(const Vec: TOpenCLMtxVec; const LTLevel, LTValue: double; VecIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Perfrom "less than" threshold operation for complex numbers. If the calling object contains none Complex values, an exception will be raised. *) function ThresholdLT(const LTLevel: double; const LTValue: TCplx): TOpenCLMtxVec; overload; (*Perfrom "less than" threshold operation for complex numbers on the calling object values in range [Index]..[Index+Len-1]. An exception is raised if array borders are overrun/underrun. If the calling object contains none Complex values, an exception will be raised. *) function ThresholdLT(const LTLevel: double; const LTValue: TCplx; Index, Len: integer): TOpenCLMtxVec; overload; (*Perform "less than" threshold operation for complex numbers on all Vec object values. Store the results in calling object. Size and Complex properties of the calling object are adjusted automatically. If Vec object contains none Complex values, an exception will be raised. *) function ThresholdLT(const Vec: TOpenCLMtxVec; const LTLevel: double; const LTValue: TCplx): TOpenCLMtxVec; overload; (*Perform "less than" threshold operation for complex numbers on Vec elements from range [VecIndex]..[VecIndex+Len-1]. Store the results in the calling object elements [Index]..[Index+Len-1]. Size and Complex properties of the calling object must be set explicitly. An exception is raised if array borders are overrun/underrun. If Vec object or calling object contain none Complex values, an exception will be raised. *) function ThresholdLT(const Vec: TOpenCLMtxVec; const LTLevel: double; const LTValue: TCplx; VecIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Threshold greater than operation. Perform operation on all calling object values. The GTValue parameter is an upper bound for threshold operation. All values bigger than LTLevel will be replaced with GTValue. For complex number comparation is applied with norm of complex value. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TOpenCLVector a; clMtxVec.CreateIt(out a); try { a.CopyFromArray( new double[] {2, 0.1, 3, 4}); a.ThresholdGT(2.3,3.4); // a = [2,0.1,3.4,3.4] } finally { clMtxVec.FreeIt(ref a); } } } *) function ThresholdGT(const GTLevel, GTValue: double): TOpenCLMtxVec; overload; (*Perfrom "greater than" threshold operation on the calling object values in range [Index]..[Index+Len-1]. An exception is raised if array borders are overrun/underrun. *) function ThresholdGT(const GTLevel, GTValue: double; Index, Len: integer): TOpenCLMtxVec; overload; (*Perform "greater than" threshold operation on all Vec object values. Store the results in calling object. Size and Complex properties of the calling object are adjusted automatically. *) function ThresholdGT(const Vec: TOpenCLMtxVec; const GTLevel, GTValue: double): TOpenCLMtxVec; overload; (*Perform "greater than" threshold operation on Vec elements from range [VecIndex]..[VecIndex+Len-1]. Store the results in the calling object elements [Index]..[Index+Len-1]. Size and Complex properties of the calling object must be set explicitly. An exception is raised if array borders are overrun/underrun. An exception will be raised if Vec.Complex and Complex of the calling object are not equal. *) function ThresholdGT(const Vec: TOpenCLMtxVec; const GTLevel, GTValue: double; VecIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Perfrom "greater than" threshold operation for complex numbers. If the calling object contains none Complex values, an exception will be raised. *) function ThresholdGT(const GTLevel: double; const GTValue: TCplx): TOpenCLMtxVec; overload; (*Perfrom "greater than" threshold operation for complex numbers on the calling object values in range [Index]..[Index+Len-1]. An exception is raised if array borders are overrun/underrun. If the calling object contains none Complex values, an exception will be raised. *) function ThresholdGT(const GTLevel: double; const GTValue: TCplx; Index, Len: integer): TOpenCLMtxVec; overload; (*Perform "greater than" threshold operation for complex numbers on all Vec object values. Store the results in calling object. Size and Complex properties of the calling object are adjusted automatically. If Vec object contains none Complex values, an exception will be raised. *) function ThresholdGT(const Vec: TOpenCLMtxVec; const GTLevel: double; const GTValue: TCplx): TOpenCLMtxVec; overload; (*Perform "greater than" threshold operation for complex numbers on Vec elements from range [VecIndex]..[VecIndex+Len-1]. Store the results in the calling object elements [Index]..[Index+Len-1]. Size and Complex properties of the calling object must be set explicitly. An exception is raised if array borders are overrun/underrun. If Vec object or calling object contain none Complex values, an exception will be raised. *) function ThresholdGT(const Vec: TOpenCLMtxVec; const GTLevel: double; const GTValue: TCplx; VecIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Threshold greater than and less than operation. Perform operation on all calling object values. The LTValue parameter is an lower bound for threshold operation. The GTValue parameter is an upper bound for threshold operation. All values less than LTLevel will be replaced with LTValue. All values bigger than GTLevel will be replaced with GTValue. Operation is available only for none Complex values. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TOpenCLVector a; clMtxVec.CreateIt(out a); try { a.CopyFromArray( new double[] {2, 0.1, 3, 4}); a.ThresholdGT_LT(2.3,3.4,1,0.5); // a = [2,0.5,3.4,3.4] } finally { clMtxVec.FreeIt(ref a); } } } *) function ThresholdGT_LT (const GTLevel, GTValue, LTLevel, LTValue: double): TOpenCLMtxVec; overload; (*Perfrom "greater than and less than" threshold operation on the calling object values in range [Index]..[Index+Len-1]. An exception is raised if array borders are overrun/underrun. An exception will be raised if the calling object contains complex numbers. *) function ThresholdGT_LT (const GTLevel, GTValue, LTLevel, LTValue: double; Index, Len: integer): TOpenCLMtxVec; overload; (*Perform "greater than and less than" threshold operation on all Vec object values. Store the results in calling object. Size and Complex properties of the calling object are adjusted automatically. An exception will be raised if Vec object contains complex numbers. *) function ThresholdGT_LT (const Vec: TOpenCLMtxVec; const GTLevel, GTValue, LTLevel, LTValue: double): TOpenCLMtxVec; overload; (*Perform "greater than and less than" threshold operation on Vec elements from range [VecIndex]..[VecIndex+Len-1]. Store the results in the calling object elements [Index]..[Index+Len-1]. Size and Complex properties of the calling object must be set explicitly. An exception is raised if array borders are overrun/underrun. An exception will be raised if Vec object or the calling object contain complex numbers. *) function ThresholdGT_LT(const Vec: TOpenCLMtxVec; const GTLevel, GTValue, LTLevel, LTValue: double; VecIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Rounds a real number towards zero and returns the fractional part. Rounds all calling object elements towards zero to an integer and stores the result in the TruncDst object as floating point numbers. The fractional part is stored in the FracDst. *) procedure TruncAndFrac(const TruncDst: TOpenCLMtxVec; const FracDst: TOpenCLMtxVec); overload; (*Truncate calling object elements [Index]..[Index+Len-1] and store the results to TruncDst object elements [TruncIdx]..[TruncIdx+Len-1]. The fractional parts are saved in FracDst elements [FracIdx]..[FracIdx+Len-1]. Size and Complex property of calling object must be set explicitly to match those of Src object. An exception is raised if array borders are overrun/underrun. *) procedure TruncAndFrac(const TruncDst: TOpenCLMtxVec; const FracDst: TOpenCLMtxVec; TruncIdx, FracIdx, Index, Len: integer); overload; (*Rounds a real number towards zero. Rounds all calling object elements towards zero to an integer and stores the result in the calling object again as floating point numbers. *) function Trunc: TOpenCLMtxVec; overload; (*Truncate calling object elements [Index]..[Index+Len-1] in-place. An exception is raised if array borders are overrun/underrun. *) function Trunc(Index,Len: integer): TOpenCLMtxVec; overload; (*Truncate all Src object elements. Store the results in calling object elements. Size and Complex property of calling object are adjusted automatically. *) function Trunc(const Src: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Truncate Src object elements [SrcIndex]..[SrcIndex+Len-1]. Store the results to calling object elemenents [Index]..[Index+Len-1]. Size and Complex property of calling object must be set explicitly to match those of Src object. An exception is raised if array borders are overrun/underrun. *) function Trunc(const Src: TOpenCLMtxVec; SrcIndex, Index,Len: integer): TOpenCLMtxVec; overload; (*The inverse of cube root 1/(v)^1/3. Calculate the inverse cube root (1/(element)^(1/3)) of all calling object elements in-place. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TVec a; MtxVec.CreateIt(out a); try { a.CopyFromArray( new double[] {-1, 8}); a.InvCbrt(); // returns [-1,0.5] } finally { MtxVec.FreeIt(ref a); } } } *) function InvCbrt: TOpenCLMtxVec; overload; (*Calculate the inverse of cube root for calling object elements [Index]..[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function InvCbrt(Index, Len: integer): TOpenCLMtxVec; overload; (*Calculate the inverse of cube root for all X elements. Store the results in the calling object. Size and Complex properties of the calling vector are set implicitly to match the X object. *) function InvCbrt(const X: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Calculate the inverse of cube root for X elements [XIndex]..[XIndex+Len-1]. Store the results in the calling object elements [Index]..[Index+Len-1]. Size and Complex properties of the calling object must be set explicitly. An exception is raised if array borders are overrun. *) function InvCbrt(const X: TOpenCLMtxVec; XIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*The inverse of square root 1/(v)^1/2. Calculate the inverse square root 1/(element)^(1/2)) of all calling object elements in-place. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TOpenCLVector a; MtxVec.CreateIt(out a); try { a.CopyFromArray( new double[] {1, 16}); a.InvSqrt(); // returns [1,0.25] } finally { MtxVec.FreeIt(ref a); } } } *) function InvSqrt: TOpenCLMtxVec; overload; (*Calculate the inverse of square root for calling object elements [Index]..[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function InvSqrt(Index, Len: integer): TOpenCLMtxVec; overload; (*Calculate the inverse of square root for all X elements. Store the results in the calling object. Size and Complex properties of the calling vector are set implicitly to match the X object. *) function InvSqrt(const X: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Calculate the inverse of square root for X elements [XIndex]..[XIndex+Len-1]. Store the results in the calling object elements [Index]..[Index+Len-1]. Size and Complex properties of the calling object must be set explicitly. An exception is raised if array borders are overrun. *) function InvSqrt(const X: TOpenCLMtxVec; XIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Magnitude. Calculate the magnitude for all calling object elements in-place. This method has the same function as the method. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TOpenCLVector a; clMtxVec.CreateIt(out a); try { a.CopyFromArray( new double[] {1,-2,3,4}); // a = [1,-2, 3,4] a.Mag(); // a = [1, 2, 3,4] } finally { clMtxVec.FreeIt(ref a); } } } *) function Mag: TOpenCLMtxVec; overload; (*Calculate the magnitude for calling object elements [Index]..[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function Mag(Index, Len: integer): TOpenCLMtxVec; overload; (*Calculate the magnitude for all X elements. Store the results in the calling object elements. Size and Complex properties of the calling vector are set implicitly to match Vec vector. *) function Mag(const X: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Calculate the magnitude for X elements [XIndex]..[XIndex+Len-1]. Store the results in the calling object elements [Index]..[Index+Len-1]. Size and Complex properties of the calling object must be set explicitly. An exception is raised if array borders are overrun. *) function Mag(const X: TOpenCLMtxVec; XIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Multiply Vec1 elements [Vec1Index]..[Vec1Index+Len-1] with Vec2 object elements [Vec2Index]..[Vec2Index+Len-1]. Store the results in calling object elements [Index]..[Index+Len-1]. Size and Complex properties of the calling object must be set explicitly. An exception is raised if array borders are overrun or underrun. *) function Mul(const Vec1, Vec2: TOpenCLMtxVec; Vec1Index, Vec2Index, Index, Len: integer): TOpenCLMtxVec; overload; (*Multiply all Vec1 elements with corresponding Vec2 elements. Store the results in calling object. Size and Complex property of calling object are adjusted automatically to match those of Vec1 and Vec2. An exception is raised if Vec1 and Vec2 size and Complex property do not match. *) function Mul(const Src1, Src2: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Vector multiplication. Multiply each of Vec elements with corresponding elements in the calling object. Size and Complex property of the calling object are set automatically. The result is stored in the calling object. *) function Mul(const Vec: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Multiply Vec elements [VecIndex]..[VecIndex+Len-1] with calling object elements [Index]..[Index+Len-1] in-place. An exception is raised if Vec and calling object Complex property do not match or if array borders are overrun/underrun. *) function Mul(const Vec: TOpenCLMtxVec; VecIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Multiply object elements with Value. Multiplies all calling object elements with Value in-place. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TOpenCLVector a; MtxVec.CreateIt(out a); try { a.CopyFromArray(new double[] {2,3,5}); // a = [2,3,5] a.Mul(3); // a = [6,9,15] } finally { MtxVec.FreeIt(ref a); } } } *) function Mul(const Value: double): TOpenCLMtxVec; overload; (*Multiply all calling object elements with complex Value in-place.*) function Mul(const Value: TCplx): TOpenCLMtxVec; overload; (*Multipy calling object elements [Index]..[Index+Len-1] with Value in-place. An exception is raised if array borders are overrun or underrun. *) function Mul(const Value: double; Index, Len: integer): TOpenCLMtxVec; overload; (*Multipy calling object elements [Index]..[Index+Len-1] with complex Value in-place. An exception is raised if array borders are overrun or underrun. *) function Mul(const Value: TCplx; Index, Len: integer): TOpenCLMtxVec; overload; (*Multiply each element of Vec with Value. Store the result in the calling object. Size and Complex properties of the calling object are adjusted automatically. *) function Mul(const Vec: TOpenCLMtxVec; const Value: double): TOpenCLMtxVec; overload; (*Multiply each element of Vec with complex Value. Store the result in the calling object. Size of the calling object is set automatically. Complex property of the calling object is set to True. *) function Mul(const Vec: TOpenCLMtxVec; const Value: TCplx): TOpenCLMtxVec; overload; (*Multiply Vec elements [VecIndex]..[VecIndex+Len-1] with Value. Store the result in calling object elements [Index]..[Index+Len-1]. Size of the calling object is not changed. An exception is raised if array borders are overrun or underrun. Complex propertiy of the calling object is set implicitly. *) function Mul(const Vec: TOpenCLMtxVec; const Value: double; VecIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Multiply Vec elements [VecIndex]..[VecIndex+Len-1] with complex Value. Store the result in calling object elements [Index]..[Index+Len-1]. Size of the calling object is not changed. An exception is raised if array borders are overrun or underrun. Complex propertiy of the calling object is set to True. *) function Mul(const Vec: TOpenCLMtxVec; const Value: TCplx; VecIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Multiply elements by imaginary unit I.*) function MulI: TOpenCLMtxVec; overload; (*Multipy calling object elements [Index]..[Index+Len-1] with I in-place.*) function MulI(Index: integer; Len: integer): TOpenCLMtxVec; overload; (*Multiply X elements with I and store the result in the calling object.*) function MulI(const X: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Multipy X elements [XIndex]..[XIndex+Len-1] with I. Xtore the result in the calling object at locations [Index]..[Index+Len-1]. *) function MulI(const X: TOpenCLMtxVec; XIndex: integer; Index: integer; Len: integer): TOpenCLMtxVec; overload; (*The phase angles (spectrum) of object elements. Calculates the phase angles (spectrum) of all Vec object elements. Phase values are returned in radians and are in the range -PI,PI. Size and Complex properties of the calling object are set implicitly to match Vec object. The phase angles are calculated from the following equation: using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TOpenCLVector a,b; clMtxVec.CreateIt(out a, out b); try { a.CopyCplxFromArray( new double[] {1,2,3,-4}); b.PhaseSpectrum(a); // b = [arctan2(1,2), arctan2(3,-4)]; } finally { clMtxVec.FreeIt(ref a, ref b); } } } *) function PhaseSpectrum(const Vec: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Calculates the power spectrum from the Vec elements [VecIndex]..[VecIndex+Len-1]. Store the results in calling object elements [Index]..[Index+Len-1]. An exception is raised if array borders are overrun/underrun. *) function PhaseSpectrum(const Vec: TOpenCLMtxVec; VecIndex, Index,Len: integer): TOpenCLMtxVec; overload; (*The power spectrum from object complex values. Calculates the power spectrum from the Vec object complex values and stores the results (power spectrum) in the real calling object. Size and Complex properties of the calling object are set implicitly to match Vec object. The spectrum elements are squares of the magnitudes of the complex input elements: using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TOpenCLVector a,b; clMtxVec.CreateIt(out a, out b); try { a.CopyCplxFromArray( new double[] {1,2,3,4}); // a = [1 + 2i, 3 - 4i] b.PhaseSpectrum(a); // b = [arctan2(1,2), arctan2(3,-4)]; } finally { clMtxVec.FreeIt(ref a, ref b); } } } *) function PowerSpectrum(const Vec: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Calculates the power spectrum from the Vec complex elements [VecIndex]..[VecIndex+Len-1]. Store the results in calling object real elements [Index]..[Index+Len-1]. An exception is raised if calling object Complex property is true or if array borders are overrun/underrun. *) function PowerSpectrum(const Vec: TOpenCLMtxVec; VecIndex, Index,Len: integer): TOpenCLMtxVec; overload; (*Converts the polar magnitude/phase pairs to cartesian pairs. Convert all AmpltVec and PhaseVec elements (combined) from polar to cartesian form. If AmpltVec and PhaseVec size is not the same , an exeption is raised. The results are stored as complex numbers (x=Re, y=Im) in the calling object. Size and Complex properties of the calling object are set implicitly to match AmpltVec and PhaseVec objects. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TOpenCLVector a,b,c; clMtxVec.CreateIt(out a, out b, out c); try { a.CopyFromArray( new double[] {1,2,3,4}); // a = [1,2,3, 4] //magnitude b.CopyFromArray( new double[] {1,0,1,-1}); // b = [1,0,1,-1] /phase c.PolarToCart(a,b); // result stored in c = projections to Re and Im axis } finally { clMtxVec.FreeIt(ref a, ref b, ref c); } } } *) function PolarToCart(const AmpltVec, PhaseVec: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Convert AmpltVec elements [aIndex]..[aIndex+Len-1] and PhaseVec elements [PIndex]..[PIndex+Len-1] from polar form (radius,angle) to cartesian form (x,y). The results are stored as complex numbers (x=Re, y=Im) in the calling object elements [Index]..[Index+Len-1]. Size and Complex properties of the calling object must be set explicitly. An exception is raised if array borders are overrun/underrun. *) function PolarToCart(const AmpltVec, PhaseVec: TOpenCLMtxVec; aIndex, PIndex,Index, Len: integer): TOpenCLMtxVec; overload; (*Gets real part of complex object values. The method method gets the real part of a complex object Vec and stores the real results in the calling object. Size and Complex properties of the calling object are set implicitly to match Vec object. Vec Complex property must be true otherwise an exception is raised. var a,b: TOpenCLVector; begin CreateIt(a,b); try a.CopyCplxFromArray(TSingleArray.Create(1,2,3,4)); // = [1+2i, 3+4i] b.RealPart(a); // b = [1,3] finally FreeIt(a,b); end; end; *) function RealPart(const Vec: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Gets the real part of a Vec object complex elements [VecIndex]..[VecIndex+Len-1]. Stores the results in calling object real elements [Index]..[Index+Len-1]. An exception is raised if array borders are overrun or underrun or if Vec object Complex propety is false. *) function RealPart(const Vec: TOpenCLMtxVec; VecIndex,Index,Len: integer): TOpenCLMtxVec; overload; (*Square. Calculate the square of all caling object elements in-place. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TOpenCLVector a; clMtxVec.CreateIt(out a); try { a.CopyCplxFromArray(new double[] {1,2,3,4}); a.Sqr(); // a=[1,4,9,16] } finally { clMtxVec.FreeIt(ref a); } } } *) function Sqr: TOpenCLMtxVec; overload; (*Calculate the square of calling object elements [Index]...[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function Sqr(Index, Len: integer): TOpenCLMtxVec; overload; (*Calculate the square of all X object elements. Store the results in the calling object. Size and Complex properties of calling object are adjusted automatically. *) function Sqr(const X: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Calculate the square of X object elements [XIndex]..[XIndex+Len-1]. The results are stored in calling object elements [Index]..[Index+Len-1]. Size and Complex properties of the calling object are not changed. An exception is raised if array borders are overrun. *) function Sqr(const X: TOpenCLMtxVec; XIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Square root. Calculate the square root of all caling object elements in-place. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TOpenCLVector a; clMtxVec.CreateIt(out a); try { a.CopyCplxFromArray(new double[] {1,4,9}); a.Sqrt(); // a=[1,2,3] } finally { clMtxVec.FreeIt(ref a); } } } *) function Sqrt: TOpenCLMtxVec; overload; (*Calculate the square root of calling object elements [Index]...[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function Sqrt(Index, Len: integer): TOpenCLMtxVec; overload; (*Calculate the square root of all X object elements. Store the results in the calling object. Size and Complex properties of the calling object are adjusted automatically. *) function Sqrt(const X: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Calculate the square root of X object elements [XIndex]..[XIndex+Len-1]. The results are stored in calling object elements [Index]..[Index+Len-1]. Size and Complex properties of calling object are not changed. An exception is raised if array borders are overrun. *) function Sqrt(const X: TOpenCLMtxVec; XIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Sine function. Calculate the sine of all caling object elements in-place. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TOpenCLVector a; clMtxVec.CreateIt(out a); try { a.CopyCplxFromArray( new double[] {1,-2,3,4}); a.Sin(); // Computes complex sine } finally { clMtxVec.FreeIt(ref a); } } } *) function Sin: TOpenCLMtxVec; overload; (*Calculate the sine of calling object elements [Index]...[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function Sin(Index: integer; Len: integer): TOpenCLMtxVec; overload; (*Calculate the sine of all X object elements and store the results in calling object. Size and Complex properties of calling object are adjusted automatically. *) function Sin(const X: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Calculate the sine of X object elements [XIndex]...[XIndex+Len-1]. The results are stored in calling object elements [Index]...[Index+Len-1]. Size and Complex properties of the calling object must be set explicitly. An exception is raised if array borders are overrun. *) function Sin(const X: TOpenCLMtxVec; XIndex: integer; Index: integer; Len: integer): TOpenCLMtxVec; overload; (*Cosine. Calculate the cosine of all caling object elements in-place. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TOpenCLVector a; clMtxVec.CreateIt(out a); try { a.CopyCplxFromArray( new double[] {1,-2,3,4}); a.Cos(); // Computes complex sine } finally { clMtxVec.FreeIt(ref a); } } } *) function Cos: TOpenCLMtxVec; overload; (*Calculate the cosine of calling object elements [Index]...[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function Cos(Index: integer; Len: integer): TOpenCLMtxVec; overload; (*Calculate the cosine of all X object elements. Store the results in the calling object.vSize and Complex properties of calling object are adjusted automatically. *) function Cos(const X: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Calculate the cosine of X object elements [XIndex]...[XIndex+Len-1]. The results are stored in calling object elements [Index]...[Index+Len-1]. Size and Complex properties of calling object and the calling object must be set explicitly. An exception is raised if array borders are overrun. *) function Cos(const X: TOpenCLMtxVec; XIndex: integer; Index: integer; Len: integer): TOpenCLMtxVec; overload; (*Tangens. Calculate the tangens of all caling object elements in-place. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TOpenCLVector a; clMtxVec.CreateIt(out a); try { a.CopyCplxFromArray( new double[] {1,-2,3,4}); a.Tan(); // Computes complex tangens } finally { clMtxVec.FreeIt(ref a); } } } *) function Tan: TOpenCLMtxVec; overload; (*Calculate the tangens of calling object elements [Index]...[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function Tan (Index: integer; Len: integer): TOpenCLMtxVec; overload; (*Calculate the tangens of all X object elements. Store the results in the calling object. Size and Complex properties of calling object are adjusted automatically. *) function Tan(const X: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Calculate the tangens of X object elements [XIndex]...[XIndex+Len-1]. The results are stored in calling object elements [Index]...[Index+Len-1]. Size and Complex properties of the calling object must be set explicitly. An exception is raised if array borders are overrun. *) function Tan(const X : TOpenCLMtxVec; XIndex: integer; Index: integer; Len: integer): TOpenCLMtxVec; overload; (*Cotangens. Calculate the cotangens of all caling object elements in-place. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TOpenCLVector a; clMtxVec.CreateIt(out a); try { a.CopyCplxFromArray( new double[] {1,-2,3,4}); a.Cot(); // Computes complex cotangens } finally { clMtxVec.FreeIt(ref a); } } } *) function Cot: TOpenCLMtxVec; overload; (*Calculate the cotangens of calling object elements [Index]...[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function Cot(Index, Len: integer): TOpenCLMtxVec; overload; (*Calculate the cotangens of all X object elements. Store the results in the calling object. Size and Complex properties of calling object are adjusted automatically. *) function Cot(const X: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Calculate the cotangens of X object elements [XIndex]...[XIndex+Len-1]. The results are stored in calling object elements [Index]...[Index+Len-1]. Size and Complex properties of the calling object must be set explicitly. An exception is raised if array borders are overrun. *) function Cot(const X: TOpenCLMtxVec; XIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Secant. Calculate the secant of all caling object elements in-place. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TOpenCLVector a; clMtxVec.CreateIt(out a); try { a.CopyCplxFromArray( new double[] {1,-2,3,4}); a.Sec(); // Computes complex secant } finally { clMtxVec.FreeIt(ref a); } } } *) function Sec: TOpenCLMtxVec; overload; (*Calculate the secant of calling object elements [Index]...[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function Sec(Index, Len: integer): TOpenCLMtxVec; overload; (*Calculate the secant of all X object elements. Store the results in the calling object. Size and Complex properties of calling object are adjusted automatically. *) function Sec(const X: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Calculate the secant of X object elements [XIndex]...[XIndex+Len-1]. The results are stored in calling object elements [Index]...[Index+Len-1]. Size and Complex properties of the calling object must be set explicitly. An exception is raised if array borders are overrun. *) function Sec(const X: TOpenCLMtxVec; XIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Cosecant. Calculate the cosecant of all caling object elements in-place. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TOpenCLVector a; clMtxVec.CreateIt(out a); try { a.CopyCplxFromArray( new double[] {1,-2,3,4}); a.Csc(); // Computes complex cosecant } finally { clMtxVec.FreeIt(ref a); } } } *) function Csc: TOpenCLMtxVec; overload; (*Calculate the cosecant of calling object elements [Index]...[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function Csc(Index, Len: integer): TOpenCLMtxVec; overload; (*Calculate the cosecant of all X object elements. Store the results in the calling object. Size and Complex properties of calling object are adjusted automatically. *) function Csc(const X: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Calculate the cosecant of X object elements [XIndex]...[XIndex+Len-1]. The results are stored in calling object elements [Index]...[Index+Len-1]. Size and Complex properties of the calling object must be set explicitly. An exception is raised if array borders are overrun. *) function Csc(const X: TOpenCLMtxVec; XIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*The inverse sine. Calculate the inverse sine of all calling object elements in-place. Values must be between -1 and 1. The return values will be in the range [0,], in radians. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TOpenCLVector a; clMtxVec.CreateIt(out a); try { a.CopyCplxFromArray( new double[] {1,-0.5,0.11,0.9}); a.ArcSin(); // Computes complex inverse sine } finally { clMtxVec.FreeIt(ref a); } } } *) function ArcSin: TOpenCLMtxVec; overload; (*Calculate the inverse sine of calling object elements [Index]...[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function ArcSin(Index, Len: integer): TOpenCLMtxVec; overload; (*Calculate the inverse sine of all X object elements. Store the results in the calling object. Size and Complex properties of calling object are adjusted automatically. *) function ArcSin(const X: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Calculate the inverse sine of X object elements [XIndex]...[XIndex+Len-1]. The results are stored in calling object elements [Index]...[Index+Len-1]. Size and Complex properties of the calling object must be set explicitly. An exception is raised if array borders are overrun. *) function ArcSin(const X: TOpenCLMtxVec; XIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*The inverse cosine. Calculate the inverse cosine of all calling object elements in-place. Values must be between -1 and 1. The return values will be in the range [0,], in radians. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TOpenCLVector a; clMtxVec.CreateIt(out a); try { a.CopyCplxFromArray( new double[] {1,-0.5,0.11,0.9}); a.ArcCos(); // Computes complex inverse cosine } finally { clMtxVec.FreeIt(ref a); } } } *) function ArcCos: TOpenCLMtxVec; overload; (*Calculate the inverse cosine of calling object elements [Index]...[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function ArcCos(Index, Len: integer): TOpenCLMtxVec; overload; (*Calculate the inverse cosine of all X object elements. Store the results in the calling object. Size and Complex properties of calling object are adjusted automatically. *) function ArcCos(const X: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Calculate the inverse cosine of X object elements [XIndex]...[XIndex+Len-1]. The results are stored in calling object elements [Index]...[Index+Len-1]. Size and Complex properties of the calling object must be set explicitly. An exception is raised if array borders are overrun. *) function ArcCos(const X: TOpenCLMtxVec; XIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Inverse tangens of Y/X. Calculates the inverse tangens of Y/X, and returns an angle in the correct quadrant. The results are stored in calling object elements. Size and Complex properties of calling object are adjusted automatically to match those of X and Y objects. An exception is raised if X and Y size and Complex properties do not match. Note that is calculated as ArcTan2(1, X). *) function ArcTan2(const Y, X: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Calculate the inverse tangens of Y/X. Calculation uses Y elements [YIndex]..[YIndex+Len-1], X elements [XIndex]..[XIndex+Len-1] and stores the results in calling object elements [Index]..[Index+Len-1]. An exception is raised if array borders are overrun. *) function ArcTan2(const Y, X: TOpenCLMtxVec; YIndex, XIndex, Index: integer; Len: integer): TOpenCLMtxVec; overload; (*Inverse tangens. Calculate the inverse tangens for all calling object elements in-place. The return values are expressed in radians. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TMtx A,B; clMtxVec.CreateIt(out A, out B); try { A.SetIt(2,2,true, new double[] {1,0, 2,0, 2,0 4,1})); // 2x2, complex matrix B.ArcTan(A); } finally { clMtxVec.FreeIt(ref A, ref B); } } } *) function ArcTan: TOpenCLMtxVec; overload; (*Calculate the inverse tangens of calling object elements [Index]...[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function ArcTan(Index, Len: integer): TOpenCLMtxVec; overload; (*Calculate the inverse tangens of all X object elements. Store the results in the calling object. Size and Complex properties of calling object are adjusted automatically. *) function ArcTan(const X: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Calculate the inverse tangens of X object elements [XIndex]...[XIndex+Len-1]. The results are stored in calling object elements [Index]...[Index+Len-1]. Size and Complex properties of the calling object must be set explicitly. An exception is raised if array borders are overrun. *) function ArcTan(const X: TOpenCLMtxVec; XIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Inverse cotangens. Calculate the inverse cotangens for all calling object elements in-place. The return values are expressed in radians. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TMtx A,B; clMtxVec.CreateIt(out A, out B); try { A.SetIt(2,2,true, new double[] {1,0, 2,0, 2,0 4,1})); // 2x2, complex matrix B.ArcCot(A); } finally { clMtxVec.FreeIt(ref A, ref B); } } } *) function ArcCot: TOpenCLMtxVec; overload; (*Calculate the inverse cotangens of calling object elements [Index]...[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function ArcCot(Index, Len: integer): TOpenCLMtxVec; overload; (*Calculate the inverse cotangens of all X object elements. Store the results in the calling object. Size and Complex properties of calling object are adjusted automatically. *) function ArcCot(const X: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Calculate the inverse cotangens of X object elements [XIndex]...[XIndex+Len-1]. The results are stored in calling object elements [Index]...[Index+Len-1]. Size and Complex properties of the calling object must be set explicitly. An exception is raised if array borders are overrun. *) function ArcCot(const X: TOpenCLMtxVec; XIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Inverse secant. Calculate the inverse secant for all calling object elements in-place. *) function ArcSec: TOpenCLMtxVec; overload; (*Calculate the inverse secant of calling object elements [Index]...[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function ArcSec(Index, Len: integer): TOpenCLMtxVec; overload; (*Calculate the inverse secant of all X object elements and store the results in the calling object. Size and Complex properties of calling object are adjusted automatically. *) function ArcSec(const X: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Calculate the inverse secant of X object elements [XIndex]...[XIndex+Len-1]. The results are stored in calling object elements [Index]...[Index+Len-1]. Size and Complex properties of the calling object must be set explicitly. An exception is raised if array borders are overrun. *) function ArcSec(const X: TOpenCLMtxVec; XIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Inverse cosecant. Calculate the inverse cosecant for all calling object elements in-place. *) function ArcCsc: TOpenCLMtxVec; overload; (*Calculate the inverse cosecant of calling object elements [Index]...[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function ArcCsc(Index, Len: integer): TOpenCLMtxVec; overload; (*Calculate the inverse cosecant of all X object elements. Store the results in the calling object. Size and Complex properties of calling object are adjusted automatically. *) function ArcCsc(const X: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Calculate the inverse cosecant of X object elements [XIndex]..[XIndex+Len-1]. The results are stored in the calling object elements [Index]..[Index+Len-1]. Size and Complex properties of the calling object must be set explicitly. An exception is raised if array borders are overrun. *) function ArcCsc(const X: TOpenCLMtxVec; XIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Hyperbolic sine. Calculate the hyperbolic sine of all caling object elements in-place. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TOpenCLVector a; clMtxVec.CreateIt(out a); try { a.CopyFromArray( new double[] {1, 1.5, 2, 0.3}); a.Sinh(); } finally { clMtxVec.FreeIt(ref a); } } } *) function Sinh: TOpenCLMtxVec; overload; (*Calculate the hyperbolic sine of calling object elements [Index]...[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function Sinh(Index, Len: integer): TOpenCLMtxVec; overload; (*Calculate the hyperbolic sine of all X object elements. Store the results in the calling object. Size and Complex properties of calling object are adjusted automatically. *) function Sinh(const X: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Calculate the hyperbolic sine for X object elements [XIndex]..[XIndex+Len-1]. The results are stored in the calling object elements [Index]..[Index+Len-1]. Size and Complex properties of the calling object must be set explicitly. An exception is raised if array borders are overrun. *) function Sinh(const X: TOpenCLMtxVec; XIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Hyperbolic cosine. Calculate the hyperbolic cosine of all caling object elements in-place. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TOpenCLVector a; clMtxVec.CreateIt(out a); try { a.CopyFromArray( new double[] {1, 1.5, 2, 0.3}); a.Cosh(); } finally { clMtxVec.FreeIt(ref a); } } } *) function Cosh: TOpenCLMtxVec; overload; (*Calculate the hyperbolic cosine for calling object elements [Index]..[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function Cosh(Index, Len: integer): TOpenCLMtxVec; overload; (*Calculate the hyperbolic cosine for all X object elements. Store the results in the calling object. Size and Complex properties of calling object are adjusted automatically. *) function Cosh(const X: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Calculate the hyperbolic cosine for X object elements [XIndex]..[XIndex+Len-1]. The results are stored in calling object elements [Index]..[Index+Len-1]. Size and Complex properties of the calling object must be set explicitly. An exception is raised if array borders are overrun. *) function Cosh(const X: TOpenCLMtxVec; XIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Hyperbolic tangens. Calculate the hyperbolic tangens of all caling object elements in-place. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TOpenCLVector a; clMtxVec.CreateIt(out a); try { a.CopyFromArray( new double[] {1, 1.5, 2, 0.3}); a.Tanh(); } finally { clMtxVec.FreeIt(ref a); } } } *) function Tanh: TOpenCLMtxVec; overload; (*Calculate the hyperbolic tangens for calling object elements [Index]..[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function Tanh(Index, Len: integer): TOpenCLMtxVec; overload; (*Calculate the hyperbolic tangens for all X object elements. Store the results in the calling object. Size and Complex properties of calling object are adjusted automatically. *) function Tanh(const X: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Calculate the hyperbolic tangens for X object elements [XIndex]..[XIndex+Len-1]. The results are stored in the calling object elements [Index]..[Index+Len-1]. Size and Complex properties of the calling object must be set explicitly. An exception is raised if array borders are overrun. *) function Tanh(const X: TOpenCLMtxVec; XIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Hyperbolic cotangens. Calculate the hyperbolic cotangens of all caling object elements in-place. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TOpenCLVector a; clMtxVec.CreateIt(out a); try { a.CopyFromArray( new double[] {1, 1.5, 2, 0.3}); a.Coth(); } finally { clMtxVec.FreeIt(ref a); } } } *) function Coth: TOpenCLMtxVec; overload; (*Calculate the hyperbolic cotangens for calling object elements [Index]...[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function Coth(Index, Len: integer): TOpenCLMtxVec; overload; (*Calculate the hyperbolic cotangens for all X object elements. Store the results in the calling object. Size and Complex properties of calling object are adjusted automatically. *) function Coth(const X: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Calculate the hyperbolic cotangens for X object elements [XIndex]..[XIndex+Len-1]. The results are stored in calling object elements [Index]..[Index+Len-1]. Size and Complex properties of the calling object must be set explicitly. An exception is raised if array borders are overrun. *) function Coth(const X: TOpenCLMtxVec; XIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Hyperbolic secant. Calculate the hyperbolic secant of all caling object elements in-place. *) function Sech: TOpenCLMtxVec; overload; (*Calculate the hyperbolic secant for calling object elements [Index]...[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function Sech(Index, Len: integer): TOpenCLMtxVec; overload; (*Calculate the hyperbolic secant for all X object elements. Store the results in the calling object. Size and Complex properties of calling object are adjusted automatically. *) function Sech(const X: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Calculate the hyperbolic secant for X object elements [XIndex]..[XIndex+Len-1]. The results are stored in calling object elements [Index]..[Index+Len-1]. Size and Complex properties of the calling object must be set explicitly. An exception is raised if array borders are overrun. *) function Sech(const X: TOpenCLMtxVec; XIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Hyperbolic cosecant. Calculate the hyperbolic cosecant of all caling object elements in-place. *) function Csch: TOpenCLMtxVec; overload; (*Calculate the hyperbolic cosecant for calling object elements [Index]..[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function Csch(Index, Len: integer): TOpenCLMtxVec; overload; (*Calculate the hyperbolic cosecant for all X object elements. Store the results in the calling object. Size and Complex properties of calling object are adjusted automatically. *) function Csch(const X: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Calculate the hyperbolic cosecant for X object elements [XIndex]..[XIndex+Len-1]. The results are stored in calling object elements [Index]..[Index+Len-1]. Size and Complex properties of the calling object must be set explicitly. An exception is raised if array borders are overrun. *) function Csch(const X: TOpenCLMtxVec; XIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Absolute values. Calculate the absolute value of all calling object elemets in-place. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TOpenCLVector a; clMtxVec.CreateIt(out a); try { a.CopyCplxFromArray( new double[] {1,-2,3,4}); a.Abs(); // a = [1,2,3,4] } finally { clMtxVec.FreeIt(ref a); } } } *) function Abs: TOpenCLMtxVec; overload; (*Calculate the absolute value for calling object elements [Index]..[Index+Len-1]. An exception is raised if array borders are overrun or underrun. *) function Abs(Index, Len: integer): TOpenCLMtxVec; overload; (*Calculate the absolute value for all X object and store the results in the calling object. Size and Complex properties of calling object are adjusted automatically. *) function Abs(const X: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Calculate the absolute value of X object elements [XIndex]..[XIndex+Len-1]. Store the results in calling object elements [Index]..[Index+Len-1]. An exception is raised if array borders are overrun or underrun. *) function Abs(const X: TOpenCLMtxVec; XIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Inverse hyperbolic sine. Calculate the inverse hyperbolic sine for all caling object elements in-place. *) function ArcSinh: TOpenCLMtxVec; overload; (*Calculate the inverse hyperbolic sine for calling object elements [Index]..[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function ArcSinh(Index, Len: integer): TOpenCLMtxVec; overload; (*Calculate the inverse hyperbolic sine for all X object elements. Store the results in the calling object. Size and Complex properties of calling object are adjusted automatically. *) function ArcSinh(const X: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Calculate the inverse hyperbolic sine for X object elements [XIndex]..[XIndex+Len-1]. The results are stored in calling object elements [Index]..[Index+Len-1]. Size and Complex properties of the calling object must be set explicitly. An exception is raised if array borders are overrun. *) function ArcSinh(const X: TOpenCLMtxVec; XIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Inverse hyperbolic cosine. Calculate the inverse hyperbolic cosine for all caling object elements in-place. *) function ArcCosh: TOpenCLMtxVec; overload; (*Calculate the inverse hyperbolic cosine for calling object elements [Index]..[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function ArcCosh(Index, Len: integer): TOpenCLMtxVec; overload; (*Calculate the inverse hyperbolic cosine for all X object elements. Store the results in the calling object. Size and Complex properties of calling object are adjusted automatically. *) function ArcCosh(const X: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Calculate the inverse hyperbolic cosine for X object elements [XIndex]..[XIndex+Len-1]. The results are stored in calling object elements [Index]..[Index+Len-1]. Size and Complex properties of the calling object must be set explicitly. An exception is raised if array borders are overrun. *) function ArcCosh(const X: TOpenCLMtxVec; XIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Inverse hyperbolic tangens. Calculate the inverse hyperbolic tangens for all caling object elements in-place. *) function ArcTanh: TOpenCLMtxVec; overload; (*Calculate the inverse hyperbolic tangens for calling object elements [Index]..[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function ArcTanh(Index, Len: integer): TOpenCLMtxVec; overload; (*Calculate the inverse hyperbolic tangens for all X object elements. Store the results in the calling object. Size and Complex properties of calling object are adjusted automatically. *) function ArcTanh(const X: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Calculate the inverse hyperbolic tangens for X object elements [XIndex]..[XIndex+Len-1]. The results are storedi n the calling object elements [Index]..[Index+Len-1]. Size and Complex properties of the calling object must be set explicitly. An exception is raised if array borders are overrun. *) function ArcTanh(const X: TOpenCLMtxVec; XIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Inverse hyperbolic cotangens. Calculate the inverse hyperbolic cotangens for all caling object elements in-place. *) function ArcCoth: TOpenCLMtxVec; overload; (*Calculate the inverse hyperbolic cotangens for calling object elements [Index]..[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function ArcCoth(Index, Len: integer): TOpenCLMtxVec; overload; (*Calculate the inverser hyperbolic cotangens for all X object elements. Store the results in calling object. Size and Complex properties of calling object are adjusted automatically. *) function ArcCoth(const X: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Calculate the inverse hyperbolic cotangens for X object elements [XIndex]..[XIndex+Len-1]. The results are stored in the calling object elements [Index]..[Index+Len-1]. Size and Complex properties of the calling object must be set explicitly. An exception is raised if array borders are overrun. *) function ArcCoth(const X: TOpenCLMtxVec; XIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Inverse hyperbolic secant. Calculate the inverse hyperbolic secant for all caling object elements in-place. *) function ArcSech: TOpenCLMtxVec; overload; (*Calculate the inverse hyperbolic secant for calling object elements [Index]..[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function ArcSech(Index, Len: integer): TOpenCLMtxVec; overload; (*Calculate the inverse hyperbolic secant for all X object elements. Store the results in calling object. Size and Complex properties of calling object are adjusted automatically. *) function ArcSech(const X: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Calculate the inverse hyperbolic secant for X object elements [XIndex]..[XIndex+Len-1]. The results are stored in calling object elements [Index]..[Index+Len-1]. Size and Complex properties of the calling object must be set explicitly. An exception is raised if array borders are overrun. *) function ArcSech(const X: TOpenCLMtxVec; XIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Inverse hyperbolic cosecant. Calculate the inverse hyperbolic cosecant for all caling object elements in-place. *) function ArcCsch: TOpenCLMtxVec; overload; (*Calculate the inverse hyperbolic cosecant for calling object elements [Index]...[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function ArcCsch(Index, Len: integer): TOpenCLMtxVec; overload; (*Calculate the inverse hyperbolic cosecant for all X object elements. Store the results in calling object. Size and Complex properties of calling object are adjusted automatically. *) function ArcCsch(const X: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Calculate the inverse hyperbolic cosecant for X object elements [XIndex]..[XIndex+Len-1]. The results are stored in calling object elements [Index]..[Index+Len-1]. Size and Complex properties of the calling object must be set explicitly. An exception is raised if array borders are overrun. *) function ArcCsch(const X: TOpenCLMtxVec; XIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*The cube root. Calculate the cube root of all calling object elements in-place. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TOpenCLVector a; clMtxVec.CreateIt(out a); try { a.CopyCplxFromArray( new double[] {1,8}); a.Cbrt(); // a = [1,2] } finally { clMtxVec.FreeIt(ref a); } } } *) function Cbrt: TOpenCLMtxVec; overload; (*Calculate the cube root of calling object elements [Index]..[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function Cbrt(Index, Len: integer): TOpenCLMtxVec; overload; (*Calculate the cube root of all X object elements. Store the results in calling object. Size and Complex properties of calling object are adjusted automatically. *) function Cbrt(const X: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Calculate the cube root of X object elements [XIndex]..[XIndex+Len-1]. The results are stored in the calling object elements [Index]..[Index+Len-1]. Size and Complex properties of the calling object must be set explicitly. An exception is raised if array borders are overrun. *) function Cbrt(const X: TOpenCLMtxVec; XIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Rounds towards positive infinity. Rounds all calling object elements towards positive infinity in-place. Ceil(-2.8) = -2 Ceil(2.8) = 3 Ceil(-1.0) = -1 *) function Ceil: TOpenCLMtxVec; overload; (*Rounds calling object elements [Index]..[Index+Len-1] towards positive infinity in-place. An exception is raised if array borders are overrun. *) function Ceil(Index,Len: integer): TOpenCLMtxVec; overload; (*Rounds all Src object elements towards positive infinity. Stores the result in the calling object. Size and Complex properties of the calling object are adjusted automatically. *) function Ceil(const Src: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Rounds Src object elements [SrcIndex]..[SrcIndex+Len-1] towards positive infinity. Stores the result in the calling object elements [Index]..[Index+Len-1] Size and Complex properties of the calling object must be set explicitly. An exception is raised if array borders are overrun. *) function Ceil(const Src: TOpenCLMtxVec; SrcIndex, Index,Len: integer): TOpenCLMtxVec; overload; (*Natural logarithm. Calculate the natural log for all calling object elements in-place. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TOpenCLVector a; clMtxVec.CreateIt(out a); try { a.CopyFromArray( new double[] {1,8}); a.Ln(); } finally { clMtxVec.FreeIt(ref a); } } } *) function Ln: TOpenCLMtxVec; overload; (*Calculate the natural algorithm for all X elements. Store the results in the calling object. Size and Complex properties of the calling vector are set implicitly to match the X object. *) function Ln(const X: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Calculate the natural logarithm for calling object elements [Index]..[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function Ln(Index, Len: integer): TOpenCLMtxVec; overload; (*Calculate the natural logarithm for X elements [XIndex]..[XIndex+Len-1]. Store the results in the calling object elements [Index]..[Index+Len-1]. Size and Complex properties of the calling object must be set explicitly. An exception is raised if array borders are overrun. *) function Ln(const X: TOpenCLMtxVec; XIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Log base 10. Calculate the log base 10 for all calling object elements in-place. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TOpenCLVector a; clMtxVec.CreateIt(out a); try { a.CopyFromArray( new double[] {10,100,1000,10000}); a.Log10(); // a = [1,2,3,4] } finally { clMtxVec.FreeIt(ref a); } } } *) function Log10: TOpenCLMtxVec; overload; (*Calculate the log base 10 for all X elements. Store the results in the calling object. Size and Complex properties of the calling vector are set implicitly to match the X object. *) function Log10(const X: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Calculate the log base 10 for calling object elements [Index]..[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function Log10(Index, Len: integer): TOpenCLMtxVec; overload; (*Calculate the log base 10 for X elements [XIndex]..[XIndex+Len-1]. Store the results in the calling object elements [Index]..[Index+Len-1]. Size and Complex properties of the calling object must be set explicitly. An exception is raised if array borders are overrun. *) function Log10(const X: TOpenCLMtxVec; XIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Log base 2. Calculate the log base 2 for all calling object elements in-place. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TOpenCLVector a; clMtxVec.CreateIt(out a); try { a.CopyFromArray( new double[] {1,2,4,8}); a.Log2(); // a = [0,1,2,3] } finally { clMtxVec.FreeIt(ref a); } } } *) function Log2: TOpenCLMtxVec; overload; (*Calculate the log base 2 for all X elements. Store the results in the calling object. Size and Complex properties of the calling vector are set implicitly to match the X object. *) function Log2(const X: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Calculate the log base 2 for calling object elements [Index]..[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function Log2(Index, Len: integer): TOpenCLMtxVec; overload; (*Calculate the log base 2 for X elements [XIndex]..[XIndex+Len-1]. Store the results in the calling object elements [Index]..[Index+Len-1]. Size and Complex properties of the calling object must be set explicitly. An exception is raised if array borders are overrun. *) function Log2(const X: TOpenCLMtxVec; XIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Exponent (e^). Calculate the exponent (e^) for all calling object elements in-place. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TOpenCLVector a; clMtxVec.CreateIt(out a); try { a.CopyFromArray( new double[] {1,System.Math.E}); a.Exp(); // a = [0.0,1.00000] } finally { clMtxVec.FreeIt(ref a); } } } *) function Exp: TOpenCLMtxVec; overload; (*Calculate the exponent (e^) for all X elements. Store the results in the calling object. Size and Complex properties of the calling vector are set implicitly to match the X object. *) function Exp(const X: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Calculate the exponent (e^) for calling object elements [Index]..[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function Exp(Index, Len: integer): TOpenCLMtxVec; overload; (*Calculate the exponent (e^) for X elements [XIndex]..[XIndex+Len-1]. Store the results in the calling object elements [Index]..[Index+Len-1]. Size and Complex properties of the calling object must be set explicitly. An exception is raised if array borders are overrun. *) function Exp(const X: TOpenCLMtxVec; XIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Exponent base 2 (2^). Calculate the exponent base 2 (2^) for all calling object elements in-place. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TOpenCLVector a; clMtxVec.CreateIt(out a); try { a.CopyFromArray( new double[] {1,2,3,4}); a.Exp2(); // a = [1,4,9,16] } finally { clMtxVec.FreeIt(ref a); } } } *) function Exp2: TOpenCLMtxVec; overload; (*Calculate the exponent base 2 (2^) for all X elements. Store the results in the calling object. Size and Complex properties of the calling vector are set implicitly to match the X object. *) function Exp2(const X: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Calculate the exponent base 2 (2^) for calling object elements [Index]..[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function Exp2(Index, Len: integer): TOpenCLMtxVec; overload; (*Calculate the exponent base 2 (2^) for X elements [XIndex]..[XIndex+Len-1]. Store the results in the calling object elements [Index]..[Index+Len-1]. Size and Complex properties of the calling object must be set explicitly. An exception is raised if array borders are overrun. *) function Exp2(const X: TOpenCLMtxVec; XIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Exponent base 10 (10^). Calculate the exponent base 10 (10^) for all calling object elements in-place. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TOpenCLVector a; clMtxVec.CreateIt(out a); try { a.CopyFromArray( new double[] {1,2,3,4}); a.Exp10(); // a = [10,100,1000,10000] } finally { clMtxVec.FreeIt(ref a); } } } *) function Exp10: TOpenCLMtxVec; overload; (*Calculate the exponent base 10 (10^) for all X elements. Store the results in the calling object. Size and Complex properties of the calling vector are set implicitly to match the X object. *) function Exp10(const X: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Calculate the exponent base 10 (10^) for calling object elements [Index]..[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function Exp10(Index, Len: integer): TOpenCLMtxVec; overload; (*Calculate the exponent base 10 (10^) for X elements [XIndex]..[XIndex+Len-1]. Store the results in the calling object elements [Index]..[Index+Len-1]. Size and Complex properties of the calling object must be set explicitly. An exception is raised if array borders are overrun. *) function Exp10(const X: TOpenCLMtxVec; XIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Gets the imaginary part of a complex object. Gets the imaginary part of a complex object Vec and stores the real results in the calling object. Size and Complex properties of the calling object are set implicitly to match Vec object. Vec Complex must be true otherwise the exception will be raised. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TOpenCLVector a,b; clMtxVec.CreateIt(out a, out b); try { a.CopyCplxFromArray(new double[] {1,2,3,4}); // a= [1+2i, 3+4i] b.ImagPart(a); // b = [2, 4] } finally { clMtxVec.FreeIt(ref a,ref b); } } } *) function ImagPart(const Vec: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Gets the imaginary part of complex object Vec elements [VecIndex]..[VecIndex+Len-1]. Stores the result in calling object. An exception is raised if the calling object is complex, if Vec is not complex or if array borders are overrun/underrun. *) function ImagPart(const Vec: TOpenCLMtxVec; VecIndex,Index,Len: integer): TOpenCLMtxVec; overload; (*Power (integer exponent). Calculate the power ^(Exponent) for all caling object elements using the integer parameter Exponent. For non integer exponents, the and methods can be used. var a: TOpenCLVector; begin CreateIt(a); try a.CopyFromArray(TSingleArray.Create(1,2,3,4)); a.IntPower(3); finally FreeIt(a); end; end; *) function IntPower(Exponent: Integer): TOpenCLMtxVec; overload; (*Calculate the power Base^(Exponent) for all Base object elements. Calclation uses the integer Exponent value and stores the results in calling object. Size and Complex properties of calling object are adjusted automatically. *) function IntPower(const aBase: TOpenCLMtxVec; Exponent: Integer): TOpenCLMtxVec; overload; (*Inverse elements. Calculates the inverse of all calling object elements in-place without limiting inverse operation. 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}); b.Inv(a); // b = [1.0, 0.5, 0.3333, 0.25] } finally { clMtxVec.FreeIt(ref a, ref b); } } } *) function Inv: TOpenCLMtxVec; overload; (*Calculate the inverse of calling object elements [Index]..[Index+Len-1] in-place. An exception is raised if array borders are overrun/underrun. *) function Inv(Index, Len: integer): TOpenCLMtxVec; overload; (*Calculate the inverse of all X object elements without limiting operating. Store the results in calling object. Size and Complex property of calling object are adjusted automatically. *) function Inv(const X: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Calculate the inverse of X object elements [XIndex]..[XIndex+Len-1] without limiting operating. Store the results in calling object elements [Index]..[Index+Len-1]. An exception is raised if X and calling object Complex property does not match or array borders are overrun/underrun. *) function Inv(const X: TOpenCLMtxVec; XIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Converts elements from cartesian to polar coordinate form. Converts all calling object elements from cartesian to polar coordinate form, storing the magnitude (radius) component of corresponding elements in the AmpltVec and the phase (angle) component of corresponding elements in the PhaseVec. If you want to use this method then the calling matrix Complex property must be true. If this is not the case, an exception is raised. Size and Complex properties of AmpltVec and PhaseVec are set automatically. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TOpenCLMatrix A, Ampl, Phase; clMtxVec.CreateIt(out A, out Ampl, out Phase); try { a.SetIt(2, 2, true, new double[] {1,0, 2,0, 2,0, 4,1}); A.CartToPolar(Amplt, Phasw); } finally { clMtxVec.FreeIt(ref A, ref Amplt, ref Phase); } } } *) procedure CartToPolar(const AmpltVec, PhaseVec: TOpenCLMtxVec); overload; (*Convert calling object elements [Index] to [Index+Len-1] from cartesian to polar form. Store the results in AmpltVec (radius values) and PhaseVec(phase values). Size and Complex properties of the calling vector must be set explicitly. An exception is raised if array borders are overrun or underrun. *) procedure CartToPolar(const AmpltVec, PhaseVec: TOpenCLMtxVec; AmpltIndex, PhaseIndex, Index, Len: integer); overload; (*Add each of Vec elements to corresponding elements in the calling object. In addition, the following formula is being used: result = result+ aScale*Vec The results are stored in the calling object. Size and Complex properties of the calling object are set implicitly to match the Vec object. *) function AddScaled(const Vec: TOpenCLMtxVec; const aScale: double): TOpenCLMtxVec; overload; (*Add each of Vec elements to corresponding elements in the calling object. In addition, the following formula is being used: result = result+ aScale*Vec . The results are stored in the calling object. Size and Complex properties of the calling object are set implicitly to match the Vec object. *) function AddScaled(const Vec: TOpenCLMtxVec; const aScale: TCplx): TOpenCLMtxVec; overload; (*Adds Vec elements [VecIndex]..[VecIndex+Len-1] to calling object elements [Index]..[Index+Len-1]. In addition, the following formula is being used: result = result+ Cplx(aScale)*Vec An exception is raised if array borders are overrun. *) function AddScaled(const Vec: TOpenCLMtxVec; const aScale: double; VecIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Adds Vec elements [VecIndex]..[VecIndex+Len-1] to calling object elements [Index]..[Index+Len-1]. In addition, the following formula is being used: result = result+ aScale*Vec An exception is raised if array borders are overrun. *) function AddScaled(const Vec: TOpenCLMtxVec; const aScale: TCplx; VecIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Add a product of two vectors. Multiply Vec1 elements with coresponding Vec2 elements and add the result to the calling vector. The size of the calling vector is set implicitly. *) function AddProduct(const Vec1, Vec2: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Multiply Vec1 elements [Vec1Index]..[Vec1Index+Len-1] with Vec2 elements [Vec2Index]..[Vec2Index+Len-1] and add the results to the calling object elements [Index]..[Index+Len-1]. An exception is raised if array borders are overrun. *) function AddProduct(const Vec1, Vec2: TOpenCLMtxVec; Vec1Index, Vec2Index, Index, Len: integer): TOpenCLMtxVec; overload; (*Conjugate and multiply. Conjugate each of Vec elements and multiply them with corresponding elements in the calling object. The results are stored in the calling object. Size and Complex properties of the calling object are set implicitly to match Vec. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TVec a,b,c; MtxVec.CreateIt(out a, out b, out c); try { a.CopyFromArray( new double[] {1,2,3,4}); b.CopyFromArray( new double[] {4,3,,2,1}); c.ConjMul(a,b); } finally { MtxVec.FreeIt(ref a,ref b,ref c); } } } *) function ConjMul(const Vec: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Conjugate Vec elements Vec[VecIndex]..Vec[VecIndex+Len-1] and multiply them with corresponding calling object elements [Index]..[Index+Len-1]. The results are stored in the calling object elements [Index]..[Index+Len-1]. Size and Complex properties are not set. An exception is raised if array borders are overrun or underrun. *) function ConjMul(const Vec: TOpenCLMtxVec; VecIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Conjugate each of Vec2 elements and multiply them with corresponding elements in Vec1. The results are stored in the calling object. Size and Complex properties of the calling object are set implicitly to match Vec1 and Vec2 objects. *) function ConjMul(const Vec1, Vec2: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Conjugate Vec2 elements [Vec2Index]..[Vec2Index+Len-1] and multiply them with corresponding Vec1 elements [Vec1Index]..[Vec1Index+Len-1]. The results are stored in the calling object elements [Index]..[Index+Len-1]. Size and Complex properties of the calling vector must be set explicitly. An exception is raised if array borders are overrun. *) function ConjMul(const Vec1, Vec2: TOpenCLMtxVec; Vec1Index, Vec2Index, Index, Len: integer): TOpenCLMtxVec; overload; (*Divide each of Num elements with corresponding elements in Den. Size and Complex property of the calling object are set automatically. The result is stored in the calling object. The result of division by zero will be the INF constant. Division of zero by zero will result in NAN. *) function Divide(const Num, Den: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Divide each of calling vector elements with corresponding elements in the Vec object. Size and Complex property of the calling object are set automatically. The result is stored in the calling object. The result of division by zero will be the INF constant. Division of zero by zero will result in NAN. *) function Divide(const Vec: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Divide calling vector elements [Index]...[Index+Len-1] with corresponding elements [VecIndex]...[VecIndex+Len-1] from the Vec object. Store the result in the claling vector. The Length of the calling vector is not changed. An exception is raised if array borders are overrun or underrun. The result of division by zero will be the INF constant. Division of zero by zero will result in NAN. *) function Divide(const Vec: TOpenCLMtxVec; VecIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Divide [NumIndex]..[NumIndex+Len-1] Num elements with [DenIndex]..[DenIndex+Len-1] elements in Den. and store result in the calling vector at positions [Index]..[Index+Len-1] and Complex property of the calling object are not changed. An exception is raised if array borders are overrun or underrun. The result of division by zero will be the INF constant. Division of zero by zero will result in NAN. *) function Divide(const Num, Den: TOpenCLMtxVec; NumIndex, DenIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Divide Value with elements of the calling object and store the result in the calling object.*) function DivideBy(const Value: double): TOpenCLMtxVec; overload; (*Divide complex Value with elements of the calling object. Store the result in the calling object. *) function DivideBy(const Value: TCplx): TOpenCLMtxVec; overload; (*Divide Value with elements [Index]...[Index+Len-1] from the calling object. Store the result in the calling object at position [Index]...[Index+Len-1]. An exception will be raised if array borders are overrun or underrun. *) function DivideBy(const Value: double; Index, Len: integer): TOpenCLMtxVec; overload; (*Divide complex Value with elements [Index]...[Index+Len-1] from the calling object. Store the result in the calling object at position [Index]...[Index+Len-1]. Calling vector will be extended to complex, if the calling vector is real. An exception will be raised if array borders are overrun or underrun. *) function DivideBy(const Value: TCplx; Index, Len: integer): TOpenCLMtxVec; overload; (*Divide Value with elements from Vec and store the result in the corresponding elements of the calling object. Size and Complex properties of the calling object are set automatically. *) function DivideBy(const Value: double; const Vec: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Divide complex Value with elements from Vec and store the result in the corresponding elements of the calling object. Size of the calling object is set automatically. Complex property of the calling object is set to True. *) function DivideBy(const Value: TCplx; const Vec: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Divide Value with Vec elements [VecIndex]..[VecIndes+Len-1]. Store the result in the elements [Index]..[Index+Len-1] of the calling object. Size of the calling object is not changed. An exception will be raised array borders are overrun or underrun. Complex property of the calling object is set implicitly. *) function DivideBy(const Value: double; const Vec: TOpenCLMtxVec; VecIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Divide complex Value with elements [VecIndex]..[VecIndes+Len-1] from Vec. Store the result in the elements [Index]..[Index+Len-1] of the calling object. Size of the calling object is not changed. An exception will be raised array borders are overrun or underrun. Complex property of the calling object is set to True. *) function DivideBy(const Value: TCplx; const Vec: TOpenCLMtxVec; VecIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Reverse vector elements. The method reverses Vec vector elements from [VecIndex].. [VecIndex+Len-1] and stores them in the calling vector from [Index]...[Index+Len-1] by using the following equation: This overload reverses calling vector elements in-place. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { MtxVec.CreateIt(out a); try { a.CopyFromArray( new double[] {1,2,3,4); a.Reverse(); // a = [4,3,2,1] } finally { MtxVec.FreeIt(ref a); } } } *) function Reverse(const Vec: TOpenCLMtxVec; VecIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Reverses the calling object elements [Index]..[Index+Len-1]. An exception is raised if array borders are overrun. *) function Reverse(Index, Len: integer): TOpenCLMtxVec; overload; (*A cyclic shift on vector elements in range. Performs cyclic shift on source vector elements in specified range [Index..Index+Len] and stores them to calling vector. The number of elements to shift is specified in the Offset parameter. Offset can be any integer number, positive or negative. *) function Rotate(const Vec: TOpenCLMtxVec; Offset: integer; VecIndex,Index: integer; Len: integer): TOpenCLMtxVec; overload; (*A shift on vector elements in range. Performs shift on source vector elements in specified range [Index..Index+Len] and stores them to calling vector. The number of elements to shift is specified in the Offset parameter. Offset can be any integer number, positive or negative. *) function Shift(const Vec: TOpenCLMtxVec; Offset: integer; VecIndex,Index: integer; Len: integer = MtxVecEOA): TOpenCLMtxVec; overload; (*Subtracts Value from object elements. Subtracts Value from all calling object elements. *) function Sub(const Value: double): TOpenCLMtxVec; overload; (*Subtracts complex Value from all calling object complex elements.*) function Sub(const Value: TCplx): TOpenCLMtxVec; overload; (*Subtracts Value from calling object elements [Index]..[Index+Len-1]. An exception is raised if array borders are overrun. *) function Sub(const Value: double; Index, Len: integer): TOpenCLMtxVec; overload; (*Subtracts complex Value from calling object complex elements [Index]..[Index+Len-1]. An exception is raised if array borders are overrun. *) function Sub(const Value: TCplx; Index, Len: integer): TOpenCLMtxVec; overload; (*Subtract real Value from Src. Store the results in calling object. Size and Complex property of calling object are adjusted automatically. *) function Sub(const Src: TOpenCLMtxVec; const Value: double): TOpenCLMtxVec; overload; (*Subtract complex Value from Src. Store the results in calling object. Size and Complex property of calling object are adjusted automatically. *) function Sub(const Src: TOpenCLMtxVec; const Value: TCplx): TOpenCLMtxVec; overload; (*Subtract real Value from Src elements [SrcIndex]..[SrcIndex+Len-1]. Stores the result in calling object elements [Index]..[Index+Len-1]. Size and Complex properties of the calling object must be set explicitly. An exception is raised if array borders are overrun or underrun. *) function Sub(const Src: TOpenCLMtxVec; const Value: double; SrcIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Subtract complex Value from Src elements [SrcIndex]..[SrcIndex+Len-1]. Stores the result in calling object elements [Index]..[Index+Len-1]. Size and Complex properties of the calling object must be set explicitly. An exception is raised if array borders are overrun or underrun. *) function Sub(const Src: TOpenCLMtxVec; const Value: TCplx; SrcIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Array subtraction. Subtract each of Vec elements from corresponding elements in the calling object. An exception is raised if Vec and calling object size and Complex properties do not match. *) function Sub(const Vec: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Subtract Vec2 elements from Vec1 elements. Stores the results in calling object. Size and Complex property of calling object are adjusted automatically. An exception is raised if Vec1 and Vec2 size and Complex property do not match. *) function Sub(const Vec1, Vec2: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Subtract Vec elements [VecIndex]..[VecIndex+Len-1] from corresponding calling object elements [Index]..[Index+Len-1]. The results are stored in the calling object elements [Index]..[Index+Len-1]. Size and Complex properties of the calling object must be set explicitly. An exception is raised if array borders are overrun or underrun. *) function Sub(const Vec: TOpenCLMtxVec; VecIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Subtract Vec22 elements [Vec2Index]..[Vec2Index+Len-1] from Vec1 object elements [Vec1Index]..[Vec1Index+Len-1]. Stores the results in calling object elements [Index]..[Index+Len-1]. Size and Complex properties of the calling object must be set explicitly. An exception is raised if array borders are overrun or underrun. *) function Sub(const Vec1, Vec2: TOpenCLMtxVec; Vec1Index, Vec2Index, Index, Len: integer): TOpenCLMtxVec; overload; (*Subtraction from value. Subtract each of calling object elements from Value. *) function SubFrom(const Value: double): TOpenCLMtxVec; overload; (*Subtract each of calling object elements from complex Value. If the calling vector s not complex, the conversion is performed automatically in a performance efficient way. *) function SubFrom(const Value: TCplx): TOpenCLMtxVec; overload; (*Subtract elements [Index]..[Index+Len-1] from Value. Store the result in calling vector. An exception is raised if array borders are overrun or underrun. *) function SubFrom(const Value: double; Index, Len: integer): TOpenCLMtxVec; overload; (*Subtract elements [Index]..[Index+Len-1] from complex Value. Store the result in calling object. If the calling vector is not complex, the conversion to complex is performed automatically in performance efficient way. An exception is raised if array borders are overrun or underrun. *) function SubFrom(const Value: TCplx; Index, Len: integer): TOpenCLMtxVec; overload; (*Substract Vec elements from Value. Stores the result in the calling object. Size and Complex properties of calling object are adjusted automatically. *) function SubFrom(const Value: double; const Vec: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Substract complex Vec elements from Value. Stores the result in the calling object. Size property of the calling object is set automatically. Complex property of the calling object is set to True. *) function SubFrom(const Value: TCplx; const Vec: TOpenCLMtxVec): TOpenCLMtxVec; overload; (*Substract Vec elements [VecIndex]..[VecIndex+Len-1] from Value. Stores the result to the calling object elements [Index]..[Index+Len-1]. Size property of the calling object is not changed. An exception is raised if array borders are overrun or underrun. Complex property of the calling object is adjusted automatically. *) function SubFrom(const Value: double; const Vec: TOpenCLMtxVec; VecIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Substract Vec elements [VecIndex]..[VecIndex+Len-1] from complex Value and store the result to the calling object elements [Index]..[Index+Len-1]. Size property of the calling object is not changed. An exception is raised if array borders are overrun or underrun. Complex property of the calling object is set to True. *) function SubFrom(const Value: TCplx; const Vec: TOpenCLMtxVec; VecIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Inserts zeroes between consecutive array values. Copy Len values from Src starting at SrcIndex to the calling object starting at position Index and place Factor-1 zeros between consecutive values. Size and Complex properties of the calling object must be set explicitly. Phase parameter defines the initial sample offset and must be less then Factor. An exception is raised, if array borders are overrun/underrun. *) function UpSample(const Src: TOpenCLMtxVec; Factor,SrcIndex, Index, Len: integer; Phase: integer = 0): TOpenCLMtxVec; overload; (*Downsamples object values. Copy only every Factor sample from Src starting at SrcIndex up to Len to the calling object starting at Index. The phase parameter determines the initial sample offset. Phase must be less then Factor. Size and Complex properties of the calling object are set implicitly. An exception is raised if array borders are overrun/underrun. *) function DownSample(const Src: TOpenCLMtxVec; Factor, SrcIndex, Index, Len: integer; Phase: integer = 0): TOpenCLMtxVec; overload; (*Difference. Calculate the difference for Vec elements [VecIndex]..[VecIndex+Len-1] and store the results in the calling object elements [Index]..[Index+Len-1]. Size and Complex properties of the calling vector must be set explicitly. The following formula is used to calculate the difference: An exception is raised if array borders are overrun or underrun. *) function Difference(const Vec: TOpenCLMtxVec; VecIndex, Index, Len: integer): TOpenCLMtxVec; overload; (*Sums vector values. the sum of all calling object elements. An exception is raised if calling object Complex property is true. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TOpenCLVector a; clMtxVec.CreateIt(out a); try { a.CopyFromArray(new double[] {1,3,-2}); doouble s = a.Sum(); // s = 2 } finally { clMtxVec.FreeIt(ref a); } } } *) function Sum: double; overload; (*Returns the sum of calling object elements [Index]..[Index+Len-1]. An exception is raised if calling object Complex property is True or array borders are overrun/underrun. *) function Sum(Index,Len: integer): double; overload; (*Calculates the sum of calling object elements [Index]..[Index+Len-1]. Stores the result in real ASum variable. An exception is raised if calling object Complex property is True or array borders are overrun/underrun. *) procedure Sum(out ASum: double; Index, Len: integer); overload; (*Calculates the sum of all calling object complex elements. Stores the result in complex ASum variable. An exception is raised if calling object Complex property is False. *) procedure Sum(out ASum: TCplx); overload; (*Calculates the sum of calling object complex elements [Index]..[Index+Len-1]. Stores the result in complex ASum variable. An exception is raised if calling object Complex property is False or array borders are overrun/underrun. *) procedure Sum(out ASum: TCplx; Index, Len: integer); overload; (*Sum (complex value). the complex sum of all calling object complex elements. An exception is raised if calling object Complex property is False. *) function Sumc: TCplx; overload; (*Returns the complex sum of calling object complex elements [Index]..[Index+Len-1]. An exception is raised if calling object Complex property is False or array borders are overrun/underrun. *) function Sumc(Index,Len: integer): TCplx; overload; (*Maximum value. the maximum value of all calling object elements. The result is a real value. An exception is raised is calling object Complex is true. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TOpenCLVector a; clMtxVec.CreateIt(out a); try { a.CopyFromArray( new double[] {1,2,3,4}); double b = a.Max(); // 4.0 } finally { clMtxVec.FreeIt(ref a); } } } *) function Max: double; overload; (*Returns the maximum value from calling object elements [Index]..[Index+Len-1]. The result is a real value. An exception is raised if calling object Complex property is true or array borders are overrun. *) function Max(Index,Len: integer): double; overload; (*Calculate the maximum value from calling object elements [Index]..[Index+Len-1]. The result AMean is a real value. An exception is raised if calling object Complex property is true or array borders are overrun. *) procedure Max(out AMax: double; Index,Len: integer); overload; (*Calculate the maximum value of all calling object elements. The AMax parameter returns the maximum value. The aIndex parameter returns the index of maximum value. An exception is raised if calling object Complex property is true. *) procedure Max(out AMax: double; out aIndex: integer); overload; (*Calculate the maximum value of calling object elements [Index]..[Index+Len-1]. The AMax parameter returns the maximum value. The aIndex parameter returns the index of maximum value. An exception is raised if calling object Complex property is true or array borders are overrud/underrun. *) procedure Max(out AMax: double; out aIndex: integer; Index, Len: integer); overload; (*Same as method.*) function Max(out AMax: TCplx; Index, Len: integer): integer; overload; (*Maximum value. the maximum value of all calling object complex elements. Complex elements are first compared by the amplitude and then by the argument. An exception is raised if calling object Complex is . *) function Maxc: TCplx; overload; (*Returns the maximum value of calling object complex elements [Index]..[Index+Len-1]. The result is a complex value. Complex elements are first compared by the amplitude and then by the argument. An exception is raised if calling object Complex property is or array borders are overrud/underrun. *) function Maxc(Index,Len: integer): TCplx; overload; (*Calculate the maximum value of calling object complex elements [Index]..[Index+Len-1]. The AMax parameter returns complex maximum value. Returns the index of maximum value. Complex elements are first compared by the amplitude and then by the argument. The aIndex parameter returns the index of maximum value. An exception is raised if calling object Complex property is or array borders are overrud/underrun. *) function Maxc(out AMax: TCplx; Index, Len: integer): integer; overload; (*Maximum and minimum value in a single pass. Calculates the maximum and minimum value of all calling object elements in a single pass. Maximum value is stored in AMax parameter, minimum value is stored in AMin parameter. Use this method if you require minimum AND maximum value. *) procedure MaxMin(out AMax,AMin: double); overload; (*Calculates the maximum and minimum value of calling object elements [Index]..[Index+Len-1]. Maximum value is stored in AMax parameter, minimum value is stored in AMin parameter. An exception is raised if calling object Complex property is true or array borders are overrud/underrun. *) procedure MaxMin(out AMax,AMin: double; Index, Len: integer); overload; (*Calculates the maximum and minimum value of all calling object elements. Maximum value is returned in AMax parameter, minimum value in AMin parameter. The MaxIdx parameter returns the index of maximum value. The MinIdx parameter returns the index of minimum value. An exception is raised if calling object Complex property is true. *) procedure MaxMin(out AMax: double; out MaxIdx: integer; out AMin: double; out MinIdx: integer); overload; (*Calculates the maximum and minimum value of calling object elements [Index]..[Index+Len-1]. Maximum value is returned in AMax parameter, minimum value in AMin parameter. The MaxIdx parameter returns the index of maximum value. The MinIdx parameter returns the index of minimum value. An exception is raised if calling object Complex property is true or if array borders are overrun/underrun. *) procedure MaxMin(out AMax: double; out MaxIdx: integer; out AMin: double; out MinIdx: integer; Index, Len: integer); overload; (*Mean value. Calculate the mean value of all calling object elements. The result is a real value. An exception is raised if calling object Complex property is true. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TOpenCLVector a; clMtxVec.CreateIt(out a); try { a.CopyFromArray(, new double[] {1,2,3,4}); double m = a.Mean(); // 2.5 } finally { clMtxVec.FreeIt(ref a); } } } *) function Mean: double; overload; (*Returns real mean value from calling object elements [Index]..[Index+Len-1]. An exception is raised if calling object Complex property is true or array borders are overrun. *) function Mean(Index, Len: integer): double; overload; (*Calculate the mean value from calling object elements [Index]..[Index+Len-1]. The result AMean is a real value. An exception is raised if calling object Complex property is true or array borders are overrun/underrun. *) procedure Mean(out AMean: double; Index, Len: integer); overload; (*Same as .*) procedure Mean(out AMean: TCplx); overload; (*Same as .*) procedure Mean(out AMean: TCplx; Index, Len: integer); overload; (*Mean value. the mean value of all calling object complex elements. The result is a complex value. An exception is raised is calling object Complex is . *) function Meanc: TCplx; overload; (*Returns complex mean value from calling object complex elements [Index]..[Index+Len-1]. An exception is raised if calling object Complex property is or array borders are overrun/underrun. *) function Meanc(Index, Len: integer): TCplx; overload; (*Calculate the mean value from all calling object complex elements. The result AMean is a complex value. An exception is raised if calling object Complex property is . *) procedure Meanc(out AMean: TCplx); overload; (*Calculate the mean value from calling object complex elements [Index]..[Index+Len-1]. The result AMean is a complex value. An exception is raised if calling object Complex property is or array borders are overrun/underrun. *) procedure Meanc(out AMean: TCplx; Index, Len: integer); overload; (*Minimum value. The minimum value of all calling object elements. The result is a real value. An exception is raised if calling object Complex property is true. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TOpenCLVector a; clMtxVec.CreateIt(out a); try { a.CopyFromArray(, new double[] {1,2,3,4}); double b = a.Min(); // 1.0 } finally { clMtxVec.FreeIt(ref a); } } } *) function Min: double; overload; (*Calculate the minimum value from calling object elements [Index]..[Index+Len-1]. The result is a real value. An exception is raised if calling object Complex property is true or array borders are overrun. *) function Min(Index,Len: integer): double; overload; (*Calculate the minimum value from calling object elements [Index]..[Index+Len-1]. The result AMin is a real value. An exception is raised if calling object Complex property is true or array borders are overrun. *) procedure Min(out AMin: double; Index,Len: integer); overload; (*Calculate the minimum value of calling object elements [Index]..[Index+Len-1]. The AMax parameter returns the minimum value. The aIndex parameter returns the index of minimum value. An exception is raised if calling object Complex property is true or array borders are overrud/underrun. *) procedure Min(out AMin: double; out aIndex: Integer; Index, Len: integer); overload; (*Calculate the minimum value of all calling object elements. The AMin parameter returns the minimum value. The aIndex parameter returns the index of minimum value. An exception is raised if calling object Complex property is true. *) procedure Min(out AMin: double; out aIndex: integer); overload; (*Same as the method.*) function Min(out AMin: TCplx; Index, Len: integer): integer; overload; (*Minimum value. Returns the minimum value of all calling object complex elements. Complex elements are first compared by the amplitude and then by the argument. An exception is raised if calling object Complex is . *) function Minc: TCplx; overload; (*Returns the minimum value of calling object complex elements [Index]..[Index+Len-1]. The result is a complex value. Complex elements are first compared by the amplitude and then by the argument. An exception is raised if calling object. Complex property is or array borders are overrud/underrun. *) function Minc(Index,Len: integer): TCplx; overload; (*Calculate the minimum value of calling object complex elements [Index]..[Index+Len-1]. The AMin parameter returns complex minimum value. Returns the index of minimum value. Complex elements are first compared by the amplitude and then by the argument. An exception is raised if calling object Complex property is or array borders are overrun/underrun. *) function Minc(out AMin: TCplx; Index, Len: integer): integer; overload; (*The C-norm. C norm: ||V-Vec||, where V is the calling vector. If the NormC is called without any parameters, the NormC calculates the norm of the calling vector. The C norm of ||V-Vec|| is defined by the formula: If RelativeError is true then the computed norm is divided by the norm of V, and the function returns the "relative error": 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.NormC(b,true); } finally { clMtxVec.FreeIt(ref a,ref b); } } } *) function NormC(const Vec: TOpenCLMtxVec; RelativeError: boolean = false): double; overload; (*Calculates the C norm ||V-Vec|| between Vec elements [VecIndex]..[VecIndex+Len-1] and calling vector elements [Index]..[Index+Len-1].*) function NormC(const Vec: TOpenCLMtxVec; VecIndex,Index,Len: integer; RelativeError: boolean = false): double; overload; (*Calculate the C-norm of calling vector. NormC = max|a[i]|, 0 < i < Length-1 .*) function NormC: double; overload; (*Calculates the C norm from calling vector elements [Index]..[Index+Len-1].*) function NormC(Index,Len: integer): double; overload; (*The L1-norm. L-1 norm, defined by: ||V-Vec||, where V is calling vector. If the NormL1 is called without any parameters, the NormL1 calculates the norm of calling vector. The L1 norm of ||V-Vec|| is defined by the formula: If RelativeError is true then the computed norm is divided by the norm of V, and the function returns the "relative error": 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.NormL1(b,true); } finally { clMtxVec.FreeIt(ref a,ref b); } } } *) function NormL1(const Vec: TOpenCLMtxVec; RelativeError: boolean = false): double; overload; (*Calculates the L1 norm ||V-Vec|| between Vec elements [VecIndex]..[VecIndex+Len-1] and calling vector elements [Index]..[Index+Len-1].*) function NormL1(const Vec: TOpenCLMtxVec; VecIndex,Index,Len: integer; RelativeError: boolean = false): double; overload; (*Calculate the L1-norm of the calling vector. L-1 norm, defined by the following equation: NormL1 = Sum(|a[i]|), 0 < i < Length-1*) function NormL1: double; overload; (*Calculates the L1 norm from calling vector elements [Index]..[Index+Len-1].*) function NormL1(Index,Len: integer): double; overload; (*The L2-norm. L2 norm, defined by ||V-Vec||, where V is calling vector. 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: If RelativeError is true then the computed norm is divided by the norm of V, and the function returns the "relative error": 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); } } } *) function NormL2(const Vec: TOpenCLMtxVec; RelativeError: boolean = False): double; overload; (*Calculates the L2 norm ||V-Vec|| between Vec elements [VecIndex]..[VecIndex+Len-1] and calling vector elements [Index]..[Index+Len-1].*) function NormL2(const Vec: TOpenCLMtxVec; VecIndex,Index,Len: integer; RelativeError: boolean = False): double; overload; (*Calculate the L2-norm of the calling vector. L2 norm, defined by: NormaL2 = ( Sum(|a[i]|^2) )^0.5 , 0 < i < Length-1 .*) function NormL2: double; overload; (*Calculates the L2 norm from calling vector elements [Index]..[Index+Len-1].*) function NormL2(Index,Len: integer): double; overload; (*Computes the sum and the sum of squared elements from the elements in the calling object.*) procedure SumAndSqrSum(out Sum, SqrSum: double); overload; (*Returns the sum and the sum of squared elements. Returns the sum and the sum of squared items from calling vector elements [Index]..[Index+Len-1]. *) procedure SumAndSqrSum(out Sum, SqrSum: double; Index, Len: integer); overload; (*Standard deviation. Calculate the standard deviation of all calling object elements. The result is a real value. An exception is raised if calling vector Complex property is true. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TOpenCLVector a; clMtxVec.CreateIt(out a); try { a.CopyFromArray(new double[] {-1,2,-3,4)); double c = a.StdDev(); } finally { clMtxVec.FreeIt(ref a); } } } *) function StdDev: double; overload; (*Returns the standard deviation of calling object elements [Index]..[Index+Len-1]. An exception is raised if calling object Complex property is true or if array borders are overrun/underrun. *) function StdDev(Index,Len: integer): double; overload; (*Returns the standard deviation of all calling object elements. The sum and the sum of squares of all calling object elements must be passed as parameters. An exception is raised if calling object Complex property is true. *) function StdDev(aSum, aSumSqr: double): double; overload; (*Returns the standard deviation of calling object elements [Index]..[Index+Len-1]. The sum and the sum of squares of the coresponding elements must be passed as parameters. An exception is raised if calling object Complex property is true or if array borders are overrun/underrun. *) function StdDev(aSum, aSumSqr: double; Index, Len: integer): double; overload; (*Standard deviation. Calculate the standard deviation of all calling object elements. The result is a real value. An exception is raised if calling vector Complex property is true. var a: clVector; c: double; aMean: double; begin a.CopyFromArray(TDoubleArray.Create(1,2,3,4)); Caption := FloatToSTr(a.RMS); end; *) function RMS: double; overload; (*Returns the root-mean-square of calling object elements [Index]..[Index+Len-1]. An exception is raised if calling object Complex property is true or if array borders are overrun/underrun. *) function RMS(Index,Len: integer): double; overload; (*Elements product. the product of all calling object elements An exception is raised if calling object Complex property is true. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TOpenCLVector a; clMtxVec.CreateIt(out a); try { a.CopyFromArray(new double[] {1,2,3,4}); double c = a.Product(); // c= 24 } finally { clMtxVec.FreeIt(ref a); } } } *) function Product: double; overload; (*Returns the product for calling object elements [Index]..[Index+Len-1]. An exception is raised if array borders are overrun or underrun. *) function Product(Index,Len: integer): double; overload; (*Calculate the product of all calling object complex elements. Store the result in complex variable X. *) procedure Product(out X: TCplx); overload; (*Calculate the product for calling object complex elements [Index]..[Index+Len-1]. Store the result in complex variable X. An exception is raised if array borders are overrun or underrun. *) procedure Product(out X: TCplx; Index,Len: integer); overload; (*Calculate the product of all calling object elements. Store the result in real variable X. *) procedure Product(out X: double); overload; (*Calculate the product for calling object elements [Index]..[Index+Len-1]. Store the result in real variable X. An exception is raised if array borders are overrun or underrun. *) procedure Product(out X: double; Index,Len: integer); overload; (*Elements product. the complex product of all calling object complext elements. An exception is raised if calling object Complex property is false. *) function Productc: TCplx; overload; (*Returns the complex product for calling object complex elements [Index]..[Index+Len-1]. An exception is raised if array borders are overrun or underrun or if Complex propety is false. *) function Productc(Index,Len: integer): TCplx; overload; (*Scalar product of two real arrays. 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: Both objects must be of equal size. If they are not, the method will return the dot product of the largest sub-array. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TOpenCLVector a,b; clMtxVec.CreateIt(out a, out b); try { a.SetIt(false, new double[] {1,2,3,4}); b.SetIt(false, new double[] {5,6,7,8}); double prod = a.DotProd(b); // = 1*5 + 2*6 + * 3*7 + 4*8 } finally { clMtxVec.FreeIt(ref a,ref b); } } } *) function DotProd(const Vec: TOpenCLMtxVec): double; overload; (*Returns the scalar product between Vec elements [VecIndex]..[VecIndex+Len-1] and calling object elements [Index]..[Index+Len-1]. An exception is raised if Vec and calling object Complex property is True. An exception is raised if array borders are overrun or underrun. *) function DotProd(const Vec: TOpenCLMtxVec; VecIndex, Index, Len: integer): double; overload; (*Scalar product of two complex arrays. Calculates the dot product (scalar value) of the calling object and Vec object and returns a complex scalar value. An exception is raised if calling or Vec object Complex property is false. The dot product is defined by the equation: Both objects must be of equal size. If they are not, the method will return the dot product of the largest sub-array. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TOpenCLVector a,b; clMtxVec.CreateIt(out a, out b); try { a.SetIt(false, new double[] {1,2,3,4}); b.SetIt(false, new double[] {5,6,7,8}); double prod = a.DotProdc(b); //= (1+2i)*(5+6i)+(3+4i)*(7+8i) } finally { clMtxVec.FreeIt(ref a,ref b); } } } *) function DotProdc(const Vec: TOpenCLMtxVec): TCplx; overload; (*Returns the scalar product between Vec (complex) elements [VecIndex]..[VecIndex+Len-1] and calling object (complex) elements [Index]..[Index+Len-1]. An exception is raised if Vec and calling object Complex property is False. An exception is raised if array borders are overrun or underrun. *) function DotProdc(const Vec: TOpenCLMtxVec; VecIndex, Index, Len: integer): TCplx; overload; (*Returns the scalar product between Vec and calling object complex elements. If ConjVec is True, scalar product between calling object and conjugated Vec object elements is calculated. An exception is raised if Vec and calling object Complex property is False. *) function DotProdc(const Vec: TOpenCLMtxVec; ConjVec: boolean): TCplx; overload; (*Returns the scalar product between Vec (complex) elements [VecIndex]..[VecIndex+Len-1] and calling object (complex) elements [Index]..[Index+Len-1]. If ConjVec is True, scalar product between calling object and conjugated Vec object elements is calculated. An exception is raised if Vec and calling object Complex property is False. An exception is raised if array borders are overrun or underrun. *) function DotProdc(const Vec: TOpenCLMtxVec; ConjVec: boolean; VecIndex, Index, Len: integer): TCplx; overload; procedure DotProd(DstIndex: integer; const Vec1, Vec2: TOpenCLMtxVec; Vec1Index, Vec2Index: integer; Len: integer; const Buffer: TOpenCLMtxVec); overload; (*Scalar product of two real or complex arrays. Calculates the dot product (scalar value) of the Vec1 and Vec2 stores the result in calling vector at position DstIndex. ConjVec parameter is ignored if data is real. If ConjVec is true, the function computes: result = Vec1*conj(Vec2) The dot product is defined by the equation: Both objects must be of equal size. If they are not, the method will return the dot product of the largest sub-array. *) procedure DotProd(DstIndex: integer; const Vec1, Vec2: TOpenCLMtxVec;ConjVec: boolean; const Buffer: TOpenCLMtxVec); overload; (*Scalar product of two real arrays. Calculates the dot product (scalar value) of the calling object and Vec object and returns a real scalar value. The result is stored at specified index in the calling vector in the GPU memory. This variant of the function is non-blocking (faster), because the result does not have to be copied to the CPU memory to be used. The dot product is defined by the equation: Both objects must be of equal size. If they are not, the method will return the dot product of the largest sub-array. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TOpenCLVector a,b,c; double[] ac; clMtxVec.CreateIt(out a, out b, out c); try { a.SetIt(false, new double[] {1,2,3,4}); b.SetIt(false, new double[] {5,6,7,8}); c.DotProd(0, a, b); // c[0] = 1*5 + 2*6 + * 3*7 + 4*8 c.DotProd(1, a, b); // c[0] = 1*5 + 2*6 + * 3*7 + 4*8 c.DotProd(2, a, b); // c[0] = 1*5 + 2*6 + * 3*7 + 4*8 c.CopyToArray(ac); //ac = [70, 70, 70] } finally { clMtxVec.FreeIt(ref a,ref b, ref c); } } } *) procedure DotProd(DstIndex: integer; const Vec1, Vec2, Buffer: TOpenCLMtxVec); overload; end; TOpenCLVector = class(TOpenCLMtxVec ) private function GetData: TVec; strict protected property Data: TVec read GetData; procedure InitData; override; procedure FreeToCache; override; function GetRealValues: string; override; function GetComplexValues: string; override; protected function DebugUpdate: integer; override; public procedure Reset; override; procedure Size(const Src: TOpenCLBase); override; function Size(const Src: TOpenCLBase; aComplex: boolean): TOpenCLBase; override; procedure Size(aLength: integer; aPrecision: TclFloatPrecision; aComplex: boolean); override; procedure SetIt(aComplex: boolean; const a: array of double); overload; procedure SetSubRange(const Src: TOpenCLMtxVec); overload; procedure SetSubRange(const Src: TOpenCLMtxVec; Index: integer; Len: integer); overload; procedure SetSubIndex(const Src: TOpenCLMtxVec); overload; procedure SetSubIndex(const Src: TOpenCLMtxVec; BeginIndex, EndIndex: integer); overload; procedure SetSubRange(Index, Len: integer); overload; override; procedure SetFullRange; override; procedure Assign(Src: TOpenCLMtxVec); virtual; (*The norm of a vector. Calculates the norm of a Vec vector and stores the results in calling vector. This functions works the same as . *) function Norm(const Vec: TOpenCLVector): TOpenCLVector; (*The difference between two succesive vector elements. Store the results in the calling vector. The Length of the calling vector is set to one less the length of Vec and Complex property is set to Vec.Complex. The following formula is used to calculate the difference: The Length of calling vector is automatically decremented by one. *) function Difference(const Vec: TOpenCLMtxVec; Lag: Integer = 1): TOpenCLVector; overload; (*Fills the calling vector with a series following linear rule. Fills the calling vector with a series following the rule: Values[k] := k (Offset is zero and Step is one). If the calling vector is complex, only the real part is set. var a: TOpenCLVector; begin clMtxVec.CreateIt(a); try a.Size(5,True); a.Ramp(0,PI); a.Sin; finally clMtxVec.FreeIt(a); end; end; which is identical to: clMtxVec.CreateIt(a); try a.Size(5,True); for i:= 0 to a.Length-1 do a[i] := sin(i * PI); finally clMtxVec.FreeIt(a); end; *) function Ramp: TOpenCLVector; overload; (*Fills the calling vector with a series. Method follow the rule: CValues[k] := Offset + k*Step. *) function Ramp(const Offset, Step: TCplx): TOpenCLVector; overload; (*Fills the calling vector. Method uses the following rule: Values[k] := Offset + k*Step. If the calling vector is complex, only the real part is set. *) function Ramp(const Offset, Step: double): TOpenCLVector; overload; (*Fills the calling vector elements [Index]..[Index+Len-1]. Method uses the following rule: Values[k] := Offset + k*Step. If the calling vector is complex, only the real part is set. An exception is raised if calling vector array borders are overrun. *) function Ramp(const Offset,Step: double; Index,Len: integer): TOpenCLVector; overload; (*Fills the calling vector elements [Index]..[Index+Len-1]. Following the rule: Values[k] := Offset + k*Step. If the calling vector is complex, only the real part is set. An exception is raised if array borders of the calling vector are overrun. *) function Ramp(const Offset, Step: TCplx; Index,Len: integer): TOpenCLVector; overload; (*The Offset is complex, but the step is real.*) function Ramp(const Offset: TCplx; const Step: double): TOpenCLVector; overload; (*Fills the calling vector elements [Index]..[Index+Len-1]. Following the rule: Values[k] := Offset + k*Step. The Offset is complex, but the step is real. *) function Ramp(const Offset: TCplx; const Step: double; Index,Len: integer): TOpenCLVector; overload; (*Inserts zeroes between consecutive vector values. Inserts zeroes between consecutive vector values. The method copies the values from Src to the calling vector and places Factor-1 zeros between consecutive values. The Length and Complex properties of the calling vector are set implicitly. Phase parameter defines the initial sample offset and must be less than Factor. var a,b: TOpenCLVector; begin clMtxVec.CreateIt(a,b); try b.CopyFromArray(TSingleArray.Create(0,0,1,3,2)); a.UpSample(b,2); // a = [0,0,0,0,1,0,3,0,2,0] finally clMtxVec.FreeIt(a,b); end; end; *) function UpSample(const Src: TOpenCLMtxVec; Factor: integer; Phase: integer = 0): TOpenCLVector; overload; (*Downsamples vector values. The methods copies only every Factor sample from the Src vector to the calling vector. The Length and Complex properties of the calling vector are set implicitly. The phase parameter determines the initial sample offset. Phase must be less than Factor. var a,b: TOpenCLVector; begin clMtxVec.CreateIt(a,b); try b.CopyFromArray(TSingleArray.Create(0,0,0,0,1,2,3,4,5,6)); a.DownSample(b,2); // a = [0,0,1,3,5] finally clMtxVec.FreeIt(a,b); end; end; *) function DownSample(const Src: TOpenCLMtxVec; Factor: integer; Phase: integer = 0): TOpenCLVector; overload; (*Reverse all Vec elements. Store the result in the calling vector elements. The Length and Complex roperties of the calling vector are set implicitly to match Vec vector. This overload reverses all vector elements. var a: TOpenCLVector; begin CreateIt(a,b); try a.CopyFromArray(TSingleArray.Create(1,2,3,4)); b.Reverse(a); // b = [4,3,2,1] finally FreeIt(a,b); end; end; *) function Reverse(const Vec: TOpenCLMtxVec): TOpenCLVector; overload; function Reverse: TOpenCLVector; overload; (*A cyclic shift on vector elements. Performs cyclic shift on vector elements. The number of elements to shift is specified in the Offset parameter. Offset can be any integer number, positive or negative. var a: TOpenCLVector; begin CreateIt(a); try a.CopyFromArray(TSingleArray.Create(1,2,3,4)); b.Rotate(a, 2); // b = [3,4,1,2] finally FreeIt(a); end; end; *) function Rotate(const Src: TOpenCLMtxVec; Offset: integer): TOpenCLVector; overload; (*Shift vector elements left or right in the array. Shifts Vec vector elements and stores the result in the calling object. The number of elements to shift is specified in the Offset parameter. Offset can be any integer number, positive or negative. *) function Shift(const Vec: TOpenCLMtxVec; Offset: integer): TOpenCLVector; overload; (*Converts the content of the calling vector to a list of strings. Converts all elements of the calling vector to strings with formating ReFormat for the real part and ImFormat for the imaginary part and stores them in aList, by using the Add method of TStringsobject. If vector is not complex only the ReFormat is used. Performance note: This routine will be exceedingly slow, if TRichEdit.Lines or TMemo.Lines are passed as a parameter for dstList. Use TStringList or StringList types and then call TMemo.Lines.AddStrings(yourList) for best results. procedure TForm1.Button1Click(Sender: TObject); var a,b: TOpenCLVector; begin clMtxVec.CreateIt(a,b); try a.SetIt(False,[1,2,3,4]); a.Cos; b.Size(a); b.SetVal(1); a.Add(b); Richedit1.Clear; Memo1.Clear; a.ValuesToStrings(Richedit1.Lines); b.ValuesToStrings(Richedit1.Lines); a.ValuesToStrings(Memo1.Lines); b.ValuesToStrings(Memo1.Lines); Memo1.Lines.SaveToFile('C:\Test.txt'); Memo1.Lines.LoadFromFile('C:\Test.txt'); finally FreeIt(a,b); end; end; *) procedure ValuesToStrings(dstList: TStrings; const ReFormat: string = ' 0.#####;-0.#####'; const ImFormat: string = '+0.#####i;-0.#####i'); overload; (*Convert elements from Index to Index+Len-1 of the calling vector to strings. Use ReFormat for the real part and ImFormat for the imaginary part and store them in aList starting at ListIndex. If aList is not large enough, the method will use the add method of aList object. If vector is not complex, only the ReFormat is used. Performance note: This routine will be exceedingly slow, if TRichEdit.Lines or TMemo.Lines are passed as a parameter for dstList. Use TStringList or StringList types and then call TMemo.Lines.AddStrings(yourList) for best results. *) procedure ValuesToStrings(dstList: TStrings; ListIndex, Index, Len: integer; const ReFormat: string = ' 0.#####;-0.#####'; const ImFormat: string = '+0.#####i;-0.#####i'); overload; (*Convert all vector elements to text.*) procedure ValuesToText(out Text: String; const ReFormat: string = ' 0.#####;-0.#####'; const ImFormat: string = '+0.#####i;-0.#####i'); overload; (*Convert Index..Index+Len-1 vector elements to text.*) procedure ValuesToText(out Text: String; Index, Len: integer; const ReFormat: string = ' 0.#####;-0.#####'; const ImFormat: string = '+0.#####i;-0.#####i'); overload; destructor Destroy; override; constructor Create(aDevice: TOpenCLDevice); override; end; TOpenCLMatrix = class(TOpenCLMtxVec ) strict private FCols: integer; FRows: integer; SCols: integer; SRows: integer; procedure SetCols(const Value: integer); procedure SetRows(const Value: integer); function GetData: TMtx; function GetCols: integer; function GetRows: integer; strict protected procedure FreeToCache; override; procedure InitData; override; procedure SetLength(const Value: integer); override; procedure DoSetComplex(Value: boolean); override; property Data: TMtx read GetData; function GetRealValues: string; override; function GetComplexValues: string; override; protected function DebugUpdate: integer; override; public constructor Create(aDevice: TOpenCLDevice); override; property Rows: integer read GetRows write SetRows; property Cols: integer read GetCols write SetCols; function Size(aRows, aCols: integer; aPrecision: TclFloatPrecision; aComplex: boolean): TOpenCLMatrix; overload; function Size(const Src: TOpenCLBase; aComplex: boolean): TOpenCLBase; overload; override; procedure Size(aLength: integer; aPrecision: TclFloatPrecision; aComplex: boolean); override; procedure Size(const Src: TOpenCLBase); override; procedure Reset; override; procedure SetFullRange; override; procedure SetSubRange(Index, Len: integer); overload; override; procedure Copy(const Src: TDenseMtxVec); overload; override; procedure Copy(const Src: TMtxVecInt); overload; override; function CopyFromArray(aRows, aCols: integer; const Src: TSingleArray): TOpenCLMtxVec; overload; function CopyFromArray(aRows, aCols: integer; const Src: TDoubleArray): TOpenCLMtxVec; overload; function CopyFromArray(aRows, aCols: integer; const Src: TCplxArray): TOpenCLMtxVec; overload; function CopyCplxFromArray(aRows, aCols: integer; const Src: TSingleArray): TOpenCLMtxVec; overload; function CopyCplxFromArray(aRows, aCols: integer; const Src: TDoubleArray): TOpenCLMtxVec; overload; procedure Assign(Src: TOpenCLMatrix); virtual; (*The inverse of matrix elements. Calculates the inverse of all matrix elements in place. The computation occurs after first limiting the magnitude of each elements by the lower bound of Treshhold. The limiting operation is performed to avoid division by zero. Since Treshold represents a magnitude, it is always real and must always be positive. For complex versions, the magnitude of the input is limited, but the phase remains unchanged. Zero-valued input is assumed to have zero phase. To bypass the limiting operation set the Threshold to zero. var A: TOpenCLMatrix; begin clMtxVec.CreateIt(A); try A.SetIt(2,2,False,[1,2, 2,4)); // 2x2, not complex matrix A.InvElem(1.0e-7); finally clMtxVec.FreeIt(A); end; end; *) function InvElem(): TOpenCLMatrix; overload; function InvElem(const Src: TOpenCLMtxVec): TOpenCLMatrix; overload; (*Matrix array multiplication. Multiplies elements in Mtx matrix with the elements in the calling matrix (array multiplication) and stores the results in calling matrix. The , and properties of both matrices must match, otherwise an exception is raised. var A,B,C: TOpenCLMatrix; begin clMtxVec.CreateIt(A,B,C); try A.SetIt(2,2,False,[1,2, 2,4)); B.SetIt(2,2,False,[1,2, 2,4)); C.MulElem(A,B); // C becomes: // [1, 4, // 4,16] finally clMtxVec.FreeIt(A,B,C); end; end; *) function MulElem(Mtx: TOpenCLMatrix): TOpenCLMatrix; overload; (*Multiplies elements in Mtx1 matrix with the elements in Mtx2 matrix (array multiplication) and stores the results in calling matrix. The , and properties of calling matrix are set implicitly to match those of Mtx1 and Mtx2 matrices. Mtx1 and Mtx2 Rows, Cols, and Complex properties must be the same, otherwise an excetion is raised. raised. *) function MulElem(Mtx1, Mtx2: TOpenCLMatrix): TOpenCLMatrix; overload; (*Converts the content of the matrix Values array to a list of strings. Convert all elements of the calling matrix to strings with formating real parts with ReFormat, imaginary parts with ImFormat, using the text delimiter Delimiter and store them in aList, by using the Add method of TStrings object. procedure TForm1.Button1Click(Sender: TObject); var a,b: TOpenCLMatrix; begin CreateIt(a,b); try a.SetIt(2,2,False,[1,2,3,4]); a.Cos; b.Size(a); b.SetVal(1); a.Add(b); Richedit1.Clear; Memo1.Clear; a.ValuesToStrings(Richedit1.Lines); b.ValuesToStrings(Richedit1.Lines); a.ValuesToStrings(Memo1.Lines); b.ValuesToStrings(Memo1.Lines); Memo1.Lines.SaveToFile('C:\Test.txt'); Memo1.Lines.LoadFromFile('C:\Test.txt'); a.StringsToValues(Memo1.Lines); finally FreeIt(a,b); end; end; *) procedure ValuesToStrings(dstList: TStrings; const Delimiter: string = kTab; const ReFormat: string = ' 0.######;-0.#######'; const ImFormat: string = '+0.######i;-0.######i'); overload; (*nvert calling matrix elements, starting with [Row,Col] and converting Len elements to strings. Vormating real parts with ReFormat, imaginary parts with ImFormat, using the text delimiter Delimiter and store them in aList starting at ListIndex. If aList is not large enough, the method will use the Add method of aList object. *) procedure ValuesToStrings(dstList: TStrings; ListIndex,Row,Col,RowCount,ColCount: integer; Delimiter: string = kTab; const ReFormat: string = ' 0.######;-0.######'; const ImFormat: string = '+0.######i;-0.######i'); overload; (*Converts all calling matrix elements to string.*) procedure ValuesToText(out Text: String; Delimiter: string = kTab; const ReFormat: string = ' 0.######;-0.#######'; const ImFormat: string = '+0.######i;-0.######i');overload; (*Converts Row..Col to Row+RowCount..Col+ColCount matrix elements to string.*) procedure ValuesToText(out Text: String; Row,Col,RowCount,ColCount: integer; Delimiter: string = kTab; const ReFormat: string = ' 0.######;-0.######'; const ImFormat: string = '+0.######i;-0.######i'); overload; procedure CopyTo(Dst: TMtx); overload; procedure CopyTo(Dst: TMtxInt); overload; destructor Destroy; override; end; (*Stores a single real or complex value in GPU memory. Copying data from and to (from CPU separate) GPU memory can cause long delays even if that data is short. Sometimes it makes sense to keep even single value variables in the GPU memory. Use this object to avoid copying individual values from GPU to CPU memory. *) TOpenCLValue = class(TOpenCLBase ) strict private function GetComplexValue: string; function GetRealValue: string; function GetData: TVec; strict protected property Data: TVec read GetData; function GetSData: PCL_mem; override; procedure InitData; override; procedure FreeToCache; override; function GetRealValues: string; override; function GetComplexValues: string; override; protected function DebugUpdate: integer; override; public constructor Create(aDevice: TOpenCLDevice); override; procedure Reset; override; function Size(const Src: TOpenCLBase; aComplex: boolean): TOpenCLBase; overload; override; procedure Size(aPrecision: TclFloatPrecision; aComplex: boolean); overload; (*Returns Open CL buffer reference. Returns the real Open CL buffer used by the object. Multiple objects may be using the same buffer. *) property SData: PCL_mem read GetSData; (*Returns Open CL buffer reference. Returns complex Open CL buffer used by the object. Multiple objects may be using the same buffer. *) property CData: PCL_mem read GetSData; property RealValue: string read GetRealValue; property ComplexValue: string read GetComplexValue; (*Returns the index offest in to the buffer. Returns the index offset in to the buffer at which real values for the this object start. *) function SDataIndex(aIndex: integer): PointerInteger; override; (*Returns the index offest in to the buffer. Returns the index offset in to the buffer at which complex values for the this object start. *) function CDataIndex(aIndex: integer): PointerInteger; override; (*Copy value. Copy Src element to the calling object. Complex property of the calling object is set implicitly to match Src object. var a,b: TOpenCLValue; begin a.Copy(2); b.Copy(a); // b = [1,2,3,4] end; *) function Copy(const Src: TOpenCLValue): TOpenCLValue; overload; (*Copy Value to GPU memory.*) function Copy(const Value: double): TOpenCLValue; overload; (*Copy complex Value to GPU memory.*) function Copy(const Value: TCplx): TOpenCLValue; overload; (*Copies value from GPU memory.*) function Copy: double; overload; (*Copy complex value from GPU memory.*) function Copyc: TCplx; overload; (*Add Src1 and Src1. The results are stored in the calling object. FloatPrecision and Complex properties of the calling object are set implicitly to match Vec1 and Vec2 vectors. *) function Add(const Src1, Src2: TOpenCLValue): TOpenCLValue; overload; (*Adds Value to Vec. Stores the result in the calling object. FloatPrecision and Complex properties of the calling object are set automatically. *) function Add(const Vec: TOpenCLValue; Value: double): TOpenCLValue; overload; (*Adds complex Value to Vec. Store the result to the calling object. Size property of the calling object is set automatically. Complex property of the calling object is set to True. *) function Add(const Vec: TOpenCLValue; Value: TCplx): TOpenCLValue; overload; (*Split complex calling object in real and imaginary part. Split calling object into real and imaginary components. Stores real component in ReVec and imaginary component in ImVec. FloatPrecision and Complex properties of ReVec and ImVec are set implicitly to match with the calling vector. An execption is raised, if calling object is not complex. var a,b,c: clValue; begin a.Copy(Cplx(3,4)); // a= [1-2i, 3+4i] a.CplxToReal(b,c); // b = 3, c = 4 end; *) procedure CplxToReal(ReVec, ImVec: TOpenCLValue); overload; (*Constructs a complex object from two real objects. Construct a complex object from the ReVec (real part) and the ImVec (imaginary part) objects. The result is stored in the calling object. FloatPrecision and Complex properties of the calling object are set implicitly to match ReVec and ImVec objects. An exception is raised if ReVec or ImVec Complex property is True. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TOpenCLValue a,b,c; clMtxVec.CreateIt(out a, out b, out c); try { a.Copy(2); b.Copy(3); c.RealToCplx(a,b); //c = 2+3i } finally { clMtxVec.FreeIt(ref a, ref b, ref c); } } } *) function RealToCplx(ReVec, ImVec: TOpenCLValue): TOpenCLValue; overload; (*Conjugate. Complex conjugate Vec value. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TOpenCLValue a; clMtxVec.CreateIt(out c, out d); try { d.Copy(Cplx(2,3)); c.Conj(d); } finally { clMtxVec.FreeIt(ref c, ref d); } } } *) function Conj(const Vec: TOpenCLValue): TOpenCLValue; overload; (*Sets angle in [-2PI,2PI]. ThetaRad within -2 and interval. Calling this function prior to passing the value to trigonometric functions can significantly improve numerical accuracy. Sine/cosine appear within many other functions especially complex versions of trigonometric functions. FixAngle method is not used implicitely within TOpenCLValue methods. To achieve maximum performance make sure that the arguments passed to complex trigonometric functions are "small" or scaled down. Note The vector must be real. *) function FixAngle(const Src: TOpenCLValue): TOpenCLValue; overload; (*Rounds Src towards negative infinity and stores the result in the calling object. FloatPrecision and Complex properties of the calling object are adjusted automatically. *) function Floor(const Src: TOpenCLValue): TOpenCLValue; overload; (*A complex exponential e^(j*Omega)). Calculate complex exponential. An exception is raised if calling object is complex. If object is complex, you should use the method instead. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TOpenCLValue a,b; clMtxVec.CreateIt(out a, out b); try { b.Copy(2); a.Expj(b); // a = e^(2i) } finally { clMtxVec.FreeIt(ref a, ref b); } } } *) function Expj(Omega: TOpenCLValue): TOpenCLValue; overload; (*Fractional part of values. Calculates the fractional part of X. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TOpenCLValue a,b; clMtxVec.CreateIt(out a, out b); try { b.Copy(2.3); a.Frac(b); // a = 0.3 } finally { clMtxVec.FreeIt(ref a, ref b); } } } *) function Frac(const X: TOpenCLValue): TOpenCLValue; overload; (*Complementary error function. Calculates the complementary error function value of Src. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TOpenCLValue a,b; clMtxVec.CreateIt(out a, out b); try { b.Copy(2.3); a.Erfc(b); // a = Erfc(2.3) } finally { clMtxVec.FreeIt(ref a, ref b); } } } *) function Erfc(const Src: TOpenCLValue): TOpenCLValue; overload; (*Error function. Calculates the error function of Src. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TOpenCLValue a,b; clMtxVec.CreateIt(out a, out b); try { b.Copy(2.3); a.Erf(b); // a = Erf(2.3) } finally { clMtxVec.FreeIt(ref a, ref b); } } } *) function Erf(const Src: TOpenCLValue): TOpenCLValue; overload; (*Flips the real and imaginary part of a complex number. Performs the following transformation: a + i*bi ==> b + i*a Method flips the real and imaginary part of the complex number X and stores the result in the calling object. *) function Flip(const X: TOpenCLValue): TOpenCLValue; overload; (*Flips the real and imaginary part of the complex numbers and conjugates the result. Performs the following transformation: a + i*bi ==> b - i*a Method flips the real and imaginary part and conjugates calling object complex value. *) function FlipConj(const X: TOpenCLValue): TOpenCLValue; overload; (*The Reminder after division X/Y. Calculates reminder after division according to formula: x[i]-y[i]*Trunc(const X[i]/y[i]). The result will be saved to the calling vector. X and Y must be a real and have the same length. FloatPrecision and Complex properties of the calling vector are set implicitly to match the X object. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TOpenCLValue a,b,c; clMtxVec.CreateIt(out a, out b, out c); try { a.Copy(4); b.Copy(3); c.Rem(a,b); // c = Rem(4,3) } finally { clMtxVec.FreeIt(ref a,ref b,ref c); } } } *) function Rem(const X, Y: TOpenCLValue): TOpenCLValue; overload; (*Log base N. returns Log with base N for value X. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TOpenCLValue a,b; clMtxVec.CreateIt(out a, out b); try { b.Copy(2.3); a.LogN(4, b); // a = LogN(4, 2.3) } finally { clMtxVec.FreeIt(ref a, ref b); } } } *) function LogN(N: double; X: TOpenCLValue): TOpenCLValue; overload; (*Raises base to any power. Computes Base^(Exponent). The is faster, if Exponent is an integer. Real valued power can handle only positive Exponent. can handle negative exponent also. To compute a power to the negative exponent in general case or when the base is negative, use the complex version of the function. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TOpenCLValue a,b,c; clMtxVec.CreateIt(out a, out b, out c); try { b.Copy(2.3); c.Copy(4); a.Power(b, c); // a = b^c } finally { clMtxVec.FreeIt(ref a, ref b, ref c); } } } *) function Power(Base, Exponent: TOpenCLValue): TOpenCLValue; overload; function Power(Base: double; Exponent: TOpenCLValue): TOpenCLValue; overload; function Power(Base: TCplx; Exponent: TOpenCLValue): TOpenCLValue; overload; function Power(Base: TOpenCLValue; Exponent: double): TOpenCLValue; overload; function Power(Base: TOpenCLValue; Exponent: TCplx): TOpenCLValue; overload; (*Round Src. Stores the result in the calling object. FloatPrecision and Complex property of calling object are adjusted automatically. *) function Round(const Src: TOpenCLValue): TOpenCLValue; overload; (* Computes signum function from Src and stores the result in the calling object. FloatPrecision and Complex properties of calling object are adjusted automatically. Signum(X) is 1 for X > 0 , equal to zero for X = 0 and -1 for X < 0. *) function Sgn(const Src: TOpenCLValue): TOpenCLValue; overload; (*Signum. Calculates the signum of Src and multiplies it with the calling object value. Signum(X) is 1 for X > 0 , equal to zero for X = 0 and -1 for X < 0. FloatPrecision and Complex property of calling object are adjusted automatically. *) function SgnMul(const Src: TOpenCLValue): TOpenCLValue; overload; (*Sine and cosine. Calculates the sine and cosine of the value stored in the calling object. FloatPrecision and Complex property of SinX and CosX are adjusted automatically. Note Use this method if you require both sine and cosine. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TOpenCLValue a,s,v; MtxVec.CreateIt(out a, out s, out c); try { a.Copy(0); a.SinCos(s,c); // s=[0], c =[1] } finally { MtxVec.FreeIt(ref a, ref s, ref c); } } } *) procedure SinCos(SinX, CosX: TOpenCLValue); overload; (*Hyperbolic sine and cosine. Calculates the hyperbolic sine and hyperbolic cosine for the calling object value and stores the sine to SinhX and cosine to CoshX. FloatPrecision and Complex property of SinhX and CoshX are adjusted automatically. Note Use this method, if you require hyperbolic sine and hyperbolic cosine. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TOpenCLValue a,s,v; clMtxVec.CreateIt(out a, out s, out c); try { a.Copy(0); a.SinhCosh(s,c); } finally { clMtxVec.FreeIt(ref a, ref s, ref c); } } } *) procedure SinhCosh(SinhX, CoshX: TOpenCLValue); overload; (*Threshold bottom operation. Perform threshold operation on Src. The Value parameter is a lower bound for the threshold operation. Src value smaller than Value will be replaced with Value. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TOpenCLValue a, b; clMtxVec.CreateIt(out a, out b); try { b.Copy(0.1); a.ThreshBottom(b, 0.2); // a = [0.2] } finally { clMtxVec.FreeIt(ref a, ref b); } } } *) function ThreshBottom(const Src: TOpenCLValue; Value: double): TOpenCLValue; overload; (*Threshold top operation. Perform threshold operation Src. The Value parameter is an upper bound for threshold operation. Src value bigger than Value will be replaced with Value. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TOpenCLValue a, b; clMtxVec.CreateIt(out a, out b); try { b.Copy(0.1); a.ThreshTop(b, 0.2); // a = [0.2] } finally { clMtxVec.FreeIt(ref a, ref b); } } } *) function ThreshTop(const Src: TOpenCLValue; Value: double): TOpenCLValue; overload; (*Threshold less than operation. Perform operation on Vec. The LTValue parameter is an lower bound for threshold operation. Vec value less than LTLevel will be replaced with LTValue. For a complex number the comparison is applied with the norm of the complex value. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TOpenCLValue a, b; clMtxVec.CreateIt(out a, out b); try { a.CopyFromArray( new double[] {2, 0.1, 3, 4}); a.ThresholdLT(b, 2.3,1.5); // a = [1.5] } finally { clMtxVec.FreeIt(ref a, ref b); } } } *) function ThresholdLT(const Vec: TOpenCLValue; LTLevel, LTValue: double): TOpenCLValue; overload; (* Perform "less than" threshold operation for complex value in Vec. Stores the result in the calling object. FloatPrecision and Complex properties of the calling object are adjusted automatically. If Vec ovalue is not complex, an exception will be raised. *) function ThresholdLT(const Vec: TOpenCLValue; LTLevel: double; LTValue: TCplx): TOpenCLValue; overload; (*Threshold greater than operation. Perform operation on Vec value. The GTValue parameter is an upper bound for threshold operation. Vec value bigger than LTLevel will be replaced with GTValue. For a complex number the comparison will be applied with the norm of the complex value. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TOpenCLValue a, b; clMtxVec.CreateIt(out a, out b); try { b.Copy(2); a.ThresholdGT(b, 1.3,1.5); // a = [1.5] } finally { clMtxVec.FreeIt(ref a, ref b); } } } *) function ThresholdGT(const Vec: TOpenCLValue; GTLevel, GTValue: double): TOpenCLValue; overload; (*Perform "greater than" threshold operation for complex value in Vec. Store the result in the calling object. FloatPrecision and Complex properties of the calling object are adjusted automatically. If Vec value is not complex, an exception will be raised. *) function ThresholdGT(const Vec: TOpenCLValue; GTLevel: double; GTValue: TCplx): TOpenCLValue; overload; (*Threshold greater than and less than operation. Perform threshold operation on Vec value. The LTValue parameter is an lower bound for threshold operation. The GTValue parameter is an upper bound for threshold operation. Vec value less than LTLevel will be replaced with LTValue. Vec value bigger than GTLevel will be replaced with GTValue. Operation is available only for not complex values. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TOpenCLValue a, b; clMtxVec.CreateIt(out a, out b); try { b.Copy(3); a.ThresholdGT_LT(b, 2.3,3.4,1,0.5); // a = [3.4] } finally { clMtxVec.FreeIt(ref a, ref b); } } } *) function ThresholdGT_LT (const Vec: TOpenCLValue; GTLevel, GTValue, LTLevel, LTValue: double): TOpenCLValue; overload; (*Rounds a real number towards zero and returns the fractional part. Rounds calling object value towards zero to an integer and stores the result in the TruncDst object as a floating point numbers. The fractional part is stored in the FracDst. *) procedure TruncAndFrac(TruncDst: TOpenCLValue; FracDst: TOpenCLValue); overload; (*Truncate all Src object elements. Stores the result in the calling object. FloatPrecision and Complex property of calling object are adjusted automatically. *) function Trunc(const Src: TOpenCLValue): TOpenCLValue; overload; (*The inverse of cube root 1/(v)^1/3. Calculate the inverse cube root (1/(element)^(1/3)) of X. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TOpenCLValue a,b; clMtxVec.CreateIt(out a, out b); try { b.Copy(2.3); a.InvCbrt(b); // a = 2.3^(1/3) } finally { clMtxVec.FreeIt(ref a, ref b); } } } *) function InvCbrt(const X: TOpenCLValue): TOpenCLValue; overload; (*The inverse of square root 1/(v)^1/2. Calculate the inverse square root 1/(element)^(1/2)) of X. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TOpenCLValue a,b; clMtxVec.CreateIt(out a, out b); try { b.Copy(2.3); a.InvCbrt(b); // a = 2.3^(1/3) } finally { clMtxVec.FreeIt(ref a, ref b); } } } *) function InvSqrt(const X: TOpenCLValue): TOpenCLValue; overload; (*Magnitude. Calculate the magnitude of X. This method has the same function as the method. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TOpenCLValue a,b; clMtxVec.CreateIt(out a, out b); try { b.Copy(Cplx(2,3)); a.Mag(b); } finally { clMtxVec.FreeIt(ref a, ref b); } } } *) function Mag(const X: TOpenCLValue): TOpenCLValue; overload; (*Multiply Src1 with Src2. Stores the result in the calling object. FloatPrecision and Complex property of calling object are adjusted automatically to match those of Vec1 and Vec2. An exception is raised if Vec1 and Vec2 FloatPrecision and Complex property do not match. *) function Mul(const Src1, Src2: TOpenCLValue): TOpenCLValue; overload; (*Multiply Vec with Value. Stores the result in to the calling object. FloatPrecision and Complex properties of the calling object are adjusted automatically. *) function Mul(const Vec: TOpenCLValue; Value: double): TOpenCLValue; overload; (*Multiply Vec with Value. Stores the result in to the calling object. FloatPrecision and Complex properties of the calling object are adjusted automatically. *) function Mul(const Vec: TOpenCLValue; Value: TCplx): TOpenCLValue; overload; (*Multiply X with 1i and store the result in to the calling object.*) function MulI(const X: TOpenCLValue): TOpenCLValue; overload; (*Converts the polar magnitude/phase pair to cartesian pair. Converts AmpltVec and PhaseVec values (combined) from polar to cartesian form. The result is stored as a complex number (x=Re, y=Im) in to the calling object. FloatPrecision and Complex properties of the calling object are set implicitly to match AmpltVec and PhaseVec objects. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TOpenCLValue a,b,c; clMtxVec.CreateIt(out a, out b, out c); try { a.Copy(2); // a = [2] //magnitude b.Copy(3); // b = [1] /phase c.PolarToCart(a,b); // result stored in c = projections to Re and Im axis } finally { clMtxVec.FreeIt(ref a, ref b, ref c); } } } *) function PolarToCart(AmpltVec, PhaseVec: TOpenCLValue): TOpenCLValue; overload; (*Gets real part of the complex value. The method gets the real part of the complex value stored in Vec and stores the real results in the calling object. FloatPrecision and Complex properties of the calling object are set implicitly to match Vec object. Vec Complex property must be true otherwise an exception is raised. var a,b: TOpenCLValue; begin CreateIt(a,b); try a.Copy(Cplx(2,3)); // = [2+3i] b.RealPart(a); // b = [2] finally FreeIt(a,b); end; end; *) function RealPart(const Vec: TOpenCLValue): TOpenCLValue; overload; (*Square. Calculate the square of X. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TOpenCLValue a,b; clMtxVec.CreateIt(out a, out b); try { b.Copy(2); a.Sqr(b); // a=[4] } finally { clMtxVec.FreeIt(ref a, ref b); } } } *) function Sqr(const X: TOpenCLValue): TOpenCLValue; overload; (*Square root. Calculate the square root of X. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TOpenCLValue a,b; clMtxVec.CreateIt(out a, out b); try { b.Copy(4); a.Sqrt(b); // a=[2] } finally { clMtxVec.FreeIt(ref a, ref b); } } } *) function Sqrt(const X: TOpenCLValue): TOpenCLValue; overload; (*Sine function. Calculate the sine of X. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TOpenCLValue a,b; clMtxVec.CreateIt(out a, out b); try { b.Copy(4); a.Sin(b); } finally { clMtxVec.FreeIt(ref a, ref b); } } } *) function Sin(const X: TOpenCLValue): TOpenCLValue; overload; (*Cosne function. Calculate the cosine of X. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TOpenCLValue a,b; clMtxVec.CreateIt(out a, out b); try { b.Copy(4); a.Cos(b); } finally { clMtxVec.FreeIt(ref a, ref b); } } } *) function Cos(const X: TOpenCLValue): TOpenCLValue; overload; (*Tangens. Calculate the tangens of X. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TOpenCLValue a,b; clMtxVec.CreateIt(out a, out b); try { b.Copy(4); a.Tan(b); } finally { clMtxVec.FreeIt(ref a, ref b); } } } *) function Tan(const X: TOpenCLValue): TOpenCLValue; overload; (*Cotangens. Calculate the cotangens of X. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TOpenCLValue a,b; clMtxVec.CreateIt(out a, out b); try { b.Copy(4); a.Cot(b); } finally { clMtxVec.FreeIt(ref a, ref b); } } } *) function Cot(const X: TOpenCLValue): TOpenCLValue; overload; (*Secant. Calculate the secant of X. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TOpenCLValue a,b; clMtxVec.CreateIt(out a, out b); try { b.Copy(4); a.Sec(b); } finally { clMtxVec.FreeIt(ref a, ref b); } } } *) function Sec(const X: TOpenCLValue): TOpenCLValue; overload; (*Cosecant. Calculate the cosecant of X. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TOpenCLValue a,b; clMtxVec.CreateIt(out a, out b); try { b.Copy(4); a.Csc(b); } finally { clMtxVec.FreeIt(ref a, ref b); } } } *) function Csc(const X: TOpenCLValue): TOpenCLValue; overload; (*The inverse sine. Calculate the inverse sine of X. Value must be between -1 and 1. The return values will be in the range [0,], in radians. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TOpenCLValue a,b; clMtxVec.CreateIt(out a, out b); try { b.Copy(4); a.ArcSin(b); } finally { clMtxVec.FreeIt(ref a, ref b); } } } *) function ArcSin(const X: TOpenCLValue): TOpenCLValue; overload; (*The inverse cosine. Calculate the inverse cosine X. Value must be between -1 and 1. The return values will be in the range [0,], in radians. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TOpenCLValue a,b; clMtxVec.CreateIt(out a, out b); try { b.Copy(4); a.ArcCos(b); } finally { clMtxVec.FreeIt(ref a, ref b); } } } *) function ArcCos(const X: TOpenCLValue): TOpenCLValue; overload; (*Inverse tangens of Y/X. Calculates the inverse tangens of Y/X, and returns an angle in the correct quadrant. The results are stored in calling object elements. FloatPrecision and Complex properties of calling object are adjusted automatically to match those of X and Y objects. An exception is raised if X and Y FloatPrecision and Complex properties do not match. Note that is calculated as ArcTan2(1, X). *) function ArcTan2(Y, X: TOpenCLValue): TOpenCLValue; overload; (*Inverse tangens. Calculate the inverse tangens for all calling object elements in-place. The return values are expressed in radians. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TOpenCLValue a,b; clMtxVec.CreateIt(out a, out b); try { b.Copy(0.5); a.ArcTan(b); } finally { clMtxVec.FreeIt(ref a, ref b); } } } *) function ArcTan(const X: TOpenCLValue): TOpenCLValue; overload; (*Inverse cotangens. Calculate the inverse cotangens of X. The return values are expressed in radians. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TOpenCLValue a,b; clMtxVec.CreateIt(out a, out b); try { b.Copy(0.5); a.ArcCot(b); } finally { clMtxVec.FreeIt(ref a, ref b); } } } *) function ArcCot(const X: TOpenCLValue): TOpenCLValue; overload; (*Calculate the inverse secant of X. FloatPrecision and Complex properties of calling object are adjusted automatically. *) function ArcSec(const X: TOpenCLValue): TOpenCLValue; overload; (*Calculate the inverse cosecant of X. Store the results in the calling object. FloatPrecision and Complex properties of calling object are adjusted automatically. *) function ArcCsc(const X: TOpenCLValue): TOpenCLValue; overload; (*Hyperbolic sine. Calculate the hyperbolic sine of X. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TOpenCLValue a,b; clMtxVec.CreateIt(out a, out b); try { b.Copy(0.5); a.Sinh(b); } finally { clMtxVec.FreeIt(ref a, ref b); } } } *) function Sinh(const X: TOpenCLValue): TOpenCLValue; overload; (*Hyperbolic cosine. Calculate the hyperbolic cosine of X. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TOpenCLValue a,b; clMtxVec.CreateIt(out a, out b); try { b.Copy(0.5); a.Cosh(b); } finally { clMtxVec.FreeIt(ref a, ref b); } } } *) function Cosh(const X: TOpenCLValue): TOpenCLValue; overload; (*Hyperbolic tangens. Calculate the hyperbolic tangens of X. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TOpenCLValue a,b; clMtxVec.CreateIt(out a, out b); try { b.Copy(0.5); a.Tanh(b); } finally { clMtxVec.FreeIt(ref a, ref b); } } } *) function Tanh(const X: TOpenCLValue): TOpenCLValue; overload; (*Hyperbolic cotangens. Calculate the hyperbolic cotangens of X. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TOpenCLValue a,b; clMtxVec.CreateIt(out a, out b); try { b.Copy(0.5); a.Coth(b); } finally { clMtxVec.FreeIt(ref a, ref b); } } } *) function Coth(const X: TOpenCLValue): TOpenCLValue; overload; (*Calculate the hyperbolic secant for all X object elements. Store the results in the calling object. FloatPrecision and Complex properties of calling object are adjusted automatically. *) function Sech(const X: TOpenCLValue): TOpenCLValue; overload; (*Calculate the hyperbolic cosecant for all X object elements. Store the results in the calling object. FloatPrecision and Complex properties of calling object are adjusted automatically. *) function Csch(const X: TOpenCLValue): TOpenCLValue; overload; (*Absolute values. Calculate the absolute value. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TOpenCLValue a,b; clMtxVec.CreateIt(out a, out b); try { b.Copy(-0.5); a.Abs(b); } finally { clMtxVec.FreeIt(ref a, ref b); } } } *) function Abs(const X: TOpenCLValue): TOpenCLValue; overload; (*Calculate the inverse hyperbolic sine of X. Store the results in the calling object. FloatPrecision and Complex properties of calling object are adjusted automatically. *) function ArcSinh(const X: TOpenCLValue): TOpenCLValue; overload; (*Calculate the inverse hyperbolic cosine of X. Store the results in the calling object. FloatPrecision and Complex properties of calling object are adjusted automatically. *) function ArcCosh(const X: TOpenCLValue): TOpenCLValue; overload; (*Calculate the inverse hyperbolic tangens of X. Store the results in the calling object. FloatPrecision and Complex properties of calling object are adjusted automatically. *) function ArcTanh(const X: TOpenCLValue): TOpenCLValue; overload; (*Calculate the inverser hyperbolic cotangens of X. Store the results in calling object. FloatPrecision and Complex properties of calling object are adjusted automatically. *) function ArcCoth(const X: TOpenCLValue): TOpenCLValue; overload; (*Calculate the inverse hyperbolic secant of X. Store the results in calling object. FloatPrecision and Complex properties of calling object are adjusted automatically. *) function ArcSech(const X: TOpenCLValue): TOpenCLValue; overload; (*Calculate the inverse hyperbolic cosecant of X. Store the results in calling object. FloatPrecision and Complex properties of calling object are adjusted automatically. *) function ArcCsch(const X: TOpenCLValue): TOpenCLValue; overload; (*The cube root. Calculate the cube root of X. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TOpenCLValue a,b; clMtxVec.CreateIt(out a, out b); try { b.Copy(8); a.Cbrt(b); } finally { clMtxVec.FreeIt(ref a, ref b); } } } *) function Cbrt(const X: TOpenCLValue): TOpenCLValue; overload; (*Rounds towards positive infinity. Rounds towards positive infinity in-place. Ceil(-2.8) = -2 Ceil(2.8) = 3 Ceil(-1.0) = -1 *) function Ceil(const Src: TOpenCLValue): TOpenCLValue; overload; (*Natural logarithm. Calculate the natural log of X. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TOpenCLValue a,b; clMtxVec.CreateIt(out a, out b); try { b.Copy(8); a.Ln(b); } finally { clMtxVec.FreeIt(ref a, ref b); } } } *) function Ln(const X: TOpenCLValue): TOpenCLValue; overload; (*Log base 10. Calculate the log base 10 of X. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TOpenCLValue a,b; clMtxVec.CreateIt(out a, out b); try { b.Copy(8); a.Log10(b); } finally { clMtxVec.FreeIt(ref a, ref b); } } } *) function Log10(const X: TOpenCLValue): TOpenCLValue; overload; (*Log base 2. Calculate the log base 2 of X. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TOpenCLValue a,b; clMtxVec.CreateIt(out a, out b); try { b.Copy(8); a.Log2(b); } finally { clMtxVec.FreeIt(ref a, ref b); } } } *) function Log2(const X: TOpenCLValue): TOpenCLValue; overload; (*Exponent (e^). Calculate the exponent (e^) of X. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TOpenCLValue a,b; clMtxVec.CreateIt(out a, out b); try { b.Copy(8); a.Exp(b); } finally { clMtxVec.FreeIt(ref a, ref b); } } } *) function Exp(const X: TOpenCLValue): TOpenCLValue; overload; (*Exponent base 2 (2^). Calculate the exponent base 2 of X ( 2^X). using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TOpenCLValue a,b; clMtxVec.CreateIt(out a, out b); try { b.Copy(8); a.Exp2(b); } finally { clMtxVec.FreeIt(ref a, ref b); } } } *) function Exp2(const X: TOpenCLValue): TOpenCLValue; overload; (*Exponent base 10 (10^X). Calculate the exponent base 10 (10^X). using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TOpenCLValue a,b; clMtxVec.CreateIt(out a, out b); try { b.Copy(8); a.Exp10(b); } finally { clMtxVec.FreeIt(ref a, ref b); } } } *) function Exp10(const X: TOpenCLValue): TOpenCLValue; overload; (*Gets the imaginary part of a complex value. Gets the imaginary part of a complex value Vec and stores the real result in the calling object. FloatPrecision and Complex properties of the calling object are set implicitly to match Vec object. Vec Complex must be true otherwise the exception will be raised. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TOpenCLValue a,b; clMtxVec.CreateIt(out a, out b); try { b.Copy(Cplx(8)); a.ImagPart(b); // a = 0 } finally { clMtxVec.FreeIt(ref a, ref b); } } } *) function ImagPart(const Vec: TOpenCLValue): TOpenCLValue; overload; (*Power (integer exponent). Calculate the power Base^(Exponent). For non-integer exponents, the method can be used. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TOpenCLValue a,b; clMtxVec.CreateIt(out a, out b); try { b.Copy(8); a.IntPower(b,2); } finally { clMtxVec.FreeIt(ref a, ref b); } } } *) function IntPower(Base: TOpenCLValue; Exponent: Integer): TOpenCLValue; overload; (*Inverse elements. Calculates the inverse of X without limiting the inverse operation (to protect against overflow). using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TOpenCLValue a,b; clMtxVec.CreateIt(out a, out b); try { b.Copy(8); a.Inv(b); // a = 1/8 } finally { clMtxVec.FreeIt(ref a, ref b); } } } *) function Inv(const X: TOpenCLValue): TOpenCLValue; overload; (*Converts value from cartesian to polar coordinate form. Converts value from cartesian to polar coordinate form, storing the magnitude (radius) component in the AmpltVec and the phase (angle) in the PhaseVec. FloatPrecision and Complex properties of AmpltVec and PhaseVec are set automatically. *) procedure CartToPolar(AmpltVec, PhaseVec: TOpenCLValue); overload; (*Divide Num with Den. FloatPrecision and Complex property of the calling object are set automatically. The result is stored in the calling object. The result of division by zero will be the INF constant. Division of zero by zero will result in NAN. *) function Divide(Num, Den: TOpenCLValue): TOpenCLValue; overload; (*Divide Value with Vec. FloatPrecision and Complex properties of the calling object are set automatically. *) function DivideBy(Value: double; Vec: TOpenCLValue): TOpenCLValue; overload; (*Divide Value with Vec. Size of the calling object is set automatically. Complex property of the calling object is set to True. *) function DivideBy(Value: TCplx; Vec: TOpenCLValue): TOpenCLValue; overload; (*Subtract real Value from Src. Stores the result in the calling object. FloatPrecision and Complex property of calling object are adjusted automatically. *) function Sub(const Src: TOpenCLValue; Value: double): TOpenCLValue; overload; (*Subtract complex Value from Src. Stores the result in the calling object. FloatPrecision and Complex property of calling object are adjusted automatically. *) function Sub(const Src: TOpenCLValue; Value: TCplx): TOpenCLValue; overload; (*Subtract Vec2 elements from Vec1 elements. Stores the result in the calling object. FloatPrecision and Complex property of calling object are adjusted automatically. An exception is raised, if Vec1 and Vec2 FloatPrecision and Complex property do not match. *) function Sub(Vec1, Vec2: TOpenCLValue): TOpenCLValue; overload; (*Substract Vec elements from Value. Stores the result in the calling object. FloatPrecision and Complex properties of calling object are adjusted automatically. *) function SubFrom(Value: double; Vec: TOpenCLValue): TOpenCLValue; overload; (*Substract Vec from Value. Stores the result in the calling object. Size property of the calling object is set automatically. Complex property of the calling object is set to True. *) function SubFrom(Value: TCplx; Vec: TOpenCLValue): TOpenCLValue; overload; destructor Destroy; override; end; TOpenCLVectorArray = array of TOpenCLVector; TOpenCLMatrixArray = array of TOpenCLMatrix; TOpenCLValueArray = array of TOpenCLValue; TOpenCLCache = class strict private fBlockLength: integer; blockPool: TIntegerArray; fScalarBlockLength: integer; ScalarBlockPool: TIntegerArray; clVectors: TOpenCLVectorArray; clMatrices: TOpenCLMatrixArray; clScalars: TOpenCLValueArray; FMatricesUsed: integer; FVectorsUsed: integer; FScalarsUsed: integer; fMaxVectorsUsed: integer; fMaxMatricesUsed: integer; fMaxScalarsUsed: integer; fDevice: TOpenCLDevice; csv: TCriticalSection; csm: TCriticalSection; function GetFreeBlock: integer; function GetFreeScalar: integer; procedure ReleaseBlock(var BlockId: integer); procedure ReleaseScalar(var ScalarId: integer); procedure InternalMatrixCacheSize; procedure InternalMatrixCacheSize2; procedure InternalScalarCacheSize; procedure InternalScalarCacheSize2; procedure InternalVectorCacheSize; procedure InternalVectorCacheSize2; strict protected function ScalarLength(aPrecision: TclFloatPrecision): integer; procedure mEnter; procedure mLeave; procedure sEnter; procedure sLeave; procedure vEnter; procedure vLeave; protected clMemory: pcl_mem; clScalarMemory: pcl_mem; procedure SetBlockPoolSize(ItemCount, ItemLength: integer); procedure SetVecCacheSize(ItemCount: integer); procedure SetMatrixCacheSize(ItemCount: integer); procedure SetScalarCacheSize(ItemCount: integer); procedure SetScalarPoolSize; function BlockLength(aPrecision: TclFloatPrecision): integer; public procedure SetCacheSize(ItemCount, ItemLength, VecCount, MtxCount: integer; ScalarCount: integer = 32); procedure CreateIt(out a: TOpenCLVector); overload; procedure FreeIt(var a: TOpenCLVector); overload; procedure CreateIt(out a: TOpenCLMatrix); overload; procedure FreeIt(var a: TOpenCLMatrix); overload; procedure CreateIt(out a: TOpenCLValue); overload; procedure FreeIt(var a: TOpenCLValue); overload; property MatricesUsed: integer read FMatricesUsed; property VectorsUsed: integer read FVectorsUsed; property ScalarssUsed: integer read FScalarsUsed; property MaxVectorsUsed: integer read fMaxVectorsUsed; property MaxMatricesUsed: integer read fMaxMatricesUsed; property MaxScalarsUsed: integer read fMaxScalarsUsed; constructor Create(aDevice: TOpenCLDevice); virtual; destructor Destroy; override; end; (*Redirects the execution path to the command que to one on the same device with support for immediate execution. This feature is supported only for CPU devices and for now only by Intel. The function returns true, if a command queue was marked with ImmediateExecution property set to true. *) function EnableCPUThreading: boolean; (*Redirects the execution path to the command que to one on the same device but without support for immediate execution. This feature is supported only for CPU devices and for now only by Intel. The function returns true, if a command queue was marked with ImmediateExecution property set to false. *) function DisableCPUThreading: boolean; procedure clCheck(Status: cl_int); function GetCurrentCLDevice: TOpenCLDevice; function GetCurrentCommandQueue: TOpenCLCommandQueue; procedure CreateIt(out a: TOpenCLVector); overload; procedure CreateIt(out a: TOpenCLMatrix); overload; procedure CreateIt(out a, b: TOpenCLVector); overload; procedure CreateIt(out a, b: TOpenCLMatrix); overload; procedure CreateIt(out a, b, c: TOpenCLVector); overload; procedure CreateIt(out a, b, c: TOpenCLMatrix); overload; procedure CreateIt(out a, b, c, d: TOpenCLVector); overload; procedure CreateIt(out a, b, c, d: TOpenCLMatrix); overload; procedure FreeIt(var a: TOpenCLVector); overload; procedure FreeIt(var a: TOpenCLMatrix); overload; procedure FreeIt(var a, b: TOpenCLVector); overload; procedure FreeIt(var a, b, c: TOpenCLVector); overload; procedure FreeIt(var a, b, c, d: TOpenCLVector); overload; procedure FreeIt(var a, b: TOpenCLMatrix); overload; procedure FreeIt(var a, b, c: TOpenCLMatrix); overload; procedure FreeIt(var a, b, c, d: TOpenCLMatrix); overload; function clPlatform: TOpenCLPlatformList; overload; (*High performance math functions. Introduces high performance math functions. It can serve as replacement for the default Delphi Math.pas unit and offers full support for complex numbers. However, in many applications, you can obtain better performance with vector arithmetics. Adapted from TPMath1 of J. Debord with permission. Some complex routines adapted from gsCmplx by Serghei Gaivan with permission. *) unit Math387; interface {$I BdsppDefs.inc} Uses SysUtils ,Classes, syncobjs ,Types ,Windows ,Contnrs ; {$Z4} type (*Default real number type used in Math387. Default real number type used in Math387. If single precision library is used TSample is of type single. If double precision library is used, TSample is of type double. *) TSample = double; (*Signed 2 byte integer. Signed 2 byte integer. *) TISample = SmallInt; (*MtxVec version.*) const MtxVecVersion = 637; const MtxVecCoreMsg = 'MtxVec Core implementation of a needed function is missing! Please contact support@dewresearch.com for more information about availability!'; const DefaultIsDouble = true ; const MtxVecInfo = 'MtxVec 6.3.7'; const MKL_ALL = 0; const MKL_BLAS = 1; const MKL_FFT = 2; const MKL_VML = 3; const MKL_PARDISO = 4; const MKL_LAPACK = 5; const MediumBlockSize = 256*1024; const MtxVecDebuggerMarker = 999999111; (*End of array constant. End of array constant. *) const MtxVecEOA = -1; const ippnamed2 = 'MtxVec.Vmld.6.3.dll'; const ippnamed = 'MtxVec.Dspd.6.3.dll'; const nmkpd2 = 'MtxVec.Lapackd.6.3.dll'; const mvspd2 = 'MtxVec.Lapackd.6.3.dll'; const ippnames2 = 'MtxVec.Vmls.6.3.dll'; const ippnames = 'MtxVec.Dsps.6.3.dll'; const nmkps2 = 'MtxVec.Lapacks.6.3.dll'; const mvsps2 = 'MtxVec.Lapacks.6.3.dll'; const vmlnamed = 'MtxVec.Vml.6.3.dll'; const vmlnames = 'MtxVec.Vml.6.3.dll'; const nmfft = 'MtxVec.Fft.6.3.dll'; const nmrnd = 'MtxVec.Random.6.3.dll'; type (*Specifies MtxVec processing precision.*) TMtxFloatPrecision = (mvSingle, mvDouble, mvSingleComplex, mvDoubleComplex); TMtxRect = TRect; TMtxPoint = TPoint; LongInteger = integer; PointerInteger = cardinal; TThreadID = Int64; PLongInteger = ^LongInteger; PPointerInteger = ^PointerInteger; (*Storage Endianness. Defines the order in which the bytes of data are (to be) stored in the file or in to a stream. *) TEndianness = ( (*Intel convention*) boLittleEndian, (*Motorola convention*) boBigEndian); (*Storage precision. Defines the precision in which the data is (to be) stored in the file or in to a stream. *) TPrecision = ( (*8 byte floating point*)prDouble, (*4 byte floating point*)prSingle, (*4 byte signed integer.*)prInteger, (*4 byte unsigned integer*)prCardinal, (*2 byte signed integer*)prSmallInt, (*2 byte unsigned integer*)prWord, (*1 byte signed integer*)prShortInt, (*1 byte unsigned integer*)prByte, (*1 byte dynamic floating point audio compression*)prMuLaw, (*1 byte dynamic floating point audio compression*)prALaw, (*3 byte signed integer*)prInt24); (*Default storage precision for integer vector and matrix values.*) TIntPrecision = ( (*32 bit integers.*)prInt32, (*16 bit integers.*)prInt16, (*8 bit integers.*) prInt8 ); (*Specifies alignment for fixed width font number to string conversion.*) TFixedTextAlign = ( (*No spaces will be appended or inserted.*)ftaNone, (*Spaces will be inserted in front of the text.*) ftaRightAlign, (*Spaces will be inserted in after the text.*) ftaLeftAlign); TMtxCompareOp = ( (*Less than, smaller, < .*) cmpLT, (*Less than or equal, <= .*) cmpLT_EQ, (*Greater than, > .*) cmpGT, (*Greater than or equal, >= .*) cmpGT_EQ, (*Equal, =, ==*) cmpEQ, (*Not equal, <> , !=*) cmpNot_EQ ); (*A pointer to TSample type. A pointer to type. *) PSample = ^TSample; (*A pointer to integer type. A pointer to type. *) PInteger = ^Integer; (*A pointer to TISample type. A pointer to type. *) PSmallInt = ^SmallInt; (*A pointer to Word type. A pointer to type. *) PWord = ^Word; (*A pointer to Byte type. A pointer to type. *) PByte = ^Byte; UInt = cardinal; (*A pointer to TCplx type. A pointer to type. *) PCplx = ^TCplx; (*Default complex number type used by Math387. Default complex number type used by Math387. *) TCplx = packed record (*Real part of the complex number.*) Re: double; (*Imaginary part of the complex number.*) Im: double; (* Returns true if Imaginary component is zero. *) function IsComplex: boolean; inline; (* Equal operator for TCplx types. *) class operator Equal(const Left, Right: TCplx): Boolean; (* Equal operator for mixed TCplx and real types. *) class operator Equal(const Left: TCplx; Right: double): Boolean; (* Equal operator for mixed TCplx and real types. *) class operator Equal(Left: double; const Right: TCplx): Boolean; (* Not equal operator for TCplx types. *) class operator NotEqual(const Left, Right: TCplx): Boolean; inline; (* Not equal operator for mixed TCplx and real types. *) class operator NotEqual(const Left: TCplx; Right: double): Boolean; inline; (* Not equal operator for mixed TCplx and real types. *) class operator NotEqual(Left: double; const Right: TCplx): Boolean; inline; (* Less than operator for TCplx types. *) class operator LessThan(const ALeft, ARight: TCplx): Boolean; inline; (* Less than operator for mixed TCplx and real types. *) class operator LessThan(const ALeft: TCplx; ARight: double): Boolean; inline; (* Less than operator for mixed TCplx and real types. *) class operator LessThan(ALeft: double; const ARight: TCplx): Boolean; inline; (* Less than or equal operator for TCplx types. *) class operator LessThanOrEqual(const ALeft, ARight: TCplx): Boolean; inline; (* Less than or equal operator for mixed TCplx and real types. *) class operator LessThanOrEqual(const ALeft: TCplx; ARight: double): Boolean; inline; (* Less than or equal operator for mixed TCplx and rela types. *) class operator LessThanOrEqual(ALeft: double; const ARight: TCplx): Boolean; inline; (* Greater than operator for TCplx types. *) class operator GreaterThan(const ALeft, ARight: TCplx): Boolean; inline; (* Greater than operator for mixed TCplx and real types. *) class operator GreaterThan(const ALeft: TCplx; ARight: double): Boolean; inline; (* Greater than operator for mixed TCplx and real types. *) class operator GreaterThan(ALeft: double; const ARight: TCplx): Boolean; inline; (* Greater than or equal operator for TCplx types. *) class operator GreaterThanOrEqual(const ALeft, ARight: TCplx): Boolean; inline; (* Greater than or equal operator for mixed TCplx and real types. *) class operator GreaterThanOrEqual(const ALeft: TCplx; ARight: double): Boolean; inline; (* Greater than or equal operator for mixed TCplx and real types. *) class operator GreaterThanOrEqual(ALeft: double; const ARight: TCplx): Boolean; inline; {$DEFINE D24} (* Add operator for TCplx types. *) class operator Add(const Left, Right: TCplx): TCplx; (* Add operator for mixed TCplx and real types. *) class operator Add(const Left: TCplx; Right: double): TCplx; (* Add operator for mixed TCplx and real types. *) class operator Add(Left: double; const Right: TCplx): TCplx; (* Subtract operator for TCplx types. *) class operator Subtract(const Left, Right: TCplx): TCplx; (* Subtract operator for mixed TCplx and real types. *) class operator Subtract(const Left: TCplx; Right: double): TCplx; (* Subtract operator for mixed TCplx and real types. *) class operator Subtract(Left: double; const Right: TCplx): TCplx; (* Multiply operator for TCplx types. *) class operator Multiply(const Left, Right: TCplx): TCplx; (* Multiply operator for mixed TCplx and real types. *) class operator Multiply(const Left: TCplx; Right: double): TCplx; (* Multiply operator for mixed TCplx and real types. *) class operator Multiply(Left: double; const Right: TCplx): TCplx; (* Divide operator for TCplx types. *) class operator Divide(const Left, Right: TCplx): TCplx; (* Divide operator for mixed TCplx and real types. *) class operator Divide(const Left: TCplx; Right: double): TCplx; (* Divide operator for mixed TCplx and real types. *) class operator Divide(Left: double; const Right: TCplx): TCplx; (* Negate operator for TCplx types. *) class operator Negative(const AValue: TCplx): TCplx; inline; (* Operator for implicit conversion of string to TCplx type. *) class operator Implicit(const AValue: string): TCplx; inline; (* Operator for explicit conversion of TCplx to real type. Imaginary value is ignored. *) class operator Explicit(const AValue: TCplx): Double; inline; (* Operator for explicit conversion of TCplx to integer type. Imaginary value is ignored. *) class operator Explicit(const AValue: TCplx): integer; inline; (* Operator for explicit conversion of TCplx to int64 type. Imaginary value is ignored. *) class operator Explicit(const AValue: TCplx): Int64; inline; (* Operator for explicit conversion of type double to TCplx type. Imaginary value is set to 0. *) class operator Explicit(const AValue: double): TCplx; inline; (* Operator for explicit conversion of type single to TCplx type. Imaginary value is set to 0. *) class operator Explicit(const AValue: single): TCplx; inline; (* Operator for explicit conversion of type integer to TCplx type. Imaginary value is set to 0. *) class operator Explicit(const AValue: integer): TCplx; inline; (* Operator for explicit conversion of type int64 to TCplx type. Imaginary value is set to 0. *) class operator Explicit(const AValue: Int64): TCplx; inline; property Complex: boolean read IsComplex; end; (*Default complex number type used by Math387. Default complex number type used by Math387. *) TSCplx = packed record (*Real part of the complex number.*) Re: single; (*Imaginary part of the complex number.*) Im: single; (* Returns true if Imaginary component is zero. *) function IsComplex: boolean; inline; (* Equal operator for TSCplx types. *) class operator Equal(const Left, Right: TSCplx): Boolean; (* Equal operator for mixed TSCplx and real types. *) class operator Equal(const Left: TSCplx; Right: single): Boolean; (* Equal operator for mixed TSCplx and real types. *) class operator Equal(Left: single; const Right: TSCplx): Boolean; (* Not equal operator for TSCplx types. *) class operator NotEqual(const Left, Right: TSCplx): Boolean; inline; (* Not equal operator for mixed TSCplx and real types. *) class operator NotEqual(const Left: TSCplx; Right: single): Boolean; inline; (* Not equal operator for mixed TSCplx and real types. *) class operator NotEqual(Left: single; const Right: TSCplx): Boolean; inline; (* Less than operator for TSCplx types. *) class operator LessThan(const ALeft, ARight: TSCplx): Boolean; inline; (* Less than operator for mixed TSCplx and real types. *) class operator LessThan(const ALeft: TSCplx; ARight: single): Boolean; inline; (* Less than operator for mixed TSCplx and real types. *) class operator LessThan(ALeft: single; const ARight: TSCplx): Boolean; inline; (* Less than or equal operator for TSCplx types. *) class operator LessThanOrEqual(const ALeft, ARight: TSCplx): Boolean; inline; (* Less than or equal operator for mixed TSCplx and real types. *) class operator LessThanOrEqual(const ALeft: TSCplx; ARight: single): Boolean; inline; (* Less than or equal operator for mixed TSCplx and rela types. *) class operator LessThanOrEqual(ALeft: single; const ARight: TSCplx): Boolean; inline; (* Greater than operator for TSCplx types. *) class operator GreaterThan(const ALeft, ARight: TSCplx): Boolean; inline; (* Greater than operator for mixed TSCplx and real types. *) class operator GreaterThan(const ALeft: TSCplx; ARight: single): Boolean; inline; (* Greater than operator for mixed TSCplx and real types. *) class operator GreaterThan(ALeft: single; const ARight: TSCplx): Boolean; inline; (* Greater than or equal operator for TSCplx types. *) class operator GreaterThanOrEqual(const ALeft, ARight: TSCplx): Boolean; inline; (* Greater than or equal operator for mixed TSCplx and real types. *) class operator GreaterThanOrEqual(const ALeft: TSCplx; ARight: single): Boolean; inline; (* Greater than or equal operator for mixed TSCplx and real types. *) class operator GreaterThanOrEqual(ALeft: single; const ARight: TSCplx): Boolean; inline; (* Add operator for TSCplx types. *) class operator Add(const Left, Right: TSCplx): TSCplx; (* Add operator for mixed TSCplx and real types. *) class operator Add(const Left: TSCplx; Right: single): TSCplx; (* Add operator for mixed TSCplx and real types. *) class operator Add(Left: single; const Right: TSCplx): TSCplx; (* Subtract operator for TSCplx types. *) class operator Subtract(const Left, Right: TSCplx): TSCplx; (* Subtract operator for mixed TSCplx and real types. *) class operator Subtract(const Left: TSCplx; Right: single): TSCplx; (* Subtract operator for mixed TSCplx and real types. *) class operator Subtract(Left: single; const Right: TSCplx): TSCplx; (* Multiply operator for TSCplx types. *) class operator Multiply(const Left, Right: TSCplx): TSCplx; (* Multiply operator for mixed TSCplx and real types. *) class operator Multiply(const Left: TSCplx; Right: single): TSCplx; (* Multiply operator for mixed TSCplx and real types. *) class operator Multiply(Left: single; const Right: TSCplx): TSCplx; (* Divide operator for TSCplx types. *) class operator Divide(const Left, Right: TSCplx): TSCplx; (* Divide operator for mixed TSCplx and real types. *) class operator Divide(const Left: TSCplx; Right: single): TSCplx; (* Divide operator for mixed TSCplx and real types. *) class operator Divide(Left: single; const Right: TSCplx): TSCplx; (* Negate operator for TSCplx types. *) class operator Negative(const AValue: TSCplx): TSCplx; inline; (* Operator for implicit conversion of string to TSCplx type. *) class operator Implicit(const AValue: string): TSCplx; inline; (* Operator for explicit conversion of string to TSCplx type. *) class operator Explicit(const AValue: TCplx): TSCplx; inline; (* Operator for explicit conversion of string to TSCplx type. *) class operator Explicit(const AValue: TSCplx): TCplx; inline; (* Operator for explicit conversion of TSCplx to real type. Imaginary value is ignored. *) class operator Explicit(const AValue: TSCplx): Double; inline; (* Operator for explicit conversion of TSCplx to integer type. Imaginary value is ignored. *) class operator Explicit(const AValue: TSCplx): integer; inline; (* Operator for explicit conversion of TSCplx to int64 type. Imaginary value is ignored. *) class operator Explicit(const AValue: TSCplx): Int64; inline; (* Operator for explicit conversion of type double to TSCplx type. Imaginary value is set to 0. *) class operator Explicit(const AValue: double): TSCplx; inline; (* Operator for explicit conversion of type single to TSCplx type. Imaginary value is set to 0. *) class operator Explicit(const AValue: single): TSCplx; inline; (* Operator for explicit conversion of type integer to TSCplx type. Imaginary value is set to 0. *) class operator Explicit(const AValue: integer): TSCplx; inline; (* Operator for explicit conversion of type int64 to TSCplx type. Imaginary value is set to 0. *) class operator Explicit(const AValue: Int64): TSCplx; inline; property Complex: boolean read IsComplex; end; (*Base notify event.*) TMtxNotifyEvent = TNotifyEvent; (*Array of string.*) StringArray = TStringDynArray; T2DStringArray = array of StringArray; (*Complex number type for integer real and complex part. Complex number type for integer real and complex part. *) TICplx = packed record (*Real part*) Re: TISample; (*Imaginary part*) Im: TISample; end; (*Complex number type for integer real and complex part. Complex number type for integer real and complex part. *) TIntegerCplx = packed record (*Real part*) Re: integer; (*Imaginary part*) Im: integer; end; (*Complex number type for integer real and complex part. Complex number type for integer real and complex part. *) TSmallIntCplx = packed record (*Real part*) Re: integer; (*Imaginary part*) Im: integer; end; (*Complex number type for double real and complex part. Complex number type for double real and complex part. *) TDCplx = packed record (*Real part*) Re: double; (*Imaginary part*) Im: double; end; PDCplx = ^TDCplx; PPDCplx = PDCplx; PSCplx = ^TSCplx; PPSCplx = PSCplx; TSArray = array [0..200000000] of TSample; PSArray = ^TSArray; PPSArray = PSArray; TDArray = array [0..200000000] of Double; PDArray = ^TDArray; PPDArray = PDArray; TFArray = array [0..200000000] of Single; PFArray = ^TFArray; PPFArray = PFArray; TCArray = array [0..20000000] of TCplx; PCArray = ^TCArray; PPCArray = PCArray; TDCArray = array [0..20000000] of TDCplx; PDCArray = ^TDCArray; PPDCArray = PDCArray; TSCArray = array [0..20000000] of TSCplx; PSCArray = ^TSCArray; PPSCArray = PSCArray; TIArray = array [0..200000000] of integer; PIArray = ^TIArray; PPIArray = PIArray; TRArray = array [0..200000000] of Cardinal; PRArray = ^TRArray; PPRArray = PRArray; TWArray = array [0..200000000] of Word; PWArray = ^TWArray; PPWArray = PWArray; TSIArray = array [0..200000000] of SmallInt; PSIArray = ^TSIArray; PPSIArray = PSIArray; TBArray = array [0..200000000] of byte; PBArray = ^TBArray; PPBArray = PBArray; TCharArray = array [0..200000000] of char; PCharArray = ^TCharArray; PPCharArray = PCharArray; THArray = array [0..200000000] of ShortInt; PHArray = ^THArray; PPHArray = PHArray; TDCplxArray = array of TDCplx; TSCplxArray = array of TSCplx; TDoubleArray = array of Double; TSingleArray = array of Single; TIntegerArray = array of integer; PDoubleArray = ^TDoubleArray; PSingleArray = ^TSingleArray; TBooleanArray = array of boolean; TInt64Array = array of Int64; TUInt64Array = array of UInt64; TIntegerCplxArray = array of integer; PIntegerArray = ^TIntegerArray; TPointerIntegerArray = array of PointerInteger; TCardinalArray = array of cardinal; TWordArray = array of Word; TShortIntArray = array of ShortInt; TSmallIntArray = array of SmallInt; TSmallIntCplxArray = array of TSmallIntCplx; TByteArray = array of byte; TObjectArray = array of TObject; TCharsArray = array of char; TThreadIDArray = array of TThreadID; (*Array of TSample type. Array of type. *) TSampleArray = TDoubleArray; (*Array of TCplx type. Array of type. *) TCplxArray = array of TCplx; TCplxSingle = TSCplx; TCplxDouble = TCplx; TCplxSingleArray = TSCplxArray; TCplxDoubleArray = TCplxArray; TSmallInTCplxSampleArray = array of SmallInt; (*Array of Integer type. Array of type. *) TIntArray = TIntegerArray; (*Array of Integer type. Array of type. *) T2DIntegerArray = array of TIntegerArray; (*Array of SmallInt type. Array of type. *) T2DSmallIntArray = array of TSmallIntArray; (*Array of SmallInt type. Array of type. *) T2DByteArray = array of TByteArray; (*Two dimensional array of TSample type. Two dimensional array of type. *) T2DSingleArray = array of TSingleArray; T2DDoubleArray = array of TDoubleArray; T2DCplxDoubleArray = array of TCplxDoubleArray; T2DCplxSingleArray = array of TCplxSingleArray; (*Two dimensional array of TCplx type. Two dimensional array of type. *) T2DCplxArray = array of TCplxArray; (*Two dimensional array of TSCplx type. Two dimensional array of type. *) T2DSCplxArray = array of TSCplxArray; PCplxArray = ^TCplxArray; PIntArray = ^TIntArray; TBytec = record Re, Im: byte; end; PBytec = ^TBytec; TWordc = record Re, Im: word; end; PWordc = ^TWordc; TCardinalc = record Re, Im: cardinal; end; PCardinalc = ^TCardinalc; TShortintc = record Re, Im: ShortInt; end; PShortintc = ^TShortIntc; TSmallintc = record Re, Im: SmallInt; end; PSmallintc = ^TSmallIntc; TIntegerc = record Re, Im: cardinal; end; PIntegerc = ^TIntegerc; TInt64c = record Re, Im: Int64; end; PInt64c = ^TInt64c; Int32 = Integer; (*Pointer to char.*) PAPChar = PChar; (*Pointer to char.*) PAPAnsiChar = PAnsiChar; (*Generic pointer type.*) PAPointer = Pointer; (*Pointer to complex byte.*) PPBytec = PBytec; (*Pointer to complex word.*) PPWordc = PWordc; (*Pointer to complex unsigned integer.*) PPCardinalc = PCardinalc; (*Pointer to complex signed short (1 byte) integer.*) PPShortIntc = PShortintc; (*Pointer to complex signed small (2 byte) integer.*) PPSmallIntc = PSmallIntc; (*Pointer to complex signed (4 byte) integer.*) PPIntegerc = PIntegerc; (*Pointer to complex 8 byte floating point type.*) PPCplx = PCplx; (*Pointer to complex long (8 byte) integer.*) PPInt64c = PInt64c; (*Pointer to byte*) PPByte = PByte; (*Pointer to 2 byte unsigned integer (word).*) PPWord = PWord; (*Pointer to 4 byte unsigned integer.*) PPCardinal = ^Cardinal; (*Pointer to 1 byte signed integer.*) PPShortInt = ^ShortInt; (*Pointer to 2 byte signed integer.*) PPSmallInt = ^SmallInt; PPPointerInteger = PPointerInteger; PPLongInteger = PLongInteger; (*Pointer to 4 byte signed integer.*) PPInteger = System.PInteger; (*Pointer to TSample.*) PPSample = PSample; (*Pointer to signed 8 byte integer.*) PPInt64 = System.PInt64; (*Pointer to 4 byte floating point.*) PPSingle = System.PSingle; (*Pointer to 8 byte floating point.*) PPDouble = System.PDouble; (*Pointer to byte.*) PPUChar = System.PByte; TPointerArray = array of PAPointer; type (*Type used to define indexation type.*) TIndexType = ( (*Incremented value.*)indIncrement, (*Vector of indices.*)indVector, (*Mask vector.*)indMask); (*The waiting method used by the sorted critical section.*) TCRWaitMode = ( (*The critical section will use sleep(0) to wait. (Default) Use for computational threads with max-thread count less than hyper-threaded core count.*) crwSleep0 = 0, (*The critical section will enter sleep(1) to wait. Use when cooperative multi-threading is used. Number of launched threads executing concurrently is more than hyper-threaded core count or working with I/O devices.*) crwSleep1 = 1, (*The critical section will call SwitchToThread to wait.*) crwSwitchThread = 2); (*Enables threads in a multithreaded application a single-thread only exclusive execution of a part of the code. Critical sections in general safeguard memory access operations in a piece of code, which might cause corruption, if they are executed concurrently by multiple threads at the same time. They are used always when there is a need to share resource, like for example memory. Once a thread enters a critical section, by calling the Enter method, all other threads will wait at the "Enter" entry, until "Leave" is called. At this point the next thread (one at a time), is allowed to continue past the "Enter" entry. The sorted critical section implementation is a FIFO design (First-In-First-Out) and will pass threads strictly in the order in which they arrive. When there are many (8, 16 or more) threads all passing through the same critical section, the ability to guarantee the order in which they pass, leads to substantial performance improvements. The Windows OS standard critical section implementations (up until year 2022) throw a dice each time a thread enters sleep, because the sleep time is not deterministic. This can lead to starvation of some threads, which might never get to "Enter", while others have entered the protected code section multiple times already. If each thread needs to allocate 2 pieces of memory, and one thread is starved for this, but all threads need to finish to finish the job, then the execution time of multi-threaded code will be extended proportionally. Important: TFiFoCriticalSection performance will deliver best results, when the launched thread count within the process does not exceed hyper-threaded thread count of the system. Threads, which exceed this number, will sleep until one of the executing threads enters sleep or exits (Windows OS kernel as-designed feature). If launched thread count is very high. this can lead to (uneccessary), wakes of threads, which otherwise sleep anyway, to find the right one to continue the execution. *) TFifoCriticalSection = class strict private EnterCounter: integer; ExecCounter: integer; public (*Tries to enter without locking. Checks, if the critical sections thread waiting queue is empty and enters immediately. Important: Always need to call "Leave" before calling "Enter" or trying to enter on the same critical section by the same thread again. *) function TryEnter: boolean; (*Enter the critical section. Guarantees the sequence of threads that pass through, to match the order in which they called Enter. Important: Always need to call "Leave" before calling "Enter" on the same critical section by the same thread again. *) procedure Enter; (*Leave the critical section. Guarantees the sequence of threads that pass through, to match the sequence in which they called Enter. Important: Always need to call "Leave" before calling "Enter" on the same critical section by the same thread again. *) procedure Leave; (*Initialize the critical section. The default value for aWaitMode is TCRWaitMode.crwSleep. Initialization/Constructor is required. It is not enough to set all fields to zero. *) constructor Create; virtual; end; (*Critical section with semaphore capability. This class allows multiple threads to run concurrently within a critical section. The maximum number of such threads will be limited to "Count". The threads will enter strictly in the order in which they arrive, but they may exit in any order depending on the workload assigned to each thread within the critical section. If all threads require a shared resource, this construct allows the programmer to limit the number of threads to the number of available shared resource(s). *) TFairSemaphoreSection = class strict private EnterCounter: integer; ExecCounter: integer; MinCounter: integer; FCount: integer; Slots: TThreadIDArray; public (*Specifies the number of threads that can enter concurrently.*) property Count: integer read FCount; (*Enter the critical section. Guarantees the sequence of threads that pass through, to match the order in which they called Enter. The function will return the index of the free shared resource. The index will start at 0 and end at Count - 1 and is guaranteed to be unusued by any thread currently executing within the critical section. The Count property of this class specifies the number of threads that can enter the semaphored critical section concurrently. Call "Leave" before calling "Enter" on the same critical section by the same thread again. *) function Enter: integer; (*Leave the critical section. Call "Leave" before calling "Enter" on the same critical section by the same thread again. *) procedure Leave; overload; (*Leave the critical section. The SharedResourceIndex parameter must be the same what was returned by the Enter method when called by the same thread. This is the index of the shared resource to be released. Call "Leave" before calling "Enter" on the same critical section by the same thread again. *) procedure Leave(const SharedResourceIndex: integer); overload; (*Initialize the critical section. The call of this constructor is required. *) constructor Create(ResourceCount: integer); virtual; end; (*Enables threads in a multithreaded application a single-thread only exclusive execution of a part of the code. The record needs to be initialized with a call to init. The order in which the threads will pass is not deterministic. *) TSimpleCriticalSection = record public (*Initializes the critical section, if the constructor was not used.*) class procedure Init(var csLock: integer); overload; static; (*Enter the critical section. The order in which the threads will pass is not deterministic. The waiting loop is using Sleep(0). *) class procedure Enter(var csLock: integer; const TrueValue: integer = 1); overload; static; (*Enter the critical section. The order in which the threads will pass is not deterministic. *) class function TryEnter(var csLock: integer; const TrueValue: integer = 1): boolean; overload; static; (*Leave the critical section. The order in which the threads will pass is not deterministic. *) class procedure Leave(var csLock: integer); overload; static; end; type (*Type used to define the storage format for FFT operations. Defines the storage format used when performing forward and inverse FFT's. The result of a forward FFT operation is an array of complex numbers. Notation: * Re(0) is the real part of the complex number stored at index 0. * Im(0) is the imaginary part of the complex number stored at index 0. The length of the FFT is N and d = N/2. N is an even value. For these parameters the complex to complex FFT returns the following complex array: (Re(0), Im(0)), (Re(1), Im(1)),...,(Re(d), Im(d)), ... , (Re(N-1), Im(N-1)) If the source was real, the real to complex FFT computes only the first half of that table, namely: (Re(0), Im(0)), (Re(1), Im(1)),...,(Re(d), Im(d)) That is because beyond index d, all elements are conjugate symmetric part of elements below index d. For example, it is possible to compute the upper half of the array doing operation's like this: (Re(d+1), Im(d+1)) = (Re(d-1), - Im(d-1)) The storage format that stores the FFT result as presented here is called the CCS format. A speciallity of the FFT result is that Im(0) and Im(d) are always zero. Because these two values are implicitely known in advance, they do not have to be stored. This is exploited by two other storage formats: pack and perm. The pack format simply leaves out the zeros and pushes the elements together and the perm format stores the Re(d) value at the position of Im(0) and pushes the elements together. If the length of the FFT N is odd, then everything remains the same, except that the center element at index d is absent. This means that pack and perm have the same storage format in this case. For a 2D FFT similar rules apply and the storage formats layout is as follows: CCS format, m x n matrix Even length (m = s*2) Re(1,1) 0 Re(1,2) Im(1,2) ... Re(1,k) Im(1,k) Re(1,k+1) 0 0 0 0 0 ... 0 0 0 0 Re(2,1) Re(2,2) Re(2,3) Re(2,4) ... Re(2,n-1) Re(2,n) n/u n/u Im(2,1) Im(2,2) Im(2,3) Im(2,4) ... Im(2,n-1) Im(2,n) n/u n/u ... ... ... ... ... ... ... n/u n/u Re(m/2,1) Re(m/2,2) Re(m/2,3) Re(m/2,4) ... Re(m/2,n-1) Re(m/2,n) n/u n/u Im(m/2,1) Im(m/2,2) Im(m/2,3) Im(m/2,4) ... Im(m/2,n-1) Im(m/2,n) n/u n/u Re(m/2+1,1) 0 Re(m/2+1,2) Im(m/2+1,2) ... Re(m/2+1,k) Im(m/2+1,k) Re(m/2+1,k+1) 0 0 0 0 0 ... 0 0 n/u n/u Odd length (m = s*2+1) Re(1,1) 0 Re(1,2) Im(1,2) ... Re(1,k) Im(1,k) Re(1,k+1) 0 0 0 0 0 ... 0 0 0 0 Re(2,1) Re(2,2) Re(2,3) Re(2,4) ... Re(2,n-1) Re(2,n) n/u n/u Im(2,1) Im(2,2) Im(2,3) Im(2,4) ... Im(2,n-1) Im(2,n) n/u n/u ... ... ... ... ... ... ... n/u n/u Re(s,1) Re(s,2) Re(s,3) Re(s,4) ... Re(s,n-1) Re(s,n) n/u n/u Im(s,1) Im(s,2) Im(s,3) Im(s,4) ... Im(s,n-1) Im(s,n) n/u n/u PACK format, m x n matrix Even length (m = s*2) Re(1,1) Re(1,2) Im(1,2) Re(1,3) ... Im(1,k) Re(1,k+1) Re(2,1) Re(2,2) Re(2,3) Re(2,4) ... Re(2,n-1) Re(2,n) Im(2,1) Im(2,2) Im(2,3) Im(2,4) ... Im(2,n-1) Im(2,n) ... ... ... ... ... ... ... Re(m/2,1) Re(m/2,2) Re(m/2,3) Re(m/2,4) ... Re(m/2,n-1) Re(m/2,n) Im(m/2,1) Im(m/2,2) Im(m/2,3) Im(m/2,4) ... Im(m/2,n-1) Im(m/2,n) z(m/2+1,1) Re(m/2+1,2) Im(m/2+1,2) Re(m/2+1,3) ... Im(m/2+1,k) z(m/2+1,k+1) Odd length (m = s*2+1) Re(1,1) Re(1,2) Im(1,2) Re(1,3) ... Im(1,k) Re(1,n/2+1) Re(2,1) Re(2,2) Re(2,3) Re(2,4) ... Re(2,n-1) Re(2,n) Im(2,1) Im(2,2) Im(2,3) Im(2,4) ... Im(2,n-1) Im(2,n) ... ... ... ... ... ... ... Re(s,1) Re(s,2) Re(s,3) Re(s,4) ... Re(s,n-1) Re(s,n) Im(s,1) Im(s,2) Im(s,3) Im(s,4) ... Im(s,n-1) Im(s,n) PERM Format, m x n matrix Even length (m = s*2) Re(1,1) Re(1,k+1) Re(1,2) Im(1,2) ... Re(1,k) Im(1,k) Re(m/2+1,1) Re(m/2+1,k+1) Re(m/2+1,2) Im(m/2+1,2) ... Re(m/2+1,k) Im(m/2+1,k) Re(2,1) Re(2,2) Re(2,3) Re(2,4) ... Re(2,n-1) Re(2,n) Im(2,1) Im(2,2) Im(2,3) Im(2,4) ... Im(2,n-1) Im(2,n) ... ... ... ... ... ... ... Re(m/2,1) Re(m/2,2) Re(m/2,3) Re(m/2,4) ... Re(m/2,n-1) Re(m/2,n) Im(m/2,1) Im(m/2,2) Im(m/2,3) Im(m/2,4) ... Im(m/2,n-1) Im(m/2,n) Odd length (m = s*2+1) Re(1,1) Re(1,k+1) Re(1,2) Im(1,2) ... Re(1,k) Im(1,k) Re(2,1) Re(2,2) Re(2,3) Re(2,4) ... Re(2,n-1) Re(2,n) Im(2,1) Im(2,2) Im(2,3) Im(2,4) ... Im(2,n-1) Im(2,n) ... ... ... ... ... ... ... Re(s,1) Re(s,2) Re(s,3) Re(s,4) ... Re(s,n-1) Re(s,n) Im(s,1) Im(s,2) Im(s,3) Im(s,4) ... Im(s,n-1) Im(s,n) *) TFFTStorageFormat = ( (* This is the "natural" FFT storage format. It's main disadvantages are: * You cannot perform an inverse FFT to real, without telling the routine of what length should the result be: odd or even. * When performing real to complex FFT, the size of the result is bigger than the size of the source data. This requires that the initial data is stored in to an array which allocates more memory then occupied by the source (2 real numbers more) *) fsfCCS ); type (*Function type with two parameters.*) TSelectTwoFunction = function(var a,b: double): integer; cdecl; (*Function type with two parameters.*) TSelectThreeFunction = function(var a,b,c: double): integer; cdecl; (*Function type with two parameters.*) TSelectOneFunctionC = function(var a: TCplx): integer; cdecl; (*Function type with two parameters.*) TSelectTwoFunctionC = function(var a,b: TCplx): integer; cdecl; (*Function type with two parameters.*) TSelectTwoFunctionSingle = function(var a,b: single): integer; cdecl; (*Function type with two parameters.*) TSelectThreeFunctionSingle = function(var a,b,c: single): integer; cdecl; (*Function type with two parameters.*) TSelectOneFunctionSingleC = function(var a: TSCplx): integer; cdecl; (*Function type with two parameters.*) TSelectTwoFunctionSingleC = function(var a,b: TSCplx): integer; cdecl; TMKLTRFunction = procedure(var m,n: Integer; xi, fi: Pointer; CustomData: TObject); cdecl; Tgemm_jit_kernel_tp = procedure(jitter: PAPointer; const a, b, c: PAPointer); cdecl; Tdgemm_jit_kernel_t = procedure(jitter: PAPointer; const a, b, c: TDoubleArray); cdecl; Tzgemm_jit_kernel_t = procedure(jitter: PAPointer; const a, b, c: TCplxDoubleArray); cdecl; Tdgemm_jit_kernel_tp = procedure(jitter: PAPointer; const a, b, c: PAPointer); cdecl; Tzgemm_jit_kernel_tp = procedure(jitter: PAPointer; const a, b, c: PAPointer); cdecl; Tsgemm_jit_kernel_t = procedure(jitter: PAPointer; const a, b, c: TSingleArray); cdecl; Tcgemm_jit_kernel_t = procedure(jitter: PAPointer; const a, b, c: TCplxSingleArray); cdecl; Tsgemm_jit_kernel_tp = procedure(jitter: PAPointer; const a, b, c: PAPointer); cdecl; Tcgemm_jit_kernel_tp = procedure(jitter: PAPointer; const a, b, c: PAPointer); cdecl; type TMKL_Sparse_status = ( (*the operation was successful*) SPARSE_STATUS_SUCCESS = 0, (*empty handle or matrix arrays*) SPARSE_STATUS_NOT_INITIALIZED = 1, (*internal error: memory allocation failed*) SPARSE_STATUS_ALLOC_FAILED = 2, (*invalid input value*) SPARSE_STATUS_INVALID_VALUE = 3, (*e.g. 0-diagonal element for triangular solver, etc.*) SPARSE_STATUS_EXECUTION_FAILED = 4, (*internal error*) SPARSE_STATUS_INTERNAL_ERROR = 5, (*e.g. operation for double precision doesn't support other types*) SPARSE_STATUS_NOT_SUPPORTED = 6 ); TMKL_Sparse_operation = ( SPARSE_OPERATION_NON_TRANSPOSE = 10, SPARSE_OPERATION_TRANSPOSE = 11, SPARSE_OPERATION_CONJUGATE_TRANSPOSE = 12 ); TMKL_Sparse_matrix_type = ( (*General case*) SPARSE_MATRIX_TYPE_GENERAL = 20, (*Triangular part of the matrix is to be processed*) SPARSE_MATRIX_TYPE_SYMMETRIC = 21, SPARSE_MATRIX_TYPE_HERMITIAN = 22, SPARSE_MATRIX_TYPE_TRIANGULAR = 23, (*diagonal matrix; only diagonal elements will be processed*) SPARSE_MATRIX_TYPE_DIAGONAL = 24, SPARSE_MATRIX_TYPE_BLOCK_TRIANGULAR = 25, (*block-diagonal matrix; only diagonal blocks will be processed*) SPARSE_MATRIX_TYPE_BLOCK_DIAGONAL = 26 ); TMKL_Sparse_index_base = ( (*C-style*) SPARSE_INDEX_BASE_ZERO = 0, (*Fortran-style*) SPARSE_INDEX_BASE_ONE = 1 ); (* Applies to triangular matrices only ( SPARSE_MATRIX_TYPE_SYMMETRIC, SPARSE_MATRIX_TYPE_HERMITIAN, SPARSE_MATRIX_TYPE_TRIANGULAR ) *) TMKL_Sparse_fill_mode = ( (*lower triangular part of the matrix is stored*) SPARSE_FILL_MODE_LOWER = 40, (*upper triangular part of the matrix is stored*) SPARSE_FILL_MODE_UPPER = 41, (*upper triangular part of the matrix is stored*) SPARSE_FILL_MODE_FULL = 42 ); (* Applies to triangular matrices only ( SPARSE_MATRIX_TYPE_SYMMETRIC, SPARSE_MATRIX_TYPE_HERMITIAN, SPARSE_MATRIX_TYPE_TRIANGULAR ) *) TMKL_Sparse_diag_type = ( (*Triangular matrix with non-unit diagonal*) SPARSE_DIAG_NON_UNIT = 50, (*Triangular matrix with unit diagonal*) SPARSE_DIAG_UNIT = 51 ); (* Applicable for Level 3 operations with dense matrices; describes storage scheme for dense matrix (row major or column major) *) TMKL_Sparse_layout = ( (*C-style*) SPARSE_LAYOUT_ROW_MAJOR = 101, (*Fortran-style*) SPARSE_LAYOUT_COLUMN_MAJOR = 102 ); (* If verbose mode activated, handle should collect and report profiling / optimization info *) TMKL_Verbose_mode = ( SPARSE_VERBOSE_OFF = 70, (*Output contains high-level information about optimization algorithms, issues, etc.*) SPARSE_VERBOSE_BASIC = 71, (*Provide detailed output information*) SPARSE_VERBOSE_EXTENDED = 72 ); (* memory optimization hints from user: describe how much memory could be used on optimization stage *) TMKL_Sparse_memory_usage = ( (*No memory should be allocated for matrix values and structures; auxiliary structures could be created only for workload balancing, parallelization, etc.*) SPARSE_MEMORY_NONE = 80, (*matrix could be converted to any internal format*) SPARSE_MEMORY_AGGRESSIVE = 81 ); TMKL_Sparse_request = ( SPARSE_STAGE_FULL_MULT = 90, SPARSE_STAGE_NNZ_COUNT = 91, SPARSE_STAGE_FINALIZE_MULT = 92, SPARSE_STAGE_FULL_MULT_NO_VAL = 93, SPARSE_STAGE_FINALIZE_MULT_NO_VAL = 94 ); (* Applies to SOR interface; define type of (S)SOR operation to perform *) TMKL_Sparse_sor_type = ( (*(omegaL + D)*x^1 = (D - omega*D - omega*U)*alpha*x^0 + omega*b*) SPARSE_SOR_FORWARD = 110, (*(omegaU + D)*x^1 = (D - omega*D - omega*L)*alpha*x^0 + omega*b*) SPARSE_SOR_BACKWARD = 111, (*SSOR, for e.g. with (omega == 1) and (alpha == 1), equal to solving a system: (L + D) X x^1 = b - U*x; (U + D) X x = b - L*x^1*) SPARSE_SOR_SYMMETRIC = 112 ); TMKL_Matrix_descr = packed record (*matrix type: general, diagonal or triangular / symmetric / hermitian*) sType: TMkl_Sparse_matrix_type; (*upper or lower triangular part of the matrix ( for triangular / symmetric / hermitian case)*) mode: TMkl_Sparse_fill_mode; (*unit or non-unit diagonal ( for triangular / symmetric / hermitian case)*) diag: TMkl_Sparse_diag_type; end; TMklSparseMatrix = PAPointer; TMKL_Layout = ( MKL_ROW_MAJOR = 101, MKL_COL_MAJOR = 102 ); TMKL_Transpose = ( MKL_NOTRANS = 111, MKL_TRANS = 112, MKL_CONJTRANS = 113, MKL_CONJ = 114 ); TMKL_Uplo = ( MKL_UPPER = 121, MKL_LOWER = 122 ); TMKL_Diag = ( MKL_NONUNIT = 131, MKL_UNIT = 132 ); TMKL_Side = ( MKL_LEFT = 141, MKL_RIGHT = 142 ); TMKL_Compact_Pack = ( MKL_COMPACT_SSE = 181, MKL_COMPACT_AVX = 182, MKL_COMPACT_AVX512 = 183 ); TMKL_Jit_Status = ( MKL_JIT_SUCCESS = 0, MKL_NO_JIT = 1, MKL_JIT_ERROR = 2 ); (*Base exception class for MtxVec library. Parent class for all exception classes in MtxVec library. *) EMtxVecException = class (Exception) end; (*Exception class indicates out of range error. Raises exception if an out of range error occurres. *) EMtxVecRangeError = class (EMtxVecException) end; (*Exception class indicates invalid arguments error. Raises exception if invalid parameters were passed to the procedure. *) EMtxVecInvalidArgument = class (EMtxVecException) end; (*Rounding algorithm.*) TRounding = ( (*Truncate values to nearest integer.*)rnTrunc, (*Round values towards nearest integer.*)rnRound); (*Comparison type for the Equal function. Determines the method used to compare two floating point numbers in order to determine if they are equal or not within some tolerance. *) TCompare = ( (*a and b are equal, if the following expression is true: abs(a-b) < Tolerance. *) cmpAbsolute, (*a and b are equal, if the following expression is true: abs(a-b)/Max( abs(a),abs(b) ) <= Tolerance This method also requires a special "zero tolerance" parameter, which determines how small must a number be so that it can be considered to be zero. *) cmpRelative ); const (*PI. = PI. *)PI: double = 3.14159265358979323846; (*PI. = PI. *)PI_SINGLE: single = 3.14159265358979323846; (*Ln(2). = Ln(2) *)LN2: double = 0.69314718055994530942; (*Ln(2). = Ln(2) *)LN2_SINGLE: single = 0.69314718055994530942; (*Ln(10). = Ln(10) *)LN10: double = 2.30258509299404568402; (*Ln(10). = Ln(10) *)LN10_SINGLE: single = 2.30258509299404568402; (*Ln(PI). = Ln(PI). *)LNPI: double = 1.14472988584940017414; (*Ln(PI). = Ln(PI). *)LNPI_SINGLE: single = 1.14472988584940017414; (*1/Ln(2). = 1/Ln(2) *)INVLN2: double = 1.44269504088896340736; (*1/Ln(2). = 1/Ln(2) *)INVLN2_SINGLE: single = 1.44269504088896340736; (*1/Ln(10). = 1/Ln(10) *)INVLN10: double = 0.43429448190325182765; (*1/Ln(10). = 1/Ln(10) *)INVLN10_SINGLE: single = 0.43429448190325182765; (*2*PI. = 2*PI. *)TWOPI: double = 6.28318530717958647693; (*2*PI. = 2*PI. *)TWOPI_SINGLE: single = 6.28318530717958647693; (*1/2PI. = 1/2PI *)INVTWOPI: double = 0.1591549430918953420; (*1/2PI. = 1/2PI *)INVTWOPI_SINGLE: single = 0.1591549430918953420; (*PI/2. = PI/2 *)PIDIV2: double = 1.57079632679489661923; (*PI/2. = PI/2 *)PIDIV2_SINGLE: single = 1.57079632679489661923; (*Sqrt(PI). = Sqrt(PI) *)SQRTPI: double = 1.77245385090551602730; (*Sqrt(PI). = Sqrt(PI) *)SQRTPI_SINGLE: single = 1.77245385090551602730; (*Sqrt(2PI) = Sqrt(2PI) *)SQRT2PI: double = 2.50662827463100050242; (*Sqrt(2PI) = Sqrt(2PI) *)SQRT2PI_SINGLE: single = 2.50662827463100050242; (*1/Sqrt(2PI). = 1/Sqrt(2PI) *)INVSQRT2PI: double = 0.39894228040143267794; (*1/Sqrt(2PI). = 1/Sqrt(2PI) *)INVSQRT2PI_SINGLE: single = 0.39894228040143267794; (*Ln(Sqrt(2*PI)). = Ln(Sqrt(2*PI) *)LNSQRT2PI: double = 0.91893853320467274178; (*Ln(Sqrt(2*PI)). = Ln(Sqrt(2*PI) *)LNSQRT2PI_SINGLE: single = 0.91893853320467274178; (*Ln(2*PI)/2. = Ln(2*PI)/2 *)LN2PIDIV2: double = 0.91893853320467274178; (*Ln(2*PI)/2. = Ln(2*PI)/2 *)LN2PIDIV2_SINGLE: single = 0.91893853320467274178; (*Sqrt(2). = Sqrt(2) *)SQRT2: double = 1.41421356237309504880; (*Sqrt(2). = Sqrt(2) *)SQRT2_SINGLE: single = 1.41421356237309504880; (*Sqrt(2)/2. = Sqrt(2)/2 *)SQRT2DIV2: double = 0.70710678118654752440; (*Sqrt(2)/2. = Sqrt(2)/2 *)SQRT2DIV2_SINGLE: single = 0.70710678118654752440; (*Golden Mean. = (1 + Sqrt(5))/2 *)GOLD: double = 1.61803398874989484821; (*Golden Mean. = (1 + Sqrt(5))/2 *)GOLD_SINGLE: single = 1.61803398874989484821; (*2 - GOLD. = 2 - GOLD *)CGOLD: double = 0.38196601125010515179; (*2 - GOLD. = 2 - GOLD *)CGOLD_SINGLE: single = 0.38196601125010515179; (*PI/180. = PI/180 *)PI180: double = 0.01745329251994329577; (*PI/180. = PI/180 *)PI180_SINGLE: single = 0.01745329251994329577; (*180/PI. = 180/PI. *)INVPI180: double = 57.2957795130823208768; (*180/PI. = 180/PI. *)INVPI180_SINGLE: single = 57.2957795130823208768; (*Euler constant. Euler-Mascheroni, the so called Euler gamma constant. *) EULERGAMMA: double = 0.5772156649015328606; (*Euler constant. Euler-Mascheroni, the so called Euler gamma constant. *) EULERGAMMA_SINGLE: single = 0.5772156649015328606; S_ONE: double = 1; S_ZERO: double = 0; S_ONE_SINGLE: single = 1; S_ZERO_SINGLE: single = 0; (*Euler number (e).*) EULER_NUMBER: double = 2.71828182845904523536028747135; (*Euler number (e).*) EULER_NUMBER_SINGLE: single = 2.71828182845904523536028747135; const (*Machine constant. Same as EPS=2^(-52). *) MACHEP: double = 2.220446049250313E-16; (*Epsilon. Machine constant. *) EPS = 2.220446049250313E-16; (*Sqrt(EPS). Square root of EPS. *) SQRTEPS = 1.4901161194e-08; (*Maximum floating point number. Maximum floating point number. *)MAXNUM = 1.797693134862315E+308; (*Minimum floating point number. Minimum floating point number: 2^(-1022). *)MINNUM: double = 2.225073858507202E-308; (*Largest result of a base 10 logarithm. Largest result of a base 10 logarithm. *)MAXLOG: double = 709.7827128933840; (*Smallest result of a base 10 logarithm. Smallest result of a base 10 logarithm. *)MINLOG: double = -708.3964185322641; (*Maximum factorial. Maximum factorial. *)MAXFAC: double = 170; (*Maximum value of the gamma function. Maximum value of the gamma function. *)MAXGAM: double = 171.624376956302; (*Maximum allowed value for the logarithm of the gamma function. If the input parameter to the lnGamma function is bigger, the function will return INF. *)MAXLGM: double = 2.556348E+305; const MACHEP_SINGLE: single = 1.192093E-7; EPS_SINGLE: single = 1.192093E-7; SQRTEPS_SINGLE:single = 0.0003452670062; MAXNUM_SINGLE: single = 3.402823E+38; MINNUM_SINGLE: single = 1.175495E-38; MAXLOG_SINGLE: single = 88.72283; MINLOG_SINGLE: single = -87.33655; MAXFAC_SINGLE: single = 33; MAXGAM_SINGLE: single = 34.648; MAXLGM_SINGLE: single = 1.0383E+36; const (*Complex zero. Complex zero. *)C_ZERO: TCplx = (Re: 0.0; Im: 0.0); (*Complex one. = 1+0*i. *)C_ONE: TCplx = (Re: 1.0; Im: 0.0); (*Imaginary value. = 0+1*i. *)C_I: TCplx = (Re: 0.0; Im: 1.0); (*PI. = PI+0*i. *)C_PI: TCplx = (Re: 3.14159265358979323846; Im: 0.0); (*PI/2. = PI/2+0*i. *)C_PI_DIV_2: TCplx = (Re: 1.57079632679489661923; Im: 0.0); (*Complex zero. Complex zero. *)C_ZERO_SINGLE: TSCplx = (Re: 0.0; Im: 0.0); (*Complex one. = 1+0*i. *)C_ONE_SINGLE: TSCplx = (Re: 1.0; Im: 0.0); (*Imaginary value. = 0+1*i. *)C_I_SINGLE: TSCplx = (Re: 0.0; Im: 1.0); (*PI. = PI+0*i. *)C_PI_SINGLE: TSCplx = (Re: 3.14159265358979323846; Im: 0.0); (*PI/2. = PI/2+0*i. *)C_PI_DIV_2_SINGLE: TSCplx = (Re: 1.57079632679489661923; Im: 0.0); Saved8087: word = $1332; kTab = Chr(9); (*Incomplete Gamma function: series expansion. Incomplete Gamma function (series expansion). Uses series expansion to calculate the incomplete Gamma function. *) function GammaSer(A, X : double) : double; overload; (*Incomplete Gamma function : series expansion. Complex version. *) function GammaSer(A: double;const X: TCplx) : TCplx; overload; (*Incomplete Gamma function : continued fraction expansion. the Incomplete Gamma function : continued fraction expansion. Uses fractional expansion to calculate the incomplete Gamma function. *) function GammaFrac(A, X : double) : double; overload; (*Incomplete Gamma function : continued fraction expansion. Incomplete Gamma function as complex number.*) function GammaFrac(A: double;const X : TCplx) : TCplx; overload; (*Incomplete gamma function. the incomplete gamma function. The IGamma function is defined by the following equation: where Gamma is function. Depending on parameters a and x fractional or series expansion is used to calculate the incomplete Gamma function. *) function IGamma(A, X: double): double; overload; (*Incomplete gamma function.*) function IGamma(A: double;const X: TCplx): TCplx; overload; (*Complement to the incomplete gamma function. the complement to the incomplete gamma function. The JGamma function is defined by the following equation: where Gamma is function. *) function JGamma(A, X: double): double; overload; (*Complement to the incomplete gamma function. Complex version. *) function JGamma(A: double;const X: TCplx) : TCplx; overload; (*Error function. the error function for given parameter X. X in Error function definition. The error function is defined by the following equation: *) function Erf(X: double): double; overload; (*Inverse error function. the Inverse error function. Returns the inverse error function Erf for given y. The inverse error function satisfies the equation x=Erf(y). *) function ErfInv(y: double): double; overload; (*Complement to the error function Erf. the complement to the error function Erf. The Erfc function is defined by the following equation: *) function Erfc(X: double): double; overload; (*Checks if number is NAN. true if complex number X is NAN.*) function IsNaN(const X: TCplx): boolean; overload; inline; function IsNaN(const X: TSCplx): boolean; overload; inline; (*Checks if number is NAN. true if real number X is NAN. *) function IsNaN(const X: double): boolean; overload; inline; function IsNanf(const X: single): boolean; overload; (*Checks if number is INF. true if complex number X is INF.*) function IsInf(const X: TCplx): boolean; overload; inline; function IsInf(const X: TSCplx): boolean; overload; inline; (*Checks if number is INF. true if real number X is INF. *) function IsInf(const X: double): boolean; overload; inline; function IsInff(const X: single): boolean; overload; inline; (*Checks if number is INF 0r NAN. true if complex number X is INF or NAN.*) function IsInfNan(const X: TCplx): boolean; overload; inline; function IsInfNan(const X: TSCplx): boolean; overload; inline; (*Checks if number is INF or NAN. true if real number X is INF or NAN. *) function IsInfNan(const X: double): boolean; overload; inline; function IsInfNanf(const X: single): boolean; overload; inline; (*Checks if number is INF or NAN. true if real number X is INF or NAN. *) function IsNanInf(const X: TCplx): boolean; overload; inline; function IsNanInf(const X: TSCplx): boolean; overload; inline; (*Checks if number is INF or NAN. true if real number X is INF or NAN. *) function IsNanInf(const X: double): boolean; overload; inline; function IsNanInff(const X: single): boolean; overload; inline; (*Minimum of two numbers. the minimum of two complex numbers X and Y. Complex numbers are first compared by the absolute value. If they are equal they are further compared by the unwrapped phase -PI,PI angle. *) function Min(const X, Y : TCplx) : TCplx; overload; function Min(const X, Y : TSCplx) : TSCplx; overload; (*Maximum of two numbers. the maximum of two complex numbers X and Y. Complex numbers are first compared by the absolute value. If they are equal they are further compared by the unwrapped phase -PI,PI angle. *) function Max(const X, Y : TCplx) : TCplx; overload; function Max(const X, Y : TSCplx) : TSCplx; overload; (*Minimum of two real numbers X and Y. the minimum of two real numbers X and Y.*) function Min(X, Y: double) : double; overload; inline; function Minf(X, Y: single) : single; overload; inline; (*Maximum of two real numbers X and Y. the maximum of two real numbers X and Y. *) function Max(X, Y: double): double; overload; inline; function Maxf(X, Y: single): single; overload; inline; (*Minimum of two integer numbers X and Y. the minimum of two integer numbers X and Y. *) function Min(X, Y: Integer) : Integer; overload; inline; (*Maximum of two integer numbers X and Y. the maximum of two integer numbers X and Y. *) function Max(X, Y: Integer) : Integer; overload; inline; (*Minimum of two 64bit integer numbers X and Y. the minimum of two 64bit integer numbers X and Y. *) function Min(X, Y: Int64) : Int64; overload; inline; (*Maximum of two 64bit integer numbers X and Y. the maximum of two 64bit integer numbers X and Y. *) function Max(X, Y: Int64) : Int64; overload; inline; (*Real part of complex number. the real part of complex number X. *) function Real(const X: TCplx): double; overload; inline; function Real(const X: TSCplx): single; overload; inline; (*Imaginary part of complex number. the imaginary part of complex number X. *) function Imag(const X: TCplx): double; overload; inline; function Imag(const X: TSCplx): single; overload; inline; (*Swaps real and imaginary part. Flipped complex number: Flip(x+i*y), becomes: y+i*x *) function Flip(const X: TCplx): TCplx; overload; function Flip(const X: TSCplx): TSCplx; overload; (*Swaps real and imaginary part and conjugates the result. Flipped conjugated complex number: Flip(x+i*y), becomes: y-i*x. *) function FlipConj(const X: TCplx): TCplx; overload; function FlipConj(const X: TSCplx): TSCplx; overload; (*Swaps real and imaginary part and conjugates the result. Defines the input parameter for swapping real and complex part. Stores the result of swapping and conjugating: a+i*b, becomes: b-i*a.*) procedure FlipConj(const X: TCplx; out result: TCplx); overload; procedure FlipConj(const X: TSCplx; out result: TSCplx); overload; (*Multiplies complex number with I. original value, multiplied with i: (x+I*y) becomes: -y+I*x*) function MulI(const X: TCplx): TCplx; overload; function MulI(const X: TSCplx): TSCplx; overload; (*Multiplies complex number with I. Defines the input parameter for multiplying with I. Stores the result of multiplying with I.*) procedure MulI(Const X: TCplx; out result: TCplx); overload; procedure MulI(Const X: TSCplx; out result: TSCplx); overload; (*The ||Z||^2. the squared norm of complex number: (x+i*y) becomes:Sqr(x) + Sqr(y). *) function Norm(const X: TCplx): double; overload; function Norm(const X: TSCplx): single; overload; function SqrAbs(const X: TCplx): double; overload; function SqrAbs(const X: TSCplx): single; overload; (*The 1/Z. the 1/X: X becomes 1/X.*) function CInv(const X: TCplx): TCplx; overload; function CInv(const X: TSCplx): TSCplx; overload; (*The 1/Z. Defines the input parameter for inverting. Stores the result of inverting: X becomes: 1/X*) procedure CInv(Const X: TCplx; out result: TCplx); overload; procedure CInv(Const X: TSCplx; out result: TSCplx); overload; (*Exchange two numbers. Exchanges two complex numbers X swaps Y. *) procedure Swap(var X, Y : TCplx); overload; inline; procedure Swap(var X, Y : TSCplx); overload; inline; (*Exchange two numbers. Exchanges two real numbers X swaps Y. *) procedure Swap(var X, Y : double); overload; (*Exchange two numbers. Exchanges two real numbers X swaps Y. *) procedure Swapf(var X, Y : single); overload; (*Exchange two numbers. Exchanges two integer numbers X swaps Y. *) procedure Swap(var X, Y : Integer); overload; procedure Swap(var X, Y: byte); overload; (*Signum. the signum of X. Signum(X) is 1 for X > 0, equal to zero for X = 0 and -1 for X < 0.*) function Sgn(const Z: TCplx): Integer; overload; inline; function Sgn(const Z: TSCplx): Integer; overload; inline; (*Signum. the signum of X. Signum(X) is 1 for X > 0 , equal to zero for X = 0 and -1 for X < 0.*) function Sgn(X: double): Integer; overload; function Sgnf(X: single): Integer; overload; function Sgn(X: integer): Integer; overload; (*e^x function. the value of e raised to the power of X, where e is the base of natural logarithm.*) function Exp(const X: TCplx): TCplx; overload; function Exp(const X: TSCplx): TSCplx; overload; (*2^x function. Returns the value of 2 raised to the power of X. This function is twice as fast as the equivalent call to the function. *) function Exp2(const X: double): double; overload; function Exp2f(const X: single): single; overload; (*2^x function. The value of 2 raised to the power of X. Valid result is returned for X smaller than 32. This function is more than 10x as fast as a call to the function. *) function Exp2Int(const X: Integer): Integer; overload; (*2^x function. Returns the value of 2 raised to the power of X. Valid result is returned for X smaller than 64. This function is more than 10x as fast as a call to the function. *) function Exp2Int64(const X: Integer): Int64; overload; (*2^x function. Returns the value of 2 raised to the power of X. *) function Exp2(const X : TCplx): TCplx; overload; function Exp2(const X : TSCplx): TSCplx; overload; (*10^x function. Returns the value of 10 raised to the power of X. This function is about 30% faster as the equivalent call to the routine. *) function Exp10(const X : double): double; overload; function Exp10f(const X : single): single; overload; (*10^x function. Returns the value of 10 raised to the power of X. This function is about 30% faster as the equivalent call to the routine *) function Exp10(const X : TCplx): TCplx; overload; function Exp10(const X : TSCplx): TSCplx; overload; (*Natural logarithm. Returns the natural logarithm of X. *) function Ln(const X: TCplx): TCplx; overload; function Ln(const X: TSCplx): TSCplx; overload; (*Euler formula for complex number. Returns the e^(i*W), using the Euler formula: e^(i*W) = cos(W) + i*sin(W) *) function Expj(const Omega: double): TCplx; overload; function Expjf(const Omega: single): TSCplx; overload; (*Log base 2. Returns the log base 2 for real argument X. *) function Log2(const X: double): double; overload; function Log2f(const X: single): single; overload; (*Log base 2. Returns the log base 2 for 64bit integer argument X. This function is more than 10x as fast as the Log2 with real argument. *) function Log2Int64(x: Int64): Int64; overload; function Log2Int(x: integer): integer; overload; (*Log base 2. Returns the log base 2 for complex argument X. *) function Log2(const X: TCplx): TCplx; overload; function Log2(const X: TSCplx): TSCplx; overload; (*Log base 10. Returns the log base 10 for real argument X. *) function Log10(const X: double): double; overload; function Log10f(const X: single): single; overload; (*Log base 10. Returns the log base 10 for complex argument X. *) function Log10(const X: TCplx): TCplx; overload; function Log10(const X: TSCplx): TSCplx; overload; (*Log base N. Returns the log base N for real argument X. *) function LogN(const N, X: double): double; overload; function LogNf(const N, X: single): single; overload; (*Log base N. Returns the log base N for complex argument X. *) function LogN(const N: double; const X: TCplx): TCplx; overload; function LogN(const N: single; const X: TSCplx): TSCplx; overload; (*Log base N. Returns the log of complex base N for complex argument X. Note Both base N argument X are complex numbers. *) function LogN(const N, X: TCplx): TCplx; overload; function LogN(const N, X: TSCplx): TSCplx; overload; (*Log base N. Returns the log of complex base N for real argument X. Note: Only base N is complex numbers. *) function LogN(const N: TCplx; const X: double): TCplx; overload; function LogN(const N: TSCplx; const X: single): TSCplx; overload; (*Power function (integer power). Base to an integer power N. Try to avoid calling this function for small powers. N can also be negative. *) function IntPower(const Base: double; const Exponent : Integer): double; overload; function IntPowerf(const Base: single; const Exponent : Integer): single; overload; (*Power function (integer power). Returns complex Base to an integer power N. Try to avoid calling this function for small powers. N can also be negative. *) function IntPower(const Base: TCplx; const N: Integer): TCplx; overload; function IntPower(const Base: TSCplx; const N: Integer): TSCplx; overload; (*Power function. Returns Base to any power. is faster, if Exponent is an integer. Real valued power can handle only positive Exponent and Base. can also handle negative exponent and/or negative base. To compute a power to the non-integer negative exponent and base in general case, use the complex version of the function. *) function Power(const Base, Exponent: double): double; overload; function Powerf(const Base, Exponent: single): single; overload; (*Power function. Returns Base to any power. Here both base and exponent can be complex values. Use this version if you want to compute a power to the negative exponent in general case. *) function Power(const A, X: TCplx): TCplx; overload; function Power(const A, X: TSCplx): TSCplx; overload; (*Power function. Returns Base to any power. Here base is real and exponent is complex. *) function Power(const A: double; const X : TCplx): TCplx; overload; function Power(const A: single; const X : TSCplx): TSCplx; overload; (*Power function. Returns Base to any power. Here base is complex and exponent is real. *) function Power(const A: TCplx; const X: double): TCplx; overload; function Power(const A: TSCplx; const X: single): TSCplx; overload; (*The Pythagora formula. Returns the Sqrt(X*X + Y*Y). *) function Pythag(const X, Y: double): double; overload; function Pythagf(const X, Y: single): single; overload; (*Complex version of Pythagora formula. Returns the Sqrt(X*X + Y*Y).*) function Pythag(const X, Y: TCplx): TCplx; overload; function Pythag(const X, Y: TSCplx): TSCplx; overload; (*Sets angle in [-2Pi,2Pi]. Returns ThetaRad within [-2Pi,2Pi] interval. Calling this function prior to passing the value to trigonometric functions can significantly improve numerical accuracy. *) function FixAngle(const ThetaRad: double): double; overload; function FixAnglef(const ThetaRad: single): single; overload; (*e^x function. Returns the value of e raised to the power of X, where e is the base of natural logarithm.*) function Lnf(const X: single): single; overload; (*e^x function. Returns the value of e raised to the power of X, where e is the base of natural logarithm.*) function Expf(const X: single): single; overload; (*Cosine function. Returns the cosine of argument X, in radians. *) function Cosf(const X :single): single; overload; (*Sine function. Returns the sine of argument X, in radians. *) function Sinf(const X :single): single; overload; (*Inverse tangens. Returns the inverse tangens of a given number X. *) function ArcTanf(const X :single): single; overload; (*Square root. Returns single precision square root of the given number X.*) function Sqrtf(const X: single): single; overload; procedure FreeAndNil(var Obj); (*Sine. the sine of a complex argument X.*) function Sin(const X: TCplx): TCplx; overload; function Sin(const X: TSCplx): TSCplx; overload; (*Sine. Calculates the sine of a complex argument X. Defines complex argument for function. Returns the result of function operation.*) procedure Sin(const X: TCplx; out result: TCplx); overload; procedure Sin(const X: TSCplx; out result: TSCplx); overload; (*Cosine. the cosine of a complex argument X.*) function Cos(const X: TCplx): TCplx; overload; function Cos(const X: TSCplx): TSCplx; overload; (*Cosine. Calculates the cosine of a complex argument X. Defines complex argument for function. Returns the result of function operation.*) procedure Cos(const X: TCplx; out result: TCplx); overload; procedure Cos(const X: TSCplx; out result: TSCplx); overload; (*Tangens. the tangens of real argument X, in radians, where Tan(x) is defined as: Tan(X) = Sin(X)/Cos(X) *) function Tan(const X :double): double; overload; function Tanf(const X :single): single; overload; (*Tangens. Returns the tangens of complex argument X, in radians.*) function Tan(const X: TCplx): TCplx; overload; function Tan(const X: TSCplx): TSCplx; overload; (*Inverse sine. Returns the inverse sine of X. X must be between -1 and 1. The return value will be in the range [-PI/2,PI/2], in radians for a real argument. To obtain an inverse sine for X outside the interval [-1,1] use the complex version of the function. *) function ArcSin(const X :double): double; overload; function ArcSinf(const X :single): single; overload; (*Inverse sine. Returns the inverse sine of X. X must be between -1 and 1. To obtain an inverse sine for X outside the interval [-1,1] use this version of function. *) function ArcSin(const X: TCplx): TCplx; overload; function ArcSin(const X: TSCplx): TSCplx; overload; (*Inverse cosine. Returns the inverse cosine of X. X must be between -1 and 1. The return value will be on closed interval [-PI/2,PI/2], in radians for a real argument. To obtain an inverse cosine for X outside the interval [-1,1] use the complex version of the function. *) function ArcCos(const X :double): double; overload; function ArcCosf(const X :single): single; overload; (*Inverse cosine of X. Returns the inverse cosine of complex argument X. To obtain an inverse cosine for X outside the interval [-1,1] use this version of the function. *) function ArcCos(const X: TCplx): TCplx; overload; function ArcCos(const X: TSCplx): TSCplx; overload; (*Inverse tangens of X. Returns the inverse tangens of complex argument X.*) function ArcTan(const X: TCplx): TCplx; overload; function ArcTan(const X: TSCplx): TSCplx; overload; (*Inverse tangens of Y/X. Returns the inverse tangens of Y/X, and returns an angle in the correct quadrant. The return value will fall in the closed interval [-PI,PI] radians. Note is calculated as ArcTan2(1, X). *) function ArcTan2(const Y, X: double): double; overload; function ArcTan2f(const Y, X:single): single; overload; (*Sine and cosine in single pass. Defines argument for sin and cos functions. Returns the hyperbolic sine. Returns the hyperbolic cosine. Computes sine and cosine in one pass. Call this routine if you require sine and cosine. *) procedure SinCos(const X: double; out SinX, CosX : double); overload; procedure SinCosf(const X: single; out SinX, CosX : single); overload; (*Hyperbolic sine. Returns the hyperbolic sine of real argument X. *) function Sinh(const X: double): double; overload; function Sinhf(const X: single): single; overload; (*Hyperbolic sine. Returns the hyperbolic sine of complex argument X.*) function Sinh(const X: TCplx): TCplx; overload; function Sinh(const X: TSCplx): TSCplx; overload; (*Hyperbolic sine. Defines argument for function. Returns the hyperbolic sine.*) procedure Sinh(const X: TCplx; out result: TCplx); overload; procedure Sinh(const X: TSCplx; out result: TSCplx); overload; (*Hyperbolic cosine. Returns the hyperbolic cosine of real argument X. *) function Cosh(const X: double): double; overload; function Coshf(const X: single): single; overload; (*Hyperbolic cosine. Returns the hyperbolic cosine of complex argument X.*) function Cosh(const X: TCplx): TCplx; overload; function Cosh(const X: TSCplx): TSCplx; overload; (*Hyperbolic cosine. Defines argument for function. Returns the hyperbolic cosine.*) procedure Cosh(const X : TCplx; out result: TCplx); overload; procedure Cosh(const X : TSCplx; out result: TSCplx); overload; (*Hyperbolic cosine. Returns the hyperbolic tangens of real argument X. *) function Tanh(const X: double): double; overload; function Tanhf(const X: single): single; overload; (*Hyperbolic cosine. Returns the hyperbolic tangens of complex argument X. *) function Tanh(const X: TCplx): TCplx; overload; function Tanh(const X: TSCplx): TSCplx; overload; (*Hyperbolic tangens. Returns the hyperbolic tangens od real argument X by using SinCosh method: Sinh(x)/Cosh(x). *) function TanhX(X: double): double; overload; function TanhXf(X: single): single; overload; (*Inverse hyperbolic sine. Returns the inverse hyperbolic sine of real argument X. *) function ArcSinh(const X: double): double; overload; function ArcSinhf(const X: single): single; overload; (*Inverse hyperbolic sine. Returns the inverse hyperbolic sine of complex argument X.*) function ArcSinh(const X: TCplx): TCplx; overload; function ArcSinh(const X: TSCplx): TSCplx; overload; (*Inverse hyperbolic cosine. the inverse hyperbolic cosine of real argument X. *) function ArcCosh(const X: double): double; overload; function ArcCoshf(const X: single): single; overload; (*Inverse hyperbolic cosine. the inverse hyperbolic cosine of complex argument X.*) function ArcCosh(const X: TCplx): TCplx; overload; function ArcCosh(const X: TSCplx): TSCplx; overload; (*Inverse hyperbolic tangens. the inverse hyperbolic tangens of real argument X. *) function ArcTanh(const X: double): double; overload; function ArcTanhf(const X: single): single; overload; (*Inverse hyperbolic tangens. the inverse hyperbolic tangens of complex argument X.*) function ArcTanh(const X: TCplx): TCplx; overload; function ArcTanh(const X: TSCplx): TSCplx; overload; (*The hyperbolic sine and cosine. Defines argument for sinh and cosh functions. Returns the hyperbolic sine. Returns the hyperbolic cosine. Calculates the hyperbolic sine and cosine in one pass. Use this version if you require both Sinh and Cosh. *) procedure SinhCosh(const X: double; out SinhX, CoshX : double); overload; procedure SinhCoshf(const X: single; out SinhX, CoshX : single); overload; (*The norm of z. the norm of a complex number z: |z| = Sqrt[z z*].*) function CAbs(const Z: TCplx): double; overload; function CAbs(const Z: TSCplx): single; overload; (*Returns the approximation of the norm of Z. The following relations are true: (CAbs(Z1) < CAbs(Z2)) < = > (CAbs1(Z1) < CAbs1(Z2)) and (CAbs(Z1) > CAbs(Z2)) < = > (CAbs1(Z1) > CAbs1(Z2)). This function can be used to speed up comparing operations between complex numbers. the approximation of the norm of complex number: |Z| = abs(Z.Re) + abs(Z.Im).*) function CAbs1(const Z: TCplx): double; overload; function CAbs1(const Z: TSCplx): single; overload; (*The argument of Z. the argument of the complex number Z: Arg(Z) = ArcTan(Z.Im/Z.Re).*) function Arg(const Z: TCplx): double; overload; function Arg(const Z: TSCplx): single; overload; (*Fortran sign function. It uses slightly different definition for changing sign of a complex number: * if b>=0, it returns |a|, * otherwise, -|a|. *) function Sign(const a,b: double): double; overload; function Signf(const a,b: single): single; overload; (*Changes the sign of a complex number.*) function Sign(const Z: TCplx): TCplx; overload; function Sign(const Z: TSCplx): TSCplx; overload; (*Limit the range X. Change X to stay within [Low,High] closed interval. Lower bound in [Low,High]. Upper bound in [Low,High]. Modify x to lie within closed interval [Low,High].*) procedure LimitRange(const Low: double; var X: double; const High: double); overload; procedure LimitRangef(const Low: single; var X: single; const High: single); overload; (*Limit the range X. Change X to stay within [Low,High] range. In this case the parameters are integers. *) procedure LimitRange(const Low: integer; var X: integer; const High: integer); overload; (*Changes the sign of Z. the sign of Z: Z becomes -Z*) function Neg(const A: TCplx): TCplx; overload; function Neg(const A: TSCplx): TSCplx; overload; (*Conjugate complex number. conjugated complex number Z becomes Z*.*) function Conj(const A: TCplx): TCplx; overload; function Conj(const A: TSCplx): TSCplx; overload; (*Complex addition. the result of complex addition: Z = A+B.*) function CAdd(const A, B: TCplx): TCplx; overload; function CAdd(const A, B: TSCplx): TSCplx; overload; (*Complex subtraction. the result of complex subtraction: Z = A-B.*) function CSub(const A, B : TCplx): TCplx; overload; function CSub(const A, B : TSCplx): TSCplx; overload; (*Complex division. the result of complex division: Z = A/B. *) function CDiv(const A, B : TCplx): TCplx; overload; function CDiv(const A, B : TSCplx): TSCplx; overload; (*Complex multipliction. the result of complex multiplication: Z = A*B. *) function CMul(const A, B : TCplx): TCplx; overload; function CMul(const A, B : TSCplx): TSCplx; overload; (*Converts two real numbers to complex number. complex number: A+i*b.*) function Cplx(A: double): TCplx; overload; function Cplx(A: double; B: double): TCplx; overload; function CplxDouble(A: double; B: double = 0): TCplx; overload; function CplxSingle(A: single; B: single = 0): TSCplx; overload; (*Square root of a complex number. the square root of a complex number. *) function CSqrt(const A: TCplx): TCplx; overload; function CSqrt(const A: TSCplx): TSCplx; overload; (*The root of complex number. 'N' roots of 'A' by varying 'K' from 0..N-1. This routine uses DeMoivre's theorem to calculate all roots of complex number. *) function Root(const A: TCplx; K, N: Integer): TCplx; overload; function Root(const A: TSCplx; K, N: Integer): TSCplx; overload; (*Modified bessel function of the first kind. *) function BesselI0(const X: TCplx): TCplx; overload; function BesselI0(const X: TSCplx): TSCplx; overload; (*Bessel function of the first kind. *) function BesselJ0(const X: TCplx): TCplx; overload; function BesselJ0(const X: TSCplx): TSCplx; overload; (*Gamma function (real). the gamma function. Gamma function is used for approximating the factorial of a number. *) function Gamma(X: double): double; overload; (*Gamma function (complex). *) function Gamma(const X: TCplx): TCplx; overload; (*Natural logarithm of the gamma function. the natural logarithm of the gamma function Ln(Gamma(X)). *) function LnGamma(const X: Double): Double; overload; (*Natural logarithm of the gamma function. the natural logarithm of the gamma function Ln(Gamma(X)). Complex version. *) function LnGamma(const X: TCplx): TCplx; overload; function SgnGamma(const X: double) : Integer; overload; (*Factorial N!. the factorial (=n!) of n. First 50 numbers are precomputed. Although the argument is integer, the result is real. The result can exceed integer range. If you exceed the TSample range the function returns Inf. *) function Fact(const N: integer): double; overload; (*Secant. the secant of the real argument X. *) function Sec(X: double): double; overload; function Secf(X: single): single; overload; (*Secant. the secant of the complex argument X.*) function Sec(const X: TCplx): TCplx; overload; function Sec(const X: TSCplx): TSCplx; overload; (*Hyperbolic secant. the hyperbolic secant of the real argument X. *) function Sech(X: double): double; overload; function Sechf(X: single): single; overload; (*Hyperbolic secant. the hyperbolic secant of the complex argument X.*) function Sech(const X: TCplx): TCplx; overload; function Sech(const X: TSCplx): TSCplx; overload; (*Inverse secant. the inverse secant of the real argument X. *) function ArcSec(X: double): double; overload; function ArcSecf(X: single): single; overload; (*Inverse secant. the inverse secant of the complex argument X.*) function ArcSec(const X: TCplx): TCplx; overload; function ArcSec(const X: TSCplx): TSCplx; overload; (*Inverse hyperbolic secant. the inverse hyperbolic secant of the real argument X. *) function ArcSech(X: double): double; overload; function ArcSechf(X: single): single; overload; (*Inverse hyperbolic secant. the inverse hyperbolic secant of the real argument X.*) function ArcSech(const X: TCplx): TCplx; overload; function ArcSech(const X: TSCplx): TSCplx; overload; (*Cosecant. the cosecant of the real argument X. *) function Csc(X: double): double; overload; function Cscf(X: single): single; overload; (*Cosecant. the cosecant of the complex argument X.*) function Csc(const X: TCplx): TCplx; overload; function Csc(const X: TSCplx): TSCplx; overload; (*Hyperbolic cosecant. the hyperbolic cosecant of the real argument X. *) function Csch(X: double): double; overload; function Cschf(X: single): single; overload; (*Hyperbolic cosecant. the hyperbolic cosecant of the complex argument X.*) function Csch(const X: TCplx): TCplx; overload; function Csch(const X: TSCplx): TSCplx; overload; (*Inverse cosecant. the inverse cosecant of the real argument X. *) function ArcCsc(X: double): double; overload; function ArcCscf(X: single): single; overload; (*Inverse cosecant. the inverse cosecant of the complex argument X.*) function ArcCsc(const X: TCplx): TCplx; overload; function ArcCsc(const X: TSCplx): TSCplx; overload; (*Inverse hyperbolic cosecant. the inverse hyperbolic cosecant of the real argument X. *) function ArcCsch(X: double): double; overload; function ArcCschf(X: single): single; overload; (*Inverse hyperbolic cosecant. the inverse hyperbolic cosecant of the complex argument X.*) function ArcCsch(const X: TCplx): TCplx; overload; function ArcCsch(const X: TSCplx): TSCplx; overload; (*Cotangent. the cotangent of real argument X. *) function Cot(X: double): double; overload; function Cotf(X: single): single; overload; (*Cotangent. the cotangent of complex argument X.*) function Cot(const X: TCplx): TCplx; overload; function Cot(const X: TSCplx): TSCplx; overload; (*Hyperbolic cotangent. the hyperbolic cotangent of real argument X. *) function Coth(X: double): double; overload; function Cothf(X: single): single; overload; (*Hyperbolic cotangent. the hyperbolic cotangent of complex argument X.*) function Coth(const X: TCplx): TCplx; overload; function Coth(const X: TSCplx): TSCplx; overload; (*Inverse cotangent. the inverse cotangent of real argument X. *) function ArcCot(X: double): double; overload; function ArcCotf(X: single): single; overload; (*Inverse cotangent. the inverse cotangent of complex argument X.*) function ArcCot(const X: TCplx): TCplx; overload; function ArcCot(const X: TSCplx): TSCplx; overload; (*Inverse hyperbolic cotangent. the inverse hyperbolic cotangent of real argument X. *) function ArcCoth(X: double): double; overload; function ArcCothf(X: single): single; overload; (*Inverse hyperbolic cotangent. the inverse hyperbolic cotangent of complex argument X.*) function ArcCoth(const X: TCplx): TCplx; overload; function ArcCoth(const X: TSCplx): TSCplx; overload; (*The reminder after division. the reminder after the division: X/Y.*) function Rem(const X,Y:double): double; overload; function Remf(const X,Y:single): single; overload; (*Reminder after division. the reminder after complex division: X/Y.*) function Rem(const X, Y: TCplx): TCplx; overload; function Rem(const X, Y: TSCplx): TSCplx; overload; (*Complex truncate function. the truncate function to real and imginary part of the X parameter.*) function CTrunc(const X: TCplx): TCplx; overload; function CTrunc(const X: TSCplx): TSCplx; overload; (*Complex round function. Round function to real and imginary part of the X parameter.*) function CRound(const X: TCplx): TCplx; overload; function CRound(const X: TSCplx): TSCplx; overload; (*Complex frac function. the frac function to real and imaginary part of the X parameter.*) function CFrac(const X: TCplx): TCplx; overload; function CFrac(const X: TSCplx): TSCplx; overload; (*The square of complex number. the square of complex number. *) function CSqr(const X: TCplx): TCplx; overload; function CSqr(const X: TSCplx): TSCplx; overload; (*Greatest common divisor. the greatest common divisor of X and Y. X and Y must be positive integers. *) function Gcd(const X,Y: integer): integer; (*Smallest common multiplier. the smallest common multiplier of X and Y. X and Y must be positive integers. *) function Lcm(const X,Y: integer): integer; overload; (*Cartesian to polar coordinate transformation. complex number, transformed from cartesian to polar coordinate system. *) function CartToPolar(const Z: TCplx): TCplx; overload; function CartToPolar(const Z: TSCplx): TSCplx; overload; (*Polar to cartesian coordinate transformation. complex number, transformed from polar to cartesian coordinate system. *) function PolarToCart(const Z: TCplx): TCplx; overload; function PolarToCart(const Z: TSCplx): TSCplx; overload; (*Round towards positive infinity. the smallest integer greater than or equal to X. Ceil(-2.8) = -2 Ceil(2.8) = 3 Ceil(-1.0) = -1 *) function Ceil(const X: double): Int64; overload; function Ceilf(const X: single): Int64; overload; (*Round towards positive infinity. Real and imaginary part are handled independently. *) function Ceil(const X: TCplx): TCplx; overload; function Ceil(const X: TSCplx): TSCplx; overload; (*Round towards negative infinity. the biggest integer less than or equal to X. Floor(-2.8) = -3 Floor(2.8) = 2 Floor(-1.0) = -1 *) function Floor(const X: double): Int64; overload; function Floorf(const X: single): Int64; overload; (*Round towards negative infinity. Real and imaginary part are handled independently. *) function Floor(const X: TCplx): TCplx; overload; function Floor(const X: TSCplx): TSCplx; overload; (*Compares two numbers. true, if complex A and B are binary equal.*) function Equal(const A,B: TCplx): boolean; overload; function Equal(const A,B: TSCplx): boolean; overload; (*Compares two numbers. true, if A and B are equal within a given Tolerance: (abs(A.Re - B.Re) <= Tolerance) and (abs(A.Im - B.Im) <= Tolerance) *) function Equal(const A,B: TCplx; const Tolerance: double): boolean; overload; function Equal(const A,B: TSCplx; const Tolerance: single): boolean; overload; (*Compares two numbers. true, if A and B are equal.*) function Equal(const A: TCplx; const B: double): boolean; overload; function Equal(const A: TSCplx; const B: single): boolean; overload; (*Compares two numbers. true, if A and B are equal.*) function Equal(const A: double; const B: TCplx): boolean; overload; function Equal(const A: single; const B: TSCplx): boolean; overload; (*Compares two numbers. Returns true, if A and B are equal within a given Tolerance. result := (abs(A-B) <= Tol); *) function Equal(const A, B: double; const Tol: double): boolean; overload; function Equalf(const A, B: single; const Tol: single): boolean; overload; (*Compares two numbers. True if both A and B are binary equal.*) function Equal(const A, B: double): boolean; overload; function Equalf(const A, B: single): boolean; overload; function Bigger2(const A, B: TCplx): boolean; overload; function Smaller2(const A, B: TCplx): boolean; overload; function Bigger2(const A, B: TSCplx): boolean; overload; function Smaller2(const A, B: TSCplx): boolean; overload; (*Compares two complex numbers. True if X is bigger then Y. If absolute values are equal it compares the phase*) function Bigger(const X, Y: TCplx): boolean; overload; function Bigger(const X, Y: TSCplx): boolean; overload; (*Compare one real and one complex number.*) function Bigger(const X: TCplx;const Y: double): boolean; overload; function Bigger(const X: TSCplx;const Y: single): boolean; overload; (*Compare one real and one complex number.*) function Bigger(const X: double; const Y: TCplx): boolean; overload; function Bigger(const X: single; const Y: TSCplx): boolean; overload; (*Compare two real numbers. true, if A is bigger than B within defined tolerance: |A-b| > Tol .*) function Bigger(const A, B: double; const Tol: double = 1E-4): boolean; overload; function Biggerf(const A, B: single; const Tol: single = 1E-4): boolean; overload; (*Compares two complex numbers. true if X is smaller than Y. If absolute values are equal it compares the phase.*) function Smaller(const X, Y: TCplx): boolean; overload; function Smaller(const X, Y: TSCplx): boolean; overload; (*Compare one real and one complex number.*) function Smaller(const X: TCplx;const Y: double): boolean; overload; function Smaller(const X: TSCplx;const Y: single): boolean; overload; (*Compare one real and one complex number.*) function Smaller(const X: double;const Y: TCplx): boolean; overload; function Smaller(const X: single;const Y: TSCplx): boolean; overload; (*Compare two real numbers. true, if A is smaller than B within defined tolerance: |A-B| < Tol .*) function Smaller(const A, B: double; const Tol: double = 1E-4): boolean; overload; function Smallerf(const A, B: single; const Tol: single = 1E-4): boolean; overload; (*Compare two complex numbers. True if X is bigger or equal to Y. If absolute values are equal it compares the phase.*) function BiggerOrEqual(const X, Y: TCplx): boolean; overload; function BiggerOrEqual(const X, Y: TSCplx): boolean; overload; (*Compare one real and one complex number.*) function BiggerOrEqual(const X: TCplx; Y: double): boolean; overload; function BiggerOrEqual(const X: TSCplx; Y: single): boolean; overload; (*Compare one real and one complex number.*) function BiggerOrEqual(X: double; const Y: TCplx): boolean; overload; function BiggerOrEqual(X: single; const Y: TSCplx): boolean; overload; (*Compare two complex numbers. True if X is smaller or equal to Y. If absolute values are equal it compares the phase.*) function SmallerOrEqual(const X, Y: TCplx): boolean; overload; function SmallerOrEqual(const X, Y: TSCplx): boolean; overload; (*Compare one real and one complex number.*) function SmallerOrEqual(const X: TCplx; Y: double): boolean; overload; function SmallerOrEqual(const X: TSCplx; Y: single): boolean; overload; (*Compare one real and one complex number.*) function SmallerOrEqual(X: double; const Y: TCplx): boolean; overload; function SmallerOrEqual(X: single; const Y: TSCplx): boolean; overload; (*Closest power of 2 to n. the first smaller or equal power of two, if n is not power of two.*) function SmallestExp2(n: integer): integer; overload; (*Returns first number being power of two that is equal or greater than n. the first number being power of two that is equal or greater than n. It is much faster than the call of: Exp2(Ceil(Log2(n))) *) function LargestExp2(n: integer): integer; overload; (*Power of two which gives the first number that is equal or greater than n. power of two which gives the first number that is equal or greater than n. *) function LargestLog2(n: integer): integer; overload; inline; (*Clears pending FPU exceptions. Clears pending FPU exceptions. Use this function to clear pending FPU exceptions before calling functions that turn FPU exception on, but do not clear them. This includes System.Trunc, System.Frac and System.Integer functions in all Delphi versions before Delphi 6. Math387 has an alternative implementation of the Trunc function that overrides the default System.Trunc function. Exception flags are set by the FPU when the result of a floating point operation is NAN or INF. If the exceptions are not enabled nothing happens, but the exception flags remain set. If you then enable FPU exceptions without first clearing the exception flags, an exception will be raised. Because those exceptions do not come from the current code (where the debugger stops), they make the debugging process much more difficult. A typical error indicating this problem is a Delphi message about a " Invalid floating point operation". With introduction of Delphi 6, this problem has been greatly reduced. When using third party code this problem might resurface, if the code requires floating exceptions to be turned on. In such cases you should call ClearFPU before enabling floating exceptions and disable them again when returning back to MtxVec code. Floating point exceptions must be turned off for MtxVec, or some optimization algorithms will not be able to converge. *) procedure ClearFPU; (*The complex number Z formated as a string. the complex number Z formated as a string. Defines complex number for formatting: Z=Re+I*Im. Defines string format used for formating real part of Z. Defines string format used for formating imaginary part of Z. If ReFormat and ImFormat parameters are empty strings, the function calls . *) function FormatCplx(const Z: TCplx; const ReFormat: string = ' 0.###;-0.###'; const ImFormat: string = '+0.###i;-0.###i'): string; overload; function FormatCplx(const Z: TSCplx; const ReFormat: string = ' 0.###;-0.###'; const ImFormat: string = '+0.###i;-0.###i'): string; overload; (*The double number X formated as string. the double number, formated as string. The Format parameter defines the valid format string. This function is similar to Delphi FormatFloat function, but it also supports single precision type by displaying only 7 valid digits instead of Delphi FormatFloat 15 valid digits. *) function FormatSample(X: double; const Format: string = '0.###'): string; overload; function FormatSamplef(X: single; const Format: string = '0.###'): string; overload; (*The double number X formatted as string. the double number, formatted as string.*) function FormatSample(const Format: string; X: double): string; overload; function FormatSamplef(const Format: string; X: single): string; overload; (*Converts a string to complex number. string, converted to complex number. The complex number must be in the following format: a + bi. Valid examples: +6, 6i, 2.4E-2i, -6E+2+2.4E-2i, 2+3i. *) function StrToCplx(const Source: string): TCplx; overload; function StrToCplxSingle(const Source: string): TSCplx; overload; (*Converts complex number to a string. complex number, converted to string. The Digits parameter controls the minimum number of zeros in the exponent (between 0 and 4). The conversion uses general number format with 15 significant digits for double precision and 7 digits if you are using single precision version of Math387. *) function CplxToStr(const Z: TCplx;const Digits: integer = 0; Precision: integer = 15): string; overload; function CplxToStr(const Z: TSCplx;const Digits: integer = 0; Precision: integer = 7): string; overload; (*Converts string to a value. original string, transformed to double value. This routine is the same as StrToFloat except that it can also handle NAN and INF values. It will work with both ',' and '.' as decimal separator, but the code will run 2x faster for the currently default decimal separator. StrToVal is used also by function. *) function StrToVal(const Source: string): double; (*Converts string to a double value. string, converted to double value. *) function StrToSample(const Source: string): double; overload; (*Converts string to a double value. string, converted to double value. *) function StrToDouble(const Source: string): double; overload; (*Converts string to a single value. string, converted to single value. *) function StrToSingle(const Source: string): single; overload; (*Converts TSample value to a string. TSample value, converted to string. The Digits parameter controls the minimum number of zeros in the exponent (between 0 and 4). The Precision parameter controls the number of significant digints in string representation of TSample value. *) function SampleToStr(const X: double; const Digits: integer; Precision: integer = 15 ): string; overload; function SampleToStrf(const X: single; const Digits: integer; Precision: integer = 7 ): string; overload; function SampleToStr(const X: double): string; overload; function SampleToStrf(const X: single): string; overload; (*Gets double number, extracted from string source. double number that was extracted from string Source looking from Offset and ended with Delimiter. The Offset is modified to point to the first character after first found Delimiter in Source string. You can use ExtractSample to process a string of complex numbers separated by Delimiter. If the Delimiter is not Found, the function returns zero. *) function ExtractSample(const Source: string; var Offset: integer; const Delimiter: string): double; overload; (*Gets integer number, extracted from string source. Integer number that was extracted from string Source looking from Offset and ended with Delimiter. The Offset is modified to point to the first character after first found Delimiter in Source string. You can use ExtractInteger to process a string of integer numbers separated by Delimiter. If the Delimiter is not Found, the function returns zero. *) function ExtractInteger(const Source: string; var Offset: integer;const Delimiter: string): integer; overload; (*Gets a complex number, extracted from string source. a complex number that was extracted from string Source looking from Offset and ended with Delimiter. The Offset is modified to point to the first character after first found Delimiter in Source string. You can use this routine for processing a string of complex numbers separated by Delimiter. If the Delimiter is not Found, the function returns zero. *) function ExtractCplx(const Source: string; var Offset: integer; const Delimiter: string): TCplx; overload; function ExtractCplxSingle(const Source: string; var Offset: integer; const Delimiter: string): TSCplx; overload; (*Add two numbers.*) function CAdd(const A: TCplx; const B: double): TCplx; overload; function CAdd(const A: TSCplx; const B: single): TSCplx; overload; (*Add two numbers.*) function CAdd(const A: double; const B: TCplx): TCplx; overload; function CAdd(const A: single; const B: TSCplx): TSCplx; overload; (*Subtract two numbers.*) function CSub(const A: TCplx; const B: double): TCplx; overload; function CSub(const A: TSCplx; const B: single): TSCplx; overload; (*Subtract two numbers.*) procedure CSub(const A: TCplx; const B: double; out result: TCplx); overload; procedure CSub(const A: TSCplx; const B: single; out result: TSCplx); overload; (*Subtract two numbers.*) function CSub(const A: double; const B: TCplx): TCplx; overload; function CSub(const A: single; const B: TSCplx): TSCplx; overload; (*Subtract two numbers.*) procedure CSub(const A: double; const B: TCplx; out result: TCplx); overload; procedure CSub(const A: single; const B: TSCplx; out result: TSCplx); overload; (*Multiply two numbers.*) function CMul(const A: TCplx; const B: double): TCplx; overload; function CMul(const A: TSCplx; const B: single): TSCplx; overload; (*Multiply two numbers.*) function CMul(const A: double; const B: TCplx): TCplx; overload; function CMul(const A: single; const B: TSCplx): TSCplx; overload; (*Divide two numbers.*) function CDiv(const A: TCplx; const B: double): TCplx; overload; function CDiv(const A: TSCplx; const B: single): TSCplx; overload; (*Divide two numbers.*) function CDiv(const A: double; const B: TCplx): TCplx; overload; function CDiv(const A: single; const B: TSCplx): TSCplx; overload; function CSubMulI(const X: TCplx): TCplx; overload; function CInvMulI(const X: TCplx): TCplx; overload; function CSubMulI(const X: TSCplx): TSCplx; overload; function CInvMulI(const X: TSCplx): TSCplx; overload; (*Add imaginary value BI to complex number A. Add imaginary value BI to complex number A: R = A + b*i; *) function CAddI(const A: TCplx; const BI: double): TCplx; overload; function CAddI(const A: TSCplx; const BI: single): TSCplx; overload; (*Add imaginary value AI to complex number B. Add imaginary value AI to complex number B: R = a*i + B; *) function CAddI(const AI: double; const B: TCplx): TCplx; overload; function CAddI(const AI: single; const B: TSCplx): TSCplx; overload; (*Subtract imaginary value BI from complex number A. Subtract imaginary value BI from complex number A: R = A - b*i; *) function CSubI(const A: TCplx; const BI: double): TCplx; overload; function CSubI(const A: TSCplx; const BI: single): TSCplx; overload; (*Subtract complex number B from imaginary number AI. Subtract complex number B from imaginary number AI: R = a*i - B; *) function CSubI(const AI: double; const B: TCplx): TCplx; overload; function CSubI(const AI: single; const B: TSCplx): TSCplx; overload; (*Multiply two complex numbers. Multiply complex number A with imaginary number Bi: R = A*b*i; *) function CMulI(const A: TCplx; const BI: double): TCplx; overload; function CMulI(const A: TSCplx; const BI: single): TSCplx; overload; (*Multiply complex number B with imaginary number Ai. Multiply complex number B with imaginary number Ai: R = a*i*B; *) function CMulI(const AI: double; const B: TCplx): TCplx; overload; function CMulI(const AI: single; const B: TSCplx): TSCplx; overload; (*Returns the value of a degree measurement expressed in radians. Use DegToRad to convert angles expressed in degrees to the corresponding value in radians, where radians = degrees(pi/180). *) function DegToRad(Deg: double): double; overload; function DegToRadf(Deg: single): single; overload; (*Converts radians to degrees. Use RadToDeg to convert angles measured in radians to degrees, where degrees = radians(180/pi). *) function RadToDeg(Rad: double): double; overload; function RadToDegf(Rad: single): single; overload; (*Raises EMtxVecException exception. Raises exception. *) procedure ERaise (const msg: string); overload; procedure ERaiseFmt(const msg: string; const Args: array of const); overload; (*Raises EMtxVecRangeError exception. Raises exception. *) procedure ERangeErrorRaise (const msg: string); overload; procedure ERangeErrorRaiseFmt(const msg: string; const Args: array of const); overload; (*Raises EMtxVecInvalidArgument exception. Raises exception. *) procedure EInvalidArgumentRaise (const msg: string); overload; procedure EInvalidArgumentRaiseFmt (const msg: string; const Args: array of const); overload; (*Check the value. true if X is bigger or equal then Low and smaller or equal then High.*) function CheckRange(const Low: double;const X: double;const High: double): boolean; overload; inline; function CheckRangef(const Low: single;const X: single;const High: single): boolean; overload; inline; function CheckRange(const Low: char;const X: char;const High: char): boolean; overload; inline; (*Check the value. Parameters can be integers. *) function CheckRange(const Low: integer;const X: integer;const High: integer): boolean; overload; inline; (*Check the value. Parameters can be integers. *) function CheckRange(const Low: Int64; const X: Int64; const High: Int64): boolean; overload; inline; (*Limits the value. Low if X is smaller then Low and High if X is bigger then High.*) function EnsureRange(const Low: double;const X: double;const High: double): double; overload; inline; function EnsureRangef(const Low: single;const X: single;const High: single): single; overload; inline; (*Limits the value. Parameters can be integers. *) function EnsureRange(const Low: integer;const X: integer;const High: integer): integer; overload; inline; function EnsureRange(const Low: Int64 ;const X: Int64; const High: Int64): Int64; overload; inline; function Pos(const substr, str: string; Offset: integer): Integer; overload; function TruncDiv(X: double; Divisor: integer): integer; overload; function TruncDivf(X: single; Divisor: integer): integer; overload; function TruncDiv(X: integer; Divisor: integer): integer; overload; (*Splits the floating point number to integer and fractional parts. Splits the floating point number to integer and fractional parts. Defines real number to be split into integer and fractional part. Returns the fractional part of X. the integer part of X.*) function TruncAndFracf(X: single; out FractionalPart: single): Int64; overload; function TruncAndFrac(X: double; out FractionalPart: double): Int64; overload; function ToSingle(X: double): single; function ToDouble(X: double): double; function PointerToDouble(P: PDouble): double; function PointerToIndexDouble(P: PDouble; Index: integer): double; function PointerToDCplx(P: PDCplx): TDCplx; function PointerToIndexDCplx(P: PDCplx; Index: integer): TDCplx; procedure WriteDouble(P: PDouble; S: double); Procedure WriteDCplx(P: PDCplx; S: TDCplx); function GlobalAllocUnmanaged(dwBytes: PointerInteger): PointerInteger; overload; procedure GlobalFreeUnmanaged(var MemPointer: PointerInteger); overload; procedure GlobalFreeUnmanaged(var MemPointer: PAPointer); overload; function AllignMemp(Address: PAPointer; ElemSize: cardinal): PAPointer; overload; function AllignMem(Address: PointerInteger; ElemSize: cardinal): PointerInteger; overload; function AllignMemOffset(Address: PAPointer; ElemSize: cardinal): integer; overload; function AllignMemOffset(Address: PointerInteger; ElemSize: cardinal): integer; overload; function StreamReadUInt64(const Src: TStream): UInt64; overload; function StreamReadUInt64(const Src: TStream; var BytesRead: integer): UInt64; overload; procedure StreamWriteUInt64(const Dst: TStream; Value: UInt64); overload; function StreamReadInt16(const Src: TStream): SmallInt; overload; function StreamReadUInt16(const Src: TStream): Word; overload; function StreamReadInt8(const Src: TStream): ShortInt; overload; function StreamReadUInt8(const Src: TStream): Byte; overload; procedure StreamWriteInt16(const Dst: TStream; Value: SmallInt); overload; procedure StreamWriteUInt16(const Dst: TStream; Value: Word); overload; procedure StreamWriteInt8(const Dst: TStream; Value: ShortInt); overload; procedure StreamWriteUInt8(const Dst: TStream; Value: Byte); overload; procedure StreamWriteString(const Dst: TStream; const Value: string); overload; function StreamReadString(const Src: TStream): string; overload; procedure StreamWriteInt32(const Dst: TStream; Value: integer); overload; procedure StreamWriteInt64(const Dst: TStream; Value: int64); overload; function StreamReadUInt32(const Src: TStream; var BytesRead: integer): cardinal; overload; function StreamReadUInt32(const Src: TStream): Cardinal; overload; function StreamReadInt32(const Src: TStream; var BytesRead: integer): integer; overload; function StreamReadInt32(const Src: TStream): integer; overload; function StreamReadInt64(const Src: TStream; var BytesRead: integer): int64; overload; function StreamReadInt64(const Src: TStream): int64; overload; function StreamReadDouble(const Src: TStream): double; overload; function StreamReadSingle(const Src: TStream): single; overload; procedure StreamWriteSingle(const Dst: TStream; Value: single); overload; procedure StreamWriteDouble(const Dst: TStream; Value: double); overload; (*Starts the microsecond timer. Call this procedure to begin measuring time. To stop call *) procedure StartTimer;overload; (*Stops the timer with microsecond resolution. Call this procedure to stop measuring time. To begin call . The result returned is time in seconds since the StartTimer routine was called. *) function StopTimer:double;overload; (*Starts the timer with microsecond resolution. Call this procedure to begin measuring time. To stop call . The timervar must be passed to the routine. *) procedure StartTimer(var timervar:int64);overload; (*Stops the microsecond timer. Call this procedure to stop measuring time. To begin call . The timervar must be the same as passed to the routine. The result returned is time in seconds since the StartTimer routine was called. *) function StopTimer(timervar:int64):double;overload; (*Returns the description of the Src.*) function IntPrecisionToStr(Src: TIntPrecision): string;overload; (*FPU control word turning off all exceptions. *) const MtxVec8087CW: Integer = $133f; (*FPU control word used by Fortran. *) const Fortran8087CW: Integer = $123f; (*Storage default endianness.*) const MtxSystemEndianness = boLittleEndian; var MtxSaved8087CW: Word; (*Not a number. Not a number. Do not use this value in comparisons. To check whether a variable or expression evaluates to NaN, use the function instead. *) NAN: double = 0/0; NAN_SINGLE: single = 0/0; (*Positive Infinity. Positive Infinity. Do not use this value in comparisons. To check whether a variable or expression represents infinity, use the routine instead. *) INF: double = 1/0; INF_SINGLE: single = 1/0; (*Complex version of NAN. Complex version of NAN. *) CNAN: TCplx = (Re: 0/0; Im: 0/0); CNAN_SINGLE: TSCplx = (Re: 0/0; Im: 0/0); (*Complex version of INF. Complex version of INF. *) CINF: TCplx = (Re: 1/0; Im: 1/0); CINF_SINGLE: TSCplx = (Re: 1/0; Im: 1/0); MtxRegistryKey: string = '\Software\Dew Research\MtxVec'; MtxVecWorkingDir: string = 'C:\'; MtxVecCopyright: string = '© 1999-2025 Dew Research'; NilPtr: PAPointer = nil ; (*Defines the block size. When MtxVec makes use of block processing, these variable defines the number of elements in each block. The size of all blocks in bytes should approximatelly match the CPU cache size. The block should not be too small to avoid overhead when handling objects to become noticeable. *) var MtxVecBlockSize: integer = 1024; var MtxVecMemoryAlignment: Int64 = 128; var DebugValueCount: integer = 200; (*Holds an array of 1000 prime numbers. *) var MtxVecPrimeArray: TIntegerArray; (*Gradient step size used by Richarson numeric gradient algorithm. *) var GradStepSize: double; var GradStepSizeSingle: single; var GradStepSizeDefault: double; var GradStepSizeSingleDefault: single; function GetDecimalSeparator: char; function GetThousandSeparator: char; function IntInterlockedIncrement(var Param: integer): integer; function IntInterlockedDecrement(var Param: integer): integer; function IntInterlockedExchange(var Target: Integer; Value: Integer): Integer; function IntGetCurrentThreadID: TThreadID; {$HPPEMIT END '#include "Math387.h"'} procedure aSetLength(var a: TUInt64Array; const Len: NativeInt); overload; procedure aSetLength(var a: TInt64Array; const Len: NativeInt); overload; procedure aSetLength(var a: Math387.TShortIntArray;const Len: NativeInt); overload; procedure aSetLength(var a: Math387.TSmallIntArray;const Len: NativeInt); overload; procedure aSetLength(var a: T2DSmallIntArray;const Len: NativeInt); overload; procedure aSetLength(var a: Math387.TWordArray;const Len: NativeInt); overload; procedure aSetLength(var a: Math387.TByteArray;const Len: NativeInt); overload; procedure aSetLength(var a: TBytes; const Len: NativeInt); overload; procedure aSetLength(var a: Math387.T2DByteArray;const Len: NativeInt); overload; procedure aSetLength(var a: TIntegerArray;const Len: NativeInt); overload; procedure aSetLength(var a: T2DIntegerArray;const Len: NativeInt); overload; procedure aSetLength(var a: TCplxArray;const Len: NativeInt); overload; procedure aSetLength(var a: T2DCplxArray;const Len: NativeInt); overload; procedure aSetLength(var a: TObjectArray;const Len: NativeInt); overload; procedure aSetLength(var a: TSCplxArray;const Len: NativeInt); overload; procedure aSetLength(var a: T2DSCplxArray;const Len: NativeInt); overload; procedure aSetLength(var a: TSingleArray;const Len: NativeInt); overload; procedure aSetLength(var a: T2DSingleArray;const Len: NativeInt); overload; procedure aSetLength(var a: TDoubleArray;const Len: NativeInt); overload; procedure aSetLength(var a: T2DDoubleArray;const Len: NativeInt); overload; procedure aSetLength(var a: T2DCplxDoubleArray;const Len: NativeInt); overload; procedure aSetLength(var a: T2DCplxSingleArray;const Len: NativeInt); overload; procedure aSetLength(var a: TCardinalArray;const Len: NativeInt); overload; procedure aSetLength(var a: string; const Len: integer); overload; procedure aSetLength(var a: TThreadIDArray; const Len: NativeInt); overload; procedure aSetLength(var a: WideString;const Len: integer); overload; procedure aSetLength(var a: AnsiString; const Len: integer); overload; procedure aSetLength(var a: TBooleanArray; const Len: NativeInt); overload; procedure aSetLength(var a: StringArray; const Len: integer); overload; procedure aSetLength(var a: T2DStringArray; const Len: integer); overload; function aGetLength(const x: TObjectArray): integer; overload; function aGetLength(const x: Math387.TByteArray): integer; overload; function aGetLength(const x: TBytes): integer; overload; function aGetLength(const x: T2DDoubleArray): integer; overload; function aGetLength(const x: T2DSingleArray): integer; overload; function aGetLength(const x: T2DCplxArray): integer; overload; function aGetLength(const x: T2DSCplxArray): integer; overload; function aGetLength(const Str: string): integer; overload; function aGetLength(const Str: AnsiString): integer; overload; function aGetLength(const x: T2DStringArray): integer; overload; function aGetLength(const x: T2DIntegerArray): integer; overload; function aGetLength(const x: T2DSmallIntArray): integer; overload; function aGetLength(const x: T2DByteArray): integer; overload; function aGetLength(const x: array of cardinal): integer; overload; function aGetLength(const x: array of integer): integer; overload; function aGetLength(const x: array of double): integer; overload; function aGetLength(const x: array of single): integer; overload; function aGetLength(const x: array of SmallInt): integer; overload; function aGetLength(const x: array of word): integer; overload; function aGetLength(const x: array of string): integer; overload; function aGetLength(const x: array of UInt64): integer; overload; function aGetLength(const x: array of Int64): integer; overload; function aGetLength(const x: array of TCplx): integer; overload; function aGetLength(const x: array of TSCplx): integer; overload; procedure SetInclude(var dstSet: UInt64; const Item: UInt64); overload; procedure SetExclude(var dstSet: UInt64; const Item: UInt64); overload; function SetContains(const Item: UInt64; const aSet: UInt64): boolean; overload; procedure SetInclude(var dstSet: Cardinal; const Item: Cardinal); overload; procedure SetExclude(var dstSet: Cardinal; const Item: Cardinal); overload; function SetContains(const Item: Cardinal; const aSet: Cardinal): boolean; overload; type (* Mapped from Delphi System Unit *) TLocalCPUID = record EAX, EBX, ECX, EDX: UInt32; end; (* Mapped from Delphi System Unit *) function GetLocalCPUID(FunctionID: UInt32; SubFunctionID: UInt32 = 0): TLocalCPUID; overload; (* Sets DAZ and FTZ bits to zero. DAZ bit is for "Denormals are zero" FTZ bit is for "Flush denormals to zero" *) (*Defines the common ancestor of all components using MtxVec.*) unit MtxBaseComp; interface {$I BdsppDefs.inc} {$WARN SYMBOL_DEPRECATED OFF} Uses Math387, MtxVecBase, MtxVecUtils ,Classes ,SysUtils ,Contnrs ; Type (*Exception type raised when operation is not supported. Exception meant to be be raised, when an operation is not supported by the component. *) ENoOperation = class(Exception) constructor Create; end; TMtxComponent = class; TReferenceList = class; TReferenceListItem = class strict private Owner: TObject; public Item: TReferenceList; Event: TNotifyEvent; Component: TObject; destructor Destroy; override; constructor Create(aOwner: TObject); end; TReferenceList = class strict private List: TObjectsList; function GetReferenceListItem(aIndex: integer): TReferenceListItem; procedure SetReferenceListItem(aIndex: integer; Item: TReferenceListItem); strict protected Owner: TObject; FNilEvent: TNotifyEvent; procedure Delete(i: integer); function IndexOf(Src: TReferenceList): integer; public procedure NotifyAll; procedure RemoveWithoutNotify(Src: TReferenceList); overload; procedure RemoveWithoutNotify(Src: TMtxComponent); overload; procedure Remove(Src: TReferenceList); overload; procedure Remove(Src: TMtxComponent); overload; procedure UpdateListReferences; function get_Count: integer; (*Add a reference of Src to Self and also a reference of Self to Src. Event that will be called, when the connected component is destroyed is the method TMtxComponent.RemoveReference. The parameter passed to the method will be the pointer of the component (and not of its TReferenceList) that is being destroyed. *) procedure Add(Src: TMtxComponent); overload; (*Add a reference to Src to Self and also a reference of Self to Src. Event is the procedure to be called, when the connected component is destroyed. *) procedure Add(Src: TReferenceList; Event: TNotifyEvent; CompSrc: TObject = nil); overload; destructor Destroy; override; constructor Create(aOwner: TObject); virtual; property Items[aIndex: integer]: TReferenceListItem read GetReferenceListItem write SetReferenceListItem; default; property Count: integer read get_Count; end; (*Common ancestor of all components using MtxVec. Most Delphi/C++Builder developers are familiar with the following methods: * SaveToStream * LoadFromStream * LoadFromFile * SaveToFile * Assign TMtxComponent declares generic versions of these routines so that all components derived from it have all their published properties streamed, without the need to make any changes to the streaming routines. Therefore, all components derived form TMtxComponent have the capability to store their states (properties) to the stream, file or to assign from another object of the same type. The default component streaming mechanism has a bug when it comes to streaming properties with a declared default value. This has been fixed for TMtxComponent. The component also declares a more advanced set of streaming methods: * LoadTemplateFromStream * SaveTemplateToStream * LoadTemplateFromFile * SaveTemplateToFile * AssignTemplate These methods set a special protected property named BlockAssign to True. This is very useful when there is a need to save only "parameters" and not the "data" of the component. The parameters will remain the same, while the "data" will be different next time and there is no point in wasting disk space by saving it. The BlockAssign property can be used in two ways. It can be used as a storage specifier for a published property: property Data: TVec read fData write SetData stored AllowStreaming; In this case when the BlockAssign property is True the AllowStreaming protected function will return false. The property will not be saved and consequently when the stream is loaded this property will not be set. This will affect only the SaveTemplateToStream/SaveTemplateToFile/Assign methods. Another approach is to allow storing the property to the stream and then explicitely check the value BlockAssign property to prevent assignment of the value. The first approach is much more elegant because it reduces the size of the "template" file. The value of the protected BlockAssign property is set automatically by the component. All the user is required to do is use the storage specifiers (the "stored" keyword with AllowStreaming function) for "template like" properties. *) TMtxComponent = class(TComponent) strict private FReference: TReferenceList; FEditorActive: boolean; FBlockAssign: boolean; procedure SetEditorActive(const Value: boolean); strict protected (*Returns True, if the component is used at design time within IDE.*) function IsDesignTime: boolean; function IsLoading: boolean; (*Setter for the BlockAssign property.*) procedure SetBlockAssign(const Value: boolean); virtual; (*Getter for the BlockAssign property.*) function GetBlockAssign: boolean; virtual; protected procedure DefineProperties(Filer: TFiler); override; strict protected (*Generic method to be overriden in descendants to request recalculation of the data.*) function Update: boolean; virtual; (*Generic method to be overriden for streaming custom data with the component.*) procedure LoadBinaryStreams(Src: TStream); overload; virtual; (*Generic method to be overriden for streaming custom data with the component.*) procedure SaveBinaryStreams(Dst: TStream); overload; virtual; protected (*Block streaming of specific properties when storing only a "template". If true, AllowStreaming will be returning false. See the description of this component for more info. *) property BlockAssign: boolean read GetBlockAssign write SetBlockAssign; (*To be overriden in descendanr classses. Should be overriden in descendant classes to return the name of the TForm descendant, dialog used to edit the properties of the component. This property has meaning only if used in conjunction with TMtxDialog. *) classfunction EditorClass: string; virtual; procedure ReferenceRemoved(Sender: TObject); virtual; (*Save the component to Dst stream.*) procedure SaveToStream(Dst: TStream); overload; virtual; (*Load the component from Src stream.*) procedure LoadFromStream(Src: TStream); overload; virtual; strict protected (*Save the component to file.*) procedure SaveToFile(FileName: string); virtual; (*Load the component from file.*) procedure LoadFromFile(FileName: string); virtual; public constructor Create(aOwner: TComponent); overload; override; destructor Destroy; override; (*Reset is called after loading the data from stream or file. Override this procedure to implement component specific processing. *) procedure Reset; virtual; (*Returns the negatated value of BlockAssign. Should be used as a storage specifier. See the description of this component for more info. *) function AllowStreaming: boolean; virtual; (*Assign values of all published properties from Source. Assign will raise an exception, if the types of the source and destination will not be an exact match. *) procedure Assign(Source: TPersistent); override; (*Assign values of "template-like" published properties from Source. Assign will raise an exception, if the types of the source and destination will not be an exact match. See the description of this component for more info. *) procedure AssignTemplate(Source: TPersistent); virtual; (*Load a template from stream. See the description of this component for more info. *) procedure LoadTemplateFromStream(Stream: TStream); overload; virtual; (*Save template to stream. See the description of this component for more info. *) procedure SaveTemplateToStream(Stream: TStream); overload; virtual; (*Copies object to an array of bytes.*) (*Load a template from file. See the description of this component for more info. *) procedure LoadTemplateFromFile(FileName: string); virtual; (*Save template to file. See the description of this component for more info. *) procedure SaveTemplateToFile(FileName: string); virtual; (*Returns True, if the component editor is displayed.*) property EditorActive: boolean read FEditorActive write SetEditorActive; (*Stores a list of components that have to be notified, when this component is destroyed.*) property Reference: TReferenceList read FReference; end; TMtxComponentList = class; (*Event for TMtxComponentList. Event triggered after a new item has been added to the component list. *) TMtxComponentAddEvent = procedure (Sender: TMtxComponentList; Item: TMtxComponent) of object; (*Event for TMtxComponentList. Event triggered before the Item has been deleted from the component list. *) TMtxComponentDeleteEvent = procedure (Sender: TMtxComponentList; Item: TMtxComponent) of object; (*Manages a list of TMtxComponents. Manages a list of TMtxComponent. The class can be quickly customized to manage a list of components derived from TMtxComponent. The components in the list are owned by the object and are created and destroyed automatically when setting the Count property. *) TMtxComponentList = class(TMtxComponent) strict private FOnItemAdd: TMtxComponentAddEvent; FOnItemDelete: TMtxComponentDeleteEvent; FPropagateTemplate: boolean; FManaged: boolean; function GetCount: integer; procedure SetOnItemAdd(const Value: TMtxComponentAddEvent); procedure SetOnItemDelete(const Value: TMtxComponentDeleteEvent); procedure SetPropagateTemplate(const Value: boolean); procedure SetManaged(const Value: boolean); strict protected aList: TObjectsList; procedure SetCount(const Value: integer); virtual; procedure SetBlockAssign(const Value: boolean); override; procedure Add(MtxComponent: TMtxComponent); virtual; (*Called every time the Count property has changed or an item has been added or removed.*) function AddItem: TMtxComponent; virtual; function getFirst: TMtxComponent; function getLast: TMtxComponent; (* Generic method to be overriden for streaming custom data with the component. Read data from the Stream that has been previously written with (overriden) . *) procedure LoadBinaryStreams(Src: TStream); override; (* Generic method to be overriden for streaming custom data with the component. Write data to be stored with the component to the Stream. Read the data by overriding . *) procedure SaveBinaryStreams(Dst: TStream); override; function GetItems(Index: integer): TMtxComponent; procedure SetItems(Index: integer; const Value: TMtxComponent); public property Managed: boolean read FManaged write SetManaged; (*Returns the pointer to Items[0].*) property First: TMtxComponent read getFirst; (*Returns Items[Count - 1]. Call Last to retrieve the last pointer in the Items array. *) property Last: TMtxComponent read getLast; (*Swaps the position of two items in the Items array. Call Exchange to swap the positions of the items at positions Index1 and Index2 of the Items array. The indexes are zero-based. *) procedure Exchange(Index1, Index2: Integer); (*Deletes the first reference to the Item parameter from the Items array. Call Remove to remove a specific item from the Items array when its index is unknown. *) function Remove(Item: TMtxComponent): Integer; (*Changes the position of an item in the Items array. Call Move to move the item at the position CurIndex so that it occupies the position NewIndex. Indexes are zero based. *) procedure Move(CurIndex, NewIndex: Integer); (*Deletes all items from the list. Clear also frees the memory used to store the Items array. All list items are destroyed. *) procedure Clear; (*Deletes the item from the list. Deletes the item at position Index from the List and frees the object. *) procedure Delete(Index: integer); (*Extracts the item from the list. Deletes the item at position Index from the List, but does not free the object. *) function Extract(Index: integer): TMtxComponent; (*Inserts an item at position Index*) procedure Insert(Index: integer); (*Rotate the list up or down. Very fast way to rotate the items in the list. If the Step is positive the items are shifted up and those that exit at the top are inserted at the begining of the List. If the Step is negative the items are shifted down and inserted at the end. *) procedure Rotate(Offset: integer); (* Default property to access elements from the stored list. *) property Items[Index: integer]: TMtxComponent read GetItems write SetItems; default; constructor Create(aOwner: TComponent); override; destructor Destroy; override; (* Assign all property values of the defined item to the items specified with their indexes in the DstIndex array. *) procedure Propagate(SrcIndex: integer; const DstIndex: array of integer); overload; published (*Defines how will proparage properties. If true, the Propagate routine, will propagate only the "template" of the selected source and not all the published properties of the source. *) property PropagateTemplate: boolean read FPropagateTemplate write SetPropagateTemplate; (*Defines the size of the list. Setting the property creates or destroys appropriate number of list items. In derived components the AddItem function should be overriden to return the custom type object. *) property Count: integer read GetCount write SetCount; (*Event triggered after a new item has been added.*) property OnItemAdd: TMtxComponentAddEvent read FOnItemAdd write SetOnItemAdd; (*Event triggered before the Item will be deleted.*) property OnItemDelete: TMtxComponentDeleteEvent read FOnItemDelete write SetOnItemDelete; end; (*Defines a collectionItem, which allows customevent defintion.*) TMtxCollectionItem = class(TCollectionItem) public procedure CustomEvent(Sender: TObject); virtual; procedure UpdateReference; virtual; end; TMtxCollection = class(TCollection) strict private FBlockAssign: boolean; function GetCount: integer; procedure SetCount(const Value: integer); procedure SetBlockAssign(const Value: boolean); virtual; protected property BlockAssign: boolean read FBlockAssign write SetBlockAssign; public property Count: integer read GetCount write SetCount; end; (*Assign a component to a component. Generic component assign. The source and destination must be of the same type. The routine will copy values of all published properties from source to destination component. *) procedure AssignComponent(Source, Destination: TMtxComponent); (*Reset the values of published properties. Resets the values of all published properties to their default values. (if defined). *) procedure ResetProperties(Instance: TPersistent); (*Adds operator overloading support. The unit declares Vector and Matrix types for +, -, *, / operator support. *) unit MtxExpr; interface {$I bdsppdefs.inc} uses MtxVec, Math387, AbstractMtxVec, AbstractMtxVecInt, MtxVecBase, MtxVecInt, MtxExprInt ,Classes ,Types ,Nmkl ,NmklSingle ; {$HPPEMIT END '#include "MtxExpr.h"'} {$HPPEMIT '#include '} {$HPPEMIT '#include '} type {$RTTI EXPLICIT METHODS([])} (*Vector class for operator overloading (Delphi 2006 and later). Declare Vector instead of TVec to take advantage of operator overloading in D2006 and later. Be carefull to declare Vector only for local variables with short lifetime. Call the Create method for Vector, if the variable is a global variable or a variable with a longer life. It also makes sense to continue to use TVec for global vars. If the Create method (constuctor) is not called, the Vector record obtains TVec object from object cache (fastest create). If the Create mehod is called, the TVec object is created in the usual way (slower). Object cache has limited size. var b, c: Vector; bv: TVec; begin b := Vector(TDoubleArray.Create(1,1,1,1)); b := [1,1,1,1]; //or like this bv := b; // b and bv point to same data object bv.Scale(2); TVec(b).Scale(2); //an alternative way to scale c := b*2 + Cplx(2,3); c := b*2 + 2 + 3i c := b*bv; // mix Vector and TVec per element multiply bv.Add(c); //pass Vector type and implicitely convert to TVec end; *) Vector = record strict private FData: TVec; private function get_Data: TVec ; property Data: TVec read get_Data; private function get_Precision: TPrecision; function get_Rounding: TRounding; function get_BlockEnd: boolean; function get_ComplexValues: string; function get_RealValues: string; procedure set_Precision(const value: TPrecision); procedure set_Rounding(const value: TRounding); procedure set_Alfa(const value: TCplx); procedure set_Beta(const value: TCplx); function get_Alfa: TCplx; function get_Beta: TCplx; procedure set_ZeroTolerance(const value: double); function get_IsSubRange: boolean; function get_SubRangeLevel: integer; function get_ZeroTolerance: double; function get_Caption: string; function get_Complex: boolean; function get_ConditionCheck: boolean; function get_Length: integer; function get_Tag: integer; procedure set_Caption(const value: string); procedure set_Complex(const value: boolean); procedure set_ConditionCheck(const value: boolean); procedure set_Length(const value: integer); procedure set_Tag(const value: integer); function get_FFTOddLength: boolean; function get_FFTScrambled: boolean; function get_FFTStorageFormat: TFFTStorageFormat; procedure set_FFTOddLength(const value: boolean); procedure set_FFTScrambled(const value: boolean); procedure set_FFTStorageFormat(const value: TFFTStorageFormat); function get_CValues(const Indx: integer): TCplx; function get_Values(const Indx: integer): double; procedure set_CValues(const Indx: integer; const value: TCplx); procedure set_Values(const Indx: integer; const value: double); function get_SCValues(const Indx: integer): TSCplx; function get_SValues(const Indx: integer): single; procedure set_SCValues(const Indx: integer; const value: TSCplx); procedure set_SValues(const Indx: integer; const value: single); function GetSelect(const Indx, Len: integer): Vector; procedure SetSelect(const Indx, Len: integer; const Value: Vector); function GetSelectIndex(const startIndex, Step, stopIndex: integer): Vector; procedure SetSelectIndex(const startIndex, Step, stopIndex: integer; const Value: Vector); function get_Capacity: Int64; procedure set_Capacity(const value: Int64); function get_CapacityStep: double; procedure set_CapacityStep(const value: double); function get_FloatPrecision: TMtxFloatPrecision; procedure set_FloatPrecision(const value: TMtxFloatPrecision); function get_IsDouble: boolean; procedure set_IsDouble(const value: boolean); function get_First: double; function get_Firstc: TCplx; function get_Last: double; function get_Lastc: TCplx; public procedure CreateFromCache(Value: boolean); (*Adopts TVec object. Src object will be adopted by Vector. When the Vector gets out of scope, the Src object will be freed. *) procedure Adopt(const Src: TVec); overload; (*Adopts aArray memory. Addopts a pointer to AArray array. The method sets the calling vector property to aFloatPrecision, to ARows, to ACols and Values1D and CValues1D to Pointer(AArray). Notes: * Required to call the method, before freeing the object * Do not resize the vector * Do not call routines relying on Lapack when cross-platform "Core edition" is used (not linking dlls), because Lapack will assume that adopted memory is a dynamic array and will modify array Index -2. * TVec.Values array assignment or passing array by var (internal to library) will cause memory corruption in this case. * To be used with great care only. *) procedure Adopt(AArray: PAPointer; ALength: integer; aFloatPrecision: TMtxFloatPrecision); overload; procedure Adopt(AArray: PAPointer; ALength: integer; aIsComplex, aIsDouble: boolean); overload; (*Disowns a values pointer. Disowns a values pointer. The Disown method is the opposite of the method. It will set the AArrays to Pointer(Values), ALength to vector's and IsComplex to Complex property. Use the Disown method to "disconnect" AArray from the TVec.Values. Disown sets Values and CValues array pointers to nil and Length property to zero, but without freeing the allocated memory. The allocated memory can be disowned only, if it was adopted with a call to the method. *) procedure Disown(out AArray: PAPointer; out ALength: integer; out aFloatPrecision: TMtxFloatPrecision); overload; procedure Disown(out AArray: PAPointer; out ALength: integer; out aIsComplex, aIsDouble: boolean); overload; (*Disowns a calling vector values pointer by setting Values, CValues to nil and to 0.*) procedure Disown; overload; (*Internally creates TVec object without using object cache. Creates TVec object without using object cache. Suitable for declaring global variables. *) constructor Create(const aLength: integer; const aFloatPrecision: TMtxFloatPrecision); overload; constructor Create(const aLength: integer); overload; (*Uses TVec object as internal storage. The resulting Vector will own Src object of TVec type and will release it once Vector gets out of scope. *) constructor Create(const Src: TVec); overload; (*Sets the following properties Vec.Length := ALength; Vec.Complex := AComplex; *) procedure Size(const aLength: integer; const aIsComplex: boolean; const aIsDouble: boolean); overload; function Size(const Src: TMtxVecBase; const aFloatPrecision: TMtxFloatPrecision): TMtxVec; overload; procedure Size(const aLength: integer; const aIsComplex: boolean); overload; (*Returns true, if Left and Right are of equal Length and Values. var a,b: Vector; c: TDoubleArray; begin c := TDoubleArray.Create(1,1,1,1,1); TVec(a).CopyFromArray(c); TVec(a).Copy(b); if a = b then ERaise('a and b are equal!'); if a = 1 then ERaise('a equals 1!'); //compare to real value if a = Cplx(1,0) then ERaise('a equals 1!'); //compare to complex value end; *) class operator Equal(const Left, Right: Vector): Boolean; (*Returns true, if all elements of Left are equal to Right.*) class operator Equal(const Left: Vector; Right: double): Boolean; (*Returns true, if all elements of Right are equal to Left.*) class operator Equal(Left: double;const Right: Vector): Boolean; (*Returns true, if all elements of Left are equal to Right.*) class operator Equal(const Left: Vector;const Right: TCplx): Boolean; (*Returns true, if all elements of Right are equal to Left.*) class operator Equal(const Left: TCplx; const Right: Vector): Boolean; (*Returns true, if Left and Right are of equal Length and Values.*) class operator Equal(const Left: TMtxVec; const Right: Vector): Boolean; (*Returns true, if Left and Right are of equal Length and Values.*) class operator Equal(const Left: Vector; const Right: TMtxVec): Boolean; (*Returns true, if Left and Right are not equal. Returns true, if Left and Right do not have equal Length and Values. TMtxVec.IsEqual is called with tolerance 0. var a,b: Vector; begin a := Vector(TDoubleArray.Create(1,1,1,1,1)); if a <> b then ERaise('a and b are not equal!'); if a <> 1 then ERaise('a does not equals 1!'); //compare to real value if a <> Cplx(1,0) then ERaise('a does not equals 1!'); //compare to complex value end; *) class operator NotEqual(const Left, Right: Vector): Boolean; (*Returns true, if any elements of Left are not equal to Right.*) class operator NotEqual(const Left: Vector; const Right: double): Boolean; (*Returns true, if any elements of Right are not equal to Left.*) class operator NotEqual(const Left: double;const Right: Vector): Boolean; (*Returns true, if any elements of Left are not equal to Right.*) class operator NotEqual(const Left: Vector;const Right: TCplx): Boolean; (*Returns true, if any elements of Right are not equal to Left.*) class operator NotEqual(const Left: TCplx;const Right: Vector): Boolean; (*Returns true, if Left and Right do not have equal Length and Values.*) class operator NotEqual(const Left: TMtxVec; const Right: Vector): Boolean; (*Returns true, if Left and Right do not have equal Length and Values.*) class operator NotEqual(const Left: Vector; const Right: TMtxVec): Boolean; (*Returns true, if Left is less than Right. Returns true, if all elements in ALeft are less than ARight.*) class operator LessThan(const ALeft: Vector; const ARight: TCplx): Boolean; (*Returns true, if ALeft is smaller from all elements in ARight.*) class operator LessThan(const ALeft: TCplx; const ARight: Vector): Boolean; (*Returns true, if all elements of ALeft are smaller from ARight.*) class operator LessThan(const ALeft: Vector; const ARight: double): Boolean; (*Returns true, if ALeft is smaller from all elements in ARight.*) class operator LessThan(const ALeft: double; const ARight: Vector): Boolean; (*Returns true, if coresponding elements in ALeft are greater than coresponding elements in ARight.*) class operator LessThan(const ALeft: Vector; const ARight: Vector): Boolean; (*Returns true, if Left is less than or equal to Right.*) class operator LessThanOrEqual(const ALeft: Vector; const ARight: TCplx): Boolean; (*Returns true, if ALeft is smaller or equal from all elements in ARight.*) class operator LessThanOrEqual(const ALeft: TCplx; const ARight: Vector): Boolean; (*Returns true, if all elements of ALeft are smaller or equal from ARight.*) class operator LessThanOrEqual(const ALeft: Vector; const ARight: double): Boolean; (*Returns true, if ALeft is smaller or equal from all elements in ARight.*) class operator LessThanOrEqual(const ALeft: double; const ARight: Vector): Boolean; (*Returns true, if coresponding elements in ALeft are smaller than or equal from coresponding elements in ARight.*) class operator LessThanOrEqual(const ALeft: Vector; const ARight: Vector): Boolean; (*Returns true, if Left is greater than or equal to Right.*) class operator GreaterThanOrEqual(const ALeft: Vector; const ARight: TCplx): Boolean; (*Returns true, if ALeft is greater or equal from all elements in ARight.*) class operator GreaterThanOrEqual(const ALeft: TCplx; const ARight: Vector): Boolean; (*Returns true, if all elements of ALeft are greater or equal from ARight.*) class operator GreaterThanOrEqual(const ALeft: Vector; const ARight: double): Boolean; (*Returns true, if ALeft is greater or equal from all elements in ARight.*) class operator GreaterThanOrEqual(const ALeft: double; const ARight: Vector): Boolean; (*Returns true, if coresponding elements in ALeft are greater or equal from coresponding elements in ARight.*) class operator GreaterThanOrEqual(const ALeft: Vector; const ARight: Vector): Boolean; (*Returns true, if Left is greater than Right.*) class operator GreaterThan(const ALeft: Vector; const ARight: TCplx): Boolean; (*Returns true, if ALeft is greater from all elements in ARight.*) class operator GreaterThan(const ALeft: TCplx; const ARight: Vector): Boolean; (*Returns true, if all elements of ALeft are greater from ARight.*) class operator GreaterThan(const ALeft: Vector; const ARight: double): Boolean; (*Returns true, if ALeft is greater from all elements in ARight.*) class operator GreaterThan(const ALeft: double; const ARight: Vector): Boolean; (*Returns true, if coresponding elements in ALeft are greater than coresponding elements in ARight.*) class operator GreaterThan(const ALeft: Vector; const ARight: Vector): Boolean; (*Add left to all elements in Right and return result.*) class operator Add(const Left: TCplx; const Right: Vector): Vector; (*Add Right to all elements in Left and return result.*) class operator Add(const Left: Vector; const Right: TCplx): Vector; (*Add Left to all elements in Right and return result.*) class operator Add(const Left: double;const Right: Vector): Vector; (*Add Right to all elements in Left and return result.*) class operator Add(const Left: Vector; const Right: double): Vector; (*Add coresponding elements in Left and Right.*) class operator Add(const Left: TMtxVec;const Right: Vector): Vector; (*Add coresponding elements in Left and Right.*) class operator Add(const Left: Vector; const Right: TMtxVec): Vector; (*Add coresponding elements in Left and Right.*) class operator Add(const Left: Vector;const Right: Vector): Vector; (*Subtract all elements in Right from Left.*) class operator Subtract(const Left: TCplx; const Right: Vector): Vector; (*Subtract Right from all elements in Left.*) class operator Subtract(const Left: Vector; const Right: TCplx): Vector; (*Subtract all elements in Right from Left.*) class operator Subtract(const Left: double; const Right: Vector): Vector; (*Subtract Right from all elements in Left.*) class operator Subtract(const Left: Vector; const Right: double): Vector; (*Subtract coresponding elements in Right from Left.*) class operator Subtract(const Left: Vector; const Right: TMtxVec): Vector; (*Subtract coresponding elements in Right from Left.*) class operator Subtract(const Left: TMtxVec; const Right: Vector): Vector; (*Subtract coresponding elements in Right from Left.*) class operator Subtract(const Left: Vector;const Right: Vector): Vector; (*Multiply all elements in Left with Right.*) class operator Multiply(const Left: Vector; const Right: TCplx): Vector; (*Multiply all elements in Right with Left.*) class operator Multiply(const Left: TCplx; const Right: Vector): Vector; (*Multiply all elements in Left with Right.*) class operator Multiply(const Left: Vector; const Right: double): Vector; (*Multiply all elements in Right with Left.*) class operator Multiply(const Left: double; const Right: Vector): Vector; (*Multiply all elements in Left with corresponding elements in Right.*) class operator Multiply(const Left: Vector; const Right: TMtxVec): Vector; (*Multiply all elements in Left with corresponding elements in Right.*) class operator Multiply(const Left: TMtxVec; const Right: Vector): Vector; (*Multiply all elements in Left with corresponding elements in Right.*) class operator Multiply(const Left: Vector; const Right: Vector): Vector; (*Divide all elements in Left with Right.*) class operator Divide(const Left: Vector; const Right: TCplx): Vector; (*Divide Left with all elements Right.*) class operator Divide(const Left: TCplx; const Right: Vector): Vector; (*Divide all elements in Left with Right.*) class operator Divide(const Left: Vector; const Right: double): Vector; (*Divide Left with all elements Right.*) class operator Divide(const Left: double; const Right: Vector): Vector; (*Divide all elements in Left with coresponding elements in Right.*) class operator Divide(const Left: Vector; const Right: TMtxVec): Vector; (*Divide all elements in Left with coresponding elements in Right.*) class operator Divide(const Left: TMtxVec; const Right: Vector): Vector; (*Divide all elements in Left with coresponding elements in Right.*) class operator Divide(const Left: Vector; const Right: Vector): Vector; (*Negates all values inside AValue.*) class operator Negative(const AValue: Vector): Vector; (*Explicitely convert array of complex values to Vector. Copies all values from the complex array to the result. *) class operator Explicit(const AValue: TCplxArray): Vector; (*Explicitely convert array of double values to Vector. Copies all values from the double array to the result. *) class operator Explicit(const AValue: TDoubleArray): Vector; (*Explicitely convert array of single values to Vector. Copies all values from the AValue array to the result. *) class operator Explicit(const AValue: TSingleArray): Vector; (*Explicitely convert TVec to Vector. Copies all values from AValue to the result. *) class operator Explicit(const AValue: TVec): Vector; (*Explicitely convert TVecInt to Vector. Copies all values from AValue to the result. *) class operator Explicit(const AValue: TVecInt): Vector; (*Explicitely convert VectorInt to Vector. Copies all values from AValue to the result. *) class operator Explicit(const AValue: VectorInt): Vector; (*Explicitely convert Vector to VectorInt. Copies all values from AValue to the result. *) class operator Explicit(const AValue: Vector): VectorInt; (*Explicitely convert Vector to array of doubles. Copies all values from AVector to an array of double. *) class operator Explicit(const AValue: Vector): TDoubleArray; (*Explicitely convert Vector to array of doubles. Copies all values from AVector to an array of single. *) class operator Explicit(const AValue: Vector): TSingleArray; (*Implicit type conversion from Vector to PSCplx. Returns a pointer to the internal array of values. If the Precision does not match an exception will be raised. This conversion avoids all range checking, which would be broken, if Vector.IsSubRange = True. *) class operator Implicit(const AValue: Vector): Math387.PPSCplx; (*Implicit type conversion from Vector to an array of double. Returns a pointer to the internal array of values. If the Precision does not match an exception will be raised. This conversion avoids all range checking, which would be broken, if Vector.IsSubRange = True. *) class operator Implicit(const AValue: Vector): System.PDouble; (*Implicit type conversion from Vector to PSingle. Returns a pointer to the internal array of values. If the Precision does not match an exception will be raised. This conversion avoids all range checking, which would be broken, if Vector.IsSubRange = True. *) class operator Implicit(const AValue: Vector): System.PSingle; (*Implicit type conversion from Vector to PCplx. Returns a pointer to the internal array of values. If the Precision does not match an exception will be raised. This conversion avoids all range checking, which would be broken, if Vector.IsSubRange = True. *) class operator Implicit(const AValue: Vector): Math387.PPCplx; (*Implicit type conversion from Vector to an array of TCplx. Returns a pointer to the internal array of values. Not thread safe for subranged objects, because it temporarily modifies negative Index of the array for RefCount purposes. *) class operator Implicit(const AValue: Vector): TCplxArray; (*Implicit type conversion from Vector to an array of double. Returns a pointer to the internal array of values. Not thread safe for subranged objects, because it temporarily modifies negative Index of the array for RefCount purposes. *) class operator Implicit(const AValue: Vector): TDoubleArray; (*Implicit type conversion from Vector to an array of TCplx. Returns a pointer to the internal array of values. Not thread safe for subranged objects, because it temporarily modifies negative Index of the array for RefCount purposes. *) class operator Implicit(const AValue: Vector): TSCplxArray; (*Implicit type conversion from Vector to an array of double. Returns a pointer to the internal array of values. Not thread safe for subranged objects, because it temporarily modifies negative Index of the array for RefCount purposes. *) class operator Implicit(const AValue: Vector): TSingleArray; (*Implicit type conversion from Vector to TVec. Returns a pointer to the internal TVec object. *) class operator Implicit(const AValue: Vector): TVec; (*Returns a pointer to the internal TVec object.*) class operator Implicit(const AValue: Vector): TMtxVec; (*Returns a pointer to the internal TVec object.*) class operator Implicit(const AValue: Vector): TDenseMtxVec; (*Returns a pointer to the internal TVec object.*) class operator Implicit(const AValue: Vector): TMtxVecBase; (*Returns a pointer to the internal TVec object.*) class operator Implicit(const AValue: Vector): TObject; (*Constructor of the record. Returns a Vector with internal TVec object created from object cache (CreateIt), if FromObjectCache is True. Pass false to the constructor, if the variable is a global variable. Object cache has limited size and is to be used only for local variables. *) constructor Create(FromObjectCache: boolean); overload; (*Constructor of the record. Returns a Vector with internal TVec object created explicitely with Length property set to aLength and Complex property set to IsComplex. Call this constructor, if the Vector type variable is a global variable with a long life span. var a,b: Vector; bvec: TVec; begin a := Vector.Create(true); //create from object cache via CreateIt //this constructor can be omitted, because it is implictely called //the first time that the variable is used. //However: b := Vector.Create(10); //Similar to bvec := TVec.Create; try bvec.Size(10); finally bvec.Free; //b is freed on the exit from the procedure end; end; *) constructor Create(const aLength: integer; const aIsComplex: boolean; const aIsDouble: boolean); overload; constructor Create(const aLength: integer; const aIsComplex: boolean); overload; public (*Defines the length in number of samples. Defines the number of samples that the Vector can store. The length property does not map directly to memory reallocation when it is changed. Until the amount of preallocated memory is not exceed, there is no reallocation going on. Changing the Length property will preserve the existing values, but only if the new property value is smaller than the amount of preallocated memory. To properly resize the memory allocated use the method. It is recommended that vector sizes do not exceed the size of preallocated memory to increase performance. The size of preallocated memory can be controlled via the Controller global variable which is defined in the MtxVec unit. *) property Length: integer read get_Length write set_Length; (*Defines the precision (single, float) and type (real, complex) of the floating point operations. *) property FloatPrecision: TMtxFloatPrecision read get_FloatPrecision write Set_FloatPrecision; (*Enables/disable inline condition checking. Enables/disables inline condition checking. When true, TVec methods perform additional (range) checking before operations are executed. The drawback is slight loss of speed. If ConditionCheck is set to false then no additional checking is performed. This speeds up the execution but disables some safeguards. For short vectors the loss of speed can be significant. The more parameters the method requires the more error checking is performed. Some methods (parameterless) don't use the ConditionCheck property at all. ConditionCheck property is initially True. This property is an additional safeguard against array overrun or underrun errors. It allows you to work with explicit range checking while writing and debugging the application and once your code is running you can turn it off. By functionality it is similar to assertions. (See Assert Delphi procedure). You can also use compiler directives to check, if assertions are on and then set ConditionCheck to True. *) property ConditionCheck: boolean read get_ConditionCheck write set_ConditionCheck; (*Vector Caption. Use this property to set/get the string caption for the vector. This can be usefull for associating description with data when making a user interface. *) property Caption: string read get_Caption write set_Caption; (*Stores an integer value as a part of the object. Tag has no predefined meaning. The Tag property is provided for the convenience of developers. It can be used for storing an additional integer value or it can be typecast to any 32-bit value such as a component reference or even a pointer. *) property Tag: integer read get_Tag write set_Tag; (*Defines if object values are complex. If true, will treat it's elements as complex numbers. Two successive number in the values array be treated as real and imaginary part of the complex number. When property is false, object will treat it's elements as real numbers. You should always set the value of the Complex property before setting object size ( for vector or , for matrix). Setting Complex from true to false does not cause memory reallocation. It simply doubles the value of the Length property. Setting Complex from false to true halves the vector length or number of matrix columns, but retains all data. Complex property is initially false. var a,b,c,d: Vector; begin a.SetIt(True,[1,2,3,4]); b.SetIt(False,[8,9,6,7]); b.Complex := True; c.Mul(a,b); // = [(1+2i)*(8*9i), (3+4i)*(6+7i)] end; *) property Complex: boolean read get_Complex write set_Complex; (*FFT storage format. The FFT storage format specifies how will the result of an operation be stored in the destination. This affects both 1D and 2D FFT's. *) property FFTStorageFormat: TFFTStorageFormat read get_FFTStorageFormat write set_FFTStorageFormat; (*Leave FFT scrambeled. The last stage (or first) of an FFT, is a sorting operation. This sorting will be left out, if this property will be set to True. This can improve performance for certain applications, if you used properly. *) property FFTScrambled: boolean read get_FFTScrambled write set_FFTScrambled; (*Defines if FFT transform length is odd. The property should be set to True, if the length of a forward real to complex FFT is odd and if the result of an inverser complex to real FFT should be odd. *) property FFTOddLength: boolean read get_FFTOddLength write set_FFTOddLength; (*Sizing the object will not allocate less than Capacity samples. To free memory allocated before, first set Capacity to 0. In case of complex numbers the size is half here specified. *) property Capacity: Int64 read get_Capacity write set_Capacity; (*Specifies increment step for the Capacity property. If this property is 0, the Capacity will never be modified on its own. When the value 1, the capacity will continue increasing to match largest value requested. When the value is more than 1, the capacity will be increasing with the factor specified. *) property CapacityStep: double read get_CapacityStep write set_CapacityStep; public property IsDouble: boolean read get_IsDouble write set_IsDouble; (*Obtains a pointer to the real value of the vector at Index. The function returns @Values[i]. Under .NET this is a pointer to unmanaged memory. *) function PValues1D(const Index: integer): PPDouble; function PSValues1D(const Index: integer): PPSingle; (*Obtains a pointer to the complex value of the vector at Index. The function returns @CValues[i]. Under .NET this is a pointer to unmanaged memory. *) function PCValues1D(const Index: integer): PPCplx; function PSCValues1D(const Index: integer): PPSCplx; (*Additional parameter for certain Lapack methods. Additional parameter for certain Lapack methods. When this value is used, it is mentioned in the method description. This parameter has been made a field of the object, to reduce the number of parameters required by a method, because it is not used very often. *) property Beta: TCplx read get_Beta write set_Beta; (*Additional parameter for certain Lapack methods. Additional parameter for certain Lapack methods. When this value is used, it is mentioned in the method description. This parameter has been made a field of the object, to reduce the number of parameters required by a method, because it is not used very often. *) property Alfa: TCplx read get_Alfa write set_Alfa; property RealValues: string read get_RealValues; property ComplexValues: string read get_ComplexValues; (*Defines the rounding used by streaming routines. Defines the rounding used by streaming routines. *) property Rounding: TRounding read get_Rounding write set_Rounding; (*Defines the precision used by streaming routines. Defines the rounding used by streaming routines. *) property Precision: TPrecision read get_Precision write set_Precision; (*Returns true, if the currrent subrange of the vector was also the last subrange in the vector. Returns true, if the currrent subrange of the vector was also the last subrange in the vector. This property be used together with and . *) property BlockEnd: boolean read Get_BlockEnd; (*Set to true after the SetSubIndex or SetSubRange call. This property is set to true after the or call. If IsSubRange is true then the TVec method/function will be performed on subrange of values. Use to set IsSubRange back to False and thus reset sub range to full vector length. *) property IsSubRange: boolean read get_IsSubRange; (*Returns the current depth of SubRange stack.*) property SubRangeLevel: integer read get_SubRangeLevel; (*The tolerance used by . The tolerance used by when the comparison type is relative. *) property ZeroTolerance: double read get_ZeroTolerance write set_ZeroTolerance; (*Allows setting/getting the real value at position Indx. Allows setting/getting the real value at position Indx. This property reads/writes to the same memory as properties. *) property Values[const Indx: integer]: double read get_Values write set_Values; default; (*Allows setting/getting the complex value at position Indx. Allows setting/getting the complex value at position Indx. This property reads/writes to the same memory as properties. *) property CValues[const Indx: integer]: TCplx read get_CValues write set_CValues; (*Allows setting/getting the real value at position Indx. Allows setting/getting the real value at position Indx. This property reads/writes to the same memory as and properties. *) property SValues[const Indx: integer]: single read get_SValues write set_SValues; (*Allows setting/getting the complex value at position Indx. Allows setting/getting the complex value at position Indx. This property reads/writes to the same memory as *) property SCValues[const Indx: integer]: TSCplx read get_SCValues write set_SCValues; (*Allows copying/assignment of subranges. Reading this property will return a sub-ranged Vector. Similar to calling b.SetSubRange(a, Indx, Len); Writing this property will copy source to the specified subrange. The size of the value being assigned needs to match the range specified. *) property Select[const Indx, Len: integer]: Vector read GetSelect write SetSelect; (*Allows copying/assignment of subranges. Reading this property will return a copied selection of subranged vector by calling Dst.GatherByIncr(Src, startIndex, Step); Writing this property will copy source to the specified range by using Data.ScatterByIncr. The size of the value being assigned needs to match the index range specified. This property does not obtain a "view" unless Step equals to 1. *) property SelectIndex[const startIndex, Step, stopIndex: integer]: Vector read GetSelectIndex write SetSelectIndex; (*Returns content as a string. Values will be separated by line breaks. *) function ToString: string; (*Parses string content as vector. Values need to be separated by the tab charachter. Rows of values need to be separated by line breaks. For other parsing options call StringToValues. The Parse method works in pair with the ToString method both meant to be a reverse of the other, but do not preserve any other property of the matrix except only values. Use SaveToStream/LoadFromStream methods for binary storage option, which uses up to 10x less memory and is a lot faster to save and load. *) class function Parse(const Src: string): Vector; static; procedure AssignWithoutCopy(const Src: Vector); procedure Assign(const Src: Vector); (*Initializes block processing. Initializes block processing. Because the size of the CPU cache is limited, significant performance gains can be obtained by splitting long vectors in to a series of short ones, which can all fit in the CPU cache entirely. The BlockInit method is to be used together with and methods to initialize a block processing while loop. BlockInit will call to obtain subrange of the data in TVec. The of the subranged vector is determined by the global variable declared in unit. Default value of MtxVecBlockSize is preset to 800 vector elements for double precision and 1600 elements for single precision. BlockInit supports nested calls and from witihin a blocked while loop you can call procedures and functions which are also blocked. If you use block processing, typical performance gains will range from 2 to a maximum of 6. Block processing can not be used, or it is difficult to apply, in cases where vector elements are not independent of each other. Block processing is a requirement, if threading is to be implemented. Without block processing, it is possible that multi-threading will not result in performance improvement regardless of core count, because the performance would be memory bandwidth limited. The block processing while loop must be written like this: a.BlockInit; while not A.BlockEnd do begin // .... user defined function a.BlockNext. end; Normal vectorized procedure: procedure ParetoPDF(const X: TVec; a, b: double; const Res: TVec); overload; begin Res.Size(X); Res.Power(X,-(a+1)); Res.Mul(Power(b,a)*a);; end; Vectorized and blocked version of the Pareto probability distribution procedure: procedure ParetoPDF(const X: TVec; a, b: double; const Res: TVec); overload; begin Res.Size(X); Res.BlockInit; X.BlockInit; while not X.BlockEnd do begin Res.Power(X,-(a+1)); Res.Mul(Power(b,a)*a); Res.BlockNext; X.BlockNext; end; end; The block version of the ParetoPDF will execute faster then the non-blocked version in cases where X contains 5000-10000 elements or more (double precision). Below that value the two versions will perform about the same, except for very short vector sizes (below 50 elements), where the non-blocked version will have a slight advantage, because of the absence of block processing methods overhead. The time is saved between the calls to Res.Power(X,-(a+1)) and Res.Mul(Power(b,a)*a), where the same memory (stored in Res vector) is accesed in two consecutive calls. That memory is loaded in the CPU cache on the first call, if the Length of the Res vector is short enough to fit in. As an excercise you can also try to compare the performance of the vectorized and blocked version of the function with the single value version (ParetoPDF(X: double; a, b: double; Res: double) and measure the execution time of both versions for long vectors (100 000 elements) and short vectors (10 elements). The differences with block processing will be more noticable on old CPU's without support for SSE2/SSE3. *) procedure BlockInit; overload; (*Initializes block processing.*) procedure BlockInit(ABlockSize: integer); overload; (*Initializes block processing.*) procedure BlockInit(const Src: TDenseMtxVec); overload; (*Initializes block processing. Block processing can be applied on possibly already subranged Src object. Src may not be freed or go out of scope until block processing loop has finished. There would be no error raised other than AV. *) procedure BlockInit(const Src: TDenseMtxVec; ABlockSize: integer); overload; (*Obtains the next subrange of the data. Obtains the next subrange of the data in TVec. The routine must be used together with and methods. *) procedure BlockNext; (*Deinitializes block processing before the final block is processed. Call this routine before breaking out of a while-loop prematurely. Vec.BlockInit While not Vec.BlockEnd do Begin If Vec.Min < 0 then //check some condition, if you need to exit begin Vec.BlockFinish; //finish the loop Break; //and break out end; Vec.BlockNext; end *) procedure BlockFinish; (*Replaces all NAN values with Value. The function will replace all occurences of NAN. If the vector is complex, it will replace any real/imag parts, which are NAN. *) function ReplaceNAN(const Value: double): TMtxVec; overload; (*Replaces all NAN values with Value within calling object elements [Index]..[Index+Len-1]. The function will replace all occurences of NAN. If the vector is complex, it will replace any real/imag parts, which are NAN. An exception is raised, if array borders are overrun. *) function ReplaceNAN(const Value: double; Index, Len: integer): TMtxVec; overload; (*Prevents calls to . Prevents calls to method. This can be usefull guard when an object is already working on a subrange and the user would like to further subrange an already subranged object. var a,b: Vector; begin a.SetIt(false, [1,2,3,4,5,6,7,8,9]); a.SetSubRange(0,2); //a = [1,2] a.DisableSubrange; a.SetSubRange(2,2); //exception raised here b.SetSubRange(a,2,2); //but this will work a.SetFullRange; //b is not changed, it still points to [4,5] end; *) procedure DisableSubrange; (*Enables calls to . Enables calls to by removing the block set by . *) procedure EnableSubrange; (*Prevents calls to . Prevents calls to method. This can be usefull guard when an object is already working on a subrange and the user would like to further subrange an already subranged object. var a,b: Vector; begin a.SetIt(false, [1,2,3,4,5,6,7,8,9]); a.Select(0,2); //a = [1,2] a.DisableSelect; a.Select(2,2); //exception raised here b.Select(a,2,2); //but this will work a.SelectAll; //b is not changed, it still points to [4,5] end; *) procedure DisableSelect; (*Enables calls to . Enables calls to by removing the block set by . *) procedure EnableSelect; (*Resets any defined selection. *) procedure SelectAll; overload; (*Resets any defined subrange. *) procedure SetFullRange; procedure SetFullRangeLevel; (*Defines a sub vector/matrix. The method will define a subarray starting at Index and ending at Index+Len-1. No copying will occur, only pointers will be shifted. All values of the original will be preserved. An exception will be raised if an attempt is made to change the size of calling object. A sub-vector/matrix is vector/matrix which does not neccessarily have its own memory allocated. Instead it adopts the memory of the source object and all operations done on the either of the objects affect the same elements. The use of subvectors/submatrices increases CPU cache reuse, lower's memory requirements, increases application performance and improves code readability. Note To again obtain a view of the full vector/matrix, see *) procedure SetSubRange(Index: integer; Len: integer); overload; (*Defines a sub vector/matrix and pushes previous subrange to internal stack. Call SetSubRangeLevel, to pop the stack. *) procedure SetSubRangeLevel(Index: integer; Len: integer); overload; (*Sets the subarray size to full size. This method is the same as the method. *) procedure SetSubRange; overload; (*Defines a subarray. The method will define a sub array starting at BeginIndex and ending at EndIndex (inclusive). All values of the original vector/matrix will be preserved. An exception will be raised if an attempt is made to change the size of calling vector/matrix. A subarray is array which does not have its own memory allocated. Instead it adopts the memory of the source object and all operations done on the either of the objects affect the same elements. The use of subarrays increases CPU cache reuse, lower's memory requirements, increases application performance and improves code readability. Note To again obtain a view of the full vector see *) procedure SetSubIndex(BeginIndex, EndIndex: integer); overload; (*Finds a match for X in sorted object values using binary search. The data in the vector must be sorted in ascending order for this function to work correctly. the Index of last matched element. If no matching elements are found, the result is -1.*) function BinarySearch(const X: double): Integer; overload; function BinarySearch(const X: double; const Index: integer; Len: integer): Integer; overload; function BinarySearch(const X: TCplx): Integer; overload; function BinarySearch(const X: TCplx; const Index: integer; Len: integer): Integer; overload; (*Finds exact or closest Index match for X in sorted object values using binary search. The data in the vector must be sorted in ascending order for this function to work correctly. The closest match is the Index of first bigger or smaller value in the array. To ensure bigger value write: Data := [0,2,3]; Data.BinarySearch(Value, XIndex); if Data[XIndex] > Value then Dec(XIndex); To ensure smaller value write: Data := [0,2,3]; Data.BinarySearch(1, XIndex); if Data[XIndex] < Value then Inc(XIndex); True and exact Index in XIndex, if found and False and the Index of the next bigger or smaller value in XIndex, if not found. *) function BinarySearch(const X: double; var XIndex: integer): boolean; overload; function BinarySearch(const X: double; var XIndex: integer; const Index: integer; Len: integer): boolean; overload; function BinarySearch(const X: TCplx; var XIndex: integer): boolean; overload; function BinarySearch(const X: TCplx; var XIndex: integer; const Index: integer; Len: integer): boolean; overload; (*Sine. Calculate the sine of all caling object elements in-place. var a: Vector; begin a.SetIt(True,[1,-2,3,4]); a.Sin; // Computes complex sine end; *) function Sin: TMtxVec; overload; (*Calculate the sine of calling object elements [Index]...[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function Sin(Index: integer; Len: integer): TMtxVec; overload; (*Calculate the sine of all X object elements and store the results in calling object. Size and properties of calling object are adjusted automatically. *) function Sin(const X: TMtxVec): TMtxVec; overload; (*Calculate the sine of X object elements [XIndex]...[XIndex+Len-1]. The results are storedin calling object elements [Index]...[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if array borders are overrun. *) function Sin(const X: TMtxVec; XIndex: integer; Index: integer; Len: integer): TMtxVec; overload; (*Cosine. Calculate the cosine of all caling object elements in-place. var a: Vector; begin a.SetIt(True,[1,-2,3,4]); a.Cos; // Computes complex sine end; *) function Cos: TMtxVec; overload; (*Calculate the cosine of calling object elements [Index]...[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function Cos(Index: integer; Len: integer): TMtxVec; overload; (*Calculate the cosine of all X object elements store the results in the calling object. Size and properties of calling object are adjusted automatically. *) function Cos(const X: TMtxVec): TMtxVec; overload; (*Calculate the cosine of X object elements [XIndex]...[XIndex+Len-1]. The results are stored in calling object elements [Index]...[Index+Len-1]. Size and properties of calling object and the calling object must be set explicitly. An exception is raised if array borders are overrun. *) function Cos(const X: TMtxVec; XIndex: integer; Index: integer; Len: integer): TMtxVec; overload; (*Tangens. Calculate the tangens of all caling object elements in-place. var a: Vector; begin a.SetIt(True,[1,-2,3,4]); a.Tan; // Computes complex tangens end; *) function Tan: TMtxVec; overload; (*Calculate the tangens of calling object elements [Index]...[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function Tan (Index: integer; Len: integer): TMtxVec; overload; (*Calculate the tangens of all X object elements. Xtore the results in the calling object. Size and properties of calling object are adjusted automatically. *) function Tan(const X: TMtxVec): TMtxVec; overload; (*Calculate the tangens of X object elements [XIndex]...[XIndex+Len-1]. The results are stored in calling object elements [Index]...[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if array borders are overrun. *) function Tan(const X : TMtxVec; XIndex: integer; Index: integer; Len: integer): TMtxVec; overload; (*Cotangens. Calculate the cotangens of all caling object elements in-place. var a: Vector; begin a.SetIt(True,[1,-2,3,4]); a.Cot; // Computes complex cotangens end; *) function Cot: TMtxVec; overload; (*Calculate the cotangens of calling object elements [Index]...[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function Cot(Index, Len: integer): TMtxVec; overload; (*Calculate the cotangens of all X object elements. Store the results in the calling object. Size and properties of calling object are adjusted automatically. *) function Cot(const X: TMtxVec): TMtxVec; overload; (*Calculate the cotangens of X object elements [XIndex]...[XIndex+Len-1]. The results are stored in calling object elements [Index]...[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if array borders are overrun. *) function Cot(const X: TMtxVec; XIndex, Index, Len: integer): TMtxVec; overload; (*Secant. Calculate the secant of all caling object elements in-place. var a: Vector; begin a.SetIt(True,[1,-2,3,4]); a.Sec; // Computes complex secant end; *) function Sec: TMtxVec; overload; (*Calculate the secant of calling object elements [Index]...[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function Sec(Index, Len: integer): TMtxVec; overload; (*Calculate the secant of all X object elements. Store the results in the calling object. Size and properties of calling object are adjusted automatically. *) function Sec(const X: TMtxVec): TMtxVec; overload; (*Calculate the secant of X object elements [XIndex]...[XIndex+Len-1]. The results are stored in calling object elements [Index]...[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if array borders are overrun. *) function Sec(const X: TMtxVec; XIndex, Index, Len: integer): TMtxVec; overload; (*Cosecant. Calculate the cosecant of all caling object elements in-place. var a: Vector; begin a.SetIt(True,[1,-2,3,4]); // a = [1-2i, 3+4i] a.Csc; // Computes complex cosecant end; *) function Csc: TMtxVec; overload; (*Calculate the cosecant of calling object elements [Index]...[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function Csc(Index, Len: integer): TMtxVec; overload; (*Calculate the cosecant of all X object elements. Store the results in the calling object. Size and properties of calling object are adjusted automatically. *) function Csc(const X: TMtxVec): TMtxVec; overload; (*Calculate the cosecant of X object elements [XIndex]...[XIndex+Len-1]. The results are stored in calling object elements [Index]...[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if array borders are overrun. *) function Csc(const X: TMtxVec; XIndex, Index, Len: integer): TMtxVec; overload; (*The inverse sine. Calculate the inverse sine of all calling object elements in-place. Values must be between -1 and 1. The return values will be in the range [0,PI], in radians. var a,b: Vector; begin a.SetIt(True,[1,-0.5,0.11,0.9]); a.ArcSin; //or b := ArcSin(a); //or a := ArcSin(a); end; *) function ArcSin: TMtxVec; overload; (*Calculate the inverse sine of calling object elements [Index]...[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function ArcSin(Index, Len: integer): TMtxVec; overload; (*Calculate the inverse sine of all X object elements. Store the results in the calling object. Size and properties of calling object are adjusted automatically. *) function ArcSin(const X: TMtxVec): TMtxVec; overload; (*Calculate the inverse sine of X object elements [XIndex]...[XIndex+Len-1]. The results are stored in calling object elements [Index]...[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if array borders are overrun. *) function ArcSin(const X: TMtxVec; XIndex, Index, Len: integer): TMtxVec; overload; (*The inverse cosine. Calculate the inverse cosine of all calling object elements in-place. Values must be between -1 and 1. The return values will be in the range [0,PI], in radians. var a,b: Vector; begin a.SetIt(True,[1,-0.5,0.11,0.9]); a.ArcCos; // or b := ArcCos(a); // or a := ArcCos(a); end; *) function ArcCos: TMtxVec; overload; (*Calculate the inverse cosine of calling object elements [Index]...[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function ArcCos(Index, Len: integer): TMtxVec; overload; (*Calculate the inverse cosine of all X object elements and store the results in the calling object. Size and properties of calling object are adjusted automatically. *) function ArcCos(const X: TMtxVec): TMtxVec; overload; (*Calculate the inverse cosine of X object elements [XIndex]...[XIndex+Len-1]. The results are stored in calling object elements [Index]...[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if array borders are overrun. *) function ArcCos(const X: TMtxVec; XIndex, Index, Len: integer): TMtxVec; overload; (*Inverse tangens of Y/X. Calculates the inverse tangens of Y/X, and returns an angle in the correct quadrant. The results are stored in calling object elements. Size and properties of calling object are adjusted automatically to match those of X and Y objects. An exception is raised if X and Y size and properties do not match. The result will fall in the range from -PI to PI radians. Note that is calculated as ArcTan2(1, X). *) function ArcTan2(Y, X: TMtxVec): TMtxVec; overload; (*Calculate the inverse tangens of Y/X by using Y elements [YIndex]..[YIndex+Len-1], X elements [XIndex]..[XIndex+Len-1]. Store the results in calling object elements [Index]..[Index+Len-1]. An exception is raised if array borders are overrun. *) function ArcTan2(Y, X: TMtxVec; YIndex, XIndex, Index: integer; Len: integer): TMtxVec; overload; (*Inverse tangens. Calculate the inverse tangens for all calling object elements in-place. The return values are expressed in radians. var A,B: Vector; begin A.SetIt(2,2,True,[1,0, 2,0 2,0 4,1]); // 2x2, complex matrix B.ArcTan(A); // or B := ArcTan(A); // or A := ArcTan(A); end; *) function ArcTan: TMtxVec; overload; (*Calculate the inverse tangens of calling object elements [Index]...[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function ArcTan(Index, Len: integer): TMtxVec; overload; (*Calculate the inverse tangens of all X object elements. Store the results in the calling object. Size and properties of calling object are adjusted automatically. *) function ArcTan(const X: TMtxVec): TMtxVec; overload; (*Calculate the inverse tangens of X object elements [XIndex]...[XIndex+Len-1]. The results are stored in calling object elements [Index]...[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if array borders are overrun. *) function ArcTan(const X: TMtxVec; XIndex, Index, Len: integer): TMtxVec; overload; (*Inverse cotangens. Calculate the inverse cotangens for all calling object elements in-place. The return values are expressed in radians. var A,B: Vector; begin A.SetIt(2,2,True,[1,0, 2,0 2,0 4,1]); // 2x2, complex matrix B.ArcCot(A); //or B := ArcCot(A); end; *) function ArcCot: TMtxVec; overload; (*Calculate the inverse cotangens of calling object elements [Index]...[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function ArcCot(Index, Len: integer): TMtxVec; overload; (*Calculate the inverse cotangens of all X object elements. Store the results in the calling object. Size and properties of calling object are adjusted automatically. *) function ArcCot(const X: TMtxVec): TMtxVec; overload; (*Calculate the inverse cotangens of X object elements [XIndex]...[XIndex+Len-1]. The results are stored in calling object elements [Index]...[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if array borders are overrun. *) function ArcCot(const X: TMtxVec; XIndex, Index, Len: integer): TMtxVec; overload; (*Inverse secant. Calculate the inverse secant for all calling object elements in-place. *) function ArcSec: TMtxVec; overload; (*Calculate the inverse secant of calling object elements [Index]...[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function ArcSec(Index, Len: integer): TMtxVec; overload; (*Calculate the inverse secant of all X object elements. Store the results in the calling object. Size and properties of calling object are adjusted automatically. *) function ArcSec(const X: TMtxVec): TMtxVec; overload; (*Calculate the inverse secant of X object elements [XIndex]...[XIndex+Len-1]. The results are stored in calling object elements [Index]...[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if array borders are overrun. *) function ArcSec(const X: TMtxVec; XIndex, Index, Len: integer): TMtxVec; overload; (*Inverse cosecant. Calculate the inverse cosecant for all calling object elements in-place. *) function ArcCsc: TMtxVec; overload; (*Calculate the inverse cosecant of calling object elements [Index]...[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function ArcCsc(Index, Len: integer): TMtxVec; overload; (*Calculate the inverse cosecant of all X object elements. Store the results in the calling object. Size and properties of calling object are adjusted automatically. *) function ArcCsc(const X: TMtxVec): TMtxVec; overload; (*Calculate the inverse cosecant of X object elements [XIndex]..[XIndex+Len-1]. The results are stored in the calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if array borders are overrun. *) function ArcCsc(const X: TMtxVec; XIndex, Index, Len: integer): TMtxVec; overload; (*Hyperbolic sine. Calculate the hyperbolic sine of all caling object elements in-place. var a: Vector; begin a.SetIt(False,[1,1.5,2,0.3]); a.Sinh; // or a := Sinh(a); // no speed loss because of copy, internally becomes a.Sinh end; *) function Sinh: TMtxVec; overload; (*Calculate the hyperbolic sine of calling object elements [Index]...[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function Sinh(Index, Len: integer): TMtxVec; overload; (*Calculate the hyperbolic sine of all X object elements. Store the results in the calling object. Size and properties of calling object are adjusted automatically. *) function Sinh(const X: TMtxVec): TMtxVec; overload; (*Calculate the hyperbolic sine for X object elements [XIndex]..[XIndex+Len-1]. The results are stored in the calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if array borders are overrun. *) function Sinh(const X: TMtxVec; XIndex, Index, Len: integer): TMtxVec; overload; (*Hyperbolic cosine. Calculate the hyperbolic cosine of all caling object elements in-place. var a,b: Vector; begin a.SetIt(False,[1,1.5,2,0.3]); a.Cosh; //or a := Cosh(a); //internally becomes a.Cosh (in-place operation) b.Cosh(a); b := Cosh(a); end; *) function Cosh: TMtxVec; overload; (*Calculate the hyperbolic cosine for calling object elements [Index]..[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function Cosh(Index, Len: integer): TMtxVec; overload; (*Calculate the hyperbolic cosine for all X object elements. Store the results in the calling object. Size and properties of calling object are adjusted automatically. *) function Cosh(const X: TMtxVec): TMtxVec; overload; (*Calculate the hyperbolic cosine for X object elements [XIndex]..[XIndex+Len-1]. The results are stored in calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if array borders are overrun. *) function Cosh(const X: TMtxVec; XIndex, Index, Len: integer): TMtxVec; overload; (*Hyperbolic tangens. Calculate the hyperbolic tangens of all caling object elements in-place. var a,b: Vector; begin a.SetIt(False,[1,1.5,2,0.3]); a.Tanh; //or a := Tanh(a); //same as a.Tanh (in place operation) b := Tanh(a); //not in place b.Tanh(a); //not in place end; *) function Tanh: TMtxVec; overload; (*Calculate the hyperbolic tangens for calling object elements [Index]..[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function Tanh(Index, Len: integer): TMtxVec; overload; (*Calculate the hyperbolic tangens for all X object elements. Store the results in the calling object. Size and properties of calling object are adjusted automatically. *) function Tanh(const X: TMtxVec): TMtxVec; overload; (*Calculate the hyperbolic tangens for X object elements [XIndex]..[XIndex+Len-1]. The results are stored in the calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if array borders are overrun. *) function Tanh(const X: TMtxVec; XIndex, Index, Len: integer): TMtxVec; overload; (*Hyperbolic cotangens. Calculate the hyperbolic cotangens of all caling object elements in-place. var a,b: Vector; begin a.SetIt(False,[1,1.5,2,0.3]); a.Coth; a := Coth(a); //internally becomes a.Coth b.Coth(a); //same as b := Coth(a); end; *) function Coth: TMtxVec; overload; (*Calculate the hyperbolic cotangens for calling object elements [Index]...[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function Coth(Index, Len: integer): TMtxVec; overload; (*Calculate the hyperbolic cotangens for all X object elements. Store the results in the calling object. Size and properties of calling object are adjusted automatically. *) function Coth(const X: TMtxVec): TMtxVec; overload; (*Calculate the hyperbolic cotangens for X object elements [XIndex]..[XIndex+Len-1]. The results are stored in calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if array borders are overrun. *) function Coth(const X: TMtxVec; XIndex, Index, Len: integer): TMtxVec; overload; (*Hyperbolic secant. Calculate the hyperbolic secant of all caling object elements in-place. *) function Sech: TMtxVec; overload; (*Calculate the hyperbolic secant for calling object elements [Index]...[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function Sech(Index, Len: integer): TMtxVec; overload; (*Calculate the hyperbolic secant for all X object elements. Store the results in the calling object. Size and properties of calling object are adjusted automatically. *) function Sech(const X: TMtxVec): TMtxVec; overload; (*Calculate the hyperbolic secant for X object elements [XIndex]..[XIndex+Len-1]. The results are stored in calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if array borders are overrun. *) function Sech(const X: TMtxVec; XIndex, Index, Len: integer): TMtxVec; overload; (*Hyperbolic cosecant. Calculate the hyperbolic cosecant of all caling object elements in-place. *) function Csch: TMtxVec; overload; (*Calculate the hyperbolic cosecant for calling object elements [Index]..[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function Csch(Index, Len: integer): TMtxVec; overload; (*Calculate the hyperbolic cosecant for all X object elements. Store the results in the calling object. Size and properties of calling object are adjusted automatically. *) function Csch(const X: TMtxVec): TMtxVec; overload; (*Calculate the hyperbolic cosecant for X object elements [XIndex]..[XIndex+Len-1]. The results are stored in calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if array borders are overrun. *) function Csch(const X: TMtxVec; XIndex, Index, Len: integer): TMtxVec; overload; (*Absolute values. Calculate the absolute value of all calling object elemets in-place. var a,b: Vector; begin a.SetIt(True,[1,-2,3,4]); a.Abs; a := Abs(a); //same as a.Abs b.Abs(a); //same as b := Abs(a); b := Abs(a); end; *) function Abs: TMtxVec; overload; (*Calculate the absolute value for calling object elements [Index]..[Index+Len-1]. An exception is raised if array borders are overrun or underrun. *) function Abs(Index, Len: integer): TMtxVec; overload; (*Calculate the absolute value for all X object. Store the results in the calling object. Size and property of calling object are adjusted automatically. *) function Abs(const X: TMtxVec): TMtxVec; overload; (*Calculate the absolute value of X object elements [XIndex]..[XIndex+Len-1]. and Store the results in calling object elements [Index]..[Index+Len-1]. An exception is raised if array borders are overrun or underrun. *) function Abs(const X: TMtxVec; XIndex, Index, Len: integer): TMtxVec; overload; (*Inverse hyperbolic sine. Calculate the inverse hyperbolic sine for all caling object elements in-place. *) function ArcSinh: TMtxVec; overload; (*Calculate the inverse hyperbolic sine for calling object elements [Index]..[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function ArcSinh(Index, Len: integer): TMtxVec; overload; (*Calculate the inverse hyperbolic sine for all X object elements. Store the results in the calling object. Size and properties of calling object are adjusted automatically. *) function ArcSinh(const X: TMtxVec): TMtxVec; overload; (*Calculate the inverse hyperbolic sine for X object elements [XIndex]..[XIndex+Len-1]. The results are stored in calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if array borders are overrun. *) function ArcSinh(const X: TMtxVec; XIndex, Index, Len: integer): TMtxVec; overload; (*Inverse hyperbolic cosine. Calculate the inverse hyperbolic cosine for all caling object elements in-place. *) function ArcCosh: TMtxVec; overload; (*Calculate the inverse hyperbolic cosine for calling object elements [Index]..[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function ArcCosh(Index, Len: integer): TMtxVec; overload; (*Calculate the inverse hyperbolic cosine for all X object elements. Store the results in the calling object. Size and properties of calling object are adjusted automatically. *) function ArcCosh(const X: TMtxVec): TMtxVec; overload; (*Calculate the inverse hyperbolic cosine for X object elements [XIndex]..[XIndex+Len-1]. The results are stored in calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if array borders are overrun. *) function ArcCosh(const X: TMtxVec; XIndex, Index, Len: integer): TMtxVec; overload; (*Inverse hyperbolic tangens. Calculate the inverse hyperbolic tangens for all caling object elements in-place. *) function ArcTanh: TMtxVec; overload; (*Calculate the inverse hyperbolic tangens for calling object elements [Index]..[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function ArcTanh(Index, Len: integer): TMtxVec; overload; (*Calculate the inverse hyperbolic tangens for all X object elements. Store the results in the calling object. Size and properties of calling object are adjusted automatically. *) function ArcTanh(const X: TMtxVec): TMtxVec; overload; (*Calculate the inverse hyperbolic tangens for X object elements [XIndex]..[XIndex+Len-1]. The results are stored in the calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if array borders are overrun. *) function Arctanh(const X: TMtxVec; XIndex, Index, Len: integer): TMtxVec; overload; (*Inverse hyperbolic cotangens. Calculate the inverse hyperbolic cotangens for all caling object elements in-place. *) function ArcCoth: TMtxVec; overload; (*Calculate the inverse hyperbolic cotangens for calling object elements [Index]..[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function ArcCoth(Index, Len: integer): TMtxVec; overload; (*Calculate the inverser hyperbolic cotangens for all X object elements. Store the results in calling object. Size and properties of calling object are adjusted automatically. *) function ArcCoth(const X: TMtxVec): TMtxVec; overload; (*Calculate the inverse hyperbolic cotangens for X object elements [XIndex]..[XIndex+Len-1]. The results are stored in the calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if array borders are overrun. *) function ArcCoth(const X: TMtxVec; XIndex, Index, Len: integer): TMtxVec; overload; (*Inverse hyperbolic secant. Calculate the inverse hyperbolic secant for all caling object elements in-place. *) function ArcSech: TMtxVec; overload; (*Calculate the inverse hyperbolic secant for calling object elements [Index]..[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function ArcSech(Index, Len: integer): TMtxVec; overload; (*Calculate the inverse hyperbolic secant for all X object elements. Store the results in calling object. Size and properties of calling object are adjusted automatically. *) function ArcSech(const X: TMtxVec): TMtxVec; overload; (*Calculate the inverse hyperbolic secant for X object elements [XIndex]..[XIndex+Len-1]. The results are stored in calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if array borders are overrun. *) function ArcSech(const X: TMtxVec; XIndex, Index, Len: integer): TMtxVec; overload; (*Inverse hyperbolic cosecant. Calculate the inverse hyperbolic cosecant for all caling object elements in-place. *) function ArcCsch: TMtxVec; overload; (*Calculate the inverse hyperbolic cosecant for calling object elements [Index]...[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function ArcCsch(Index, Len: integer): TMtxVec; overload; (*Calculate the inverse hyperbolic cosecant for all X object elements. Store the results in calling object. Size and properties of calling object are adjusted automatically. *) function ArcCsch(const X: TMtxVec): TMtxVec; overload; (*Calculate the inverse hyperbolic cosecant for X object elements [XIndex]..[XIndex+Len-1]. The results are stored in calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if array borders are overrun. *) function ArcCsch(const X: TMtxVec; XIndex, Index, Len: integer): TMtxVec; overload; (*The cube root. Calculate the cube root of all calling object elements in-place. var v,w: Vector; begin v.SetIt(false,[1,8]); v.Cbrt; // v = [1,2], same as: v := Cbrt(v); w := Cbrt(v); //same as: w.Cbrt(v); end; *) function Cbrt: TMtxVec; overload; (*Calculate the cube root of calling object elements [Index]..[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function Cbrt(Index, Len: integer): TMtxVec; overload; (*Calculate the cube root of all X object elements and store the results in calling object. Size and properties of calling object are adjusted automatically. *) function Cbrt(const X: TMtxVec): TMtxVec; overload; (*Calculate the cube root of X object elements [XIndex]..[XIndex+Len-1]. The results are stored in the calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if array borders are overrun. *) function Cbrt(const X: TMtxVec; XIndex, Index, Len: integer): TMtxVec; overload; (*Rounds towards positive infinity. Rounds all calling object elements towards positive infinity in-place. Ceil(-2.8) = -2 Ceil(2.8) = 3 Ceil(-1.0) = -1 *) function Ceil: TMtxVec; overload; (*Rounds calling object elements [Index]..[Index+Len-1] towards positive infinity in-place. An exception is raised if array borders are overrun. *) function Ceil(Index,Len: integer): TMtxVec; overload; (*Rounds all Src object elements towards positive infinity. Stores the result in the calling object. Size and properties of the calling object are adjusted automatically. *) function Ceil(const Src: TMtxVec): TMtxVec; overload; (*Rounds Src object elements [SrcIndex]..[SrcIndex+Len-1] towards positive infinity. Dtores the result in the calling object elements [Index]..[Index+Len-1] Size and properties of the calling object must be set explicitly. An exception is raised if array borders are overrun. *) function Ceil(const Src: TMtxVec; SrcIndex, Index,Len: integer): TMtxVec; overload; (*Natural logarithm. Calculate the natural log for all calling object elements in-place. var a,b: Vector; begin a.SetIt(False,[1,2,3,4]); a.Ln; //same as: a := Ln(a); b.Ln(a); //same as: b := Ln(a); end; *) function Ln: TMtxVec; overload; (*Calculate the natural algorithm for all X elements and store the results in the calling object. Size and properties of the calling vector are set implicitly to match the X object. *) function Ln(const X: TMtxVec): TMtxVec; overload; (*Calculate the natural logarithm for calling object elements [Index]..[Index+Len-1] in-place. An exception is raised if is True and array borders are overrun. *) function Ln(Index, Len: integer): TMtxVec; overload; (*Calculate the natural logarithm for X elements [XIndex]..[XIndex+Len-1]. Store the results in the calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if is True and array borders are overrun. *) function Ln(const X: TMtxVec; XIndex, Index, Len: integer): TMtxVec; overload; (*Log base 10. Calculate the log base 10 for all calling object elements in-place. var a,b: Vector; begin a.SetIt(False,[10,100,1000,10000]); // a = [10,100,1000,10000] a.Log10; // a = [1,2,3,4], same as: a := Log10(a); b.Log10(a); //same as b := Log10(a); end; *) function Log10: TMtxVec; overload; (*Calculate the log base 10 for all X elements. Store the results in the calling object. Size and properties of the calling vector are set implicitly to match the X object. *) function Log10(const X: TMtxVec): TMtxVec; overload; (*Calculate the log base 10 for calling object elements [Index]..[Index+Len-1] in-place. An exception is raised if is True and array borders are overrun. *) function Log10(Index, Len: integer): TMtxVec; overload; (*Calculate the log base 10 for X elements [XIndex]..[XIndex+Len-1]. Store the results in the calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if is True and array borders are overrun. *) function Log10(const X: TMtxVec; XIndex, Index, Len: integer): TMtxVec; overload; (*Log base 2. Calculate the log base 2 for all calling object elements in-place. var a,b: Vector; begin a.SetIt(False,[1,2,4,8]); a.Log2; //same as: a := Log2(a); b := Log2(a); //same as: b.Log2(a); end; *) function Log2: TMtxVec; overload; (*Calculate the log base 2 for all X elements. Store the results in the calling object. Size and properties of the calling vector are set implicitly to match the X object. *) function Log2(const X: TMtxVec): TMtxVec; overload; (*Calculate the log base 2 for calling object elements [Index]..[Index+Len-1] in-place. An exception is raised if is True and array borders are overrun. *) function Log2(Index, Len: integer): TMtxVec; overload; (*Calculate the log base 2 for X elements [XIndex]..[XIndex+Len-1]. Store the results in the calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if is True and array borders are overrun. *) function Log2(const X: TMtxVec; XIndex, Index, Len: integer): TMtxVec; overload; (*Exponent (e^). Calculate the exponent (e^) for all calling object elements in-place. var a,b: Vector; begin a.SetIt(False,[1,2,4,8]); a.Exp; //same as: a := Exp(a); b := Exp(a); //same as: b.Exp(a); end; *) function Exp: TMtxVec; overload; (*Calculate the exponent (e^) for all X elements. Store the results in the calling object. Size and properties of the calling vector are set implicitly to match the X object. *) function Exp(const X: TMtxVec): TMtxVec; overload; (*Calculate the exponent (e^) for calling object elements [Index]..[Index+Len-1] in-place. An exception is raised if is True and array borders are overrun. *) function Exp(Index, Len: integer): TMtxVec; overload; (*Calculate the exponent (e^) for X elements [XIndex]..[XIndex+Len-1]. Store the results in the calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if is True and array borders are overrun. *) function Exp(const X: TMtxVec; XIndex, Index, Len: integer): TMtxVec; overload; (*Exponent base 2 (2^). Calculate the exponent base 2 (2^) for all calling object elements in-place. var a,b: Vector; begin a.SetIt(False,[1,2,3,4]); // a = [1,2,3,4] a.Exp2; // a = [2,4,8,16] a := Exp2(a); b.Exp2(a); //same as b := Exp2(a); end; *) function Exp2: TMtxVec; overload; (*Calculate the exponent base 2 (2^) for all X elements. Store the results in the calling object. Size and properties of the calling vector are set implicitly to match the X object. *) function Exp2(const X: TMtxVec): TMtxVec; overload; (*Calculate the exponent base 2 (2^) for calling object elements [Index]..[Index+Len-1] in-place. An exception is raised if is True and array borders are overrun. *) function Exp2(Index, Len: integer): TMtxVec; overload; (*Calculate the exponent base 2 (2^) for X elements [XIndex]..[XIndex+Len-1]. Store the results in the calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if is True and array borders are overrun. *) function Exp2(const X: TMtxVec; XIndex, Index, Len: integer): TMtxVec; overload; (*Exponent base 10 (10^). Calculate the exponent base 10 (10^) for all calling object elements in-place. var a,b: Vector; begin a.SetIt(False,[1,2,3,4]); // a = [1,2,3,4] a.Exp10; // a = [10,100,1000,10000] a := Exp10(a); b.Exp10(a); //same as b := Exp10(a); end; *) function Exp10: TMtxVec; overload; (*Calculate the exponent base 10 (10^) for all X elements and store the results in the calling object. Size and properties of the calling vector are set implicitly to match the X object. *) function Exp10(const X: TMtxVec): TMtxVec; overload; (*Calculate the exponent base 10 (10^) for calling object elements [Index]..[Index+Len-1] in-place. An exception is raised if is True and array borders are overrun. *) function Exp10(Index, Len: integer): TMtxVec; overload; (*Calculate the exponent base 10 (10^) for X elements [XIndex]..[XIndex+Len-1]. Store the results in the calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if is True and array borders are overrun. *) function Exp10(const X: TMtxVec; XIndex, Index, Len: integer): TMtxVec; overload; (* Sums items from Src with matching corresponding indexes from Bins and places result in self. The size of self is set to Bins.Max+1 provided that sufficient memory is available. BinsMax with default value of -1 indicates that Bins.Max call is made internally. The routine does not perform additional range checking, if BinsMax is provided explicitely (memory overwrite is possible). *) function GroupSum(const Bins: TMtxVecInt; const Src: TMtxVec; const BinsMax: integer = -1): TVec; overload; (* Sums items from Src with matching corresponding indexes from Bins and places result in self. The size of self is checked to be BinsMax+1. The routine does not initialize the calling vector to 0. The routine does not perform additional range checking, because BinsMax is provided explicitely (memory overwrite is possible). *) function GroupSumIteration(const Bins: TMtxVecInt; const Src: TMtxVec; const BinsMax: integer): TVec; overload; (*Gets the imaginary part of a complex object. Gets the imaginary part of a complex object Vec and stores the real results in the calling object. Size and properties of the calling object are set implicitly to match Vec object. Vec must be true otherwise the exception will be raised. var a,b: Vector; begin a.SetIt(True,[1,2,3,4]); // a= [1+2i, 3+4i] b.ImagPart(a); // b = [2, 4] end; *) function ImagPart(const Vec: TMtxVec): TMtxVec; overload; (*Gets the imaginary part of complex object Vec elements [VecIndex]..[VecIndex+Len-1]. Stores the result in calling object. An exception is raised if the calling object is complex, if Vec is not complex or if array borders are overrun/underrun. *) function ImagPart(const Vec: TMtxVec; VecIndex,Index,Len: integer): TMtxVec; overload; (*Power (integer exponent). Calculate the power ^(Exponent) for all caling object elements using the integer parameter Exponent. For non integer exponents, the and methods can be used. var a,b: Vector; begin a.SetIt(False,[1,2,3,4]); a.IntPower(3); //same as: a := IntPower(a,3); b.IntPower(a,3); //same as: b := IntPower(a,3); end; *) function IntPower(Exponent: Integer): TMtxVec; overload; (*Calculate the power Base^(Exponent) for all Base object elements using the integer Exponent value. Store the results in calling object. Size and properties of calling object are adjusted automatically. *) function IntPower(Base: TMtxVec; Exponent: Integer): TMtxVec; overload; (*Invert elements. Calculates the inverse of all calling object elements in-place without limiting inverse operation. var a,b: Vector; begin a.SetIt(False,[1,2,3,4]); // a = [1, 2, 3, 4] b.Inv(a); // b = [1.0, 0.5, 0.3333, 0.25] b := Inv(a); end; *) function Inv: TMtxVec; overload; (*Calculate the inverse of calling object elements [Index]..[Index+Len-1] in-place. An exception is raised if array borders are overrun/underrun. *) function Inv(Index, Len: integer): TMtxVec; overload; (*Calculate the inverse of all calling object elements in-place. The computation occurs after first limiting the magnitude of each element by the lower bound of Threshold. The limiting operation is performed to avoid division by zero. Since Threshold represents a magnitude, it is always real and must always be positive. For complex versions, the magnitude of the input is limited, but the phase remains unchanged. Zero-valued input is assumed to have zero phase. *) function Inv(Threshold: double): TMtxVec; overload; (*Calculate the inverse of calling object elements [Index]..[Index+Len-1] in-place after limiting the magnitude of each element by the lower bound of Threshold. An exception is raised if array borders are overrun/underrun. *) function Inv(Threshold: double; Index, Len: integer): TMtxVec; overload; (*Calculate the inverse of all X object elements without limiting operating. Store the results in calling object. Size and property of calling object are adjusted automatically. *) function Inv(const X: TMtxVec): TMtxVec; overload; (*Calculate the inverse of X object elements [XIndex]..[XIndex+Len-1] without limiting operating. Store the results in calling object elements [Index]..[Index+Len-1]. An exception is raised if X and calling object property does not match or array borders are overrun/underrun. *) function Inv(const X: TMtxVec; XIndex, Index, Len: integer): TMtxVec; overload; (*Calculate the inverse of all X object elements anmd store the results to calling object elements. Size and property of calling obhect are adjusted automatically. The computation occurs after first limiting the magnitude of each element by the lower bound of Threshold. The limiting operation is performed to avoid division by zero. Since Threshold represents a magnitude, it is always real and must always be positive. For complex versions, the magnitude of the input is limited, but the phase remains unchanged. Zero-valued input is assumed to have zero phase. *) function Inv(const X: TMtxVec; Threshold: double): TMtxVec; overload; (*Calculate the inverse of X object elements [XIndex]..[XIndex+Len-1] after limiting the magnitude of each element by the lower bound of Threshold. Store the results in calling object elements [Index]..[Index+Len-1]. An exception is raised if X and calling object property do not match or array borders are overrun/underrun. *) function Inv(const X: TMtxVec; Threshold: double; XIndex, Index, Len: integer): TMtxVec; overload; (*Converts elements from cartesian to polar coordinate form. Converts all calling object elements from cartesian to polar coordinate form, storing the magnitude (radius) component of corresponding elements in the AmpltVec and the phase (angle) component of corresponding elements in the PhaseVec. If you want to use this method then the calling matrix property must be true. If this is not the case, an exception is raised. Size and properties of AmpltVec and PhaseVec are set automatically. var A,Amplt,Phase: Vector; begin A.SetIt(2,True,[1,0, 2,0 2,0 4,1]); A.CartToPolar(Amplt,Phase); end; *) procedure CartToPolar(AmpltVec, PhaseVec: TMtxVec); overload; (*Convert calling object elements [Index] to [Index+Len-1] from cartesian to polar form. Store the results in AmpltVec (radius values) and PhaseVec(phase values). Size and properties of the calling vector must be set explicitly. An exception is raised if is True and array borders are overrun or underrun. *) procedure CartToPolar(AmpltVec, PhaseVec: TMtxVec; AmpltIndex, PhaseIndex, Index, Len: integer); overload; (*Copy object values. Copy each of Vec elements to the calling object. Size and properties of the calling object are set implicitly to match Vec object. var a,b,c: Vector; begin a.SetIt(True,[1,2,3,4]); // a = [1,2,3,4] b.Copy(a); // b = [1,2,3,4] c.Copy(a,b); //concatenate a and b and store in c = [1,2,3,4,1,2,3,4] end; *) function Copy(const Vec: TMtxVec): TMtxVec; overload; (*Copy object values. Copy each of Src elements to the calling object. Size and properties of the calling object are set implicitly to match Src object. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TVec a,b,c; MtxVec.CreateIt(out a, out b, out c); try { a.SetIt(true,new double[] {1,2,3,4}); // a = [1,2,3,4] i.e 1+2i ; 3+4i b.Copy(a, mvSingle); // convert to single precision } finally { MtxVec.FreeIt(ref a,ref b,ref c); } } } *) function Copy(const Src: TMtxVec; const dstFloatPrecision: TMtxFloatPrecision): TMtxVec; overload; (*Copy Vec elements [VecIndex]..[VecIndex+Len-1] in the calling object elements [Index]..[Index+Len-1]. Size and properties must be set explicitly. An exception is raised if is True and array borders are overrun or underrun. *) function Copy(const Vec: TMtxVec; VecIndex, Index, Len: integer): TMtxVec; overload; (*Copy and convert values from TVecInt. Applies appropriate conversion and copy data from TVecInt. *) function Copy(const Src: TVecInt; const dstFloatPrecision: TMtxFloatPrecision):TMtxVec; overload; (*Copy and convert values from TVecInt. Applies appropriate conversion and copy data from TVecInt. Existing value of FloatPrecision is preserved. *) function Copy(const Src: TVecInt):TMtxVec; overload; (*Copy and convert values from TVecInt at indexes [SrcIndex]...[SrcIndex+Len-1]. Applies appropriate conversion and copy data from TVecInt. The results are stored in calling object elements [Index]...[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if array borders are overrun. *) function Copy(const Src: TVecInt; SrcIndex, Index, Len: integer):TMtxVec; overload; (*Copy and convert values to TVecInt. Applies appropriate conversion and copy data to TVecInt. The value IntPrecision is preserved. *) procedure CopyTo(const Dst: TVecInt; Rounding: TRounding); overload; (*Copy and convert values to TVecInt at indexes [DstIndex]...[DstIndex+Len-1]. Applies appropriate conversion and copy data from TVecInt. The results are stored in calling object elements [Index]...[Index+Len-1]. Size and properties of the destination object must be set explicitly. An exception is raised if array borders are overrun. *) procedure CopyTo(const Dst: TVecInt; Rounding: TRounding; DstIndex, Index, Len: integer); overload; (*Copy and convert values to specified dstFloatPrecision. Dst will be sized to hold all calling object data in specified dstFloatPrecision. The single/double and Complex/Not Complex conversion cant be handled concurrently. *) procedure CopyTo(const Dst: TMtxVec; const dstFloatPrecision: TMtxFloatPrecision); overload; (*Copy and convert values to Dst.FloatPrecision at indexes [DstIndex]...[DstIndex+Len-1]. Applies appropriate conversion and copy data from the calling object. The results are stored in Dst object elements [Index]...[Index+Len-1]. Size and properties of the destination object must be set explicitly. An exception is raised if array borders are overrun. *) procedure CopyTo(const Dst: TMtxVec; const DstIndex, Index: integer; Len: integer); overload; (*Copy and if needed convert values to Dst. Existing value of Dst.FloatPrecision is preserved. *) procedure CopyTo(const Dst: TMtxVec); overload; (*Sets vector size to zero. Calling Clear sets property to 0 and property to false. *) procedure Clear; (*Saves the current value of ConditionCheck property and sets it to false. You can restore back to the original setting by calling method. *) procedure CondDisable; (*Sets the ConditionCheck property to whatever it was before the CondDisable was used. Sets the property to whatever it was before the was used. *) procedure CondEnable; (*Conjugate. Conjugate all calling object elements in-place. var c: Vector; begin c.SetIt(True,[1,2,3,4]); // c = [1+2i, 3+4i] c.Conj; // c = [1-2i, 3-4i] end; *) function Conj: TMtxVec; overload; (*Conjugate calling object elements [Index]..[Index+Len-1] in-place. An exception is raised if is true and array borders are overrun. *) function Conj(Index,Len: integer): TMtxVec; overload; (*Conjugate each of Vec elements and store the results in the calling object. The Size and properties of the calling object are set implicitly to match Vec vector. *) function Conj(const Vec: TMtxVec): TMtxVec; overload; (*Conjugate Vec elements Vec[VecIndex]..Vec[VecIndex+Len-1]. Store them in the calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if is true and array borders are overrun. *) function Conj(const Vec: TMtxVec; VecIndex, Index, Len: integer): TMtxVec; overload; (*Copies values from an array. Copies values from a complex array. The size and properties of the calling object are set implicitly. *) function CopyFromArray(const Src: TCplxArray): TMtxVec; overload; (*Copies values from the Src array [SrcIndex]..[SrcIndex+Len-1] to the calling object values [Index]..[Index+len-1]. The size of the calling object is not changed. If the array border are overrun an exception will be raised. *) function CopyFromArray(const Src: TCplxArray; SrcIndex,Index,Len: integer): TMtxVec; overload; (*Copies values from a real Src array. The size and properties of the calling object are set implicitely. *) function CopyFromArray(const Src: TDoubleArray): TMtxVec; overload; (*Copies values from the double precision floating point Src array [SrcIndex]..[SrcIndex+Len-1] to the calling object values [Index]..[Index+len-1]. The size of the calling object is not changed. If the array border are overrun an exception will be raised. *) function CopyFromArray(const Src: TDoubleArray; SrcIndex,Index,Len: integer): TMtxVec; overload; (*Copies values from a real single precision floating point Src array. The size and properties of the calling object are set implicitely. *) function CopyFromArray(const Src: TSingleArray): TMtxVec; overload; (*Copies values from the single precision floating point Src array [SrcIndex]..[SrcIndex+Len-1] to the calling object values [Index]..[Index+len-1]. The size of the calling object is not changed. If the array border are overrun an exception will be raised. *) function CopyFromArray(const Src: TSingleArray; SrcIndex,Index,Len: integer): TMtxVec; overload; (*Copies values from an integer type Src array. The size and properties of the calling object are set implicitely. *) function CopyFromArray(const Src: TIntegerArray): TMtxVec; overload; (*Copies values from a 4 byte signed integer type Src array [SrcIndex]..[SrcIndex+Len-1] to the calling object values [Index]..[Index+len-1]. The size of the calling object is not changed. If the array border are overrun an exception will be raised. *) function CopyFromArray(const Src: TIntegerArray; SrcIndex,Index,Len: integer): TMtxVec; overload; (*Copies values from an 2 byte signed integer type Src array. The size and properties of the calling object are set implicitely. *) function CopyFromArray(const Src: TSmallIntArray): TMtxVec; overload; (*Copies values from a 2 byte signed integer type Src array [SrcIndex]..[SrcIndex+Len-1] to the calling object values [Index]..[Index+len-1]. The size of the calling object is not changed. If the array border are overrun an exception will be raised. *) function CopyFromArray(const Src: TSmallIntArray; SrcIndex,Index,Len: integer): TMtxVec; overload; (*Copies values from a 1 byte unsigned integer type Src array. The size and properties of the calling object are set implicitely. *) function CopyFromArray(const Src: Math387.TByteArray): TMtxVec; overload; (*Copies values from a 1 byte unsigned integer type Src array [SrcIndex]..[SrcIndex+Len-1] to the calling object values [Index]..[Index+len-1]. The size of the calling object is not changed. If the array border are overrun an exception will be raised. *) function CopyFromArray(const Src: Math387.TByteArray; SrcIndex,Index,Len: integer): TMtxVec; overload; (*Copy values to an array. Copy complex values to Dst array. The size of the array is set automatically. If the calling object is not complex an exception will be raised. *) function CopyToArray(var Dst: TCplxArray): TMtxVec; overload; (*Copy complex values from the calling object [Index]..[Index+len-1] to the Dst array at positions [DstIndex]...[DstIndex+Len-1]. The size of the Dst array is not changed. *) function CopyToArray(var Dst: TCplxArray; DstIndex, Index,Len: integer): TMtxVec; overload; (*Copy values to Dst array. The size of the array is set automatically. If the calling object is complex, the size of the Dst array will be equal to 2*. If the calling object is not complex an exception will be raised. *) function CopyToArray(var Dst: TDoubleArray): TMtxVec; overload; (*Copy real or complex values from the calling object [Index]..[Index+len-1] to the Dst array at positions [DstIndex]...[DstIndex+Len-1]. The size of the Dst array is not changed. If the calling object is complex, the Index and Len parameters define the number of complex elements. *) function CopyToArray(var Dst: TDoubleArray; DstIndex, Index,Len: integer): TMtxVec; overload; (*Copies the calling object data to an array of single precision floating point data. Note Any values exceeding the range are clipped. *) function CopyToArray(var Dst: TSingleArray): TMtxVec; overload; function CopyToArray(var Dst: TSingleArray; DstIndex, Index,Len: integer): TMtxVec; overload; (*Copies values from the calling object to the Dst array and converts floating point data to integer numbers. The rounding method used is specified with the Rounding parameter. *) function CopyToArray(var Dst: TIntegerArray; Rounding: TRounding): TMtxVec; overload; (*Copy real or complex values from the calling object [Index]..[Index+len-1] to the Dst integer array at positions [DstIndex]...[DstIndex+Len-1]. The size of the Dst array is not changed. If the calling object is complex, the Index and Len parameters define the number of complex elements. The method converts floating point values to integer. Values exceeding the range of the integer type are clipped. *) function CopyToArray(var Dst: TIntegerArray; Rounding: TRounding; DstIndex, Index,Len: integer): TMtxVec; overload; (*Copies values from the calling object to the Dst array and converts floating point data to 2 byte signed integer numbers. The rounding method used is specified with the Rounding parameter. *) function CopyToArray(var Dst: TSmallIntArray; Rounding: TRounding): TMtxVec; overload; (*Copy real or complex values from the calling object [Index]..[Index+len-1] to the Dst integer array at positions [DstIndex]...[DstIndex+Len-1]. The size of the Dst array is not changed. If the calling object is complex, the Index and Len parameters define the number of complex elements. The method converts floating point values to integers. Values exceeding the range of a 2 byte signed integer type are clipped. *) function CopyToArray(var Dst: TSmallIntArray; Rounding: TRounding; DstIndex, Index,Len: integer): TMtxVec; overload; (*Copies values from the calling object to the Dst array. Converts floating point data to 1 byte unsigned integer numbers. The rounding method used is specified with the Rounding parameter. *) function CopyToArray(var Dst: Math387.TByteArray; Rounding: TRounding): TMtxVec; overload; (*Copy real or complex values from the calling object [Index]..[Index+len-1] to the Dst integer array at positions [DstIndex]...[DstIndex+Len-1]. The size of the Dst array is not changed. If the calling object is complex, the Index and Len parameters define the number of complex elements. The method converts floating point values to integers. Values exceeding the range of 1 byte unsigned integer type are clipped. *) function CopyToArray(var Dst: Math387.TByteArray; Rounding: TRounding; DstIndex,Index,Len: integer): TMtxVec; overload; (*Split complex calling object in real and imaginary part. Split calling object into real and imaginary components. Store all real components in ReVec and all imaginary components in ImVec. Size and properties of ReVec and ImVec are set implicitly to match with the calling vector. An execption is raised if calling object is not complex. var a,b,c: Vector; begin a.SetIt(True,[1,-2,3,4]); a.CplxToReal(b,c); end; *) procedure CplxToReal(ReVec, ImVec: TMtxVec); overload; (*Split calling object elements [Index]..[Index+Len-1] into real and imaginary components. Store real components in ReVec elements [ReIndex]..[ReIndex+Len-1] and imaginary components in ImVec elements [ImIndex]..[ImIndex+Len-1]. Size and properties must be set explicitly. An exception is raised if is true and array borders are overrun or underrun. *) procedure CplxToReal(ReVec, ImVec: TMtxVec; ReIndex, ImIndex, Index, Len: integer); overload; (*Extends a real object to a complex object. Extend the calling object to complex vector. After the calling of ExtendToComplex the imaginary part becomes the same as real part if Zeros is false. If Zeros is true the imaginary part is set to zero. The use of the in-place version of the method is discouraged because it requires 3*N copy operations, while the not-in-place version requires only 2*N copy operations. var a,b: Vector; begin a.SetIt(False,[1,2,3,4]); b.ExtendToComplex(a,True); end; *) function ExtendToComplex(Zeros: boolean = True): TMtxVec; overload; (*Extend Vec object to complex calling object. If Zeros is true then the calling vector imaginary part is set to zero, otherwise the calling object imaginary part is the same as calling object real part. *) function ExtendToComplex(const Src: TMtxVec; Zeros: Boolean): TMtxVec; overload; (*Converts the source to complex. Converts the source to complex by setting the imaginary part to either zero (zeros = True) or same as real (zeros = false). Does not set size of the calling vector. If there is not sufficient space available to store the result an exception will be raised. *) function ExtendToComplex(const Src: TMtxVec; Zeros: Boolean; SrcIndex,DstIndex, Len: integer): TMtxVec; overload; (*Sets angle in [-2Pi,2Pi]. ThetaRad within [-2Pi,2Pi] interval. Calling this function prior to passing the value to trigonometric functions can significantly improve numerical accuracy. For arguments larger than 10000, the computation of sine/cosine is speeded up by about 10x for SSE2/SSE3. The performance gains for classic FPU math are also significant. The cost of this function call is approx 30% of the cost of the sine function. It is important to mention that the sine/cosine appear within many other functions especially complex versions of trigonometric functions. FixAngle method is never used implicitely within TMtxVec methods. To achieve maximum performance make sure that the arguments passed to complex trigonometric functions are "small" or scaled down. Note The vector must be real. *) function FixAngle: TMtxVec; overload; (*FixAngle for calling object complex elements [Index]..[Index+Len-1] in-place. An exception is raised if calling object property is True or if array borders are overrun/underrun. *) function FixAngle(Index,Len: integer): TMtxVec; overload; (*Sets angle in [-2Pi,2Pi] for all Src elements. Store the results in the calling object. Size and properties of the calling vector are set implicitly to match the Src object. *) function FixAngle(const Src: TMtxVec): TMtxVec; overload; (*Sets angle in [-2Pi,2Pi] for Src elements [SrcIndex]..[SrcIndex+Len-1]. Store the results in the calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if is True and array borders are overrun. *) function FixAngle(const Src: TMtxVec; SrcIndex, Index,Len: integer): TMtxVec; overload; (*Rounds towards negative infinity. Rounds all calling object elements towards negative infinity in-place. Floor(-2.8) = -3 Floor(2.8) = 2 Floor(-1.0) = -1 *) function Floor: TMtxVec; overload; (*Rounds calling object elements [Index]..[Index+Len-1] towards negative infinity in-place. An exception is raised if array borders are overrun. *) function Floor(Index,Len: integer): TMtxVec; overload; (*Rounds all Src object elements towards negative infinity. Stores the result in the calling object. Size and properties of the calling object are adjusted automatically. *) function Floor(const Src: TMtxVec): TMtxVec; overload; (*Rounds Src object elements [SrcIndex]..[SrcIndex+Len-1] towards negative infinity- Store the result in the calling object elements [Index]..[Index+Len-1] Size and properties of the calling object must be set explicitly. An exception is raised if array borders are overrun. *) function Floor(const Src: TMtxVec; SrcIndex, Index,Len: integer): TMtxVec; overload; (*A complex exponential e^(j*W). Calculate the calling object complex exponential in-place. An exception is raised if calling object is complex. If object is complex, you should use the method instead. var a: Vector; begin a.SetIt(False,[1,2,3,4]); a.Expj; // a = [e^i, e^2i, e^3i, e^4i] end; *) function Expj: TMtxVec; overload; (*Calculate the e^(j*W), a complex exponential. Omega must be a real object. If omega is complex, then use the method. *) function Expj(Omega: TMtxVec): TMtxVec; overload; (*Calculate the complex exponential for Omega elements [OmegaIndex]..[OmegaIndex+Len-1]. Store the results in calling object elemets [Index]..[Index+Len-1]. Size and properties of the calling vector must be set explicitly. An exception is raised if is True and array borders are overrun or underrun. *) function Expj(Omega: TMtxVec; OmegaIndex, Index, Len: integer): TMtxVec; overload; (*Finds a match for X in object values. Compare real value X with all calling object elements and return the Index of last matched element. If no matching elements are found, the result is -1. Note This method also supports the NAN and INF search. var a: Vector; ind: Integer; begin a.SetIt(False,[2,5,1,6]); ind := a.Find(1.0); // returns 2 (the arrays are zero based) end; *) function Find(const X: double): integer; overload; (*Compare complex value X with all calling object elements. the Index of last matched element. If no matching elements are found, the result is -1. An exception is raised if calling object property is false. *) function Find(const X: TCplx): integer; overload; (*Fractional part of values. Calculates the fractional part for all object values in-place. var a: Vector; ind: Integer; begin a.SetIt(False,[1,5.5,-1.6,6]); // a = [1, 5.5, -1.6, 6] a.Frac; // a = [0, 0.5, -0.6, 0] end; *) function Frac: TMtxVec; overload; (*Calculates the fractional part for all X object values. Stores the result in calling object. Size and properties of calling object are adjusted automatically. *) function Frac(const X: TMtxVec): TMtxVec; overload; (*Calculates the fractional part for calling object elements [Index]..[Index+Len-1] in-place. An exception is raised if array borders are overrun or underrun. *) function Frac(Index,Len: integer): TMtxVec; overload; (*Calculates the fractional part for X object elements [XIndex]..[XIndex+Len-1]. Stores the result in calling object elements [Index]..[Index+Len-1]. An exception is raised if array borders are overrun or underrun. *) function Frac(const X: TMtxVec; XIndex, Index, Len: integer): TMtxVec; overload; (*First element in object Values array. first real element in object Values array. *) property First: double read get_First; (*First element in object CValues array. first complex element in object CValues array. An exception is raised if calling object property is false. *) property Firstc: TCplx read get_Firstc; (*Flips the real and imaginary part of complex numbers. Flips the real and imaginary part of complex numbers for all calling object elements in-place. *) function Flip: TMtxVec; overload; (*Flips the real and imaginary part of complex numbers for calling object elements [Index]..[Index+Len-1] in-place. An exception is raised if array borders are overrun or underrun. *) function Flip(Index, Len: integer): TMtxVec; overload; (*Flips the real and imaginary part of complex numbers for all X object elements. Store the results in the calling object. Size and properties of calling object are adjusted automatically. *) function Flip(const X: TMtxVec): TMtxVec; overload; (*Flips the real and imaginary part of complex numbers for X object elements [XIndex]..[XIndex+Len-1]. Store the results in the calling object elements [Index]..[Index+Len-1] An exception is raised if array borders are overrun or underrun. *) function Flip(const X: TMtxVec; XIndex, Index, Len: integer): TMtxVec; overload; (*Flips the real and imaginary part of complex numbers and conjugates the complex numbers. Performs the following operation: a + bi ==> b - ai Method flips the real and imaginary part and conjugates calling object complex elements in-place. *) function FlipConj: TMtxVec; overload; (*Flip calling object complex elements [Index]..[Index+Len-1] in-place. An exception is raised if calling object property is false or if array borders are overrun/underrun. *) function FlipConj(Index, Len: integer): TMtxVec; overload; (*Flip all X object complex elements and store the results in calling object. Size and property of calling object are adjusted automatically. *) function FlipConj(const X: TMtxVec): TMtxVec; overload; (*Flip X object complex elements [XIndex]..[XIndex+Len-1]. Store the results in calling object elements [Index]..[Index+Len-1]. An exception is raised if calling object property is false or if array borders are overrun/underrun. *) function FlipConj(const X: TMtxVec; XIndex, Index, Len: integer): TMtxVec; overload; (*The inverse of square root 1/(v)^1/2. Calculate the inverse square root (1/(element)^(1/2)) of all calling object elements in-place. v.SetIt(false,[1,16]); v.InvSqrt; // returns [1,0.25] *) function InvSqrt: TMtxVec; overload; (*Calculate the inverse of square root for calling object elements [Index]..[Index+Len-1] in-place. An exception is raised if is True and array borders are overrun. *) function InvSqrt(Index, Len: integer): TMtxVec; overload; (*Calculate the inverse of square root for all X elements. Store the results in the calling object. Size and properties of the calling vector are set implicitly to match the X object. *) function InvSqrt(const X: TMtxVec): TMtxVec; overload; (*Calculate the inverse of square root for X elements [XIndex]..[XIndex+Len-1]. Store the results in the calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if is True and array borders are overrun. *) function InvSqrt(const X: TMtxVec; XIndex, Index, Len: integer): TMtxVec; overload; (*The inverse of cube root 1/(v)^1/3. Calculate the inverse cube root (1/(element)^(1/3)) of all calling object elements in-place. v.SetIt(false,[1,8]); v.InvCbrt; // returns [1,0.5] *) function InvCbrt: TMtxVec; overload; (*Calculate the inverse of cube root for calling object elements [Index]..[Index+Len-1] in-place. An exception is raised if is True and array borders are overrun. *) function InvCbrt(Index, Len: integer): TMtxVec; overload; (*Calculate the inverse of cube root for all X elements. Store the results in the calling object. Size and properties of the calling vector are set implicitly to match the X object. *) function InvCbrt(const X: TMtxVec): TMtxVec; overload; (*Calculate the inverse of cube root for X elements [XIndex]..[XIndex+Len-1]. Store the results in the calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if is True and array borders are overrun. *) function InvCbrt(const X: TMtxVec; XIndex, Index, Len: integer): TMtxVec; overload; (*The Reminder after division X/Y. Calculates reminder after division according to formula: X[i]-y[i]*Trunc(X[i]/y[i]). The results will be saved to the calling vector. X and Y must be a real and have the same length. Size and properties of the calling vector are set implicitly to match the X object. var a,b,c: Vector; begin a.SetIt(false,[0,1,10,-1,-10]); // a = [0, 1, 10, -1, -10]; b.SetIt(false,[0,1,PI,-1,-PI]); // b = [0, 1, PI, -1, -PI]; c.Rem(a,b); // c = [0, 0, 0.5752, 0, -0.5752] end; *) function Rem(const X, Y: TMtxVec): TMtxVec; overload; (*Calculates reminder after division X/Y according to formula: z[i] = X[xi]-y[yi]*Trunc(X[xi]/y[yi]), where i in [Index..Index+Len], xi in [XIndex..XIndex+Len], yi in [YIndex..YIndex+Len]. The results will be saved to the calling vector. X must be a real. An exception will be raised if is True and array borders are overrun. *) function Rem(const X, Y: TMtxVec; XIndex, YIndex, Index, Len: integer): TMtxVec; overload; (*Calculates reminder after division X/Y according to formula X[i]-y*Trunc(X[i]/y). X must be a real. The results will be saved to the calling vector. Size and properties of the calling vector are set implicitly to match the X object. *) function Rem(const X: TMtxVec; Y: double): TMtxVec; overload; (*Calculates reminder after division X/Y according to formula: z[i] = X[xi]-y*Trunc(X[xi]/y), where i in [Index..Index+Len], xi in [XIndex..XIndex+Len]. X must be a real. The results will be saved to the calling vector. An exception will be raised if is True and array borders are overrun. *) function Rem(const X: TMtxVec; Y: double; XIndex, Index, Len: integer): TMtxVec; overload; (*Magnitude. Calculate the magnitude for all calling object elements in-place. This method has the same function as the method. var a: Vector; begin a.SetIt(false,[1,-2,3,4]); // a = [1,-2, 3,4] a.Mag; // a = [1, 2, 3,4] end; *) function Mag: TMtxVec; overload; (*Calculate the magnitude for calling object elements [Index]..[Index+Len-1] in-place. An exception is raised if is True and array borders are overrun. *) function Mag(Index, Len: integer): TMtxVec; overload; (*Calculate the magnitude for all X elements. Store the results in the calling object elements. Size and and properties of the calling vector are set implicitly to match Vec vector. *) function Mag(const X: TMtxVec): TMtxVec; overload; (*Calculate the magnitude for X elements [XIndex]..[XIndex+Len-1]. Store the results in the calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if is True and array borders are overrun. *) function Mag(const X: TMtxVec; XIndex, Index, Len: integer): TMtxVec; overload; (*Multiply object elements with Value. Multiply all calling object elements with Value in-place. This method is the same as the method overloads multiplying with vector elements with a scalar. var v: Vector; begin v.SetIt(false,[2,3,5]); // v = [2,3,5] v.Scale(3); // v = [6,9,15] end; *) function Scale(Factor: double): TMtxVec; overload; (*Multipy calling object elements [Index]..[Index+Len-1] with Value in-place. An exception is raised if array borders are overrun or underrun. *) function Scale(Factor: double; Index, Len: integer): TMtxVec; overload; (*Multiply all calling object elements with a complex Value in-place.*) function Scale(Factor: TCplx): TMtxVec; overload; (*Multipy calling object elements [Index]..[Index+Len-1] with complex Value in-place. An exception is raised if array borders are overrun or underrun. *) function Scale(Factor: TCplx; Index, Len: integer): TMtxVec; overload; (*Scatter object elements. Scatter the elements of the Src and store them in the calling object according to the IndexType, Increment and Offset parameters. The Indexes vector is used only if IndexType is either indVector or indMask. If IndexType is indVector, the values from the Indexes object denote the Index positions in the calling object to which the values should be copied from the Src. The Indexes vector must have the indexes stored in the IValues array. The IValues integer arrays points the same memory as Values array. The Increment and Offset parameters are used only if TIndexType is indIncrement. They define the target offset and a fixed step (increment) between calling vector elements. If IndexType is indMaks the Indexes object must have the same size as the Src object. The routine will copy only those elements from the Src to the calling object, for which there is a 1 at the coresponding Index in the Indexes object.The elements in the calling object are stored consecutively. See the method to see how to perform gathering. The performance of the CPU heavily depends on the assumption that elements are stored at consecutive memory locations. If it is neccessary to apply a set of operations only to elements at specific indexes, performance-wise it can prove to be very helpfull, if the elements are gathered first. *) function Scatter(const Src: TMtxVec; const Indexes: TVecInt = nil; IndexType: TIndexType = indVector; Increment: integer = 1; Offset: integer = 0): TMtxVec; overload; (*Scatter object elements. Scatter the elements of the Src and store them in the calling object at indices: Increment*i + Offset *) function ScatterByIncr(const Src: TMtxVec; Increment: integer = 1; Offset: integer = 0): TMtxVec; overload; (*Scatter object elements. Scatter the elements of the Src and store them in the calling object at indices stored in the Indexes parameter. *) function ScatterByIndexes(const Src: TMtxVec; const Indexes: TVecInt): TMtxVec; overload; (*Scatter object elements. Scatter the elements of the Src and store them in the calling object at indices set to 1 in the Mask parameter. *) function ScatterByMask(const Src: TMtxVec; const Mask: TVecInt; allow_resizing: boolean = False): TMtxVec; overload; (*Copies those values from MaskVec, at which aMask is different from 0.*) function Mask(const MaskVec: TMtxVec; const aMask: TMtxVecInt): TMtxVec; overload; (*Copies those values from MaskVecNot, at which aMask is equal to 0.*) function MaskNot(const MaskVecNot: TMtxVec; const aMask: TMtxVecInt): TMtxVec; overload; (*Assigns Value at indexes of the calling object, at which aMask is different from 0.*) function Mask(const Value: double; const aMask: TMtxVecInt): TMtxVec; overload; (*Assigns Value at indexes of the calling object, at which aMask is equal to 0.*) function MaskNot(const Value: double; const aMask: TMtxVecInt): TMtxVec; overload; (*Assigns Value at indexes of the calling object, at which aMask is different from 0.*) function Mask(const Value: TCplx; const aMask: TMtxVecInt): TMtxVec; overload; (*Assigns Value at indexes of the calling object, at which aMask is equal to 0.*) function MaskNot(const Value: TCplx; const aMask: TMtxVecInt): TMtxVec; overload; (*Sets object values. Set object values. Method call does not change object's size or property, but it does check for array overrun. The elements of A array are copied to the calling object elements, starting at Index. If the calling object is complex, then real parts of complex numbers are on even (0,2,4..) and imaginary parts on odd indexes.(1,3,5,..). *) function SetIt(Index: integer; const A: array of double): TMtxVec; overload; (*The elements of A array, starting at AIndex, are copied to the calling object elements, starting at Index. If the calling object is complex, then real parts of complex numbers in the A array are on even (0,2,4..) and imaginary parts on odd indexes.(1,3,5,..). *) function SetIt(Index, AIndex, Len: integer; const A: array of double): TMtxVec; overload; (*Sets object values (single). The single elements of A array are copied to the calling object elements [Index]..[Index+Length(A)-1]. An exception is raised if calling object array borders are overrun/underrun. Note Use this method for integer array only. *) function SetSingle(Index: integer; const A: array of single): TMtxVec; overload; function SetSingle(Index: integer; aIndex, Len: integer; const A: array of single): TMtxVec; overload; (*Sets object values (double). The double elements of A array are copied to the calling object elements [Index]..[Index+Length(A)-1]. An exception is raised if calling object array borders are overrun/underrun. Note Use this method for integer array only. *) function SetDouble(Index: integer; const A: array of double): TMtxVec; overload; function SetDouble(Index: integer; aIndex, Len: integer; const A: array of double): TMtxVec; overload; (*Sets object values (integer). The integer elements of A array are copied to the calling object elements [Index]..[Index+Length(A)-1]. An exception is raised if calling object array borders are overrun/underrun. Note Use this method for integer array only. *) function SetInteger(Index: integer; const A: array of Integer): TMtxVec; overload; function SetInteger(Index: integer; aIndex, Len: integer; const A: array of Integer): TMtxVec; overload; (*Square. Calculate the square of all caling object elements in-place. var a: Vector; begin a.SetIt(True,[1,2,3,4]); a.Sqr; // a=[1,4,9,16] end; *) function Sqr: TMtxVec; overload; (*Calculate the square of calling object elements [Index]...[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function Sqr(Index, Len: integer): TMtxVec; overload; (*Calculate the square of all X object elements and store the results in the calling object. Size and properties of calling object are adjusted automatically. *) function Sqr(const X: TMtxVec): TMtxVec; overload; (*Calculate the square of X object elements [XIndex]..[XIndex+Len-1]. The results are stored in calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object are not changed. An exception is raised if array borders are overrun. *) function Sqr(const X: TMtxVec; XIndex, Index, Len: integer): TMtxVec; overload; (*Square root. Calculate the square root of all caling object elements in-place. var a: Vector; begin a.SetIt(False,[1,4,9,16]); a.Sqrt; // a= [1, 2, 3, 4] end; *) function Sqrt: TMtxVec; overload; (*Calculate the square root of calling object elements [Index]...[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function Sqrt(Index, Len: integer): TMtxVec; overload; (*Calculate the square root of all X object elements. Store the results in the calling object. Size and properties of the calling object are adjusted automatically. *) function Sqrt(const X: TMtxVec): TMtxVec; overload; (*Calculate the square root of X object elements [XIndex]..[XIndex+Len-1]. The results are stored in calling object elements [Index]..[Index+Len-1]. Size and properties of calling object are not changed. An exception is raised if array borders are overrun. *) function Sqrt(const X: TMtxVec; XIndex, Index, Len: integer): TMtxVec; overload; (*Last complex element in object CValues array. last complex element in object CValues array. *) property Lastc: TCplx read get_Lastc; (*Last element in object Values array. last real element in object Values array. *) property Last: double read get_Last; (*Log base N. Calculate the log base N for all calling object elements in-place. var a: Vector; begin a.SetIt(False,[1,2,3,4]); // a = [1,2,3,4] a.LogN(10.0); // log base 10, the slow way a = [Log10(1), Log10(2),...] end; *) function LogN(N: double): TMtxVec; overload; (*Calculate the log base N of calling object elements [Index]..[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function LogN(N: double; Index, Len: integer):TMtxVec; overload; (*Calculate the log base N of all X object elements. Store the results in calling object. Size and properties of the calling object are adjusted automatically. *) function LogN(N: double; X: TMtxVec): TMtxVec; overload; (*Calculate the log base N of X object elements [XIndex]..[XIndex+Len-1]. The results are stored in calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object are not changed. An exception is raised if array borders are overrun. *) function LogN(N: double; X: TMtxVec; XIndex, Index, Len: integer): TMtxVec; overload; (*Multiply object elements with Value. Multiply all calling object elements with Value in-place. var v: TVec; begin v:= TVec.Create; try v.SetIt(false,[2,3,5]); // v = [2,3,5] v.Mul(3); // v = [6,9,15] finally v.Free; end; end; *) function Mul(Value: double): TMtxVec; overload; (*Multiply all calling object elements with complex Value in-place.*) function Mul(Value: TCplx): TMtxVec; overload; (*Multipy calling object elements [Index]..[Index+Len-1] with Value in-place. An exception is raised if array borders are overrun or underrun. *) function Mul(Value: double; Index, Len: integer): TMtxVec; overload; (*Multipy calling object elements [Index]..[Index+Len-1] with complex Value in-place. An exception is raised if array borders are overrun or underrun. *) function Mul(Value: TCplx; Index, Len: integer): TMtxVec; overload; (*Multiply each element of Vec with Value. Store the result in the calling object. Size and properties of the calling object are adjusted automatically. *) function Mul(const Vec: TMtxVec; Value: double): TMtxVec; overload; (*Multiply each element of Vec with complex Value. Store the result in the calling object. Size of the calling object is set automatically. property of the calling object is set to True. *) function Mul(const Vec: TMtxVec; Value: TCplx): TMtxVec; overload; (*Multiply Vec elements [VecIndex]..[VecIndex+Len-1] with Value. Store the result in calling object elements [Index]..[Index+Len-1]. Size of the calling object is not changed. An exception is raised if array borders are overrun or underrun. propertiy of the calling object is set implicitly. *) function Mul(const Vec: TMtxVec; Value: double; VecIndex, Index, Len: integer): TMtxVec; overload; (*Multiply Vec elements [VecIndex]..[VecIndex+Len-1] with complex Value. Store the result in calling object elements [Index]..[Index+Len-1]. Size of the calling object is not changed. An exception is raised if array borders are overrun or underrun. propertiy of the calling object is set to True. *) function Mul(const Vec: TMtxVec; Value: TCplx; VecIndex, Index, Len: integer): TMtxVec; overload; (*Multiply elements by imaginary unit I. Multiply calling vector elements with "I". *) function MulI: TMtxVec; overload; (*Multiply calling object elements [Index]..[Index+Len-1] with I in-place.*) function MulI(Index: integer; Len: integer): TMtxVec; overload; (*Multiply X elements with I. Store the result in the calling object. *) function MulI(const X: TMtxVec): TMtxVec; overload; (*Multipy X elements [XIndex]..[XIndex+Len-1] with I. Store the result in the calling object at locations [Index]..[Index+Len-1]. *) function MulI(const X: TMtxVec; XIndex: integer; Index: integer; Len: integer): TMtxVec; overload; (*Normalize data. Normalizes values in the calling object by subtracting a constant Offset from Elements and dividing the result by constant Factor: The results are stored in calling object. Use this method if you want to do a multiply and add (scale and offset) operations in a single method call. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TVec a; MtxVec.CreateIt(out a); try { a.SetIt(false,new double[] {1,2,3,4}); // a = [1,2,3,4] a.Normalize(2,3); } finally { MtxVec.FreeIt(ref a); } } } *) function Normalize(const SubOffset, DivFactor: double): TMtxVec; overload; (*Normalize by subtracting a complex constant SubOffset from Vec elements and dividing the result by complex constant DivFactor. Size and property of calling object are adjusted automatically. An exception is raised, if object is complex. *) function Normalize(const SubOffset, DivFactor: TCplx): TMtxVec; overload; (*Normalize objects complex values [Index]..[Index+Len-1] by subtracting a complex constant SubOffset from Vec elements and dividing the result by complex constant DivFactor. An exception is raised, if object is not complex or array borders are overrun/underrun. *) function Normalize(const SubOffset, DivFactor: TCplx; Index,Len: integer): TMtxVec; overload; (*Normalize object values [Index]..[Index+Len-1] by subtracting a real constant SubOffset from Vec elements and dividing the result by complex constant DivFactor. Store the results in calling vector values [Index]..[Index+Len-1]. An exception is raised, if Vec or calling object is complex or array borders are overrun/underrun. *) function Normalize(const SubOffset, DivFactor: double; Index,Len: integer): TMtxVec; overload; (*Normalize object by subtracting a complex constant SubOffset from elements and dividing the result by real constant DivFactor. An exception is raised, if object is not complex. *) function Normalize(const SubOffset: TCplx; const DivFactor: double): TMtxVec; overload; (*Normalize objects complex values [Index]..[Index+Len-1] by subtracting a complex constant SubOffset from elements and dividing the result by real constant DivFactor. Store the results in calling vector complex values [Index]..[Index+Len-1]. An exception is raised, if the calling object is not complex or array borders are overrun/underrun. *) function Normalize(const SubOffset: TCplx; const DivFactor: double; Index,Len: integer): TMtxVec; overload; (*Normalize object. Normalizes Vec object by subtracting a constant Offset from Vec elements and dividing the result by constant Factor: The results are stored in calling object. Use this method if you want to do a multiply and add (scale and offset) operations in a single method call. var a,b: Vector; begin a.SetIt(False,[1,2,3,4]); b.Normalize(a,2,3); end; *) function Normalize(const Vec: TMtxVec; SubOffset, DivFactor: double): TMtxVec; overload; (*Normalize Vec object by subtracting a complex constant SubOffset from Vec elements and dividing the result by complex constant DivFactor. Size and property of calling object are adjusted automatically. An exception is raised if Vec is complex. *) function Normalize(const Vec: TMtxVec; SubOffset, DivFactor: TCplx): TMtxVec; overload; (*Normalize Vec object complex values [VecIndex]..[VecIndex+Len-1] by subtracting a complex constant SubOffset from Vec elements and dividing the result by complex constant DivFactor. Store the results in calling vector complex values [Index]..[Index+Len-1]. An exception is raised if Vec or calling object is not complex or array borders are overrun/underrun. *) function Normalize(const Vec: TMtxVec; SubOffset, DivFactor: TCplx; VecIndex,Index,Len: integer): TMtxVec; overload; (*Normalize Vec object values [VecIndex]..[VecIndex+Len-1] by subtracting a real constant SubOffset from Vec elements and dividing the result by complex constant DivFactor. Store the results in calling vector values [Index]..[Index+Len-1]. An exception is raised if Vec or calling object is complex or array borders are overrun/underrun. *) function Normalize(const Vec: TMtxVec; SubOffset, DivFactor: double; VecIndex,Index,Len: integer): TMtxVec; overload; (*Normalize Vec object by subtracting a complex constant SubOffset from Vec elements and dividing the result by real constant DivFactor. Size and property of calling object are adjusted automatically. An exception is raised if Vec is complex. *) function Normalize(const Vec: TMtxVec; SubOffset: TCplx; DivFactor: double): TMtxVec; overload; (*Normalize Vec object complex values [VecIndex]..[VecIndex+Len-1] by subtracting a complex constant SubOffset from Vec elements and dividing the result by real constant DivFactor. Store the results in calling vector complex values [Index]..[Index+Len-1]. An exception is raised if Vec or calling object is not complex or array borders are overrun/underrun. *) function Normalize(const Vec: TMtxVec; SubOffset: TCplx; DivFactor: double; VecIndex,Index,Len: integer): TMtxVec; overload; (*Converts the polar magnitude/phase pairs to cartesian pairs. Convert all AmpltVec and PhaseVec elements (combined) from polar to cartesian form. If AmpltVec and PhaseVec size is not the same , an exeption is raised. The results are stored as complex numbers (X=Re, y=Im) in the calling object. Size and properties of the calling object are set implicitly to match AmpltVec and PhaseVec objects. var a,b,c: Vector; begin a.SetIt(false,[1,2,3,4]); // a = [1,2,3, 4] //magnitude b.SetIt(false,[1,0,1,-1]); // b = [1,0,1,-1] /phase c.PolarToCart(a,b); // result stored in c = projections to Re and Im axis end; *) function PolarToCart(AmpltVec, PhaseVec: TMtxVec): TMtxVec; overload; (*Convert AmpltVec elements [AIndex]..[AIndex+Len-1] and PhaseVec elements [PIndex]..[PIndex+Len-1] from polar form (radius,angle) to cartesian form (X,y). The results are stored as complex numbers (X=Re, y=Im) in the calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if is True and array borders are overrun/underrun. *) function PolarToCart(AmpltVec, PhaseVec: TMtxVec; AIndex, PIndex,Index, Len: integer): TMtxVec; overload; (*Raises base object elements to any power. Raises Base calling object elements to any power. The is faster, if Exponent is an integer. Real valued power can handle only positive Exponent. can handle negative exponent also. To compute a power to the negative exponent in general case or when the base is negative, use the complex version of the function. var a: Vector; begin a.SetIt(False,[1,2,3,4]); a.Power(1.2); end; *) function Power(Exponent: double): TMtxVec; overload; (*Raises all calling vector elements to complex power Exponent in-place. If the calling vector is real and has negative elements, the result will be NAN at those entries. To obtain a valid result in this case, extend the calling vector to complex with method. In all real/complex combinations, the Power method will not automatically assume that a number is complex to speed up the computation. Alternatively the user can of course always convert the real numbers to complex before passing them to the Power routine. *) function Power(Exponent: TCplx): TMtxVec; overload; (*The phase angles (spectrum) of object elements. Calculates the phase angles (spectrum) of all Vec object elements. Phase values are returned in radians and are in the range [-PI,PI]. Size and properties of the calling object are set implicitly to match Vec object. The phase angles are calculated from the following equation: var a,b: Vector; begin a.SetIt(True,[1,2,3,4]); // a = [1 + 2i, 3 - 4i] b.PhaseSpectrum(a); // b = [arctan2(1,2), arctan2(3,-4)]; end; *) function PhaseSpectrum(const Vec: TMtxVec): TMtxVec; overload; (*Calculates the power spectrum from the Vec elements [VecIndex]..[VecIndex+Len-1]. Store the results in calling object elements [Index]..[Index+Len-1]. An exception is raised if array borders are overrun/underrun. *) function PhaseSpectrum(const Vec: TMtxVec; VecIndex, Index,Len: integer): TMtxVec; overload; (*The power spectrum from object complex values. Calculates the power spectrum from the Vec object complex values and stores the results (power spectrum) in the real calling object. Size and properties of the calling object are set implicitly to match Vec object. The spectrum elements are squares of the magnitudes of the complex input elements: var a,b: Vector; begin a.SetIt(True,[1,2,3,-4]); // a = [1 + 2i, 3 - 4i] b.PowerSpectrum(a); // b = [1*1 + 2*2, 3*3+(-4)*(-4)] end; *) function PowerSpectrum(const Vec: TMtxVec): TMtxVec; overload; (*Calculates the power spectrum from the Vec complex elements [VecIndex]..[VecIndex+Len-1]. Store the results in calling object real elements [Index]..[Index+Len-1]. An exception is raised if calling object property is true or if array borders are overrun/underrun. *) function PowerSpectrum(const Vec: TMtxVec; VecIndex, Index,Len: integer): TMtxVec; overload; (*Raises base elements to exponent power. Raises Base value to Exponent object values powers and store the results to calling object values. Size and properties of calling object are adjusted automatically. *) function Power(Base: double; Exponent: TMtxVec): TMtxVec; overload; (*Raises Base complex value to Exponent object values powers and store the results to calling object values. Size and properties of calling object are adjusted automatically. *) function Power(Base: TCplx; Exponent: TMtxVec): TMtxVec; overload; (*Raises each of Base object elements to corresponding power Powers are stored in Exponenet elements: Power[i] = Base[i]^Exponent[i] Size and property of calling object are adjusted automatically. An exception is raised if Base and Exponent sizes do not match. *) function Power(Base, Exponent: TMtxVec): TMtxVec; overload; (*Raises each of the Base object elements to complex Exponent power. Size and properties of calling object are adjusted automatically. *) function Power(Base: TMtxVec; Exponent: TCplx): TMtxVec; overload; (*Raises each of the Base object elements to real Exponent power. Size and properties of calling object are adjusted automatically. *) function Power(Base: TMtxVec; Exponent: double): TMtxVec; overload; (*Raises Base object elements to Exponent object elements power. Raises Base elements to Exponent elements power. Only positive exponents can be handled if exponent object property is True. var a,b,c: Vector; begin a.SetIt(True,[1,2,3,4]); b.SetIt(True,[3,3,2,2]); c.PowerVec(a,b); // c = [1,8,9,16] end; *) function PowerVec(Base, Exponent: TMtxVec): TMtxVec; (*Elements product. the product of all calling object elements. Formula: An exception is raised if calling object property is true. var a: Vector; c: double; begin a.SetIt(False,[1,2,3,4]); c := a.Product; // c= 24 end; *) function Product: double; overload; (*Returns the product for calling object elements [Index]..[Index+Len-1]. An exception is raised if array borders are overrun or underrun. *) function Product(Index,Len: integer): double; overload; (*Calculate the product of all calling object complex elements. Store the result in complex variable X. *) procedure Product(out X: TCplx); overload; (*Calculate the product for calling object complex elements [Index]..[Index+Len-1]. Store the result in complex variable X. An exception is raised if array borders are overrun or underrun. *) procedure Product(out X: TCplx; Index,Len: integer); overload; (*Calculate the product of all calling object elements. Store the result in real variable X. *) procedure Product(out X: double); overload; (*Calculate the product for calling object elements [Index]..[Index+Len-1]. Store the result in real variable X. An exception is raised if array borders are overrun or underrun. *) procedure Product(out X: double; Index,Len: integer); overload; (*Elements product. the complex product of all calling object complex elements. An exception is raised if calling object property is false. *) function Productc: TCplx; overload; (*Returns the complex product for calling object complex elements [Index]..[Index+Len-1]. An exception is raised if array borders are overrun or underrun or if propety is false. *) function Productc(Index,Len: integer): TCplx; overload; (*The pseudo random sample generator with Gaussian distribution. Fills the calling object values with pseudo random samples following the Gaussian distribution with parameters: Mean = 0, StdDev = 1 ("Standard disctribution"). The value for the seed is obtained from the CPU clock. var a: Vector; begin a.Size(500,False); a.RandGauss; end; *) function RandGauss: TMtxVec; overload; (*Fills the calling object values with pseudo random samples following the Gaussian distribution. Parameters: AMean and AStdDev. The value for the seed is obtained from the CPU clock. *) function RandGauss(AMean, AStdDev: double): TMtxVec; overload; (*Fills the calling object values with pseudo random samples following the Gaussian distribution. Parameters: AMean, AStdDev and with Seed. *) function RandGauss(Seed: cardinal; AMean, AStdDev: double): TMtxVec; overload; (*The pseudo random sample generator with continuous uniform distribution. Fills the calling object values with pseudo random samples following the continuous uniform distribution using the parameters Low = 0, High = 1. The value for the seed is obtained from the CPU clock. var a: Matrix; begin a.Size(100,False); a.RandUniform(0,5); end; *) function RandUniform: TMtxVec; overload; (*Fills the calling object values with pseudo random samples following the continuous uniform distribution. Parameters Low and High. The value for the seed is obtained from the CPU clock. *) function RandUniform(aLow, aHigh: double): TMtxVec; overload; (*Fills the calling object values with pseudo random samples following the continuous uniform distribution. Parameters Low and High and Seed. *) function RandUniform(Seed: cardinal; aLow, aHigh: double): TMtxVec; overload; (*Gets real part of complex object values. The method method gets the real part of a complex object Vec and stores the real results in the calling object. Size and properties of the calling object are set implicitly to match Vec object. Vec property must be true otherwise an exception is raised. var a,b: Vector; begin a.SetIt(True,[1,2,3,4]); // = [1+2i, 3+4i] b.RealPart(a); // b = [1,3] end; *) function RealPart(const Vec: TMtxVec): TMtxVec; overload; (*Gets the real part of a Vec object complex elements [VecIndex]..[VecIndex+Len-1]. Stores the results in calling object real elements [Index]..[Index+Len-1]. An exception is raised if array borders are overrun or underrun or if Vec object propety is false. *) function RealPart(const Vec: TMtxVec; VecIndex,Index,Len: integer): TMtxVec; overload; (*Read values content from stream to object. Reads values content from SrcStream stream to calling objct. No other values describing the data type or length are read from the DstStream. Number type is defined by the Precision parameter, which can be obtained from method call. Note Use this method separately only, if you want user defined storage format. var b: Vector; AStream: TFileStream; Precision: TPrecision; begin AStream := TFileStream.Create('C:\test.bin',fmOpenRead); try Precision := b.ReadHeader(AStream); // Read info for b b.ReadValues(AStream,Precision); // Read values of b finally AStream.Free; end; end; *) function ReadValues(const Src: TStream; Precision: TPrecision): Int64; overload; (*Constructs a complex object from two real objects. Construct a complex object from the ReVec (real part) and the ImVec (imaginary part) objects. The results are stored in the calling object. Size and properties of the calling object are set implicitly to match ReVec and ImVec objects. An exception is raised if ReVec or ImVec property is True. var a,b,c: Vector; begin a.SetIt(True,[1,2,3,4]); b.SetIt(True,[2,2,3,4]); c.RealToCplx(a,b); end; *) function RealToCplx(const ReVec, ImVec: TMtxVec): TMtxVec; overload; (*Construct a complex object from the ReVec elements [ReIndex]..[ReIndex+Len-1] (real part) and the ImVec elements [ImIndex]..[ImIndex+Len-1] (imaginary part). The results are stored to calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if is True and array borders are overrun. An exception is also raised if ReVec or ImVec property is True. *) function RealToCplx(const ReVec, ImVec: TMtxVec; ReIndex, ImIndex, Index, Len: integer): TMtxVec; overload; (*Resets object properties to default values. Resets object properties to default values. The method is used by the Object cache management to reset the properties of the object freed with a call to . *) procedure Reset; (*Search and replace a value. Replaces the SearchValue with a ReplaceValue, where the searchValue is compared with Tol to the values of the calling object. *) function Replace(SearchValue, ReplaceValue: double; Tol: double = 0.0001): TMtxVec; overload; (*Replaces the SearchValue with a ReplaceValue, where the searchValue is compared with Tol to the calling object elements [Index]..[Index+Len-1]. An exception is raised if array borders are overrun/underrun. *) function Replace(SearchValue, ReplaceValue: double; Index, Len: integer; Tol: double = 0.0001): TMtxVec; overload; (*Search and replace a complex value.*) function Replace(SearchValue, ReplaceValue: TCplx; Tol: double = 0.0001): TMtxVec; overload; (*Replaces the SearchValue with a ReplaceValue, where the searchValue is compared with Tol to the calling object elements [Index]..[Index+Len-1]. An exception is raised if array borders are overrun/underrun. *) function Replace(SearchValue, ReplaceValue: TCplx; Index, Len: integer; Tol: double = 0.0001): TMtxVec; overload; (*Root mean square (RMS). Calculate the root mean square value for all calling object elements in-place. The root mean square (RMS) is defined by the equation: var a: Vector; c: double; begin a.SetIt(False,[1,2,3,4]); c := a.RMS; end; *) function RMS: double; overload; (*Calculate the RMS for calling object elements [Index]..[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function RMS(Index, Len: integer): double; overload; (*Elements rounded to the nearest whole number. Rounds all calling object elements to the nearest whole number. The result can be stored to an array of integers or as floating point number. *) function Round: TMtxVec; overload; (*Round calling object elements [Index]..[Index+Len-1] in-place. An exception is raised if array borders are overrun/underrun. *) function Round(Index,Len: integer): TMtxVec; overload; (*Round all Src object elements and store the results in calling object elements. Size and property of calling object are adjusted automatically. *) function Round(const Src: TMtxVec): TMtxVec; overload; (*Rounds the calling object elements to 4 byte integers and stores the result in the Dst array. The size of the Dst array is set automatically. If the complex property is True then the length of the array will be equal to Self.Length*2. *) procedure Round(var Dst: TIntegerArray); overload; (*Round Src object elements [SrcIndex]..[SrcIndex+Len-1] and store the results to calling object elements [Index]..[Index+Len-1]. Size and property of the calling object must be set explicitly. An exception is raised if array borders are overrun/underrun. *) function Round(const Src: TMtxVec; SrcIndex,Index,Len: integer): TMtxVec; overload; (*Initialize elements to Value. Set all calling object elements to Value. If the calling object is complex then the real part is set to Value and the imaginary is set to zero. var a: Vector; begin a.Size(4,False); a.SetVal(1); // a = [1,1,1,1] end; *) function SetVal(Value: double): TMtxVec; overload; (*Set all calling object elements [Index]..[Index+Len-1] to real Value. If the calling object is complex then the real part is set to Value and the imaginary is set to zero. An exception is raised if array borders are overrun/underrun. *) function SetVal(Value: double; Index, Len: integer): TMtxVec; overload; (*Set all calling object complex elements to complex Value.*) function SetVal(Value: TCplx): TMtxVec; overload; (*Set calling object complex elements [Index]..[Index+Len-1] to complex Value. properties of the calling object are set to true even before the call it was false. An exception is raised if calling object array borders are overrun/underrun. *) function SetVal(Value: TCplx; Index: integer; Len: integer): TMtxVec; overload; (*Initializes object elements to zero. Set all calling object elements to zero. *) function SetZero: TMtxVec; overload; (*Initializes calling object elements [Index]..[Index+Len-1] to zero. An exception is raised if array borders are overrun *) function SetZero(Index, Len: integer): TMtxVec; overload; (*Changes elements sign. Changes all calling object elements sign (v -> -v) in-place. var a: Vector; begin a.SetIt(False,[1,2,-3,4]); a.Sign; // a = [-1,-2,3,-4] end; *) function Sign: TMtxVec; overload; (*Change calling object elements [Index]..[Index+Len-1] sign in-place. An exception is raised if array borders are overrun or underrun. *) function Sign(Index,Len: integer): TMtxVec; overload; (*Change all X object elements sign and store the results in calling object. Size and properties of calling object are adjusted automatically. *) function Sign(const X: TMtxVec): TMtxVec; overload; (*Change X object elements [XIndex]..[XIndex+Len-1] sign and store the results in calling object elements [Index]..[Index+Len-1]. An exception is raised if array borders are overrun or underrun. *) function Sign(const X: TMtxVec; XIndex,Index,Len: integer): TMtxVec; overload; (* Computes signum function of calling object elements. Signum(X) is 1 for X > 0 , equal to zero for X = 0 and -1 for X < 0. *) function Sgn: TMtxVec; overload; (* Computes signum function of calling object elements [Index..Index+Len-1]. Signum(X) is 1 for X > 0 , equal to zero for X = 0 and -1 for X < 0. *) function Sgn(Index,Len: integer): TMtxVec; overload; (* Computes signum function from Src elements and stores the result in the calling object. Size and properties of calling object are adjusted automatically. Signum(X) is 1 for X > 0 , equal to zero for X = 0 and -1 for X < 0. *) function Sgn(const Src: TMtxVec): TMtxVec; overload; (* Computes signum function from Src elements [SrcIndex..SrcIndex+Len-1] and stores the result in the calling object [Index..Index+Len-1]. Size and properties of calling object are adjusted automatically. Signum(X) is 1 for X > 0 , equal to zero for X = 0 and -1 for X < 0. *) function Sgn(const Src: TMtxVec; SrcIndex,Index,Len: integer): TMtxVec; overload; (*Signum. Calculates the signum of all Src object elements and multiplies it with the calling object elements accordingly. Signum(X) is 1 for X > 0 , equal to zero for X = 0 and -1 for X < 0. Note The length of Src and of the calling object must match or an exception will be raised. Size and property of calling object are adjusted automatically. *) function SgnMul(const Src: TMtxVec): TMtxVec; overload; (*Size the object. Assignes the size of the Src object to the calling object. If the calling object is a TVec object then the Src can be of any type, otherwise TMtx can only obtain size from a TMtx object and TSparseMtx can only obtain size from a TSparseMtx object. If the calling object and Src are of different types, the complex property can be different, if both objects have a matching property. In this case only the Complex property of the calling object will changed, while all other properties describing the size of the object (rows, cols, length, nonZeros) will be preserved. This is different from simply setting the Complex property. Changing the Complex property directly would also change the Length, Cols and NonZeros properties. *) function Size(const Src: TMtxVec): TMtxVec ; overload; (*Also allows the complex property of the calling object to become of AComplex value instead of Src.Complex value. It is also possible to pass the calling object as the Src with a different AComplex value. The value of the complex property can be changed without knowing the actual type of the object. *) function Size(const Src: TMtxVec; AComplex: boolean): TMtxVec ; overload; (*Sizes the array. Sizes the Dst array so that it can hold all the values stored in the calling object. If the property is false an exception will be raised. *) procedure SizeToArray(var Dst: TCplxArray); overload; (*Sizes double precision array. If the property is true the Length of the Dst array will be 2*. *) procedure SizeToArray(var Dst: TDoubleArray); overload; (*Size single precision array. If the property is true the Length of the Dst array will be 2*. *) procedure SizeToArray(var Dst: TSingleArray); overload; (*Sizes integer array. If the property is true the Length of the Dst array will be 2*. *) procedure SizeToArray(var Dst: TIntegerArray); overload; (*Sizes integer array. If the property is true the Length of the Dst array will be 2*. *) procedure SizeToArray(var Dst: TSmallIntArray); overload; (*Sizes integer array. If the property is true the Length of the Dst array will be 2*. *) procedure SizeToArray(var Dst: Math387.TByteArray); overload; (*Compares two objects and returns True, if they are equal. Compares two objects and returns True, if they are equal. The IsEqual uses cmpAbsolute comparison method with comparison tolerance of 10*EPS by default. The method compares only and properties and coresponding values. To compare matrices or sparse matrices, use the Equal method. *) function IsEqual(const Vec: TMtxVec): boolean; overload; (*Compares Vec elements [VecIndex]..[VecIndex+Len-1] with calling object elements [Index]..[Index+Len-1].*) function IsEqual(const Vec: TMtxVec; VecIndex, Index, Len: integer): boolean; overload; (*Compares Vec elements with coresponding calling object elements with Compare method and specified Precision.*) function IsEqual(const Vec: TMtxVec; Precision: double; Compare: TCompare = cmpAbsolute): boolean; overload; (*Compares Vec elements [VecIndex]..[VecIndex+Len-1] with calling object elements [Index]..[Index+Len-1] with Compare method and specified Precision.*) function IsEqual(const Vec: TMtxVec; VecIndex, Index, Len: integer; Precision: double; Compare: TCompare = cmpAbsolute): boolean; overload; (*Compares complex Value with all calling object elements.*) function IsEqual(Value: TCplx): boolean; overload; (*Compares real Value with all calling object elements.*) function IsEqual(Value: double): boolean; overload; (*Compares real Value with all calling object elements with Compare method and specified Tolerance.*) function IsEqual(Value: double; Tolerance: double; Compare: TCompare): boolean; overload; (*Compares complex Value with all calling object elements with Compare method and specified Tolerance.*) function IsEqual(Value: TCplx; Tolerance: double; Compare: TCompare): boolean; overload; (*Standard deviation. Calculate the standard deviation of all calling object elements. The result is a real value. An exception is raised if calling vector property is true. var a: Vector; c: double; aMean: double; begin a.SetIt(False,[1,2,3,4]); aMean := a.Mean; c := a.StdDev(aMean); //if both Mean and StdDev are required this is faster // c := a.StdDev; //this is an alternative. end; *) function StdDev: double; overload; (*Returns the standard deviation of calling object elements [Index]..[Index+Len-1]. An exception is raised if calling object property is true or if array borders are overrun/underrun. *) function StdDev(Index,Len: integer): double; overload; (*Returns the standard deviation of all calling object complex elements. The average of all calling object elements must be passed as a AMean parameter. An exception is raised if calling object property is false. *) function StdDev(AMean: TCplx): TCplx; overload; (*Returns the standard deviation of calling object complex elements [Index]..[Index+Len-1]. The average of all calling object elements must be passed as a AMean parameter. An exception is raised if calling object property is false or if array borders are overrun/underrun. *) function StdDev(AMean: TCplx; Index, Len: integer): TCplx; overload; (*Returns the standard deviation of all calling object elements. The average of all calling object elements must be passed as a AMean parameter. An exception is raised if calling object property is true. *) function StdDev(AMean: double): double; overload; (*Returns the standard deviation of calling object elements [Index]..[Index+Len-1]. The average of the coresponding elements must be passed as a parameter. An exception is raised if calling object property is true or if array borders are overrun/underrun. *) function StdDev(AMean: double; Index, Len: integer): double; overload; (*Returns the standard deviation of all calling object elements. The average of all calling object elements must be passed as a AMean parameter. An exception is raised if calling object property is true. *) procedure MeanAndStdDev(var aMean, aStdDev: double); overload; (*Returns the standard deviation of calling object elements [Index]..[Index+Len-1]. The average of the coresponding elements must be passed as a parameter. An exception is raised if calling object property is true or if array borders are overrun/underrun. *) procedure MeanAndStdDev(var aMean, aStdDev: double; Index, Len: integer); overload; (*Sine and cosine. Calculates the sine and cosine for all calling object elements and stores the sines to SinX and cosines to CosX. Size and property of SinX and CosX are adjusted automatically. Note Use this method if you require both sine and cosine. var a,s,c: Vector; begin a.SetIt(false[0,PIDIV2,PI]); a.Sincos(s,c); // s=[0,1,0], c =[1,0,-1] end; *) procedure SinCos(SinX, CosX: TMtxVec); overload; (*Calculates the sine and cosine for calling object elements [Index]..[Index+Len-1]. Stores the sines to SinX elemets [SinXIndex]..[SinXIndex+Len-1] and cosines to CosX elements [CosXIndex]..[CosXIndex+Len-1] elements. Size and property of SinX and CosX objects are not set automatically. An exception is raised if and array borders are overrun/underun. *) procedure SinCos(SinX, CosX: TMtxVec; SinXIndex, CosXIndex, Index, Len: integer); overload; (*Hyperbolic sine and cosine. Calculates the hyperbolic sine and hyperbolic cosine for all calling object elements and stores the sines to SinhX and cosines to CoshX. Size and property of SinhX and CoshX are adjusted automatically. Note Use this method if you require hyperbolic sine and hyperbolic cosine. var a,s,c: Vector; begin a.SetIt(false[0,PIDIV2,PI]); a.SinhCosh(s,c); end; *) procedure SinhCosh(SinhX, CoshX: TMtxVec); overload; (*Calculates the hyperbolic sine and hyperbolic cosine for calling object elements [Index]..[Index+Len-1]. Stores the sines to SinhX elemets [SinhIndex]..[SinhIndex+Len-1] and cosines to CoshX elements [CoshIndex]..[CoshIndex+Len-1] elements. Size and property of SinhX and CoshX objects are not set automatically. An exception is raised if and array borders are overrun/underun. *) procedure SinhCosh(SinhX, CoshX: TMtxVec; SinhIndex, CoshIndex, Index, Len: integer); overload; (*Sums vector values. Returns the sum of all calling object elements. An exception is raised if calling object property is true. var a: Vector; b: double; begin a.SetIt(False,[1,2,3,4]); b := a.Sum; // b = 10 end; *) function Sum: double; overload; (*Returns the sum of calling object elements [Index]..[Index+Len-1]. An exception is raised if calling object property is True or array borders are overrun/underrun. *) function Sum(Index,Len: integer): double; overload; (*Calculates the sum of calling object elements [Index]..[Index+Len-1]. Stores the result in real ASum variable. An exception is raised if calling object property is True or array borders are overrun/underrun. *) procedure Sum(out ASum: double; Index, Len: integer); overload; (*Calculates the sum of all calling object complex elements. Stores the result in complex ASum variable. An exception is raised if calling object property is False. *) procedure Sum(out ASum: TCplx); overload; (*Calculates the sum of calling object complex elements [Index]..[Index+Len-1]- Stores the result in complex ASum variable. An exception is raised if calling object property is False or array borders are overrun/underrun. *) procedure Sum(out ASum: TCplx; Index, Len: integer); overload; (*Sum (complex value). Returns the complex sum of all calling object complex elements. An exception is raised if calling object property is False. *) function Sumc: TCplx; overload; (*Returns the complex sum of calling object complex elements [Index]..[Index+Len-1]. An exception is raised if calling object property is False or array borders are overrun/underrun. *) function Sumc(Index,Len: integer): TCplx; overload; (*Threshold bottom operation. Perform threshold operation on all calling object values. The Value parameter is a lower bound for threshold operation. All values smaller than Value will be replaced with Value. var a: Vector; begin a.SetIt(True,[2,0.1,3,4]); a.ThreshBottom(0.2); // a = [2,0.2,3,4] end; *) function ThreshBottom(Value: double): TMtxVec; overload; (*Perform the threshold operation on calling object values [Index]..[Index+Len-1]. An exception is raised if array borders are overrun/underrun. *) function ThreshBottom(Value: double; Index, Len: integer): TMtxVec; overload; (*Perform threshold operation on all Src object values and store the results in calling object. Size and properties of the calling object are adjusted automatically. *) function ThreshBottom(const Src: TMtxVec; Value: double): TMtxVec; overload; (*Perform a threshold operation on Vec elements [VecIndex]..[VecIndex+Len-1] and store the results in the calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if is true and array borders are overrun/underrun. *) function ThreshBottom(const Vec: TMtxVec; Value: double; VecIndex, Index, Len: integer): TMtxVec; overload; (*Threshold top operation. Perform threshold operation on all calling object values. The Value parameter is an upper bound for threshold operation. All values bigger than Value will be replaced with Value. var a: Vector; begin a.SetIt(True,[2,0.1,3,4]); a.Threshtop(0.2); // a = [0.2,0.1,0.2,0.2] end; *) function ThreshTop(Value: double): TMtxVec; overload; (*Perfrom the threshold operation on calling object values [Index]..[Index+Len-1]. An exception is raised if array borders are overrun/underrun. *) function ThreshTop(Value: double; Index, Len: integer): TMtxVec; overload; (*Perform threshold operation on all Src object values and store the results in calling object. Size and properties of the calling object are adjusted automatically. *) function ThreshTop(const Src: TMtxVec; Value: double): TMtxVec; overload; (*Perform a threshold operation Vec elements [VecIndex]..[VecIndex+Len-1] and store the results in the calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if is true and array borders are overrun/underrun. *) function ThreshTop(const Vec: TMtxVec; Value: double; VecIndex, Index, Len: integer): TMtxVec; overload; (*Threshold top and bottom centered around zero. Perform threshold operation on all calling object values. The Value parameter is an upper bound for threshold operation. All values smaller than Value will be replaced with Value and all values bigger than -Value will be replaced with -Value. The comparison checks if abs(Values[i]) < Value. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TVec a; MtxVec.CreateIt(out a); try { a.SetIt(false, new double[] {2,-0.1,3,4}); a.ThreshAbsLT(0.2); // a = [2,-0.2,3,4] } finally { MtxVec.FreeIt(ref a); } } } *) function ThreshAbsLT(const Value: double): TMtxVec; overload; (*Perfrom the threshold operation on calling object values [Index]..[Index+Len-1]. An exception is raised if array borders are overrun/underrun. *) function ThreshAbsLT(const Value: double; Index, Len: integer): TMtxVec; overload; (*Perform threshold operation on all Src object values. Store the results in calling object. Size and properties of the calling object are adjusted automatically. *) function ThreshAbsLT(const Src: TMtxVec; const Value: double): TMtxVec; overload; (*Perform a threshold operation Vec elements [VecIndex]..[VecIndex+Len-1]. Store the results in the calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if is true and array borders are overrun/underrun. *) function ThreshAbsLT(const Vec: TMtxVec; const Value: double; VecIndex, Index, Len: integer): TMtxVec; overload; (*Threshold top and bottom centered around zero. Perform threshold operation on all calling object values. The Value parameter is an upper bound for threshold operation. All values bigger than Value will be replaced with Value and all values smaller than -Value will be replaced with -Value. The comparison checks if abs(Values[i]) > Value. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TVec a; MtxVec.CreateIt(out a); try { a.SetIt(false, new double[] {2, -1, 3, 4}); a.ThreshAbsGT(0.2); // a = [0.2, -0.2, 0.2, 0.2] } finally { MtxVec.FreeIt(ref a); } } } *) function ThreshAbsGT(const Value: double): TMtxVec; overload; (*Perfrom the threshold operation on calling object values [Index]..[Index+Len-1]. An exception is raised if array borders are overrun/underrun. *) function ThreshAbsGT(const Value: double; Index, Len: integer): TMtxVec; overload; (*Perform threshold operation on all Src object values. Store the results in calling object. Size and properties of the calling object are adjusted automatically. *) function ThreshAbsGT(const Src: TMtxVec; const Value: double): TMtxVec; overload; (*Perform a threshold operation Vec elements [VecIndex]..[VecIndex+Len-1]. Store the results in the calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if is true and array borders are overrun/underrun. *) function ThreshAbsGT(const Vec: TMtxVec; const Value: double; VecIndex, Index, Len: integer): TMtxVec; overload; (*Threshold less than operation. Perform operation on all calling object values. The LTValue parameter is an lower bound for threshold operation. All values less than LTLevel will be replaced with LTValue. For complex number comparation is applied with norm of complex value. var a: Vector; begin a.SetIt(True,[2,0.1,3,4]); a.ThresholdLT(2.3,1.5); // a = [1.5,1.5,3,4] end; *) function ThresholdLT(LTLevel, LTValue: double): TMtxVec; overload; (*Perfrom "less than" threshold operation on the calling object values in range [Index]..[Index+Len-1]. An exception is raised if array borders are overrun/underrun. *) function ThresholdLT(LTLevel, LTValue: double; Index, Len: integer): TMtxVec; overload; (*Perform "less than" threshold operation on all Vec object values and store the results in calling object. Size and properties of the calling object are adjusted automatically. *) function ThresholdLT(const Vec: TMtxVec; LTLevel, LTValue: double): TMtxVec; overload; (*Perform "less than" threshold operation on Vec elements from range [VecIndex]..[VecIndex+Len-1] and store the results in the calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if is true and array borders are overrun/underrun. An exception will be raised if Vec.Complex and Complex of the calling object are not equal. *) function ThresholdLT(const Vec: TMtxVec; LTLevel, LTValue: double; VecIndex, Index, Len: integer): TMtxVec; overload; (*Perfrom "less than" threshold operation for complex numbers. If the calling object contains none Complex values, an exception will be raised. *) function ThresholdLT(LTLevel: double; LTValue: TCplx): TMtxVec; overload; (*Perfrom "less than" threshold operation for complex numbers on the calling object values in range [Index]..[Index+Len-1]. An exception is raised if array borders are overrun/underrun. If the calling object contains none Complex values, an exception will be raised. *) function ThresholdLT(LTLevel: double; LTValue: TCplx; Index, Len: integer): TMtxVec; overload; (*Perform "less than" threshold operation for complex numbers on all Vec object values and store the results in calling object. Size and properties of the calling object are adjusted automatically. If Vec object contains none Complex values, an exception will be raised. *) function ThresholdLT(const Vec: TMtxVec; LTLevel: double; LTValue: TCplx): TMtxVec; overload; (*Perform "less than" threshold operation for complex numbers on Vec elements from range [VecIndex]..[VecIndex+Len-1] and store the results in the calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if is true and array borders are overrun/underrun. If Vec object or calling object contain none Complex values, an exception will be raised. *) function ThresholdLT(const Vec: TMtxVec; LTLevel: double; LTValue: TCplx; VecIndex, Index, Len: integer): TMtxVec; overload; (*Threshold greater than operation Perform operation on all calling object values. The GTValue parameter is an upper bound for threshold operation. All values bigger than LTLevel will be replaced with GTValue. Note For complex number comparation is applied with norm of complex value. var a: Vector; begin a.SetIt(True,[2,0.1,3,4]); a.ThresholdGT(2.3,3.4); // a = [2,0.1,3.4,3.4] end; *) function ThresholdGT(GTLevel, GTValue: double): TMtxVec; overload; (*Perfrom "greater than" threshold operation on the calling object values in range [Index]..[Index+Len-1]. An exception is raised if array borders are overrun/underrun. *) function ThresholdGT(GTLevel, GTValue: double; Index, Len: integer): TMtxVec; overload; (*Perform "greater than" threshold operation on all Vec object values and store the results in calling object. Size and properties of the calling object are adjusted automatically. *) function ThresholdGT(const Vec: TMtxVec; GTLevel, GTValue: double): TMtxVec; overload; (*Perform "greater than" threshold operation on Vec elements from range [VecIndex]..[VecIndex+Len-1] and store the results in the calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if is true and array borders are overrun/underrun. An exception will be raised if Vec.Complex and Complex of the calling object are not equal. *) function ThresholdGT(const Vec: TMtxVec; GTLevel, GTValue: double; VecIndex, Index, Len: integer): TMtxVec; overload; (*Perfrom "greater than" threshold operation for complex numbers. If the calling object contains none Complex values, an exception will be raised. *) function ThresholdGT(GTLevel: double; GTValue: TCplx): TMtxVec; overload; (*Perfrom "greater than" threshold operation for complex numbers on the calling object values in range [Index]..[Index+Len-1]. An exception is raised if array borders are overrun/underrun. If the calling object contains none Complex values, an exception will be raised. *) function ThresholdGT(GTLevel: double; GTValue: TCplx; Index, Len: integer): TMtxVec; overload; (*Perform "greater than" threshold operation for complex numbers on all Vec object values and store the results in calling object. Size and properties of the calling object are adjusted automatically. If Vec object contains none Complex values, an exception will be raised. *) function ThresholdGT(const Vec: TMtxVec; GTLevel: double; GTValue: TCplx): TMtxVec; overload; (*Perform "greater than" threshold operation for complex numbers on Vec elements from range [VecIndex]..[VecIndex+Len-1] and store the results in the calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if is true and array borders are overrun/underrun. If Vec object or calling object contain none Complex values, an exception will be raised. *) function ThresholdGT(const Vec: TMtxVec; GTLevel: double; GTValue: TCplx; VecIndex, Index, Len: integer): TMtxVec; overload; (*Threshold greater than and less than operation. Perform operation on all calling object values. The LTValue parameter is an lower bound for threshold operation. The GTValue parameter is an upper bound for threshold operation. All values less than LTLevel will be replaced with LTValue. All values bigger than GTLevel will be replaced with GTValue. Operation is available only for none Complex values. var a: Vector; begin a.SetIt(True,[2,0.1,3,4]); a.ThresholdGT_LT(2.3,3.4,1,0.5); // a = [2,0.5,3.4,3.4] end; *) function ThresholdGT_LT (GTLevel, GTValue, LTLevel, LTValue: double): TMtxVec; overload; (*Perform "greater than and less than" threshold operation on the calling object values in range [Index]..[Index+Len-1]. An exception is raised if array borders are overrun/underrun. An exception will be raised if the calling object contains complex numbers. *) function ThresholdGT_LT (GTLevel, GTValue, LTLevel, LTValue: double; Index, Len: integer): TMtxVec; overload; (*Perform "greater than and less than" threshold operation on all Vec object values and store the results in calling object. Size and properties of the calling object are adjusted automatically. An exception will be raised if Vec object contains complex numbers. *) function ThresholdGT_LT (const Vec: TMtxVec; GTLevel, GTValue, LTLevel, LTValue: double): TMtxVec; overload; (*Perform "greater than and less than" threshold operation on Vec elements from range [VecIndex]..[VecIndex+Len-1] and store the results in the calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if is true and array borders are overrun/underrun. An exception will be raised if Vec object or the calling object contain complex numbers. *) function ThresholdGT_LT(const Vec: TMtxVec; GTLevel, GTValue, LTLevel, LTValue: double; VecIndex, Index, Len: integer): TMtxVec; overload; (*Rounds a real number towards zero and returns the fractional part. Rounds all calling object elements towards zero to an integer and stores the result in the TruncDst object as floating point numbers. The fractional part is stored in the FracDst. *) procedure TruncAndFrac(TruncDst: TMtxVec; FracDst: TDenseMtxVec); overload; (*Truncate calling object elements [Index]..[Index+Len-1]. Store the results to TruncDst object elements [TruncIdx]..[TruncIdx+Len-1]. The fractional parts are saved in FracDst elements [FracIdx]..[FracIdx+Len-1]. Size and property of calling object must be set explicitly to match those of Src object. An exception is raised if array borders are overrun/underrun. *) procedure TruncAndFrac(TruncDst: TMtxVec; FracDst: TDenseMtxVec; TruncIdx, FracIdx, Index, Len: integer); overload; (*Rounds a real number towards zero. Rounds all calling object elements towards zero to an integer and stores the result in the calling object again as floating point numbers. *) function Trunc: TMtxVec; overload; (*Truncate calling object elements [Index]..[Index+Len-1] in-place. An exception is raised if array borders are overrun/underrun. *) function Trunc(Index,Len: integer): TMtxVec; overload; (*Truncate all Src object elements and store the results in calling object elements. Size and property of calling object are adjusted automatically. *) function Trunc(const Src: TMtxVec): TMtxVec; overload; (*Truncate all calling object elements and store the result in the Dst integer array. Length of the array is automatically adjusted. If the calling object is Complex, the length of the Dst array is equal to 2*. *) procedure Trunc(var Dst: TIntegerArray); overload; (*Truncate Src object elements [SrcIndex]..[SrcIndex+Len-1] and store the results to calling object elemenents [Index]..[Index+Len-1]. Size and property of calling object must be set explicitly to match those of Src object. An exception is raised if array borders are overrun/underrun. *) function Trunc(const Src: TMtxVec; SrcIndex, Index,Len: integer): TMtxVec; overload; (*Write object header and values to a file. Write the header describing the calling object and the values array of the calling object to the file, specified by the FileName. If the file already exist, the data is overwritten by default. If Append is True, the data is appended to the end of the file. The data is always saved with default precision. (single or double). * In case of '.csv' extension a comma is used as a column delimiter for matrices. * In case of '.txt' extension a tab is used as a column delimiter for matrices. * For all other extensions, the expected format is binary. Note It is recommended you use a *.mtx extension when you're saving/loading matrix to/from file. Similarly, you should use a *.Vec extension when you're saving/loading vector to/from file. var Mtx: Matrix; begin Mtx.SetIt(2,2,False,[3,1,-1,5]); Mtx.SaveToFile('c:\test.mtx'); // Write info and header for Mtx to file end; *) procedure SaveToFile(const FileName: string; Append: boolean = False); (*Reads the header information and the values array content from the file. Reads the header information and the values array content from the file specified by FileName parameter. * In case of '.csv' extension a comma is used as a column delimiter for matrices. * In case of '.txt' extension a tab is used as a column delimiter for matrices. * For all other extensions, the expected format is binary. var b: Vector; begin b.LoadFromFile('c:\test.Vec'); // Read header and values for b end; *) procedure LoadFromFile(const FileName: string); (*Reads the header information and the values array content from a stream. Reads the header information and the values array content from the SrcStream. The return value indicates the number of elements read. var b: Vector; AStream: TFileStream; begin b.SetIt(False,[0,0,1,3,2]); AStream := TFileStream.Create('C:\test.Vec',fmCreate); try b.LoadFromStream(AStream); // Read info and header for b finally AStream.Free; end; end; *) function LoadFromStream(const Src: TStream): Int64; overload; (*Writes the header information and the Values content to a stream. Writes the header information and the Values content to a DstStream stream. Number type is defined by the Precision parameter. Rounding defines the rounding for integer types. When saving double precision as single precision, all overflows are saved as INF (-INF). When saving to integer types all overflows are clipped. Attempt to save single precision as double precision will raise an exception. var b: Vector; AStream: TFileStream; begin b.SetIt(False,[0,0,1,3,2]); AStream := TFileStream.Create('C:\test.Vec',fmCreate); try b.SaveToStream(AStream); // Write info and header for b finally AStream.Free; end end; *) procedure SaveToStream(const Dst: TStream); overload; (*Writes object Values content to a stream. Writes the calling object Values content to the DstStream stream. No other values describing the data type or length are written to the DstStream. Number type is defined by the Precision parameter. Rounding defines the rounding for integer types. When saving double precision as single precision, all overflows are saved as INF (-INF). When saving to integer types all overflows are clipped. Attempt to save single precision as double precision will raise an exception. The paramateres must be the same as for the method. Note Use this method separately only, if you want user defined storage format. var b: Vector; AStream: TFileStream; begin b.SetIt(False,[0,0,1,3,2]); AStream := TFileStream.Create('C:\test.Vec',fmCreate); try b.WriteHeader(AStream); // Write info for b b.WriteValues(AStream); // Write values of b finally AStream.Free; end; end; *) procedure WriteValues(const Dst: TStream; Precision: TPrecision; Rounding: TRounding = rnTrunc); overload; procedure WriteValues(const Dst: TStream); overload; (*Writes the header information for the calling vector to a stream. Writes the header information for the calling object to a DstStream stream. The header information contains information about object (size, complex, type of values in Values array, ...) which all define the state of the object. Number type is defined by the Precision parameter. Rounding defines the rounding for integer types. When saving double precision as single precision, all overflows are saved as INF (-INF). When saving to integer types all overflows are clipped. var b: Vector; AStream: TFileStream; begin b.SetIt(False,[0,0,1,3,2]); AStream := TFileStream.Create('C:\test.bin',fmCreate); try b.WriteHeader(AStream); // Write info for b b.WriteValues(AStream); // Write values of b finally AStream.Free; end; end; *) procedure WriteHeader(const Dst: TStream; Precision: TPrecision; Rounding: TRounding = rnTrunc); overload; procedure WriteHeader(const Dst: TStream); overload; (*Reads the header information from a stream to object. Reads the header information from a DstStream stream to calling object. The header information contains all necessary information defining the object. The function returns the precision in which the data was stored. This information is required for the method. var b: Vector; AStream: TFileStream; Precision: TPrecision; begin AStream := TFileStream.Create('C:\test.bin',fmOpenRead); try Precision := b.ReadHeader(AStream); // Read info for b b.ReadValues(AStream,Precision); // Read values of b finally AStream.Free; end; end; *) function ReadHeader(const Src: TStream): TPrecision; overload; (*Adds Value to object elements. *) function Add(Value: double): TMtxVec; overload; (*Adds complex Value to all calling object complex elements.*) function Add(Value: TCplx): TMtxVec; overload; (*Adds Value to calling object elements [Index]..[Index+Len-1]. An exception is raised if array borders are overrun. *) function Add(Value: double; Index, Len: integer): TMtxVec; overload; (*Adds complex Value to calling object complex elements [Index]..[Index+Len-1]. An exception is raised if array borders are overrun. *) function Add(Value: TCplx; Index, Len: integer): TMtxVec; overload; (*Adds Value to the each element of the Vec object. Stores the result in the calling object. Size and properties of the calling object are set automatically. *) function Add(const Vec: TMtxVec; Value: double): TMtxVec; overload; (*Adds complex Value to each element of the Vec object. Store the result to the calling object. Size property of the calling object is set automatically. property of the calling object is set to True. *) function Add(const Vec: TMtxVec; Value: TCplx): TMtxVec; overload; (*Adds Value to each element of Vec object in range [VecIndex]..[VecIndex+Len-1]. Store the results to elements [Index]..[Index+Len-1] of the calling object. Size of the calling object is not changed. An exception is raised if array borders are overrun. property of the calling object is set implicitly. *) function Add(const Vec: TMtxVec; Value: double; VecIndex, Index, Len: integer): TMtxVec; overload; (*Adds complex Value to each elements of the Vec object in range [VecIndex]..[VecIndex+Len-1]. Stores the result to elements [Index]..[Index+Len-1] of the calling object. Size of the calling object is not changed. An exception is raised if array borders are overrun. property of the calling object is set to True. *) function Add(const Vec: TMtxVec; Value: TCplx; VecIndex, Index, Len: integer): TMtxVec; overload; (*Array addition. Add each of Vec elements to corresponding elements in the calling object. *) function Add(const Vec: TMtxVec): TMtxVec; overload; (*Add each of Vec elements to corresponding elements in the calling object. In addition, the following formula is begin used: result = result+ aScale*Vec . The results are stored in the calling object. Size and properties of the calling object are set implicitly to match the Vec object. *) function AddScaled(const Vec: TMtxVec; aScale: double): TMtxVec; overload; (*Add each of Vec elements to corresponding elements in the calling object. In addition, the following formula is begin used: result = result+ Cplx(RScale,IScale)*Vec . When default values for parameters are being used the "normal" addition is being performed. The results are stored in the calling object. Size and properties of the calling object are set implicitly to match the Vec object. *) function AddScaled(const Vec: TMtxVec; RScale: double; IScale: double): TMtxVec; overload; (*Add each of Vec elements to corresponding elements in the calling object. In addition, the following formula is begin used: result = result+ aScale*Vec . The results are stored in the calling object. Size and properties of the calling object are set implicitly to match the Vec object. *) function AddScaled(const Vec: TMtxVec; aScale: TCplx): TMtxVec; overload; (*Add each of Vec2 elements to corresponding elements in Vec1. The results are stored in the calling object. Size and properties of the calling object are set implicitly to match Vec1 and Vec2 vectors. *) function Add(const Vec1, Vec2: TMtxVec): TMtxVec; overload; (*Add Vec elements [VecIndex]..[VecIndex+Len-1] to calling object elements [Index]..[Index+Len-1]. An exception is raised if is true and array borders are overrun. *) function Add(const Vec: TMtxVec; VecIndex, Index, Len: integer): TMtxVec; overload; (*Adds Vec elements [VecIndex]..[VecIndex+Len-1] to calling object elements [Index]..[Index+Len-1]. In addition, the following formula is begin used: result = result+ Cplx(aScale)*Vec . An exception is raised if is true and array borders are overrun. *) function AddScaled(const Vec: TMtxVec; aScale: double; VecIndex, Index, Len: integer): TMtxVec; overload; (*Adds Vec elements [VecIndex]..[VecIndex+Len-1] to calling object elements [Index]..[Index+Len-1]. In addition, the following formula is begin used: result = result+ aScale*Vec . An exception is raised if is true and array borders are overrun. *) function AddScaled(const Vec: TMtxVec; aScale: TCplx; VecIndex, Index, Len: integer): TMtxVec; overload; (*Add Vec1 elements [Vec1Index]..[Vec1Index+Len-1] to Vec2 elements [Vec2Index]..[Vec2Index+Len-1]. Store the results in calling object elements [Index]..[Index+Len-1]. An exception is raised if is true and array borders are overrun. *) function Add(const Vec1, Vec2: TMtxVec; Vec1Index, Vec2Index, Index, Len: integer): TMtxVec; overload; (*Add a product of two vectors. Multiply Vec1 elements with coresponding Vec2 elements and add the result to the calling vector. The size of the calling vector is set implicitly. *) function AddProduct(const Vec1, Vec2: TMtxVec): TMtxVec; overload; (*Multiply Vec1 elements [Vec1Index]..[Vec1Index+Len-1] with Vec2 elements [Vec2Index]..[Vec2Index+Len-1] add the results to the calling object elements [Index]..[Index+Len-1]. An exception is raised if is true and array borders are overrun. *) function AddProduct(const Vec1, Vec2: TMtxVec; Vec1Index, Vec2Index, Index, Len: integer): TMtxVec; overload; (*Conjugate and multiply. Conjugate each of Vec elements and multiply them with corresponding elements in the calling object. The results are stored in the calling object. Size and properties of the calling object are set implicitly to match Vec. var a,b,c: Vector; begin a.SetIt(True,[1,2,3,4]); b.SetIt(True,[4,3,2,1]); c.ConjMul(a,b); end; *) function ConjMul(const Vec: TMtxVec): TMtxVec; overload; (*Conjugate Vec elements Vec[VecIndex]..Vec[VecIndex+Len-1] and multiply them with corresponding calling object elements [Index]..[Index+Len-1]. The results are stored in the calling object elements [Index]..[Index+Len-1]. Size and properties are not set. An exception is raised if is true and array borders are overrun or underrun. *) function ConjMul(const Vec: TMtxVec; VecIndex, Index, Len: integer): TMtxVec; overload; (*Conjugate each of Vec2 elements and multiply them with corresponding elements in Vec1. The results are stored in the calling object. Size and properties of the calling object are set implicitly to match Vec1 and Vec2 objects. *) function ConjMul(const Vec1, Vec2: TMtxVec): TMtxVec; overload; (*Conjugate Vec2 elements [Vec2Index]..[Vec2Index+Len-1] and multiply them with corresponding Vec1 elements [Vec1Index]..[Vec1Index+Len-1]. The results are stored in the calling object elements [Index]..[Index+Len-1]. Size and properties of the calling vector must be set explicitly. An exception is raised if is true and array borders are overrun. *) function ConjMul(const Vec1, Vec2: TMtxVec; Vec1Index, Vec2Index, Index, Len: integer): TMtxVec; overload; (* Compute X + Y*yScale *) function AddScaled(const X, Y: TMtxVec; const yScale: Double): TMtxVec; overload; (* Compute X + Y*yScale with complex arguments.*) function AddScaled(const X, Y: TMtxVec; const yScale: TCplx): TMtxVec; overload; (* Compute X + Y*yScale on sub arrays. *) function AddScaled(const X: TMtxVec; xIndex: integer; const Y: TMtxVec; yIndex: integer; const yScale: Double; Index, Len: integer): TMtxVec; overload; (* Compute X + Y*yScale on sub arrays with complex arguments. *) function AddScaled(const X: TMtxVec; xIndex: integer; const Y: TMtxVec; yIndex: integer; const yScale: TCplx; Index, Len: integer): TMtxVec; overload; (* Compute sqr(X + Y*yScale) By making use of yScale, it is also possible to compute the following (at the same or higher speed): (X - Y)^2 = X^2 - 2XY +Y^2 *) function AddScaledSqr(const X, Y: TMtxVec; const yScale: Double): TMtxVec; overload; (* Compute sqr(X + Y*yScale) *) function AddScaledSqr(const X, Y: TMtxVec; const yScale: TCplx): TMtxVec; overload; (* Compute sqr(X + Y*yScale) on sub arrays *) function AddScaledSqr(const X: TMtxVec; xIndex: integer; const Y: TMtxVec; yIndex: integer; const yScale: Double; Index, Len: integer): TMtxVec; overload; (* Compute sqr(X + Y*yScale) on sub arrays *) function AddScaledSqr(const X: TMtxVec; xIndex: integer; const Y: TMtxVec; yIndex: integer; const yScale: TCplx; Index, Len: integer): TMtxVec; overload; (* Compute sqr(X) + sqr(Y)*yScale By making use of yScale, it is also possible to compute the following (at the same or higher speed): X^2 - Y^2 *) function SqrAddScaled(const X, Y: TMtxVec; const yScale: Double): TMtxVec; overload; (* Compute sqr(X) + sqr(Y)*yScale *) function SqrAddScaled(const X, Y: TMtxVec; const yScale: TCplx): TMtxVec; overload; (* Compute sqr(X) + sqr(Y)*yScale on sub arrays *) function SqrAddScaled(const X: TMtxVec; xIndex: integer; const Y: TMtxVec; yIndex: integer; const yScale: Double; Index, Len: integer): TMtxVec; overload; (* Compute sqr(X) + sqr(Y)*yScale on sub arrays *) function SqrAddScaled(const X: TMtxVec; xIndex: integer; const Y: TMtxVec; yIndex: integer; const yScale: TCplx; Index, Len: integer): TMtxVec; overload; (* Compute X + Y + Z *) function Add(const X, Y, Z: TMtxVec): TMtxVec; overload; (* Compute X + Y + Z on sub arrays *) function Add(const X: TMtxVec; xIndex: integer; const Y: TMtxVec; yIndex: integer; const Z: TMtxVec; zIndex: integer; Index, Len: integer): TMtxVec; overload; (* Compute X + Y + Z*zScale *) function AddScaled(const X, Y, Z: TMtxVec; const zScale: Double): TMtxVec; overload; (* Compute X + Y + Z*zScale *) function AddScaled(const X, Y, Z: TMtxVec; const zScale: TCplx): TMtxVec; overload; (* Compute X + Y + Z*zScale on sub arrays *) function AddScaled(const X: TMtxVec; xIndex: integer; const Y: TMtxVec; yIndex: integer; const Z: TMtxVec; zIndex: integer; const zScale: Double; Index, Len: integer): TMtxVec; overload; (* Compute X + Y + Z*zScale on sub arrays *) function AddScaled(const X: TMtxVec; xIndex: integer; const Y: TMtxVec; yIndex: integer; const Z: TMtxVec; zIndex: integer; const zScale: TCplx; Index, Len: integer): TMtxVec; overload; (* Compute X + Y*yScale + Z*zScale *) function AddScaled(const X, Y: TMtxVec; const yScale: Double; const Z: TMtxVec; const zScale: Double): TMtxVec; overload; (* Compute X + Y*yScale + Z*zScale *) function AddScaled(const X, Y: TMtxVec; const yScale: TCplx; const Z: TMtxVec; const zScale: TCplx): TMtxVec; overload; (* Compute X + Y*yScale + Z*zScale on sub arrays *) function AddScaled(const X: TMtxVec; xIndex: integer; const Y: TMtxVec; yIndex: integer; const yScale: Double; const Z: TMtxVec; zIndex: integer; const zScale: Double; Index, Len: integer): TMtxVec; overload; (* Compute X + Y*yScale + Z*zScale on sub arrays *) function AddScaled(const X: TMtxVec; xIndex: integer; const Y: TMtxVec; yIndex: integer; const yScale: TCplx; const Z: TMtxVec; zIndex: integer; const zScale: TCplx; Index, Len: integer): TMtxVec; overload; (* Compute X + Y + zScalar *) function Add(const X, Y: TMtxVec; const Z: Double): TMtxVec; overload; (* Compute X + Y + zScalar *) function Add(const X, Y: TMtxVec; const Z: TCplx): TMtxVec; overload; (* Compute X + Y + zScalar on sub arrays *) function Add(const X: TMtxVec; xIndex: integer; const Y: TMtxVec; yIndex: integer; const Z: Double; Index, Len: integer): TMtxVec; overload; (* Compute X + Y + zScalar on sub arrays *) function Add(const X: TMtxVec; xIndex: integer; const Y: TMtxVec; yIndex: integer; const Z: TCplx; Index, Len: integer): TMtxVec; overload; (* Compute X + Y*yScale + zScalar *) function AddScaledC(const X, Y: TMtxVec; const yScale: Double; const Z: Double): TMtxVec; overload; (* Compute X + Y*yScale + zScalar *) function AddScaledC(const X, Y: TMtxVec; const yScale: TCplx; const Z: TCplx): TMtxVec; overload; (* Compute X + Y*yScale + zScalar on sub arrays *) function AddScaledC(const X: TMtxVec; xIndex: integer; const Y: TMtxVec; yIndex: integer; const yScale: Double; const Z: Double; Index, Len: integer): TMtxVec; overload; (* Compute X + Y*yScale + zScalar on sub arrays *) function AddScaledC(const X: TMtxVec; xIndex: integer; const Y: TMtxVec; yIndex: integer; const yScale: TCplx; const Z: TCplx; Index, Len: integer): TMtxVec; overload; (* Compute X - Y - Z *) function Sub(const X, Y, Z: TMtxVec): TMtxVec; overload; (* Compute X - Y - Z on sub array*) function Sub(const X: TMtxVec; xIndex: integer; const Y: TMtxVec; yIndex: integer;const Z: TMtxVec; zIndex: integer; Index, Len: integer): TMtxVec; overload; (* Compute X - Y*yScale - Z*zScale *) function SubScaled(const X, Y: TMtxVec; const yScale: Double; const Z: TMtxVec; const zScale: Double): TMtxVec; overload; (* Compute X - Y*yScale - Z*zScale *) function SubScaled(const X, Y: TMtxVec; const yScale: TCplx; const Z: TMtxVec; const zScale: TCplx): TMtxVec; overload; (* Compute X - Y*yScale - Z*zScale on sub array*) function SubScaled(const X: TMtxVec; xIndex: integer; const Y: TMtxVec; yIndex: integer; const yScale: Double; const Z: TMtxVec; zIndex: integer; const zScale: Double; Index, Len: integer): TMtxVec; overload; (* Compute X - Y*yScale - Z*zScale on sub array*) function SubScaled(const X: TMtxVec; xIndex: integer; const Y: TMtxVec; yIndex: integer; const yScale: TCplx; const Z: TMtxVec; zIndex: integer; const zScale: TCplx; Index, Len: integer): TMtxVec; overload; (* Compute X - Y - Z*zScale *) function SubScaled(const X, Y, Z: TMtxVec; const zScale: Double): TMtxVec; overload; (* Compute X - Y - Z*zScale *) function SubScaled(const X, Y, Z: TMtxVec; const zScale: TCplx): TMtxVec; overload; (* Compute X - Y - Z*zScale on sub array*) function SubScaled(const X: TMtxVec; xIndex: integer; const Y: TMtxVec; yIndex: integer; const Z: TMtxVec; zIndex: integer; const zScale: Double; Index, Len: integer): TMtxVec; overload; (* Compute X - Y - Z*zScale on sub array*) function SubScaled(const X: TMtxVec; xIndex: integer; const Y: TMtxVec; yIndex: integer; const Z: TMtxVec; zIndex: integer; const zScale: TCplx; Index, Len: integer): TMtxVec; overload; (* Compute X - Y - zScalar *) function Sub(const X, Y: TMtxVec; const Z: Double): TMtxVec; overload; (* Compute X - Y - zScalar *) function Sub(const X, Y: TMtxVec; const Z: TCplx): TMtxVec; overload; (* Compute X - Y - zScalar on sub array*) function Sub(const X: TMtxVec; xIndex: integer; const Y: TMtxVec; yIndex: integer; const Z: Double; Index, Len: integer): TMtxVec; overload; (* Compute X - Y - zScalar on sub array*) function Sub(const X: TMtxVec; xIndex: integer; const Y: TMtxVec; yIndex: integer; const Z: TCplx; Index, Len: integer): TMtxVec; overload; (* Compute X - Y*yScale - zScalar *) function SubScaledC(const X, Y: TMtxVec; const yScale: Double; const Z: Double): TMtxVec; overload; (* Compute X - Y*yScale - zScalar *) function SubScaledC(const X, Y: TMtxVec; const yScale: TCplx; const Z: TCplx): TMtxVec; overload; (* Compute X - Y*yScale - zScalar on sub array*) function SubScaledC(const X: TMtxVec; xIndex: integer; const Y: TMtxVec; yIndex: integer; const yScale: Double; const Z: Double; Index, Len: integer): TMtxVec; overload; (* Compute X - Y*yScale - zScalar on sub array*) function SubScaledC(const X: TMtxVec; xIndex: integer; const Y: TMtxVec; yIndex: integer; const yScale: TCplx; const Z: TCplx; Index, Len: integer): TMtxVec; overload; (* Compute X * Y / Z *) function MulAndDiv(const X, Y, Z: TMtxVec): TMtxVec; overload; (* Compute X * Y / Z on sub array*) function MulAndDiv(const X: TMtxVec; xIndex: integer; const Y: TMtxVec; yIndex: integer; const Z: TMtxVec; zIndex: integer; Index, Len: integer): TMtxVec; overload; (* Compute (X + Y)*Z *) function AddAndMul(const X, Y, Z: TMtxVec): TMtxVec; overload; (* Compute (X + Y)*Z on sub array*) function AddAndMul(const X: TMtxVec; xIndex: Integer; const Y: TMtxVec; yIndex: Integer; const Z: TMtxVec; zIndex: Integer; Index, Len: Integer): TMtxVec; overload; (* Compute (X + Y)*Z*zScale *) function AddAndMul(const X, Y, Z: TMtxVec; const zScale: double): TMtxVec; overload; (* Compute (X + Y)*Z*zScale *) function AddAndMul(const X, Y, Z: TMtxVec; const zScale: TCplx): TMtxVec; overload; (* Compute (X + Y)*Z*zScale on sub array*) function AddAndMul(const X: TMtxVec; xIndex: Integer; const Y: TMtxVec; yIndex: Integer; const Z: TMtxVec; zIndex: Integer; const zScale: double; Index, Len: Integer): TMtxVec; overload; (* Compute (X + Y)*Z*zScale on sub array*) function AddAndMul(const X: TMtxVec; xIndex: Integer; const Y: TMtxVec; yIndex: Integer; const Z: TMtxVec; zIndex: Integer; const zScale: TCplx; Index, Len: Integer): TMtxVec; overload; (* Compute (X + Y*yScale)*Z*zScale *) function AddAndMul(const X, Y: TMtxVec; const yScale: double; const Z: TMtxVec; const zScale: double): TMtxVec; overload; (* Compute (X + Y*yScale)*Z*zScale *) function AddAndMul(const X, Y: TMtxVec;const yScale: TCplx; const Z: TMtxVec;const zScale: TCplx): TMtxVec; overload; (* Compute (X + Y*yScale)*Z*zScale on sub array*) function AddAndMul(const X: TMtxVec; xIndex: Integer; const Y: TMtxVec; yIndex: Integer; const yScale: double; const Z: TMtxVec; zIndex: Integer; const zScale: double; Index, Len: Integer): TMtxVec; overload; (* Compute (X + Y*yScale)*Z*zScale on sub array*) function AddAndMul(const X: TMtxVec; xIndex: Integer; const Y: TMtxVec; yIndex: Integer; const yScale: TCplx; const Z: TMtxVec; zIndex: Integer; const zScale: TCplx; Index, Len: Integer): TMtxVec; overload; (* Compute (X + Y)*zScalar *) function AddAndMul(const X, Y: TMtxVec; const Z: Double): TMtxVec; overload; (* Compute (X + Y)*zScalar *) function AddAndMul(const X, Y: TMtxVec; const Z: TCplx): TMtxVec; overload; (* Compute (X + Y)*zScalar on sub array*) function AddAndMul(const X: TMtxVec; xIndex: Integer; const Y: TMtxVec; yIndex: Integer; const Z: Double; Index, Len: Integer): TMtxVec; overload; (* Compute (X + Y)*zScalar on sub array*) function AddAndMul(const X: TMtxVec; xIndex: Integer; const Y: TMtxVec; yIndex: Integer; const Z: TCplx; Index, Len: Integer): TMtxVec; overload; (* Compute (X + Y*yScale)*zScalar *) function AddAndMul(const X, Y: TMtxVec; const yScale, Z: Double): TMtxVec; overload; (* Compute (X + Y*yScale)*zScalar *) function AddAndMul(const X, Y: TMtxVec; const yScale, Z: TCplx): TMtxVec; overload; (* Compute (X + Y*yScale)*zScalar on sub array*) function AddAndMul(const X: TMtxVec; xIndex: Integer; const Y: TMtxVec; yIndex: Integer; const yScale, Z: Double; Index, Len: Integer): TMtxVec; overload; (* Compute (X + Y*yScale)*zScalar on sub array*) function AddAndMul(const X: TMtxVec; xIndex: Integer; const Y: TMtxVec; yIndex: Integer; const yScale, Z: TCplx; Index, Len: Integer): TMtxVec; overload; (* Compute (X + yScalar)*Z*zScale *) function AddAndMul(const X: TMtxVec; const Y: Double; const Z: TMtxVec; const zScale: Double): TMtxVec; overload; (* Compute (X + yScalar)*Z*zScale *) function AddAndMul(const X: TMtxVec; const Y: TCplx; const Z: TMtxVec; const zScale: TCplx): TMtxVec; overload; (* Compute (X + yScalar)*Z*zScale on sub-array*) function AddAndMul(const X: TMtxVec; xIndex: integer; const Y: Double; const Z: TMtxVec; zIndex: integer; const zScale: Double; Index, Len: integer): TMtxVec; overload; (* Compute (X + yScalar)*Z*zScale on sub-array*) function AddAndMul(const X: TMtxVec; xIndex: integer; const Y: TCplx; const Z: TMtxVec; zIndex: integer; const zScale: TCplx; Index, Len: integer): TMtxVec; overload; (* Compute (X*xScale + yScalar)*Z *) function AddAndMul(const X: TMtxVec; const xScale, Y: Double; const Z: TMtxVec): TMtxVec; overload; (* Compute (X*xScale + yScalar)*Z *) function AddAndMul(const X: TMtxVec; const xScale, Y: TCplx; const Z: TMtxVec): TMtxVec; overload; (* Compute (X*xScale + yScalar)*Z on sub-array*) function AddAndMul(const X: TMtxVec; xIndex: integer; const xScale, Y: Double; const Z: TMtxVec; zIndex: integer; Index, Len: integer): TMtxVec; overload; (* Compute (X*xScale + yScalar)*Z on sub-array*) function AddAndMul(const X: TMtxVec; xIndex: integer; const xScale, Y: TCplx; const Z: TMtxVec; zIndex: integer; Index, Len: integer): TMtxVec; overload; (* Compute (X + yScalar)*Z *) function AddAndMul(const X: TMtxVec; const Y: Double; const Z: TMtxVec): TMtxVec; overload; (* Compute (X + yScalar)*Z *) function AddAndMul(const X: TMtxVec; const Y: TCplx; const Z: TMtxVec): TMtxVec; overload; (* Compute (X + yScalar)*Z on sub-array*) function AddAndMul(const X: TMtxVec; xIndex: integer; const Y: Double; const Z: TMtxVec; zIndex: integer; Index, Len: integer): TMtxVec; overload; (* Compute (X + yScalar)*Z on sub-array*) function AddAndMul(const X: TMtxVec; xIndex: integer; const Y: TCplx; const Z: TMtxVec; zIndex: integer; Index, Len: integer): TMtxVec; overload; (* Compute (X + yScalar)*zScalar *) function AddAndMul(const X: TMtxVec; const Y, Z: Double): TMtxVec; overload; (* Compute (X + yScalar)*zScalar *) function AddAndMul(const X: TMtxVec; const Y, Z: TCplx): TMtxVec; overload; (* Compute (X + yScalar)*zScalar on sub-array*) function AddAndMul(const X: TMtxVec; xIndex: integer; const Y, Z: Double; Index, Len: integer): TMtxVec; overload; (* Compute (X + yScalar)*zScalar on sub-array*) function AddAndMul(const X: TMtxVec; xIndex: integer; const Y, Z: TCplx; Index, Len: integer): TMtxVec; overload; (* Compute (X - Y)*Z *) function SubAndMul(const X, Y, Z: TMtxVec): TMtxVec; overload; (* Compute (X + Y)*Z on sub array*) function SubAndMul(const X: TMtxVec; xIndex: Integer; const Y: TMtxVec; yIndex: Integer; const Z: TMtxVec; zIndex: Integer; Index, Len: Integer): TMtxVec; overload; (* Compute (X - Y)*Z*zScale *) function SubAndMul(const X, Y, Z: TMtxVec; const zScale: double): TMtxVec; overload; (* Compute (X - Y)*Z*zScale *) function SubAndMul(const X, Y, Z: TMtxVec; const zScale: TCplx): TMtxVec; overload; (* Compute (X - Y)*Z*zScale on sub array*) function SubAndMul(const X: TMtxVec; xIndex: Integer; const Y: TMtxVec; yIndex: Integer; const Z: TMtxVec; zIndex: Integer;const zScale: double; Index, Len: Integer): TMtxVec; overload; (* Compute (X - Y)*Z*zScale on sub array*) function SubAndMul(const X: TMtxVec; xIndex: Integer; const Y: TMtxVec; yIndex: Integer; const Z: TMtxVec; zIndex: Integer;const zScale: TCplx; Index, Len: Integer): TMtxVec; overload; (* Compute (X - Y*yScale)*Z*zScale *) function SubAndMul(const X, Y: TMtxVec; const yScale: double; const Z: TMtxVec; const zScale: double): TMtxVec; overload; (* Compute (X - Y*yScale)*Z*zScale *) function SubAndMul(const X, Y: TMtxVec; const yScale: TCplx; const Z: TMtxVec; const zScale: TCplx): TMtxVec; overload; (* Compute (X - Y*yScale)*Z*zScale on sub array*) function SubAndMul(const X: TMtxVec; xIndex: Integer; const Y: TMtxVec; yIndex: Integer; const yScale: double; const Z: TMtxVec; zIndex: Integer; const zScale: double; Index, Len: Integer): TMtxVec; overload; (* Compute (X - Y*yScale)*Z*zScale on sub array*) function SubAndMul(const X: TMtxVec; xIndex: Integer; const Y: TMtxVec; yIndex: Integer; const yScale: TCplx; const Z: TMtxVec; zIndex: Integer; const zScale: TCplx; Index, Len: Integer): TMtxVec; overload; (* Compute (X - Y)*zScalar *) function SubAndMul(const X, Y: TMtxVec; const Z: Double): TMtxVec; overload; (* Compute (X - Y)*zScalar *) function SubAndMul(const X, Y: TMtxVec; const Z: TCplx): TMtxVec; overload; (* Compute (X - Y)*zScalar on sub array*) function SubAndMul(const X: TMtxVec; xIndex: Integer; const Y: TMtxVec; yIndex: Integer; const Z: Double; Index, Len: Integer): TMtxVec; overload; (* Compute (X - Y)*zScalar on sub array*) function SubAndMul(const X: TMtxVec; xIndex: Integer; const Y: TMtxVec; yIndex: Integer; const Z: TCplx; Index, Len: Integer): TMtxVec; overload; (* Compute (X - Y*yScale)*zScalar *) function SubAndMul(const X, Y: TMtxVec; const yScale, Z: Double): TMtxVec; overload; (* Compute (X - Y*yScale)*zScalar *) function SubAndMul(const X, Y: TMtxVec; const yScale, Z: TCplx): TMtxVec; overload; (* Compute (X - Y*yScale)*zScalar on sub array*) function SubAndMul(const X: TMtxVec; xIndex: Integer; const Y: TMtxVec; yIndex: Integer; const yScale, Z: Double; Index, Len: Integer): TMtxVec; overload; (* Compute (X - Y*yScale)*zScalar on sub array*) function SubAndMul(const X: TMtxVec; xIndex: Integer; const Y: TMtxVec; yIndex: Integer; const yScale, Z: TCplx; Index, Len: Integer): TMtxVec; overload; (* Compute (X - yScalar)*Z*zScale *) function SubAndMul(const X: TMtxVec; const Y: Double; const Z: TMtxVec; const zScale: Double): TMtxVec; overload; (* Compute (X - yScalar)*Z*zScale *) function SubAndMul(const X: TMtxVec; const Y: TCplx; const Z: TMtxVec; const zScale: TCplx): TMtxVec; overload; (* Compute (X - yScalar)*Z*zScale on sub-array*) function SubAndMul(const X: TMtxVec; xIndex: integer; const Y: Double; const Z: TMtxVec; zIndex: integer; const zScale: Double; Index, Len: integer): TMtxVec; overload; (* Compute (X - yScalar)*Z*zScale on sub-array*) function SubAndMul(const X: TMtxVec; xIndex: integer; const Y: TCplx; const Z: TMtxVec; zIndex: integer; const zScale: TCplx; Index, Len: integer): TMtxVec; overload; (* Compute (X*xScale - yScalar)*Z *) function SubAndMul(const X: TMtxVec; const xScale, Y: Double; const Z: TMtxVec): TMtxVec; overload; (* Compute (X*xScale - yScalar)*Z *) function SubAndMul(const X: TMtxVec; const xScale, Y: TCplx; const Z: TMtxVec): TMtxVec; overload; (* Compute (X*xScale - yScalar)*Z on sub-array*) function SubAndMul(const X: TMtxVec; xIndex: integer; const xScale, Y: Double; const Z: TMtxVec; zIndex: integer; Index, Len: integer): TMtxVec; overload; (* Compute (X*xScale - yScalar)*Z on sub-array*) function SubAndMul(const X: TMtxVec; xIndex: integer; const xScale, Y: TCplx; const Z: TMtxVec; zIndex: integer; Index, Len: integer): TMtxVec; overload; (* Compute (X - yScalar)*Z *) function SubAndMul(const X: TMtxVec; const Y: Double; const Z: TMtxVec): TMtxVec; overload; (* Compute (X - yScalar)*Z *) function SubAndMul(const X: TMtxVec; const Y: TCplx; const Z: TMtxVec): TMtxVec; overload; (* Compute (X - yScalar)*Z on sub-array*) function SubAndMul(const X: TMtxVec; xIndex: integer; const Y: Double; const Z: TMtxVec; zIndex: integer; Index, Len: integer): TMtxVec; overload; (* Compute (X - yScalar)*Z on sub-array*) function SubAndMul(const X: TMtxVec; xIndex: integer; const Y: TCplx; const Z: TMtxVec; zIndex: integer; Index, Len: integer): TMtxVec; overload; (* Compute (X - yScalar)*zScalar *) function SubAndMul(const X: TMtxVec; const Y, Z: Double): TMtxVec; overload; (* Compute (X - yScalar)*zScalar *) function SubAndMul(const X: TMtxVec; const Y, Z: TCplx): TMtxVec; overload; (* Compute (X - yScalar)*zScalar on sub-array*) function SubAndMul(const X: TMtxVec; xIndex: integer; const Y, Z: Double; Index, Len: integer): TMtxVec; overload; (* Compute (X - yScalar)*zScalar on sub-array*) function SubAndMul(const X: TMtxVec; xIndex: integer; const Y, Z: TCplx; Index, Len: integer): TMtxVec; overload; (* Compute X*Y + Z *) function MulAndAdd(const X, Y, Z: TMtxVec): TMtxVec; overload; (* Compute X*Y + Z on sub array*) function MulAndAdd(const X: TMtxVec; xIndex: Integer; const Y: TMtxVec; yIndex: Integer; const Z: TMtxVec; zIndex: Integer; Index, Len: Integer): TMtxVec; overload; (* Compute X*Y*xyScale + Z *) function MulAndAdd(const X, Y: TMtxVec; const xyScale: double; const Z: TMtxVec): TMtxVec; overload; (* Compute X*Y*xyScale + Z *) function MulAndAdd(const X, Y: TMtxVec; const xyScale: TCplx; const Z: TMtxVec): TMtxVec; overload; (* Compute X*Y*xyScale + Z on sub array*) function MulAndAdd(const X: TMtxVec; xIndex: Integer; const Y: TMtxVec; yIndex: Integer; const xyScale: double; const Z: TMtxVec; zIndex: Integer; Index, Len: Integer): TMtxVec; overload; (* Compute X*Y*xyScale + Z on sub array*) function MulAndAdd(const X: TMtxVec; xIndex: Integer; const Y: TMtxVec; yIndex: Integer; const xyScale: TCplx; const Z: TMtxVec; zIndex: Integer; Index, Len: Integer): TMtxVec; overload; (* Compute X*Y + Z*zScale *) function MulAndAdd(const X, Y, Z: TMtxVec; const zScale: double): TMtxVec; overload; (* Compute X*Y + Z*zScale *) function MulAndAdd(const X, Y, Z: TMtxVec; const zScale: TCplx): TMtxVec; overload; (* Compute X*Y + Z*zScale on sub array*) function MulAndAdd(const X: TMtxVec; xIndex: Integer; const Y: TMtxVec; yIndex: Integer; const Z: TMtxVec; zIndex: Integer; const zScale: double; Index, Len: Integer): TMtxVec; overload; (* Compute X*Y + Z*zScale on sub array*) function MulAndAdd(const X: TMtxVec; xIndex: Integer; const Y: TMtxVec; yIndex: Integer; const Z: TMtxVec; zIndex: Integer; const zScale: TCplx; Index, Len: Integer): TMtxVec; overload; (* Compute X*Y + zScalar *) function MulAndAdd(const X, Y: TMtxVec; const Z: Double): TMtxVec; overload; (* Compute X*Y + zScalar *) function MulAndAdd(const X, Y: TMtxVec; const Z: TCplx): TMtxVec; overload; (* Compute X*Y + zScalar on sub array*) function MulAndAdd(const X: TMtxVec; xIndex: Integer; const Y: TMtxVec; yIndex: Integer; const Z: Double; Index, Len: Integer): TMtxVec; overload; (* Compute X*Y + zScalar on sub array*) function MulAndAdd(const X: TMtxVec; xIndex: Integer; const Y: TMtxVec; yIndex: Integer; const Z: TCplx; Index, Len: Integer): TMtxVec; overload; (* Compute X*Y - Z *) function MulAndSub(const X, Y, Z: TMtxVec): TMtxVec; overload; (* Compute X*Y + Z on sub array*) function MulAndSub(const X: TMtxVec; xIndex: Integer; const Y: TMtxVec; yIndex: Integer; const Z: TMtxVec; zIndex: Integer; Index, Len: Integer): TMtxVec; overload; (* Compute X*Y*xyScale - Z *) function MulAndSub(const X, Y: TMtxVec; const xyScale: double; const Z: TMtxVec): TMtxVec; overload; (* Compute X*Y*xyScale - Z *) function MulAndSub(const X, Y: TMtxVec; const xyScale: TCplx; const Z: TMtxVec): TMtxVec; overload; (* Compute X*Y*xyScale + Z on sub array*) function MulAndSub(const X: TMtxVec; xIndex: Integer; const Y: TMtxVec; yIndex: Integer; const xyScale: double; const Z: TMtxVec; zIndex: Integer; Index, Len: Integer): TMtxVec; overload; (* Compute X*Y*xyScale + Z on sub array*) function MulAndSub(const X: TMtxVec; xIndex: Integer; const Y: TMtxVec; yIndex: Integer; const xyScale: TCplx; const Z: TMtxVec; zIndex: Integer; Index, Len: Integer): TMtxVec; overload; (* Compute X*Y - Z*zScale *) function MulAndSub(const X, Y, Z: TMtxVec; const zScale: double): TMtxVec; overload; (* Compute X*Y - Z*zScale *) function MulAndSub(const X, Y, Z: TMtxVec; const zScale: TCplx): TMtxVec; overload; (* Compute X*Y + Z*zScale on sub array*) function MulAndSub(const X: TMtxVec; xIndex: Integer; const Y: TMtxVec; yIndex: Integer; const Z: TMtxVec; zIndex: Integer; const zScale: double; Index, Len: Integer): TMtxVec; overload; (* Compute X*Y + Z*zScale on sub array*) function MulAndSub(const X: TMtxVec; xIndex: Integer; const Y: TMtxVec; yIndex: Integer; const Z: TMtxVec; zIndex: Integer; const zScale: TCplx; Index, Len: Integer): TMtxVec; overload; (* Compute X*Y - zScalar *) function MulAndSub(const X, Y: TMtxVec; const Z: Double): TMtxVec; overload; (* Compute X*Y - zScalar *) function MulAndSub(const X, Y: TMtxVec; const Z: TCplx): TMtxVec; overload; (* Compute X*Y - zScalar on sub array*) function MulAndSub(const X: TMtxVec; xIndex: Integer; const Y: TMtxVec; yIndex: Integer; const Z: Double; Index, Len: Integer): TMtxVec; overload; (* Compute X*Y - zScalar on sub array*) function MulAndSub(const X: TMtxVec; xIndex: Integer; const Y: TMtxVec; yIndex: Integer; const Z: TCplx; Index, Len: Integer): TMtxVec; overload; (* Compute X/Y + Z *) function DivAndAdd(const X, Y, Z: TMtxVec): TMtxVec; overload; (* Compute X/Y + Z on sub array*) function DivAndAdd(const X: TMtxVec; xIndex: Integer; const Y: TMtxVec; yIndex: Integer; const Z: TMtxVec; zIndex: Integer; Index, Len: Integer): TMtxVec; overload; (* Compute X/Y*xyScale + Z *) function DivAndAdd(const X, Y: TMtxVec; const xyScale: double; const Z: TMtxVec): TMtxVec; overload; (* Compute X/Y*xyScale + Z *) function DivAndAdd(const X, Y: TMtxVec; const xyScale: TCplx; const Z: TMtxVec): TMtxVec; overload; (* Compute X/Y*xyScale + Z on sub array*) function DivAndAdd(const X: TMtxVec; xIndex: Integer; const Y: TMtxVec; yIndex: Integer; const xyScale: double; const Z: TMtxVec; zIndex: Integer; Index, Len: Integer): TMtxVec; overload; (* Compute X/Y*xyScale + Z on sub array*) function DivAndAdd(const X: TMtxVec; xIndex: Integer; const Y: TMtxVec; yIndex: Integer; const xyScale: TCplx; const Z: TMtxVec; zIndex: Integer; Index, Len: Integer): TMtxVec; overload; (* Compute X/Y + Z*zScale *) function DivAndAdd(const X, Y, Z: TMtxVec; const zScale: double): TMtxVec; overload; (* Compute X/Y + Z*zScale *) function DivAndAdd(const X, Y, Z: TMtxVec; const zScale: TCplx): TMtxVec; overload; (* Compute X/Y + Z*zScale on sub array*) function DivAndAdd(const X: TMtxVec; xIndex: Integer; const Y: TMtxVec; yIndex: Integer; const Z: TMtxVec; zIndex: Integer; const zScale: double; Index, Len: Integer): TMtxVec; overload; (* Compute X/Y + Z*zScale on sub array*) function DivAndAdd(const X: TMtxVec; xIndex: Integer; const Y: TMtxVec; yIndex: Integer; const Z: TMtxVec; zIndex: Integer; const zScale: TCplx; Index, Len: Integer): TMtxVec; overload; (* Compute X/Y + zScalar *) function DivAndAdd(const X, Y: TMtxVec; const Z: Double): TMtxVec; overload; (* Compute X/Y + zScalar *) function DivAndAdd(const X, Y: TMtxVec; const Z: TCplx): TMtxVec; overload; (* Compute X/Y + zScalar on sub array*) function DivAndAdd(const X: TMtxVec; xIndex: Integer; const Y: TMtxVec; yIndex: Integer; const Z: Double; Index, Len: Integer): TMtxVec; overload; (* Compute X/Y + zScalar on sub array*) function DivAndAdd(const X: TMtxVec; xIndex: Integer; const Y: TMtxVec; yIndex: Integer; const Z: TCplx; Index, Len: Integer): TMtxVec; overload; (* Compute X/Y - Z *) function DivAndSub(const X, Y, Z: TMtxVec): TMtxVec; overload; (* Compute X/Y - Z on sub array*) function DivAndSub(const X: TMtxVec; xIndex: Integer; const Y: TMtxVec; yIndex: Integer; const Z: TMtxVec; zIndex: Integer; Index, Len: Integer): TMtxVec; overload; (* Compute X/Y*xyScale - Z *) function DivAndSub(const X, Y: TMtxVec; const xyScale: double; const Z: TMtxVec): TMtxVec; overload; (* Compute X/Y*xyScale - Z *) function DivAndSub(const X, Y: TMtxVec; const xyScale: TCplx; const Z: TMtxVec): TMtxVec; overload; (* Compute X/Y*xyScale - Z on sub array*) function DivAndSub(const X: TMtxVec; xIndex: Integer; const Y: TMtxVec; yIndex: Integer; const xyScale: double; const Z: TMtxVec; zIndex: Integer; Index, Len: Integer): TMtxVec; overload; (* Compute X/Y*xyScale - Z on sub array*) function DivAndSub(const X: TMtxVec; xIndex: Integer; const Y: TMtxVec; yIndex: Integer; const xyScale: TCplx; const Z: TMtxVec; zIndex: Integer; Index, Len: Integer): TMtxVec; overload; (* Compute X/Y - Z*zScale *) function DivAndSub(const X, Y, Z: TMtxVec; const zScale: double): TMtxVec; overload; (* Compute X/Y - Z*zScale *) function DivAndSub(const X, Y, Z: TMtxVec; const zScale: TCplx): TMtxVec; overload; (* Compute X/Y - Z*zScale on sub array*) function DivAndSub(const X: TMtxVec; xIndex: Integer; const Y: TMtxVec; yIndex: Integer; const Z: TMtxVec; zIndex: Integer; const zScale: double; Index, Len: Integer): TMtxVec; overload; (* Compute X/Y - Z*zScale on sub array*) function DivAndSub(const X: TMtxVec; xIndex: Integer; const Y: TMtxVec; yIndex: Integer; const Z: TMtxVec; zIndex: Integer; const zScale: TCplx; Index, Len: Integer): TMtxVec; overload; (* Compute X/Y - zScalar *) function DivAndSub(const X, Y: TMtxVec; const Z: Double): TMtxVec; overload; (* Compute X/Y - zScalar *) function DivAndSub(const X, Y: TMtxVec; const Z: TCplx): TMtxVec; overload; (* Compute X/Y - zScalar on sub array*) function DivAndSub(const X: TMtxVec; xIndex: Integer; const Y: TMtxVec; yIndex: Integer; const Z: Double; Index, Len: Integer): TMtxVec; overload; (* Compute X/Y - zScalar on sub array*) function DivAndSub(const X: TMtxVec; xIndex: Integer; const Y: TMtxVec; yIndex: Integer; const Z: TCplx; Index, Len: Integer): TMtxVec; overload; (* Compute X*xScale + Y*yScale *) function AddScaled(const X: TMtxVec; const xScale: Double; const Y: TMtxVec; const yScale: Double): TMtxVec; overload; (* Compute X*xScale + Y*yScale *) function AddScaled(const X: TMtxVec; const xScale: TCplx; const Y: TMtxVec; const yScale: TCplx): TMtxVec; overload; (* Compute X*xScale + Y*yScale on sub arrays *) function AddScaled(const X: TMtxVec; xIndex: integer; const xScale: Double; const Y: TMtxVec; yIndex: integer; const yScale: Double; Index, Len: integer): TMtxVec; overload; (* Compute X*xScale + Y*yScale on sub arrays *) function AddScaled(const X: TMtxVec; xIndex: integer; const xScale: TCplx; const Y: TMtxVec; yIndex: integer; const yScale: TCplx; Index, Len: integer): TMtxVec; overload; (* Compute sqr(X*xScale + Y*yScale) *) function AddScaledSqr(const X: TMtxVec; const xScale: Double; const Y: TMtxVec; const yScale: Double): TMtxVec; overload; (* Compute sqr(X*xScale + Y*yScale) *) function AddScaledSqr(const X: TMtxVec; const xScale: TCplx; const Y: TMtxVec; const yScale: TCplx): TMtxVec; overload; (* Compute sqr(X*xScale + Y*yScale) on sub arrays *) function AddScaledSqr(const X: TMtxVec; xIndex: integer; const xScale: Double; const Y: TMtxVec; yIndex: integer; const yScale: Double; Index, Len: integer): TMtxVec; overload; (* Compute sqr(X*xScale + Y*yScale) on sub arrays *) function AddScaledSqr(const X: TMtxVec; xIndex: integer; const xScale: TCplx; const Y: TMtxVec; yIndex: integer; const yScale: TCplx; Index, Len: integer): TMtxVec; overload; (* Compute sqr(X)*xScale + sqr(Y)*yScale *) function SqrAddScaled(const X: TMtxVec; const xScale: Double; const Y: TMtxVec; const yScale: Double): TMtxVec; overload; (* Compute sqr(X)*xScale + sqr(Y)*yScale *) function SqrAddScaled(const X: TMtxVec; const xScale: TCplx; const Y: TMtxVec; const yScale: TCplx): TMtxVec; overload; (* Compute sqr(X)*xScale + sqr(Y)*yScale on sub arrays *) function SqrAddScaled(const X: TMtxVec; xIndex: integer; const xScale: Double; const Y: TMtxVec; yIndex: integer; const yScale: Double; Index, Len: integer): TMtxVec; overload; (* Compute sqr(X)*xScale + sqr(Y)*yScale on sub arrays *) function SqrAddScaled(const X: TMtxVec; xIndex: integer; const xScale: TCplx; const Y: TMtxVec; yIndex: integer; const yScale: TCplx; Index, Len: integer): TMtxVec; overload; (* Compute X*xScale + Y*yScale + Z*zScale *) function AddScaled(const X: TMtxVec; const xScale: Double; const Y: TMtxVec; const yScale: Double; const Z: TMtxVec; const zScale: Double): TMtxVec; overload; (* Compute X*xScale + Y*yScale + Z*zScale *) function AddScaled(const X: TMtxVec; const xScale: TCplx; const Y: TMtxVec; const yScale: TCplx; const Z: TMtxVec; const zScale: TCplx): TMtxVec; overload; (* Compute X*xScale + Y*yScale + Z*zScale on sub arrays *) function AddScaled(const X: TMtxVec; xIndex: integer; const xScale: Double; const Y: TMtxVec; yIndex: integer; const yScale: Double; const Z: TMtxVec; zIndex: integer; const zScale: Double; Index, Len: integer): TMtxVec; overload; (* Compute X*xScale + Y*yScale + Z*zScale on sub arrays *) function AddScaled(const X: TMtxVec; xIndex: integer; const xScale: TCplx; const Y: TMtxVec; yIndex: integer; const yScale: TCplx; const Z: TMtxVec; zIndex: integer; const zScale: TCplx; Index, Len: integer): TMtxVec; overload; (* Compute X*xScale + Y*yScale + zScalar *) function AddScaledC(const X: TMtxVec; const xScale: Double; const Y: TMtxVec; const yScale: Double; const Z: Double): TMtxVec; overload; (* Compute X*xScale + Y*yScale + zScalar *) function AddScaledC(const X: TMtxVec; const xScale: TCplx; const Y: TMtxVec; const yScale: TCplx; const Z: TCplx): TMtxVec; overload; (* Compute X*xScale + Y*yScale + z on sub arrays *) function AddScaledC(const X: TMtxVec; xIndex: integer; const xScale: Double; const Y: TMtxVec; yIndex: integer; const yScale: Double; const Z: Double; Index, Len: integer): TMtxVec; overload; (* Compute X*xScale + Y*yScale + z on sub arrays *) function AddScaledC(const X: TMtxVec; xIndex: integer; const xScale: TCplx; const Y: TMtxVec; yIndex: integer; const yScale: TCplx; const Z: TCplx; Index, Len: integer): TMtxVec; overload; (* Compute X*xScale - Y*yScale - Z*zScale *) function SubScaled(const X: TMtxVec; const xScale: Double; const Y: TMtxVec; const yScale: Double; const Z: TMtxVec; const zScale: Double): TMtxVec; overload; (* Compute X*xScale - Y*yScale - Z*zScale *) function SubScaled(const X: TMtxVec; const xScale: TCplx; const Y: TMtxVec; const yScale: TCplx; const Z: TMtxVec; const zScale: TCplx): TMtxVec; overload; (* Compute X*xScale - Y*yScale - zScalar *) function SubScaledC(const X: TMtxVec; const xScale: Double; const Y: TMtxVec; const yScale: Double; const Z: Double): TMtxVec; overload; (* Compute X*xScale - Y*yScale - zScalar *) function SubScaledC(const X: TMtxVec; const xScale: TCplx; const Y: TMtxVec; const yScale: TCplx; const Z: TCplx): TMtxVec; overload; (* Compute X*xScale - Y*yScale - Z*zScale on sub array*) function SubScaled(const X: TMtxVec; xIndex: integer; const xScale: Double; const Y: TMtxVec; yIndex: integer; const yScale: Double; const Z: TMtxVec; zIndex: integer; const zScale: Double; Index, Len: integer): TMtxVec; overload; (* Compute X*xScale - Y*yScale - Z*zScale on sub array*) function SubScaled(const X: TMtxVec; xIndex: integer; const xScale: TCplx; const Y: TMtxVec; yIndex: integer; const yScale: TCplx; const Z: TMtxVec; zIndex: integer; const zScale: TCplx; Index, Len: integer): TMtxVec; overload; (* Compute X*xScale - Y*yScale - zScalar on sub array*) function SubScaledC(const X: TMtxVec; xIndex: integer; const xScale: Double; const Y: TMtxVec; yIndex: integer; const yScale: Double; const Z: Double; Index, Len: integer): TMtxVec; overload; (* Compute X*xScale - Y*yScale - zScalar on sub array*) function SubScaledC(const X: TMtxVec; xIndex: integer; const xScale: TCplx; const Y: TMtxVec; yIndex: integer; const yScale: TCplx; const Z: TCplx; Index, Len: integer): TMtxVec; overload; (* Compute X*Y*Z The following expression would also run at the same or higher speed, when passing X also for the Z parameter: X^2*Y *) function Mul(const X, Y,Z: TMtxVec): TMtxVec; overload; (* Compute X*Y*zScalar The following expression would also run at the same or higher speed, when passing X also for the Z parameter: X^2*zScalar *) function Mul(const X,Y: TMtxVec; const Z: Double): TMtxVec; overload; (* Compute X*Y*zScalar The following expression would also run at the same or higher speed, when passing X also for the Z parameter: X^2*zScalar *) function Mul(const X,Y: TMtxVec; const Z: TCplx): TMtxVec; overload; (* Compute X*Y*Z on sub array*) function Mul(const X: TMtxVec; xIndex: integer; const Y: TMtxVec; yIndex: integer; const Z: TMtxVec; zIndex: integer; Index, Len: integer): TMtxVec; overload; (* Compute X*Y*zScalar on sub array*) function Mul(const X: TMtxVec; xIndex: integer; const Y: TMtxVec; yIndex: integer; const Z: Double; Index, Len: integer): TMtxVec; overload; (* Compute X*Y*zScalar on sub array*) function Mul(const X: TMtxVec; xIndex: integer; const Y: TMtxVec; yIndex: integer; const Z: TCplx; Index, Len: integer): TMtxVec; overload; (* Compute X / (Y*Z) The following expression would also run at the same or higher speed, when passing Y also for the Z parameter: X / (Y^2) *) function Divide(const X, Y, Z: TMtxVec): TMtxVec; overload; (* Compute X/( Y*Z ) on sub array*) function Divide(const X: TMtxVec; xIndex: integer; const Y: TMtxVec; yIndex: integer; const Z: TMtxVec; zIndex: integer; Index, Len: integer): TMtxVec; overload; (* Compute X / (Y*zScale) *) function DivideC(const X, Y: TMtxVec; const Z: Double): TMtxVec; overload; (* Compute X / (Y*zScale) *) function DivideC(const X, Y: TMtxVec; const Z: TCplx): TMtxVec; overload; (* Compute X / (Y*zScalar) on sub array*) function DivideC(const X: TMtxVec; xIndex: integer; const Y: TMtxVec; yIndex: integer; const Z: Double; Index, Len: integer): TMtxVec; overload; (* Compute X / (Y*zScalar) on sub array*) function DivideC(const X: TMtxVec; xIndex: integer; const Y: TMtxVec; yIndex: integer; const Z: TCplx; Index, Len: integer): TMtxVec; overload; (* Compute X * Y * xyScale / Z The following expression would also run at the same or higher speed, when passing X also for the Y parameter: X^2 * xyScale/ Z *) function MulAndDiv(const X, Y: TMtxVec; const xyScale: Double; const Z: TMtxVec): TMtxVec; overload; (* Compute X * Y * xyScale / Z The following expression would also run at the same or higher speed, when passing X also for the Y parameter: X^2 * xyScale/ Z *) function MulAndDiv(const X, Y: TMtxVec; const xyScale: TCplx; const Z: TMtxVec): TMtxVec; overload; (* Compute X * Y * xyScale / Z on sub array*) function MulAndDiv(const X: TMtxVec; xIndex: integer; const Y: TMtxVec; yIndex: integer; const xyScale: Double; const Z: TMtxVec; zIndex: integer; Index, Len: integer): TMtxVec; overload; (* Compute X * Y * xyScale / Z on sub array*) function MulAndDiv(const X: TMtxVec; xIndex: integer; const Y: TMtxVec; yIndex: integer; const xyScale: TCplx; const Z: TMtxVec; zIndex: integer; Index, Len: integer): TMtxVec; overload; (* Compute X * Y / zScalar *) function MulAndDiv(const X, Y: TMtxVec; const Z: Double): TMtxVec; overload; (* Compute X * Y / zScalar *) function MulAndDiv(const X, Y: TMtxVec; const Z: TCplx): TMtxVec; overload; (* Compute X * Y / zScalar on sub array*) function MulAndDiv(const X: TMtxVec; xIndex: integer; const Y: TMtxVec; yIndex: integer; const Z: Double; Index, Len: integer): TMtxVec; overload; (* Compute X * Y / zScalar on sub array*) function MulAndDiv(const X: TMtxVec; xIndex: integer; const Y: TMtxVec; yIndex: integer; const Z: TCplx; Index, Len: integer): TMtxVec; overload; (* Compute xScalar / (Y*Z) *) function Divide(const X: Double; const Y, Z: TMtxVec): TMtxVec; overload; (* Compute xScalar / (Y*Z) *) function Divide(const X: TCplx; const Y, Z: TMtxVec): TMtxVec; overload; (* Compute xScalar / (Y*Z) on sub array*) function Divide(const X: Double; const Y: TMtxVec; yIndex: integer; const Z: TMtxVec; zIndex: integer; Index, Len: integer): TMtxVec; overload; (* Compute xScalar / (Y*Z) on sub array*) function Divide(const X: TCplx; const Y: TMtxVec; yIndex: integer; const Z: TMtxVec; zIndex: integer; Index, Len: integer): TMtxVec; overload; (* Compute (X*xScale + Y*yScale)*Z*zScale The following is also possible at the same or higher speed: X^2 * xScale + XY * yScale by passing X also for the Z parameter. *) function AddAndMul(const X: TMtxVec; const xScale: Double; const Y: TMtxVec; const yScale: Double; const Z: TMtxVec; const zScale: Double): TMtxVec; overload; (* Compute (X*xScale + Y*yScale)*Z*zScale The following is also possible at the same or higher speed: X^2 * xScale + XY * yScale by passing X also for the Z parameter. *) function AddAndMul(const X: TMtxVec; const xScale: TCplx; const Y: TMtxVec; const yScale: TCplx; const Z: TMtxVec; const zScale: TCplx): TMtxVec; overload; (* Compute (X*xScale + Y*yScale)*Z*Scale on sub array*) function AddAndMul(const X: TMtxVec; xIndex: Integer; const xScale: Double; const Y: TMtxVec; yIndex: Integer; const yScale: Double; const Z: TMtxVec; zIndex: Integer; const zScale: Double; Index, Len: Integer): TMtxVec; overload; (* Compute (X*xScale + Y*yScale)*Z*Scale on sub array*) function AddAndMul(const X: TMtxVec; xIndex: Integer; const xScale: TCplx; const Y: TMtxVec; yIndex: Integer; const yScale: TCplx; const Z: TMtxVec; zIndex: Integer; const zScale: TCplx; Index, Len: Integer): TMtxVec; overload; (* Compute (X*xScale + Y*yScale)*zScalar*) function AddAndMul(const X: TMtxVec; const xScale: Double; const Y: TMtxVec; const yScale: Double; const Z: Double): TMtxVec; overload; (* Compute (X*xScale + Y*yScale)*zScalar*) function AddAndMul(const X: TMtxVec; const xScale: TCplx; const Y: TMtxVec; const yScale: TCplx; const Z: TCplx): TMtxVec; overload; (* Compute (X*xScale + Y*yScale)*zScalar on sub array*) function AddAndMul(const X: TMtxVec; xIndex: Integer; const xScale: Double; const Y: TMtxVec; yIndex: Integer; const yScale: Double; const Z: Double; Index, Len: Integer): TMtxVec; overload; (* Compute (X*xScale + Y*yScale)*zScalar on sub array*) function AddAndMul(const X: TMtxVec; xIndex: Integer; const xScale: TCplx; const Y: TMtxVec; yIndex: Integer; const yScale: TCplx; const Z: TCplx; Index, Len: Integer): TMtxVec; overload; (* Compute (X* xScale + yScalar)*Z*zScale*) function AddAndMul(const X: TMtxVec; const xScale: Double; const Y: Double; const Z: TMtxVec; const zScale: Double): TMtxVec; overload; (* Compute (X* xScale + yScalar)*Z*zScale*) function AddAndMul(const X: TMtxVec; const xScale: TCplx; const Y: TCplx; const Z: TMtxVec; const zScale: TCplx): TMtxVec; overload; (* Compute (X* xScale + yScalar)*Z*zScale on sub-array*) function AddAndMul(const X: TMtxVec; xIndex: integer; const xScale: Double; const Y: Double; const Z: TMtxVec; zIndex: integer; const zScale: Double; Index, Len: integer): TMtxVec; overload; (* Compute (X* xScale + yScalar)*Z*zScale on sub-array*) function AddAndMul(const X: TMtxVec; xIndex: integer; const xScale: TCplx; const Y: TCplx; const Z: TMtxVec; zIndex: integer; const zScale: TCplx; Index, Len: integer): TMtxVec; overload; (* Compute (X*xScale + yScalar)*zScalar*) function AddAndMul(const X: TMtxVec; const xScale: Double; const Y, Z: Double): TMtxVec; overload; (* Compute (X*xScale + yScalar)*zScalar*) function AddAndMul(const X: TMtxVec; const xScale: TCplx; const Y, Z: TCplx): TMtxVec; overload; (* Compute (X*xScale + yScalar)*zScalar on sub array*) function AddAndMul(const X: TMtxVec; xIndex: integer; const xScale: Double; const Y, Z: Double; Index, Len: integer): TMtxVec; overload; (* Compute (X*xScale + yScalar)*zScalar on sub array*) function AddAndMul(const X: TMtxVec; xIndex: integer; const xScale: TCplx; const Y, Z: TCplx; Index, Len: integer): TMtxVec; overload; (* Compute (X*xScale - Y*yScale)*Z*zScale*) function SubAndMul(const X: TMtxVec; const xScale: Double; const Y: TMtxVec; const yScale: Double; const Z: TMtxVec; const zScale: Double): TMtxVec; overload; (* Compute (X*xScale - Y*yScale)*Z*zScale*) function SubAndMul(const X: TMtxVec; const xScale: TCplx; const Y: TMtxVec; const yScale: TCplx; const Z: TMtxVec; const zScale: TCplx): TMtxVec; overload; (* Compute (X*xScale - Y*yScale)*Z*Scale on sub array*) function SubAndMul(const X: TMtxVec; xIndex: Integer; const xScale: Double; const Y: TMtxVec; yIndex: Integer; const yScale: Double; const Z: TMtxVec; zIndex: Integer; const zScale: Double; Index, Len: Integer): TMtxVec; overload; (* Compute (X*xScale - Y*yScale)*Z*Scale on sub array*) function SubAndMul(const X: TMtxVec; xIndex: Integer; const xScale: TCplx; const Y: TMtxVec; yIndex: Integer; const yScale: TCplx; const Z: TMtxVec; zIndex: Integer; const zScale: TCplx; Index, Len: Integer): TMtxVec; overload; (* Compute (X*xScale - Y*yScale)*zScalar*) function SubAndMul(const X: TMtxVec; const xScale: Double; const Y: TMtxVec; const yScale: Double; const Z: Double): TMtxVec; overload; (* Compute (X*xScale - Y*yScale)*zScalar*) function SubAndMul(const X: TMtxVec; const xScale: TCplx; const Y: TMtxVec; const yScale: TCplx; const Z: TCplx): TMtxVec; overload; (* Compute (X*xScale - Y*yScale)*zScalar on sub array*) function SubAndMul(const X: TMtxVec; xIndex: Integer; const xScale: Double; const Y: TMtxVec; yIndex: Integer; const yScale: Double; const Z: Double; Index, Len: Integer): TMtxVec; overload; (* Compute (X*xScale - Y*yScale)*zScalar on sub array*) function SubAndMul(const X: TMtxVec; xIndex: Integer; const xScale: TCplx; const Y: TMtxVec; yIndex: Integer; const yScale: TCplx; const Z: TCplx; Index, Len: Integer): TMtxVec; overload; (* Compute (X*xScale - yScalar)*Z*zScale*) function SubAndMul(const X: TMtxVec; const xScale: Double; const Y: Double; const Z: TMtxVec; const zScale: Double): TMtxVec; overload; (* Compute (X*xScale - yScalar)*Z*zScale*) function SubAndMul(const X: TMtxVec; const xScale: TCplx; const Y: TCplx; const Z: TMtxVec; const zScale: TCplx): TMtxVec; overload; (* Compute (X*xScale - yScalar)*Z*zScale on sub-array*) function SubAndMul(const X: TMtxVec; xIndex: integer; const xScale: Double; const Y: Double; const Z: TMtxVec; zIndex: integer; const zScale: Double; Index, Len: integer): TMtxVec; overload; (* Compute (X*xScale - yScalar)*Z*zScale on sub-array*) function SubAndMul(const X: TMtxVec; xIndex: integer; const xScale: TCplx; const Y: TCplx; const Z: TMtxVec; zIndex: integer; const zScale: TCplx; Index, Len: integer): TMtxVec; overload; (* Compute (X*xScale - yScalar)*zScalar*) function SubAndMul(const X: TMtxVec; const xScale: Double; const Y, Z: Double): TMtxVec; overload; (* Compute (X*xScale - yScalar)*zScalar*) function SubAndMul(const X: TMtxVec; const xScale: TCplx; const Y, Z: TCplx): TMtxVec; overload; (* Compute (X*xScale - yScalar)*zScalar on sub array*) function SubAndMul(const X: TMtxVec; xIndex: integer; const xScale: Double; const Y, Z: Double; Index, Len: integer): TMtxVec; overload; (* Compute (X*xScale - yScalar)*zScalar on sub array*) function SubAndMul(const X: TMtxVec; xIndex: integer; const xScale: TCplx; const Y, Z: TCplx; Index, Len: integer): TMtxVec; overload; (* Compute (X*Y)*xyScale + Z*zScale The following expression would also run at the same or higher speed, when passing X also for the Y parameter: X^2*xyScale + Z*zScale *) function MulAndAdd(const X: TMtxVec; const Y: TMtxVec; const xyScale: Double; const Z: TMtxVec; const zScale: Double): TMtxVec; overload; (* Compute (X*Y)*xyScale + Z*zScale on sub array*) function MulAndAdd(const X: TMtxVec; xIndex: Integer; const Y: TMtxVec; yIndex: Integer; const xyScale: Double; const Z: TMtxVec; zIndex: Integer; const zScale: Double; Index, Len: Integer): TMtxVec; overload; (* Compute (X*Y)*xyScale + Z*zScale The following expression would also run at the same or higher speed, when passing X also for the Y parameter: X^2*xyScale + Z*zScale *) function MulAndAdd(const X: TMtxVec; const Y: TMtxVec; const xyScale: TCplx; const Z: TMtxVec; const zScale: TCplx): TMtxVec; overload; (* Compute (X*Y)*xyScale + Z*zScale on sub array*) function MulAndAdd(const X: TMtxVec; xIndex: Integer; const Y: TMtxVec; yIndex: Integer; const xyScale: TCplx; const Z: TMtxVec; zIndex: Integer;const zScale: TCplx; Index, Len: Integer): TMtxVec; overload; (* Compute (X*Y)*xyScale + zScalar*) function MulAndAdd(const X: TMtxVec; const Y: TMtxVec; const xyScale: Double; const Z: Double): TMtxVec; overload; (* Compute (X*Y)*xyScale + zScalar on sub array The following expression would also run at the same or higher speed, when passing X also for the Y parameter: X^2*xyScale + zScale *) function MulAndAdd(const X: TMtxVec; xIndex: Integer; const Y: TMtxVec; yIndex: Integer; const xyScale: Double; const Z: Double; Index, Len: Integer): TMtxVec; overload; (* Compute (X*Y)*xyScale + zScalar*) function MulAndAdd(const X: TMtxVec; const Y: TMtxVec; const xyScale: TCplx; const Z: TCplx): TMtxVec; overload; (* Compute (X*Y)*xyScale + zScalar on sub array The following expression would also run at the same or higher speed, when passing X also for the Y parameter: X^2*xyScale + zScale *) function MulAndAdd(const X: TMtxVec; xIndex: Integer; const Y: TMtxVec; yIndex: Integer; const xyScale: TCplx; const Z: TCplx; Index, Len: Integer): TMtxVec; overload; (* Compute (X*yScalar) + zScalar*) function MulAndAdd(const X: TMtxVec; const Y, Z: Double): TMtxVec; overload; (* Compute (X*yScalar) + zScalar*) function MulAndAdd(const X: TMtxVec; xIndex: integer; const Y, Z: Double; Index, Len: integer): TMtxVec; overload; (* Compute (X*yScalar) + zScalar*) function MulAndAdd(const X: TMtxVec; const Y, Z: TCplx): TMtxVec; overload; (* Compute (X*yScalar) + zScalar*) function MulAndAdd(const X: TMtxVec; xIndex: integer; const Y, Z: TCplx; Index, Len: integer): TMtxVec; overload; (* Compute (X*Y)*xyScale - Z*zScale*) function MulAndSub(const X: TMtxVec; const Y: TMtxVec; const xyScale: Double; const Z: TMtxVec; const zScale: Double): TMtxVec; overload; (* Compute (X*Y)*xyScale - Z*zScale*) function MulAndSub(const X: TMtxVec; const Y: TMtxVec; const xyScale: TCplx; const Z: TMtxVec; const zScale: TCplx): TMtxVec; overload; (* Compute (X*Y)*xyScale - Z*zScale on sub array*) function MulAndSub(const X: TMtxVec; xIndex: Integer; const Y: TMtxVec; yIndex: Integer; const xyScale: Double; const Z: TMtxVec; zIndex: Integer; const zScale: Double; Index, Len: Integer): TMtxVec; overload; (* Compute (X*Y)*xyScale - Z*zScale on sub array*) function MulAndSub(const X: TMtxVec; xIndex: Integer; const Y: TMtxVec; yIndex: Integer; const xyScale: TCplx; const Z: TMtxVec; zIndex: Integer; const zScale: TCplx; Index, Len: Integer): TMtxVec; overload; (* Compute (X*Y)*xyScale - zScalar*) function MulAndSub(const X: TMtxVec; const Y: TMtxVec; const xyScale, Z: Double): TMtxVec; overload; (* Compute (X*Y)*xyScale - zScalar*) function MulAndSub(const X: TMtxVec; const Y: TMtxVec; const xyScale, Z: TCplx): TMtxVec; overload; (* Compute (X*Y)*xyScale - zScalar on sub array*) function MulAndSub(const X: TMtxVec; xIndex: Integer; const Y: TMtxVec; yIndex: Integer; const xyScale: Double; const Z: Double; Index, Len: Integer): TMtxVec; overload; (* Compute (X*Y)*xyScale - zScalar on sub array*) function MulAndSub(const X: TMtxVec; xIndex: Integer; const Y: TMtxVec; yIndex: Integer; const xyScale: TCplx; const Z: TCplx; Index, Len: Integer): TMtxVec; overload; (* Compute X*yScalar - Z*zScale*) function MulAndSub(const X: TMtxVec; const Y: Double; const Z: TMtxVec; const zScale: Double): TMtxVec; overload; (* Compute X*yScalar - Z*zScale*) function MulAndSub(const X: TMtxVec; const Y: TCplx; const Z: TMtxVec; const zScale: TCplx): TMtxVec; overload; (* Compute X*yScalar - Z*zScale on sub array*) function MulAndSub(const X: TMtxVec; xIndex: integer; const Y: Double; const Z: TMtxVec; zIndex: integer; const zScale: Double; Index, Len: integer): TMtxVec; overload; (* Compute X*yScalar - Z*zScale on sub array*) function MulAndSub(const X: TMtxVec; xIndex: integer; const Y: TCplx; const Z: TMtxVec; zIndex: integer; const zScale: TCplx; Index, Len: integer): TMtxVec; overload; (* Compute (X / Y)*xyScale + Z*zScale The following expression would also run at the same or higher speed, when passing Z also for the Y parameter: (X / Z) * xyScale + Z * zScale *) function DivAndAdd(const X: TMtxVec; const Y: TMtxVec; const xyScale: Double; const Z: TMtxVec; const zScale: Double): TMtxVec; overload; (* Compute (X / Y)*xyScale + Z*zScale on sub array*) function DivAndAdd(const X: TMtxVec; xIndex: Integer; const Y: TMtxVec; yIndex: Integer; const xyScale: Double; const Z: TMtxVec; zIndex: Integer; const zScale: Double; Index, Len: Integer): TMtxVec; overload; (* Compute (X / Y)*xyScale + Z*zScale The following expression would also run at the same or higher speed, when passing Z also for the Y parameter: (X / Z) * xyScale + Z * zScale *) function DivAndAdd(const X: TMtxVec; const Y: TMtxVec; const xyScale: TCplx; const Z: TMtxVec; const zScale: TCplx): TMtxVec; overload; (* Compute (X / Y)*xyScale + Z*zScale on sub array*) function DivAndAdd(const X: TMtxVec; xIndex: Integer; const Y: TMtxVec; yIndex: Integer; const xyScale: TCplx; const Z: TMtxVec; zIndex: Integer; const zScale: TCplx; Index, Len: Integer): TMtxVec; overload; (* Compute (X / Y) * xyScale + zScalar*) function DivAndAdd(const X: TMtxVec; const Y: TMtxVec; const xyScale: Double; const Z: Double): TMtxVec; overload; (* Compute (X / Y) * xyScale + zScalar*) function DivAndAdd(const X: TMtxVec; xIndex: Integer; const Y: TMtxVec; yIndex: Integer; const xyScale: Double; const Z: Double; Index, Len: Integer): TMtxVec; overload; (* Compute (X / Y) * xyScale + zScalar*) function DivAndAdd(const X: TMtxVec; const Y: TMtxVec; const xyScale: TCplx; const Z: TCplx): TMtxVec; overload; (* Compute (X / Y) * xyScale + zScalar*) function DivAndAdd(const X: TMtxVec; xIndex: Integer; const Y: TMtxVec; yIndex: Integer; const xyScale: TCplx; const Z: TCplx; Index, Len: Integer): TMtxVec; overload; (* Compute (X / Y) * xyScale - Z*zScale *) function DivAndSub(const X: TMtxVec; const Y: TMtxVec; const xyScale: Double; const Z: TMtxVec; const zScale: Double): TMtxVec; overload; (* Compute (X / Y) * xyScale - Z on sub array*) function DivAndSub(const X: TMtxVec; xIndex: Integer; const Y: TMtxVec; yIndex: Integer; const xyScale: Double; const Z: TMtxVec; zIndex: Integer; const zScale: Double; Index, Len: Integer): TMtxVec; overload; (* Compute (X / Y) * xyScale - Z*zScale *) function DivAndSub(const X: TMtxVec; const Y: TMtxVec; const xyScale: TCplx; const Z: TMtxVec; const zScale: TCplx): TMtxVec; overload; (* Compute (X / Y) * xyScale - Z on sub array*) function DivAndSub(const X: TMtxVec; xIndex: Integer; const Y: TMtxVec; yIndex: Integer; const xyScale: TCplx; const Z: TMtxVec; zIndex: Integer; const zScale: TCplx; Index, Len: Integer): TMtxVec; overload; (* Compute (X / Y) * xyScale - zScalar*) function DivAndSub(const X: TMtxVec; const Y: TMtxVec; const xyScale: Double; const Z: Double): TMtxVec; overload; (* Compute (X / Y) * xyScale - zScalar on sub array*) function DivAndSub(const X: TMtxVec; xIndex: Integer; const Y: TMtxVec; yIndex: Integer; const xyScale: Double; const Z: Double; Index, Len: Integer): TMtxVec; overload; (* Compute (X / Y) * xyScale - zScalar*) function DivAndSub(const X: TMtxVec; const Y: TMtxVec; const xyScale: TCplx; const Z: TCplx): TMtxVec; overload; (* Compute (X / Y) * xyScale - zScalar on sub array*) function DivAndSub(const X: TMtxVec; xIndex: Integer; const Y: TMtxVec; yIndex: Integer; const xyScale: TCplx; const Z: TCplx; Index, Len: Integer): TMtxVec; overload; (*Cumulative sum. Calculate the cumulative sum for calling object elements [Index]..[Index+Len-1] in-place. An exception is raised if is true and array borders are overrun. var a: Vector; begin a.SetIt(false,[1,2,3,4]; a.CumSum; // a = [1,3,6,10] end; *) function CumSum(Index, Len: Integer): TMtxVec; overload; (*Calculate the cumulative sum for Vec elements [VecIndex]..[VecIndex+Len-1] and store the results in calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. Exception is raised if property is True and array borders are overrun. *) function CumSum(const Vec: TMtxVec; VecIndex,Index,Len: Integer): TMtxVec; overload; (*Calculate the cumulative product for all Vec elements. The size must be set by the user. The function will store all powers of Value: Values[Index + i] := IntPower(Value, i) at corresponding array Index *) function CumProduct(Value: Double; Index, Len: integer): TMtxVec; overload; (*Calculate the cumulative product for all Vec elements. The size must be set by the user. The function will store all powers of Value: CValues[Index + i] := IntPower(Value, i) at corresponding array Index *) function CumProduct(const Value: TCplx; Index, Len: integer): TMtxVec; overload; (*Calculate the cumulative product for all Vec elements. The size must be set by the user. The function will store all powers of Value in Values[i] := IntPower(Value, i) at corresponding array index. *) function CumProduct(Value: Double): TMtxVec; overload; (*Calculate the cumulative product for all Vec elements. The size must be set by the user. The function will store all powers of Value in CValues[i] := IntPower(Value, i) at corresponding array index. *) function CumProduct(const Value: TCplx): TMtxVec; overload; (*The forward discrete cosine transform (DCT). Calculates the forward discrete cosine transform (DCT) of the Vec and writes the result in the calling vector. If Vec.Length is a power of 2, the function uses an efficient algorithm that is significantly faster than the direct computation of DCT. For other values of Vec Length, this function uses the direct formulas given below; however, the symmetry of cosine function is taken into account, which allows to perform about half of the multiplication operations in the formulas. In the following definition of DCT, N=Vec.Length and V is the calling vector: var a,b: Vector; begin a.SetIt(False,[1,-2,3,4]); b.DCT(a); end; *) function DCT(const Vec: TMtxVec; VecIndex, Index, Len: integer): TMtxVec; overload; (*Difference. Calculate the difference for Vec elements [VecIndex]..[VecIndex+Len-1] and store the results in the calling object elements [Index]..[Index+Len-1]. Size and properties of the calling vector must be set explicitly. The following formula is used to calculate the difference: An exception is raised if is True and array borders are overrun or underrun. *) function Difference(const Vec: TMtxVec; VecIndex, Index, Len: integer): TMtxVec; overload; (*Vector division. Divide each of Vec elements with corresponding elements in the calling object. Size and property of the calling object are set automatically. The result is stored in the calling object. The threshold parameter is used to prevent against division by zero and numerical instabilities in the follow on processing. All values of Vec smaller than Threshold will be replaced with Threshold. *) function Divide(const Vec: TMtxVec; Threshold: double): TMtxVec; overload; (*Divide each of Vec elements with corresponding elements in the calling object. Store the result in the calling object. Size and property of the calling object are set automatically. *) function Divide(const Vec: TMtxVec; Threshold: double; VecIndex, Index, Len: integer): TMtxVec; overload; (*Divide each of Vec1 elements with corresponding elements in the Vec2 object. Store the result in the calling vector. *) function Divide(const Vec1, Vec2: TMtxVec; Threshold: double): TMtxVec; overload; (*Divide Vec1 elements [Vec1Index]...[Vec1Index+Len-1] with corresponding elements [Vec2Index]...[Vec2Index+Len-1] from the Vec object. Store the result in the calling vector [Index]...[Index+Len-1]. *) function Divide(const Vec1, Vec2: TMtxVec; Threshold: double; Vec1Index, Vec2Index, Index, Len: integer): TMtxVec; overload; (*Divide each of Num elements with corresponding elements in Den. Size and property of the calling object are set automatically. The result is stored in the calling object. Note The result of division by zero will be the INF constant. Division of zero by zero will result in NAN. *) function Divide(Num, Den: TMtxVec): TMtxVec; overload; (*Divide each of calling vector elements with corresponding elements in the Vec object. Size and property of the calling object are set automatically. The result is stored in the calling object. Note The result of division by zero will be the INF constant. Division of zero by zero will result in NAN. *) function Divide(const Vec: TMtxVec): TMtxVec; overload; (*Divide calling vector elements [Index]...[Index+Len-1] with corresponding elements [VecIndex]...[VecIndex+Len-1] from the Vec object. Store the result in the calling vector. The of the calling vector is not changed. An exception is raised if is True and array borders are overrun or underrun. Note The result of division by zero will be the INF constant. Division of zero by zero will result in NAN. *) function Divide(const Vec: TMtxVec; VecIndex, Index, Len: integer): TMtxVec; overload; (*Divide [NumIndex]..[NumIndex+Len-1] Num elements with [DenIndex]..[DenIndex+Len-1] elements in Den. Store result in the calling vector at positions [Index]..[Index+Len-1] and property of the calling object are not changed. An exception is raised if is True and array borders are overrun or underrun. Note The result of division by zero will be the INF constant. Division of zero by zero will result in NAN. *) function Divide(Num, Den: TMtxVec; NumIndex, DenIndex, Index, Len: integer): TMtxVec; overload; (*Divide Value with elements of the calling object and store the result in the calling object.*) function DivideBy(Value: double): TMtxVec; overload; (*Divide complex Value with elements of the calling object and store the result in the calling object. Calling vector will be extended to complex, if the calling vector is real. *) function DivideBy(Value: TCplx): TMtxVec; overload; (*Divide Value with elements [Index]...[Index+Len-1] from the calling object. Store the result in the calling object at position [Index]...[Index+Len-1]. An exception will be raised if is True and array borders are overrun or underrun. *) function DivideBy(Value: double; Index, Len: integer): TMtxVec; overload; (*Divide complex Value with elements [Index]...[Index+Len-1] from the calling object. Store the result in the calling object at position [Index]...[Index+Len-1]. Calling vector will be extended to complex, if the calling vector is real. An exception will be raised if is True and array borders are overrun or underrun. *) function DivideBy(Value: TCplx; Index, Len: integer): TMtxVec; overload; (*Divide Value with elements from Vec and store the result in the corresponding elements of the calling object. Size and properties of the calling object are set automatically. *) function DivideBy(Value: double; Vec: TMtxVec): TMtxVec; overload; (*Divide complex Value with elements from Vec and store the result in the corresponding elements of the calling object. Size of the calling object is set automatically. property of the calling object is set to True. *) function DivideBy(Value: TCplx; Vec: TMtxVec): TMtxVec; overload; (*Divide Value with Vec elements [VecIndex]..[VecIndes+Len-1]. Store the result in the elements [Index]..[Index+Len-1] of the calling object. Size of the calling object is not changed. An exception will be raised if is True and array borders are overrun or underrun. property of the calling object is set implicitly. *) function DivideBy(Value: double; Vec: TMtxVec; VecIndex, Index, Len: integer): TMtxVec; overload; (*Divide complex Value with elements [VecIndex]..[VecIndes+Len-1] from Vec. Store the result in the elements [Index]..[Index+Len-1] of the calling object. Size of the calling object is not changed. An exception will be raised if is True and array borders are overrun or underrun. property of the calling object is set to True. *) function DivideBy(Value: TCplx; Vec: TMtxVec; VecIndex, Index, Len: integer): TMtxVec; overload; (*Scalar product of two real arrays. 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: Both objects must be of equal size. If they are not, the method will return the dot product of the largest sub-array. var a,b: Vector; prod: double; begin a.SetIt(False,[1,2,3,4]); b.SetIt(False,[5,6,7,8]); prod := a.DotProd(b); // = 1*5 + 2*6 + * 3*7 + 4*8 end; *) function DotProd(const Vec: TMtxVec): double; overload; (*Returns the scalar product between Vec elements [VecIndex]..[VecIndex+Len-1] and calling object elements [Index]..[Index+Len-1]. An exception is raised if Vec and calling object property is True. An exception is raised if is True and array borders are overrun or underrun. *) function DotProd(const Vec: TMtxVec; VecIndex, Index, Len: integer): double; overload; (*Scalar product of two complex arrays. Calculates the dot product (scalar value) of the calling object and Vec object and returns a complex scalar value. An exception is raised if calling or Vec object property is false. The dot product is defined by the equation: Note Both objects must be of equal size. If they are not, the method will return the dot product of the largest sub-array. var a,b: Vector; prod: TCplx; begin a.SetIt(True,[1,2,3,4]); b.SetIt(True,[5,6,7,8]); prod := a.DotProdc(b); //= (1+2i)*(5+6i)+(3+4i)*(7+8i) end; *) function DotProdc(const Vec: TMtxVec): TCplx; overload; (*Returns the scalar product between Vec (complex) elements [VecIndex]..[VecIndex+Len-1] and calling object (complex) elements [Index]..[Index+Len-1]. An exception is raised if Vec and calling object property is False. An exception is raised if is True and array borders are overrun or underrun. *) function DotProdc(const Vec: TMtxVec; VecIndex, Index, Len: integer): TCplx; overload; (*Returns the scalar product between Vec and calling object complex elements. If ConjVec is True, scalar product between calling object and conjugated Vec object elements is calculated. An exception is raised if Vec and calling object property is False. *) function DotProdc(const Vec: TMtxVec; ConjVec: boolean): TCplx; overload; (*Returns the scalar product between Vec (complex) elements [VecIndex]..[VecIndex+Len-1] and calling object (complex) elements [Index]..[Index+Len-1]. If ConjVec is True, scalar product between calling object and conjugated Vec object elements is calculated. An exception is raised if Vec and calling object property is False. An exception is raised if is True and array borders are overrun or underrun. *) function DotProdc(const Vec: TMtxVec; ConjVec: boolean; VecIndex, Index, Len: integer): TCplx; overload; (*Downsamples object values. Copy only every Factor sample from Src starting at SrcIndex up to Len to the calling object starting at Index. The phase parameter determines the initial sample offset. Phase must be less then Factor. Size and properties of the calling object are set implicitly. An exception is raised if array borders are overrun/underrun. *) function DownSample(const Src: TMtxVec; Factor, SrcIndex, Index, Len: integer; Phase: integer = 0): TMtxVec; overload; (*Fast Furier Transformation (FFT) from complex to complex or from real to complex. Calculate the FFT from Vec elements [VecIndex]..[VecIndex+Len-1] and store the results in the calling object elements [Index]..[Index+Len-1]. The Len parameter must be a power of two. Size and properties of the calling object must be set explicitly. An exception is raised if is True and array borders are overrun. If Vec is complex, then complex to complex forward FFT is performed. If Vec is real, then real to complex forward FFT is performed. Note This is the indexed version of the FFT routine . Look there for more information on FFT parameters and storage requirements. *) function FFT(const Vec: TMtxVec; ConjugateExtend: boolean; VecIndex, Index, Len: integer): TMtxVec; overload; (*The forward Fast Fourier Transformation (FFT) from real to complex. Calculate the FFT from real Vec elements [VecIndex]..[VecIndex+Len-1] and store the results in the calling object elements [Index]..[Index+Len-1]. The Len parameter must not be a power of two. Size and properties of the calling object must be set explicitly. An exception is raised if is True and Vec is not complex or if array borders are overrun. Note This is the indexed version of the FFT routine . Look there for more information on FFT parameters and storage requirements. *) function FFTFromReal(const Vec: TMtxVec; VecIndex, Index, Len: integer): TMtxVec; overload; (*The inverse discrete cosine transform (DCT). Calculate the inverse discrete cosine transform (DCT) from Vec elements [VecIndex]..[VecIndex+Len-1] and store the results in the calling object elements [Index]..[Index+Len-1]. The Len parameter must be the power of two. Size and properties of the calling vector must be set explicitly. An exception is raised if is True and array borders are overrun. *) function IDCT(const Vec: TMtxVec; VecIndex, Index, Len: integer): TMtxVec; overload; (*The inverse FFT from complex to complex. Calculate the inverse FFT from Vec elements [VecIndex]..[VecIndex+Len-1] and store the results in the calling object elements [Index]..[Index+Len-1]. The Len parameter must be the power of two. Size and properties of the calling vector must be set explicitly. An exception is raised if is True and array borders are overrun. Note This is the indexed version of the FFT routine . Look there For more information on FFT parameters and storage requirements. *) function IFFT(const Vec: TMtxVec; VecIndex, Index, Len: integer; NoScale: boolean=False): TMtxVec; overload; (*The inverse FFT from complex to real. Calculate the inverse FFT from Vec elements [VecIndex]..[VecIndex+Len-1] and store the results in the calling object elements [Index]..[Index+Len-1]. The Len parameter must not be a power of two. Size and properties of the calling object must be set explicitly. An exception is raised if is True and array borders are overrun. Note This is the indexed version of the FFT routine . Look there for more information on FFT parameters and storage requirements. *) function IFFTToReal(const Vec: TMtxVec; VecIndex, Index, Len: integer; NoScale: boolean=False): TMtxVec; overload; (*The Kurtosis (fourth central momentum). Calculate the calling object kurtosis by using mean value AMean and standard deviation AStdDev. Kurtosis is the fourth central moment, divided by fourth power of standard deviation: *) function Kurtosis(AMean, AStdDev: double): double; overload; (*Calculate the kurtosis for elements [Index]..[Index+Len-1]. An exception is raised if is True and array borders are overrun. The AMean and AStdDev passed as parameters must be computed from the same elements (Index, Len) as the Kurtosis itself. *) function Kurtosis(AMean, AStdDev: double; Index, Len: integer): double; overload; (*Median. Calculate median value for all calling object elements. var a: Vector; c: double; begin a.SetIt(False,[1,2,3,4]); c := a.Median; end; *) function Median: double; overload; (*Calculate median value for calling vector elements [Index]..[Index+Len-1]. An exception is raised if is true and array borders are overrun. *) function Median(Index: integer; Len: integer): double; overload; (*Vector multiplication. Multiply each of Vec elements with corresponding elements in the calling object. Size and property of the calling object are set automatically. The result is stored in the calling object. *) function Mul(const Vec: TMtxVec): TMtxVec; overload; (*Multiply Vec elements [VecIndex]..[VecIndex+Len-1] with calling object elements [Index]..[Index+Len-1] in-place. An exception is raised if Vec and calling object property do not match or if array borders are overrun/underrun. *) function Mul(const Vec: TMtxVec; VecIndex, Index, Len: integer): TMtxVec; overload; (*Multiply all Vec1 elements with corresponding Vec2 elements. Store the results in calling object. Size and property of calling object are adjusted automatically to match those of Vec1 and Vec2. An exception is raised if Vec1 and Vec2 size and property do not match. *) function Mul(const Vec1, Vec2: TMtxVec): TMtxVec; overload; (*Multiply Vec1 elements [Vec1Index]..[Vec1Index+Len-1] with Vec2 object elements [Vec2Index]..[Vec2Index+Len-1] and store the results in calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if is True and array borders are overrun or underrun. *) function Mul(const Vec1, Vec2: TMtxVec; Vec1Index, Vec2Index, Index, Len: integer): TMtxVec; overload; (*Vectorised maximum. Compares Vec values with corresponding elements in the calling object and stores the bigger value in Self. Size and property of the calling object are set automatically. Supports real value data only. *) function MaxEvery(const Vec: TMtxVec): TMtxVec; overload; (*Compare Vec elements [VecIndex]..[VecIndex+Len-1] with calling object elements [Index]..[Index+Len-1] and store result in Self. An exception is raised if Vec and calling object property do not match or if array borders are overrun/underrun. Supports real value data only. *) function MaxEvery(const Vec: TMtxVec; VecIndex, Index, Len: integer): TMtxVec; overload; (*Compare all Vec1 elements with corresponding Vec2 elements and store bigger value in Self. Stores the results in to the calling object. Size and property of calling object are adjusted automatically to match those of Vec1 and Vec2. An exception is raised if Vec1 and Vec2 size and property do not match. Supports real value data only. *) function MaxEvery(const Vec1, Vec2: TMtxVec): TMtxVec; overload; (*Compare Vec1 elements [Vec1Index]..[Vec1Index+Len-1] with Vec2 object elements [Vec2Index]..[Vec2Index+Len-1] and store bigger value in Self. Stores the results in to the calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if ConditionCheck is True and array borders are overrun or underrun. *) function MaxEvery(const Vec1, Vec2: TMtxVec; Vec1Index, Vec2Index, Index, Len: integer): TMtxVec; overload; (*Vectorised minimum. Compares Vec values with corresponding elements in the calling object and stores the smaller value in Self. Size and property of the calling object are set automatically. Supports real value data only. *) function MinEvery(const Vec: TMtxVec): TMtxVec; overload; (*Compare Vec elements [VecIndex]..[VecIndex+Len-1] with calling object elements [Index]..[Index+Len-1] and store result in Self. An exception is raised if Vec and calling object property do not match or if array borders are overrun/underrun. Supports real value data only. *) function MinEvery(const Vec: TMtxVec; VecIndex, Index, Len: integer): TMtxVec; overload; (*Compare all Vec1 elements with corresponding Vec2 elements and store the smaller value in Self. Stores the results in to the calling object. Size and property of calling object are adjusted automatically to match those of Vec1 and Vec2. An exception is raised if Vec1 and Vec2 size and property do not match. Supports real value data only. *) function MinEvery(const Vec1, Vec2: TMtxVec): TMtxVec; overload; (*Compare Vec1 elements [Vec1Index]..[Vec1Index+Len-1] with Vec2 object elements [Vec2Index]..[Vec2Index+Len-1] and store the smaller value in Self. Stores the results in to the calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if ConditionCheck is True and array borders are overrun or underrun. *) function MinEvery(const Vec1, Vec2: TMtxVec; Vec1Index, Vec2Index, Index, Len: integer): TMtxVec; overload; (*Maximum value. Returns the maximum value of all calling object elements. The result is a real value. An exception is raised is calling object is true. var a: Vector; b: double; begin a.SetIt(False,[1,2,3,4]); b := a.Max; // b = 4 end; *) function Max: double; overload; (*Returns the maximum value from calling object elements [Index]..[Index+Len-1]. The result is a real value. An exception is raised if calling object property is true or array borders are overrun. *) function Max(Index,Len: integer): double; overload; (*Calculate the maximum value from calling object elements [Index]..[Index+Len-1]. The result AMean is a real value. An exception is raised if calling object property is true or array borders are overrun. *) procedure Max(out AMax: double; Index,Len: integer); overload; (*Calculate the maximum value of all calling object elements. The AMax parameter returns the maximum value. The AIndex parameter returns the Index of maximum value. An exception is raised if calling object property is true. *) procedure Max(out AMax: double; out AIndex: integer); overload; (*Calculate the maximum value of calling object elements [Index]..[Index+Len-1]. The AMax parameter returns the maximum value. The AIndex parameter returns the Index of maximum value. An exception is raised if calling object property is true or array borders are overrud/underrun. *) procedure Max(out AMax: double; out AIndex: integer; Index, Len: integer); overload; (*Maximum value. Returns the maximum value of all calling object complex elements. Complex elements are first compared by the amplitude and then by the argument. An exception is raised if calling object is False. *) function Maxc: TCplx; overload; (*Returns the maximum value of calling object complex elements [Index]..[Index+Len-1]. The result is a complex value. Complex elements are first compared by the amplitude and then by the argument. An exception is raised if calling object property is False or array borders are overrud/underrun. *) function Maxc(Index,Len: integer): TCplx; overload; (*Calculate the maximum value of calling object complex elements [Index]..[Index+Len-1]. The AMax parameter returns complex maximum value. Returns the Index of maximum value. Complex elements are first compared by the amplitude and then by the argument. The AIndex parameter returns the Index of maximum value. An exception is raised if calling object property is False or array borders are overrud/underrun. *) function Maxc(out AMax: TCplx; Index, Len: integer): integer; overload; (*Maximum and minimum value in a single pass. Calculates the maximum and minimum value of all calling object elements in a single pass. Maximum value is stored in AMax parameter, minimum value is stored in AMin parameter. Use this method if you require minimum AND maximum value. *) procedure MaxMin(out AMax,AMin: double); overload; (*Calculates the maximum and minimum value of calling object elements [Index]..[Index+Len-1]. Maximum value is stored in AMax parameter, minimum value is stored in AMin parameter. An exception is raised if calling object property is true or array borders are overrud/underrun. *) procedure MaxMin(out AMax,AMin: double; Index, Len: integer); overload; (*Calculates the maximum and minimum value of all calling object elements. Maximum value is returned in AMax parameter, minimum value in AMin parameter. The MaxIdx parameter returns the Index of maximum value. The MinIdx parameter returns the Index of minimum value. An exception is raised if calling object property is true. *) procedure MaxMin(out AMax: double; out MaxIdx: integer; out AMin: double; out MinIdx: integer); overload; (*Calculates the maximum and minimum value of calling object elements [Index]..[Index+Len-1]. Maximum value is returned in AMax parameter, minimum value in AMin parameter. The MaxIdx parameter returns the Index of maximum value. The MinIdx parameter returns the Index of minimum value. An exception is raised if calling object property is true or if array borders are overrud/underrun. *) procedure MaxMin(out AMax: double; out MaxIdx: integer; out AMin: double; out MinIdx: integer; Index, Len: integer); overload; (*Mean value. Calculate the mean value of all calling object elements. The result is a real value. An exception is raised if calling object property is true. var a: Vector; b: double; begin a.SetIt(False,[1,2,3,4]); b := a.Mean; // b = 2.5 end; *) function Mean: double; overload; (*Returns real mean value from calling object elements [Index]..[Index+Len-1]. An exception is raised if calling object property is true or array borders are overrun. *) function Mean(Index, Len: integer): double; overload; (*Calculate the mean value from calling object elements [Index]..[Index+Len-1]. The result AMean is a real value. An exception is raised if calling object property is true or array borders are overrun/underrun. *) procedure Mean(out AMean: double; Index, Len: integer); overload; (*Mean value. Returns the mean value of all calling object complex elements. The result is a complex value. An exception is raised is calling object is False. *) function Meanc: TCplx; overload; (*Returns complex mean value from calling object complex elements [Index]..[Index+Len-1]. An exception is raised if calling object property is False or array borders are overrun/underrun. *) function Meanc(Index, Len: integer): TCplx; overload; (*Calculate the mean value from all calling object complex elements. The result AMean is a complex value. An exception is raised if calling object property is False. *) procedure Meanc(out AMean: TCplx); overload; (*Calculate the mean value from calling object complex elements [Index]..[Index+Len-1]. The result AMean is a complex value. An exception is raised if calling object property is False or array borders are overrun/underrun. *) procedure Meanc(out AMean: TCplx; Index, Len: integer); overload; (*Minimum value. Calculate the minimum value of all calling object elements. The result is a real value. An exception is raised if calling object property is true. var a: Vector; b: double; begin a.SetIt(False,[1,2,3,4]); b := a.Min; // b = 1 end; *) function Min: double; overload; (*Calculate the minimum value from calling object elements [Index]..[Index+Len-1]. The result is a real value. An exception is raised if calling object property is true or array borders are overrun. *) function Min(Index,Len: integer): double; overload; (*Calculate the minimum value from calling object elements [Index]..[Index+Len-1]. The result AMin is a real value. An exception is raised if calling object property is true or array borders are overrun. *) procedure Min(out AMin: double; Index,Len: integer); overload; (*Calculate the minimum value of calling object elements [Index]..[Index+Len-1]. The AMin parameter returns the minimum value. The AIndex parameter returns the Index of minimum value. An exception is raised if calling object property is true or array borders are overrud/underrun. *) procedure Min(out AMin: double; out AIndex: Integer; Index, Len: integer); overload; (*Calculate the minimum value of all calling object elements. The AMin parameter returns the minimum value. The AIndex parameter returns the Index of minimum value. An exception is raised if calling object property is true. *) procedure Min(out AMin: double; out AIndex: integer); overload; (*Minimum value. Returns the minimum value of all calling object complex elements. Complex elements are first compared by the amplitude and then by the argument. An exception is raised if calling object is False. *) function Minc: TCplx; overload; (*Returns the minimum value of calling object complex elements [Index]..[Index+Len-1]. The result is a complex value. Complex elements are first compared by the amplitude and then by the argument. An exception is raised if calling object property is False or array borders are overrud/underrun. *) function Minc(Index,Len: integer): TCplx; overload; (*Calculate the minimum value of calling object complex elements [Index]..[Index+Len-1]. The AMin parameter returns complex minimum value. Returns the Index of minimum value. Complex elements are first compared by the amplitude and then by the argument. An exception is raised if calling object property is False or array borders are overrun/underrun. *) function Minc(out AMin: TCplx; Index, Len: integer): integer; overload; (*The C-norm. Calculates the C norm: ||V-Vec||, where V is the calling vector. If the NormC is called without any parameters, the NormC calculates the norm of the calling vector. The C norm of ||V-Vec|| is defined by the formula: If RelativeError is true then the computed norm is divided by the norm of V, and the function returns the "relative error": var a,b: Vector; c: double; begin a.SetIt(False,[1,2,3,4]); b.SetIt(False,[4,3,2,1]); c := a.NormC(b,False); end; *) function NormC(const Vec: TDenseMtxVec; RelativeError: boolean = False): double; overload; (*Calculates the C norm ||V-Vec|| between Vec elements [VecIndex]..[VecIndex+Len-1] and calling vector elements [Index]..[Index+Len-1].*) function NormC(const Vec: TDenseMtxVec; VecIndex,Index,Len: integer; RelativeError: boolean = False): double; overload; (*Calculate the C-norm of calling vector. Computes: NormC = max|a[i]|, 0 < i < Length-1 *) function NormC: double; overload; (*Calculates the C norm from calling vector elements [Index]..[Index+Len-1].*) function NormC(Index,Len: integer): double; overload; (*The L1-norm. Calculates the L1 norm : ||V-Vec||, where V is calling vector. If the NormL1 is called without any parameters, the NormL1 calculates the norm of calling vector. The L1 norm of ||V-Vec|| is defined by the formula: If RelativeError is true then the computed norm is divided by the norm of V, and the function returns the "relative error": var a,b: Vector; c: double; begin a.SetIt(False,[1,2,3,4]); b.SetIt(False,[4,3,2,1]); c := a.NormL1(b,True); end; *) function NormL1(const Vec: TDenseMtxVec; RelativeError: boolean = False): double; overload; (*Calculates the L1 norm ||V-Vec|| between Vec elements [VecIndex]..[VecIndex+Len-1] and calling vector elements [Index]..[Index+Len-1].*) function NormL1(const Vec: TDenseMtxVec; VecIndex,Index,Len: integer; RelativeError: boolean = False): double; overload; (*Calculate the L1-norm of the calling vector. NormL1 = Sum(|a[i]|), 0 < i < Length-1 *) function NormL1: double; overload; (*Calculates the L1 norm from calling vector elements [Index]..[Index+Len-1].*) function NormL1(Index,Len: integer): double; overload; (*The L2-norm. Calculates the L2 norm : ||V-Vec||, where V is calling vector. 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: If RelativeError is true then the computed norm is divided by the norm of V, and the function returns the "relative error": var a,b: Vector; c: double; begin a.SetIt(False,[1,2,3,4]); b.SetIt(False,[4,3,2,1]); c := a.NormL2(b,True); end; *) function NormL2(const Vec: TDenseMtxVec; RelativeError: boolean = False): double; overload; (*Calculates the L2 norm ||V-Vec|| between Vec elements [VecIndex]..[VecIndex+Len-1] and calling vector elements [Index]..[Index+Len-1].*) function NormL2(const Vec: TDenseMtxVec; VecIndex,Index,Len: integer; RelativeError: boolean = False): double; overload; (*Calculate the L2-norm of the calling vector. NormaL2 = ( Sum(|a[i]|^2) )^0.5 , 0 < i < Length-1 *) function NormL2: double; overload; (*Calculates the L2 norm from calling vector elements [Index]..[Index+Len-1].*) function NormL2(Index,Len: integer): double; overload; (*Add/Subtract a value. Depreciated Use (Value) instead. *) function Offset(Value: double): TMtxVec; overload; (*Add/Subtract a complex value.*) function Offset(Value: TCplx): TMtxVec; overload; (*Add/Subtract a value from [Index]..[Index+Len-1].*) function Offset(Value: double; Index,Len: integer): TMtxVec; overload; (*Add/Subtract a complex value from [Index]..[Index+Len-1].*) function Offset(Value: TCplx; Index,Len: integer): TMtxVec; overload; (*Calculate the range from all calling object elements.*) function Range: double; overload; (*Returns real range value from calling object elements [Index]..[Index+Len-1]. An exception is raised if calling object property is true or array borders are overrun. *) function Range(Index, Len: integer): double; overload; (*Calculate the range from calling object elements [Index]..[Index+Len-1]. The result ARange is a real value. An exception is raised if calling object property is true or array borders are overrun/underrun. *) procedure Range(out ARange: double; Index, Len: integer); overload; (*Reverse vector elements. The method reverses Vec vector elements from [VecIndex].. [VecIndex+Len-1] and stores them in the calling vector from [Index]...[Index+Len-1] by using the following equation: This overload reverses calling vector elements in-place. var a: Vector; begin a.SetIt(False,[1,2,3,4]); a.Reverse; // a = [4,3,2,1] end; *) function Reverse(const Vec: TMtxVec; VecIndex, Index, Len: integer): TMtxVec; overload; (*Reverses the calling object elements [Index]..[Index+Len-1]. An exception is raised if array borders are overrun. *) function Reverse(Index, Len: integer): TMtxVec; overload; (*A cyclic shift on vector elements in range. Performs cyclic shift on vector elements in specified range [Index..Index+Len]. The number of elements to shift is specified in the Offset parameter. Offset can be any integer number, positive or negative. *) function Rotate(Offset: integer; Index: integer; Len: integer = MtxVecEOA): TMtxVec; overload; (*A cyclic shift on vector elements in range. Performs cyclic shift on source vector elements in specified range [Index..Index+Len] and stores them to calling vector. The number of elements to shift is specified in the Offset parameter. Offset can be any integer number, positive or negative. *) function Rotate(const Vec: TMtxVec; Offset: integer; VecIndex,Index: integer; Len: integer = MtxVecEOA): TMtxVec; overload; (*Shift vector elements in range. Shifts calling vector elements in specified range [Index..Index+Len]. The number of elements by which to shift is specified in the Offset parameter. Offset can be any integer number, positive or negative. *) function Shift(Offset: integer; Index: integer; Len: integer = MtxVecEOA): TMtxVec; overload; (*A shift on vector elements in range. Performs shift on source vector elements in specified range [Index..Index+Len] and stores them to calling vector. The number of elements to shift is specified in the Offset parameter. Offset can be any integer number, positive or negative. *) function Shift(const Vec: TMtxVec; Offset: integer; VecIndex,Index: integer; Len: integer = MtxVecEOA): TMtxVec; overload; (*Subtracts Value from object elements. Subtracts Value from all calling object elements. *) function Sub(Value: double): TMtxVec; overload; (*Subtracts complex Value from all calling object complex elements.*) function Sub(Value: TCplx): TMtxVec; overload; (*Subtracts Value from calling object elements [Index]..[Index+Len-1]. An exception is raised if array borders are overrun. *) function Sub(Value: double; Index, Len: integer): TMtxVec; overload; (*Subtracts complex Value from calling object complex elements [Index]..[Index+Len-1]. An exception is raised if array borders are overrun. *) function Sub(Value: TCplx; Index, Len: integer): TMtxVec; overload; (*Subtract real Value from Src. Store the results in calling object. Size and property of calling object are adjusted automatically. *) function Sub(const Src: TMtxVec; Value: double): TMtxVec; overload; (*Subtract complex Value from Src store the results in calling object. Size and property of calling object are adjusted automatically. *) function Sub(const Src: TMtxVec; Value: TCplx): TMtxVec; overload; (*Subtract real Value from Src elements [SrcIndex]..[SrcIndex+Len-1] and store the result in calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if is True and array borders are overrun or underrun. *) function Sub(const Src: TMtxVec; Value: double; SrcIndex, Index, Len: integer): TMtxVec; overload; (*Subtract complex Value from Src elements [SrcIndex]..[SrcIndex+Len-1] and store the result in calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if is True and array borders are overrun or underrun. *) function Sub(const Src: TMtxVec; Value: TCplx; SrcIndex, Index, Len: integer): TMtxVec; overload; (*Array subtraction. Subtract each of Vec elements from corresponding elements in the calling object. An exception is raised if Vec and calling object size and properties do not match. *) function Sub(const Vec: TMtxVec): TMtxVec; overload; (*Subtract Vec2 elements from Vec1 elements and store the results in calling object. Size and property of calling object are adjusted automatically. An exception is raised if Vec1 and Vec2 size and property do not match. *) function Sub(const Vec1, Vec2: TMtxVec): TMtxVec; overload; (*Subtract Vec elements [VecIndex]..[VecIndex+Len-1] from corresponding calling object elements [Index]..[Index+Len-1]. The results are stored in the calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if is True and array borders are overrun or underrun. *) function Sub(const Vec: TMtxVec; VecIndex, Index, Len: integer): TMtxVec; overload; (*Subtract Vec22 elements [Vec2Index]..[Vec2Index+Len-1] from Vec1 object elements [Vec1Index]..[Vec1Index+Len-1]. Store the results in calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if is True and array borders are overrun or underrun. *) function Sub(const Vec1, Vec2: TMtxVec; Vec1Index, Vec2Index, Index, Len: integer): TMtxVec; overload; (*Subtraction from value. Subtract each of calling object elements from Value. *) function SubFrom(Value: double): TMtxVec; overload; (*Subtract each of calling object elements from complex Value. If the calling vector is not complex, the conversion is performed automatically in a performance efficient way. *) function SubFrom(Value: TCplx): TMtxVec; overload; (*Subtract elements [Index]..[Index+Len-1] from Value and store the result in Self. An exception is raised if is True and array borders are overrun or underrun. *) function SubFrom(Value: double; Index,Len: integer): TMtxVec; overload; (*Subtract elements [Index]..[Index+Len-1] from complex Value and store the result in Self. If the calling vector is not complex, the conversion to complex is performed automatically in performance efficient way. An exception is raised if is True and array borders are overrun or underrun. *) function SubFrom(Value: TCplx; Index,Len: integer): TMtxVec; overload; (*Substract Vec elements from Value and store the result in the calling object. Size and properties of calling object are adjusted automatically. *) function SubFrom(Value: double; Vec: TMtxVec): TMtxVec; overload; (*Substract complex Vec elements from Value and store the result in the calling object. Size property of the calling object is set automatically. property of the calling object is set to True. *) function SubFrom(Value: TCplx; Vec: TMtxVec): TMtxVec; overload; (*Substract Vec elements [VecIndex]..[VecIndex+Len-1] from Value. Store the result to the calling object elements [Index]..[Index+Len-1]. Size property of the calling object is not changed. An exception is raised if is True and array borders are overrun or underrun. property of the calling object is adjusted automatically. *) function SubFrom(Value: double; Vec: TMtxVec; VecIndex, Index, Len: integer): TMtxVec; overload; (*Substract Vec elements [VecIndex]..[VecIndex+Len-1] from complex Value and store the result to the calling object elements [Index]..[Index+Len-1]. Size property of the calling object is not changed. An exception is raised if is True and array borders are overrun or underrun. property of the calling object is set to True. *) function SubFrom(Value: TCplx; Vec: TMtxVec; VecIndex, Index, Len: integer): TMtxVec; overload; (*Calculate the Sum of squares of the calling vector. For complex numbers, the routine computes the squared L2 norm. SumOfSquares = Sum(|a[i]|^2) , 0 < i < Length-1 *) function SumOfSquares: double; overload; (*Calculates the sum of squares from the calling vector elements [Index]..[Index+Len-1].*) function SumOfSquares(Index,Len: integer): double; overload; (*Inserts zeroes between consecutive array values. Copy Len values from Src starting at SrcIndex to the calling object starting at position Index and place Factor-1 zeros between consecutive values. Size and properties of the calling object must be set explicitly. Phase parameter defines the initial sample offset and must be less then Factor. An exception is raised, if array borders are overrun/underrun. *) function UpSample(const Src: TMtxVec; Factor,SrcIndex, Index, Len: integer; Phase: integer = 0): TMtxVec; overload; (*Skewness (third central momentum). Calculate the calling object skewness by using mean value AMean and standard deviation AStdDev. Skewness is the third central moment, divided by third power of standard deviation: var a: Vector; c,d: double; begin a.SetIt(False,[1,2,3,4]); d := a.Mean; c := a.Skewness(d, a.StdDev(d)); end; *) function Skewness(AMean, AStdDev: double): double; overload; (*Calculate the skewness for elements [Index]..[Index+Len-1]. An exception is raised if is True and array borders are overrun. The AMean and AStdDev parameters must be computed from the same elements from which the Skewness is to be computed. *) function Skewness(AMean, AStdDev: double; Index, Len: integer): double; overload; (*Biased auto-correlation. Calculates the biased auto-correlation of the vector Vec. The result of Length = Lags is stored in the calling vector (V). The Lags parameter must be equal or smaller than the calling vector length. The biased auto-correlation is defined by the following equation: var a,b: Vector; begin a.SetIt(False,[1,2,3,4]); b.AutoCorrBiased(a,2); end; *) function AutoCorrBiased(const Vec: TVec; Lags: integer): TVec; (*Normal auto-corellation. Calculates the normal auto-correlation of the vector Vec. The result of Length = Lags is stored in the calling vector (V). The Lags parameter must be equal or smaller than the calling vector (V) length. The normal auto-correlation is defined by the following equation: var a,b: Vector; begin a.SetIt(False,[1,2,3,4]); b.AutoCorrNormal(a,2); end; *) function AutoCorrNormal(const Vec: TVec; Lags: integer): TVec; (*Unbiased auto-correlation. Calculate the unbiased auto-correlation of the vector Vec. The result of Length = Lags is stored in the calling vector (V). The Lags parameter must be equal or smaller than the calling vector (V) length. The unbiased auto-correlation is defined by the following equation: var a,b: Vector; begin a.SetIt(False,[1,2,3,4]); b.AutoCorrUnBiased(a,2); end; *) function AutoCorrUnBiased(const Vec: TVec; Lags: integer): TVec; (*Concatenates an array of TVec objects. Concatenates an array of TVec objects. The method copies the contents of all TVec objects from the Src array to the calling object. The and properties of the calling vector are set implicitly. An exception is raised, if Complex properties of TVec objects do not match. var a,b,c,d: Vector; begin a.SetIt(False,[1,2,3]); b.Copy(a); c.Concat([a,b]); // c = [1,2,3,1,2,3] d.Size(10,True); d.SetZero(0,4); d.Concat(4,[c]); // d = [0,0,0,0,1,2,3,1,2,3] end; *) function Concat(const Src: array of TVec): TVec; overload; (*Copies the contents of all TVec objects from the Src array to the calling vector elements, starting with at Index. The and properties of the calling vector must be set explicitly. An exception is raised, if Complex properties of TVec objects do not match or if the sum of Length's exceeds the Length property of the calling object. *) function Concat(Index: integer; const Src: array of TVec): TVec; overload; (*Single-rate finite, linear convolution of two sequences. Calculate the single-rate finite, linear convolution of two sequences. The results are stored in the calling vector. The argument names X and H are chosen to suggest FIR filtering. The result of the convolution is defined as follows: This finite-length convolution is related to infinite-length by: In the above equations, X'[n] and h'[n] are the zero-padded (infinite-length) versions of X[n] and h[n]; y'[n] is the infinite-length output version of y[n]. Then y'[n] is zero everywhere except over: *) function Convolve(const X,H: TVec): TVec; (*Copies values from Vec1 and Vec2 (concatenate). Copy each of Vec1 and Vec2 elements to the calling vector (concatenate). The and properties of the calling vector are set implicitly to match Vec1 and Vec2 vector. var a,b,c: Vector; begin a.SetIt(True,[1,2,3,4]); b.Copy(a); c.Copy(a,b); //concatenate a and b and store in c // c = [1,2,3,4,1,2,3,4] end; *) function Copy(const Vec1,Vec2: TMtxVec): TVec; overload; (*The cross-correlation of two vectors. Calculate the cross-correlation of two vectors Vec1 and Vec2. The parameter HiLag indicates the top of the range of lags at which the correlation estimates should be computed. The parameter LoLag indicates the bottom of the range of lags at which the correlation estimates should be computed. The results are stored in calling vector. The resulting elements are defined by the equation: var a,b,c: Vector; begin a.SetIt(False,[1,-2,3,4]); b.SetIt(False,[2,-2,3,4]); c.CrossCorr(a,b,2,2); end; *) function CrossCorr(const Vec1, Vec2: TVec; HiLag, LoLag: integer): TVec; (*Cumulative sum. Calculate the cumulative sum for all calling object elements in-place. var a: Vector; begin a.SetIt(false,[1,2,3,4]; a.CumSum; // a = [1,3,6,10] end; *) function CumSum: TVec; overload; (*Calculate the cumulative sum for all Vec elements. Store the results in calling object. Size and properties of the calling object are set implicitly. *) function CumSum(const Vec: TVec): TVec; overload; (*The forward discrete cosine transform (DCT). Calculates the forward discrete cosine transform (DCT) of all calling vector elements in-place. If vector is a power of 2, the function uses an efficient algorithm that is significantly faster than the direct computation of DCT. For different lengths this function uses the direct formulas given below; however, the symmetry of cosine function is taken into account, which allows to perform about half of the multiplication operations in the formulas. In the following definition of DCT, N=Vec.Length and V is the calling vector: var a,b: Vector; begin a.SetIt(False,[1,-2,3,4]); b.DCT(a); end; *) function DCT: TVec; overload; (*Calculates the forward discrete cosine transform (DCT) of the Vec. Writes the result in the calling vector. If Vec.Length is a power of 2, the function uses an efficient algorithm that is significantly faster than the direct computation of DCT. For other values of Vec Length, this function uses the direct formulas. *) function DCT(const Vec: TVec): TVec; overload; (*Copies the k-th diagonal from the TMtx object. Copies the k-th diagonal from the TMtx object. If k = 0 then the main diagonal is copied, if k < 0 then the subdiagonal is copied and if k > 0 then the k-th super diagonal is copied to the calling vector. In the following example we setup a matrix, populate it with values and then extract it's main diagonal to a vector. var a: Vector; d: Matrix; begin // setup matrix d.SetIt(2,2,False,[1,-2, 3, 4]); // get main diagonal from matrix a.Diag(d,0); // a now containes [1,4]; end; *) function Diag(const Mtx: TMtx; k: integer): TVec; (*The difference between two succesive vector elements. Calculate the difference for all calling vector elements. The following formula is used to calculate the difference: The Length of calling vector is automatically decremented by one. *) function Difference(Lag: Integer = 1): TVec; overload; (*Calculate the difference for all Vec elements and store the results in the calling vector. The of the calling vector is set to one less the length of Vec and property is set to Vec.Complex. *) function Difference(const Vec: TMtxVec; Lag: Integer = 1): TVec; overload; (*Downsamples vector values. The methods copies only every Factor sample from the Src vector to the calling vector. The and properties of the calling vector are set implicitly. The phase parameter determines the initial sample offset. Phase must be less than Factor. var a,b: Vector; begin b.SetIt(False,[0,0,0,0,1,2,3,4,5,6]); a.DownSample(b,2); // a = [0,0,1,3,5] end; *) function DownSample(const Src: TMtxVec; Factor: integer; Phase: integer = 0): TVec; overload; (*Compares vector elements and returns true if vectors are equal. Compares vector elements and returns true if vectors are equal, that is if all elements match in position and value. The Tolerance parameter defines the comparison tolerance. The maximum difference between elements may not exceed: +/-Tolerance. var A,B: Matrix; c: boolean; begin A.SetIt(2,2,false,[1,2, 2,4]); // 2x2 real matrix B.SetIt(2,2,false,[1,2, 2,4]); // 2x2 real matrix c := A.Equal(B,1e-8); // Check for differences bigger than 0.00000001 c := A.Equal(B); // Check for exact match end; *) function Equal(const Vec: TMtxVec; Tolerance: double = 0): boolean; overload; (*Optionally it is also possible to specify the Compare method.*) function Equal(const Vec: TMtxVec; Tolerance: double; Compare: TCompare): boolean; overload; (*Fast Furier Transformation (FFT) from complex to complex or from real to complex. Fast Furier Transformation (FFT) from complex to complex or from real to complex. Calculate the FFT from all calling vector elements in-place. If the calling vector is complex then complex to complex forward FFT is performed. If the calling vector is real then real to complex FFT is performed. The of the transforming vector can be any number but highest performance will be achieved if it is a power of two. Note When performing FFT from real to complex the conjugated symmetric part is also generated by conjugating and mirroring the first half of the spectrum. If Complex is false, the operation will not be performed in-place, if the Length of the destination will allocate more than amount of the memory preallocated for the TVec object. Instead, the data will be copied first to allocate enough space to store the result. There are two important parameters to consider that affect how will the FFT be computed: and . The default storage format is fsfCCS. var a,b: Vector; begin a.SetIt(False,[1,2,3,4]); b.FFT(a); a.FFT; // a = [(10, 0),( -2,2), (-2, 0), (-2,-2)] if not a.Equal(b) then ERaise('Not equal'); end; *) function FFT(ConjugateExtend: boolean = false): TVec; overload; (*Calculate the FFT from all Vec elements. Store the results in the calling vector. Vec must not be a power of two, but highest performance will be achieved if it is a power of two. Length and properties of the calling vector are set implicitly to match Vec vector. If Vec is complex then complex to complex forward FFT is performed. If Vec is real then real to complex FFT is performed and the conjugate symmetric part is appended. *) function FFT(const Vec: TVec; ConjugateExtend: boolean = false): TVec; overload; (*The forward Fast Fourier Transformation (FFT) from real to complex. Calculates the forward Fast Fourier Transformation (FFT) from real to complex for the calling vector in-place. The transform should be used, when the conjugate symmetric part of the frequency spectrum is not desired. If the calling vector is complex an exception will be raised. The operation implicitly sets the calling vector Complex property to True. The highest performance will be achieved if the transform length will be a power of two. The transform length is equal to , when the is fsfPack or fsfPerm. The default storage format is fsfCCS. In-place fsfCCS complication The transform length in case of fsfCCS will be equal to Length-2, because the result is bigger than the source data by 2 real samples, if the source data is even. If the source data length is odd, then must be set to True and only Length-1 samples will be used, but Length must of course in that case be even, or Length-1 will not be odd. The last two (one) samples in the vector will be ignored and will be overwritten with the result. var a,b: Vector; begin //Even a.SetIt(false,[1,2,3,4]); b.FFTFromReal(a); // b = [(10, 0),( -2,2), (-2, 0)] a.SetIt(false,[1,2,3,4, 0, 0]); //result requires 3 complex (or 6 real values) a.FFTFromReal; // b = [(10, 0),( -2,2), (-2, 0)] //Odd length a.SetIt(false,[1,2,3]); b.FFTOddLength := True; //use only Length-1 samples b.FFTFromReal(a); // b = [(6,0),( -1.5,0.8660)] //result requires 2 complex (= 4 real numbers) a.SetIt(false,[1,2,3,0]); a.FFTOddLength := True; //use only Length-1 samples a.FFTFromReal; // b = [(6,0),( -1.5,0.8660)] //result requires 2 complex (= 4 real numbers) end; *) function FFTFromReal: TVec; overload; (*Calculate the FFT from all Vec elements and store the result in the calling vector. of the calling vector is set to match the length of the result. *) function FFTFromReal(const Vec: TVec): TVec; overload; (*Finds and gathers vector elements. Fills the Indexes vector with indexes, of those elements where the Op comparison between a and b is True. Op string parameter can be '<', '>', '>=','<=','=' or '<>'. The method also copies or "gathers" the matched elements to the calling vector. The Length and complex property of the calling vector are set automatically. The Indexes vector stores the indexes as Integer in to the memory location occupied by Values array. The memory is typecasted to an array of integers via IValues array property. Other TMtxVec methods can not be used to perform operations on an array of integers unless explicitely specified. *) function FindAndGather(const a: TMtxVec; const op: string; const b: TCplx; const Indexes: TVecInt = nil): TVec; overload; (*The b parameter is of double type.*) function FindAndGather(const a: TMtxVec; const op: string; const b: double; const Indexes: TVecInt = nil): TVec; overload; (*The b parameter is of type.*) function FindAndGather(const a: TMtxVec; const op: string; const b: TMtxVec; const Indexes: TVecInt = nil): TVec; overload; (*Gather vector elements. Gather the elements of vector X and store them to the calling vector according to the IndexType, Increment and Offset parameters. The Indexes vector is used only if IndexType is either indVector or indMask. If IndexType is indVector, the values from the Indexes vector denote the Index positions in the X vector from which the values should be copied to the calling vector. The Indexes vector must have the indexes stored in the IValues array. The IValues integer arrays points the same memory as Values array. The Increment and Offset parameters are used only if TIndexType is indIncrement. They define the initial offset and a fixed step (increment) between elements to be gathered. If IndexType is indMaks the Indexes vector must have the same size as the X vector. The routine will copy only those elements from the X vector to the calling vector, for which there is a 1 at the coresponding Index in the Indexes vector. The elements copied from the X vector will be stored consecutively in the calling vector. See the method to see how to undo the gathering. Note The performance of the CPU heavily depends on the assumption that elements are stored at consecutive memory locations. If it is neccessary to apply a set of operations only to elements at specific indexes, performance-wise it can proof to be very helpfull, if the elements are gathered first. *) function Gather(const X: TMtxVec; const Indexes: TVecInt =nil; IndexType: TIndexType = indVector; Increment: integer = 1; Offset: integer = 0): TVec; overload; (*Gather vector elements. Gather the elements of vector X at indices defined with Increment*i + Offset and store them to the calling vector. *) function GatherByIncr (const X: TMtxVec; Increment: integer = 1; Offset: integer = 0): TVec; overload; (*Gather vector elements. Gather the elements of vector X at indices defined with Indexes and store them to the calling vector. *) function GatherByIndex(const X: TMtxVec; const Indexes: TVecInt): TVec; overload; (*Gather vector elements. Gather the elements of vector X at indices defined with Mask and store them to the calling vector. *) function GatherByMask (const X: TMtxVec; const Mask: TVecInt): TVec; overload; (*Gather a vector, split to two vectors. If the elements of a vector have been split with a Mask and the "positive" elements have been stored in the MaskVec and "negative" elements have been stored in the NotMaskVec, this routine will restore the original vector. The length of the MaskVec vector must be equal to the number of ones in the Mask vector. The length of the NotMaskVec vector must be equal to the number of zeroes in the Mask vector. *) function GatherSplit(const MaskVec, NotMaskVec: TMtxVec; const Mask: TVecInt): TVec; overload; (*Copies a column from matrix. Copies the Col-th column from Mtx matrix to calling vector. The and properties of calling vector are adjusted automatically. An exception is raised if condition checking is enabled and Col is greater than Mtx.Cols-1. var a: Vector; b: Matrix; begin b.SetIt(2,2,False,[1,2, 3,4]); a.GetCol(b,0); // a now contains [1,3] end; *) function GetCol(const Mtx: TMtx; aCol: integer): TVec; overload; (*Copy the Col-th column elements [Row]..[Row+Len-1] to calling vector elements [Index]..[Index+Len-1]. The property of calling vector must be set explicitly. An exception is raised if condition checking is enabled and column array borders are overrun. *) function GetCol(const Mtx: TMtx; aRow, aCol, Index, Len: integer): TVec; overload; (*Copy the Col-th column elements [Row]..[Row+Len-1] to calling vector. The and properties of calling vector are adjusted automatically. An exception is raised if condition checking is enabled and column array borders are overrun. *) function GetCol(const Mtx: TMtx; aRow, aCol, Len: integer): TVec; overload; (*Copies a row from matrix. Copies the Row-th row from Mtx matrix to calling vector. The and properties of calling vector are adjusted automatically. An exception is raised if condition checking is enabled and Row is greater than Mtx.Rows-1. var a: Vector; b: Matrix; begin b.SetIt(2,2,False,[1,2, 3,4]); a.GetRow(b,0); // a now contains [1,2] end; *) function GetRow(const Mtx: TMtx; aRow: integer): TVec; overload; (*Copy the Row-th column elements [Col]..[Col+Len-1] to calling vector elements [Index]..[Index+Len-1]. The property of calling vector must be set explicitly. An exception is raised if condition checking is enabled and column array borders are overrun. *) function GetRow(const Mtx: TMtx; aRow, aCol, Index, Len: integer): TVec; overload; (*Copy the Row-th column elements [Col]..[Col+Len-1] to calling vector. The and properties of calling vector are adjusted automatically. An exception is raised if condition checking is enabled and column array borders are overrun. *) function GetRow(const Mtx: TMtx; aRow, aCol, Len: integer): TVec; overload; (*The fast hilbert transform (FFT based). The method forms the imaginary orthogonal part (90 degrees phase shifted version of the original) from the real series by using the fast hilbert transform (FFT based) and saves the complex result in the calling vector. No windowing is performed. Vec must be a real vector or an exception is raised. The and properties of the calling vector are set implicitly to match Vec vector. var a,b,Re,Im: Vector; azero: double; begin a.SetIt(false,[1,2,3,4,5,6,7,8]); b.Hilbert(a); Re.RealPart(b); Im.ImagPart(b); azero := DotProd(Re,Im); // if Re is orthogonal to Im, azero becomes 0 end; *) function Hilbert(const Vec: TVec; method: THilbertMethod = hmMethod1): TVec; overload; (*The inverse discrete cosine transform (DCT). Calculates the inverse discrete cosine transform (DCT) of a Vec and writes the results in the calling vector. If Vec is a power of 2, the function uses an efficient algorithm that is significantly faster than the direct computation of DCT. For other values of Vec length, this function uses the direct formulas given below; however, the symmetry of cosine function is taken into account, which allows to perform about half of the multiplication operations in the formulas. In the following definition of inverse DCT, N=Vec.Length and V is the calling vector: var a,b: Vector; begin a.SetIt(False,[1,-2,3,4]); b.IDCT(a); end; *) function IDCT(const Vec: TVec): TVec; overload; (*Calculate the inverse DCT in-pllace. The length of the calling vector is adjusted automatically. *) function IDCT: TVec; overload; (*The inverse backward FFT from complex to complex. Calculates the inverse (backward) Fast Fourier Transformation (FFT) from complex to complex for all calling vector elements in-place. If the NoScale parameter is true, then no scaling is performed for the calling vector. The results can be erroneous if overflow or underflow occurs. var a,b: Vector; begin a.SetIt(True,[1,2,3,4]); b.IFFT(a,True); end; *) function IFFT(NoScale: boolean = False): TVec; overload; (*Calculate the inverse FFT from all Vec elements and store the results in the calling vector. If the NoScale parameter is true then no scaling is performed for the calling vector. Vec must not be the power of two. and properties of the calling vector are set implicitly to match Vec vector. *) function IFFT(const Vec: TVec; NoScale: boolean = False): TVec; overload; (*The inverse FFT from complex to real. Calculates the inverse Fast Fourier Transformation (FFT) from complex to real from all calling vector elements. The result is a real type vector. Input vector must be a complex vector or an exception is raised. If the NoScale parameter is true then no scaling is performed for the calling vector. The results can be erroneous if overflow or underflow occurs. In-place fsfCCS complication When is equal to fsfCCS the Length of the result will be equal to Length-2, because the source data is bigger than the result data by 2 real samples, if is false. If is True the result will fill up Length-1 samples. var a,b: Vector; begin //Even a.SetIt(True,[1,2,3,4]); b.FFTFromReal(a); // b = [(10, 0),( -2,2), (-2, 0)] b.IFFTToReal; // b = [1, 2, 3, 4, -2, 0)] //Odd length a.SetIt(True,[1,2,3,0]); b.FFTOddLength := True; //use only Length-1 samples b.FFTFromReal(a); // b = [(6,0),( -1.5,0.8660)] //result requires 2 complex (= 4 real numbers) b.IFFTToReal; //b = [1, 2, 3, 0.8660] //Event length a.SetIt(True,[1,2,3,4, 0,0]); //allocate two more elements a.FFTOddLength := false; //use only Length-2 samples a.FFTFromReal; // a = [(10, 0),( -2,2), (-2, 0)] //result requires 3 complex (= 6 real numbers) a.IFFToReal; // a = [1, 2, 3, 4, -2, 0)] end; *) function IFFTToReal(NoScale: boolean = False): TVec; overload; (*Calculate the inverse FFT from all Vec elements. Store the results in the calling vector. Vec must not be the power of two. and properties of the calling vector are set implicitly the size and type of the result. *) function IFFTToReal(const Vec: TVec; NoScale: boolean = False): TVec; overload; (*Integrate calling vector values. Perform d-times integration of calling vector values, where d is equal to Init length. Definies initial values for integration. Size of Init vector determines how many times calling vector values will be integrated.*) function Integrate(const Init: TVec): TVec; overload; (*Integrate all Vec elements using initial values in Init and store the results in calling vector. and properties of the calling vector are set implicitly the size and type of the result. *) function Integrate(const Vec, Init: TVec):TVec; overload; (*The Kronecker product between two vectors. Calculates the Kronecker product between vectors Vec1 and Vec2 and stores the results in calling vector. var a,b,c: Vector; begin a.SetIt(False,[1,2,3,4]); b.SetIt(False,[1,2,3,4]); c.Kron(a,b); // c = [1,2,3,4, 2,4,6,8, 3,6,9,12, 4,8,12,16] end; *) function Kron(const Vec1, Vec2: TVec): TVec; overload; (*The norm of a vector. Calculates the norm of a Vec vector and stores the results in calling vector. This functions works the same as . *) function Norm(const Vec: TMtxVec): TMtxVec; (*Downsamples (reduces) the number of vector elements. This method speeds up drawing of huge amounts of data (>> 2000 samples). You should pass your data to the PixelDownSample method before you pass the values to the Charting routine. The X and Y vectors contain the values for X and Y axis, that you would normally pass to the charting procedure. The downsampled Y is stored in the calling vector and downsampled X is stored in the NX vector. If your data is equidistant on X axis, you can omit the X vector or, if you are in doubt, allow the routine to downsample the X vector also. If your data is not equidistant on the X axis, you must indicate that by specifying the Equidistant parameter as False and provide X and NX vectors, where X containes the step on the X axis and NX will contain the downsampled result for X axis. With Width parameter you specify the width of the charting region in pixels. (Example: Chart.Width). The routine will reduce the number of samples in vectors Y and X in such a way that there will be no visual difference between the original and downsampled data. That however will no longer be true, if you will zoom-in on the data. The performance gain can be as big as 100x depending on the charting tool that you use. You can easily draw data series from vectors with length of over 1.000.000 samples in real time. var a,b: Vector; begin a.SetIt(False,[0,0,0,1,2,3,1,2,3]); b.PixelDownSample(3,a); end; *) procedure PixelDownSample(Width: integer; Y: TVec; Index,Len: integer; X: TVec = nil; NX: TVec = nil; Equidistant: TEquidistantSample = eqsXEquidistant); overload; (*Downsample the vectors Y and (optionaly) X starting at position Index and for Len samples. Store result for Y in the calling vector and the result for X in the NX vector. If X axis is equidistant, you can omit X and NX parameters. Set Width to the number of target pixels. An exception is reaised, if any of the vectors is complex or if array borders are overrun/underrun. *) procedure PixelDownSample(Width: integer; Y: TVec; X: TVec = nil; NX: TVec = nil; Equidistant: TEquidistantSample = eqsXEquidistant); overload; (*Fills vector with prime numbers, starting from 2 up to the value of n. Fills calling vector with prime numbers, starting from 2 up to the value of n. The memory for at least n elements is allocated. The maximum value of n is 1000. The prime numbers are fetched from a precreated table. var a: Vector; begin a.PrimeNumbers(10); // a = [2,3,5,7] end; *) function PrimeNumbers(n: integer): TVec; (*Fills the calling vector with a series following linear rule. Fills the calling vector with a series following the rule: Values[k] := k (Offset is zero and Step is one). If the calling vector is complex, only the real part is set. var a: Vector; begin a.Size(5,True); a.Ramp(0,PI); a.Sin; end; which is identical to: a.Size(5,True); for i:= 0 to a.Length-1 do a[i] := sin(i*PI); *) function Ramp: TVec; overload; (*Fills the calling vector with a series. Follow the rule: CValues[k] := Offset + k*Step. *) function Ramp(Offset, Step: TCplx): TVec; overload; (*Fills the calling vector with a series. Follow the rule: Values[k] := Offset + k*Step. If the calling vector is complex, only the real part is set. *) function Ramp(Offset, Step: double): TVec; overload; (*Fills the calling vector elements [Index]..[Index+Len-1] with a series. Follow the rule: Values[k] := Offset + k*Step. If the calling vector is complex, only the real part is set. An exception is raised if calling vector array borders are overrun. *) function Ramp(Offset,Step: double; Index,Len: integer): TVec; overload; (*Fills the calling vector elements [Index]..[Index+Len-1] with a series. Follow the rule: Values[k] := Offset + k*Step. If the calling vector is complex, only the real part is set. An exception is raised if array borders of the calling vector are overrun. *) function Ramp(Offset, Step: TCplx; Index,Len: integer): TVec; overload; (*The Offset is complex, but the step is real.*) function Ramp(Offset: TCplx; Step: double): TVec; overload; (*Fills the calling vector elements [Index]..[Index+Len-1] with a series. Follow the rule: Values[k] := Offset + k*Step. The Offset is complex, but the step is real. *) function Ramp(Offset: TCplx; Step: double; Index,Len: integer): TVec; overload; (*Resizes vector size while preserving values. Resizes calling vector to Len and fills it with Src vector first Len values. If Src length is less than Len and ZeroIt parameter is true, the remaining calling vector values are set to zero. var a, b: Vector; begin a.SetIt(false,[1,2,3]); b.SetIt(false,[9]); b.Resize(a,7,True); // b=(9,1,2,3,4,0,0,0) end; *) function Resize(const Src: TMtxVec; Len: integer; ZeroIt: boolean = False): TVec; overload; (*Resizes calling vector to Len. If is less than Len and ZeroIt parameter is true, the remaining calling vector values are set to zero. var a: Vector; begin a.SetIt(false,[1,2,3]); a.Resize(7,True); // a= [1,2,3,0,0,0,0] end; *) function Resize(Len: integer; ZeroIt: boolean = False): TMtxVec; overload; (*Reverse vector elements. The method reverses vector elements by using the following equation: This overload reverses all calling vector elements in-place. var a: Vector; begin a.SetIt(False,[1,2,3,4]); a.Reverse; // a = [4,3,2,1] end; *) function Reverse: TVec; overload; (*Reverse all Vec elements. Store the result in the calling vector elements. The and properties of the calling vector are set implicitly to match Vec vector. *) function Reverse(const Vec: TMtxVec): TVec; overload; (*A cyclic shift on vector elements. Performs cyclic shift on vector elements. The number of elements to shift is specified in the Offset parameter. Offset can be any integer number, positive or negative. var a: Vector; begin a.SetIt(False,[1,2,3,4]); a.Rotate(2); // a = [3,4,1,2] end; *) function Rotate(Offset: integer): TVec; overload; (*Applies cyclic shift on Src vector elements and stores the result in Self.*) function Rotate(const Src: TMtxVec; Offset: integer): TVec; overload; (*Sets vector values (double). Sets the property of the calling vector to (High(A)+1) and the property to AComplex. The double elements of A array are copied to the calling vector. If AComplex is True then real parts of complex numbers are on even (0,2,4..)and imaginary parts on odd indexes.(1,3,5,..) Note Use this method for setting a double array only. *) function SetDouble(AComplex: boolean; const A: array of double): TVec; overload; (*Sets vector values (integer). Sets the property of the calling vector to (High(A)+1) and the property to AComplex. The integer elements of A array are copied to the calling vector. If AComplex is True then real parts of complex numbers are on even (0,2,4..)and imaginary parts on odd indexes.(1,3,5,..) Note Use this method for integer array only. *) function SetInteger(AComplex: boolean;const A: array of Integer): TVec; overload; (*Sets vector values (single). Sets the property of the calling vector to (High(A)+1) and the property to AComplex. The single elements of A array are copied to the calling vector. If AComplex is True then real parts of complex numbers are on even (0,2,4..)and imaginary parts on odd indexes.(1,3,5,..) Note Use this method for single array only. *) function SetSingle(AComplex: boolean; const A: array of single): TVec; overload; (*Sets vector values. SetIt makes the use of open array construction, to set the values of the calling vector. It gives you the possibility to pass large arrays of elements without having to declare constant arrays. Sets the property of the calling vector to (High(A)+1) and the property to AComplex. The elements of A array are copied to the calling vector. If AComplex is True then real parts of complex numbers are on even (0,2,4..)and imaginary parts on odd indexes.(1,3,5,..) var a: Vector; begin a.SetIt(False,[1,2,3,4]); // a = [1,2,3,4] end; *) function SetIt(AComplex: boolean;const A: array of double): TVec; overload; (*Does not change the or properties of the calling vector. It does check for array overrun. The elements of A array are copied to the calling vector, starting at Index 0. If the calling vector is complex then real parts of complex numbers are on even (0,2,4..)and imaginary parts on odd indexes.(1,3,5,..) *) function SetIt(const A: array of double): TVec; overload; (*Sets vector values (complex). Sets the property of the calling vector to (High(A)+1) and the property to true. The complex elements of A array are copied to the calling vector CValues. Note Use this method for complex array only. *) function SetCplx(const a: array of TCplx): TVec; (*Defines a sub-vector. Define a subvector of the Src vector starting at BeginIndex and ending at EndIndex (inclusive). *) procedure SetSubIndex(const Src: TMtxVec; BeginIndex, EndIndex: integer); overload; (*Defines the calling vector to have the view of the same memory as Src. Src vector's Length property may not change while any other object has it's own view of it. a.SetSubRange(b,..); This SetSubRange method is to be handled with greater care. Namely: * b can be freed before "a" and accessing "a" gives AV. * a can be further subranged with c and same problem occurs when b is freed before c. * If you resize b, all objects which have subranged b are no longer pointing to valid memory. * b can Subrange other objects. Similar problem as when changing the size of b. Again all objects which have subranged b are not longer pointing to valid memory. All this can lead to hard to find bugs. *) procedure SetSubRange(const Src: TMtxVec); overload; (*Define a subvector of the Src vector starting at Index and ending at Index+Len-1.*) procedure SetSubRange(const Src: TMtxVec; Index: integer; Len: integer = MtxVecEOA); overload; (*Define a subvector of the Src vector starting at Index and ending at Index+Len-1. Additionally, it pushes the previous subrange on to a stack, which can be poped by calling SetFullRangeLevel. *) procedure SetSubRangeLevel(const Src: TMtxVec; Index: integer; Len: integer = MtxVecEOA); overload; (*Shift vector elements. Shifts calling vector elements. The number of elements to shift is specified in the Offset parameter. Offset can be any integer number, positive or negative. var a: Vector; begin a.SetIt(False,[1,-2,3,0]); a.Shift(1); // a = 1,1,-2,3 end; *) function Shift(Offset: integer): TVec; overload; (*Shift vector elements left or right in the array. Shifts Src vector elements and stores the result in the calling object. The number of elements to shift is specified in the Offset parameter. Offset can be any integer number, positive or negative. *) function Shift(const Src: TMtxVec; Offset: integer): TVec; overload; (*Sets the size of the vector to match an array. Sets the Length of the calling vector to match the length of the array. The is set to True. *) procedure SizeFromArray(const Src: TCplxArray); overload; (*Sets the size of the vector to match an array. Sets the Length of the calling vector to match the length of the array. The is set to false. *) procedure SizeFromArray(const Src: TDoubleArray); overload; (*Sets the size of the vector to match an array. Sets the Length of the calling vector to match the length of the array. The is set to false. *) procedure SizeFromArray(const Src: TSingleArray); overload; (*Sets the size of the vector to match an array. Sets the Length of the calling vector to match the length of the array. The is set to false. *) procedure SizeFromArray(const Src: TIntegerArray); overload; (*Sets the size of the vector to match an array. Sets the Length of the calling vector to match the length of the array. The is set to false. *) procedure SizeFromArray(const Src: TSmallIntArray); overload; (*Sets the size of the vector to match an array. Sets the size (Length) of the calling vector to match the length of the array. The is set to false. *) procedure SizeFromArray(const Src: Math387.TByteArray); overload; (*Sets the following properties: Vec.Length := ALength; Vec.Complex := false; *) function Size(const ALength: integer; const aFloatPrecision: TMtxFloatPrecision): TVec ; overload; function Size(const ALength: integer; const aFloatPrecisionRef: TMtxVec): TVec ; overload; function Size(const ALength: integer): TVec ; overload; (*Sorts vector elements in ascending order. Sort all calling vector elements. Note If the vector is complex, the complex values are first compared by the absolute value and then (if absolute value is equal) by the argument. var a: Vector; begin a.SetIt(True,[2,1,3,4]); a.SortAscend; // a = [1,2,3,4] end; *) function SortAscend: TVec; overload; (*Sort calling vector elements [Index]..[Index+Len-1]. An exception is raised if is True and array borders are overrun. *) function SortAscend(Index,Len: integer): TVec; overload; (*Sort calling vector elements [Index]..[Index+Len-1]. An exception is raised if is True and array borders are overrun. IndexVec contains the new order of elements. The order is stored in an array of integers which are accessible via the IValues property. *) function SortAscend(Index,Len: integer; const IndexVec: TVecInt): TVec; overload; (*Sort all calling vector elements. IndexVec contains the new (zero based) order of elements. The order is stored in an array of integers which are accessible via the IValues property. *) function SortAscend(const IndexVec: TVecInt): TVec; overload; (*Sorts vector elements in descending order. Sort all calling vector elements in descending order. Note If the vector is complex, the complex values are first compared by the absolute value and then by the argument. var a: Vector; begin a.SetIt(True,[2,1,3,4]); a.SortDescend; // a = [4,3,2,1] *) function SortDescend: TVec; overload; (*Sort calling vector elements [Index]..[Index+Len-1]. An exception is raised if is True and array borders are overrun. *) function SortDescend(Index,Len: integer): TVec; overload; (*Sort calling vector elements [Index]..[Index+Len-1]. An exception is raised if is True and array borders are overrun. IndexVec contains the new order of elements. *) function SortDescend(Index,Len: integer; const IndexVec: TVecInt): TVec; overload; (*Sort all calling vector elements. IndexVec contains contains the new order of elements.*) function SortDescend(const IndexVec: TVecInt): TVec; overload; (*Splits the calling vector to an array of TVec objects. Copy the contents of the calling TVec object to the TVec objects in Dst array. The and properties of vectors in Dst array must be set explicitly. An exception is raised, if properties of TVec objects do not match or the sum of TVec lengths exceeds the of the calling vector. var a,b,c,d: Vector; begin a.SetIt(False,[0,0,0,0,1,2,3,1,2,3]); a.Split([b,c,d],[4,3,3]); // b = [0,0,0,0], c = [1,2,3], d = [1,2,3] end; *) function Split(const Dst: array of TVec): TVec; overload; (*Copy the contents of the calling TVec object to the TVec objects in Dst array. The Length of objects in Dst array is defined in the DstSize array. The and properties of vectors in Dst array are set implicitly. An exception is raised if the sum of DstSize lengths exceeds the of the calling vector. *) procedure Split(const Dst: array of TVec;const DstSize: array of integer); overload; (*Copy the contents of the calling TVec object to Vec1 and Vec2 objects. The and properties of are set implicitly. An exception is raised, if Offset parameter exceeds the length of the calling vector. The property of Vec1 object is set to Offset and the Length of Vec2 is set to the rest. *) procedure Split(const Vec1: TVec; Offset: integer; Vec2: TVec); overload; (*Tensor product between vector and matrix. Calculates the right tensor product between matrix and vector. The result is placed in the calling vector. Depending on the the following operations are available: * mtSymmetric: y = alfa*a*X + beta*y * mtSymmPosDef: y = alfa*a*X + beta*y * mtHermitian: y = alfa*a*X + beta*y * mtHermPosDef: y = alfa*a*X + beta*y * mtTriangular: y = op(a)*X * mtGeneral: y = alfa*op(a)*X + beta*y The and are TVec complex public variables. Their default values are: Alfa = Cplx(1,0) Beta = Cplx(0,0). Note Each time you call TensorProd the values of Alfa and Beta are reset to default. If the matrix is not complex, only the real part of Alfa and Beta is used. If matrix complex and symmetric the general type is used. var a,b,c,t: Matrix; d,e,f: Vector; begin // Test non quadratic general matrix a.SetIt(2,3,False,[4,3,3, 3,4,2]); e.SetIt(false,[1,2]); d.TensorProd(e,a); f.SetIt(False,[10,11,7]); if not f.Equal(d) then raise Exception.Create('Not same'); // Test on triangular matrices, left a.TriangleForm := tfUpper; a.TriangleUnit := False; a.SetIt(2,2,False,[4,3, 0,4]); e.SetIt(false,[1,2]); d.TensorProd(e,a,mtTriangle); f.SetIt(False,[4,11]); if not f.Equal(d) then raise Exception.Create('Not same'); // Test on triangular matrices, right a.Reset; a.TriangleForm := tfUpper; // data to be referenced is in upper triangle a.TriangleUnit := False; // non unit diagonal a.SetIt(2,2,False,[4,3, 0,4]); e.SetIt(false,[1,2]); d.TensorProd(a,e,mtTriangle); f.SetIt(False,[10,8]); if not f.Equal(d) then raise Exception.Create('Not same'); // Test on symmetric matrices, right a.Reset; a.TriangleForm := tfUpper; a.SetIt(2,2,False,[4,3, 3,4]); e.SetIt(false,[1,2]); d.TensorProd(e,a,mtSymmetric); f.SetIt(False,[10,11]); if not f.Equal(d) then raise Exception.Create('Not same'); // Test on symmetric matrices, Left a.Reset; a.TriangleForm := tfUpper; a.SetIt(2,2,False,[4,3, 3,4]); e.SetIt(false,[1,2]); d.TensorProd(a,e,mtSymmetric); f.SetIt(False,[10,11]); if not f.Equal(d) then raise Exception.Create('Not same'); end; *) function TensorProd(const Mtx: TMtx; Vec: TVec; MtxType: TMtxType = mtGeneral; Operation: TMtxOperation = opNone): TVec; overload; (*Calculates the left tensor product between vector and matrix.*) function TensorProd(const Vec: TVec; Mtx: TMtx; MtxType: TMtxType = mtGeneral; Operation: TMtxOperation = opNone): TVec; overload; (*Inserts zeroes between consecutive vector values. Inserts zeroes between consecutive vector values. The method copies the values from Src to the calling vector and places Factor-1 zeros between consecutive values. The and properties of the calling vector are set implicitly. Phase parameter defines the initial sample offset and must be less than Factor. var a,b: Vector; begin b.SetIt(False,[0,0,1,3,2]); a.UpSample(b,2); // a = [0,0,0,0,1,0,3,0,2,0] end; *) function UpSample(const Src: TMtxVec; Factor: integer; Phase: integer = 0): TVec; overload; (*Transforms vector into vector of standardized data in-place.*) function ZScore: TVec; overload; (*Transforms Src vector into vector of standardized data*) function ZScore(const Src: TVec): TVec; overload; (*Converts the content of the Values array of the calling vector to a list of strings. Converts all elements of the calling vector to strings with formating ReFormat for the real part and ImFormat for the imaginary part and stores them in aList, by using the Add method of TStringsobject. If vector is not complex only the ReFormat is used. Note Complex numbers are formated by default as: a+bi. You can have any formating by specifying the ReFormat and ImFormat parameters, but in order for the to work, the basic a+bi formating must be preserved - (chars '+' (' - ') and 'i' ). Performance note: This routine will be exceedingly slow, if TRichEdit.Lines or TMemo.Lines are passed as a parameter for dstList. Use TStringList or StringList types and then call TMemo.Lines.AddStrings(yourList) for best results. procedure TForm1.Button1Click(Sender: TObject); var a,b: Vector; begin a.SetIt(False,[1,2,3,4]); a.Cos; b.Size(a); b.SetVal(1); a := a + b; //calls a.Add(b);; Richedit1.Clear; Memo1.Clear; a.ValuesToStrings(Richedit1.Lines); b.ValuesToStrings(Richedit1.Lines); a.ValuesToStrings(Memo1.Lines); b.ValuesToStrings(Memo1.Lines); Memo1.Lines.SaveToFile('C:\Test.txt'); Memo1.Lines.LoadFromFile('C:\Test.txt'); a.StringsToValues(Memo1.Lines); end; *) function ValuesToStrings(const dstList: TStrings; const Align: TFixedTextAlign = ftaNone; const ReFormat: string = ' 0.###;-0.###'; const ImFormat: string = '+0.###i;-0.###i'; const Headers: boolean = false; const ColumnWidth: integer = -1): integer; overload; (*Convert elements from Index to Index+Len-1 of the calling vector to strings with formating ReFormat for the real part and ImFormat for the imaginary part. Store them in aList starting at ListIndex. If aList is not large enough, the method will use the add method of aList object. If vector is not complex, only the ReFormat is used. Performance note: This routine will be exceedingly slow, if TRichEdit.Lines or TMemo.Lines are passed as a parameter for dstList. Use TStringList or StringList types and then call TMemo.Lines.AddStrings(yourList) for best results. *) procedure ValuesToStrings(const dstList: TStrings; ListIndex, Index, Len: integer; const Align: TFixedTextAlign = ftaNone; const ReFormat: string = ' 0.###;-0.###'; const ImFormat: string = '+0.###i;-0.###i'; const Headers: boolean = false; const ColumnWidth: integer = -1); overload; (*Convert strings in aList to double or TCplx. Convert strings in aList to complex/real values and store them in the Values array of the calling vector. If any of the strings represent a complex value, then the property is set to True and strings are converted by using the function. The of the calling vector is set to aList.Count. var a,b: Vector; begin a.SetIt(False,[1,2,3,4]); a.cos; b.Size(a); b.SetVal(1); a := a + b; //a.Add(b); Richedit1.Clear; Memo1.Clear; a.ValuesToStrings(Richedit1.Lines); b.ValuesToStrings(Richedit1.Lines); a.ValuesToStrings(Memo1.Lines); b.ValuesToStrings(Memo1.Lines); Memo1.Lines.SaveToFile('C:\Test.txt'); Memo1.Lines.LoadFromFile('C:\Test.txt'); a.StringsToValues(Memo1.Lines); end; *) procedure StringsToValues(aList: TStrings); overload; (*Convert strings in aList to double (TCplx) starting at ListIndex. Store them in the Values array of the calling vector from Index to Index+Len-1. If strings represent complex numbers, then the complex property must be True or an exception is raised. The Length property of the calling vector is not changed. If array bounds are overrun and exception is raised. *) function StringsToValues(aList: TStrings; ListIndex: integer; Index: integer = 0; Len: integer = MtxVecEOA): TVec; overload; end; (*Matrix class for operator overloading in D2006 and later. Declare Matrix instead of TMtx to take advantage of operator overloading in D2006 and later. Be carefull to declare Matrix only for local variables with short lifetime. Call the Create method for Matrix, if the variable is a global variable or a variable with a longer life. It also makes sense to continue to use TMtx for global vars. If the Create method (constuctor) is not called, the Matrix record obtains TMtx object from object cache (fast create). If the Create mehod is called, the TMtx object is created (slower) for use by Matrix record. Object cache has limited size. Note Calling the Create method (constructor) is not mandatory. *) Matrix = record strict private FData: TMtx; private function get_Data: TMtx ; property Data: TMtx read get_Data; function get_FloatPrecision: TMtxFloatPrecision; procedure set_FloatPrecision(const value: TMtxFloatPrecision); function get_IsDouble: boolean; procedure set_IsDouble(const value: boolean); function get_Capacity: Int64; procedure set_Capacity(const value: Int64); function get_CapacityStep: double; procedure set_CapacityStep(const value: double); function get_First: double; function get_Firstc: TCplx; function get_Precision: TPrecision; function get_Rounding: TRounding; function get_BlockEnd: boolean; function get_ComplexValues: string; function get_RealValues: string; procedure set_Precision(const value: TPrecision); procedure set_Rounding(const value: TRounding); procedure set_Alfa(const value: TCplx); procedure set_Beta(const value: TCplx); function get_Alfa: TCplx; function get_Beta: TCplx; procedure set_ZeroTolerance(const value: double); function get_IsSubRange: boolean; function get_SubRangeLevel: integer; function get_ZeroTolerance: double; function get_Caption: string; function get_Complex: boolean; function get_ConditionCheck: boolean; function get_Length: integer; function get_Tag: integer; procedure set_Caption(const value: string); procedure set_Complex(const value: boolean); procedure set_ConditionCheck(const value: boolean); procedure set_Tag(const value: integer); procedure set_Cols(const value: integer); procedure set_Rows(const value: integer); function get_Cols: integer; function get_Rows: integer; function get_AutoMtxType: boolean; function get_Balance: TBalanceType; function get_ConditionNumber: TConditionNumber; function get_FFTOddLength: boolean; function get_FFTScrambledOrder: boolean; function get_FFTStorageFormat: TFFTStorageFormat; function get_LeadingCols: integer; function get_RefineSolution: boolean; function get_SubDiag: integer; function get_SuperDiag: integer; function get_TriangleForm: TTriangleForm; function get_TriangleUnit: boolean; procedure set_AutoMtxType(const value: boolean); procedure set_Balance(const value: TBalanceType); procedure set_ConditionNumber(const value: TConditionNumber); procedure set_FFTOddLength(const value: boolean); procedure set_FFTScrambledOrder(const value: boolean); procedure set_FFTStorageFormat(const value: TFFTStorageFormat); procedure set_LeadingCols(const value: integer); procedure set_RefineSolution(const value: boolean); procedure set_SubDiag(const value: integer); procedure set_SuperDiag(const value: integer); procedure set_TriangleForm(const value: TTriangleForm); procedure set_TriangleUnit(const value: boolean); function get_Last: double; function get_Lastc: TCplx; function get_BackError: double; function get_ConditionNr: double; function get_ForwError: double; function get_Info: integer; function get_MtxError: string; function get_Quadratic: boolean; function get_CValues(const RowIdx, ColIdx: integer): TCplx; function get_Values(const RowIdx, ColIdx: integer): double; procedure set_CValues(const RowIdx, ColIdx: integer; const Value: TCplx); procedure set_Values(const RowIdx, ColIdx: integer; const Value: double); function get_CValues1D(const Idx: integer): TCplx; function get_Values1D(const Idx: integer): double; procedure set_CValues1D(const Idx: integer; const Value: TCplx); procedure set_Values1D(const Idx: integer; const Value: double); function get_SCValues(const RowIdx, ColIdx: integer): TSCplx; function get_SCValues1D(const Idx: integer): TSCplx; function get_SValues(const RowIdx, ColIdx: integer): single; function get_SValues1D(const Idx: integer): single; procedure set_SCValues(const RowIdx, ColIdx: integer; const Value: TSCplx); procedure set_SCValues1D(const Idx: integer; const Value: TSCplx); procedure set_SValues(const RowIdx, ColIdx: integer; const Value: single); procedure set_SValues1D(const Idx: integer; const Value: single); function GetSelect(const Indx, Len: integer): Vector; procedure SetSelect(const Indx, Len: integer; const Value: Vector); function GetSelectIndex(const startIndex, Step, stopIndex: integer): Vector; procedure SetSelectIndex(const startIndex, Step, stopIndex: integer; const Value: Vector); function GetSelect2D(const RowIdx, ColIdx, RowLen, ColLen: integer): Matrix; function GetSelectIndex2D(const StartRowIdx, StartColIdx, StopRowIdx, StopColIdx: integer): Matrix; procedure SetSelect2D(const RowIdx, ColIdx, RowLen, ColLen: integer; const Value: Matrix); procedure SetSelectIndex2D(const StartRowIdx, StartColIdx, StopRowIdx, StopColIdx: integer; const Value: Matrix); public procedure CreateFromCache(Value: boolean); public (*Returns true, if all elements of Left are equal to Right. Size and Complex properties must also match. *) class operator Equal(const Left, Right: Matrix): Boolean; (*Returns true, if all elements of Left are equal to Right.*) class operator Equal(const Left: Matrix; Right: double): Boolean; (*Returns true, if Left is equal to all elements in Right.*) class operator Equal(Left: double;const Right: Matrix): Boolean; (*Returns true, if all elements of Left are equal to Right.*) class operator Equal(const Left: Matrix;const Right: TCplx): Boolean; (*Returns true, if Left is equal to all elements in Right.*) class operator Equal(const Left: TCplx; const Right: Matrix): Boolean; (*Returns true, if all elements of Left are equal to Right. Size and Complex properties must also match. *) class operator Equal(Left: TMtx; const Right: Matrix): Boolean; (*Returns true, if all elements of Left are equal to Right. Size and Complex properties must also match. *) class operator Equal(const Left: Matrix; Right: TMtx): Boolean; (*Returns true, if all elements of Left are equal to Right. Size and Complex properties must also match. *) class operator Equal(Left: TVec; const Right: Matrix): Boolean; (*Returns true, if all elements of Left are equal to Right. Size and Complex properties must also match. *) class operator Equal(const Left: Matrix; Right: TVec): Boolean; (*Returns true, if any elements in Left are not equal to Right. Size or Complex properties also do not match. *) class operator NotEqual(const Left, Right: Matrix): Boolean; (*Returns true, if any elements in Left are not equal to Right. Size or Complex properties also do not match. *) class operator NotEqual(const Left: Matrix; Right: double): Boolean; (*Returns true, if any elements in Right are not equal to Left.*) class operator NotEqual(Left: double;const Right: Matrix): Boolean; (*Returns true, if any elements in Left are not equal to Right.*) class operator NotEqual(Left: Matrix;const Right: TCplx): Boolean; (*Returns true, if any elements in Right are not equal to Left.*) class operator NotEqual(const Left: TCplx;const Right: Matrix): Boolean; (*Returns true, if any elements in Left are not equal to Right. Size or Complex properties also do not match. *) class operator NotEqual(Left: TMtx; const Right: Matrix): Boolean; (*Returns true, if any elements in Left are not equal to Right. Size or Complex properties also do not match. *) class operator NotEqual(Left: TVec; const Right: Matrix): Boolean; (*Returns true, if any elements in Left are not equal to Right. Size or Complex properties also do not match. *) class operator NotEqual(const Left: Matrix; Right: TMtx): Boolean; (*Returns true, if any elements in Left are not equal to Right. Size or Complex properties also do not match. *) class operator NotEqual(const Left: Matrix; Right: TVec): Boolean; (*Returns true, if ALeft is less than ARight. Returns true, if all elements in ALeft are less than ARight. *) class operator LessThan(const ALeft: Matrix; const ARight: TCplx): Boolean; (*Returns true, if ALeft is less than ARight. Returns true, if ALeft is less from all elements in ARight. *) class operator LessThan(const ALeft: TCplx; const ARight: Matrix): Boolean; (*Returns true, if ALeft is less than ARight. Returns true, if all elements in ALeft are less than ARight. *) class operator LessThan(const ALeft: Matrix; const ARight: double): Boolean; (*Returns true, if ALeft is less than ARight. Returns true, if ALeft is less from all elements in ARight. *) class operator LessThan(const ALeft: double; const ARight: Matrix): Boolean; (*Returns true, if ALeft is less than ARight. Returns true, if all elements in ALeft are less than ARight. *) class operator LessThan(const ALeft: Matrix; const ARight: Matrix): Boolean; (*Returns true, if ALeft is less than ARight. Returns true, if all elements in ALeft are less than ARight. *) class operator LessThan(const ALeft: Vector; const ARight: Matrix): Boolean; (*Returns true, if ALeft is less than ARight. Returns true, if all elements in ALeft are less than ARight. *) class operator LessThan(const ALeft: Matrix; const ARight: Vector): Boolean; (*Returns true, if ALeft is less than or equal to ARight. Returns true, if all elements in ALeft are less than or equal to ARight. *) class operator LessThanOrEqual(const ALeft: Matrix; const ARight: TCplx): Boolean; (*Returns true, if ALeft is less than or equal to ARight. Returns true, if ALeft is less than or equal to all elements in ARight. *) class operator LessThanOrEqual(const ALeft: TCplx; const ARight: Matrix): Boolean; (*Returns true, if ALeft is less than or equal to ARight. Returns true, if all elements in ALeft are less than or equal to ARight. *) class operator LessThanOrEqual(const ALeft: Matrix; const ARight: double): Boolean; (*Returns true, if ALeft is less than or equal to ARight. Returns true, if ALeft is less than or equal to all elements in ARight. *) class operator LessThanOrEqual(const ALeft: double; const ARight: Matrix): Boolean; (*Returns true, if ALeft is less than or equal to ARight. Returns true, if ALeft is less than or equal to all elements in ARight. *) class operator LessThanOrEqual(const ALeft: Matrix; const ARight: Matrix): Boolean; (*Returns true, if ALeft is less than or equal to ARight. Returns true, if ALeft is less than or equal to all elements in ARight. *) class operator LessThanOrEqual(const ALeft: Vector; const ARight: Matrix): Boolean; (*Returns true, if ALeft is less than or equal to ARight. Returns true, if ALeft is less than or equal to all elements in ARight. *) class operator LessThanOrEqual(const ALeft: Matrix; const ARight: Vector): Boolean; (*Returns true, if ALeft is greater than or equal to ARight. Returns true, if all elements in ALeft are greater than or equal to ARight. *) class operator GreaterThanOrEqual(const ALeft: Matrix; const ARight: TCplx): Boolean; (*Returns true, if ALeft is greater than or equal to ARight. Returns true, if ALeft is greater than or equal to all elements in ARight. *) class operator GreaterThanOrEqual(const ALeft: TCplx; const ARight: Matrix): Boolean; (*Returns true, if ALeft is greater than or equal to ARight. Returns true, if all elements in ALeft are greater than or equal to ARight. *) class operator GreaterThanOrEqual(const ALeft: Matrix; const ARight: double): Boolean; (*Returns true, if ALeft is greater than or equal to ARight. Returns true, if ALeft is greater than or equal to all elements in ARight. *) class operator GreaterThanOrEqual(const ALeft: double; const ARight: Matrix): Boolean; (*Returns true, if ALeft is greater than or equal to ARight. Returns true, if ALeft is greater than or equal to all elements in ARight. *) class operator GreaterThanOrEqual(const ALeft: Matrix; const ARight: Matrix): Boolean; (*Returns true, if ALeft is greater than or equal to ARight. Returns true, if ALeft is greater than or equal to all elements in ARight. *) class operator GreaterThanOrEqual(const ALeft: Vector; const ARight: Matrix): Boolean; (*Returns true, if ALeft is greater than or equal to ARight. Returns true, if ALeft is greater than or equal to all elements in ARight. *) class operator GreaterThanOrEqual(const ALeft: Matrix; const ARight: Vector): Boolean; (*Returns true, if ALeft is greater than ARight. Returns true, if all elements in ALeft are greater than ARight. *) class operator GreaterThan(const ALeft: Matrix; const ARight: TCplx): Boolean; (*Returns true, if ALeft is greater than ARight. Returns true, if ALeft is greater than to all elements in ARight. *) class operator GreaterThan(const ALeft: TCplx; const ARight: Matrix): Boolean; (*Returns true, if ALeft is greater than ARight. Returns true, if all elements in ALeft are greater than ARight. *) class operator GreaterThan(const ALeft: Matrix; const ARight: double): Boolean; (*Returns true, if ALeft is greater than ARight. Returns true, if ALeft is greater than to all elements in ARight. *) class operator GreaterThan(const ALeft: double; const ARight: Matrix): Boolean; (*Returns true, if ALeft is greater than ARight. Returns true, if ALeft is greater than to all elements in ARight. *) class operator GreaterThan(const ALeft: Matrix; const ARight: Matrix): Boolean; (*Returns true, if ALeft is greater than ARight. Returns true, if ALeft is greater than to all elements in ARight. *) class operator GreaterThan(const ALeft: Vector; const ARight: Matrix): Boolean; (*Returns true, if ALeft is greater than ARight. Returns true, if ALeft is greater than to all elements in ARight. *) class operator GreaterThan(const ALeft: Matrix; const ARight: Vector): Boolean; (*Adds Left to Right and returns result. *) class operator Add(const Left: TCplx; const Right: Matrix): Matrix; (*Adds Left to Right and returns result. *) class operator Add(const Left: Matrix; const Right: TCplx): Matrix; (*Adds Left to Right and returns result. *) class operator Add(Left: double;const Right: Matrix): Matrix; (*Adds Left to Right and returns result. *) class operator Add(const Left: Matrix; Right: double): Matrix; (*Adds Left to Right and returns result. *) class operator Add(Left: TMtxVec;const Right: Matrix): Matrix; (*Adds Left to Right and returns result. *) class operator Add(const Left: Matrix; Right: TMtxVec): Matrix; (*Adds Left to Right and returns result. *) class operator Add(const Left: Matrix;const Right: Matrix): Matrix; (*Subtracts Right from Left and returns result. *) class operator Subtract(const Left: TCplx; const Right: Matrix): Matrix; (*Subtracts Right from Left and returns result. *) class operator Subtract(const Left: Matrix; const Right: TCplx): Matrix; (*Subtracts Right from Left and returns result. *) class operator Subtract(Left: double; const Right: Matrix): Matrix; (*Subtracts Right from Left and returns result. *) class operator Subtract(const Left: Matrix; Right: double): Matrix; (*Subtracts Right from Left and returns result. *) class operator Subtract(const Left: Matrix; Right: TMtxVec): Matrix; (*Subtracts Right from Left and returns result. *) class operator Subtract(Left: TMtxVec; const Right: Matrix): Matrix; (*Subtracts Right from Left and returns result. *) class operator Subtract(const Left: Matrix;const Right: Matrix): Matrix; (*Multiplies Left with Right and returns result. *) class operator Multiply(const Left: Matrix; const Right: TCplx): Matrix; (*Multiplies Left with Right and returns result. *) class operator Multiply(const Left: TCplx; const Right: Matrix): Matrix; (*Multiplies Left with Right and returns result. *) class operator Multiply(const Left: Matrix; Right: double): Matrix; (*Multiplies Left with Right and returns result. *) class operator Multiply(Left: double; const Right: Matrix): Matrix; (*Multiplies Left with Right and returns result. *) class operator Multiply(const Left: Matrix; const Right: TMtxVec): Matrix; (*Multiplies Left with Right and returns result. *) class operator Multiply(const Left: TMtxVec; const Right: Matrix): Matrix; (*Multiplies Left with Right and returns result. *) class operator Multiply(const Left: Matrix; const Right: Vector): Matrix; (*Multiplies Left with Right and returns result. *) class operator Multiply(const Left: Vector; const Right: Matrix): Matrix; (*Multiplies Left with Right and returns result. *) class operator Multiply(const Left: Matrix; const Right: Matrix): Matrix; (*Dividies Left with Right and returns result. *) class operator Divide(const Left: Matrix; const Right: TCplx): Matrix; (*Dividies Left with Right and returns result. *) class operator Divide(const Left: TCplx; const Right: Matrix): Matrix; (*Dividies Left with Right and returns result. *) class operator Divide(const Left: Matrix; Right: double): Matrix; (*Dividies Left with Right and returns result. *) class operator Divide(Left: double; const Right: Matrix): Matrix; (*Dividies Left with Right and returns result. *) class operator Divide(const Left: Matrix; Right: TMtxVec): Matrix; (*Dividies Left with Right and returns result. *) class operator Divide(Left: TMtxVec; const Right: Matrix): Matrix; (*Dividies Left with Right and returns result. *) class operator Divide(const Left: Matrix; const Right: Matrix): Matrix; (*Negates AValue and returns result. *) class operator Negative(const AValue: Matrix): Matrix; (*Copies data in AValue to T2DCxplArray and returns result. *) class operator Explicit(const AValue: Matrix): T2DCplxArray; (*Copies data in AValue to T2DDoubleArray and returns result. *) class operator Explicit(const AValue: Matrix): T2DDoubleArray; (*Copies data in AValue to T2DCxplArray and returns result. *) class operator Explicit(const AValue: T2DCplxArray): Matrix; (*Copies data in AValue to T2DDoubleArray and returns result. *) class operator Explicit(const AValue: T2DDoubleArray): Matrix; (*Copies Matrix data to VectorInt. Copies all values from AValue to the result. *) class operator Explicit(const AValue: Matrix): VectorInt; (*Dereferences internal TMtx objects and returns a pointer.*) class operator Implicit(const AValue: Matrix): TMtx; overload; (*Dereferences internal TMtx objects and returns a pointer.*) class operator Implicit(const AValue: Matrix): TMtxVec; overload; (*Dereferences internal TMtx objects and returns a pointer.*) class operator Implicit(const AValue: Matrix): TDenseMtxVec; overload; (*Dereferences internal TMtx objects and returns a pointer.*) class operator Implicit(const AValue: Matrix): TMtxVecBase; overload; (*Dereferences internal TMtx objects and returns a pointer.*) class operator Implicit(const AValue: Matrix): TObject; overload; (*Copies data in AValue to TSingleArray and returns result. *) class operator Explicit(const AValue: Matrix): TSingleArray; (*Copies data in AValue to TDoubleArray and returns result. *) class operator Explicit(const AValue: Matrix): TDoubleArray; (*Copies data in AValue to TCplxArray and returns result. Not thread safe for subranged objects, because it temporarily modifies negative Index of the array for RefCount purposes. *) class operator Implicit(const AValue: Matrix): TCplxArray; (*Implicit type conversion from Matrix to PCplx. Returns a pointer to the internal array of values. If the Precision does not match an exception will be raised. This conversion avoids all range checking, which would be broken, if Matrix.IsSubRange = True. *) class operator Implicit(const AValue: Matrix): PPCplx; (*Copies data in AValue to TDoubleArray and returns result. Not thread safe for subranged objects, because it temporarily modifies negative Index of the array for RefCount purposes. *) class operator Implicit(const AValue: Matrix): TDoubleArray; (*Implicit type conversion from Matrix to an array of double. Returns a pointer to the internal array of values. If the Precision does not match an exception will be raised. This conversion avoids all range checking, which would be broken, if Matrix.IsSubRange = True. *) class operator Implicit(const AValue: Matrix): PPDouble; (*Copies data in AValue to TCplxArray and returns result. Not thread safe for subranged objects, because it temporarily modifies negative Index of the array for RefCount purposes. *) class operator Implicit(const AValue: Matrix): TSCplxArray; (*Implicit type conversion from Matrix to PSCplx. Returns a pointer to the internal array of values. If the Precision does not match an exception will be raised. This conversion avoids all range checking, which would be broken, if Matrix.IsSubRange = True. *) class operator Implicit(const AValue: Matrix): PPSCplx; (*Copies data in AValue to TDoubleArray and returns result. Not thread safe for subranged objects, because it temporarily modifies negative Index of the array for RefCount purposes. *) class operator Implicit(const AValue: Matrix): TSingleArray; (*Implicit type conversion from Matrix to PSingle. Returns a pointer to the internal array of values. If the Precision does not match an exception will be raised. This conversion avoids all range checking, which would be broken, if Matrix.IsSubRange = True. *) class operator Implicit(const AValue: Matrix): PPSingle; (*Adopts TMtx object. Src object will be adopted by Matrix. When the Matrix gets out of scope, the object will be freed. *) procedure Adopt(const Src: TMtx); overload; (*Adopts a pointer to one dimensional array. Addopts a pointer to AArray array. The method sets the calling matrix property to aFloatPrecision, to ARows, to ACols and Values1D and CValues1D to Pointer(AArray). Notes: * Required to call the method, before freeing the object * Do not resize the matrix * Do not call routines relying on Lapack when cross-platform "Core edition" is used (not linking dlls), because pascal version of Lapack will assume that adopted memory is a dynamic array and will modify array Index -2. * TMtx.Values1D array assignment or passing array by var (internal to library) will cause memory corruption in this case. * To be used with great care only. *) procedure Adopt(AArray: PAPointer; ARows, ACols: integer; aIsComplex: boolean; aIsDouble: boolean); overload; procedure Adopt(AArray: PAPointer; ARows, ACols: integer; aFloatPrecision: TMtxFloatPrecision); overload; (*Disowns a pointer to an array from matrix Values1D. The method does the opposite of the method. It will set the AArrays to Pointer(Values), ARows and ACols to matrix's and and IsComplex to matrix Complex property. Use the Disown method to "disconnect" AArray from the TMtx.Values1D. Disown sets Values1D and CValues1D array pointers to nil and Rows, Cols properties to ACols, but without freeing the allocated memory. The allocated memory can be disowned only, if it was adopted with a call to the method. *) procedure Disown(out AArray: PAPointer; out ARows, ACols: integer; out aIsComplex: boolean; out aIsDouble: boolean); overload; procedure Disown(out AArray: PAPointer; out ARows, ACols: integer; out aFloatPrecision: TMtxFloatPrecision); overload; (*Disowns a pointer to an array from calling matrix Values1D. It dismisses the Values, Values1D, CValues1D array and sets the and to zero. *) procedure Disown; overload; (*Uses Src object as internal storage. The resulting Matrix will own Src object of TMtx type and will release it once Matrix gets out of scope. *) constructor Create(const Src: TMtx); overload; (*Internally creates TMtx object without using object cache. Creates TMtx object without using object cache. Suitable for declaring global variables. To obtain Matrix type with storage from object cache, do not call the constructor, but simply declare the var. *) constructor Create(const aRows, aCols: integer; const aIsComplex: boolean; const aIsDouble: boolean); overload; public (*Enables/disable inline condition checking. Enables/disables inline condition checking. When true, TVec methods perform additional (range) checking before operations are executed. The drawback is slight loss of speed. If ConditionCheck is set to false then no additional checking is performed. This speeds up the execution but disables some safeguards. For short vectors the loss of speed can be significant. The more parameters the method requires the more error checking is performed. Some methods (parameterless) don't use the ConditionCheck property at all. ConditionCheck property is initially True. This property is an additional safeguard against array overrun or underrun errors. It allows you to work with explicit range checking while writing and debugging the application and once your code is running you can turn it off. By functionality it is similar to assertions. (See Assert procedure). You can also use compiler directives to check, if assertions are on and then set ConditionCheck to True. *) property ConditionCheck: boolean read get_ConditionCheck write set_ConditionCheck; (*Object caption. Use this property to set/get the object string caption. This can be usefull for associating description with data when making a user interface. *) property Caption: string read get_Caption write set_Caption; (*Stores an integer value as a part of Matrix object. Stores an integer value as a part of Matrix object. Tag has no predefined meaning. The Tag property is provided for the convenience of developers. It can be used for storing an additional integer value or it can be typecast to any 32-bit value such as a component reference or even Object pointer. *) property Tag: integer read get_Tag write set_Tag; (*Defines if object values are complex. If true, will treat it's elements as complex numbers. Two successive number in the values array be treated as real and imaginary part of the complex number. When property is false, object will treat it's elements as real numbers. You should always set the value of the Complex property before setting object size ( for vector or , for matrix). Setting Complex from true to false does not cause memory reallocation. It simply doubles the value of the Length property. Setting Complex from false to true halves the vector length or number of matrix columns, but retains all data. Complex property is initially false. var a,b,c,d: Matrix; begin a.SetIt(1,2,True,[1,2,3,4]); b.SetIt(1,4,False,[8,9,6,7]); b.Complex := True; c.Mul(a,b); // = [(1+2i)*(8*9i), (3+4i)*(6+7i)] end; *) property Complex: boolean read get_Complex write set_Complex; (*Defines the number of matrix rows. Use this property to set or get the number of the calling matrix rows. Setting the Rows does not affect the actual amount of memory allocated unless Rows*Cols is bigger than cache size. Note Always set the property before setting Rows. Complex is initially false and Rows is initially 0. You can also set the Rows property by calling the method. *) property Rows: integer read get_Rows write set_Rows; (*Defines the number of matrix columns. Use this property to set or get the number of the calling matrix columns. Setting the Cols does not affect the actual amount of memory allocated unless Rows*Cols is bigger than cache size. Note Always set the property before setting Cols. Complex is initially false and Cols is initially 0. You can also set the Cols property by calling the method. *) property Cols: integer read get_Cols write set_Cols; (*Defines the precision (single, float) and type (real, complex) of the floating point operations. *) property FloatPrecision: TMtxFloatPrecision read get_FloatPrecision write set_FloatPrecision; (*FFT storage format. The FFT storage format specifies how will the result of an operation be stored in the destination. This affects both 1D and 2D FFT's. *) property FFTStorageFormat: TFFTStorageFormat read get_FFTStorageFormat write set_FFTStorageFormat; (*Leave FFT scrambeled. The last stage (or first) of an FFT, is a sorting operation. This sorting will be left out, if this property will be set to True. This can improve performance for certain applications, if you used properly. *) property FFTScrambled: boolean read get_FFTScrambledOrder write set_FFTScrambledOrder; (*Defines if FFT transform length is odd. The property should be set to True, if the length of a forward real to complex FFT is odd and if the result of an inverser complex to real FFT should be odd. *) property FFTOddLength: boolean read get_FFTOddLength write set_FFTOddLength; (*Defines if matrix type will be checked automatically. If True, some routines requesting information will check for the matrix type first by calling the method, in order to select the most efficient algorithm. The following types will be detected: mtSymmetric = symmetric matrix mtHermitian = Hermitian matrix mtTriangle = triangular matrix, with unit or non unit main diagonal mtGeneral = general matrix (none of the above) In worst case the matrix type detection will require O(n^2) compare operations. In case of a general matrix, it only takes a few cycles for the algorithm to detect that the matrix is not Symmetric, triangular or Hermitian. And in case of a symmetric or hermitian or triangular matrix, the cost of O(n^2) compare operations is still much lower than the loss of performance, when using the general purpose algorithm. For some computations, like eigenvalues, the type of the matrix has to specified explicitly, especially when it comes to symmetric matrices, because the algorithm for the general matrix will fail on a symmetric matrix. If you specify the type of matrix explicitly to the procedures and AutoMtxType is set to True, then AutoMtxType will override the user specified type. *) property AutoMtxType: boolean read get_AutoMtxType write set_AutoMtxType; (*Defines matrix balancing method. Defines which will be used to balance the calling matrix. Balancing the calling matrix can be very useful when calculating the eigenvalues and eigenvector. Balancing operation can perform one or both of the following similarity transformations: 1.Permute the calling matrix (A) to block of upper triangular form: where P is a permutation matrix, and A'11 and A' 33 are upper triangular. The diagonal elements of A'11 and A' 33 are eigenvalues of the calling matrix (A). 2.Apply a diagonal similarity transformation to A', to make the rows and columns of A'22 as close in norm as possible: This scaling can reduce the norm of the matrix (that is, ||A''22|| < ||A'22||), and hence reduce the effect of rounding errors on the accuracy of computed eigenvalues and eigenvectors. var A: Matrix; d: Vector; begin // ... A.Balance := btFull; // applies both methods A.Eig(d); // ... end; *) property Balance: TBalanceType read get_Balance write set_Balance; (*Defines the norm used to compute the condition number. Defines the norm used to compute the . The default value is cnNone meaning that no condition number will be estimated. *) property ConditionNumber: TConditionNumber read get_ConditionNumber write set_ConditionNumber; (*Enables/disables the refining of the solution of the system of linear equations. The method enables/disables the refining of the solution of the system of linear equations, computed by method. When RefineSolution is enabled, an iterative refinement of the solution to a system of linear equations is executed. For each computed solution the component-wise and the the component-wise in the computed solution are calculated as well. var X,B: Vector; A: Matrix; begin B.SetIt(False,[0,2]); A.SetIt(2,2,false,[1,2, 3,4]); // 2x2, not complex matrix A.RefineSolution := True; A.ConditionNumber := cnNormInf; A.LUSolve(B,X); end; *) property RefineSolution: boolean read get_RefineSolution write set_RefineSolution; (*Defines the number of leading columns. This value defines the spacing in number of samples between rows. It is fixed to be the same to the value of (for now). *) property LeadingCols: integer read get_LeadingCols write set_LeadingCols; (*The number of superdiagonals in banded matrices. Sets/reads the number of superdiagonals in banded matrices. *) property SuperDiag: integer read get_SuperDiag write set_SuperDiag; (*The number of subdiagonals in banded matrices. Sets/reads the number of subdiagonals in banded matrices. *) property SubDiag: integer read get_SubDiag write set_SubDiag; (*Determine which part (upper or lower) of the symmetric, hermitian or triangular matrix is set. Determine which part (upper or lower) of the symmetric, hermitian or triangular matrix is set. *) property TriangleForm: TTriangleForm read get_TriangleForm write set_TriangleForm; (*Determine, if the matrix is unit triangular. *) property TriangleUnit: boolean read get_TriangleUnit write set_TriangleUnit; (*Stores the condition number reciprocial value after the call to LUSolve. The property is set by the method. It contains the calling matrix condition number reciprocial value after the call to method and if property was not cnNone. If the ConditionNr (inverse of condition number) is a very small number (thus the condition number is very large), then the calling matrix is ill-conditioned and the error in the solution will also be large. The condition number is used for analyzing the errors in the solution of a system of linear equations. In practice, most computations are performed with rounding errors. Besides, you often need to solve a system Ax = b where the data (the elements of A and b) are not known exactly. Therefore, it's important to understand how the data errors and rounding errors can affect the solution X. If X is the exact solution of Ax = b, and X + dx is the exact solution of a perturbed problem (A + dA)X = (b + db), then In other words, relative errors in A or b may be amplified in the solution vector X by a factor k(A) = ||A|| ||A -1 || called the condition number of A. The norm used to calculate the condition number is set by the property. Rounding errors have the same effect as relative perturbations c(n)e in the original data. Here e is the machine precision, and c(n) is a modest function of the matrix order n. The corresponding solution error is ||dx||/||x|| <= c(n)k(A)e. (The value of c(n) is seldom greater than 10n), Thus, if your matrix A is ill-conditioned (that is, its condition number k(A) is very large), then the error in the solution X is also large; you may even encounter a complete loss of precision. This loss can be greatly reduced by enabling the property. var X,B: Vector; A: Matrix; begin B.SetIt(False,[0,2]); A.SetIt(2,2,false,[1,2, 3,4]); // 2x2, not complex matrix A.RefineSolution := True; A.ConditionNumber := cnNormInf; A.LUSolve(B,X); end; *) property ConditionNr: double read get_ConditionNr; (*The info parameter as returned by the last called LAPACK function.*) property Info: integer read get_Info; (*The type of the error condition signaled by LAPACK. The string is set by the various methods, to indicate the type of the error condition signaled by LAPACK if property is not zero. *) property MtxError: string read get_MtxError; (*True, if matrix is quadratic (rows=cols).*) property Quadratic: boolean read get_Quadratic; (*The component-wise backward error. Set by the method, if the property was True. The BackError property returns the component-wise backward error b. The backward error is the smallest relative perturbation in elements of A (where A is the calling matrix) and b such that X is the exact solution of the perturbed system: The BackError property is calculated only if the property is set to true. *) property BackError: double read get_BackError; (*The component-wise forward error. Set by the method, if the property was True. The ForwError property returns the component-wise forward error in the computed solution: *) property ForwError: double read get_ForwError; (*Defines the length of matrix in number of samples. The length of matrix equals: rows*cols. *) property Length: integer read get_Length; (*Sizing the object will not allocate less than Capacity samples. To free memory allocated before, first set Capacity to 0. In case of complex numbers the size is half here specified. *) property Capacity: Int64 read get_Capacity write set_Capacity; (*Specifies increment step for the Capacity property. If this property is 0, the Capacity will never be modified on its own. When the value 1, the capacity will continue increasing to match largest value requested. When the value is more than 1, the capacity will be increasing with the factor specified. *) property CapacityStep: double read get_CapacityStep write set_CapacityStep; public (*Matrix constructor.*) constructor Create(const aRows, aCols: integer; const aFloatPrecision: TMtxFloatPrecision); overload; constructor Create(const aRows, aCols: integer; const aFloatPrecisionRef: TMtxVec); overload; constructor Create(const aRows, aCols: integer); overload; constructor Create(const aRows, aCols: integer; const aIsComplex: boolean); overload; property IsDouble: boolean read get_IsDouble write set_IsDouble; (*Constructor of the record. Returns a Matrix with internal TMtx object created from object cache (CreateIt), if FromObjectCache is True. Pass false to the constructor, if the variable is a global variable. Object cache has limited size and to be used only for local variables. *) constructor Create(FromObjectCache: boolean); overload; (*Obtains a pointer to the real value of the Matrix at Index. The function returns @Values[i]. Under .NET this is a pointer to pinned memory. *) function PValues1D(const Index: integer): PPDouble; (*Obtains a pointer to the real value of the Matrix at Index. The function returns @Values[i]. Under .NET this is a pointer to pinned memory. *) function PSValues1D(const Index: integer): PPSingle; (*Obtains a pointer to the complex value of the Matrix at Index. The function returns @CValues[i]. Under .NET this is a pointer to unmanaged memory. *) function PCValues1D(const Index: integer): PPCplx; (*Obtains a pointer to the complex value of the Matrix at Index. The function returns @CValues[i]. Under .NET this is a pointer to unmanaged memory. *) function PSCValues1D(const Index: integer): PPSCplx; (*Additional parameter for certain Lapack methods. Additional parameter for certain Lapack methods. When this value is used, it is mentioned in the method description. This parameter has been made a field of the object, to reduce the number of parameters required by a method, because it is not used very often. *) property Beta: TCplx read get_Beta write set_Beta; (*Additional parameter for certain Lapack methods. Additional parameter for certain Lapack methods. When this value is used, it is mentioned in the method description. This parameter has been made a field of the object, to reduce the number of parameters required by a method, because it is not used very often. *) property Alfa: TCplx read get_Alfa write set_Alfa; (*Debugging aid. Returns the contents of the object formated as a string to be used by the debugger Watches. *) property RealValues: string read get_RealValues; (*Debugging aid. Returns the contents of the object formated as a string to be used by the debugger Watches. *) property ComplexValues: string read get_ComplexValues; (*Defines the rounding used by streaming routines. *) property Rounding: TRounding read get_Rounding write set_Rounding; (*Defines the precision used by streaming routines. *) property Precision: TPrecision read get_Precision write set_Precision; (*Returns true, if the currrent subrange of the Matrix was also the last subrange in the Matrix. Returns true, if the currrent subrange of the Matrix was also the last subrange in the Matrix. This property be used together with and . *) property BlockEnd: boolean read Get_BlockEnd; (*Set to true after the SetSubIndex or SetSubRange call. This property is set to true after the or call. If IsSubRange is true then the TVec method/function will be performed on subrange of values. Use to set IsSubRange back to False and thus reset sub range to full Matrix length. *) property IsSubRange: boolean read get_IsSubRange; (*Returns the current depth of SubRange stack.*) property SubRangeLevel: integer read get_SubRangeLevel; (*The tolerance used by . The tolerance used by when the comparison type is relative. *) property ZeroTolerance: double read get_ZeroTolerance write set_ZeroTolerance; {$WARNINGS OFF} (*Access elements of the matrix. The RowIdx indicates the row Index and the ColIdx parameter indiciates the column Index. *) property Values[const RowIdx, ColIdx: integer]: double read get_Values write set_Values; default; (*Access elements of the matrix. The RowIdx indicates the row Index and the ColIdx parameter indiciates the column Index. *) property CValues[const RowIdx, ColIdx: integer]: TCplx read get_CValues write set_CValues; (*Access elements of the Matrix or matrix. The Idx parameter can be translated to row and column indexes like this: RowIndex := Idx div Mtx.Cols; ColumnIndex := Idx mod Mtx.Cols; To compute the Index at a given row and column: Idx := RowIndex*Mtx.Cols + ColumnIndex; *) property Values1D[const Idx: integer]: double read get_Values1D write set_Values1D; (*Access elements of the Matrix or matrix. The Idx parameter can be translated to row and column indexes like this: RowIndex := Idx div Mtx.Cols; ColumnIndex := Idx mod Mtx.Cols; To compute the Index at a given row and column: Idx := RowIndex*Mtx.Cols + ColumnIndex; *) property CValues1D[const Idx: integer]: TCplx read get_CValues1D write set_CValues1D; (*Access elements of the matrix. The RowIdx indicates the row Index and the ColIdx parameter indiciates the column Index. *) property SValues[const RowIdx, ColIdx: integer]: single read get_SValues write set_SValues; (*Access elements of the matrix. The RowIdx indicates the row Index and the ColIdx parameter indiciates the column Index. *) property SCValues[const RowIdx, ColIdx: integer]: TSCplx read get_SCValues write set_SCValues; (*Access elements of the Matrix or matrix. The Idx parameter can be translated to row and column indexes like this: RowIndex := Idx div Mtx.Cols; ColumnIndex := Idx mod Mtx.Cols; To compute the Index at a given row and column: Idx := RowIndex*Mtx.Cols + ColumnIndex; *) property SValues1D[const Idx: integer]: single read get_SValues1D write set_SValues1D; (*Access elements of the Matrix or matrix. The Idx parameter can be translated to row and column indexes like this: RowIndex := Idx div Mtx.Cols; ColumnIndex := Idx mod Mtx.Cols; To compute the Index at a given row and column: Idx := RowIndex*Mtx.Cols + ColumnIndex; *) property SCValues1D[const Idx: integer]: TSCplx read get_SCValues1D write set_SCValues1D; (*Allows copying/assignment of subranges. Reading this property will return a sub-ranged Vector. Similar to calling b.SetSubRange(a, Indx, Len); Writing this property will copy source to the specified subrange. The size of the value being assigned needs to match the range specified. *) property Select[const Indx, Len: integer]: Vector read GetSelect write SetSelect; (*Allows copying/assignment of subranges. Reading this property will return a copied selection of subranged vector by calling Dst.GatherByIncr(Src, startIndex, Step); Writing this property will copy source to the specified range by using Data.ScatterByIncr. The size of the value being assigned needs to match the index range specified. This property does not obtain a "view" unless Step equals to 1. *) property SelectIndex[const startIndex, Step, stopIndex: integer]: Vector read GetSelectIndex write SetSelectIndex; (*Allows copying/assignment of subranges. Reading this property will copy Matrix from the specified location. Writing this property will copy the Source to the specified location. This property does not obtain a "view". *) property Select2D[const RowIdx, ColIdx, RowLen, ColLen: integer]: Matrix read GetSelect2D write SetSelect2D; (*Allows copying/assignment of subranges. Reading this property will copy Matrix from the specified location. Writing this property will copy the Source to the specified location. This property does not obtain a "view". *) property SelectIndex2D[const StartRowIdx, StartColIdx, StopRowIdx, StopColIdx: integer]: Matrix read GetSelectIndex2D write SetSelectIndex2D; {$WARNINGS ON} (*Returns content as a string. Values will be separated by line breaks. *) function ToString: string; (*Parses string content as vector. Values need to be separated by the tab charachter. Rows of values need to be separated by line breaks. For other parsing options call StringToValues. The Parse method works in pair with the ToString method both meant to be a reverse of the other, but do not preserve any other property of the matrix except only values. Use SaveToStream/LoadFromStream methods for binary storage option, which uses about 2x less memory and is a lot faster to save and load. *) class function Parse(const Src: string): Matrix; static; procedure AssignWithoutCopy(const Src: Matrix); procedure Assign(const Src: Matrix); (*Initializes block processing. Initializes block processing. Because the size of the CPU cache is limited, significant performance gains can be obtained by splitting long vectors in to a series of short ones, which can all fit in the CPU cache entirely. The BlockInit method is to be used together with and methods to initialize a block processing while loop. BlockInit will call to obtain subrange of the data in TVec. The of the subranged Matrix is determined by the global variable declared in unit. Default value of MtxVecBlockSize is preset to 800 Matrix elements for double precision and 1600 elements for single precision. BlockInit supports nested calls and from witihin a blocked while loop you can call procedures and functions which are also blocked. If you use block processing, typical performance gains will range from 2 to a maximum of 6. Block processing can not be used, or it is difficult to apply, in cases where Matrix elements are not independent of each other. The block processing while loop must be written like this: a.BlockInit; while not A.BlockEnd do begin // .... user defined function a.BlockNext. end; Normal vectorized procedure: procedure ParetoPDF(const X: Matrix; a, b: double;var Res: Matrix); overload; begin Res.Size(X); Res.Power(X,-(a+1)); Res.Mul(Power(b,a)*a);; end; Vectorized and blocked version of the Pareto probability distribution procedure: procedure ParetoPDF(const X: Matrix; a, b: double; var Res: Matrix); overload; begin Res.Size(X); Res.BlockInit; X.BlockInit; while not X.BlockEnd do begin Res.Power(X,-(a+1)); Res.Mul(Power(b,a)*a); Res.BlockNext; X.BlockNext; end; end; The block version of the ParetoPDF will execute faster then the non-blocked version in cases where X contains 5000-10000 elements or more (double precision). Below that value the two versions will perform about the same, except for very short Matrix sizes (below 50 elements), where the non-blocked version will have a slight advantage, because of the absence of block processing methods overhead. The time is saved between the calls to Res.Power(X,-(a+1)) and Res.Mul(Power(b,a)*a), where the same memory (stored in Res Matrix) is accesed in two consecutive calls. That memory is loaded in the CPU cache on the first call, if the Length of the Res Matrix is short enough to fit in. As an excercise you can also try to compare the performance of the vectorized and blocked version of the function with the single value version (ParetoPDF(X: double; a, b: double; Res: double) and measure the execution time of both versions for long vectors (100 000 elements) and short vectors (10 elements). The differences with block processing will be more noticable on old CPU's without support for SSE2/SSE3. *) procedure BlockInit; overload; (**) procedure BlockInit(ABlockSize: integer); overload; (*Initializes block processing.*) procedure BlockInit(const Src: TMtxVecBase); overload; (*Initializes block processing. Block processing can be applied on possibly already subranged Src object. Src may not be freed or go out of scope until block processing loop has finished. There would be no error raised other than AV. *) procedure BlockInit(const Src: TMtxVecBase; ABlockSize: integer); overload; (*Obtains the next subrange of the data. Obtains the next subrange of the data in TVec. The routine must be used together with and methods. *) procedure BlockNext; (*Deinitializes block processing before the final block is processed. Call this routine before breaking out of a while-loop prematurely. Vec.BlockInit While not Vec.BlockEnd do Begin If Vec.Min < 0 then //check some condition, if you need to exit begin Vec.BlockFinish; //finish the loop Break; //and break out end; Vec.BlockNext; end *) procedure BlockFinish; (*Compute maximum of each row. Compute maximum of each row and store the result in to Dst vector. The Dst is sized automatically. *) procedure MaxRows(const Dst: TVec); overload; (*Compute minimum of each row. Compute mniimum of each row and store the result in to Dst vector. The Dst is sized automatically. *) procedure MinRows(const Dst: TVec); overload; (*Compute maximum of each column. Compute maximum of each column and store the result in to Dst vector. The Dst is sized automatically. *) procedure MaxCols(const Dst: TVec); overload; (*Compute minimum of each column. Compute mniimum of each column and store the result in to Dst vector. The Dst is sized automatically. *) procedure MinCols(const Dst: TVec); overload; (*Compute maximum and minimum of each row. Compute maximum and minimum of each row and store the result in to Dst vectors. The Dst's are sized automatically. *) procedure MaxMinRows(const DstMaxRows, DstMinRows: TVec); overload; (*Compute maximum and minimum of each column. Compute maximum and minimum of each column and store the result in to Dst vectors. The Dst's are sized automatically. *) procedure MaxMinCols(const DstMaxCols, DstMinCols: TVec); (*Replaces all NAN values with Value.*) function ReplaceNAN(const Value: double): TMtxVec; overload; (*Replaces all NAN values with Value within calling object elements [Index]..[Index+Len-1]. An exception is raised if array borders are overrun. *) function ReplaceNAN(const Value: double; Index, Len: integer): TMtxVec; overload; (*Prevents calls to . Prevents calls to method. This can be usefull guard when an object is already working on a subrange and the user would like to further subrange an already subranged object. When subranging matrices in-place, they are temporariliy converted to a vector by settings Rows to 1 and Cols to Length. var a: Matrix; b: Vector; begin a.SetIt(3,3,false, [1,2,3,4,5,6,7,8,9]); a.SetSubRange(0,2); //a = [1,2] a.DisableSubrange; a.SetSubRange(2,2); //exception raised here b.SetSubRange(a,2,2); //but this will work a.SetFullRange; //b is not changed, it still points to [4,5] end; *) procedure DisableSubrange; (*Enables calls to . Enables calls to by removing the block set by . *) procedure EnableSubrange; (*Prevents calls to . Prevents calls to method. This can be usefull guard when an object is already working on a subrange and the user would like to further subrange an already subranged object. var a: Matrix; b: Vector; begin a.SetIt(3,3,false, [1,2,3,4,5,6,7,8,9]); a.Select(0,2); //a = [1,2] a.DisableSelect; a.Select(2,2); //exception raised here b.Select(a,2,2); //but this will work a.SelectAll; //b is not changed, it still points to [4,5] end; *) procedure DisableSelect; (*Enables calls to . Enables calls to by removing the block set by . *) procedure EnableSelect; (*Resets any defined selection. *) procedure SelectAll; overload; (*Resets any defined subrange. *) procedure SetFullRange; (*Resets any defined subrange and pops the stack.*) procedure SetFullRangeLevel; (*Defines a sub Matrix/matrix. The method will define a subarray starting at Index and ending at Index+Len-1. No copying will occur, only pointers will be shifted. All values of the original will be preserved. An exception will be raised if an attempt is made to change the size of calling object. A sub-Matrix/matrix is Matrix/matrix which does not neccessarily have its own memory allocated. Instead it adopts the memory of the source object and all operations done on the either of the objects affect the same elements. The use of subvectors/submatrices increases CPU cache reuse, lower's memory requirements, increases application performance and improves code readability. To again obtain a view of the full Matrix/matrix, see *) procedure SetSubRange(Index: integer; Len: integer); overload; (*Defines a sub Matrix/matrix.*) procedure SetSubRange(const Src: TDenseMtxVec; Index, Len: integer); overload; (*Defines a sub vector/matrix. The method will define a subarray starting at Index and ending at Index + (aRows*aCols)-1. No copying will occur, only pointers will be shifted or indices adjusted. The subranged matrix will have the size aRows and aCols. Length will be equal to aRows*aCols. All values of the original will be preserved. An exception will be raised if an attempt is made to change the size of calling object. A sub-vector/matrix is vector/matrix, which does not have its own memory allocated. Instead it adopts the memory of the source object and all operations done on either of the objects affect the same elements. The use of subvectors/submatrices increases CPU cache reuse, lower's memory requirements, increases application performance and improves code readability. To again obtain a view of the full vector/matrix, see The routine only makes sense to be used where aCols matches Src.Cols. MtxVec has only limited support for matrices where the matrix rows are not stored strictly consecutively. This overload is to be used with great caution. The routine should not be mixed with other SetSubRange routines or subrange stack. *) procedure SetSubRange(const Src: TMtxVec; Index: integer; aRows, aCols: integer); overload; (*Defines a sub Matrix/matrix and pushes the stack.*) procedure SetSubRangeLevel(Index: integer; Len: integer); overload; (*Defines a sub Matrix/matrix and pushes the stack.*) procedure SetSubRangeLevel(const Src: TDenseMtxVec; Index, Len: integer); overload; (*Sets the subarray size to full size. This method is the same as the method.*) procedure SetSubRange; overload; (*Defines a subarray. The method will define a sub array starting at BeginIndex and ending at EndIndex (inclusive). All values of the original Matrix/matrix will be preserved. An exception will be raised if an attempt is made to change the size of calling Matrix/matrix. A subarray is array which does not have its own memory allocated. Instead it adopts the memory of the source object and all operations done on the either of the objects affect the same elements. The use of subarrays increases CPU cache reuse, lower's memory requirements, increases application performance and improves code readability. Note To again obtain a view of the full Matrix see *) procedure SetSubIndex(BeginIndex, EndIndex: integer); (*Finds a match for X in sorted object values using binary search. The data in the vector must be sorted in ascending order for this function to work correctly. the Index of last matched element. If no matching elements are found, the result is -1.*) function BinarySearch(const X: double): Integer; overload; function BinarySearch(const X: double; const Index: integer; Len: integer): Integer; overload; function BinarySearch(const X: TCplx): Integer; overload; function BinarySearch(const X: TCplx; const Index: integer; Len: integer): Integer; overload; (*Scale all matrix columns with values from Src. Src.Length must be equal to Self.Cols. *) function ScaleCols(const Src: TVec): TMtx; overload; (*Scale all matrix rows with values from Src. Src.Length must be equal to Self.Rows. *) function ScaleRows(const Src: TVec): TMtx; overload; (*Scale all Mtx matrix columns with values from Src. Src.Length must be equal to Mtx.Cols. The result is stored to the calling matrix. *) function ScaleCols(const Mtx: TMtx; const Src: TVec): TMtx; overload; (*Scale all Mtx matrix rows with values from Src. Src.Length must be equal to Mtx.Rows. The result is stored to the calling matrix. *) function ScaleRows(const Mtx: TMtx; const Src: TVec): TMtx; overload; (*Multiply matrix with diagonal matrix from the left. DiagMtx contains the values of the main diagional of the diagonal matrix. Other values of the DiagMtx matrix are assumed to be zero. DiagMtx.Length must be equal to Self.Cols. This operation is the same as calling TMtx.ScaleRows. *) function MulDiagLeft(const DiagMtx: TVec): TMtx; overload; (*Multiply matrix with diagonal matrix from the right. DiagMtx contains the values of the main diagional of the diagonal matrix. Other values of the DiagMtx matrix are assumed to be zero. DiagMtx.Length must be equal to Self.Rows. This operation is the same as calling TMtx.ScaleCols. *) function MulDiagRight(const DiagMtx: TVec): TMtx; overload; (*Multiply matrix with diagonal matrix from the left. DiagMtx contains the values of the main diagional of the diagonal matrix. Other values of the DiagMtx matrix are assumed to be zero. DiagMtx.Length must be equal to Self.Cols. This operation is the same as calling TMtx.ScaleRows. *) function MulDiagLeft(const DiagMtx: TVec; const Mtx: TMtx): TMtx; overload; (*Multiply matrix with diagonal matrix from the right. DiagMtx contains the values of the main diagional of the diagonal matrix. Other values of the DiagMtx matrix are assumed to be zero. DiagMtx.Length must be equal to Self.Rows. This operation is the same as calling TMtx.ScaleCols. *) function MulDiagRight(const Mtx: TMtx; const DiagMtx: TVec): TMtx; overload; (*Finds exact or closest Index match for X in sorted object values using binary search. The data in the vector must be sorted in ascending order for this function to work correctly. The closest match is the Index of first bigger or smaller value in the array. To ensure bigger value write: Data := [0,2,3]; Data.BinarySearch(Value, XIndex); if Data[XIndex] > Value then Dec(XIndex); To ensure smaller value write: Data := [0,2,3]; Data.BinarySearch(1, XIndex); if Data[XIndex] < Value then Inc(XIndex); True and exact Index in XIndex, if found and False and the Index of the next bigger or smaller value in XIndex, if not found. *) function BinarySearch(const X: double; var XIndex: integer): boolean; overload; function BinarySearch(const X: double; var XIndex: integer; const Index: integer; Len: integer): boolean; overload; function BinarySearch(const X: TCplx; var XIndex: integer): boolean; overload; function BinarySearch(const X: TCplx; var XIndex: integer; const Index: integer; Len: integer): boolean; overload; (*Sine. Calculate the sine of all caling object elements in-place. var a: Matrix; begin a.SetIt(1,2,True,[1,-2,3,4]); a.Sin; // Computes complex sine end; *) function Sin: TMtxVec; overload; (*Calculate the sine of calling object elements [Index]...[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function Sin(Index: integer; Len: integer): TMtxVec; overload; (*Calculate the sine of all X object elements and store the results in calling object. Size and properties of calling object are adjusted automatically. *) function Sin(const X: TMtxVec): TMtxVec; overload; (*Calculate the sine of X object elements [XIndex]...[XIndex+Len-1]. The results are stored in calling object elements [Index]...[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if array borders are overrun. *) function Sin(const X: TMtxVec; XIndex: integer; Index: integer; Len: integer): TMtxVec; overload; (*Cosine. Calculate the cosine of all caling object elements in-place. var a: Matrix; begin a.SetIt(1,2,True,[1,-2,3,4]); a.Cos; // Computes complex sine end; *) function Cos: TMtxVec; overload; (*Calculate the cosine of calling object elements [Index]...[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function Cos(Index: integer; Len: integer): TMtxVec; overload; (*Calculate the cosine of all X object elements and store the results in the calling object. Size and properties of calling object are adjusted automatically. *) function Cos(const X: TMtxVec): TMtxVec; overload; (*Calculate the cosine of X object elements [XIndex]...[XIndex+Len-1]. The results are stored in calling object elements [Index]...[Index+Len-1]. Size and properties of calling object and the calling object must be set explicitly. An exception is raised if array borders are overrun. *) function Cos(const X: TMtxVec; XIndex: integer; Index: integer; Len: integer): TMtxVec; overload; (*Tangens. Calculate the tangens of all caling object elements in-place. var a: Matrix; begin a.SetIt(1,2,True,[1,-2,3,4]); a.Tan; // Computes complex tangens end; *) function Tan: TMtxVec; overload; (*Calculate the tangens of calling object elements [Index]...[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function Tan (Index: integer; Len: integer): TMtxVec; overload; (*Calculate the tangens of all X object elements and store the results in the calling object. Size and properties of calling object are adjusted automatically. *) function Tan(const X: TMtxVec): TMtxVec; overload; (*Calculate the tangens of X object elements [XIndex]...[XIndex+Len-1]. The results are stored in calling object elements [Index]...[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if array borders are overrun. *) function Tan(const X : TMtxVec; XIndex: integer; Index: integer; Len: integer): TMtxVec; overload; (*Cotangens. Calculate the cotangens of all caling object elements in-place. var a: Matrix; begin a.SetIt(1,2,True,[1,-2,3,4]); a.Cot; // Computes complex cotangens end; *) function Cot: TMtxVec; overload; (*Calculate the cotangens of calling object elements [Index]...[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function Cot(Index, Len: integer): TMtxVec; overload; (*Calculate the cotangens of all X object elements and store the results in the calling object. Size and properties of calling object are adjusted automatically. *) function Cot(const X: TMtxVec): TMtxVec; overload; (*Calculate the cotangens of X object elements [XIndex]...[XIndex+Len-1]. The results are stored in calling object elements [Index]...[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if array borders are overrun. *) function Cot(const X: TMtxVec; XIndex, Index, Len: integer): TMtxVec; overload; (*Secant. Calculate the secant of all caling object elements in-place. var a: Matrix; begin a.SetIt(1,2,True,[1,-2,3,4]); a.Sec; // Computes complex secant end; *) function Sec: TMtxVec; overload; (*Calculate the secant of calling object elements [Index]...[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function Sec(Index, Len: integer): TMtxVec; overload; (*Calculate the secant of all X object elements and store the results in the calling object. Size and properties of calling object are adjusted automatically. *) function Sec(const X: TMtxVec): TMtxVec; overload; (*Calculate the secant of X object elements [XIndex]...[XIndex+Len-1]. The results are stored in calling object elements [Index]...[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if array borders are overrun. *) function Sec(const X: TMtxVec; XIndex, Index, Len: integer): TMtxVec; overload; (*Cosecant. Calculate the cosecant of all caling object elements in-place. var a: Matrix; begin a.SetIt(1,2,True,[1,-2,3,4]); // a = [1-2i, 3+4i] a.Csc; // Computes complex cosecant end; *) function Csc: TMtxVec; overload; (*Calculate the cosecant of calling object elements [Index]...[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function Csc(Index, Len: integer): TMtxVec; overload; (*Calculate the cosecant of all X object elements and store the results in the calling object. Size and properties of calling object are adjusted automatically. *) function Csc(const X: TMtxVec): TMtxVec; overload; (*Calculate the cosecant of X object elements [XIndex]...[XIndex+Len-1]. The results are stored in calling object elements [Index]...[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if array borders are overrun. *) function Csc(const X: TMtxVec; XIndex, Index, Len: integer): TMtxVec; overload; (*The inverse sine. Calculate the inverse sine of all calling object elements in-place. Values must be between -1 and 1. The return values will be in the range [0,PI], in radians. var a,b: Matrix; begin a.SetIt(1,2, True,[1,-0.5,0.11,0.9]); a.ArcSin; //or b := ArcSin(a); //or a := ArcSin(a); end; *) function ArcSin: TMtxVec; overload; (*Calculate the inverse sine of calling object elements [Index]...[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function ArcSin(Index, Len: integer): TMtxVec; overload; (*Calculate the inverse sine of all X object elements and store the results in the calling object. Size and properties of calling object are adjusted automatically. *) function ArcSin(const X: TMtxVec): TMtxVec; overload; (*Calculate the inverse sine of X object elements [XIndex]...[XIndex+Len-1]. The results are stored in calling object elements [Index]...[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if array borders are overrun. *) function ArcSin(const X: TMtxVec; XIndex, Index, Len: integer): TMtxVec; overload; (*The inverse cosine. Calculate the inverse cosine of all calling object elements in-place. Values must be between -1 and 1. The return values will be in the range [0,PI], in radians. var a,b: Matrix; begin a.SetIt(1,2 True,[1,-0.5,0.11,0.9]); a.ArcCos; // or b := ArcCos(a); // or a := ArcCos(a); end; *) function ArcCos: TMtxVec; overload; (*Calculate the inverse cosine of calling object elements [Index]...[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function ArcCos(Index, Len: integer): TMtxVec; overload; (*Calculate the inverse cosine of all X object elements and store the results in the calling object. Size and properties of calling object are adjusted automatically. *) function ArcCos(const X: TMtxVec): TMtxVec; overload; (*Calculate the inverse cosine of X object elements [XIndex]...[XIndex+Len-1]. The results are stored in calling object elements [Index]...[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if array borders are overrun. *) function ArcCos(const X: TMtxVec; XIndex, Index, Len: integer): TMtxVec; overload; (*Inverse tangens of Y/X. Calculates the inverse tangens of Y/X, and returns an angle in the correct quadrant. The results are stored in calling object elements. Size and properties of calling object are adjusted automatically to match those of X and Y objects. An exception is raised if X and Y size and properties do not match. The result will fall in the range from -PI to PI radians. Note is calculated as ArcTan2(1, X). *) function ArcTan2(Y, X: TMtxVec): TMtxVec; overload; (*Calculate the inverse tangens of Y/X by using Y elements [YIndex]..[YIndex+Len-1], X elements [XIndex]..[XIndex+Len-1] and store the results in calling object elements [Index]..[Index+Len-1]. An exception is raised if array borders are overrun. *) function ArcTan2(Y, X: TMtxVec; YIndex, XIndex, Index: integer; Len: integer): TMtxVec; overload; (*Inverse tangens. Calculate the inverse tangens for all calling object elements in-place. The return values are expressed in radians. var A,B: Matrix; begin A.SetIt(2,2,True,[1,0, 2,0 2,0 4,1]); // 2x2, complex matrix B.ArcTan(A); // or B := ArcTan(A); // or A := ArcTan(A); end; *) function ArcTan: TMtxVec; overload; (*Calculate the inverse tangens of calling object elements [Index]...[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function ArcTan(Index, Len: integer): TMtxVec; overload; (*Calculate the inverse tangens of all X object elements and store the results in the calling object. Size and properties of calling object are adjusted automatically. *) function ArcTan(const X: TMtxVec): TMtxVec; overload; (*Calculate the inverse tangens of X object elements [XIndex]...[XIndex+Len-1]. The results are stored in calling object elements [Index]...[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if array borders are overrun. *) function ArcTan(const X: TMtxVec; XIndex, Index, Len: integer): TMtxVec; overload; (*Inverse cotangens. Calculate the inverse cotangens for all calling object elements in-place. The return values are expressed in radians. var A,B: Matrix; begin A.SetIt(2,2,True,[1,0, 2,0 2,0 4,1]); // 2x2, complex matrix B.ArcCot(A); //or B := ArcCot(A); end; *) function ArcCot: TMtxVec; overload; (*Calculate the inverse cotangens of calling object elements [Index]...[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function ArcCot(Index, Len: integer): TMtxVec; overload; (*Calculate the inverse cotangens of all X object elements and store the results in the calling object. Size and properties of calling object are adjusted automatically. *) function ArcCot(const X: TMtxVec): TMtxVec; overload; (*Calculate the inverse cotangens of X object elements [XIndex]...[XIndex+Len-1]. The results are stored in calling object elements [Index]...[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if array borders are overrun. *) function ArcCot(const X: TMtxVec; XIndex, Index, Len: integer): TMtxVec; overload; (*Inverse secant. Calculate the inverse secant for all calling object elements in-place. *) function ArcSec: TMtxVec; overload; (*Calculate the inverse secant of calling object elements [Index]...[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function ArcSec(Index, Len: integer): TMtxVec; overload; (*Calculate the inverse secant of all X object elements and store the results in the calling object. Size and properties of calling object are adjusted automatically. *) function ArcSec(const X: TMtxVec): TMtxVec; overload; (*Calculate the inverse secant of X object elements [XIndex]...[XIndex+Len-1]. The results are stored in calling object elements [Index]...[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if array borders are overrun. *) function ArcSec(const X: TMtxVec; XIndex, Index, Len: integer): TMtxVec; overload; (*Inverse cosecant. Calculate the inverse cosecant for all calling object elements in-place. *) function ArcCsc: TMtxVec; overload; (*Calculate the inverse cosecant of calling object elements [Index]...[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function ArcCsc(Index, Len: integer): TMtxVec; overload; (*Calculate the inverse cosecant of all X object elements and store the results in the calling object. Size and properties of calling object are adjusted automatically. *) function ArcCsc(const X: TMtxVec): TMtxVec; overload; (*Calculate the inverse cosecant of X object elements [XIndex]..[XIndex+Len-1]. The results are stored in the calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if array borders are overrun. *) function ArcCsc(const X: TMtxVec; XIndex, Index, Len: integer): TMtxVec; overload; (*Hyperbolic sine. Calculate the hyperbolic sine of all caling object elements in-place. var a: Matrix; begin a.SetIt(2,2,False,[1,1.5,2,0.3]); a.Sinh; // or a := Sinh(a); end; *) function Sinh: TMtxVec; overload; (*Calculate the hyperbolic sine of calling object elements [Index]...[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function Sinh(Index, Len: integer): TMtxVec; overload; (*Calculate the hyperbolic sine of all X object elements and store the results in the calling object. Size and properties of calling object are adjusted automatically. *) function Sinh(const X: TMtxVec): TMtxVec; overload; (*Calculate the hyperbolic sine for X object elements [XIndex]..[XIndex+Len-1]. The results are stored in the calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if array borders are overrun. *) function Sinh(const X: TMtxVec; XIndex, Index, Len: integer): TMtxVec; overload; (*Hyperbolic cosine. Calculate the hyperbolic cosine of all caling object elements in-place. var a,b: Matrix; begin a.SetIt(2,2,False,[1,1.5,2,0.3]); a.Cosh; //or a := Cosh(a); //internally becomes a.Cosh (in-place operation) b.Cosh(a); b := Cosh(a); end; *) function Cosh: TMtxVec; overload; (*Calculate the hyperbolic cosine for calling object elements [Index]..[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function Cosh(Index, Len: integer): TMtxVec; overload; (*Calculate the hyperbolic cosine for all X object elements and store the results in the calling object. Size and properties of calling object are adjusted automatically. *) function Cosh(const X: TMtxVec): TMtxVec; overload; (*Calculate the hyperbolic cosine for X object elements [XIndex]..[XIndex+Len-1]. The results are stored in calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if array borders are overrun. *) function Cosh(const X: TMtxVec; XIndex, Index, Len: integer): TMtxVec; overload; (*Hyperbolic tangens. Calculate the hyperbolic tangens of all caling object elements in-place. var a,b: Matrix; begin a.SetIt(2,2,False,[1,1.5,2,0.3]); a.Tanh; //or a := Tanh(a); //same as a.Tanh (in place operation) b := Tanh(a); //not in place b.Tanh(a); //not in place end; *) function Tanh: TMtxVec; overload; (*Calculate the hyperbolic tangens for calling object elements [Index]..[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function Tanh(Index, Len: integer): TMtxVec; overload; (*Calculate the hyperbolic tangens for all X object elements and store the results in the calling object. Size and properties of calling object are adjusted automatically. *) function Tanh(const X: TMtxVec): TMtxVec; overload; (*Calculate the hyperbolic tangens for X object elements [XIndex]..[XIndex+Len-1]. The results are stored in the calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if array borders are overrun. *) function Tanh(const X: TMtxVec; XIndex, Index, Len: integer): TMtxVec; overload; (*Hyperbolic cotangens. Calculate the hyperbolic cotangens of all caling object elements in-place. var a,b: Matrix; begin a.SetIt(2,2,False,[1,1.5,2,0.3]); a.Coth; a := Coth(a); b.Coth(a); //same as b := Coth(a); end; *) function Coth: TMtxVec; overload; (*Calculate the hyperbolic cotangens for calling object elements [Index]...[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function Coth(Index, Len: integer): TMtxVec; overload; (*Calculate the hyperbolic cotangens for all X object elements and store the results in the calling object. Size and properties of calling object are adjusted automatically. *) function Coth(const X: TMtxVec): TMtxVec; overload; (*Calculate the hyperbolic cotangens for X object elements [XIndex]..[XIndex+Len-1]. The results are stored in calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if array borders are overrun. *) function Coth(const X: TMtxVec; XIndex, Index, Len: integer): TMtxVec; overload; (*Hyperbolic secant. Calculate the hyperbolic secant of all caling object elements in-place. *) function Sech: TMtxVec; overload; (*Calculate the hyperbolic secant for calling object elements [Index]...[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function Sech(Index, Len: integer): TMtxVec; overload; (*Calculate the hyperbolic secant for all X object elements and store the results in the calling object. Size and properties of calling object are adjusted automatically. *) function Sech(const X: TMtxVec): TMtxVec; overload; (*Calculate the hyperbolic secant for X object elements [XIndex]..[XIndex+Len-1]. The results are stored in calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if array borders are overrun. *) function Sech(const X: TMtxVec; XIndex, Index, Len: integer): TMtxVec; overload; (*Hyperbolic cosecant. Calculate the hyperbolic cosecant of all caling object elements in-place. *) function Csch: TMtxVec; overload; (*Calculate the hyperbolic cosecant for calling object elements [Index]..[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function Csch(Index, Len: integer): TMtxVec; overload; (*Calculate the hyperbolic cosecant for all X object elements and store the results in the calling object. Size and properties of calling object are adjusted automatically. *) function Csch(const X: TMtxVec): TMtxVec; overload; (*Calculate the hyperbolic cosecant for X object elements [XIndex]..[XIndex+Len-1]. The results are stored in calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if array borders are overrun. *) function Csch(const X: TMtxVec; XIndex, Index, Len: integer): TMtxVec; overload; (*Absolute values. Calculate the absolute value of all calling object elemets in-place. var a,b: Matrix; begin a.SetIt(1,2,True,[1,-2,3,4]); a.Abs; a := Abs(a); //same as a.Abs b.Abs(a); //same as b := Abs(a); b := Abs(a); end; *) function Abs: TMtxVec; overload; (*Calculate the absolute value for calling object elements [Index]..[Index+Len-1]. An exception is raised if array borders are overrun or underrun. *) function Abs(Index, Len: integer): TMtxVec; overload; (*Calculate the absolute value for all X object. Store the results in the calling object. Size and property of calling object are adjusted automatically. *) function Abs(const X: TMtxVec): TMtxVec; overload; (*Calculate the absolute value of X object elements [XIndex]..[XIndex+Len-1]. Store the results in calling object elements [Index]..[Index+Len-1]. An exception is raised if array borders are overrun or underrun. *) function Abs(const X: TMtxVec; XIndex, Index, Len: integer): TMtxVec; overload; (*Inverse hyperbolic sine. Calculate the inverse hyperbolic sine for all caling object elements in-place. *) function ArcSinh: TMtxVec; overload; (*Calculate the inverse hyperbolic sine for calling object elements [Index]..[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function ArcSinh(Index, Len: integer): TMtxVec; overload; (*Calculate the inverse hyperbolic sine for all X object elements and store the results in the calling object. Size and properties of calling object are adjusted automatically. *) function ArcSinh(const X: TMtxVec): TMtxVec; overload; (*Calculate the inverse hyperbolic sine for X object elements [XIndex]..[XIndex+Len-1]. The results are stored in calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if array borders are overrun. *) function ArcSinh(const X: TMtxVec; XIndex, Index, Len: integer): TMtxVec; overload; (*Inverse hyperbolic cosine. Calculate the inverse hyperbolic cosine for all caling object elements in-place. *) function ArcCosh: TMtxVec; overload; (*Calculate the inverse hyperbolic cosine for calling object elements [Index]..[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function ArcCosh(Index, Len: integer): TMtxVec; overload; (*Calculate the inverse hyperbolic cosine for all X object elements and store the results in the calling object. Size and properties of calling object are adjusted automatically. *) function ArcCosh(const X: TMtxVec): TMtxVec; overload; (*Calculate the inverse hyperbolic cosine for X object elements [XIndex]..[XIndex+Len-1]. The results are stored in calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if array borders are overrun. *) function ArcCosh(const X: TMtxVec; XIndex, Index, Len: integer): TMtxVec; overload; (*Inverse hyperbolic tangens. Calculate the inverse hyperbolic tangens for all caling object elements in-place. *) function ArcTanh: TMtxVec; overload; (*Calculate the inverse hyperbolic tangens for calling object elements [Index]..[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function ArcTanh(Index, Len: integer): TMtxVec; overload; (*Calculate the inverse hyperbolic tangens for all X object elements and store the results in the calling object. Size and properties of calling object are adjusted automatically. *) function ArcTanh(const X: TMtxVec): TMtxVec; overload; (*Calculate the inverse hyperbolic tangens for X object elements [XIndex]..[XIndex+Len-1]. The results are stored in the calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if array borders are overrun. *) function Arctanh(const X: TMtxVec; XIndex, Index, Len: integer): TMtxVec; overload; (*Inverse hyperbolic cotangens. Calculate the inverse hyperbolic cotangens for all caling object elements in-place. *) function ArcCoth: TMtxVec; overload; (*Calculate the inverse hyperbolic cotangens for calling object elements [Index]..[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function ArcCoth(Index, Len: integer): TMtxVec; overload; (*Calculate the inverser hyperbolic cotangens for all X object elements and store the results in calling object. Size and properties of calling object are adjusted automatically. *) function ArcCoth(const X: TMtxVec): TMtxVec; overload; (*Calculate the inverse hyperbolic cotangens for X object elements [XIndex]..[XIndex+Len-1]. The results are stored in the calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if array borders are overrun. *) function ArcCoth(const X: TMtxVec; XIndex, Index, Len: integer): TMtxVec; overload; (*Inverse hyperbolic secant. Calculate the inverse hyperbolic secant for all caling object elements in-place. *) function ArcSech: TMtxVec; overload; (*Calculate the inverse hyperbolic secant for calling object elements [Index]..[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function ArcSech(Index, Len: integer): TMtxVec; overload; (*Calculate the inverse hyperbolic secant for all X object elements and store the results in calling object. Size and properties of calling object are adjusted automatically. *) function ArcSech(const X: TMtxVec): TMtxVec; overload; (*Calculate the inverse hyperbolic secant for X object elements [XIndex]..[XIndex+Len-1]. The results are stored in calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if array borders are overrun. *) function ArcSech(const X: TMtxVec; XIndex, Index, Len: integer): TMtxVec; overload; (*Inverse hyperbolic cosecant. Calculate the inverse hyperbolic cosecant for all caling object elements in-place. *) function ArcCsch: TMtxVec; overload; (*Calculate the inverse hyperbolic cosecant for calling object elements [Index]...[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function ArcCsch(Index, Len: integer): TMtxVec; overload; (*Calculate the inverse hyperbolic cosecant for all X object elements and store the results in calling object. Size and properties of calling object are adjusted automatically. *) function ArcCsch(const X: TMtxVec): TMtxVec; overload; (*Calculate the inverse hyperbolic cosecant for X object elements [XIndex]..[XIndex+Len-1]. The results are stored in calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if array borders are overrun. *) function ArcCsch(const X: TMtxVec; XIndex, Index, Len: integer): TMtxVec; overload; (*The cube root. Calculate the cube root of all calling object elements in-place. var v,w: Matrix; begin v.SetIt(1,2,false,[1,8]); v.Cbrt; // v = [1,2], same as: v := Cbrt(v); w := Cbrt(v); //same as: w.Cbrt(v); end; *) function Cbrt: TMtxVec; overload; (*Calculate the cube root of calling object elements [Index]..[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function Cbrt(Index, Len: integer): TMtxVec; overload; (*Calculate the cube root of all X object elements and store the results in calling object. Size and properties of calling object are adjusted automatically. *) function Cbrt(const X: TMtxVec): TMtxVec; overload; (*Calculate the cube root of X object elements [XIndex]..[XIndex+Len-1]. The results are stored in the calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if array borders are overrun. *) function Cbrt(const X: TMtxVec; XIndex, Index, Len: integer): TMtxVec; overload; (*Rounds towards positive infinity. Rounds all calling object elements towards positive infinity in-place. Ceil(-2.8) = -2 Ceil(2.8) = 3 Ceil(-1.0) = -1 *) function Ceil: TMtxVec; overload; (*Rounds calling object elements [Index]..[Index+Len-1] towards positive infinity in-place. An exception is raised if array borders are overrun. *) function Ceil(Index,Len: integer): TMtxVec; overload; (*Rounds all Src object elements towards positive infinity and stores the result in the calling object. Size and properties of the calling object are adjusted automatically. *) function Ceil(const Src: TMtxVec): TMtxVec; overload; (*Rounds Src object elements [SrcIndex]..[SrcIndex+Len-1] towards positive infinity and stores the result in the calling object elements [Index]..[Index+Len-1]- Size and properties of the calling object must be set explicitly. An exception is raised if array borders are overrun. *) function Ceil(const Src: TMtxVec; SrcIndex, Index,Len: integer): TMtxVec; overload; (*Natural logarithm. Calculate the natural log for all calling object elements in-place. var a,b: Matrix; begin a.SetIt(2,2,False,[1,2,3,4]); a.Ln; //same as: a := Ln(a); b.Ln(a); //same as: b := Ln(a); end; *) function Ln: TMtxVec; overload; (*Calculate the natural algorithm for all X elements and store the results in the calling object. Size and properties of the calling Matrix are set implicitly to match the X object. *) function Ln(const X: TMtxVec): TMtxVec; overload; (*Calculate the natural logarithm for calling object elements [Index]..[Index+Len-1] in-place. An exception is raised if is True and array borders are overrun. *) function Ln(Index, Len: integer): TMtxVec; overload; (*Calculate the natural logarithm for X elements [XIndex]..[XIndex+Len-1] and store the results in the calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if is True and array borders are overrun. *) function Ln(const X: TMtxVec; XIndex, Index, Len: integer): TMtxVec; overload; (*Log base 10. Calculate the log base 10 for all calling object elements in-place. var a,b: Matrix; begin a.SetIt(2,2,False,[10,100,1000,10000]); // a = [10,100,1000,10000] a.Log10; // a = [1,2,3,4], same as: a := Log10(a); b.Log10(a); //same as b := Log10(a); end; *) function Log10: TMtxVec; overload; (*Calculate the log base 10 for all X elements and store the results in the calling object. Size and properties of the calling Matrix are set implicitly to match the X object. *) function Log10(const X: TMtxVec): TMtxVec; overload; (*Calculate the log base 10 for calling object elements [Index]..[Index+Len-1] in-place. An exception is raised if is True and array borders are overrun. *) function Log10(Index, Len: integer): TMtxVec; overload; (*Calculate the log base 10 for X elements [XIndex]..[XIndex+Len-1] and store the results in the calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if is True and array borders are overrun. *) function Log10(const X: TMtxVec; XIndex, Index, Len: integer): TMtxVec; overload; (*Log base 2. Calculate the log base 2 for all calling object elements in-place. var a,b: Matrix; begin a.SetIt(2,2,False,[1,2,4,8]); a.Log2; //same as: a := Log2(a); b := Log2(a); //same as: b.Log2(a); end; *) function Log2: TMtxVec; overload; (*Calculate the log base 2 for all X elements and store the results in the calling object. Size and properties of the calling Matrix are set implicitly to match the X object. *) function Log2(const X: TMtxVec): TMtxVec; overload; (*Calculate the log base 2 for calling object elements [Index]..[Index+Len-1] in-place. An exception is raised if is True and array borders are overrun. *) function Log2(Index, Len: integer): TMtxVec; overload; (*Calculate the log base 2 for X elements [XIndex]..[XIndex+Len-1] and store the results in the calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if is True and array borders are overrun. *) function Log2(const X: TMtxVec; XIndex, Index, Len: integer): TMtxVec; overload; (*Exponent (e^). Calculate the exponent (e^) for all calling object elements in-place. var a,b: Matrix; begin a.SetIt(2,2,False,[1,2,4,8]); a.Exp; //same as: a := Exp(a); b := Exp(a); //same as: b.Exp(a); end; *) function Exp: TMtxVec; overload; (*Calculate the exponent (e^) for all X elements and store the results in the calling object. Size and properties of the calling Matrix are set implicitly to match the X object. *) function Exp(const X: TMtxVec): TMtxVec; overload; (*Calculate the exponent (e^) for calling object elements [Index]..[Index+Len-1] in-place. An exception is raised if is True and array borders are overrun. *) function Exp(Index, Len: integer): TMtxVec; overload; (*Calculate the exponent (e^) for X elements [XIndex]..[XIndex+Len-1] and store the results in the calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if is True and array borders are overrun. *) function Exp(const X: TMtxVec; XIndex, Index, Len: integer): TMtxVec; overload; (*Exponent base 2 (2^). Calculate the exponent base 2 (2^) for all calling object elements in-place. var a,b: Matrix; begin a.SetIt(2,2,False,[1,2,3,4]); // a = [1,2,3,4] a.Exp2; // a = [2,4,8,16] a := Exp2(a); b.Exp2(a); //same as b := Exp2(a); end; *) function Exp2: TMtxVec; overload; (*Calculate the exponent base 2 (2^) for all X elements and store the results in the calling object. Size and properties of the calling Matrix are set implicitly to match the X object. *) function Exp2(const X: TMtxVec): TMtxVec; overload; (*Calculate the exponent base 2 (2^) for calling object elements [Index]..[Index+Len-1] in-place. An exception is raised if is True and array borders are overrun. *) function Exp2(Index, Len: integer): TMtxVec; overload; (*Calculate the exponent base 2 (2^) for X elements [XIndex]..[XIndex+Len-1] and store the results in the calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if is True and array borders are overrun. *) function Exp2(const X: TMtxVec; XIndex, Index, Len: integer): TMtxVec; overload; (*Exponent base 10 (10^). Calculate the exponent base 10 (10^) for all calling object elements in-place. var a,b: Matrix; begin a.SetIt(2,2,False,[1,2,3,4]); // a = [1,2,3,4] a.Exp10; // a = [10,100,1000,10000] a := Exp10(a); b.Exp10(a); //same as b := Exp10(a); end; *) function Exp10: TMtxVec; overload; (*Calculate the exponent base 10 (10^) for all X elements and store the results in the calling object. Size and properties of the calling Matrix are set implicitly to match the X object. *) function Exp10(const X: TMtxVec): TMtxVec; overload; (*Calculate the exponent base 10 (10^) for calling object elements [Index]..[Index+Len-1] in-place. An exception is raised if is True and array borders are overrun. *) function Exp10(Index, Len: integer): TMtxVec; overload; (*Calculate the exponent base 10 (10^) for X elements [XIndex]..[XIndex+Len-1] and store the results in the calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if is True and array borders are overrun. *) function Exp10(const X: TMtxVec; XIndex, Index, Len: integer): TMtxVec; overload; (*Gets the imaginary part of a complex object. Gets the imaginary part of a complex object Vec and stores the real results in the calling object. Size and properties of the calling object are set implicitly to match Vec object. Vec must be true otherwise the exception will be raised. var a,b: Matrix; begin a.SetIt(1,2,True,[1,2,3,4]); // a= [1+2i, 3+4i] b.ImagPart(a); // b = [2, 4] end; *) function ImagPart(const Vec: TMtxVec): TMtxVec; overload; (*Gets the imaginary part of complex object Vec elements [VecIndex]..[VecIndex+Len-1]. Store the result in calling object. An exception is raised if the calling object is complex, if Vec is not complex or if array borders are overrun/underrun. *) function ImagPart(const Vec: TMtxVec; VecIndex,Index,Len: integer): TMtxVec; overload; (*Power (integer exponent). Calculate the power ^(Exponent) for all caling object elements using the integer parameter Exponent. For non integer exponents, the and methods can be used. var a,b: Matrix; begin a.SetIt(2,2,False,[1,2,3,4]); a.IntPower(3); //same as: a := IntPower(a,3); b.IntPower(a,3); //same as: b := IntPower(a,3); end; *) function IntPower(Exponent: Integer): TMtxVec; overload; (*Calculate the power Base^(Exponent) for all Base object elements using the integer Exponent value and store the results in calling object. Size and properties of calling object are adjusted automatically. *) function IntPower(Base: TMtxVec; Exponent: Integer): TMtxVec; overload; (*Calculate the inverse of calling object elements [Index]..[Index+Len-1] in-place. An exception is raised if array borders are overrun/underrun. var a,b: Matrix; begin a.SetIt(2,2,False,[1,2,3,4]); // a = [1, 2, 3, 4] b.Inv(a,0.01); // b = [1.0, 0.5, 0.3333, 0.25] b := Inv(a,0.01); end; *) function Inv(Index, Len: integer): TMtxVec; overload; (*Calculate the inverse of all calling object elements in-place. The computation occurs after first limiting the magnitude of each element by the lower bound of Threshold. The limiting operation is performed to avoid division by zero. Since Threshold represents a magnitude, it is always real and must always be positive. For complex versions, the magnitude of the input is limited, but the phase remains unchanged. Zero-valued input is assumed to have zero phase. *) function Inv(Threshold: double): TMtxVec; overload; (*Calculate the inverse of calling object elements [Index]..[Index+Len-1] in-place. Limit the magnitude of each element by the lower bound of Threshold. An exception is raised if array borders are overrun/underrun. *) function Inv(Threshold: double; Index, Len: integer): TMtxVec; overload; (*Calculate the inverse of all X object elements without the limiting operating. Store the results in calling object. Size and property of calling object are adjusted automatically. Does not compute matrix inverse. The limiting of the magnitude of each element by the lower bound of Threshold is left out. *) function Inv(const X: TMtxVec): TMtxVec; overload; (*Calculate the inverse of X object elements [XIndex]..[XIndex+Len-1] without limiting operating. Store the results in calling object elements [Index]..[Index+Len-1]. An exception is raised if X and calling object property does not match or array borders are overrun/underrun. *) function Inv(const X: TMtxVec; XIndex, Index, Len: integer): TMtxVec; overload; (*Calculate the inverse of all X object elements anmd store the results to calling object elements. Size and property of calling obhect are adjusted automatically. The computation occurs after first limiting the magnitude of each element by the lower bound of Threshold. The limiting operation is performed to avoid division by zero. Since Threshold represents a magnitude, it is always real and must always be positive. Note For complex versions, the magnitude of the input is limited, but the phase remains unchanged. Zero-valued input is assumed to have zero phase. *) function Inv(const X: TMtxVec; Threshold: double): TMtxVec; overload; (*Calculate the inverse of X object elements [XIndex]..[XIndex+Len-1]. Limit the magnitude of each element by the lower bound of Threshold. Store the results in calling object elements [Index]..[Index+Len-1]. An exception is raised if X and calling object property do not match or array borders are overrun/underrun. *) function Inv(const X: TMtxVec; Threshold: double; XIndex, Index, Len: integer): TMtxVec; overload; (*Converts elements from cartesian to polar coordinate form. Converts all calling object elements from cartesian to polar coordinate form, storing the magnitude (radius) component of corresponding elements in the AmpltVec and the phase (angle) component of corresponding elements in the PhaseVec. If you want to use this method then the calling matrix property must be true. If this is not the case, an exception is raised. Size and properties of AmpltVec and PhaseVec are set automatically. var A,Amplt,Phase: Matrix; begin A.SetIt(2,2,True,[1,0, 2,0 2,0 4,1]); A.CartToPolar(Amplt,Phase); end; *) procedure CartToPolar(AmpltVec, PhaseVec: TMtxVec); overload; (*Convert calling object elements [Index] to [Index+Len-1] from cartesian to polar form. Store the results in AmpltVec (radius values) and PhaseVec(phase values). Size and properties of the calling Matrix must be set explicitly. An exception is raised if is True and array borders are overrun or underrun. *) procedure CartToPolar(AmpltVec, PhaseVec: TMtxVec; AmpltIndex, PhaseIndex, Index, Len: integer); overload; (*Copy object values. Copy each of Vec elements to the calling object. Size and properties of the calling object are set implicitly to match Vec object. var a,b,c: Matrix; begin a.SetIt(1,2,True,[1,2,3,4]); // a = [1,2,3,4] b.Copy(a); // b = [1,2,3,4] c.Copy(a,b); //concatenate a and b and store in c = [1,2,3,4,1,2,3,4] end; *) function Copy(const Vec: TMtxVec): TMtxVec; overload; (*Copy object values. Copy each of Src elements to the calling object. Size and properties of the calling object are set implicitly to match Src object. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TVec a,b,c; MtxVec.CreateIt(out a, out b, out c); try { a.SetIt(true,new double[] {1,2,3,4}); // a = [1,2,3,4] i.e 1+2i ; 3+4i b.Copy(a, mvSingle); // convert to single precision } finally { MtxVec.FreeIt(ref a,ref b,ref c); } } } *) function Copy(const Src: TMtxVec; const dstFloatPrecision: TMtxFloatPrecision): TMtxVec; overload; (*Copy Vec elements [VecIndex]..[VecIndex+Len-1] in the calling object elements [Index]..[Index+Len-1]. Size and properties must be set explicitly. An exception is raised if is True and array borders are overrun or underrun. *) function Copy(const Vec: TMtxVec; VecIndex, Index, Len: integer): TMtxVec; overload; (*Sets Matrix size to zero. Calling Clear sets property to 0 and property to False. *) procedure Clear; (*Saves the current value of ConditionCheck property and sets it to false. Saves the current value of property and sets it to false. You can restore back to the original setting by calling method. *) procedure CondDisable; (*Sets the ConditionCheck property to whatever it was before the CondDisable was used. Sets the property to whatever it was before the was used. *) procedure CondEnable; (*Conjugate. Conjugate all calling object elements in-place. var c: Matrix; begin c.SetIt(1,2,True,[1,2,3,4]); // c = [1+2i, 3+4i] c.Conj; // c = [1-2i, 3-4i] end; *) function Conj: TMtxVec; overload; (*Conjugate calling object elements [Index]..[Index+Len-1] in-place. An exception is raised if is true and array borders are overrun. *) function Conj(Index,Len: integer): TMtxVec; overload; (*Conjugate each of Vec elements and store the results in the calling object. Size and properties of the calling object are set implicitly to match Vec Matrix. *) function Conj(const Vec: TMtxVec): TMtxVec; overload; (*Conjugate Vec elements Vec[VecIndex]..Vec[VecIndex+Len-1]. Store them in the calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if is true and array borders are overrun. *) function Conj(const Vec: TMtxVec; VecIndex, Index, Len: integer): TMtxVec; overload; (*Copies values from an array. Copies values from a complex array. The size and properties of the calling object are set implicitely. *) function CopyFromArray(const Src: TCplxArray): TMtxVec; overload; (*Copies values from the Src array [SrcIndex]..[SrcIndex+Len-1] to the calling object values [Index]..[Index+len-1]. The size of the calling object is not changed. If the array border are overrun an exception will be raised. *) function CopyFromArray(const Src: TCplxArray; SrcIndex,Index,Len: integer): TMtxVec; overload; (*Copies values from a real Src array. The size and properties of the calling object are set implicitely. *) function CopyFromArray(const Src: TDoubleArray): TMtxVec; overload; (*Copies values from the double precision floating point Src array [SrcIndex]..[SrcIndex+Len-1] to the calling object values [Index]..[Index+len-1]. The size of the calling object is not changed. If the array border are overrun an exception will be raised. *) function CopyFromArray(const Src: TDoubleArray; SrcIndex,Index,Len: integer): TMtxVec; overload; (*Copies values from a real single precision floating point Src array. The size and properties of the calling object are set implicitely. *) function CopyFromArray(const Src: TSingleArray): TMtxVec; overload; (*Copies values from the single precision floating point Src array [SrcIndex]..[SrcIndex+Len-1] to the calling object values [Index]..[Index+len-1]. The size of the calling object is not changed. If the array border are overrun an exception will be raised. *) function CopyFromArray(const Src: TSingleArray; SrcIndex,Index,Len: integer): TMtxVec; overload; (*Copies values from an integer type Src array. The size and properties of the calling object are set implicitely. *) function CopyFromArray(const Src: TIntegerArray): TMtxVec; overload; (*Copies values from a 4 byte signed integer type Src array [SrcIndex]..[SrcIndex+Len-1] to the calling object values [Index]..[Index+len-1]. The size of the calling object is not changed. If the array border are overrun an exception will be raised. *) function CopyFromArray(const Src: TIntegerArray; SrcIndex,Index,Len: integer): TMtxVec; overload; (*Copies values from an 2 byte signed integer type Src array. The size and properties of the calling object are set implicitely. *) function CopyFromArray(const Src: TSmallIntArray): TMtxVec; overload; (*Copies values from a 2 byte signed integer type Src array [SrcIndex]..[SrcIndex+Len-1] to the calling object values [Index]..[Index+len-1]. The size of the calling object is not changed. If the array border are overrun an exception will be raised. *) function CopyFromArray(const Src: TSmallIntArray; SrcIndex,Index,Len: integer): TMtxVec; overload; (*Copies values from a 1 byte unsigned integer type Src array. The size and properties of the calling object are set implicitely. *) function CopyFromArray(const Src: Math387.TByteArray): TMtxVec; overload; (*Copies values from a 1 byte unsigned integer type Src array [SrcIndex]..[SrcIndex+Len-1] to the calling object values [Index]..[Index+len-1]. The size of the calling object is not changed. If the array border are overrun an exception will be raised. *) function CopyFromArray(const Src: Math387.TByteArray; SrcIndex,Index,Len: integer): TMtxVec; overload; (*Copy values to an array. Copy complex values to Dst array. The size of the array is set automatically. If the calling object is not complex an exception will be raised. *) function CopyToArray(var Dst: TCplxArray): TMtxVec; overload; (*Copy complex values from the calling object [Index]..[Index+len-1] to the Dst array at positions [DstIndex]...[DstIndex+Len-1]. The size of the Dst array is not changed. *) function CopyToArray(var Dst: TCplxArray; DstIndex, Index,Len: integer): TMtxVec; overload; (*Copy values to Dst array. The size of the array is set automatically. If the calling object is complex, the size of the Dst array will be equal to 2*. If the calling object is not complex an exception will be raised. *) function CopyToArray(var Dst: TDoubleArray): TMtxVec; overload; (*Copy real or complex values from the calling object [Index]..[Index+len-1] to the Dst array at positions [DstIndex]...[DstIndex+Len-1]. The size of the Dst array is not changed. If the calling object is complex, the Index and Len parameters define the number of complex elements. *) function CopyToArray(var Dst: TDoubleArray; DstIndex, Index,Len: integer): TMtxVec; overload; (*Copies the calling object data to an array of single precision floating point data. Any values exceeding the range are clipped. *) function CopyToArray(var Dst: TSingleArray): TMtxVec; overload; (*Copy real or complex values from the calling object [Index]..[Index+len-1] to the Dst single precision floating point array at positions [DstIndex]...[DstIndex+Len-1]. The size of the Dst array is not changed. If the calling object is complex, the Index and Len parameters define the number of complex elements. *) function CopyToArray(var Dst: TSingleArray; DstIndex, Index,Len: integer): TMtxVec; overload; (*Copies values from the calling object to the Dst array and converts floating point data to integer numbers. The rounding method used is specified with the Rounding parameter. *) function CopyToArray(var Dst: TIntegerArray; Rounding: TRounding): TMtxVec; overload; (*Copy real or complex values from the calling object [Index]..[Index+len-1] to the Dst integer array at positions [DstIndex]...[DstIndex+Len-1]. The size of the Dst array is not changed. If the calling object is complex, the Index and Len parameters define the number of complex elements. The method converts floating point values to integer. Values exceeding the range of the integer type are clipped. *) function CopyToArray(var Dst: TIntegerArray; Rounding: TRounding; DstIndex, Index,Len: integer): TMtxVec; overload; (*Copies values from the calling object to the Dst array and converts floating point data to 2 byte signed integer numbers. The rounding method used is specified with the Rounding parameter. *) function CopyToArray(var Dst: TSmallIntArray; Rounding: TRounding): TMtxVec; overload; (*Copy real or complex values from the calling object [Index]..[Index+len-1] to the Dst integer array at positions [DstIndex]...[DstIndex+Len-1]. The size of the Dst array is not changed. If the calling object is complex, the Index and Len parameters define the number of complex elements. The method converts floating point values to integers. Values exceeding the range of a 2 byte signed integer type are clipped. *) function CopyToArray(var Dst: TSmallIntArray; Rounding: TRounding; DstIndex, Index,Len: integer): TMtxVec; overload; (*Copies values from the calling object to the Dst array and converts floating point data to 1 byte unsigned integer numbers. The rounding method used is specified with the Rounding parameter. *) function CopyToArray(var Dst: Math387.TByteArray; Rounding: TRounding): TMtxVec; overload; (*Copy real or complex values from the calling object [Index]..[Index+len-1] to the Dst integer array at positions [DstIndex]...[DstIndex+Len-1]. The size of the Dst array is not changed. If the calling object is complex, the Index and Len parameters define the number of complex elements. The method converts floating point values to integers. Values exceeding the range of 1 byte unsigned integer type are clipped. *) function CopyToArray(var Dst: Math387.TByteArray; Rounding: TRounding; DstIndex,Index,Len: integer): TMtxVec; overload; (*Split complex calling object in real and imaginary part. Split calling object into real and imaginary components. Store all real components in ReVec and all imaginary components in ImVec. Size and properties of ReVec and ImVec are set implicitly to match with the calling Matrix. An execption is raised if calling object is not complex. var a,b,c: Matrix; begin a.SetIt(1,2,True,[1,-2,3,4]); a.CplxToReal(b,c); end; *) procedure CplxToReal(ReVec, ImVec: TMtxVec); overload; (*Split calling object elements [Index]..[Index+Len-1] into real and imaginary components. Store real components in ReVec elements [ReIndex]..[ReIndex+Len-1] and imaginary components in ImVec elements [ImIndex]..[ImIndex+Len-1]. Size and properties must be set explicitly. An exception is raised if is true and array borders are overrun or underrun. *) procedure CplxToReal(ReVec, ImVec: TMtxVec; ReIndex, ImIndex, Index, Len: integer); overload; (*Extends a real object to a complex object. Extend the calling object to complex Matrix. After the calling of ExtendToComplex the imaginary part becomes the same as real part if Zeros is false. If Zeros is true the imaginary part is set to zero. The use of the in-place version of the method is discouraged because it requires 3*N copy operations, while the not-in-place version requires only 2*N copy operations. var a,b: Matrix; begin a.SetIt(2,2,False,[1,2,3,4]); b.ExtendToComplex(a,True); end; *) function ExtendToComplex(Zeros: boolean = True): TMtxVec; overload; (*Extend Vec object to complex calling object. If Zeros is true then the calling Matrix imaginary part is set to zero, otherwise the calling object imaginary part is the same as calling object real part. *) function ExtendToComplex(const Src: TMtxVec; Zeros: Boolean): TMtxVec; overload; (*Converts the source to complex. Converts the source to complex by setting the imaginary part to either zero (zeros = True) or same as real (zeros = false). Does not set size of the calling Matrix. If there is not sufficient space available to store the result an exception will be raised. *) function ExtendToComplex(const Src: TMtxVec; Zeros: Boolean; SrcIndex,DstIndex, Len: integer): TMtxVec; overload; (*Sets angle in [-2Pi,2Pi]. ThetaRad within [-2Pi,2Pi] interval. Calling this function prior to passing the value to trigonometric functions can significantly improve numerical accuracy. For arguments larger than 10000, the computation of sine/cosine is speeded up by about 10x for SSE2/SSE3. The performance gains for classic FPU math are also significant. The cost of this function call is approx 30% of the cost of the sine function. It is important to mention that the sine/cosine appear within many other functions especially complex versions of trigonometric functions. FixAngle method is never used implicitely within TMtxVec methods. To achieve maximum performance make sure that the arguments passed to complex trigonometric functions are "small" or scaled down. Note The Matrix must be real. *) function FixAngle: TMtxVec; overload; (*FixAngle for calling object complex elements [Index]..[Index+Len-1] in-place. An exception is raised if calling object property is True or if array borders are overrun/underrun. *) function FixAngle(Index,Len: integer): TMtxVec; overload; (*Sets angle in [-2Pi,2Pi] for all Src elements. Store the results in the calling object. Size and properties of the calling Matrix are set implicitly to match the Src object. *) function FixAngle(const Src: TMtxVec): TMtxVec; overload; (*Sets angle in [-2Pi,2Pi] for Src elements [SrcIndex]..[SrcIndex+Len-1]. Store the results in the calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if is True and array borders are overrun. *) function FixAngle(const Src: TMtxVec; SrcIndex, Index,Len: integer): TMtxVec; overload; (*Rounds towards negative infinity. Rounds all calling object elements towards negative infinity in-place. Floor(-2.8) = -3 Floor(2.8) = 2 Floor(-1.0) = -1 *) function Floor: TMtxVec; overload; (*Rounds calling object elements [Index]..[Index+Len-1] towards negative infinity in-place. An exception is raised if array borders are overrun. *) function Floor(Index,Len: integer): TMtxVec; overload; (*Rounds all Src object elements towards negative infinity and stores the result in the calling object. Size and properties of the calling object are adjusted automatically. *) function Floor(const Src: TMtxVec): TMtxVec; overload; (*Rounds Src object elements [SrcIndex]..[SrcIndex+Len-1] towards negative infinity. Sores the result in the calling object elements [Index]..[Index+Len-1] Size and properties of the calling object must be set explicitly. An exception is raised if array borders are overrun. *) function Floor(const Src: TMtxVec; SrcIndex, Index,Len: integer): TMtxVec; overload; (*A complex exponential e^(j*W). Calculate the calling object complex exponential in-place. An exception is raised if calling object is complex. If object is complex, you should use the method instead. var a: Matrix; begin a.SetIt(2,2,False,[1,2,3,4]); a.Expj; // a = [e^i, e^2i, e^3i, e^4i] end; *) function Expj: TMtxVec; overload; (*Calculate the e^(j*W), a complex exponential. Omega must be a real object. If omega is complex, then use the method. *) function Expj(Omega: TMtxVec): TMtxVec; overload; (*Calculate the complex exponential for Omega elements [OmegaIndex]..[OmegaIndex+Len-1]. Store the results in calling object elemets [Index]..[Index+Len-1]. Size and properties of the calling Matrix must be set explicitly. An exception is raised if is True and array borders are overrun or underrun. *) function Expj(Omega: TMtxVec; OmegaIndex, Index, Len: integer): TMtxVec; overload; (*Finds a match for X in object values. Compare real value X with all calling object elements and return the Index of last matched element. If no matching elements are found, the result is -1. Note This method also supports the NAN and INF search. var a: Matrix; ind: Integer; begin a.SetIt(False,[2,5,1,6]); ind := a.Find(1.0); // returns 2 (the arrays are zero based) end; *) function Find(const X: double): integer; overload; (*Compare complex value X with all calling object elements. the Index of last matched element. If no matching elements are found, the result is -1. An exception is raised if calling object property is false. *) function Find(const X: TCplx): integer; overload; (*Fractional part of values. Calculates the fractional part for all object values in-place. var a: Matrix; ind: Integer; begin a.SetIt(2,2,False,[1,5.5,-1.6,6]); // a = [1, 5.5, -1.6, 6] a.Frac; // a = [0, 0.5, -0.6, 0] end; *) function Frac: TMtxVec; overload; (*Calculates the fractional part for all X object values and stores the result in calling object. Size and properties of calling object are adjusted automatically. *) function Frac(const X: TMtxVec): TMtxVec; overload; (*Calculates the fractional part for calling object elements [Index]..[Index+Len-1] in-place An exception is raised if array borders are overrun or underrun. *) function Frac(Index,Len: integer): TMtxVec; overload; (*Calculates the fractional part for X object elements [XIndex]..[XIndex+Len-1] and stores the result in calling object elements [Index]..[Index+Len-1]. An exception is raised if array borders are overrun or underrun. *) function Frac(const X: TMtxVec; XIndex, Index, Len: integer): TMtxVec; overload; (*First element in object Values array. first real element in object Values array. *) property First: double read get_First; (*First element in object CValues array. first complex element in object CValues array. An exception is raised if calling object property is false. *) property Firstc: TCplx read get_Firstc; (*Flips the real and imaginary part of complex numbers. Flips the real and imaginary part of complex numbers for all calling object elements in-place. *) function Flip: TMtxVec; overload; (*Flips the real and imaginary part of complex numbers for calling object elements [Index]..[Index+Len-1] in-place. An exception is raised if array borders are overrun or underrun. *) function Flip(Index, Len: integer): TMtxVec; overload; (*Flips the real and imaginary part of complex numbers for all X object elements and store the results in the calling object. Size and properties of calling object are adjusted automatically. *) function Flip(const X: TMtxVec): TMtxVec; overload; (*Flips the real and imaginary part of complex numbers for X object elements [XIndex]..[XIndex+Len-1]. Store the results in the calling object elements [Index]..[Index+Len-1] An exception is raised if array borders are overrun or underrun. *) function Flip(const X: TMtxVec; XIndex, Index, Len: integer): TMtxVec; overload; (*Flips the real and imaginary part of complex numbers and conjugates the complex numbers. Performs the following operation: a + bi ==> b - ai Method flips the real and imaginary part and conjugates calling object complex elements in-place. *) function FlipConj: TMtxVec; overload; (*Flip calling object complex elements [Index]..[Index+Len-1] in-place. An exception is raised if calling object property is false or if array borders are overrun/underrun. *) function FlipConj(Index, Len: integer): TMtxVec; overload; (*Flip all X object complex elements and store the results in calling object. Size and property of calling object are adjusted automatically. *) function FlipConj(const X: TMtxVec): TMtxVec; overload; (*Flip X object complex elements [XIndex]..[XIndex+Len-1] and store the results in calling object elements [Index]..[Index+Len-1]. An exception is raised if calling object property is false or if array borders are overrun/underrun. *) function FlipConj(const X: TMtxVec; XIndex, Index, Len: integer): TMtxVec; overload; (*The inverse of square root 1/(v)^1/2. Calculate the inverse square root (1/(element)^(1/2)) of all calling object elements in-place. v.SetIt(false,[1,16]); v.InvSqrt; // returns [1,0.25] *) function InvSqrt: TMtxVec; overload; (*Calculate the inverse of square root for calling object elements [Index]..[Index+Len-1] in-place. An exception is raised if is True and array borders are overrun. *) function InvSqrt(Index, Len: integer): TMtxVec; overload; (*Calculate the inverse of square root for all X elements and store the results in the calling object. Size and properties of the calling Matrix are set implicitly to match the X object. *) function InvSqrt(const X: TMtxVec): TMtxVec; overload; (*Calculate the inverse of square root for X elements [XIndex]..[XIndex+Len-1] and store the results in the calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if is True and array borders are overrun. *) function InvSqrt(const X: TMtxVec; XIndex, Index, Len: integer): TMtxVec; overload; (*The inverse of cube root 1/(v)^1/3. Calculate the inverse cube root (1/(element)^(1/3)) of all calling object elements in-place. v.SetIt(false,[1,8]); v.InvCbrt; // returns [1,0.5] *) function InvCbrt: TMtxVec; overload; (*Calculate the inverse of cube root for calling object elements [Index]..[Index+Len-1] in-place. An exception is raised if is True and array borders are overrun. *) function InvCbrt(Index, Len: integer): TMtxVec; overload; (*Calculate the inverse of cube root for all X elements and store the results in the calling object. Size and properties of the calling Matrix are set implicitly to match the X object. *) function InvCbrt(const X: TMtxVec): TMtxVec; overload; (*Calculate the inverse of cube root for X elements [XIndex]..[XIndex+Len-1] and store the results in the calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if is True and array borders are overrun. *) function InvCbrt(const X: TMtxVec; XIndex, Index, Len: integer): TMtxVec; overload; (*The Reminder after division X/Y. Calculates reminder after division according to formula: X[i]-y[i]*Trunc(X[i]/y[i]). The results will be saved to the calling Matrix. X and Y must be a real and have the same length. Size and properties of the calling Matrix are set implicitly to match the X object. var a,b,c: Matrix; begin a.SetIt(1,4,false,[0,1,10,-1,-10]); // a = [0, 1, 10, -1, -10]; b.SetIt(1,4,false,[0,1,PI,-1,-PI]); // b = [0, 1, PI, -1, -PI]; c.Rem(a,b); // c = [0, 0, 0.5752, 0, -0.5752] end; *) function Rem(const X, Y: TMtxVec): TMtxVec; overload; (*Calculates reminder after division X/Y according to formula: z[i] = X[xi]-y[yi]*Trunc(X[xi]/y[yi]), where i in [Index..Index+Len], xi in [XIndex..XIndex+Len], yi in [YIndex..YIndex+Len]. The results will be saved to the calling Matrix. X must be a real. An exception will be raised if is True and array borders are overrun. *) function Rem(const X, Y: TMtxVec; XIndex, YIndex, Index, Len: integer): TMtxVec; overload; (*Calculates reminder after division X/Y according to formula X[i]-y*Trunc(X[i]/y). X must be a real. The results will be saved to the calling Matrix. Size and properties of the calling Matrix are set implicitly to match the X object. *) function Rem(const X: TMtxVec; Y: double): TMtxVec; overload; (*Calculates reminder after division X/Y according to formula: z[i] = X[xi]-y*Trunc(X[xi]/y), where i in [Index..Index+Len], xi in [XIndex..XIndex+Len]. X must be a real. The results will be saved to the calling Matrix. An exception will be raised if is True and array borders are overrun. *) function Rem(const X: TMtxVec; Y: double; XIndex, Index, Len: integer): TMtxVec; overload; (*Magnitude. Calculate the magnitude for all calling object elements in-place. This method has the same function as the method. var a: Matrix; begin a.SetIt(1,4,false,[1,-2,3,4]); // a = [1,-2, 3,4] a.Mag; // a = [1, 2, 3,4] end; *) function Mag: TMtxVec; overload; (*Calculate the magnitude for calling object elements [Index]..[Index+Len-1] in-place. An exception is raised if is True and array borders are overrun. *) function Mag(Index, Len: integer): TMtxVec; overload; (*Calculate the magnitude for all X elements and store the results in the calling object elements. Size and and properties of the calling Matrix are set implicitly to match Vec Matrix. *) function Mag(const X: TMtxVec): TMtxVec; overload; (*Calculate the magnitude for X elements [XIndex]..[XIndex+Len-1] and store the results in the calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if is True and array borders are overrun. *) function Mag(const X: TMtxVec; XIndex, Index, Len: integer): TMtxVec; overload; (*Multiply object elements with Value. Multiply all calling object elements with Value in-place. This method is the same as the method overloads multiplying with Matrix elements with a scalar. var v: Matrix; begin v.SetIt(1,3,false,[2,3,5]); // v = [2,3,5] v.Scale(3); // v = [6,9,15] end; *) function Scale(Factor: double): TMtxVec; overload; (*Multipy calling object elements [Index]..[Index+Len-1] with Value in-place. An exception is raised if array borders are overrun or underrun. *) function Scale(Factor: double; Index, Len: integer): TMtxVec; overload; (*Multiply all calling object elements with a complex Value in-place.*) function Scale(Factor: TCplx): TMtxVec; overload; (*Multipy calling object elements [Index]..[Index+Len-1] with complex Value in-place. An exception is raised if array borders are overrun or underrun. *) function Scale(Factor: TCplx; Index, Len: integer): TMtxVec; overload; (*Scatter object elements. Scatter the elements of the Src and store them in the calling object according to the IndexType, Increment and Offset parameters. The Indexes Matrix is used only if IndexType is either indVector or indMask. If IndexType is indVector, the values from the Indexes object denote the Index positions in the calling object to which the values should be copied from the Src. The Indexes Matrix must have the indexes stored in the IValues array. The IValues integer arrays points the same memory as Values array. The Increment and Offset parameters are used only if TIndexType is indIncrement. They define the target offset and a fixed step (increment) between calling Matrix elements. If IndexType is indMaks the Indexes object must have the same size as the Src object. The routine will copy only those elements from the Src to the calling object, for which there is a 1 at the coresponding Index in the Indexes object.The elements in the calling object are stored consecutively. See the method to see how to perform gathering. The performance of the CPU heavily depends on the assumption that elements are stored at consecutive memory locations. If it is neccessary to apply a set of operations only to elements at specific indexes, performance-wise it can prove to be very helpfull, if the elements are gathered first. *) function Scatter(const Src: TMtxVec; const Indexes: TVecInt =nil; IndexType: TIndexType = indVector; Increment: integer = 1; Offset: integer = 0): TMtxVec; overload; (*Scatter object elements. Scatter the elements of the Src and store them in the calling object at indices: Increment*i + Offset *) function ScatterByIncr(const Src: TMtxVec; Increment: integer = 1; Offset: integer = 0): TMtxVec; overload; (*Scatter object elements. Scatter the elements of the Src and store them in the calling object at indices stored in the Indexes parameter. *) function ScatterByIndexes(const Src: TMtxVec; const Indexes: TVecInt): TMtxVec; overload; (*Scatter object elements. Scatter the elements of the Src and store them in the calling object at indices set to 1 in the Mask parameter. *) function ScatterByMask(const Src: TMtxVec; const Mask: TVecInt; allow_resizing: boolean = False): TMtxVec; overload; (*Copies those values from MaskVec, at which aMask is different from 0.*) function Mask(const MaskVec: TMtxVec; const aMask: TMtxVecInt): TMtxVec; overload; (*Copies those values from MaskVecNot, at which aMask is equal to 0.*) function MaskNot(const MaskVecNot: TMtxVec; const aMask: TMtxVecInt): TMtxVec; overload; (*Assigns Value at indexes of the calling object, at which aMask is different from 0.*) function Mask(const Value: double; const aMask: TMtxVecInt): TMtxVec; overload; (*Assigns Value at indexes of the calling object, at which aMask is equal to 0.*) function MaskNot(const Value: double; const aMask: TMtxVecInt): TMtxVec; overload; (*Assigns Value at indexes of the calling object, at which aMask is different from 0.*) function Mask(const Value: TCplx; const aMask: TMtxVecInt): TMtxVec; overload; (*Assigns Value at indexes of the calling object, at which aMask is equal to 0.*) function MaskNot(const Value: TCplx; const aMask: TMtxVecInt): TMtxVec; overload; (*Sets object values. Set object values. Method call does not change object's size or property, but it does check for array overrun. The elements of A array are copied to the calling object elements, starting at Index. If the calling object is complex, then real parts of complex numbers are on even (0,2,4..) and imaginary parts on odd indexes.(1,3,5,..). *) function SetIt(Index: integer; const A: array of double): TMtxVec; overload; (*The elements of A array, starting at AIndex, are copied to the calling object elements, starting at Index. If the calling object is complex, then real parts of complex numbers in the A array are on even (0,2,4..) and imaginary parts on odd indexes.(1,3,5,..). *) function SetIt(Index, AIndex, Len: integer; const A: array of double): TMtxVec; overload; (*Sets object values (single). The single elements of A array are copied to the calling object elements [Index]..[Index+Length(A)-1]. An exception is raised if calling object array borders are overrun/underrun. Note Use this method for integer array only. *) function SetSingle(Index: integer; const A: array of single): TMtxVec; overload; function SetSingle(Index: integer; aIndex, Len: integer; const A: array of single): TMtxVec; overload; (*Sets object values (double). The double elements of A array are copied to the calling object elements [Index]..[Index+Length(A)-1]. An exception is raised if calling object array borders are overrun/underrun. Note Use this method for integer array only. *) function SetDouble(Index: integer; const A: array of double): TMtxVec; overload; function SetDouble(Index: integer; aIndex, Len: integer; const A: array of double): TMtxVec; overload; (*Sets object values (integer). The integer elements of A array are copied to the calling object elements [Index]..[Index+Length(A)-1]. An exception is raised if calling object array borders are overrun/underrun. Note Use this method for integer array only. *) function SetInteger(Index: integer; const A: array of Integer): TMtxVec; overload; function SetInteger(Index: integer; aIndex, Len: integer; const A: array of Integer): TMtxVec; overload; (*Square. Calculate the square of all caling object elements in-place. var a: Matrix; begin a.SetIt(True,[1,2,3,4]); a.Sqr; // a=[1,4,9,16] end; *) function Sqr: TMtxVec; overload; (*Calculate the square of calling object elements [Index]...[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function Sqr(Index, Len: integer): TMtxVec; overload; (*Calculate the square of all X object elements and store the results in the calling object. Size and properties of calling object are adjusted automatically. *) function Sqr(const X: TMtxVec): TMtxVec; overload; (*Calculate the square of X object elements [XIndex]..[XIndex+Len-1]. The results are stored in calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object are not changed. An exception is raised if array borders are overrun. *) function Sqr(const X: TMtxVec; XIndex, Index, Len: integer): TMtxVec; overload; (*Square root. Calculate the square root of all caling object elements in-place. var a: Matrix; begin a.SetIt(2,2,False,[1,4,9,16]); a.Sqrt; // a= [1, 2, // 3, 4] end; *) function Sqrt: TMtxVec; overload; (*Calculate the square root of calling object elements [Index]...[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function Sqrt(Index, Len: integer): TMtxVec; overload; (*Calculate the square root of all X object elements and store the results in the calling object. Size and properties of the calling object are adjusted automatically. *) function Sqrt(const X: TMtxVec): TMtxVec; overload; (*Calculate the square root of X object elements [XIndex]..[XIndex+Len-1]. The results are stored in calling object elements [Index]..[Index+Len-1]. Size and properties of calling object are not changed. An exception is raised if array borders are overrun. *) function Sqrt(const X: TMtxVec; XIndex, Index, Len: integer): TMtxVec; overload; (*Last complex element in object CValues array. last complex element in object CValues array. *) property Lastc: TCplx read get_Lastc; (*Last element in object Values array. *) property Last: double read get_Last; (*Log base N. Calculate the log base N for all calling object elements in-place. var a: Matrix; begin a.SetIt(1,4,False,[1,2,3,4]); // a = [1,2,3,4] a.LogN(10.0); // log base 10, the slow way a = [Log10(1), Log10(2),...] end; *) function LogN(N: double): TMtxVec; overload; (*Calculate the log base N of calling object elements [Index]..[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function LogN(N: double; Index, Len: integer):TMtxVec; overload; (*Calculate the log base N of all X object elements and store the results in calling object. Size and properties of the calling object are adjusted automatically. *) function LogN(N: double; X: TMtxVec): TMtxVec; overload; (*Calculate the log base N of X object elements [XIndex]..[XIndex+Len-1]. The results are stored in calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object are not changed. An exception is raised if array borders are overrun. *) function LogN(N: double;const X: TMtxVec; XIndex, Index, Len: integer): TMtxVec; overload; (*Multiply object elements with Value. Multiply all calling object elements with Value in-place. var v: Vector; begin v.SetIt(1,3,false,[2,3,5]); // v = [2,3,5] v := v*3; // v = [6,9,15] end; *) function Mul(const Value: double): TMtxVec; overload; (*Multiply all calling object elements with complex Value in-place.*) function Mul(const Value: TCplx): TMtxVec; overload; (*Multipy calling object elements [Index]..[Index+Len-1] with Value in-place. An exception is raised if array borders are overrun or underrun. *) function Mul(const Value: double; Index, Len: integer): TMtxVec; overload; (*Multipy calling object elements [Index]..[Index+Len-1] with complex Value in-place. An exception is raised if array borders are overrun or underrun. *) function Mul(const Value: TCplx; Index, Len: integer): TMtxVec; overload; (*Multiply each element of Vec with Value and store the result in the calling object. Size and properties of the calling object are adjusted automatically. *) function Mul(const Vec: TMtxVec; Value: double): TMtxVec; overload; (*Multiply each element of Vec with complex Value and store the result in the calling object. Size of the calling object is set automatically. property of the calling object is set to True. *) function Mul(const Vec: TMtxVec; Value: TCplx): TMtxVec; overload; (*Multiply Vec elements [VecIndex]..[VecIndex+Len-1] with Value and store the result in calling object elements [Index]..[Index+Len-1]. Size of the calling object is not changed. An exception is raised if array borders are overrun or underrun. propertiy of the calling object is set implicitly. *) function Mul(const Vec: TMtxVec; Value: double; VecIndex, Index, Len: integer): TMtxVec; overload; (*Multiply Vec elements [VecIndex]..[VecIndex+Len-1] with complex Value and store the result in calling object elements [Index]..[Index+Len-1]. Size of the calling object is not changed. An exception is raised if array borders are overrun or underrun. propertiy of the calling object is set to True. *) function Mul(const Vec: TMtxVec; Value: TCplx; VecIndex, Index, Len: integer): TMtxVec; overload; (*Multiply elements by imaginary unit. Multiply calling Matrix elements with "I". *) function MulI: TMtxVec; overload; (*Multipy calling object elements [Index]..[Index+Len-1] with I in-place.*) function MulI(Index: integer; Len: integer): TMtxVec; overload; (*Multiply X elements with I and store the result in the calling object.*) function MulI(const X: TMtxVec): TMtxVec; overload; (*Multipy X elements [XIndex]..[XIndex+Len-1] with I. Store the result in the calling object at locations [Index]..[Index+Len-1]. *) function MulI(const X: TMtxVec; XIndex: integer; Index: integer; Len: integer): TMtxVec; overload; (*Normalize data. Normalizes values in the calling object by subtracting a constant Offset from Elements and dividing the result by constant Factor: The results are stored in calling object. Use this method if you want to do a multiply and add (scale and offset) operations in a single method call. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TVec a; MtxVec.CreateIt(out a); try { a.SetIt(false,new double[] {1,2,3,4}); // a = [1,2,3,4] a.Normalize(2,3); } finally { MtxVec.FreeIt(ref a); } } } *) function Normalize(const SubOffset, DivFactor: double): TMtxVec; overload; (*Normalize by subtracting a complex constant SubOffset from Vec elements and dividing the result by complex constant DivFactor. Size and property of calling object are adjusted automatically. An exception is raised, if object is complex. *) function Normalize(const SubOffset, DivFactor: TCplx): TMtxVec; overload; (*Normalize objects complex values [Index]..[Index+Len-1] by subtracting a complex constant SubOffset from Vec elements and dividing the result by complex constant DivFactor. An exception is raised, if object is not complex or array borders are overrun/underrun. *) function Normalize(const SubOffset, DivFactor: TCplx; Index,Len: integer): TMtxVec; overload; (*Normalize object values [Index]..[Index+Len-1] by subtracting a real constant SubOffset from Vec elements and dividing the result by complex constant DivFactor. Store the results in calling vector values [Index]..[Index+Len-1]. An exception is raised, if Vec or calling object is complex or array borders are overrun/underrun. *) function Normalize(const SubOffset, DivFactor: double; Index,Len: integer): TMtxVec; overload; (*Normalize object by subtracting a complex constant SubOffset from elements and dividing the result by real constant DivFactor. An exception is raised, if object is not complex. *) function Normalize(const SubOffset: TCplx; const DivFactor: double): TMtxVec; overload; (*Normalize objects complex values [Index]..[Index+Len-1] by subtracting a complex constant SubOffset from elements and dividing the result by real constant DivFactor. Store the results in calling vector complex values [Index]..[Index+Len-1]. An exception is raised, if the calling object is not complex or array borders are overrun/underrun. *) function Normalize(const SubOffset: TCplx; const DivFactor: double; Index,Len: integer): TMtxVec; overload; (*Normalize object. Normalizes Vec object by subtracting a constant Offset from Vec elements and dividing the result by constant Factor: The results are stored in calling object. Note Use this method if you want to do a multiply and add (scale and offset) operations in a single method call. var a,b: Matrix; begin a.SetIt(1,4,False,[1,2,3,4]); b.Normalize(a,2,3); end; *) function Normalize(const Vec: TMtxVec; SubOffset, DivFactor: double): TMtxVec; overload; (*Normalize Vec object by subtracting a complex constant SubOffset from Vec elements and dividing the result by complex constant DivFactor. Size and property of calling object are adjusted automatically. An exception is raised if Vec is complex. *) function Normalize(const Vec: TMtxVec; SubOffset, DivFactor: TCplx): TMtxVec; overload; (*Normalize Vec object complex values [VecIndex]..[VecIndex+Len-1] by subtracting a complex constant SubOffset from Vec elements and dividing the result by complex constant DivFactor. Store the results in calling Matrix complex values [Index]..[Index+Len-1]. An exception is raised if Vec or calling object is not complex or array borders are overrun/underrun. *) function Normalize(const Vec: TMtxVec; SubOffset, DivFactor: TCplx; VecIndex,Index,Len: integer): TMtxVec; overload; (*Normalize Vec object values [VecIndex]..[VecIndex+Len-1] by subtracting a real constant SubOffset from Vec elements and dividing the result by complex constant DivFactor. Store the results in calling Matrix values [Index]..[Index+Len-1]. An exception is raised if Vec or calling object is complex or array borders are overrun/underrun. *) function Normalize(const Vec: TMtxVec; SubOffset, DivFactor: double; VecIndex,Index,Len: integer): TMtxVec; overload; (*Normalize Vec object by subtracting a complex constant SubOffset from Vec elements and dividing the result by real constant DivFactor. Size and property of calling object are adjusted automatically. An exception is raised if Vec is complex. *) function Normalize(const Vec: TMtxVec; SubOffset: TCplx; DivFactor: double): TMtxVec; overload; (*Normalize Vec object complex values [VecIndex]..[VecIndex+Len-1] by subtracting a complex constant SubOffset from Vec elements and dividing the result by real constant DivFactor. Store the results in calling Matrix complex values [Index]..[Index+Len-1]. An exception is raised if Vec or calling object is not complex or array borders are overrun/underrun. *) function Normalize(const Vec: TMtxVec; SubOffset: TCplx; DivFactor: double; VecIndex,Index,Len: integer): TMtxVec; overload; (*Converts the polar magnitude/phase pairs to cartesian pairs. Convert all AmpltVec and PhaseVec elements (combined) from polar to cartesian form. If AmpltVec and PhaseVec size is not the same, an exeption is raised. The results are stored as complex numbers (X=Re, y=Im) in the calling object. Size and properties of the calling object are set implicitly to match AmpltVec and PhaseVec objects. var a,b,c: Matrix; begin a.SetIt(1,4,false,[1,2,3,4]); // a = [1,2,3, 4] //magnitude b.SetIt(1,4,false,[1,0,1,-1]); // b = [1,0,1,-1] /phase c.PolarToCart(a,b); // result stored in c = projections to Re and Im axis end; *) function PolarToCart(AmpltVec, PhaseVec: TMtxVec): TMtxVec; overload; (*Convert AmpltVec elements [AIndex]..[AIndex+Len-1] and PhaseVec elements [PIndex]..[PIndex+Len-1] from polar form (radius,angle) to cartesian form (X,y). The results are stored as complex numbers (X=Re, y=Im) in the calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if is True and array borders are overrun/underrun. *) function PolarToCart(AmpltVec, PhaseVec: TMtxVec; AIndex, PIndex,Index, Len: integer): TMtxVec; overload; (*Raises base object elements to any power. Raises Base calling object elements to any power. The is faster, if Exponent is an integer. Real valued power can handle only positive Exponent. can handle negative exponent also. Note To compute a power to the negative exponent in general case or when the base is negative, use the complex version of the function. var a: Matrix; begin a.SetIt(1,4,False,[1,2,3,4]); a.Power(1.2); end; *) function Power(Exponent: double): TMtxVec; overload; (*Raises all calling Matrix elements to complex power Exponent in-place. If the calling Matrix is real and has negative elements, the result will be NAN at those entries. To obtain a valid result in this case, extend the calling Matrix to complex with method. In all real/complex combinations, the Power method will not automatically assume that a number is complex to speed up the computation. Alternatively the user can of course always convert the real numbers to complex before passing them to the Power routine. *) function Power(Exponent: TCplx): TMtxVec; overload; (*The phase angles (spectrum) of object elements. Calculates the phase angles (spectrum) of all Vec object elements. Phase values are returned in radians and are in the range [-PI,PI]. Size and properties of the calling object are set implicitly to match Vec object. The phase angles are calculated from the following equation: var a,b: Matrix; begin a.SetIt(1,2,True,[1,2,3,4]); // a = [1 + 2i, 3 - 4i] b.PhaseSpectrum(a); // b = [arctan2(1,2), arctan2(3,-4)]; end; *) function PhaseSpectrum(const Vec: TMtxVec): TMtxVec; overload; (*Calculates the power spectrum from the Vec elements [VecIndex]..[VecIndex+Len-1]. Store the results in calling object elements [Index]..[Index+Len-1]. An exception is raised if array borders are overrun/underrun. *) function PhaseSpectrum(const Vec: TMtxVec; VecIndex, Index,Len: integer): TMtxVec; overload; (*The power spectrum from object complex values. Calculates the power spectrum from the Vec object complex values and stores the results (power spectrum) in the real calling object. Size and properties of the calling object are set implicitly to match Vec object. The spectrum elements are squares of the magnitudes of the complex input elements: var a,b: Matrix; begin a.SetIt(1,2,True,[1,2,3,-4]); // a = [1 + 2i, 3 - 4i] b.PowerSpectrum(a); // b = [1*1 + 2*2, 3*3+(-4)*(-4)] end; *) function PowerSpectrum(const Vec: TMtxVec): TMtxVec; overload; (*Calculates the power spectrum from the Vec complex elements [VecIndex]..[VecIndex+Len-1]. Store the results in calling object real elements [Index]..[Index+Len-1]. An exception is raised if calling object property is true or if array borders are overrun/underrun. *) function PowerSpectrum(const Vec: TMtxVec; VecIndex, Index,Len: integer): TMtxVec; overload; (*Raises base elements to exponent power. Raises Base value to Exponent object values powers and store the results to calling object values. Size and properties of calling object are adjusted automatically. *) function Power(Base: double; Exponent: TMtxVec): TMtxVec; overload; (*Raises Base complex value to Exponent object values powers and store the results to calling object values. Size and properties of calling object are adjusted automatically. *) function Power(Base: TCplx; Exponent: TMtxVec): TMtxVec; overload; (*Raises each of Base object elements to corresponding power. Store the result in Exponenet elements: Power[i] = Base[i]^Exponent[i] Size and property of calling object are adjusted automatically. An exception is raised if Base and Exponent sizes do not match. *) function Power(Base, Exponent: TMtxVec): TMtxVec; overload; (*Raises each of the Base object elements to complex Exponent power. Size and properties of calling object are adjusted automatically. *) function Power(Base: TMtxVec; Exponent: TCplx): TMtxVec; overload; (*Raises each of the Base object elements to real Exponent power. Size and properties of calling object are adjusted automatically. *) function Power(Base: TMtxVec; Exponent: double): TMtxVec; overload; (*Raises Base object elements to Exponent object elements power. Raises Base elements to Exponent elements power. Only positive exponents can be handled if exponent object property is True. var a,b,c: Matrix; begin a.SetIt(1,2,True,[1,2,3,4]); b.SetIt(1,2,True,[3,3,2,2]); c.PowerVec(a,b); // c = [1,8,9,16] end; *) function PowerVec(Base, Exponent: TMtxVec): TMtxVec; (*Elements product. the product of all calling object elements: An exception is raised if calling object property is true. var a: Matrix; c: double; begin a.SetIt(1,4,False,[1,2,3,4]); c := a.Product; // c= 24 end; *) function Product: double; overload; (*Returns the product for calling object elements [Index]..[Index+Len-1]. An exception is raised if array borders are overrun or underrun. *) function Product(Index,Len: integer): double; overload; (*Calculate the product of all calling object complex elements. Store the result in complex variable X. *) procedure Product(out X: TCplx); overload; (*Calculate the product for calling object complex elements [Index]..[Index+Len-1]. Store the result in complex variable X. An exception is raised if array borders are overrun or underrun. *) procedure Product(out X: TCplx; Index,Len: integer); overload; (*Calculate the product of all calling object elements and store the result in real variable X.*) procedure Product(out X: double); overload; (*Calculate the product for calling object elements [Index]..[Index+Len-1] and store the result in real variable X. An exception is raised if array borders are overrun or underrun. *) procedure Product(out X: double; Index,Len: integer); overload; (*Elements product. the complex product of all calling object complext elements: An exception is raised if calling object property is false. *) function Productc: TCplx; overload; (*Returns the complex product for calling object complex elements [Index]..[Index+Len-1]. An exception is raised if array borders are overrun or underrun or if propety is false. *) function Productc(Index,Len: integer): TCplx; overload; (*The pseudo random sample generator with Gaussian distribution. Fills the calling object values with pseudo random samples following the Gaussian distribution with parameters: Mean = 0, StdDev = 1 ("Standard disctribution"). The value for the seed is obtained from the CPU clock. var a: Matrix; begin a.Size(50,10,False); a.RandGauss; end; *) function RandGauss: TMtxVec; overload; (*Fills the calling object values with pseudo random samples following the Gaussian distribution. Use parameters: AMean and AStdDev. The value for the seed is obtained from the CPU clock. *) function RandGauss(AMean, AStdDev: double): TMtxVec; overload; (*Fills the calling object values with pseudo random samples following the Gaussian distribution. Use parameters: AMean, AStdDev and with Seed. *) function RandGauss(Seed: cardinal; AMean, AStdDev: double): TMtxVec; overload; (*The pseudo random sample generator with continuous uniform distribution. Fills the calling object values with pseudo random samples following the continuous uniform distribution using the parameters Low = 0, High = 1. The value for the seed is obtained from the CPU clock. var a: Matrix; begin a.Size(10,10,False); a.RandUniform(0,5); end; *) function RandUniform: TMtxVec; overload; (*Fills the calling object values with pseudo random samples following the continuous uniform distribution. Use parameters Low and High. The value for the seed is obtained from the CPU clock. *) function RandUniform(aLow, aHigh: double): TMtxVec; overload; (*Fills the calling object values with pseudo random samples following the continuous uniform distribution. Use parameters Low and High and Seed. *) function RandUniform(Seed: cardinal; aLow, aHigh: double): TMtxVec; overload; (*Gets real part of complex object values. The method method gets the real part of a complex object Vec and stores the real results in the calling object. Size and properties of the calling object are set implicitly to match Vec object. Vec property must be true otherwise an exception is raised. var a,b: Matrix; begin a.SetIt(True,[1,2,3,4]); // = [1+2i, 3+4i] b.RealPart(a); // b = [1,3] end; *) function RealPart(const Vec: TMtxVec): TMtxVec; overload; (*Gets the real part of a Vec object complex elements [VecIndex]..[VecIndex+Len-1]. Stores the results in calling object real elements [Index]..[Index+Len-1]. An exception is raised if array borders are overrun or underrun or if Vec object propety is false. *) function RealPart(const Vec: TMtxVec; VecIndex,Index,Len: integer): TMtxVec; overload; (*Read values content from stream to object. Reads values content from SrcStream stream to calling objct. No other values describing the data type or length are read from the DstStream. Number type is defined by the Precision parameter, which can be obtained from method call. Note Use this method separately only, if you want user defined storage format. var b: Matrix; AStream: TFileStream; Precision: TPrecision; begin AStream := TFileStream.Create('C:\test.bin',fmOpenRead); try Precision := b.ReadHeader(AStream); // Read info for b b.ReadValues(AStream,Precision); // Read values of b finally AStream.Free; end; end; *) function ReadValues(const Src: TStream; Precision: TPrecision): Int64; overload; (*Constructs a complex object from two real objects. Construct a complex object from the ReVec (real part) and the ImVec (imaginary part) objects. The results are stored in the calling object. Size and properties of the calling object are set implicitly to match ReVec and ImVec objects. An exception is raised if ReVec or ImVec property is True. var a,b,c: Matrix; begin a.SetIt(1,2,True,[1,2,3,4]); b.SetIt(1,2,True,[2,2,3,4]); c.RealToCplx(a,b); end; *) function RealToCplx(ReVec, ImVec: TMtxVec): TMtxVec; overload; (*Construct a complex object from the ReVec elements [ReIndex]..[ReIndex+Len-1] (real part) and the ImVec elements [ImIndex]..[ImIndex+Len-1] (imaginary part). The results are stored to calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if is True and array borders are overrun. An exception is also raised if ReVec or ImVec property is True. *) function RealToCplx(ReVec, ImVec: TMtxVec; ReIndex, ImIndex, Index, Len: integer): TMtxVec; overload; (*Resets object properties to default values. Resets object properties to default values. The method is used by the Object cache management to reset the properties of the object freed with a call to . *) procedure Reset; (*Search and replace a value. Replaces the SearchValue with a ReplaceValue, where the searchValue is compared with Tol to the values of the calling object. *) function Replace(SearchValue, ReplaceValue: double; Tol: double = 0.0001): TMtxVec; overload; (*Replaces the SearchValue with a ReplaceValue. The searchValue is compared with Tol to the calling object elements [Index]..[Index+Len-1]. An exception is raised if array borders are overrun/underrun. *) function Replace(SearchValue, ReplaceValue: double; Index, Len: integer; Tol: double = 0.0001): TMtxVec; overload; (*Search and replace a complex value.*) function Replace(SearchValue, ReplaceValue: TCplx; Tol: double = 0.0001): TMtxVec; overload; (*Replaces the SearchValue with a ReplaceValue, where the searchValue is compared with Tol to the calling object elements [Index]..[Index+Len-1]. An exception is raised if array borders are overrun/underrun. *) function Replace(SearchValue, ReplaceValue: TCplx; Index, Len: integer; Tol: double = 0.0001): TMtxVec; overload; (*Root mean square (RMS). Calculate the root mean square value for all calling object elements in-place. The root mean square (RMS) is defined by the equation: var a: Matrix; c: double; begin a.SetIt(1,4,False,[1,2,3,4]); c := a.RMS; end; *) function RMS: double; overload; (*Calculate the RMS for calling object elements [Index]..[Index+Len-1] in-place. An exception is raised if array borders are overrun. *) function RMS(Index, Len: integer): double; overload; (*Elements rounded to the nearest whole number. Rounds all calling object elements to the nearest whole number. The result can be stored to an array of integers or as floating point number. *) function Round: TMtxVec; overload; (*Round calling object elements [Index]..[Index+Len-1] in-place. An exception is raised if array borders are overrun/underrun. *) function Round(Index,Len: integer): TMtxVec; overload; (*Round all Src object elements and store the results in calling object elements. Size and property of calling object are adjusted automatically. *) function Round(const Src: TMtxVec): TMtxVec; overload; (*Rounds the calling object elements to 4 byte integers and stores the result in the Dst array. The size of the Dst array is set automatically. If the complex property is True then the length of the array will be equal to Self.Length*2. *) procedure Round(var Dst: TIntegerArray); overload; (*Round Src object elements [SrcIndex]..[SrcIndex+Len-1]. Store the results to calling object elements [Index]..[Index+Len-1]. Size and property of the calling object must be set explicitly. An exception is raised if array borders are overrun/underrun. *) function Round(const Src: TMtxVec; SrcIndex,Index,Len: integer): TMtxVec; overload; (*Initialize elements to Value. Set all calling object elements to Value. If the calling object is complex then the real part is set to Value and the imaginary is set to zero. var a: Matrix; begin a.Size(1,4,False); a.SetVal(1); // a = [1,1,1,1] end; *) function SetVal(Value: double): TMtxVec; overload; (*Set all calling object elements [Index]..[Index+Len-1] to real Value. If the calling object is complex then the real part is set to Value and the imaginary is set to zero. An exception is raised if array borders are overrun/underrun. *) function SetVal(Value: double; Index, Len: integer): TMtxVec; overload; (*Set all calling object complex elements to complex Value.*) function SetVal(Value: TCplx): TMtxVec; overload; (*Set calling object complex elements [Index]..[Index+Len-1] to complex Value. properties of the calling object are set to true even before the call it was false. An exception is raised if calling object array borders are overrun/underrun. *) function SetVal(Value: TCplx; Index: integer; Len: integer): TMtxVec; overload; (*Initializes object elements to zero. *) function SetZero: TMtxVec; overload; (*Set all calling object elements to zero. Initializes calling object elements [Index]..[Index+Len-1] to zero. An exception is raised if array borders are overrun. *) function SetZero(Index, Len: integer): TMtxVec; overload; (*Changes elements sign. Changes all calling object elements sign (v -> -v) in-place. var a: Matrix; begin a.SetIt(1,4,False,[1,2,-3,4]); a.Sign; // a = [-1,-2,3,-4] end; *) function Sign: TMtxVec; overload; (*Change calling object elements [Index]..[Index+Len-1] sign in-place. An exception is raised if array borders are overrun or underrun. *) function Sign(Index,Len: integer): TMtxVec; overload; (*Change all X object elements sign and store the results in calling object. Size and properties of calling object are adjusted automatically. *) function Sign(const X: TMtxVec): TMtxVec; overload; (*Change X object elements [XIndex]..[XIndex+Len-1] sign. Store the results in calling object elements [Index]..[Index+Len-1]. An exception is raised if array borders are overrun or underrun. *) function Sign(const X: TMtxVec; XIndex,Index,Len: integer): TMtxVec; overload; function Sgn: TMtxVec; overload; function Sgn(Index,Len: integer): TMtxVec; overload; function Sgn(const Src: TMtxVec): TMtxVec; overload; function Sgn(const Src: TMtxVec; SrcIndex,Index,Len: integer): TMtxVec; overload; (*Signum. Calculates the signum of all Src object elements and multiplies it with the calling object elements accordingly. Signum(X) is 1 for X > 0 , equal to zero for X = 0 and -1 for X < 0. The length of Src and of the calling object must match or an exception will be raised. Size and property of calling object are adjusted automatically. *) function SgnMul(const Src: TMtxVec): TMtxVec; overload; (*Size the object. Assignes the size of the Src object to the calling object. If the calling object is a TVec object then the Src can be of any type, otherwise TMtx can only obtain size from a TMtx object and TSparseMtx can only obtain size from a TSparseMtx object. If the calling object and Src are of different types, the complex property can be different, if both objects have a matching property. In this case only the Complex property of the calling object will changed, while all other properties describing the size of the object (rows, cols, length, nonZeros) will be preserved. This is different from simply setting the Complex property. Changing the Complex property directly would also change the Length, Cols and NonZeros properties. *) function Size(const Src: TMtxVec): TMtxVec ; overload; (*Allows the complex property of the calling object to become of AComplex value instead of Src.Complex value. It is also possible to pass the calling object as the Src with a different AComplex value. The value of the complex property can be changed without knowing the actual type of the object. *) function Size(const Src: TMtxVec; AComplex: boolean): TMtxVec ; overload; function Size(const Src: TMtxVecBase; const aFloatPrecision: TMtxFloatPrecision): TMtxVec; overload; (*Sizes the array. Sizes the Dst array so that it can hold all the values stored in the calling object. If the property is false an exception will be raised. *) procedure SizeToArray(var Dst: TCplxArray); overload; (*Sizes double precision array. If the property is true the Length of the Dst array will be 2*. *) procedure SizeToArray(var Dst: TDoubleArray); overload; (*Size single precision array. If the property is true the Length of the Dst array will be 2*. *) procedure SizeToArray(var Dst: TSingleArray); overload; (*Sizes integer array. If the property is true the Length of the Dst array will be 2*. *) procedure SizeToArray(var Dst: TIntegerArray); overload; (*Sizes integer array. If the property is true the Length of the Dst array will be 2*. *) procedure SizeToArray(var Dst: TSmallIntArray); overload; (*Sizes integer array. If the property is true the Length of the Dst array will be 2*. *) procedure SizeToArray(var Dst: Math387.TByteArray); overload; (*Compares two objects and returns True, if they are equal. Compares two objects and returns True, if they are equal. The IsEqual uses cmpAbsolute comparison method with comparison tolerance of 10*EPS by default. The method compares only and properties and coresponding values. To compare matrices or sparse matrices, use the method. *) function IsEqual(const Vec: TMtxVec): boolean; overload; (*Compares Vec elements [VecIndex]..[VecIndex+Len-1] with calling object elements [Index]..[Index+Len-1].*) function IsEqual(const Vec: TMtxVec; VecIndex, Index, Len: integer): boolean; overload; (*Compares Vec elements with coresponding calling object elements. Use method and specified . *) function IsEqual(const Vec: TMtxVec; Precision: double; Compare: TCompare = cmpAbsolute): boolean; overload; (*Compares Vec elements [VecIndex]..[VecIndex+Len-1] with calling object elements [Index]..[Index+Len-1]. Use method and specified . *) function IsEqual(const Vec: TMtxVec; VecIndex, Index, Len: integer; Precision: double; Compare: TCompare = cmpAbsolute): boolean; overload; (*Compares complex Value with all calling object elements.*) function IsEqual(Value: TCplx): boolean; overload; (*Compares real Value with all calling object elements.*) function IsEqual(Value: double): boolean; overload; (*Compares real Value with all calling object elements with Compare method and specified Tolerance.*) function IsEqual(Value: double; Tolerance: double; Compare: TCompare): boolean; overload; (*Compares complex Value with all calling object elements with Compare method and specified Tolerance.*) function IsEqual(Value: TCplx; Tolerance: double; Compare: TCompare): boolean; overload; (*Standard deviation. Calculate the standard deviation of all calling object elements. The result is a real value. An exception is raised if calling Matrix property is true. var a: Matrix; c: double; aMean: double; begin a.SetIt(2,2,False,[1,2,3,4]); aMean := a.Mean; c := a.StdDev(aMean); //if both Mean and StdDev are required this is faster // c := a.StdDev; //this is an alternative. end; *) function StdDev: double; overload; (*Returns the standard deviation of calling object elements [Index]..[Index+Len-1]. An exception is raised if calling object property is true or if array borders are overrun/underrun. *) function StdDev(Index,Len: integer): double; overload; (*Returns the standard deviation of all calling object complex elements. The average of all calling object elements must be passed as a AMean parameter. An exception is raised if calling object property is false. *) function StdDev(AMean: TCplx): TCplx; overload; (*Returns the standard deviation of calling object complex elements [Index]..[Index+Len-1]. The average of all calling object elements must be passed as a AMean parameter. An exception is raised if calling object property is false or if array borders are overrun/underrun. *) function StdDev(AMean: TCplx; Index, Len: integer): TCplx; overload; (*Returns the standard deviation of all calling object elements. The average of all calling object elements must be passed as a AMean parameter. An exception is raised if calling object property is true. *) function StdDev(AMean: double): double; overload; (*Returns the standard deviation of calling object elements [Index]..[Index+Len-1]. The average of the coresponding elements must be passed as a parameter. An exception is raised if calling object property is true or if array borders are overrun/underrun. *) function StdDev(AMean: double; Index, Len: integer): double; overload; (*Sine and cosine. Calculates the sine and cosine for all calling object elements and stores the sines to SinX and cosines to CosX. Size and property of SinX and CosX are adjusted automatically. Note Use this method if you require both sine and cosine. var a,s,c: Matrix; begin a.SetIt(1,3,false[0,PIDIV2,PI]); a.Sincos(s,c); // s=[0,1,0], c =[1,0,-1] end; *) procedure SinCos(SinX, CosX: TMtxVec); overload; (*Calculates the sine and cosine for calling object elements [Index]..[Index+Len-1]. Stores the sines to SinX elemets [SinXIndex]..[SinXIndex+Len-1] and cosines to CosX elements [CosXIndex]..[CosXIndex+Len-1] elements. Size and property of SinX and CosX objects are not set automatically. An exception is raised if and array borders are overrun/underun. *) procedure SinCos(SinX, CosX: TMtxVec; SinXIndex, CosXIndex, Index, Len: integer); overload; (*Hyperbolic sine and cosine. Calculates the hyperbolic sine and hyperbolic cosine for all calling object elements and stores the sines to SinhX and cosines to CoshX. Size and property of SinhX and CoshX are adjusted automatically. Note Use this method if you require hyperbolic sine and hyperbolic cosine. var a,s,c: Matrix; begin a.SetIt(1,3,false[0,PIDIV2,PI]); a.SinhCosh(s,c); end; *) procedure SinhCosh(SinhX, CoshX: TMtxVec); overload; (*Calculates the hyperbolic sine and hyperbolic cosine for calling object elements [Index]..[Index+Len-1]. Stores the sines to SinhX elemets [SinhIndex]..[SinhIndex+Len-1] and cosines to CoshX elements [CoshIndex]..[CoshIndex+Len-1] elements. Size and property of SinhX and CoshX objects are not set automatically. An exception is raised if and array borders are overrun/underun. *) procedure SinhCosh(SinhX, CoshX: TMtxVec; SinhIndex, CoshIndex, Index, Len: integer); overload; (*Sums Matrix values. the sum of all calling object elements. An exception is raised if calling object property is true. var a: Matrix; b: double; begin a.SetIt(1,4,False,[1,2,3,4]); b := a.Sum; // b = 10 end; *) function Sum: double; overload; (*Returns the sum of calling object elements [Index]..[Index+Len-1]. An exception is raised if calling object property is True or array borders are overrun/underrun. *) function Sum(Index,Len: integer): double; overload; (*Calculates the sum of calling object elements [Index]..[Index+Len-1]. Stores the result in real ASum variable. An exception is raised if calling object property is True or array borders are overrun/underrun. *) procedure Sum(out ASum: double; Index, Len: integer); overload; (*Calculates the sum of all calling object complex elements. Stores the result in complex ASum variable. An exception is raised if calling object property is False. *) procedure Sum(out ASum: TCplx); overload; (*Calculates the sum of calling object complex elements [Index]..[Index+Len-1] and stores the result in complex ASum variable. An exception is raised if calling object property is False or array borders are overrun/underrun. *) procedure Sum(out ASum: TCplx; Index, Len: integer); overload; (*Sum (complex value). Returns the complex sum of all calling object complex elements. An exception is raised if calling object property is False. *) function Sumc: TCplx; overload; (*Returns the complex sum of calling object complex elements [Index]..[Index+Len-1]. An exception is raised if calling object property is False or array borders are overrun/underrun. *) function Sumc(Index,Len: integer): TCplx; overload; (*Threshold bottom operation. Perform threshold operation on all calling object values. The Value parameter is a lower bound for threshold operation. All values smaller than Value will be replaced with Value. var a: Matrix; begin a.SetIt(1,2,True,[2,0.1,3,4]); a.ThreshBottom(0.2); // a = [2,0.2,3,4] end; *) function ThreshBottom(Value: double): TMtxVec; overload; (*Perform the threshold operation on calling object values [Index]..[Index+Len-1]. An exception is raised if array borders are overrun/underrun. *) function ThreshBottom(Value: double; Index, Len: integer): TMtxVec; overload; (*Perform threshold operation on all Src object values and store the results in calling object. Size and properties of the calling object are adjusted automatically. *) function ThreshBottom(const Src: TMtxVec; Value: double): TMtxVec; overload; (*Perform a threshold operation on Vec elements [VecIndex]..[VecIndex+Len-1]. Store the results in the calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if is true and array borders are overrun/underrun. *) function ThreshBottom(const Vec: TMtxVec; Value: double; VecIndex, Index, Len: integer): TMtxVec; overload; (*Threshold top operation. Perform threshold operation on all calling object values. The Value parameter is an upper bound for threshold operation. All values bigger than Value will be replaced with Value. var a: Matrix; begin a.SetIt(1,2,True,[2,0.1,3,4]); a.Threshtop(0.2); // a = [0.2,0.1,0.2,0.2] end; *) function ThreshTop(Value: double): TMtxVec; overload; (*Perfrom the threshold operation on calling object values [Index]..[Index+Len-1]. An exception is raised if array borders are overrun/underrun. *) function ThreshTop(Value: double; Index, Len: integer): TMtxVec; overload; (*Perform threshold operation on all Src object values and store the results in calling object. Size and properties of the calling object are adjusted automatically. *) function ThreshTop(const Src: TMtxVec; Value: double): TMtxVec; overload; (*Perform a threshold operation Vec elements [VecIndex]..[VecIndex+Len-1]. Store the results in the calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if is true and array borders are overrun/underrun. *) function ThreshTop(const Vec: TMtxVec; Value: double; VecIndex, Index, Len: integer): TMtxVec; overload; (*Threshold top and bottom centered around zero. Perform threshold operation on all calling object values. The Value parameter is an upper bound for threshold operation. All values smaller than Value will be replaced with Value and all values bigger than -Value will be replaced with -Value. The comparison checks if abs(Values[i]) < Value. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TVec a; MtxVec.CreateIt(out a); try { a.SetIt(false, new double[] {2,-0.1,3,4}); a.ThreshAbsLT(0.2); // a = [2,-0.2,3,4] } finally { MtxVec.FreeIt(ref a); } } } *) function ThreshAbsLT(const Value: double): TMtxVec; overload; (*Perfrom the threshold operation on calling object values [Index]..[Index+Len-1]. An exception is raised if array borders are overrun/underrun. *) function ThreshAbsLT(const Value: double; Index, Len: integer): TMtxVec; overload; (*Perform threshold operation on all Src object values. Store the results in calling object. Size and properties of the calling object are adjusted automatically. *) function ThreshAbsLT(const Src: TMtxVec; const Value: double): TMtxVec; overload; (*Perform a threshold operation Vec elements [VecIndex]..[VecIndex+Len-1]. Store the results in the calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if is true and array borders are overrun/underrun. *) function ThreshAbsLT(const Vec: TMtxVec; const Value: double; VecIndex, Index, Len: integer): TMtxVec; overload; (*Threshold top and bottom centered around zero. Perform threshold operation on all calling object values. The Value parameter is an upper bound for threshold operation. All values bigger than Value will be replaced with Value and all values smaller than -Value will be replaced with -Value. The comparison checks if abs(Values[i]) > Value. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TVec a; MtxVec.CreateIt(out a); try { a.SetIt(false, new double[] {2, -1, 3, 4}); a.ThreshAbsGT(0.2); // a = [0.2, -0.2, 0.2, 0.2] } finally { MtxVec.FreeIt(ref a); } } } *) function ThreshAbsGT(const Value: double): TMtxVec; overload; (*Perfrom the threshold operation on calling object values [Index]..[Index+Len-1]. An exception is raised if array borders are overrun/underrun. *) function ThreshAbsGT(const Value: double; Index, Len: integer): TMtxVec; overload; (*Perform threshold operation on all Src object values. Store the results in calling object. Size and properties of the calling object are adjusted automatically. *) function ThreshAbsGT(const Src: TMtxVec; const Value: double): TMtxVec; overload; (*Perform a threshold operation Vec elements [VecIndex]..[VecIndex+Len-1]. Store the results in the calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if is true and array borders are overrun/underrun. *) function ThreshAbsGT(const Vec: TMtxVec; const Value: double; VecIndex, Index, Len: integer): TMtxVec; overload; (*Threshold less than operation. Perform operation on all calling object values. The LTValue parameter is an lower bound for threshold operation. All values less than LTLevel will be replaced with LTValue. For complex number comparation is applied with norm of complex value. var a: Matrix; begin a.SetIt(1,2,True,[2,0.1,3,4]); a.ThresholdLT(2.3,1.5); // a = [1.5,1.5,3,4] end; *) function ThresholdLT(LTLevel, LTValue: double): TMtxVec; overload; (*Perfrom "less than" threshold operation on the calling object values in range [Index]..[Index+Len-1]. An exception is raised if array borders are overrun/underrun. *) function ThresholdLT(LTLevel, LTValue: double; Index, Len: integer): TMtxVec; overload; (*Perform "less than" threshold operation on all Vec object values and store the results in calling object. Size and properties of the calling object are adjusted automatically. *) function ThresholdLT(const Vec: TMtxVec; LTLevel, LTValue: double): TMtxVec; overload; (*Perform "less than" threshold operation on Vec elements from range [VecIndex]..[VecIndex+Len-1]. Store the results in the calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if is true and array borders are overrun/underrun. An exception will be raised if Vec.Complex and Complex of the calling object are not equal. *) function ThresholdLT(const Vec: TMtxVec; LTLevel, LTValue: double; VecIndex, Index, Len: integer): TMtxVec; overload; (*Perfrom "less than" threshold operation for complex numbers. If the calling object contains none Complex values, an exception will be raised. *) function ThresholdLT(LTLevel: double; LTValue: TCplx): TMtxVec; overload; (*Perfrom "less than" threshold operation for complex numbers on the calling object values in range [Index]..[Index+Len-1]. An exception is raised if array borders are overrun/underrun. If the calling object contains none Complex values, an exception will be raised. *) function ThresholdLT(LTLevel: double; LTValue: TCplx; Index, Len: integer): TMtxVec; overload; (*Perform "less than" threshold operation for complex numbers on all Vec object values and store the results in calling object. Size and properties of the calling object are adjusted automatically. If Vec object contains none Complex values, an exception will be raised. *) function ThresholdLT(const Vec: TMtxVec; LTLevel: double; LTValue: TCplx): TMtxVec; overload; (*Perform "less than" threshold operation for complex numbers on Vec elements from range [VecIndex]..[VecIndex+Len-1]. Store the results in the calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if is true and array borders are overrun/underrun. If Vec object or calling object contain none Complex values, an exception will be raised. *) function ThresholdLT(const Vec: TMtxVec; LTLevel: double; LTValue: TCplx; VecIndex, Index, Len: integer): TMtxVec; overload; (*Threshold greater than operation. Perform operation on all calling object values. The GTValue parameter is an upper bound for threshold operation. All values bigger than LTLevel will be replaced with GTValue. For complex number comparation is applied with norm of complex value. var a: Matrix; begin a.SetIt(1,2,True,[2,0.1,3,4]); a.ThresholdGT(2.3,3.4); // a = [2,0.1,3.4,3.4] end; *) function ThresholdGT(GTLevel, GTValue: double): TMtxVec; overload; (*Perfrom "greater than" threshold operation on the calling object values in range [Index]..[Index+Len-1]. An exception is raised if array borders are overrun/underrun. *) function ThresholdGT(GTLevel, GTValue: double; Index, Len: integer): TMtxVec; overload; (* Perform "greater than" threshold operation on all Vec object values and store the results in calling object. Size and properties of the calling object are adjusted automatically. *) function ThresholdGT(const Vec: TMtxVec; GTLevel, GTValue: double): TMtxVec; overload; (* Perform "greater than" threshold operation on Vec elements from range [VecIndex]..[VecIndex+Len-1] and store the results in the calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if is true and array borders are overrun/underrun. An exception will be raised if Vec.Complex and Complex of the calling object are not equal. *) function ThresholdGT(const Vec: TMtxVec; GTLevel, GTValue: double; VecIndex, Index, Len: integer): TMtxVec; overload; (*Perfrom "greater than" threshold operation for complex numbers. If the calling object contains none Complex values, an exception will be raised. *) function ThresholdGT(GTLevel: double; GTValue: TCplx): TMtxVec; overload; (*Perfrom "greater than" threshold operation for complex numbers on the calling object values in range [Index]..[Index+Len-1]. An exception is raised if array borders are overrun/underrun. If the calling object contains none Complex values, an exception will be raised. *) function ThresholdGT(GTLevel: double; GTValue: TCplx; Index, Len: integer): TMtxVec; overload; (*Perform "greater than" threshold operation for complex numbers on all Vec object values and store the results in calling object. Size and properties of the calling object are adjusted automatically. If Vec object contains none Complex values, an exception will be raised. *) function ThresholdGT(const Vec: TMtxVec; GTLevel: double; GTValue: TCplx): TMtxVec; overload; (*Perform "greater than" threshold operation for complex numbers on Vec elements from range [VecIndex]..[VecIndex+Len-1]. Store the results in the calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if is true and array borders are overrun/underrun. If Vec object or calling object contain none Complex values, an exception will be raised. *) function ThresholdGT(const Vec: TMtxVec; GTLevel: double; GTValue: TCplx; VecIndex, Index, Len: integer): TMtxVec; overload; (*Threshold greater than and less than operation. Perform operation on all calling object values. The LTValue parameter is an lower bound for threshold operation. The GTValue parameter is an upper bound for threshold operation. All values less than LTLevel will be replaced with LTValue. All values bigger than GTLevel will be replaced with GTValue. Operation is available only for none Complex values. var a: Matrix; begin a.SetIt(1,2,True,[2,0.1,3,4]); a.ThresholdGT_LT(2.3,3.4,1,0.5); // a = [2,0.5,3.4,3.4] end; *) function ThresholdGT_LT (GTLevel, GTValue, LTLevel, LTValue: double): TMtxVec; overload; (*Perfrom "greater than and less than" threshold operation on the calling object values in range [Index]..[Index+Len-1]. An exception is raised if array borders are overrun/underrun. An exception will be raised if the calling object contains complex numbers. *) function ThresholdGT_LT (GTLevel, GTValue, LTLevel, LTValue: double; Index, Len: integer): TMtxVec; overload; (*Perform "greater than and less than" threshold operation on all Vec object values and store the results in calling object. Size and properties of the calling object are adjusted automatically. An exception will be raised if Vec object contains complex numbers. *) function ThresholdGT_LT (const Vec: TMtxVec; GTLevel, GTValue, LTLevel, LTValue: double): TMtxVec; overload; (*Perform "greater than and less than" threshold operation on Vec elements from range [VecIndex]..[VecIndex+Len-1] and store the results in the calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if is true and array borders are overrun/underrun. An exception will be raised if Vec object or the calling object contain complex numbers. *) function ThresholdGT_LT(const Vec: TMtxVec; GTLevel, GTValue, LTLevel, LTValue: double; VecIndex, Index, Len: integer): TMtxVec; overload; (*Rounds a real number towards zero and returns the fractional part. Rounds all calling object elements towards zero to an integer and stores the result in the TruncDst object as floating point numbers. The fractional part is stored in the FracDst. *) procedure TruncAndFrac(TruncDst: TMtxVec; FracDst: TDenseMtxVec); overload; (*Truncate calling object elements [Index]..[Index+Len-1]. Store the results to TruncDst object elements [TruncIdx]..[TruncIdx+Len-1]. The fractional parts are saved in FracDst elements [FracIdx]..[FracIdx+Len-1]. Size and property of calling object must be set explicitly to match those of Src object. An exception is raised if array borders are overrun/underrun. *) procedure TruncAndFrac(TruncDst: TMtxVec; FracDst: TDenseMtxVec; TruncIdx, FracIdx, Index, Len: integer); overload; (*Rounds a real number towards zero. Rounds all calling object elements towards zero to an integer and stores the result in the calling object again as floating point numbers. *) function Trunc: TMtxVec; overload; (*Truncate calling object elements [Index]..[Index+Len-1] in-place. An exception is raised if array borders are overrun/underrun. *) function Trunc(Index,Len: integer): TMtxVec; overload; (*Truncate all Src object elements and store the results in calling object elements. Size and property of calling object are adjusted automatically. *) function Trunc(const Src: TMtxVec): TMtxVec; overload; (*Truncate all calling object elements and store the result in the Dst integer array. Length of the array is automatically adjusted. If the calling object is Complex, the length of the Dst array is equal to 2*. *) procedure Trunc(var Dst: TIntegerArray); overload; (*Truncate Src object elements [SrcIndex]..[SrcIndex+Len-1]. Store the results to calling object elemenents [Index]..[Index+Len-1]. Size and property of calling object must be set explicitly to match those of Src object. An exception is raised if array borders are overrun/underrun. *) function Trunc(const Src: TMtxVec; SrcIndex, Index,Len: integer): TMtxVec; overload; (*Write object header and values to a file. Write the header describing the calling object and the values array of the calling object to the file, specified by the FileName. If the file already exist, the data is overwritten by default. If Append is True, the data is appended to the end of the file. The data is always saved with default precision. (single or double). * In case of '.csv' extension a comma is used as a column delimiter for matrices. * In case of '.txt' extension a tab is used as a column delimiter for matrices. * For all other extensions, the format is binary Note It is recommended you use a *.mtx extension when you're saving/loading matrix to/from file. Similarly, you should use a *.Vec extension when you're saving/loading vector to/from file. var Mtx: Matrix; begin Mtx.SetIt(2,2,False,[3,1,-1,5]); Mtx.SaveToFile('c:\test.mtx'); // Write info and header for Mtx to file end; *) procedure SaveToFile(const FileName: string; Append: boolean = False); (*Reads the header information and the values array content from the file. Reads the header information and the values array content from the file specified by FileName parameter. * In case of '.csv' extension a comma is used as a column delimiter for matrices. * In case of '.txt' extension a tab is used as a column delimiter for matrices. * For all other extensions, the expected format is binary. var b: Matrix; begin b.LoadFromFile('c:\test.Vec'); // Read header and values for b end; *) procedure LoadFromFile(const FileName: string); (*Reads the header information and the values array content from a stream. Reads the header information and the values array content from the SrcStream. The return value indicates the number of elements read. var b: Matrix; AStream: TFileStream; begin b.SetIt(2,2,False,[0,0,1,3,2]); AStream := TFileStream.Create('C:\test.Vec',fmCreate); try b.LoadFromStream(AStream); // Read info and header for b finally AStream.Free; end; end; *) function LoadFromStream(const Src: TStream): Int64; overload; (*Writes the header information and the Values content to a stream. Writes the header information and the Values content to a DstStream stream. Number type is defined by the Precision parameter. Rounding defines the rounding for integer types. When saving double precision as single precision, all overflows are saved as INF (-INF). When saving to integer types all overflows are clipped. Attempt to save single precision as double precision will raise an exception. var b: Matrix; AStream: TFileStream; begin b.SetIt(2,2,False,[0,0,1,3,2]); AStream := TFileStream.Create('C:\test.Vec',fmCreate); try b.SaveToStream(AStream); // Write info and header for b finally AStream.Free; end end; *) procedure SaveToStream(const Dst: TStream); overload; (*Writes object Values content to a stream. Writes the calling object Values content to the DstStream stream. No other values describing the data type or length are written to the DstStream. Number type is defined by the Precision parameter. Rounding defines the rounding for integer types. When saving double precision as single precision, all overflows are saved as INF (-INF). When saving to integer types all overflows are clipped. Attempt to save single precision as double precision will raise an exception. The paramateres must be the same as for the method. Note Use this method separately only, if you want user defined storage format. var b: Matrix; AStream: TFileStream; begin b.SetIt(2,2,False,[0,0,1,3,2]); AStream := TFileStream.Create('C:\test.Vec',fmCreate); try b.WriteHeader(AStream); // Write info for b b.WriteValues(AStream); // Write values of b finally AStream.Free; end; end; *) procedure WriteValues(const Dst: TStream; Precision: TPrecision; Rounding: TRounding = rnTrunc); overload; procedure WriteValues(const Dst: TStream); overload; (*Writes the header information for the calling Matrix to a stream. Writes the header information for the calling object to a DstStream stream. The header information contains information about object (size, complex, type of values in Values array, ...) which all define the state of the object. Number type is defined by the Precision parameter. Rounding defines the rounding for integer types. When saving double precision as single precision, all overflows are saved as INF (-INF). When saving to integer types all overflows are clipped. var b: Matrix; AStream: TFileStream; begin b.SetIt(2,2,False,[0,0,1,3,2]); AStream := TFileStream.Create('C:\test.bin',fmCreate); try b.WriteHeader(AStream); // Write info for b b.WriteValues(AStream); // Write values of b finally AStream.Free; end; end; *) procedure WriteHeader(const Dst: TStream; Precision: TPrecision; Rounding: TRounding = rnTrunc); overload; procedure WriteHeader(const Dst: TStream); overload; (*Reads the header information from a stream to object. Reads the header information from a DstStream stream to calling object. The header information contains all necessary information defining the object. The function returns the precision in which the data was stored. This information is required for the method. var b: Matrix; AStream: TFileStream; Precision: TPrecision; begin AStream := TFileStream.Create('C:\test.bin',fmOpenRead); try Precision := b.ReadHeader(AStream); // Read info for b b.ReadValues(AStream,Precision); // Read values of b finally AStream.Free; end; end; *) function ReadHeader(const Src: TStream): TPrecision; overload; (*Adds Value to object elements. Adds Value to all calling object elements. *) function Add(Value: double): TMtxVec; overload; (*Adds complex Value to all calling object complex elements.*) function Add(Value: TCplx): TMtxVec; overload; (*Adds Value to calling object elements [Index]..[Index+Len-1]. An exception is raised if array borders are overrun. *) function Add(Value: double; Index, Len: integer): TMtxVec; overload; (*Adds complex Value to calling object complex elements [Index]..[Index+Len-1]. An exception is raised if array borders are overrun. *) function Add(Value: TCplx; Index, Len: integer): TMtxVec; overload; (*Adds Value to the each element of the Vec object and stores the result in the calling object. Size and properties of the calling object are set automatically. *) function Add(const Vec: TMtxVec; Value: double): TMtxVec; overload; (*Adds complex Value to each element of the Vec object and store the result to the calling object. Size property of the calling object is set automatically. property of the calling object is set to True. *) function Add(const Vec: TMtxVec; Value: TCplx): TMtxVec; overload; (*Adds Value to each element of Vec object in range [VecIndex]..[VecIndex+Len-1] and stores result to elements [Index]..[Index+Len-1] of the calling object. Size of the calling object is not changed. An exception is raised if array borders are overrun. property of the calling object is set implicitly. *) function Add(const Vec: TMtxVec; Value: double; VecIndex, Index, Len: integer): TMtxVec; overload; (*Adds complex Value to each elements of the Vec object in range [VecIndex]..[VecIndex+Len-1] and stores the result to elements [Index]..[Index+Len-1] of the calling object. Size of the calling object is not changed. An exception is raised if array borders are overrun. property of the calling object is set to True. *) function Add(const Vec: TMtxVec; Value: TCplx; VecIndex, Index, Len: integer): TMtxVec; overload; (*Array addition. Add each of Vec elements to corresponding elements in the calling object. *) function Add(const Vec: TMtxVec): TMtxVec; overload; (*Add each of Vec elements to corresponding elements in the calling object. In addition, the following formula is begin used: result = result+ aScale*Vec . The results are stored in the calling object. Size and properties of the calling object are set implicitly to match the Vec object. *) function AddScaled(const Vec: TMtxVec; aScale: double): TMtxVec; overload; (*Add each of Vec elements to corresponding elements in the calling object. In addition, the following formula is begin used: result = result+ Cplx(RScale,IScale)*Vec . When default values for parameters are being used the "normal" addition is being performed. The results are stored in the calling object. Size and properties of the calling object are set implicitly to match the Vec object. *) function AddScaled(const Vec: TMtxVec; RScale: double; IScale: double): TMtxVec; overload; (*Add each of Vec elements to corresponding elements in the calling object. In addition, the following formula is begin used: result = result+ aScale*Vec . The results are stored in the calling object. Size and properties of the calling object are set implicitly to match the Vec object. *) function AddScaled(const Vec: TMtxVec; aScale: TCplx): TMtxVec; overload; (*Add each of Vec2 elements to corresponding elements in Vec1. The results are stored in the calling object. Size and properties of the calling object are set implicitly to match Vec1 and Vec2 matrices. *) function Add(const Vec1, Vec2: TMtxVec): TMtxVec; overload; (*Add Vec elements [VecIndex]..[VecIndex+Len-1] to calling object elements [Index]..[Index+Len-1]. An exception is raised if is true and array borders are overrun. *) function Add(const Vec: TMtxVec; VecIndex, Index, Len: integer): TMtxVec; overload; (*Adds Vec elements [VecIndex]..[VecIndex+Len-1] to calling object elements [Index]..[Index+Len-1]. In addition, the following formula is begin used: result = result+ Cplx(aScale)*Vec . An exception is raised if is true and array borders are overrun. *) function AddScaled(const Vec: TMtxVec; aScale: double; VecIndex, Index, Len: integer): TMtxVec; overload; (*Adds Vec elements [VecIndex]..[VecIndex+Len-1] to calling object elements [Index]..[Index+Len-1]. In addition, the following formula is begin used: result = result+ aScale*Vec . An exception is raised if is true and array borders are overrun. *) function AddScaled(const Vec: TMtxVec; aScale: TCplx; VecIndex, Index, Len: integer): TMtxVec; overload; (*Add Vec1 elements [Vec1Index]..[Vec1Index+Len-1] to Vec2 elements [Vec2Index]..[Vec2Index+Len-1] and store the results in calling object elements [Index]..[Index+Len-1]. An exception is raised if is true and array borders are overrun. *) function Add(const Vec1, Vec2: TMtxVec; Vec1Index, Vec2Index, Index, Len: integer): TMtxVec; overload; (*Add a product of two matrices. Multiply Vec1 elements with coresponding Vec2 elements and add the result to the calling Matrix. The size of the calling Matrix is set implicitly. *) function AddProduct(const Vec1, Vec2: TMtxVec): TMtxVec; overload; (*Multiply Vec1 elements [Vec1Index]..[Vec1Index+Len-1] with Vec2 elements [Vec2Index]..[Vec2Index+Len-1]. Ad the results to the calling object elements [Index]..[Index+Len-1]. An exception is raised if is true and array borders are overrun. *) function AddProduct(const Vec1, Vec2: TMtxVec; Vec1Index, Vec2Index, Index, Len: integer): TMtxVec; overload; (* Compute X + Y*yScale *) function AddScaled(const X, Y: TMtxVec; const yScale: Double): TMtxVec; overload; (* Compute X + Y*yScale with complex arguments.*) function AddScaled(const X, Y: TMtxVec; const yScale: TCplx): TMtxVec; overload; (* Compute X + Y*yScale on sub arrays. *) function AddScaled(const X: TMtxVec; xIndex: integer; const Y: TMtxVec; yIndex: integer; const yScale: Double; Index, Len: integer): TMtxVec; overload; (* Compute X + Y*yScale on sub arrays with complex arguments. *) function AddScaled(const X: TMtxVec; xIndex: integer; const Y: TMtxVec; yIndex: integer; const yScale: TCplx; Index, Len: integer): TMtxVec; overload; (* Compute sqr(X + Y*yScale) By making use of yScale, it is also possible to compute the following (at the same or higher speed): (X - Y)^2 = X^2 - 2XY +Y^2 *) function AddScaledSqr(const X, Y: TMtxVec; const yScale: Double): TMtxVec; overload; (* Compute sqr(X + Y*yScale) *) function AddScaledSqr(const X, Y: TMtxVec; const yScale: TCplx): TMtxVec; overload; (* Compute sqr(X + Y*yScale) on sub arrays *) function AddScaledSqr(const X: TMtxVec; xIndex: integer; const Y: TMtxVec; yIndex: integer; const yScale: Double; Index, Len: integer): TMtxVec; overload; (* Compute sqr(X + Y*yScale) on sub arrays *) function AddScaledSqr(const X: TMtxVec; xIndex: integer; const Y: TMtxVec; yIndex: integer; const yScale: TCplx; Index, Len: integer): TMtxVec; overload; (* Compute sqr(X) + sqr(Y)*yScale By making use of yScale, it is also possible to compute the following (at the same or higher speed): X^2 - Y^2 *) function SqrAddScaled(const X, Y: TMtxVec; const yScale: Double): TMtxVec; overload; (* Compute sqr(X) + sqr(Y)*yScale *) function SqrAddScaled(const X, Y: TMtxVec; const yScale: TCplx): TMtxVec; overload; (* Compute sqr(X) + sqr(Y)*yScale on sub arrays *) function SqrAddScaled(const X: TMtxVec; xIndex: integer; const Y: TMtxVec; yIndex: integer; const yScale: Double; Index, Len: integer): TMtxVec; overload; (* Compute sqr(X) + sqr(Y)*yScale on sub arrays *) function SqrAddScaled(const X: TMtxVec; xIndex: integer; const Y: TMtxVec; yIndex: integer; const yScale: TCplx; Index, Len: integer): TMtxVec; overload; (* Compute X + Y + Z *) function Add(const X, Y, Z: TMtxVec): TMtxVec; overload; (* Compute X + Y + Z on sub arrays *) function Add(const X: TMtxVec; xIndex: integer; const Y: TMtxVec; yIndex: integer; const Z: TMtxVec; zIndex: integer; Index, Len: integer): TMtxVec; overload; (* Compute X + Y + Z*zScale *) function AddScaled(const X, Y, Z: TMtxVec; const zScale: Double): TMtxVec; overload; (* Compute X + Y + Z*zScale *) function AddScaled(const X, Y, Z: TMtxVec; const zScale: TCplx): TMtxVec; overload; (* Compute X + Y + Z*zScale on sub arrays *) function AddScaled(const X: TMtxVec; xIndex: integer; const Y: TMtxVec; yIndex: integer; const Z: TMtxVec; zIndex: integer; const zScale: Double; Index, Len: integer): TMtxVec; overload; (* Compute X + Y + Z*zScale on sub arrays *) function AddScaled(const X: TMtxVec; xIndex: integer; const Y: TMtxVec; yIndex: integer; const Z: TMtxVec; zIndex: integer; const zScale: TCplx; Index, Len: integer): TMtxVec; overload; (* Compute X + Y*yScale + Z*zScale *) function AddScaled(const X, Y: TMtxVec; const yScale: Double; const Z: TMtxVec; const zScale: Double): TMtxVec; overload; (* Compute X + Y*yScale + Z*zScale *) function AddScaled(const X, Y: TMtxVec; const yScale: TCplx; const Z: TMtxVec; const zScale: TCplx): TMtxVec; overload; (* Compute X + Y*yScale + Z*zScale on sub arrays *) function AddScaled(const X: TMtxVec; xIndex: integer; const Y: TMtxVec; yIndex: integer; const yScale: Double; const Z: TMtxVec; zIndex: integer; const zScale: Double; Index, Len: integer): TMtxVec; overload; (* Compute X + Y*yScale + Z*zScale on sub arrays *) function AddScaled(const X: TMtxVec; xIndex: integer; const Y: TMtxVec; yIndex: integer; const yScale: TCplx; const Z: TMtxVec; zIndex: integer; const zScale: TCplx; Index, Len: integer): TMtxVec; overload; (* Compute X + Y + zScalar *) function Add(const X, Y: TMtxVec; const Z: Double): TMtxVec; overload; (* Compute X + Y + zScalar *) function Add(const X, Y: TMtxVec; const Z: TCplx): TMtxVec; overload; (* Compute X + Y + zScalar on sub arrays *) function Add(const X: TMtxVec; xIndex: integer; const Y: TMtxVec; yIndex: integer; const Z: Double; Index, Len: integer): TMtxVec; overload; (* Compute X + Y + zScalar on sub arrays *) function Add(const X: TMtxVec; xIndex: integer; const Y: TMtxVec; yIndex: integer; const Z: TCplx; Index, Len: integer): TMtxVec; overload; (* Compute X + Y*yScale + zScalar *) function AddScaledC(const X, Y: TMtxVec; const yScale: Double; const Z: Double): TMtxVec; overload; (* Compute X + Y*yScale + zScalar *) function AddScaledC(const X, Y: TMtxVec; const yScale: TCplx; const Z: TCplx): TMtxVec; overload; (* Compute X + Y*yScale + zScalar on sub arrays *) function AddScaledC(const X: TMtxVec; xIndex: integer; const Y: TMtxVec; yIndex: integer; const yScale: Double; const Z: Double; Index, Len: integer): TMtxVec; overload; (* Compute X + Y*yScale + zScalar on sub arrays *) function AddScaledC(const X: TMtxVec; xIndex: integer; const Y: TMtxVec; yIndex: integer; const yScale: TCplx; const Z: TCplx; Index, Len: integer): TMtxVec; overload; (* Compute X - Y - Z *) function Sub(const X, Y, Z: TMtxVec): TMtxVec; overload; (* Compute X - Y - Z on sub array*) function Sub(const X: TMtxVec; xIndex: integer; const Y: TMtxVec; yIndex: integer;const Z: TMtxVec; zIndex: integer; Index, Len: integer): TMtxVec; overload; (* Compute X - Y*yScale - Z*zScale *) function SubScaled(const X, Y: TMtxVec; const yScale: Double; const Z: TMtxVec; const zScale: Double): TMtxVec; overload; (* Compute X - Y*yScale - Z*zScale *) function SubScaled(const X, Y: TMtxVec; const yScale: TCplx; const Z: TMtxVec; const zScale: TCplx): TMtxVec; overload; (* Compute X - Y*yScale - Z*zScale on sub array*) function SubScaled(const X: TMtxVec; xIndex: integer; const Y: TMtxVec; yIndex: integer; const yScale: Double; const Z: TMtxVec; zIndex: integer; const zScale: Double; Index, Len: integer): TMtxVec; overload; (* Compute X - Y*yScale - Z*zScale on sub array*) function SubScaled(const X: TMtxVec; xIndex: integer; const Y: TMtxVec; yIndex: integer; const yScale: TCplx; const Z: TMtxVec; zIndex: integer; const zScale: TCplx; Index, Len: integer): TMtxVec; overload; (* Compute X - Y - Z*zScale *) function SubScaled(const X, Y, Z: TMtxVec; const zScale: Double): TMtxVec; overload; (* Compute X - Y - Z*zScale *) function SubScaled(const X, Y, Z: TMtxVec; const zScale: TCplx): TMtxVec; overload; (* Compute X - Y - Z*zScale on sub array*) function SubScaled(const X: TMtxVec; xIndex: integer; const Y: TMtxVec; yIndex: integer; const Z: TMtxVec; zIndex: integer; const zScale: Double; Index, Len: integer): TMtxVec; overload; (* Compute X - Y - Z*zScale on sub array*) function SubScaled(const X: TMtxVec; xIndex: integer; const Y: TMtxVec; yIndex: integer; const Z: TMtxVec; zIndex: integer; const zScale: TCplx; Index, Len: integer): TMtxVec; overload; (* Compute X - Y - zScalar *) function Sub(const X, Y: TMtxVec; const Z: Double): TMtxVec; overload; (* Compute X - Y - zScalar *) function Sub(const X, Y: TMtxVec; const Z: TCplx): TMtxVec; overload; (* Compute X - Y - zScalar on sub array*) function Sub(const X: TMtxVec; xIndex: integer; const Y: TMtxVec; yIndex: integer; const Z: Double; Index, Len: integer): TMtxVec; overload; (* Compute X - Y - zScalar on sub array*) function Sub(const X: TMtxVec; xIndex: integer; const Y: TMtxVec; yIndex: integer; const Z: TCplx; Index, Len: integer): TMtxVec; overload; (* Compute X - Y*yScale - zScalar *) function SubScaledC(const X, Y: TMtxVec; const yScale: Double; const Z: Double): TMtxVec; overload; (* Compute X - Y*yScale - zScalar *) function SubScaledC(const X, Y: TMtxVec; const yScale: TCplx; const Z: TCplx): TMtxVec; overload; (* Compute X - Y*yScale - zScalar on sub array*) function SubScaledC(const X: TMtxVec; xIndex: integer; const Y: TMtxVec; yIndex: integer; const yScale: Double; const Z: Double; Index, Len: integer): TMtxVec; overload; (* Compute X - Y*yScale - zScalar on sub array*) function SubScaledC(const X: TMtxVec; xIndex: integer; const Y: TMtxVec; yIndex: integer; const yScale: TCplx; const Z: TCplx; Index, Len: integer): TMtxVec; overload; (* Compute X * Y / Z *) function MulAndDiv(const X, Y, Z: TMtxVec): TMtxVec; overload; (* Compute X * Y / Z on sub array*) function MulAndDiv(const X: TMtxVec; xIndex: integer; const Y: TMtxVec; yIndex: integer; const Z: TMtxVec; zIndex: integer; Index, Len: integer): TMtxVec; overload; (* Compute (X + Y)*Z *) function AddAndMul(const X, Y, Z: TMtxVec): TMtxVec; overload; (* Compute (X + Y)*Z on sub array*) function AddAndMul(const X: TMtxVec; xIndex: Integer; const Y: TMtxVec; yIndex: Integer; const Z: TMtxVec; zIndex: Integer; Index, Len: Integer): TMtxVec; overload; (* Compute (X + Y)*Z*zScale *) function AddAndMul(const X, Y, Z: TMtxVec; const zScale: double): TMtxVec; overload; (* Compute (X + Y)*Z*zScale *) function AddAndMul(const X, Y, Z: TMtxVec; const zScale: TCplx): TMtxVec; overload; (* Compute (X + Y)*Z*zScale on sub array*) function AddAndMul(const X: TMtxVec; xIndex: Integer; const Y: TMtxVec; yIndex: Integer; const Z: TMtxVec; zIndex: Integer; const zScale: double; Index, Len: Integer): TMtxVec; overload; (* Compute (X + Y)*Z*zScale on sub array*) function AddAndMul(const X: TMtxVec; xIndex: Integer; const Y: TMtxVec; yIndex: Integer; const Z: TMtxVec; zIndex: Integer; const zScale: TCplx; Index, Len: Integer): TMtxVec; overload; (* Compute (X + Y*yScale)*Z*zScale *) function AddAndMul(const X, Y: TMtxVec; const yScale: double; const Z: TMtxVec; const zScale: double): TMtxVec; overload; (* Compute (X + Y*yScale)*Z*zScale *) function AddAndMul(const X, Y: TMtxVec;const yScale: TCplx; const Z: TMtxVec;const zScale: TCplx): TMtxVec; overload; (* Compute (X + Y*yScale)*Z*zScale on sub array*) function AddAndMul(const X: TMtxVec; xIndex: Integer; const Y: TMtxVec; yIndex: Integer; const yScale: double; const Z: TMtxVec; zIndex: Integer; const zScale: double; Index, Len: Integer): TMtxVec; overload; (* Compute (X + Y*yScale)*Z*zScale on sub array*) function AddAndMul(const X: TMtxVec; xIndex: Integer; const Y: TMtxVec; yIndex: Integer; const yScale: TCplx; const Z: TMtxVec; zIndex: Integer; const zScale: TCplx; Index, Len: Integer): TMtxVec; overload; (* Compute (X + Y)*zScalar *) function AddAndMul(const X, Y: TMtxVec; const Z: Double): TMtxVec; overload; (* Compute (X + Y)*zScalar *) function AddAndMul(const X, Y: TMtxVec; const Z: TCplx): TMtxVec; overload; (* Compute (X + Y)*zScalar on sub array*) function AddAndMul(const X: TMtxVec; xIndex: Integer; const Y: TMtxVec; yIndex: Integer; const Z: Double; Index, Len: Integer): TMtxVec; overload; (* Compute (X + Y)*zScalar on sub array*) function AddAndMul(const X: TMtxVec; xIndex: Integer; const Y: TMtxVec; yIndex: Integer; const Z: TCplx; Index, Len: Integer): TMtxVec; overload; (* Compute (X + Y*yScale)*zScalar *) function AddAndMul(const X, Y: TMtxVec; const yScale, Z: Double): TMtxVec; overload; (* Compute (X + Y*yScale)*zScalar *) function AddAndMul(const X, Y: TMtxVec; const yScale, Z: TCplx): TMtxVec; overload; (* Compute (X + Y*yScale)*zScalar on sub array*) function AddAndMul(const X: TMtxVec; xIndex: Integer; const Y: TMtxVec; yIndex: Integer; const yScale, Z: Double; Index, Len: Integer): TMtxVec; overload; (* Compute (X + Y*yScale)*zScalar on sub array*) function AddAndMul(const X: TMtxVec; xIndex: Integer; const Y: TMtxVec; yIndex: Integer; const yScale, Z: TCplx; Index, Len: Integer): TMtxVec; overload; (* Compute (X + yScalar)*Z*zScale *) function AddAndMul(const X: TMtxVec; const Y: Double; const Z: TMtxVec; const zScale: Double): TMtxVec; overload; (* Compute (X + yScalar)*Z*zScale *) function AddAndMul(const X: TMtxVec; const Y: TCplx; const Z: TMtxVec; const zScale: TCplx): TMtxVec; overload; (* Compute (X + yScalar)*Z*zScale on sub-array*) function AddAndMul(const X: TMtxVec; xIndex: integer; const Y: Double; const Z: TMtxVec; zIndex: integer; const zScale: Double; Index, Len: integer): TMtxVec; overload; (* Compute (X + yScalar)*Z*zScale on sub-array*) function AddAndMul(const X: TMtxVec; xIndex: integer; const Y: TCplx; const Z: TMtxVec; zIndex: integer; const zScale: TCplx; Index, Len: integer): TMtxVec; overload; (* Compute (X*xScale + yScalar)*Z *) function AddAndMul(const X: TMtxVec; const xScale, Y: Double; const Z: TMtxVec): TMtxVec; overload; (* Compute (X*xScale + yScalar)*Z *) function AddAndMul(const X: TMtxVec; const xScale, Y: TCplx; const Z: TMtxVec): TMtxVec; overload; (* Compute (X*xScale + yScalar)*Z on sub-array*) function AddAndMul(const X: TMtxVec; xIndex: integer; const xScale, Y: Double; const Z: TMtxVec; zIndex: integer; Index, Len: integer): TMtxVec; overload; (* Compute (X*xScale + yScalar)*Z on sub-array*) function AddAndMul(const X: TMtxVec; xIndex: integer; const xScale, Y: TCplx; const Z: TMtxVec; zIndex: integer; Index, Len: integer): TMtxVec; overload; (* Compute (X + yScalar)*Z *) function AddAndMul(const X: TMtxVec; const Y: Double; const Z: TMtxVec): TMtxVec; overload; (* Compute (X + yScalar)*Z *) function AddAndMul(const X: TMtxVec; const Y: TCplx; const Z: TMtxVec): TMtxVec; overload; (* Compute (X + yScalar)*Z on sub-array*) function AddAndMul(const X: TMtxVec; xIndex: integer; const Y: Double; const Z: TMtxVec; zIndex: integer; Index, Len: integer): TMtxVec; overload; (* Compute (X + yScalar)*Z on sub-array*) function AddAndMul(const X: TMtxVec; xIndex: integer; const Y: TCplx; const Z: TMtxVec; zIndex: integer; Index, Len: integer): TMtxVec; overload; (* Compute (X + yScalar)*zScalar *) function AddAndMul(const X: TMtxVec; const Y, Z: Double): TMtxVec; overload; (* Compute (X + yScalar)*zScalar *) function AddAndMul(const X: TMtxVec; const Y, Z: TCplx): TMtxVec; overload; (* Compute (X + yScalar)*zScalar on sub-array*) function AddAndMul(const X: TMtxVec; xIndex: integer; const Y, Z: Double; Index, Len: integer): TMtxVec; overload; (* Compute (X + yScalar)*zScalar on sub-array*) function AddAndMul(const X: TMtxVec; xIndex: integer; const Y, Z: TCplx; Index, Len: integer): TMtxVec; overload; (* Compute (X - Y)*Z *) function SubAndMul(const X, Y, Z: TMtxVec): TMtxVec; overload; (* Compute (X + Y)*Z on sub array*) function SubAndMul(const X: TMtxVec; xIndex: Integer; const Y: TMtxVec; yIndex: Integer; const Z: TMtxVec; zIndex: Integer; Index, Len: Integer): TMtxVec; overload; (* Compute (X - Y)*Z*zScale *) function SubAndMul(const X, Y, Z: TMtxVec; const zScale: double): TMtxVec; overload; (* Compute (X - Y)*Z*zScale *) function SubAndMul(const X, Y, Z: TMtxVec; const zScale: TCplx): TMtxVec; overload; (* Compute (X - Y)*Z*zScale on sub array*) function SubAndMul(const X: TMtxVec; xIndex: Integer; const Y: TMtxVec; yIndex: Integer; const Z: TMtxVec; zIndex: Integer;const zScale: double; Index, Len: Integer): TMtxVec; overload; (* Compute (X - Y)*Z*zScale on sub array*) function SubAndMul(const X: TMtxVec; xIndex: Integer; const Y: TMtxVec; yIndex: Integer; const Z: TMtxVec; zIndex: Integer;const zScale: TCplx; Index, Len: Integer): TMtxVec; overload; (* Compute (X - Y*yScale)*Z*zScale *) function SubAndMul(const X, Y: TMtxVec; const yScale: double; const Z: TMtxVec; const zScale: double): TMtxVec; overload; (* Compute (X - Y*yScale)*Z*zScale *) function SubAndMul(const X, Y: TMtxVec; const yScale: TCplx; const Z: TMtxVec; const zScale: TCplx): TMtxVec; overload; (* Compute (X - Y*yScale)*Z*zScale on sub array*) function SubAndMul(const X: TMtxVec; xIndex: Integer; const Y: TMtxVec; yIndex: Integer; const yScale: double; const Z: TMtxVec; zIndex: Integer; const zScale: double; Index, Len: Integer): TMtxVec; overload; (* Compute (X - Y*yScale)*Z*zScale on sub array*) function SubAndMul(const X: TMtxVec; xIndex: Integer; const Y: TMtxVec; yIndex: Integer; const yScale: TCplx; const Z: TMtxVec; zIndex: Integer; const zScale: TCplx; Index, Len: Integer): TMtxVec; overload; (* Compute (X - Y)*zScalar *) function SubAndMul(const X, Y: TMtxVec; const Z: Double): TMtxVec; overload; (* Compute (X - Y)*zScalar *) function SubAndMul(const X, Y: TMtxVec; const Z: TCplx): TMtxVec; overload; (* Compute (X - Y)*zScalar on sub array*) function SubAndMul(const X: TMtxVec; xIndex: Integer; const Y: TMtxVec; yIndex: Integer; const Z: Double; Index, Len: Integer): TMtxVec; overload; (* Compute (X - Y)*zScalar on sub array*) function SubAndMul(const X: TMtxVec; xIndex: Integer; const Y: TMtxVec; yIndex: Integer; const Z: TCplx; Index, Len: Integer): TMtxVec; overload; (* Compute (X - Y*yScale)*zScalar *) function SubAndMul(const X, Y: TMtxVec; const yScale, Z: Double): TMtxVec; overload; (* Compute (X - Y*yScale)*zScalar *) function SubAndMul(const X, Y: TMtxVec; const yScale, Z: TCplx): TMtxVec; overload; (* Compute (X - Y*yScale)*zScalar on sub array*) function SubAndMul(const X: TMtxVec; xIndex: Integer; const Y: TMtxVec; yIndex: Integer; const yScale, Z: Double; Index, Len: Integer): TMtxVec; overload; (* Compute (X - Y*yScale)*zScalar on sub array*) function SubAndMul(const X: TMtxVec; xIndex: Integer; const Y: TMtxVec; yIndex: Integer; const yScale, Z: TCplx; Index, Len: Integer): TMtxVec; overload; (* Compute (X - yScalar)*Z*zScale *) function SubAndMul(const X: TMtxVec; const Y: Double; const Z: TMtxVec; const zScale: Double): TMtxVec; overload; (* Compute (X - yScalar)*Z*zScale *) function SubAndMul(const X: TMtxVec; const Y: TCplx; const Z: TMtxVec; const zScale: TCplx): TMtxVec; overload; (* Compute (X - yScalar)*Z*zScale on sub-array*) function SubAndMul(const X: TMtxVec; xIndex: integer; const Y: Double; const Z: TMtxVec; zIndex: integer; const zScale: Double; Index, Len: integer): TMtxVec; overload; (* Compute (X - yScalar)*Z*zScale on sub-array*) function SubAndMul(const X: TMtxVec; xIndex: integer; const Y: TCplx; const Z: TMtxVec; zIndex: integer; const zScale: TCplx; Index, Len: integer): TMtxVec; overload; (* Compute (X*xScale - yScalar)*Z *) function SubAndMul(const X: TMtxVec; const xScale, Y: Double; const Z: TMtxVec): TMtxVec; overload; (* Compute (X*xScale - yScalar)*Z *) function SubAndMul(const X: TMtxVec; const xScale, Y: TCplx; const Z: TMtxVec): TMtxVec; overload; (* Compute (X*xScale - yScalar)*Z on sub-array*) function SubAndMul(const X: TMtxVec; xIndex: integer; const xScale, Y: Double; const Z: TMtxVec; zIndex: integer; Index, Len: integer): TMtxVec; overload; (* Compute (X*xScale - yScalar)*Z on sub-array*) function SubAndMul(const X: TMtxVec; xIndex: integer; const xScale, Y: TCplx; const Z: TMtxVec; zIndex: integer; Index, Len: integer): TMtxVec; overload; (* Compute (X - yScalar)*Z *) function SubAndMul(const X: TMtxVec; const Y: Double; const Z: TMtxVec): TMtxVec; overload; (* Compute (X - yScalar)*Z *) function SubAndMul(const X: TMtxVec; const Y: TCplx; const Z: TMtxVec): TMtxVec; overload; (* Compute (X - yScalar)*Z on sub-array*) function SubAndMul(const X: TMtxVec; xIndex: integer; const Y: Double; const Z: TMtxVec; zIndex: integer; Index, Len: integer): TMtxVec; overload; (* Compute (X - yScalar)*Z on sub-array*) function SubAndMul(const X: TMtxVec; xIndex: integer; const Y: TCplx; const Z: TMtxVec; zIndex: integer; Index, Len: integer): TMtxVec; overload; (* Compute (X - yScalar)*zScalar *) function SubAndMul(const X: TMtxVec; const Y, Z: Double): TMtxVec; overload; (* Compute (X - yScalar)*zScalar *) function SubAndMul(const X: TMtxVec; const Y, Z: TCplx): TMtxVec; overload; (* Compute (X - yScalar)*zScalar on sub-array*) function SubAndMul(const X: TMtxVec; xIndex: integer; const Y, Z: Double; Index, Len: integer): TMtxVec; overload; (* Compute (X - yScalar)*zScalar on sub-array*) function SubAndMul(const X: TMtxVec; xIndex: integer; const Y, Z: TCplx; Index, Len: integer): TMtxVec; overload; (* Compute X*Y + Z *) function MulAndAdd(const X, Y, Z: TMtxVec): TMtxVec; overload; (* Compute X*Y + Z on sub array*) function MulAndAdd(const X: TMtxVec; xIndex: Integer; const Y: TMtxVec; yIndex: Integer; const Z: TMtxVec; zIndex: Integer; Index, Len: Integer): TMtxVec; overload; (* Compute X*Y*xyScale + Z *) function MulAndAdd(const X, Y: TMtxVec; const xyScale: double; const Z: TMtxVec): TMtxVec; overload; (* Compute X*Y*xyScale + Z *) function MulAndAdd(const X, Y: TMtxVec; const xyScale: TCplx; const Z: TMtxVec): TMtxVec; overload; (* Compute X*Y*xyScale + Z on sub array*) function MulAndAdd(const X: TMtxVec; xIndex: Integer; const Y: TMtxVec; yIndex: Integer; const xyScale: double; const Z: TMtxVec; zIndex: Integer; Index, Len: Integer): TMtxVec; overload; (* Compute X*Y*xyScale + Z on sub array*) function MulAndAdd(const X: TMtxVec; xIndex: Integer; const Y: TMtxVec; yIndex: Integer; const xyScale: TCplx; const Z: TMtxVec; zIndex: Integer; Index, Len: Integer): TMtxVec; overload; (* Compute X*Y + Z*zScale *) function MulAndAdd(const X, Y, Z: TMtxVec; const zScale: double): TMtxVec; overload; (* Compute X*Y + Z*zScale *) function MulAndAdd(const X, Y, Z: TMtxVec; const zScale: TCplx): TMtxVec; overload; (* Compute X*Y + Z*zScale on sub array*) function MulAndAdd(const X: TMtxVec; xIndex: Integer; const Y: TMtxVec; yIndex: Integer; const Z: TMtxVec; zIndex: Integer; const zScale: double; Index, Len: Integer): TMtxVec; overload; (* Compute X*Y + Z*zScale on sub array*) function MulAndAdd(const X: TMtxVec; xIndex: Integer; const Y: TMtxVec; yIndex: Integer; const Z: TMtxVec; zIndex: Integer; const zScale: TCplx; Index, Len: Integer): TMtxVec; overload; (* Compute X*Y + zScalar *) function MulAndAdd(const X, Y: TMtxVec; const Z: Double): TMtxVec; overload; (* Compute X*Y + zScalar *) function MulAndAdd(const X, Y: TMtxVec; const Z: TCplx): TMtxVec; overload; (* Compute X*Y + zScalar on sub array*) function MulAndAdd(const X: TMtxVec; xIndex: Integer; const Y: TMtxVec; yIndex: Integer; const Z: Double; Index, Len: Integer): TMtxVec; overload; (* Compute X*Y + zScalar on sub array*) function MulAndAdd(const X: TMtxVec; xIndex: Integer; const Y: TMtxVec; yIndex: Integer; const Z: TCplx; Index, Len: Integer): TMtxVec; overload; (* Compute X*Y - Z *) function MulAndSub(const X, Y, Z: TMtxVec): TMtxVec; overload; (* Compute X*Y + Z on sub array*) function MulAndSub(const X: TMtxVec; xIndex: Integer; const Y: TMtxVec; yIndex: Integer; const Z: TMtxVec; zIndex: Integer; Index, Len: Integer): TMtxVec; overload; (* Compute X*Y*xyScale - Z *) function MulAndSub(const X, Y: TMtxVec; const xyScale: double; const Z: TMtxVec): TMtxVec; overload; (* Compute X*Y*xyScale - Z *) function MulAndSub(const X, Y: TMtxVec; const xyScale: TCplx; const Z: TMtxVec): TMtxVec; overload; (* Compute X*Y*xyScale + Z on sub array*) function MulAndSub(const X: TMtxVec; xIndex: Integer; const Y: TMtxVec; yIndex: Integer; const xyScale: double; const Z: TMtxVec; zIndex: Integer; Index, Len: Integer): TMtxVec; overload; (* Compute X*Y*xyScale + Z on sub array*) function MulAndSub(const X: TMtxVec; xIndex: Integer; const Y: TMtxVec; yIndex: Integer; const xyScale: TCplx; const Z: TMtxVec; zIndex: Integer; Index, Len: Integer): TMtxVec; overload; (* Compute X*Y - Z*zScale *) function MulAndSub(const X, Y, Z: TMtxVec; const zScale: double): TMtxVec; overload; (* Compute X*Y - Z*zScale *) function MulAndSub(const X, Y, Z: TMtxVec; const zScale: TCplx): TMtxVec; overload; (* Compute X*Y + Z*zScale on sub array*) function MulAndSub(const X: TMtxVec; xIndex: Integer; const Y: TMtxVec; yIndex: Integer; const Z: TMtxVec; zIndex: Integer; const zScale: double; Index, Len: Integer): TMtxVec; overload; (* Compute X*Y + Z*zScale on sub array*) function MulAndSub(const X: TMtxVec; xIndex: Integer; const Y: TMtxVec; yIndex: Integer; const Z: TMtxVec; zIndex: Integer; const zScale: TCplx; Index, Len: Integer): TMtxVec; overload; (* Compute X*Y - zScalar *) function MulAndSub(const X, Y: TMtxVec; const Z: Double): TMtxVec; overload; (* Compute X*Y - zScalar *) function MulAndSub(const X, Y: TMtxVec; const Z: TCplx): TMtxVec; overload; (* Compute X*Y - zScalar on sub array*) function MulAndSub(const X: TMtxVec; xIndex: Integer; const Y: TMtxVec; yIndex: Integer; const Z: Double; Index, Len: Integer): TMtxVec; overload; (* Compute X*Y - zScalar on sub array*) function MulAndSub(const X: TMtxVec; xIndex: Integer; const Y: TMtxVec; yIndex: Integer; const Z: TCplx; Index, Len: Integer): TMtxVec; overload; (* Compute X/Y + Z *) function DivAndAdd(const X, Y, Z: TMtxVec): TMtxVec; overload; (* Compute X/Y + Z on sub array*) function DivAndAdd(const X: TMtxVec; xIndex: Integer; const Y: TMtxVec; yIndex: Integer; const Z: TMtxVec; zIndex: Integer; Index, Len: Integer): TMtxVec; overload; (* Compute X/Y*xyScale + Z *) function DivAndAdd(const X, Y: TMtxVec; const xyScale: double; const Z: TMtxVec): TMtxVec; overload; (* Compute X/Y*xyScale + Z *) function DivAndAdd(const X, Y: TMtxVec; const xyScale: TCplx; const Z: TMtxVec): TMtxVec; overload; (* Compute X/Y*xyScale + Z on sub array*) function DivAndAdd(const X: TMtxVec; xIndex: Integer; const Y: TMtxVec; yIndex: Integer; const xyScale: double; const Z: TMtxVec; zIndex: Integer; Index, Len: Integer): TMtxVec; overload; (* Compute X/Y*xyScale + Z on sub array*) function DivAndAdd(const X: TMtxVec; xIndex: Integer; const Y: TMtxVec; yIndex: Integer; const xyScale: TCplx; const Z: TMtxVec; zIndex: Integer; Index, Len: Integer): TMtxVec; overload; (* Compute X/Y + Z*zScale *) function DivAndAdd(const X, Y, Z: TMtxVec; const zScale: double): TMtxVec; overload; (* Compute X/Y + Z*zScale *) function DivAndAdd(const X, Y, Z: TMtxVec; const zScale: TCplx): TMtxVec; overload; (* Compute X/Y + Z*zScale on sub array*) function DivAndAdd(const X: TMtxVec; xIndex: Integer; const Y: TMtxVec; yIndex: Integer; const Z: TMtxVec; zIndex: Integer; const zScale: double; Index, Len: Integer): TMtxVec; overload; (* Compute X/Y + Z*zScale on sub array*) function DivAndAdd(const X: TMtxVec; xIndex: Integer; const Y: TMtxVec; yIndex: Integer; const Z: TMtxVec; zIndex: Integer; const zScale: TCplx; Index, Len: Integer): TMtxVec; overload; (* Compute X/Y + zScalar *) function DivAndAdd(const X, Y: TMtxVec; const Z: Double): TMtxVec; overload; (* Compute X/Y + zScalar *) function DivAndAdd(const X, Y: TMtxVec; const Z: TCplx): TMtxVec; overload; (* Compute X/Y + zScalar on sub array*) function DivAndAdd(const X: TMtxVec; xIndex: Integer; const Y: TMtxVec; yIndex: Integer; const Z: Double; Index, Len: Integer): TMtxVec; overload; (* Compute X/Y + zScalar on sub array*) function DivAndAdd(const X: TMtxVec; xIndex: Integer; const Y: TMtxVec; yIndex: Integer; const Z: TCplx; Index, Len: Integer): TMtxVec; overload; (* Compute X/Y - Z *) function DivAndSub(const X, Y, Z: TMtxVec): TMtxVec; overload; (* Compute X/Y - Z on sub array*) function DivAndSub(const X: TMtxVec; xIndex: Integer; const Y: TMtxVec; yIndex: Integer; const Z: TMtxVec; zIndex: Integer; Index, Len: Integer): TMtxVec; overload; (* Compute X/Y*xyScale - Z *) function DivAndSub(const X, Y: TMtxVec; const xyScale: double; const Z: TMtxVec): TMtxVec; overload; (* Compute X/Y*xyScale - Z *) function DivAndSub(const X, Y: TMtxVec; const xyScale: TCplx; const Z: TMtxVec): TMtxVec; overload; (* Compute X/Y*xyScale - Z on sub array*) function DivAndSub(const X: TMtxVec; xIndex: Integer; const Y: TMtxVec; yIndex: Integer; const xyScale: double; const Z: TMtxVec; zIndex: Integer; Index, Len: Integer): TMtxVec; overload; (* Compute X/Y*xyScale - Z on sub array*) function DivAndSub(const X: TMtxVec; xIndex: Integer; const Y: TMtxVec; yIndex: Integer; const xyScale: TCplx; const Z: TMtxVec; zIndex: Integer; Index, Len: Integer): TMtxVec; overload; (* Compute X/Y - Z*zScale *) function DivAndSub(const X, Y, Z: TMtxVec; const zScale: double): TMtxVec; overload; (* Compute X/Y - Z*zScale *) function DivAndSub(const X, Y, Z: TMtxVec; const zScale: TCplx): TMtxVec; overload; (* Compute X/Y - Z*zScale on sub array*) function DivAndSub(const X: TMtxVec; xIndex: Integer; const Y: TMtxVec; yIndex: Integer; const Z: TMtxVec; zIndex: Integer; const zScale: double; Index, Len: Integer): TMtxVec; overload; (* Compute X/Y - Z*zScale on sub array*) function DivAndSub(const X: TMtxVec; xIndex: Integer; const Y: TMtxVec; yIndex: Integer; const Z: TMtxVec; zIndex: Integer; const zScale: TCplx; Index, Len: Integer): TMtxVec; overload; (* Compute X/Y - zScalar *) function DivAndSub(const X, Y: TMtxVec; const Z: Double): TMtxVec; overload; (* Compute X/Y - zScalar *) function DivAndSub(const X, Y: TMtxVec; const Z: TCplx): TMtxVec; overload; (* Compute X/Y - zScalar on sub array*) function DivAndSub(const X: TMtxVec; xIndex: Integer; const Y: TMtxVec; yIndex: Integer; const Z: Double; Index, Len: Integer): TMtxVec; overload; (* Compute X/Y - zScalar on sub array*) function DivAndSub(const X: TMtxVec; xIndex: Integer; const Y: TMtxVec; yIndex: Integer; const Z: TCplx; Index, Len: Integer): TMtxVec; overload; (* Compute X*xScale + Y*yScale *) function AddScaled(const X: TMtxVec; const xScale: Double; const Y: TMtxVec; const yScale: Double): TMtxVec; overload; (* Compute X*xScale + Y*yScale *) function AddScaled(const X: TMtxVec; const xScale: TCplx; const Y: TMtxVec; const yScale: TCplx): TMtxVec; overload; (* Compute X*xScale + Y*yScale on sub arrays *) function AddScaled(const X: TMtxVec; xIndex: integer; const xScale: Double; const Y: TMtxVec; yIndex: integer; const yScale: Double; Index, Len: integer): TMtxVec; overload; (* Compute X*xScale + Y*yScale on sub arrays *) function AddScaled(const X: TMtxVec; xIndex: integer; const xScale: TCplx; const Y: TMtxVec; yIndex: integer; const yScale: TCplx; Index, Len: integer): TMtxVec; overload; (* Compute sqr(X*xScale + Y*yScale) *) function AddScaledSqr(const X: TMtxVec; const xScale: Double; const Y: TMtxVec; const yScale: Double): TMtxVec; overload; (* Compute sqr(X*xScale + Y*yScale) *) function AddScaledSqr(const X: TMtxVec; const xScale: TCplx; const Y: TMtxVec; const yScale: TCplx): TMtxVec; overload; (* Compute sqr(X*xScale + Y*yScale) on sub arrays *) function AddScaledSqr(const X: TMtxVec; xIndex: integer; const xScale: Double; const Y: TMtxVec; yIndex: integer; const yScale: Double; Index, Len: integer): TMtxVec; overload; (* Compute sqr(X*xScale + Y*yScale) on sub arrays *) function AddScaledSqr(const X: TMtxVec; xIndex: integer; const xScale: TCplx; const Y: TMtxVec; yIndex: integer; const yScale: TCplx; Index, Len: integer): TMtxVec; overload; (* Compute sqr(X)*xScale + sqr(Y)*yScale *) function SqrAddScaled(const X: TMtxVec; const xScale: Double; const Y: TMtxVec; const yScale: Double): TMtxVec; overload; (* Compute sqr(X)*xScale + sqr(Y)*yScale *) function SqrAddScaled(const X: TMtxVec; const xScale: TCplx; const Y: TMtxVec; const yScale: TCplx): TMtxVec; overload; (* Compute sqr(X)*xScale + sqr(Y)*yScale on sub arrays *) function SqrAddScaled(const X: TMtxVec; xIndex: integer; const xScale: Double; const Y: TMtxVec; yIndex: integer; const yScale: Double; Index, Len: integer): TMtxVec; overload; (* Compute sqr(X)*xScale + sqr(Y)*yScale on sub arrays *) function SqrAddScaled(const X: TMtxVec; xIndex: integer; const xScale: TCplx; const Y: TMtxVec; yIndex: integer; const yScale: TCplx; Index, Len: integer): TMtxVec; overload; (* Compute X*xScale + Y*yScale + Z*zScale *) function AddScaled(const X: TMtxVec; const xScale: Double; const Y: TMtxVec; const yScale: Double; const Z: TMtxVec; const zScale: Double): TMtxVec; overload; (* Compute X*xScale + Y*yScale + Z*zScale *) function AddScaled(const X: TMtxVec; const xScale: TCplx; const Y: TMtxVec; const yScale: TCplx; const Z: TMtxVec; const zScale: TCplx): TMtxVec; overload; (* Compute X*xScale + Y*yScale + Z*zScale on sub arrays *) function AddScaled(const X: TMtxVec; xIndex: integer; const xScale: Double; const Y: TMtxVec; yIndex: integer; const yScale: Double; const Z: TMtxVec; zIndex: integer; const zScale: Double; Index, Len: integer): TMtxVec; overload; (* Compute X*xScale + Y*yScale + Z*zScale on sub arrays *) function AddScaled(const X: TMtxVec; xIndex: integer; const xScale: TCplx; const Y: TMtxVec; yIndex: integer; const yScale: TCplx; const Z: TMtxVec; zIndex: integer; const zScale: TCplx; Index, Len: integer): TMtxVec; overload; (* Compute X*xScale + Y*yScale + zScalar *) function AddScaledC(const X: TMtxVec; const xScale: Double; const Y: TMtxVec; const yScale: Double; const Z: Double): TMtxVec; overload; (* Compute X*xScale + Y*yScale + zScalar *) function AddScaledC(const X: TMtxVec; const xScale: TCplx; const Y: TMtxVec; const yScale: TCplx; const Z: TCplx): TMtxVec; overload; (* Compute X*xScale + Y*yScale + z on sub arrays *) function AddScaledC(const X: TMtxVec; xIndex: integer; const xScale: Double; const Y: TMtxVec; yIndex: integer; const yScale: Double; const Z: Double; Index, Len: integer): TMtxVec; overload; (* Compute X*xScale + Y*yScale + z on sub arrays *) function AddScaledC(const X: TMtxVec; xIndex: integer; const xScale: TCplx; const Y: TMtxVec; yIndex: integer; const yScale: TCplx; const Z: TCplx; Index, Len: integer): TMtxVec; overload; (* Compute X*xScale - Y*yScale - Z*zScale *) function SubScaled(const X: TMtxVec; const xScale: Double; const Y: TMtxVec; const yScale: Double; const Z: TMtxVec; const zScale: Double): TMtxVec; overload; (* Compute X*xScale - Y*yScale - Z*zScale *) function SubScaled(const X: TMtxVec; const xScale: TCplx; const Y: TMtxVec; const yScale: TCplx; const Z: TMtxVec; const zScale: TCplx): TMtxVec; overload; (* Compute X*xScale - Y*yScale - zScalar *) function SubScaledC(const X: TMtxVec; const xScale: Double; const Y: TMtxVec; const yScale: Double; const Z: Double): TMtxVec; overload; (* Compute X*xScale - Y*yScale - zScalar *) function SubScaledC(const X: TMtxVec; const xScale: TCplx; const Y: TMtxVec; const yScale: TCplx; const Z: TCplx): TMtxVec; overload; (* Compute X*xScale - Y*yScale - Z*zScale on sub array*) function SubScaled(const X: TMtxVec; xIndex: integer; const xScale: Double; const Y: TMtxVec; yIndex: integer; const yScale: Double; const Z: TMtxVec; zIndex: integer; const zScale: Double; Index, Len: integer): TMtxVec; overload; (* Compute X*xScale - Y*yScale - Z*zScale on sub array*) function SubScaled(const X: TMtxVec; xIndex: integer; const xScale: TCplx; const Y: TMtxVec; yIndex: integer; const yScale: TCplx; const Z: TMtxVec; zIndex: integer; const zScale: TCplx; Index, Len: integer): TMtxVec; overload; (* Compute X*xScale - Y*yScale - zScalar on sub array*) function SubScaledC(const X: TMtxVec; xIndex: integer; const xScale: Double; const Y: TMtxVec; yIndex: integer; const yScale: Double; const Z: Double; Index, Len: integer): TMtxVec; overload; (* Compute X*xScale - Y*yScale - zScalar on sub array*) function SubScaledC(const X: TMtxVec; xIndex: integer; const xScale: TCplx; const Y: TMtxVec; yIndex: integer; const yScale: TCplx; const Z: TCplx; Index, Len: integer): TMtxVec; overload; (* Compute X*Y*Z The following expression would also run at the same or higher speed, when passing X also for the Z parameter: X^2*Y *) function MulElem(const X, Y,Z: TMtxVec): TMtxVec; overload; (* Compute X*Y*zScalar The following expression would also run at the same or higher speed, when passing X also for the Z parameter: X^2*zScalar *) function MulElem(const X,Y: TMtxVec; const Z: Double): TMtxVec; overload; (* Compute X*Y*zScalar The following expression would also run at the same or higher speed, when passing X also for the Z parameter: X^2*zScalar *) function MulElem(const X,Y: TMtxVec; const Z: TCplx): TMtxVec; overload; (* Compute X*Y*Z on sub array*) function MulElem(const X: TMtxVec; xIndex: integer; const Y: TMtxVec; yIndex: integer; const Z: TMtxVec; zIndex: integer; Index, Len: integer): TMtxVec; overload; (* Compute X*Y*zScalar on sub array*) function MulElem(const X: TMtxVec; xIndex: integer; const Y: TMtxVec; yIndex: integer; const Z: Double; Index, Len: integer): TMtxVec; overload; (* Compute X*Y*zScalar on sub array*) function MulElem(const X: TMtxVec; xIndex: integer; const Y: TMtxVec; yIndex: integer; const Z: TCplx; Index, Len: integer): TMtxVec; overload; (* Compute X / (Y*Z) The following expression would also run at the same or higher speed, when passing Y also for the Z parameter: X / (Y^2) *) function Divide(const X, Y, Z: TMtxVec): TMtxVec; overload; (* Compute X/( Y*Z ) on sub array*) function Divide(const X: TMtxVec; xIndex: integer; const Y: TMtxVec; yIndex: integer; const Z: TMtxVec; zIndex: integer; Index, Len: integer): TMtxVec; overload; (* Compute X / (Y*zScale) *) function DivideC(const X, Y: TMtxVec; const Z: Double): TMtxVec; overload; (* Compute X / (Y*zScale) *) function DivideC(const X, Y: TMtxVec; const Z: TCplx): TMtxVec; overload; (* Compute X / (Y*zScalar) on sub array*) function DivideC(const X: TMtxVec; xIndex: integer; const Y: TMtxVec; yIndex: integer; const Z: Double; Index, Len: integer): TMtxVec; overload; (* Compute X / (Y*zScalar) on sub array*) function DivideC(const X: TMtxVec; xIndex: integer; const Y: TMtxVec; yIndex: integer; const Z: TCplx; Index, Len: integer): TMtxVec; overload; (* Compute X * Y * xyScale / Z The following expression would also run at the same or higher speed, when passing X also for the Y parameter: X^2 * xyScale/ Z *) function MulAndDiv(const X, Y: TMtxVec; const xyScale: Double; const Z: TMtxVec): TMtxVec; overload; (* Compute X * Y * xyScale / Z The following expression would also run at the same or higher speed, when passing X also for the Y parameter: X^2 * xyScale/ Z *) function MulAndDiv(const X, Y: TMtxVec; const xyScale: TCplx; const Z: TMtxVec): TMtxVec; overload; (* Compute X * Y * xyScale / Z on sub array*) function MulAndDiv(const X: TMtxVec; xIndex: integer; const Y: TMtxVec; yIndex: integer; const xyScale: Double; const Z: TMtxVec; zIndex: integer; Index, Len: integer): TMtxVec; overload; (* Compute X * Y * xyScale / Z on sub array*) function MulAndDiv(const X: TMtxVec; xIndex: integer; const Y: TMtxVec; yIndex: integer; const xyScale: TCplx; const Z: TMtxVec; zIndex: integer; Index, Len: integer): TMtxVec; overload; (* Compute X * Y / zScalar *) function MulAndDiv(const X, Y: TMtxVec; const Z: Double): TMtxVec; overload; (* Compute X * Y / zScalar *) function MulAndDiv(const X, Y: TMtxVec; const Z: TCplx): TMtxVec; overload; (* Compute X * Y / zScalar on sub array*) function MulAndDiv(const X: TMtxVec; xIndex: integer; const Y: TMtxVec; yIndex: integer; const Z: Double; Index, Len: integer): TMtxVec; overload; (* Compute X * Y / zScalar on sub array*) function MulAndDiv(const X: TMtxVec; xIndex: integer; const Y: TMtxVec; yIndex: integer; const Z: TCplx; Index, Len: integer): TMtxVec; overload; (* Compute xScalar / (Y*Z) *) function Divide(const X: Double; const Y, Z: TMtxVec): TMtxVec; overload; (* Compute xScalar / (Y*Z) *) function Divide(const X: TCplx; const Y, Z: TMtxVec): TMtxVec; overload; (* Compute xScalar / (Y*Z) on sub array*) function Divide(const X: Double; const Y: TMtxVec; yIndex: integer; const Z: TMtxVec; zIndex: integer; Index, Len: integer): TMtxVec; overload; (* Compute xScalar / (Y*Z) on sub array*) function Divide(const X: TCplx; const Y: TMtxVec; yIndex: integer; const Z: TMtxVec; zIndex: integer; Index, Len: integer): TMtxVec; overload; (* Compute (X*xScale + Y*yScale)*Z*zScale The following is also possible at the same or higher speed: X^2 * xScale + XY * yScale by passing X also for the Z parameter. *) function AddAndMul(const X: TMtxVec; const xScale: Double; const Y: TMtxVec; const yScale: Double; const Z: TMtxVec; const zScale: Double): TMtxVec; overload; (* Compute (X*xScale + Y*yScale)*Z*zScale The following is also possible at the same or higher speed: X^2 * xScale + XY * yScale by passing X also for the Z parameter. *) function AddAndMul(const X: TMtxVec; const xScale: TCplx; const Y: TMtxVec; const yScale: TCplx; const Z: TMtxVec; const zScale: TCplx): TMtxVec; overload; (* Compute (X*xScale + Y*yScale)*Z*Scale on sub array*) function AddAndMul(const X: TMtxVec; xIndex: Integer; const xScale: Double; const Y: TMtxVec; yIndex: Integer; const yScale: Double; const Z: TMtxVec; zIndex: Integer; const zScale: Double; Index, Len: Integer): TMtxVec; overload; (* Compute (X*xScale + Y*yScale)*Z*Scale on sub array*) function AddAndMul(const X: TMtxVec; xIndex: Integer; const xScale: TCplx; const Y: TMtxVec; yIndex: Integer; const yScale: TCplx; const Z: TMtxVec; zIndex: Integer; const zScale: TCplx; Index, Len: Integer): TMtxVec; overload; (* Compute (X*xScale + Y*yScale)*zScalar*) function AddAndMul(const X: TMtxVec; const xScale: Double; const Y: TMtxVec; const yScale: Double; const Z: Double): TMtxVec; overload; (* Compute (X*xScale + Y*yScale)*zScalar*) function AddAndMul(const X: TMtxVec; const xScale: TCplx; const Y: TMtxVec; const yScale: TCplx; const Z: TCplx): TMtxVec; overload; (* Compute (X*xScale + Y*yScale)*zScalar on sub array*) function AddAndMul(const X: TMtxVec; xIndex: Integer; const xScale: Double; const Y: TMtxVec; yIndex: Integer; const yScale: Double; const Z: Double; Index, Len: Integer): TMtxVec; overload; (* Compute (X*xScale + Y*yScale)*zScalar on sub array*) function AddAndMul(const X: TMtxVec; xIndex: Integer; const xScale: TCplx; const Y: TMtxVec; yIndex: Integer; const yScale: TCplx; const Z: TCplx; Index, Len: Integer): TMtxVec; overload; (* Compute (X* xScale + yScalar)*Z*zScale*) function AddAndMul(const X: TMtxVec; const xScale: Double; const Y: Double; const Z: TMtxVec; const zScale: Double): TMtxVec; overload; (* Compute (X* xScale + yScalar)*Z*zScale*) function AddAndMul(const X: TMtxVec; const xScale: TCplx; const Y: TCplx; const Z: TMtxVec; const zScale: TCplx): TMtxVec; overload; (* Compute (X* xScale + yScalar)*Z*zScale on sub-array*) function AddAndMul(const X: TMtxVec; xIndex: integer; const xScale: Double; const Y: Double; const Z: TMtxVec; zIndex: integer; const zScale: Double; Index, Len: integer): TMtxVec; overload; (* Compute (X* xScale + yScalar)*Z*zScale on sub-array*) function AddAndMul(const X: TMtxVec; xIndex: integer; const xScale: TCplx; const Y: TCplx; const Z: TMtxVec; zIndex: integer; const zScale: TCplx; Index, Len: integer): TMtxVec; overload; (* Compute (X*xScale + yScalar)*zScalar*) function AddAndMul(const X: TMtxVec; const xScale: Double; const Y, Z: Double): TMtxVec; overload; (* Compute (X*xScale + yScalar)*zScalar*) function AddAndMul(const X: TMtxVec; const xScale: TCplx; const Y, Z: TCplx): TMtxVec; overload; (* Compute (X*xScale + yScalar)*zScalar on sub array*) function AddAndMul(const X: TMtxVec; xIndex: integer; const xScale: Double; const Y, Z: Double; Index, Len: integer): TMtxVec; overload; (* Compute (X*xScale + yScalar)*zScalar on sub array*) function AddAndMul(const X: TMtxVec; xIndex: integer; const xScale: TCplx; const Y, Z: TCplx; Index, Len: integer): TMtxVec; overload; (* Compute (X*xScale - Y*yScale)*Z*zScale*) function SubAndMul(const X: TMtxVec; const xScale: Double; const Y: TMtxVec; const yScale: Double; const Z: TMtxVec; const zScale: Double): TMtxVec; overload; (* Compute (X*xScale - Y*yScale)*Z*zScale*) function SubAndMul(const X: TMtxVec; const xScale: TCplx; const Y: TMtxVec; const yScale: TCplx; const Z: TMtxVec; const zScale: TCplx): TMtxVec; overload; (* Compute (X*xScale - Y*yScale)*Z*Scale on sub array*) function SubAndMul(const X: TMtxVec; xIndex: Integer; const xScale: Double; const Y: TMtxVec; yIndex: Integer; const yScale: Double; const Z: TMtxVec; zIndex: Integer; const zScale: Double; Index, Len: Integer): TMtxVec; overload; (* Compute (X*xScale - Y*yScale)*Z*Scale on sub array*) function SubAndMul(const X: TMtxVec; xIndex: Integer; const xScale: TCplx; const Y: TMtxVec; yIndex: Integer; const yScale: TCplx; const Z: TMtxVec; zIndex: Integer; const zScale: TCplx; Index, Len: Integer): TMtxVec; overload; (* Compute (X*xScale - Y*yScale)*zScalar*) function SubAndMul(const X: TMtxVec; const xScale: Double; const Y: TMtxVec; const yScale: Double; const Z: Double): TMtxVec; overload; (* Compute (X*xScale - Y*yScale)*zScalar*) function SubAndMul(const X: TMtxVec; const xScale: TCplx; const Y: TMtxVec; const yScale: TCplx; const Z: TCplx): TMtxVec; overload; (* Compute (X*xScale - Y*yScale)*zScalar on sub array*) function SubAndMul(const X: TMtxVec; xIndex: Integer; const xScale: Double; const Y: TMtxVec; yIndex: Integer; const yScale: Double; const Z: Double; Index, Len: Integer): TMtxVec; overload; (* Compute (X*xScale - Y*yScale)*zScalar on sub array*) function SubAndMul(const X: TMtxVec; xIndex: Integer; const xScale: TCplx; const Y: TMtxVec; yIndex: Integer; const yScale: TCplx; const Z: TCplx; Index, Len: Integer): TMtxVec; overload; (* Compute (X*xScale - yScalar)*Z*zScale*) function SubAndMul(const X: TMtxVec; const xScale: Double; const Y: Double; const Z: TMtxVec; const zScale: Double): TMtxVec; overload; (* Compute (X*xScale - yScalar)*Z*zScale*) function SubAndMul(const X: TMtxVec; const xScale: TCplx; const Y: TCplx; const Z: TMtxVec; const zScale: TCplx): TMtxVec; overload; (* Compute (X*xScale - yScalar)*Z*zScale on sub-array*) function SubAndMul(const X: TMtxVec; xIndex: integer; const xScale: Double; const Y: Double; const Z: TMtxVec; zIndex: integer; const zScale: Double; Index, Len: integer): TMtxVec; overload; (* Compute (X*xScale - yScalar)*Z*zScale on sub-array*) function SubAndMul(const X: TMtxVec; xIndex: integer; const xScale: TCplx; const Y: TCplx; const Z: TMtxVec; zIndex: integer; const zScale: TCplx; Index, Len: integer): TMtxVec; overload; (* Compute (X*xScale - yScalar)*zScalar*) function SubAndMul(const X: TMtxVec; const xScale: Double; const Y, Z: Double): TMtxVec; overload; (* Compute (X*xScale - yScalar)*zScalar*) function SubAndMul(const X: TMtxVec; const xScale: TCplx; const Y, Z: TCplx): TMtxVec; overload; (* Compute (X*xScale - yScalar)*zScalar on sub array*) function SubAndMul(const X: TMtxVec; xIndex: integer; const xScale: Double; const Y, Z: Double; Index, Len: integer): TMtxVec; overload; (* Compute (X*xScale - yScalar)*zScalar on sub array*) function SubAndMul(const X: TMtxVec; xIndex: integer; const xScale: TCplx; const Y, Z: TCplx; Index, Len: integer): TMtxVec; overload; (* Compute (X*Y)*xyScale + Z*zScale The following expression would also run at the same or higher speed, when passing X also for the Y parameter: X^2*xyScale + Z*zScale *) function MulAndAdd(const X: TMtxVec; const Y: TMtxVec; const xyScale: Double; const Z: TMtxVec; const zScale: Double): TMtxVec; overload; (* Compute (X*Y)*xyScale + Z*zScale on sub array*) function MulAndAdd(const X: TMtxVec; xIndex: Integer; const Y: TMtxVec; yIndex: Integer; const xyScale: Double; const Z: TMtxVec; zIndex: Integer; const zScale: Double; Index, Len: Integer): TMtxVec; overload; (* Compute (X*Y)*xyScale + Z*zScale The following expression would also run at the same or higher speed, when passing X also for the Y parameter: X^2*xyScale + Z*zScale *) function MulAndAdd(const X: TMtxVec; const Y: TMtxVec; const xyScale: TCplx; const Z: TMtxVec; const zScale: TCplx): TMtxVec; overload; (* Compute (X*Y)*xyScale + Z*zScale on sub array*) function MulAndAdd(const X: TMtxVec; xIndex: Integer; const Y: TMtxVec; yIndex: Integer; const xyScale: TCplx; const Z: TMtxVec; zIndex: Integer;const zScale: TCplx; Index, Len: Integer): TMtxVec; overload; (* Compute (X*Y)*xyScale + zScalar*) function MulAndAdd(const X: TMtxVec; const Y: TMtxVec; const xyScale: Double; const Z: Double): TMtxVec; overload; (* Compute (X*Y)*xyScale + zScalar on sub array The following expression would also run at the same or higher speed, when passing X also for the Y parameter: X^2*xyScale + zScale *) function MulAndAdd(const X: TMtxVec; xIndex: Integer; const Y: TMtxVec; yIndex: Integer; const xyScale: Double; const Z: Double; Index, Len: Integer): TMtxVec; overload; (* Compute (X*Y)*xyScale + zScalar*) function MulAndAdd(const X: TMtxVec; const Y: TMtxVec; const xyScale: TCplx; const Z: TCplx): TMtxVec; overload; (* Compute (X*Y)*xyScale + zScalar on sub array The following expression would also run at the same or higher speed, when passing X also for the Y parameter: X^2*xyScale + zScale *) function MulAndAdd(const X: TMtxVec; xIndex: Integer; const Y: TMtxVec; yIndex: Integer; const xyScale: TCplx; const Z: TCplx; Index, Len: Integer): TMtxVec; overload; (* Compute (X*yScalar) + zScalar*) function MulAndAdd(const X: TMtxVec; const Y, Z: Double): TMtxVec; overload; (* Compute (X*yScalar) + zScalar*) function MulAndAdd(const X: TMtxVec; xIndex: integer; const Y, Z: Double; Index, Len: integer): TMtxVec; overload; (* Compute (X*yScalar) + zScalar*) function MulAndAdd(const X: TMtxVec; const Y, Z: TCplx): TMtxVec; overload; (* Compute (X*yScalar) + zScalar*) function MulAndAdd(const X: TMtxVec; xIndex: integer; const Y, Z: TCplx; Index, Len: integer): TMtxVec; overload; (* Compute (X*Y)*xyScale - Z*zScale*) function MulAndSub(const X: TMtxVec; const Y: TMtxVec; const xyScale: Double; const Z: TMtxVec; const zScale: Double): TMtxVec; overload; (* Compute (X*Y)*xyScale - Z*zScale*) function MulAndSub(const X: TMtxVec; const Y: TMtxVec; const xyScale: TCplx; const Z: TMtxVec; const zScale: TCplx): TMtxVec; overload; (* Compute (X*Y)*xyScale - Z*zScale on sub array*) function MulAndSub(const X: TMtxVec; xIndex: Integer; const Y: TMtxVec; yIndex: Integer; const xyScale: Double; const Z: TMtxVec; zIndex: Integer; const zScale: Double; Index, Len: Integer): TMtxVec; overload; (* Compute (X*Y)*xyScale - Z*zScale on sub array*) function MulAndSub(const X: TMtxVec; xIndex: Integer; const Y: TMtxVec; yIndex: Integer; const xyScale: TCplx; const Z: TMtxVec; zIndex: Integer; const zScale: TCplx; Index, Len: Integer): TMtxVec; overload; (* Compute (X*Y)*xyScale - zScalar*) function MulAndSub(const X: TMtxVec; const Y: TMtxVec; const xyScale, Z: Double): TMtxVec; overload; (* Compute (X*Y)*xyScale - zScalar*) function MulAndSub(const X: TMtxVec; const Y: TMtxVec; const xyScale, Z: TCplx): TMtxVec; overload; (* Compute (X*Y)*xyScale - zScalar on sub array*) function MulAndSub(const X: TMtxVec; xIndex: Integer; const Y: TMtxVec; yIndex: Integer; const xyScale: Double; const Z: Double; Index, Len: Integer): TMtxVec; overload; (* Compute (X*Y)*xyScale - zScalar on sub array*) function MulAndSub(const X: TMtxVec; xIndex: Integer; const Y: TMtxVec; yIndex: Integer; const xyScale: TCplx; const Z: TCplx; Index, Len: Integer): TMtxVec; overload; (* Compute X*yScalar - Z*zScale*) function MulAndSub(const X: TMtxVec; const Y: Double; const Z: TMtxVec; const zScale: Double): TMtxVec; overload; (* Compute X*yScalar - Z*zScale*) function MulAndSub(const X: TMtxVec; const Y: TCplx; const Z: TMtxVec; const zScale: TCplx): TMtxVec; overload; (* Compute X*yScalar - Z*zScale on sub array*) function MulAndSub(const X: TMtxVec; xIndex: integer; const Y: Double; const Z: TMtxVec; zIndex: integer; const zScale: Double; Index, Len: integer): TMtxVec; overload; (* Compute X*yScalar - Z*zScale on sub array*) function MulAndSub(const X: TMtxVec; xIndex: integer; const Y: TCplx; const Z: TMtxVec; zIndex: integer; const zScale: TCplx; Index, Len: integer): TMtxVec; overload; (* Compute (X / Y)*xyScale + Z*zScale The following expression would also run at the same or higher speed, when passing Z also for the Y parameter: (X / Z) * xyScale + Z * zScale *) function DivAndAdd(const X: TMtxVec; const Y: TMtxVec; const xyScale: Double; const Z: TMtxVec; const zScale: Double): TMtxVec; overload; (* Compute (X / Y)*xyScale + Z*zScale on sub array*) function DivAndAdd(const X: TMtxVec; xIndex: Integer; const Y: TMtxVec; yIndex: Integer; const xyScale: Double; const Z: TMtxVec; zIndex: Integer; const zScale: Double; Index, Len: Integer): TMtxVec; overload; (* Compute (X / Y)*xyScale + Z*zScale The following expression would also run at the same or higher speed, when passing Z also for the Y parameter: (X / Z) * xyScale + Z * zScale *) function DivAndAdd(const X: TMtxVec; const Y: TMtxVec; const xyScale: TCplx; const Z: TMtxVec; const zScale: TCplx): TMtxVec; overload; (* Compute (X / Y)*xyScale + Z*zScale on sub array*) function DivAndAdd(const X: TMtxVec; xIndex: Integer; const Y: TMtxVec; yIndex: Integer; const xyScale: TCplx; const Z: TMtxVec; zIndex: Integer; const zScale: TCplx; Index, Len: Integer): TMtxVec; overload; (* Compute (X / Y) * xyScale + zScalar*) function DivAndAdd(const X: TMtxVec; const Y: TMtxVec; const xyScale: Double; const Z: Double): TMtxVec; overload; (* Compute (X / Y) * xyScale + zScalar*) function DivAndAdd(const X: TMtxVec; xIndex: Integer; const Y: TMtxVec; yIndex: Integer; const xyScale: Double; const Z: Double; Index, Len: Integer): TMtxVec; overload; (* Compute (X / Y) * xyScale + zScalar*) function DivAndAdd(const X: TMtxVec; const Y: TMtxVec; const xyScale: TCplx; const Z: TCplx): TMtxVec; overload; (* Compute (X / Y) * xyScale + zScalar*) function DivAndAdd(const X: TMtxVec; xIndex: Integer; const Y: TMtxVec; yIndex: Integer; const xyScale: TCplx; const Z: TCplx; Index, Len: Integer): TMtxVec; overload; (* Compute (X / Y) * xyScale - Z*zScale *) function DivAndSub(const X: TMtxVec; const Y: TMtxVec; const xyScale: Double; const Z: TMtxVec; const zScale: Double): TMtxVec; overload; (* Compute (X / Y) * xyScale - Z on sub array*) function DivAndSub(const X: TMtxVec; xIndex: Integer; const Y: TMtxVec; yIndex: Integer; const xyScale: Double; const Z: TMtxVec; zIndex: Integer; const zScale: Double; Index, Len: Integer): TMtxVec; overload; (* Compute (X / Y) * xyScale - Z*zScale *) function DivAndSub(const X: TMtxVec; const Y: TMtxVec; const xyScale: TCplx; const Z: TMtxVec; const zScale: TCplx): TMtxVec; overload; (* Compute (X / Y) * xyScale - Z on sub array*) function DivAndSub(const X: TMtxVec; xIndex: Integer; const Y: TMtxVec; yIndex: Integer; const xyScale: TCplx; const Z: TMtxVec; zIndex: Integer; const zScale: TCplx; Index, Len: Integer): TMtxVec; overload; (* Compute (X / Y) * xyScale - zScalar*) function DivAndSub(const X: TMtxVec; const Y: TMtxVec; const xyScale: Double; const Z: Double): TMtxVec; overload; (* Compute (X / Y) * xyScale - zScalar on sub array*) function DivAndSub(const X: TMtxVec; xIndex: Integer; const Y: TMtxVec; yIndex: Integer; const xyScale: Double; const Z: Double; Index, Len: Integer): TMtxVec; overload; (* Compute (X / Y) * xyScale - zScalar*) function DivAndSub(const X: TMtxVec; const Y: TMtxVec; const xyScale: TCplx; const Z: TCplx): TMtxVec; overload; (* Compute (X / Y) * xyScale - zScalar on sub array*) function DivAndSub(const X: TMtxVec; xIndex: Integer; const Y: TMtxVec; yIndex: Integer; const xyScale: TCplx; const Z: TCplx; Index, Len: Integer): TMtxVec; overload; (*Conjugate and multiply. Conjugate each of Matrix elements and multiply them with corresponding elements in the calling object. The results are stored in the calling object. Size and properties of the calling object are set implicitly to match Vec. var a,b,c: Matrix; begin a.SetIt(1,2,True,[1,2,3,4]); b.SetIt(1,2,True,[4,3,2,1]); c.ConjMul(a,b); end; *) function ConjMul(const Vec: TMtxVec): TMtxVec; overload; (*Conjugate Vec elements Vec[VecIndex]..Vec[VecIndex+Len-1] and multiply them with corresponding calling object elements [Index]..[Index+Len-1]. The results are stored in the calling object elements [Index]..[Index+Len-1]. Size and properties are not set. An exception is raised if is true and array borders are overrun or underrun. *) function ConjMul(const Vec: TMtxVec; VecIndex, Index, Len: integer): TMtxVec; overload; (*Conjugate each of Vec2 elements and multiply them with corresponding elements in Vec1. The results are stored in the calling object. Size and properties of the calling object are set implicitly to match Vec1 and Vec2 objects. *) function ConjMul(const Vec1, Vec2: TMtxVec): TMtxVec; overload; (*Conjugate Vec2 elements [Vec2Index]..[Vec2Index+Len-1] and multiply them with corresponding Vec1 elements [Vec1Index]..[Vec1Index+Len-1]. The results are stored in the calling object elements [Index]..[Index+Len-1]. Size and properties of the calling Matrix must be set explicitly. An exception is raised if is true and array borders are overrun. *) function ConjMul(const Vec1, Vec2: TMtxVec; Vec1Index, Vec2Index, Index, Len: integer): TMtxVec; overload; (*Cumulative sum. Calculate the cumulative sum for calling object elements [Index]..[Index+Len-1] in-place. An exception is raised if is true and array borders are overrun. var a: Matrix; begin a.SetIt(2,2,false,[1,2,3,4]; a.CumSum(0,4); // a = [1,3,6,10] end; *) function CumSum(Index, Len: Integer): TMtxVec; overload; (*Calculate the cumulative sum for Vec elements [VecIndex]..[VecIndex+Len-1]. Store the results in calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. Exception is raised if property is True and array borders are overrun. *) function CumSum(const Vec: TMtxVec; VecIndex,Index,Len: Integer): TMtxVec; overload; (*Calculate the cumulative product for all Vec elements. The size must be set by the user. The function will store all powers of Value: Values[Index + i] := IntPower(Value, i) at corresponding array Index *) function CumProduct(Value: Double; Index, Len: integer): TMtxVec; overload; (*Calculate the cumulative product for all Vec elements. The size must be set by the user. The function will store all powers of Value: CValues[Index + i] := IntPower(Value, i) at corresponding array Index *) function CumProduct(const Value: TCplx; Index, Len: integer): TMtxVec; overload; (*The forward discrete cosine transform (DCT). Calculates the forward discrete cosine transform (DCT) of the Vec and writes the result in the calling Matrix. If Vec.Length is a power of 2, the function uses an efficient algorithm that is significantly faster than the direct computation of DCT. For other values of Vec Length, this function uses the direct formulas given below; however, the symmetry of cosine function is taken into account, which allows to perform about half of the multiplication operations in the formulas. In the following definition of DCT, N=Vec.Length and V is the calling Matrix: var a,b: Matrix; begin a.SetIt(1,4,False,[1,-2,3,4]); b.DCT(a,0,0,4); end; *) function DCT(const Vec: TMtxVec; VecIndex, Index, Len: integer): TMtxVec; overload; (*Difference. Calculate the difference for Vec elements [VecIndex]..[VecIndex+Len-1] and store the results in the calling object elements [Index]..[Index+Len-1]. Size and properties of the calling Matrix must be set explicitly. The following formula is used to calculate the difference: An exception is raised if is True and array borders are overrun or underrun. *) function Difference(const Vec: TMtxVec; VecIndex, Index, Len: integer): TMtxVec; overload; (*Matrix division. Divide each of Vec elements with corresponding elements in the calling object. Size and property of the calling object are set automatically. The result is stored in the calling object. The threshold parameter is used to prevent against division by zero and numerical instabilities in the follow on processing. All values of Vec smaller than Threshold will be replaced with Threshold. *) function Divide(const Vec: TMtxVec; Threshold: double): TMtxVec; overload; (*Divide each of Vec elements with corresponding elements in the calling object. Store the result in the calling object. Size and property of the calling object are set automatically. *) function Divide(const Vec: TMtxVec; Threshold: double; VecIndex, Index, Len: integer): TMtxVec; overload; (*Divide each of Vec1 elements with corresponding elements in the Vec2 object. Store the result in the calling Matrix. *) function Divide(const Vec1, Vec2: TMtxVec; Threshold: double): TMtxVec; overload; (*Divide Vec1 elements [Vec1Index]...[Vec1Index+Len-1] with corresponding elements [Vec2Index]...[Vec2Index+Len-1] from the Vec object. Store the result in the calling Matrix [Index]...[Index+Len-1]. *) function Divide(const Vec1, Vec2: TMtxVec; Threshold: double; Vec1Index, Vec2Index, Index, Len: integer): TMtxVec; overload; (*Divide each of Num elements with corresponding elements in Den. Size and property of the calling object are set automatically. The result is stored in the calling object. Note The result of division by zero will be the INF constant. Division of zero by zero will result in NAN. *) function Divide(Num, Den: TMtxVec): TMtxVec; overload; (*Divide each of calling Matrix elements with corresponding elements in the Vec object. Size and property of the calling object are set automatically. The result is stored in the calling object. Note The result of division by zero will be the INF constant. Division of zero by zero will result in NAN. *) function Divide(const Vec: TMtxVec): TMtxVec; overload; (*Divide calling Matrix elements [Index]...[Index+Len-1] with corresponding elements [VecIndex]...[VecIndex+Len-1] from the Vec object. Store the result in the claling Matrix. The of the calling Matrix is not changed. An exception is raised if is True and array borders are overrun or underrun. Note The result of division by zero will be the INF constant. Division of zero by zero will result in NAN. *) function Divide(const Vec: TMtxVec; VecIndex, Index, Len: integer): TMtxVec; overload; (*Divide [NumIndex]..[NumIndex+Len-1] Num elements with [DenIndex]..[DenIndex+Len-1] elements in Den. Store result in the calling Matrix at positions [Index]..[Index+Len-1] and property of the calling object are not changed. An exception is raised if is True and array borders are overrun or underrun. Note The result of division by zero will be the INF constant. Division of zero by zero will result in NAN. *) function Divide(Num, Den: TMtxVec; NumIndex, DenIndex, Index, Len: integer): TMtxVec; overload; (*Divide Value with elements of the calling object and store the result in the calling object.*) function DivideBy(Value: double): TMtxVec; overload; (*Divide complex Value with elements of the calling object and store the result in the calling object. Calling Matrix will be extended to complex, if the calling Matrix is real. *) function DivideBy(Value: TCplx): TMtxVec; overload; (*Divide Value with elements [Index]...[Index+Len-1] from the calling object. Store the result in the calling object at position [Index]...[Index+Len-1]. An exception will be raised if is True and array borders are overrun or underrun. *) function DivideBy(Value: double; Index, Len: integer): TMtxVec; overload; (*Divide complex Value with elements [Index]...[Index+Len-1] from the calling object. Store the result in the calling object at position [Index]...[Index+Len-1]. Calling Matrix will be extended to complex, if the calling Matrix is real. An exception will be raised if is True and array borders are overrun or underrun. *) function DivideBy(Value: TCplx; Index, Len: integer): TMtxVec; overload; (*Divide Value with elements from Vec and store the result in the corresponding elements of the calling object. Size and properties of the calling object are set automatically. *) function DivideBy(Value: double; Vec: TMtxVec): TMtxVec; overload; (*Divide complex Value with elements from Vec and store the result in the corresponding elements of the calling object. Size of the calling object is set automatically. property of the calling object is set to True. *) function DivideBy(Value: TCplx; Vec: TMtxVec): TMtxVec; overload; (*Divide Value with Vec elements [VecIndex]..[VecIndes+Len-1]. Store the result in the elements [Index]..[Index+Len-1] of the calling object. Size of the calling object is not changed. An exception will be raised if is True and array borders are overrun or underrun. property of the calling object is set implicitly. *) function DivideBy(Value: double; Vec: TMtxVec; VecIndex, Index, Len: integer): TMtxVec; overload; (*Divide complex Value with elements [VecIndex]..[VecIndes+Len-1] from Vec and store the result in the elements [Index]..[Index+Len-1] of the calling object. Size of the calling object is not changed. An exception will be raised if is True and array borders are overrun or underrun. property of the calling object is set to True. *) function DivideBy(Value: TCplx; Vec: TMtxVec; VecIndex, Index, Len: integer): TMtxVec; overload; (*Scalar product of two real arrays. Returns the scalar product between Vec elements [VecIndex]..[VecIndex+Len-1] and calling object elements [Index]..[Index+Len-1]. An exception is raised if Vec and calling object property is True. An exception is raised if is True and array borders are overrun or underrun. The dot product is defined by the equation: Both objects must be of equal size. If they are not, the method will return the dot product of the largest sub-array. var a,b: Matrix; prod: double; begin a.SetIt(1,4,False,[1,2,3,4]); b.SetIt(1,4,False,[5,6,7,8]); prod := a.DotProd(b,0,0,4); // = 1*5 + 2*6 + * 3*7 + 4*8 end; *) function DotProd(const Vec: TMtxVec; VecIndex, Index, Len: integer): double; overload; (*Scalar product of two complex arrays. Returns the scalar product between Vec (complex) elements [VecIndex]..[VecIndex+Len-1] and calling object (complex) elements [Index]..[Index+Len-1]. An exception is raised if Vec and calling object property is False. An exception is raised if is True and array borders are overrun or underrun. An exception is raised if calling or Vec object property is false. The dot product is defined by the equation: Both objects must be of equal size. If they are not, the method will return the dot product of the largest sub-array. var a,b: Matrix; prod: TCplx; begin a.SetIt(1,2,True,[1,2,3,4]); b.SetIt(1,2,True,[5,6,7,8]); prod := a.DotProdc(b,0,0,2); //= (1+2i)*(5+6i)+(3+4i)*(7+8i) end; *) function DotProdc(const Vec: TMtxVec; VecIndex, Index, Len: integer): TCplx; overload; function DotProdc(const Vec: TMtxVec; ConjVec: boolean; VecIndex, Index, Len: integer): TCplx; overload; (*Downsamples object values. Copy only every Factor sample from Src starting at SrcIndex up to Len to the calling object starting at Index. The phase parameter determines the initial sample offset. Phase must be less then Factor. Size and properties of the calling object are set implicitly. An exception is raised if array borders are overrun/underrun. *) function DownSample(const Src: TMtxVec; Factor, SrcIndex, Index, Len: integer; Phase: integer = 0): TMtxVec; overload; (*Fast Furier Transformation (FFT) from complex to complex or from real to complex. Calculate the 1D FFT from Vec elements [VecIndex]..[VecIndex+Len-1] and store the results in the calling object elements [Index]..[Index+Len-1]. The Len parameter must be a power of two. Size and properties of the calling object must be set explicitly. An exception is raised if is True and array borders are overrun. If Vec is complex, then complex to complex forward FFT is performed. If Vec is real, then real to complex forward FFT is performed. This is the indexed version of the FFT routine . Look there for more information on FFT parameters and storage requirements. *) function FFT(const Vec: TMtxVec; ConjugateExtend: boolean; VecIndex, Index, Len: integer): TMtxVec; overload; (*The forward Fast Fourier Transformation (FFT) from real to complex. Calculate the 1D FFT from real Vec elements [VecIndex]..[VecIndex+Len-1] and store the results in the calling object elements [Index]..[Index+Len-1]. The Len parameter must not be a power of two. Size and properties of the calling object must be set explicitly. An exception is raised if is True and Vec is not complex or if array borders are overrun. This is the indexed version of the FFT routine . Look there for more information on FFT parameters and storage requirements. *) function FFTFromReal(const Vec: TMtxVec; VecIndex, Index, Len: integer): TMtxVec; overload; (*The inverse discrete cosine transform (DCT). Calculate the inverse discrete cosine transform (DCT) from Vec elements [VecIndex]..[VecIndex+Len-1] and store the results in the calling object elements [Index]..[Index+Len-1]. The Len parameter must be the power of two. Size and properties of the calling Matrix must be set explicitly. An exception is raised if is True and array borders are overrun. *) function IDCT(const Vec: TMtxVec; VecIndex, Index, Len: integer): TMtxVec; overload; (*The inverse FFT from complex to complex. Calculate the inverse 1D FFT from Vec elements [VecIndex]..[VecIndex+Len-1] and store the results in the calling object elements [Index]..[Index+Len-1]. The Len parameter must be the power of two. Size and properties of the calling Matrix must be set explicitly. An exception is raised if is True and array borders are overrun. Note This is the indexed version of the FFT routine . Look there For more information on FFT parameters and storage requirements. *) function IFFT(const Vec: TMtxVec; VecIndex, Index, Len: integer; NoScale: boolean=False): TMtxVec; overload; (*The inverse FFT from complex to real. Calculate the inverse FFT from Vec elements [VecIndex]..[VecIndex+Len-1] and store the results in the calling object elements [Index]..[Index+Len-1]. The Len parameter must not be a power of two. Size and properties of the calling object must be set explicitly. An exception is raised if is True and array borders are overrun. Note This is the indexed version of the FFT routine . Look there for more information on FFT parameters and storage requirements. *) function IFFTToReal(const Vec: TMtxVec; VecIndex, Index, Len: integer; NoScale: boolean=False): TMtxVec; overload; (*The Kurtosis (fourth central momentum). Calculate the calling object kurtosis by using mean value AMean and standard deviation AStdDev. Kurtosis is the fourth central moment, divided by fourth power of standard deviation: *) function Kurtosis(AMean, AStdDev: double): double; overload; (*Calculate the kurtosis for elements [Index]..[Index+Len-1]. An exception is raised if is True and array borders are overrun. The AMean and AStdDev passed as parameters must be computed from the same elements (Index, Len) as the Kurtosis itself. *) function Kurtosis(AMean, AStdDev: double; Index, Len: integer): double; overload; (*Median. Calculate median value for all calling object elements. var a: Matrix; c: double; begin a.SetIt(1,4,False,[1,2,3,4]); c := a.Median; end; *) function Median: double; overload; (*Calculate median value for calling Matrix elements [Index]..[Index+Len-1]. An exception is raised if is true and array borders are overrun. *) function Median(Index: integer; Len: integer): double; overload; (*Matrix multiplication. Multiply each of Vec elements with corresponding elements in the calling object. Size and property of the calling object are set automatically. The result is stored in the calling object. *) function Mul(const Vec: TMtxVec): TMtxVec; overload; (*Multiply Vec elements [VecIndex]..[VecIndex+Len-1] with calling object elements [Index]..[Index+Len-1] in-place. An exception is raised if Vec and calling object property do not match or if array borders are overrun/underrun. *) function Mul(const Vec: TMtxVec; VecIndex, Index, Len: integer): TMtxVec; overload; (*Multiply Vec1 elements [Vec1Index]..[Vec1Index+Len-1] with Vec2 object elements [Vec2Index]..[Vec2Index+Len-1] and store the results in calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if is True and array borders are overrun or underrun. *) function Mul(const Vec1, Vec2: TMtxVec; Vec1Index, Vec2Index, Index, Len: integer): TMtxVec; overload; (*Vectorised maximum. Compares Vec values with corresponding elements in the calling object and stores the bigger value in Self. Size and property of the calling object are set automatically. Supports real value data only. *) function MaxEvery(const Vec: TMtxVec): TMtxVec; overload; (*Compare Vec elements [VecIndex]..[VecIndex+Len-1] with calling object elements [Index]..[Index+Len-1] and store result in Self. An exception is raised if Vec and calling object property do not match or if array borders are overrun/underrun. Supports real value data only. *) function MaxEvery(const Vec: TMtxVec; VecIndex, Index, Len: integer): TMtxVec; overload; (*Compare all Vec1 elements with corresponding Vec2 elements and store bigger value in Self. Stores the results in to the calling object. Size and property of calling object are adjusted automatically to match those of Vec1 and Vec2. An exception is raised if Vec1 and Vec2 size and property do not match. Supports real value data only. *) function MaxEvery(const Vec1, Vec2: TMtxVec): TMtxVec; overload; (*Compare Vec1 elements [Vec1Index]..[Vec1Index+Len-1] with Vec2 object elements [Vec2Index]..[Vec2Index+Len-1] and store bigger value in Self. Stores the results in to the calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if ConditionCheck is True and array borders are overrun or underrun. *) function MaxEvery(const Vec1, Vec2: TMtxVec; Vec1Index, Vec2Index, Index, Len: integer): TMtxVec; overload; (*Vectorised minimum. Compares Vec values with corresponding elements in the calling object and stores the smaller value in Self. Size and property of the calling object are set automatically. Supports real value data only. *) function MinEvery(const Vec: TMtxVec): TMtxVec; overload; (*Compare Vec elements [VecIndex]..[VecIndex+Len-1] with calling object elements [Index]..[Index+Len-1] and store result in Self. An exception is raised if Vec and calling object property do not match or if array borders are overrun/underrun. Supports real value data only. *) function MinEvery(const Vec: TMtxVec; VecIndex, Index, Len: integer): TMtxVec; overload; (*Compare all Vec1 elements with corresponding Vec2 elements and store the smaller value in Self. Stores the results in to the calling object. Size and property of calling object are adjusted automatically to match those of Vec1 and Vec2. An exception is raised if Vec1 and Vec2 size and property do not match. Supports real value data only. *) function MinEvery(const Vec1, Vec2: TMtxVec): TMtxVec; overload; (*Compare Vec1 elements [Vec1Index]..[Vec1Index+Len-1] with Vec2 object elements [Vec2Index]..[Vec2Index+Len-1] and store the smaller value in Self. Stores the results in to the calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if ConditionCheck is True and array borders are overrun or underrun. *) function MinEvery(const Vec1, Vec2: TMtxVec; Vec1Index, Vec2Index, Index, Len: integer): TMtxVec; overload; (*Maximum value. Returns the maximum value of all calling object elements. The result is a real value. An exception is raised is calling object is true. var a: Matrix; b: double; begin a.SetIt(2,2,False,[1,2,3,4]); b := a.Max; // b = 4 end; *) function Max: double; overload; (*Returns the maximum value from calling object elements [Index]..[Index+Len-1]. The result is a real value. An exception is raised if calling object property is true or array borders are overrun. *) function Max(Index,Len: integer): double; overload; (*Calculate the maximum value from calling object elements [Index]..[Index+Len-1]. The result AMean is a real value. An exception is raised if calling object property is true or array borders are overrun. *) procedure Max(out AMax: double; Index,Len: integer); overload; procedure Max(out AMax: double; out AIndex: integer); overload; (*Calculate the maximum value of calling object elements [Index]..[Index+Len-1]. The AMax parameter returns the maximum value. The AIndex parameter returns the Index of maximum value. An exception is raised if calling object property is true or array borders are overrud/underrun. *) procedure Max(out AMax: double; out AIndex: integer; Index, Len: integer); overload; (*Maximum value. Returns the maximum value of all calling object complex elements. Complex elements are first compared by the amplitude and then by the argument. An exception is raised if calling object is False. *) function Maxc: TCplx; overload; (*Returns the maximum value of calling object complex elements [Index]..[Index+Len-1]. The result is a complex value. Complex elements are first compared by the amplitude and then by the argument. An exception is raised if calling object property is False or array borders are overrud/underrun. *) function Maxc(Index,Len: integer): TCplx; overload; (*Calculate the maximum value of calling object complex elements [Index]..[Index+Len-1]. The AMax parameter returns complex maximum value. Returns the Index of maximum value. Complex elements are first compared by the amplitude and then by the argument. The AIndex parameter returns the Index of maximum value. An exception is raised if calling object property is False or array borders are overrud/underrun. *) function Maxc(out AMax: TCplx; Index, Len: integer): integer; overload; (*Maximum and minimum value in a single pass. Calculates the maximum and minimum value of all calling object elements in a single pass. Maximum value is stored in AMax parameter, minimum value is stored in AMin parameter. Use this method if you require minimum AND maximum value. *) procedure MaxMin(out AMax,AMin: double); overload; (*Calculates the maximum and minimum value of calling object elements [Index]..[Index+Len-1]. Maximum value is stored in AMax parameter, minimum value is stored in AMin parameter. An exception is raised if calling object property is true or array borders are overrud/underrun. *) procedure MaxMin(out AMax,AMin: double; Index, Len: integer); overload; (*Calculates the maximum and minimum value of all calling object elements. Maximum value is returned in AMax parameter, minimum value in AMin parameter. The MaxIdx parameter returns the Index of maximum value. The MinIdx parameter returns the Index of minimum value. An exception is raised if calling object property is true. *) procedure MaxMin(out AMax: double; out MaxIdx: integer; out AMin: double; out MinIdx: integer); overload; (*Calculates the maximum and minimum value of calling object elements [Index]..[Index+Len-1]. Maximum value is returned in AMax parameter, minimum value in AMin parameter. The MaxIdx parameter returns the Index of maximum value. The MinIdx parameter returns the Index of minimum value. An exception is raised if calling object property is true or if array borders are overrud/underrun. *) procedure MaxMin(out AMax: double; out MaxIdx: integer; out AMin: double; out MinIdx: integer; Index, Len: integer); overload; (*Mean value. Calculate the mean value of all calling object elements. The result is a real value. An exception is raised if calling object property is true. var a: Matrix; b: double; begin a.SetIt(4,1,False,[1,2,3,4]); b := a.Mean; // b = 2.5 end; *) function Mean: double; overload; (*Returns real mean value from calling object elements [Index]..[Index+Len-1]. An exception is raised if calling object property is true or array borders are overrun. *) function Mean(Index, Len: integer): double; overload; (*Calculate the mean value from calling object elements [Index]..[Index+Len-1]. The result AMean is a real value. An exception is raised if calling object property is true or array borders are overrun/underrun. *) procedure Mean(out AMean: double; Index, Len: integer); overload; (*Mean value (complex). Returns the mean value of all calling object complex elements. The result is a complex value. An exception is raised is calling object is False. *) function Meanc: TCplx; overload; (*Returns complex mean value from calling object complex elements [Index]..[Index+Len-1]. An exception is raised if calling object property is False or array borders are overrun/underrun. *) function Meanc(Index, Len: integer): TCplx; overload; (*Calculate the mean value from all calling object complex elements. The result AMean is a complex value. An exception is raised if calling object property is False. *) procedure Meanc(out AMean: TCplx); overload; (*Calculate the mean value from calling object complex elements [Index]..[Index+Len-1]. The result AMean is a complex value. An exception is raised if calling object property is False or array borders are overrun/underrun. *) procedure Meanc(out AMean: TCplx; Index, Len: integer); overload; (*Minimum value. Calculate the minimum value of all calling object elements. The result is a real value. An exception is raised if calling object property is true. var a: Matrix; b: double; begin a.SetIt(2,2,False,[1,2,3,4]); b := a.Min; // b = 1 end; *) function Min: double; overload; (*Calculate the minimum value from calling object elements [Index]..[Index+Len-1]. The result is a real value. An exception is raised if calling object property is true or array borders are overrun. *) function Min(Index,Len: integer): double; overload; (*Calculate the minimum value from calling object elements [Index]..[Index+Len-1]. The result AMin is a real value. An exception is raised if calling object property is true or array borders are overrun. *) procedure Min(out AMin: double; Index,Len: integer); overload; (*Calculate the minimum value of calling object elements [Index]..[Index+Len-1]. The AMax parameter returns the minimum value. The AIndex parameter returns the Index of minimum value. An exception is raised if calling object property is true or array borders are overrud/underrun. *) procedure Min(out AMin: double; out AIndex: Integer; Index, Len: integer); overload; (*Calculate the minimum value of all calling object elements. The AMin parameter returns the minimum value. The AIndex parameter returns the Index of minimum value. An exception is raised if calling object property is true. *) procedure Min(out AMin: double; out AIndex: integer); overload; (*Minimum value (complex). Returns the minimum value of all calling object complex elements. Complex elements are first compared by the amplitude and then by the argument. An exception is raised if calling object is False. *) function Minc: TCplx; overload; (*Returns the minimum value of calling object complex elements [Index]..[Index+Len-1]. The result is a complex value. Complex elements are first compared by the amplitude and then by the argument. An exception is raised if calling object property is False or array borders are overrud/underrun. *) function Minc(Index,Len: integer): TCplx; overload; (*Calculate the minimum value of calling object complex elements [Index]..[Index+Len-1]. The AMin parameter returns complex minimum value. Returns the Index of minimum value. Complex elements are first compared by the amplitude and then by the argument. An exception is raised if calling object property is False or array borders are overrun/underrun. *) function Minc(out AMin: TCplx; Index, Len: integer): integer; overload; (*The C-norm. Calculates the C norm: ||V-Vec||, where V is the calling Matrix. If the NormC is called without any parameters, the NormC calculates the norm of the calling Matrix. The C norm of ||V-Vec|| is defined by the formula: If RelativeError is true then the computed norm is divided by the norm of V, and the function returns the "relative error": var a,b: Matrix; c: double; begin a.SetIt(1,4,False,[1,2,3,4]); b.SetIt(1,4,False,[4,3,2,1]); c := a.NormC(b,False); end; *) function NormC(const Vec: TDenseMtxVec; RelativeError: boolean = False): double; overload; (*Calculates the C norm ||V-Vec|| between Vec elements [VecIndex]..[VecIndex+Len-1] and calling Matrix elements [Index]..[Index+Len-1].*) function NormC(const Vec: TDenseMtxVec; VecIndex,Index,Len: integer; RelativeError: boolean = False): double; overload; (*The C-norm of calling Matrix. Computes: NormC = max|a[i]|, 0 < i < Length-1 *) function NormC: double; overload; (*Calculates the C norm from calling Matrix elements [Index]..[Index+Len-1].*) function NormC(Index,Len: integer): double; overload; (*The L1-norm. Calculates the L1 norm : ||V-Vec||, where V is calling Matrix. If the NormL1 is called without any parameters, the NormL1 calculates the norm of calling Matrix. The L1 norm of ||V-Vec|| is defined by the formula: If RelativeError is true then the computed norm is divided by the norm of V, and the function returns the "relative error": var a,b: Matrix; c: double; begin a.SetIt(1,4,False,[1,2,3,4]); b.SetIt(1,4,False,[4,3,2,1]); c := a.NormL1(b,True); end; *) function NormL1(const Vec: TDenseMtxVec; RelativeError: boolean = False): double; overload; (*Calculates the L1 norm ||V-Vec|| between Vec elements [VecIndex]..[VecIndex+Len-1] and calling Matrix elements [Index]..[Index+Len-1].*) function NormL1(const Vec: TDenseMtxVec; VecIndex,Index,Len: integer; RelativeError: boolean = False): double; overload; (*The L1-norm of the calling Matrix. Calculates: NormL1 = Sum(|a[i]|), 0 < i < Length-1 *) function NormL1: double; overload; (*Calculates the L1 norm from calling Matrix elements [Index]..[Index+Len-1].*) function NormL1(Index,Len: integer): double; overload; (*The L2-norm. Calculates the L2 norm : ||V-Vec||, where V is calling Matrix. If the NormL2 is called without any parameters, the NormL2 calculates the norm of calling Matrix. The L2 norm of ||V-Vec|| is defined by the formula: If RelativeError is true then the computed norm is divided by the norm of V, and the function returns the "relative error": var a,b: Matrix; c: double; begin a.SetIt(1,4,False,[1,2,3,4]); b.SetIt(1,4,False,[4,3,2,1]); c := a.NormL2(b,True); // or c := NormL2(a,b,true); end; *) function NormL2(const Vec: TDenseMtxVec; RelativeError: boolean = False): double; overload; (*Calculates the L2 norm ||V-Vec|| between Vec elements [VecIndex]..[VecIndex+Len-1] and calling Matrix elements [Index]..[Index+Len-1].*) function NormL2(const Vec: TDenseMtxVec; VecIndex,Index,Len: integer; RelativeError: boolean = False): double; overload; (*The L2-norm of the calling Matrix. Calculates: NormaL2 = ( Sum(|a[i]|^2) )^0.5 , 0 < i < Length-1 *) function NormL2: double; overload; (*Calculates the L2 norm from calling Matrix elements [Index]..[Index+Len-1].*) function NormL2(Index,Len: integer): double; overload; (*Add/Subtract a value. Depreciated Use (Value) instead. *) function Offset(Value: double): TMtxVec; overload; (*Add/Subtract a complex value.*) function Offset(Value: TCplx): TMtxVec; overload; (*Add/Subtract a value from [Index]..[Index+Len-1].*) function Offset(Value: double; Index,Len: integer): TMtxVec; overload; (*Add/Subtract a complex value from [Index]..[Index+Len-1].*) function Offset(Value: TCplx; Index,Len: integer): TMtxVec; overload; (*Calculate the range from all calling object elements.*) function Range: double; overload; (*Returns real range value from calling object elements [Index]..[Index+Len-1]. An exception is raised if calling object property is true or array borders are overrun. *) function Range(Index, Len: integer): double; overload; (*Calculate the range from calling object elements [Index]..[Index+Len-1]. The result ARange is a real value. An exception is raised if calling object property is true or array borders are overrun/underrun. *) procedure Range(out ARange: double; Index, Len: integer); overload; (*Reverse Matrix elements. The method reverses Vec Matrix elements from [VecIndex].. [VecIndex+Len-1] and stores them in the calling Matrix from [Index]...[Index+Len-1] by using the following equation: This overload reverses calling Matrix elements in-place. var a: Matrix; begin a.SetIt(2,2,False,[1,2,3,4]); a.Reverse(0,2); // a = [2,1,3,4] end; *) function Reverse(const Vec: TMtxVec; VecIndex, Index, Len: integer): TMtxVec; overload; (*Reverses the calling object elements [Index]..[Index+Len-1]. An exception is raised if array borders are overrun. *) function Reverse(Index, Len: integer): TMtxVec; overload; (*A cyclic shift on Matrix elements in range. Performs cyclic shift on Matrix elements in specified range [Index..Index+Len]. The number of elements to shift is specified in the Offset parameter. Offset can be any integer number, positive or negative. *) function Rotate(Offset: integer; Index: integer; Len: integer = MtxVecEOA): TMtxVec; overload; (*A cyclic shift on Matrix elements in range. Performs cyclic shift on source Matrix elements in specified range [Index..Index+Len] and stores them to calling Matrix. The number of elements to shift is specified in the Offset parameter. Offset can be any integer number, positive or negative. *) function Rotate(const Vec: TMtxVec; Offset: integer; VecIndex,Index: integer; Len: integer = MtxVecEOA): TMtxVec; overload; (*Shift Matrix elements in range. Shifts calling Matrix elements in specified range [Index..Index+Len]. The number of elements by which to shift is specified in the Offset parameter. Offset can be any integer number, positive or negative. *) function Shift(Offset: integer; Index: integer; Len: integer = MtxVecEOA): TMtxVec; overload; (*A shift on Matrix elements in range. Performs shift on source Matrix elements in specified range [Index..Index+Len] and stores them to calling Matrix. The number of elements to shift is specified in the Offset parameter. Offset can be any integer number, positive or negative. *) function Shift(const Vec: TMtxVec; Offset: integer; VecIndex,Index: integer; Len: integer = MtxVecEOA): TMtxVec; overload; (*Subtracts Value from object elements. Subtracts Value from all calling object elements. *) function Sub(Value: double): TMtxVec; overload; (*Subtracts complex Value from all calling object complex elements.*) function Sub(Value: TCplx): TMtxVec; overload; (*Subtracts Value from calling object elements [Index]..[Index+Len-1]. An exception is raised if array borders are overrun. *) function Sub(Value: double; Index, Len: integer): TMtxVec; overload; (*Subtracts complex Value from calling object complex elements [Index]..[Index+Len-1]. An exception is raised if array borders are overrun. *) function Sub(Value: TCplx; Index, Len: integer): TMtxVec; overload; (*Subtract real Value from Src store the results in calling object. Size and property of calling object are adjusted automatically. *) function Sub(const Src: TMtxVec; Value: double): TMtxVec; overload; (*Subtract complex Value from Src store the results in calling object. Size and property of calling object are adjusted automatically. *) function Sub(const Src: TMtxVec; Value: TCplx): TMtxVec; overload; (*Subtract real Value from Src elements [SrcIndex]..[SrcIndex+Len-1]. Store the result in calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if is True and array borders are overrun or underrun. *) function Sub(const Src: TMtxVec; Value: double; SrcIndex, Index, Len: integer): TMtxVec; overload; (*Subtract complex Value from Src elements [SrcIndex]..[SrcIndex+Len-1]. Store the result in calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if is True and array borders are overrun or underrun. *) function Sub(const Src: TMtxVec; Value: TCplx; SrcIndex, Index, Len: integer): TMtxVec; overload; (*Array subtraction. Subtract each of Vec elements from corresponding elements in the calling object. An exception is raised if Vec and calling object size and properties do not match. *) function Sub(const Vec: TMtxVec): TMtxVec; overload; (*Subtract Vec2 elements from Vec1 elements and store the results in calling object. Size and property of calling object are adjusted automatically. An exception is raised if Vec1 and Vec2 size and property do not match. *) function Sub(const Vec1, Vec2: TMtxVec): TMtxVec; overload; (*Subtract Vec elements [VecIndex]..[VecIndex+Len-1] from corresponding calling object elements [Index]..[Index+Len-1]. The results are stored in the calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if is True and array borders are overrun or underrun. *) function Sub(const Vec: TMtxVec; VecIndex, Index, Len: integer): TMtxVec; overload; (*Subtract Vec22 elements [Vec2Index]..[Vec2Index+Len-1] from Vec1 object elements [Vec1Index]..[Vec1Index+Len-1]. Store the results in calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if is True and array borders are overrun or underrun. *) function Sub(const Vec1, Vec2: TMtxVec; Vec1Index, Vec2Index, Index, Len: integer): TMtxVec; overload; (*Subtraction from value. Subtract each of calling object elements from Value. *) function SubFrom(Value: double): TMtxVec; overload; (*Subtract each of calling object elements from complex Value. If the calling Matrix is not complex, the conversion is performed automatically in a performance efficient way. *) function SubFrom(Value: TCplx): TMtxVec; overload; (*Subtract elements [Index]..[Index+Len-1] from Value and store the result in Self. An exception is raised if is True and array borders are overrun or underrun. *) function SubFrom(Value: double; Index,Len: integer): TMtxVec; overload; (*Subtract elements [Index]..[Index+Len-1] from complex Value and store the result in Self. If the calling Matrix is not complex, the conversion to complex is performed automatically in performance efficient way. An exception is raised if is True and array borders are overrun or underrun. *) function SubFrom(Value: TCplx; Index,Len: integer): TMtxVec; overload; (*Substract Vec elements from Value and store the result in the calling object. Size and properties of calling object are adjusted automatically. *) function SubFrom(Value: double; Vec: TMtxVec): TMtxVec; overload; (*Substract complex Vec elements from Value and store the result in the calling object. Size property of the calling object is set automatically. property of the calling object is set to True. *) function SubFrom(Value: TCplx; Vec: TMtxVec): TMtxVec; overload; (*Substract Vec elements [VecIndex]..[VecIndex+Len-1] from Value and store the result to the calling object elements [Index]..[Index+Len-1]. Size property of the calling object is not changed. An exception is raised if is True and array borders are overrun or underrun. property of the calling object is adjusted automatically. *) function SubFrom(Value: double; Vec: TMtxVec; VecIndex, Index, Len: integer): TMtxVec; overload; (*Substract Vec elements [VecIndex]..[VecIndex+Len-1] from complex Value and store the result to the calling object elements [Index]..[Index+Len-1]. Size property of the calling object is not changed. An exception is raised if is True and array borders are overrun or underrun. property of the calling object is set to True. *) function SubFrom(Value: TCplx; Vec: TMtxVec; VecIndex, Index, Len: integer): TMtxVec; overload; (*Calculate the Sum of squares of the calling Matrix. For complex numbers, the routine computes the squared L2 norm. SumOfSquares = Sum(|a[i]|^2) , 0 < i < Length-1 *) function SumOfSquares: double; overload; (*Calculates the sum of squares from the calling Matrix elements [Index]..[Index+Len-1].*) function SumOfSquares(Index,Len: integer): double; overload; (*Inserts zeroes between consecutive array values. Copy Len values from Src starting at SrcIndex to the calling object starting at position Index and place Factor-1 zeros between consecutive values. Size and properties of the calling object must be set explicitly. Phase parameter defines the initial sample offset and must be less then Factor. An exception is raised, if array borders are overrun/underrun. *) function UpSample(const Src: TMtxVec; Factor,SrcIndex, Index, Len: integer; Phase: integer = 0): TMtxVec; overload; (*Skewness (third central momentum). Calculate the calling object skewness by using mean value AMean and standard deviation AStdDev. Skewness is the third central moment, divided by third power of standard deviation: var a: Matrix; c,d: double; begin a.SetIt(1,4,False,[1,2,3,4]); d := a.Mean; c := a.Skewness(d, a.StdDev(d)); //or d := Mean(a); c := Skewness(a, d, StdDev(a, d)); end; *) function Skewness(AMean, AStdDev: double): double; overload; (*Calculate the skewness for elements [Index]..[Index+Len-1]. An exception is raised if is True and array borders are overrun. The AMean and AStdDev parameters must be computed from the same elements from which the Skewness is to be computed. *) function Skewness(AMean, AStdDev: double; Index, Len: integer): double; overload; (*Calculates the tensor product of two vectors and adds the result to calling matrix. Calculates the tensor product of Vec1 and Vec2 vectors and adds the result to the calling matrix by using the following formula: Y=Vec1 X Vec2 + Y. If the ConjVec2 parameter is true, then the result will be tensor product of Vec1 and conjugated Vec2. The property is set to Vec1. and property is set to Vec2.. The property of the calling matrix is adjusted automatically. var a,b: Matrix; v1,v2: Vector; begin // Test non quadratic general matrix a.SetIt(2,2,False,[0,2,2,0]); v1.SetIt(false,[1,0]); v2.setIt(false,[0,1]); a.AddTensorProd(v1,v2,False); b.SetIt(False,[1,2,2,1]); if not (a = b) then raise Exception.Create('Not same'); end; *) function AddTensorProd(const Vec1, Vec2: TVec; ConjVec2: boolean = False): TMtx; overload; (*Adjungate matrix. Calculate the adjungate matrix in-place. Adjungation is equal to transpose and conjugate. *) function Adjung: TMtx; overload; (*Calculate the adjungate to X matrix and store the results in calling matrix. The , and properties of the calling matrix are set implicitly to match those of X matrix. *) function Adjung(const X: TMtx): TMtx; overload; (*Convert banded matrix to dense. Convert matrix stored in banded format to dense format. *) procedure BandedToDense(const Src: TMtx); overload; (*Test if the matrix is semi positive definite. True, if the matrix semi positive definite and at the same time performs the Cholesky decomposition of the calling matrix.*) function Cholesky: boolean; overload; (*Exchange matrix columns. Exchange the i-tj and j-th columns of the calling matrix in-place. An exception is raised if matrix bounds are overrun. *) function ColExchange(i, j: integer): TMtx; overload; (*Permute the columns of the Src matrix. The parameter PermuteIdx contains indexes of columns P[i] to which column at Index "i" is to be moved. The result of the permutation is stored in the calling matrix. Only entire matrix can be copied. *) function ColPermute(const Src: TMtx; PermuteIdx: TVecInt): TMtx; overload; (*Permute the rows of the Src matrix. The parameter PermuteIdx contains indexes of columns P[i] to which column at Index "i" is to be moved. The result of the permutation is stored in the calling matrix. Only entire matrix can be copied. *) function RowPermute(const Src: TMtx; PermuteIdx: TVecInt): TMtx; overload; (*Concatenate an array of matrices to single matrix. Concatenate an array of matrices to form one big matrix and store the result in the calling matrix. The dimensions of the block matrices in the Src array must match, to form the new matrix. The block matrices must be all real or all complex, otherwise an exception will be raised. You must specify Arows*ACols block matrices in the Src array. The , and properties of the calling matrix are adjusted automatically. var A,B,C,D,E: Matrix; begin A.Size(2,2); B.Size(A); C.Size(A); D.Size(A); E.Concat(2,2[A,B C,D]); // form one 4x4 matrix end; *) function Concat(ARows, ACols: integer;const Src: array of TMtx): TMtx; overload; (*Concenates an array of matrices horizontally. Concenate the Src matrices horizontally and store the results in the calling matrix. The , and properties of the calling matrix are adjusted automatically. An exception is raised if any of the Src matrices Complex or Rows property does not match. var A,B,C,D,E: Matrix; begin A.Size(2,2); B.Size(A); E.Size(4,4); // overwrite the lower part of the E matrix // with values from A and B E.ConcatHorz(2,2[A,B]); //E becomes: //[E11 E12 E13 E14] //[E21 E22 E23 E24] //[A11 A12 B11 B12] //[A21 A22 B21 B22] end; *) function ConcatHorz(const Src: array of TMtx): TMtx; overload; (*Concenate the Src matrices horizontally and store the results in the calling matrix. The DestRow and DestCol parameters indicate the starting position (in the calling matrix) for concenating. An exception is raised, if the calling matrix array bounds are overrun. An exception is raised, if any of the Src matrices Complex or Rows properties do not match. *) function ConcatHorz(DestRow, DestCol: integer;const Src: array of TMtx): TMtx; overload; (*Concenates an array of matrices vertically. Concenate the Src matrices vertically and store the results in calling matrix. The , and properties of the calling matrix are adjusted automatically. An exception is raised, if any of the Src matrices Complex or Cols properties do not match. var A,B,C,D,E: Matrix; begin A.Size(1,2); B.Size(A); E.Size(4,4); // overwrite the lower part of the E matrix // with values from A and B E.ConcatVert(2,2[A,B]); // E becomes: //[E11 E12 E13 E14] //[E21 E22 E23 E24] //[A11 A12 E33 E34] //[B11 B12 E43 E44]s end; *) function ConcatVert(const Src: array of TMtx): TMtx; overload; (*Concenate the Src matrices vertically and store the results in calling matrix. The DestRow and DestCol parameters indicate the starting position (in the calling matrix) for concatenating. An exception is raised, if the calling matrix array bounds are overrun. An exception is raised, if any of the Src matrices Complex or Cols properties do not match. *) function ConcatVert(DestRow, DestCol: integer;const Src: array of TMtx): TMtx; overload; (*{:Performs finite, linear convolution of two two-dimensional signals. Performs finite, linear convolution of two two-dimensional signals. The argument names X and H are chosen to suggest FIR filtering. The result of the convolution is defined as follows: In the above expressions, X[n, m] is a shorthand for X[n+ m* X.Cols], H[n, m] is a shorthand for H[n+ m* H.Cols], and y[n, m] is a shorthand for: y[n+ m* (X.Cols+ H.Cols-1)]. If NoResize parameter is True, the size of the calling matrix is set to the size of the X matrix and filtering edge effect is equally distributed. If the NoResize parameter is False, the size of the calling matrix is set to: Rows = X.Rows + H.Rows - 1 Cols = X.Cols + H.Cols - 1 In image processing X is the mitxure and H is the convolution kernel. } function Convolve(X,H :TMtx; NoResize: boolean = True): TMtx; overload;*) (*Copy the Mtx elements [MtxRow,MtxCol]..[MtxRow+NrRows-1,MtxCol+NrCols-1] to the calling matrix elements [Row,Col],,[Row+NrRows-1,Col+NrCols-1]. An exception is raised if is true and bounds are overrun. If Transpose is true, the matrix is transposed as well. An exception is raised if is true and Complex properties of the calling matrix and Mtx do not match. *) function Copy(const Mtx: TMtx; MtxRow, MtxCol, Row, Col, NrRows, NrCols: integer; Transpose: boolean = false): TMtx; overload; (*Copy and convert values from TVecInt. Applies appropriate conversion and copy data from TVecInt. The size of the matrix must match the length of the vector or an exception will be raised. *) function Copy(const Src: TVecInt; const dstFloatPrecision: TMtxFloatPrecision):TMtxVec; overload; (*Copy and convert values from TVecInt at indexes [SrcIndex]...[SrcIndex+Len-1]. Applies appropriate conversion and copy data from TVecInt. The results are stored in calling object elements [Index]...[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if array borders are overrun. *) function Copy(const Src: TVecInt; SrcIndex, Index, Len: integer):TMtxVec; overload; (*Copy and convert values from TVecInt. Applies appropriate conversion and copy data from TVecInt. The size of the matrix must match the length of the vector or an exception will be raised. *) function Copy(const Src: TMtxInt; const DstFloatPrecision: TMtxFloatPrecision):TMtxVec; overload; (*Copy and convert values from TMtxInt at indexes [SrcIndex]...[SrcIndex+Len-1]. Applies appropriate conversion and copy data from TMtxInt. The results are stored in calling object elements [Index]...[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if array borders are overrun. *) function Copy(const Src: TMtxInt; SrcIndex, Index, Len: integer):TMtxVec; overload; (*Copy and convert values to TVecInt. Applies appropriate conversion and copy data to TVecInt. The value TMtxVecInt.IntPrecision is preserved. *) procedure CopyTo(const Dst: TVecInt; Rounding: TRounding); overload; (*Copy and convert values to TMtxInt. Applies appropriate conversion and copy data to TMtxInt. The value TMtxInt.IntPrecision is preserved. *) procedure CopyTo(const Dst: TMtxInt; Rounding: TRounding); overload; (*Copy and convert values to TVecInt at indexes [DstIndex]...[DstIndex+Len-1]. Applies appropriate conversion and copy data from TVecInt. The results are stored in calling object elements [Index]...[Index+Len-1]. Size and properties of the destination object must be set explicitly. An exception is raised if array borders are overrun. *) procedure CopyTo(const Dst: TVecInt; Rounding: TRounding; DstIndex, Index, Len: integer); overload; (*Copy and convert values to TMtxInt at indexes [DstIndex]...[DstIndex+Len-1]. Applies appropriate conversion and copy data from TVecInt. The results are stored in calling object elements [Index]...[Index+Len-1]. Size and properties of the destination object must be set explicitly. An exception is raised if array borders are overrun. *) procedure CopyTo(const Dst: TMtxInt; Rounding: TRounding; DstIndex, Index, Len: integer); overload; (*Copy and convert values to specified dstFloatPrecision. Dst will be sized to hold all calling object data in specified dstFloatPrecision. The single/double and Complex/Not Complex conversion cant be handled concurrently. *) procedure CopyTo(const Dst: TMtxVec; const dstFloatPrecision: TMtxFloatPrecision); overload; (*Copy and convert values to Dst.FloatPrecision at indexes [DstIndex]...[DstIndex+Len-1]. Applies appropriate conversion and copy data from the calling object. The results are stored in Dst object elements [Index]...[Index+Len-1]. Size and properties of the destination object must be set explicitly. An exception is raised if array borders are overrun. *) procedure CopyTo(const Dst: TMtxVec; const DstIndex, Index: integer; Len: integer); overload; (*Copy and if needed convert values to Dst. Existing value of Dst.FloatPrecision is preserved. *) procedure CopyTo(const Dst: TMtxVec); overload; (*Copies matrix values to a 2D array. Copies all matrix values to a 2D array. The rows of the array will have two times as many columns, if the calling matrix object is Complex. *) procedure CopyToArray(var Dst: T2DDoubleArray); overload; (*Copies all matrix values to a 2D array.*) procedure CopyToArray(var Dst: T2DCplxArray); overload; (*Copies the matrix from a 2D array. Sizes the matrix to match the size of the 2D array and copies all the values. *) procedure CopyFromArray(const Src: T2DDoubleArray); overload; (*Sizes the matrix to match the size of the 2D array and copies all the values.*) procedure CopyFromArray(const Src: T2DCplxArray); overload; (*Sizes the Dst array to match the matrix. Sizes the Dst array to match the size of the matrix. An exception will be raised if the calling object is not complex. *) procedure SizeToArray(var Dst: T2DCplxArray); overload; (*Sizes the Dst array to match the size of the matrix The rows will have two times as many columns, if the calling matrix object is Complex. *) procedure SizeToArray(var Dst: T2DDoubleArray); overload; (*Sizes the calling matrix to match the size of the array. Sizes the calling matrix to match the size of the array. An exception will be raised if the calling object is not complex. *) procedure SizeFromArray(const Src: T2DCplxArray); overload; (*Sizes the calling matrix to match the size of the array.*) procedure SizeFromArray(const Src: T2DDoubleArray); overload; (*Copies values from vector to a matrix. Copy all Vec elements to the calling matrix. Set the calling matrix property to NrRows. Set the calling matrix property to Vec.Length div NrRow (Length = Rows*Cols). The calling matrix property is adjusted automatically. An exception is raised if Vec.Length mod NrRows <> 0. var A: Matrix; v: Vector; begin v.SetIt(true,[1, 0, 2, -1, 5, 1.2]) ; A.CopyVec(v); end; *) function CopyVec(const Vec: TVec; NrRows: Integer): TMtx; overload; (*Copy Vec elements [VecIndex]..[VecIndex+Len-1] to the calling matrix elements starting with [Row,Col]. An exception is raised if is true and bounds are overrun or if properties of the calling matrix and Vec do not match. *) function CopyVec(const Vec: TVec; VecIndex, Len, Row, Col: Integer): TMtx; overload; (*Cumulative sum for each of the matrix columns. Calculate the cumulative sum for each of the calling matrix columns in-place. var Mtx: Matrix; begin Mtx.Size(false,3,2,[1,2, 2,5, 3,1]); Mtx.CumSum; // Mtx becomes: // 1, 2 // 3, 7 // 6, 8 end; *) function CumSum: TMtx; overload; (*Calculate tehe cumulative sum for each of the X matrix columns. Store the results in calling matrix. The , and properties of the callig matrix are adjusted implicitly to match those of Mtx matrix. *) function CumSum(const Mtx: TMtx): TMtx; overload; (*Determines type of the matrix. Tests the calling matrix and returns the of the calling of matrix. The following types are supported: * mtSymmPosDef = symmetric positive definite matrix * mtSymmetric = symmetric matrix * mtHermPosDef = Hermitian positive definite matrix * mtHermitian = Hermitian matrix * mtTriangle = triangular matrix, with unit or non unit main diagonal * mtGeneral = general matrix (none of the above) Checking for positive definite matrix can be very expensive (O(n) = 1/3*n^3). Therefore the ChekPosDef parameter is False by default, unless the user specifies otherwise. The method will not detect banded matrix storage. var X,B: Vector; A: Matrix; at: TMtxType; begin B.SetIt(false,[0,2]); A.SetIt(2,2,false,[1,2, 2,4]); // 2x2 real matrix at := A.DetectMtxType; A.LUSolve(B,X,at); // This is the same for this example (except slower) A.LUSolve(B,X,mtSymmetric); // You could also specify A.AutoMtxType := True A.LUSolve(B,X); // the type is autodetected end; *) function DetectMtxType(CheckPosDef: boolean = False): TMtxType; overload; (*Convert dense matrix to banded. Convert the calling matrix stored in dense format to banded format and store the result in Dst. MaxElemCount defines the maximum number of elements that the Banded matrix may have before an exception will be raised. *) procedure DenseToBanded(Dst: TMtx; MaxElemCount: integer = 10000000); overload; (*Determinant of squared matrix. Calculate the determinant of squared real matrix. An exception is raised if the calling matrix property is true. var A: Matrix; b: double; begin A.SetIt(2,2,false,[1,2, 2,4]); // 2x2, not complex matrix b := A.Determinant; // 4 + 4 = 8 end; *) function Determinant(MtxType: TMtxType = mtGeneral): double; overload; (*Calculates the determinant of squared complex matrix. the result in result complex variable. An exception is raised if the calling matrix property is false. *) function Determinantc(MtxType: TMtxType = mtGeneral): TCplx; overload; (*Sets the matrix diagonal to values from the vector. Sets the k-th diagonal of the calling matrix to values from from the Vec object. If k = 0 then the main diagonal matrix is set, if k < 0 then the k-th subdiagonal matrix is set and if k > 0 the then the k-th super diagonal is set. The matrix must be large enough to hold diagonal or an exception is raised. var A: Matrix; D: Vector; begin A.SetIt(2,2,True,[1,1, 2,1, 1,2, 2,2]); D.SetIt(2, True,[2,2, 1,1]); A.Diag(D,0); // A becomes: // [2,2, 2,1] // [1,2, 1,1] end; *) function Diag(const Vec: TVec; k: integer): TMtx; overload; (*Calculates matrix eigenvalues and eigenvectors. Calculates the eigenvalues (stored in vector D elements) and optionally the eigenvectors (stored in matrix the columns of matrices VL and VR) of the calling matrix. The MtxType parameter indicates the calling matrix . Depending the type of the calling matrix the Eig method will use specific optimized algorithm. If you don't know the type of the calling matrix, you can not omit the MtxType parameter. To determine the type of matrix use the method, or set property to True. Depending on the MtxType parameter, the following algorithms will be used : 1) for symmetric positive definite matrix (mtSymPosDef, mtHermPosDef): a) reduce the calling matrix to tridiagonal form A=Q*T*Q' b) generate matrix Q c) find eigenvalues and eigenvectors of the tridiagonal matrix T. 2) for symmetric or hermitian matrix (mtSymetric, mtHermitian): a) reduce the calling matrix to tridiagonal form A=Q*T*Q' b) generate matrix Q c) find eigenvalues and eigenvectors of the tridiagonal matrix T. 3) for general matrix (mtGeneral): A) VectorForm = vfEig: a) perform full balance of the calling matrix b) reduce the calling matrix to Hessenberg form A=Q*H*Q' c) generate matrix Q d) find eigenvalues and left and/or right eigenvectors. e) transform eigenvectors of the balanced matrix back to those of the original matrix. B) VectorForm = vfSchur: a) perform user defined balance of the calling matrix b) reduce the calling matrix to Hessenberg form A=Q*H*Q' c) generate matrix Q d) Find the real Schur form and optionally the eigenvectors Z*T*Z'. Matrix T is the real Schur form and Z are the eigen vectors. e) transform the eigenvectors of the balanced matrix to those of the original matrix. Matrix is in real Schur form, if it is upper quasi-triangular with 1-by-1 and 2-by-2 blocks. 2-by-2 blocks are standardized in the form [ a b ] [ c a ] where b*c < 0. The eigenvalues of such a block are: a +/- sqrt(bc). Note The calling matrix property must be true, otherwise an exception is raised. This overloaded version calculates the calling matrix eigenvalues and stores them in the vector D. The and properties of the vector D are adjusted automatically. The MtxType parameter specifies the calling . If MtxType parameter is omitted, the default value mtGeneral (general matrix) will be used, but for symmetric matrices the matrix type has to be specified explicitly, because the algorithm for general matrices will fail on the symmetric matrix. The matrix Q is not explicitly generated. var D: Vector; A,V: Matrix; begin A.SetIt(2,2,False,[1,2, 2,4]); // 2x2, real matrix A.Eig(D,mtSymmetric); // or if eigenvectors are also required A.Eig(V,D,nil,mtSymmetric); // get left eigenvectors end; *) function Eig(D: TVec; MtxType: TMtxType = mtGeneral): TMtx; overload; (*Calculate the calling matrix eigenvalues and eigenvectors. Store the eigenvalues in the vector D. The Complex and Length properties of the vector D are adjusted automatically. If VectorForm is vfEig, store the left eigenvectors in matrix VL and the right eigenvectors in the matrix VR. Either of the eigenvector matrices VL and VR can be nil to indicate that they are not required. If the are both nil, an exception is raised. In case of symmetric matrices only VL is checked. The computed eigenvectors are normalized to have Euclidean norm equal to 1 and largest component real and are stored in the columns of the VL and VR matrices. If VectorForm is vfSchur, it will store the real T form in the matrix VL and the eigenvectors Z in the matrix VR. VR can be nil, to indicate that eigenvectors are not required. If VL is nil an exception is raised. The Rows, Cols and Complex properties of matrices VR and VL are adjusted automatically. The MtxType parameter specifies the calling . If MtxType parameter is omitted, the default value mtGeneral (general matrix) will be used, but for symmetric matrices the matrix type has to be specified explicitly, because the algorithm for general matrices will fail on the symmetric matrix. *) function Eig(VL:TMtx; D: TVec; VR: TMTx = nil; MtxType: TMTxType = mtGeneral; VectorForm: TVectorForm = vfEig; Expand: boolean = True): TMtx; overload; (* Computes the eigenvalues and left and right eigenvectors of A general matrix. If VL and VR are not nil, corresponding left and right eigenvectors are computed. Does not work for symmetric matrices. *) procedure Eig(D: TVec; VL, VR: TMtx); overload; (* Computes the eigenvalues and left and right eigenvectors of A general matrix. If VL and VR are not nil, corresponding left and right eigenvectors are computed. Additionally balancing can be speicifed with Balance. The info about balancing performed is stored in TEigBalancing object. This object can be nil, if no balancing was requested. If assigned the rconde parameter contains reciprocal condition number of the j-th eigenvalue. If assigned the rcondv contains reciprocal condition number of the j-th right eigenvector. Does not work for symmetric matrices. *) procedure Eig(D: TVec; Balance: TBalanceType; BInfo: TEigBalancing = nil; rconde: TVec = nil; rcondv: TVec = nil; VL: TMtx = nil; VR: TMTx = nil); overload; (*Computes eigenvalues and optionally Schure matrix Computes for an N-by-N nonsymmetric matrix A, the eigenvalues, the Schur form T, and, optionally, the matrix of Schur vectors VS. This gives the Schur factorization A = VS*T*(VS**H). Optionally the routine also orders the eigenvalues on the diagonal of the Schur form so that selected eigenvalues are at the top left. The Select function parameters accepts a function with two parameters. First is the real and the second is the imaginary part of the eigenvalue. The function is to return true, if the specified eigenvalue is to be included in to sorting at the top left of the Schur form. If sorting is not required pass nil (NULL) for this parameter. *) procedure EigSchure(D: TVec; VS: TMTx = nil; T: TMtx = nil; Select: TSelectTwoFunction = nil; cSelect: TSelectOneFunctionC = nil; SelectSingle: TSelectTwoFunctionSingle = nil; cSelectSingle: TSelectOneFunctionSingleC = nil); overload; (*Computes eigenvalues and optionally Schure matrix Computes for an N-by-N nonsymmetric matrix A, the eigenvalues, the Schur form T, and, optionally, the matrix of Schur vectors VS. This gives the Schur factorization A = VS*T*(VS**H). Optionally, it also orders the eigenvalues on the diagonal of the Schur form so that selected eigenvalues are at the top left. If this is needed specify the Select function parameter and return true for each eigenvalue desired. Optionally computes a reciprocal condition number for the average of the selected eigenvalues (rconde[0]) and computes a reciprocal condition number for the right invariant subspace corresponding to the selected eigenvalues (rcondv[0]). The leading columns of VS form an orthonormal basis for this invariant subspace. *) procedure EigSchure(D: TVec; VS, T: TMTx; rconde: TVec; rcondv: TVec; Select: TSelectTwoFunction = nil; cSelect: TSelectOneFunctionC = nil; SelectSingle: TSelectTwoFunctionSingle = nil; cSelectSingle: TSelectOneFunctionSingleC = nil); overload; (*Computes all the eigenvalues, and optionally, the eigenvectors of a generalized symmetric-definite eigenproblem. It can find solution to either of the following problems: A*X = lambda*B*X, A*B*X = lambda*X, or B*A*X = lambda*X Here A and B are assumed to be symmetric (Hermitian) and B is also positive definite. Eigenvector are stored within V in columns. var D: TVec; A,B,C: TMtx; begin CreateIt(D); CreateIt(A,B,C); try D.SetIt(2 ,False,[0,2]); // vector, length 2, real A.SetIt(2,2,False,[1,2, 2,4]); // 2x2, real matrix // A must be symmetric B.SetIt(2,2,False,[1,1, 1,2]); // 2x2, real matrix // B must be symmetric and positive definite A.EigSymGen(B,D); // Use A and B to find eigenvalues finally FreeIt(A,B,C); FreeIt(D); end; end; *) procedure EigSymGen(B: TMtx; D: TVec; V: TMtx; EigGenType: TEigGenType = etAzBz); overload; procedure EigSymGen(B: TMtx; D: TVec; EigGenType: TEigGenType = etAzBz); overload; (*Computes generalized eigenvalues with reduction of the symmetric-definite generalized eigenvalues/eigenvectors problem to the normal eigenvalue case. The routine computes selected eigenvalues and optionally also eigenvectors. The problem is of type: A*X = lambda*B*X, A*B*X = lambda*X, or B*A*X = lambda*X A and B are symmetric (Hermitian) and B is also positive definite. Eigenvalues and eigenvectors can be selected by specifying a range of values. Eigenvectors are not computed, if V is passed as nil. (NULL). Tolerance parameter specifies the absolute error tolerance for the eigenvalues. An approximate eigenvalue is accepted as converged when it is determined to lie in an interval [a,b] of width less than or equal to Tolerance + EPS / max( |a|,|b| ) , where EPS is the machine precision. If Tolerance is less than or equal to zero, then EPS*|T| will be used in its place, where |T| is the 1-norm of the tridiagonal matrix obtained by reducing A to tridiagonal form. Eigenvalues will be computed most accurately when Tolerance is set to twice the underflow threshold, not zero. If this routine returns fails , indicating that some eigenvectors did not converge, try setting Tolerance to 2*UnderflowThreshold. If V is assinged, VInfo contains values equal to 0 at indices for which eigenvector calculation converged. Eigenvector are stored within V in columns. The returned column count may vary between calls depending on the number of eigenvectors that converged. The eigenvectors are normalized as follows: etAzBz, etBAz, Z**T*B*Z = I; etABz , Z**T*inv(B)*Z = I. *) procedure EigSymGen(B: TMtx; D: TVec; Minimum, Maximum: double; V: TMtx; var VInfo: TIntegerArray; Tolerance: double = 0; EigGenType: TEigGenType = etAzBz); overload; procedure EigSymGen(B: TMtx; D: TVec; Minimum, Maximum: double; Tolerance: double = 0; EigGenType: TEigGenType = etAzBz); overload; (*Computes generalized eigenvalues with reduction of the symmetric-definite generalized eigenvalues/eigenvectors problem to the normal eigenvalue case. The routine computes selected eigenvalues and optionally also eigenvectors. The problem is of type: A*X = lambda*B*X, A*B*X = lambda*X, or B*A*X = lambda*X A and B are symmetric (Hermitian) and B is also positive definite. Eigenvalues and eigenvectors can be selected by specifying a range of indexes of values. Eigenvectors are not computed, if V is passed as nil (NULL). Tolerance parameter specifies the absolute error tolerance for the eigenvalues. An approximate eigenvalue is accepted as converged when it is determined to lie in an interval [a,b] of width less than or equal to Tolerance + EPS / max( |a|,|b| ) , where EPS is the machine precision. If Tolerance is less than or equal to zero, then EPS*|T| will be used in its place, where |T| is the 1-norm of the tridiagonal matrix obtained by reducing A to tridiagonal form. Eigenvalues will be computed most accurately when Tolerance is set to twice the underflow threshold, not zero. If this routine returns fails , indicating that some eigenvectors did not converge, try setting Tolerance to 2*UnderflowThreshold. If V is assinged, VInfo contains values equal to 0 at indices for which eigenvector calculation converged. Eigenvector are stored within V in columns. The returned column count may vary between calls depending on the number of eigenvectors that converged. The eigenvectors are normalized as follows: etAzBz, etBAz, Z**T*B*Z = I; etABz , Z**T*inv(B)*Z = I. *) procedure EigSymGen(B: TMtx; D: TVec; LowerRange, UpperRange: integer; V: TMtx; var VInfo: TIntegerArray; Tolerance: double = 0; EigGenType: TEigGenType = etAzBz); overload; procedure EigSymGen(B: TMtx; D: TVec; LowerRange, UpperRange: integer; Tolerance: double = 0; EigGenType: TEigGenType = etAzBz); overload; (*Computes eigenvalues of a symmetric (Hermitian) matrix between minimum and maximum. The computation is based on Relatively Robust Representations. Tolerance parameter specifies the absolute error tolerance for the eigenvalues. An approximate eigenvalue is accepted as converged when it is determined to lie in an interval [a,b] of width less than or equal to Tolerance + EPS / max( |a|,|b| ) , where EPS is the machine precision. If Tolerance is less than or equal to zero, then EPS*|T| will be used in its place, where |T| is the 1-norm of the tridiagonal matrix obtained by reducing A to tridiagonal form. Eigenvalues will be computed most accurately when Tolerance is set to twice the underflow threshold, not zero. If this routine returns fails , indicating that some eigenvectors did not converge, try setting Tolerance to UnderflowThreshold. *) function EigSym(D: TVec; Minimum, Maximum: double; Tolerance: double = 0): TMtx; overload; (*Computes eigenvalues and eigenvectors of a symmetric (Hermitian) matrix between minimum and maximum. The computation is based on Relatively Robust Representations. Tolerance parameter specifies the absolute error tolerance for the eigenvalues. An approximate eigenvalue is accepted as converged when it is determined to lie in an interval [a,b] of width less than or equal to Tolerance + EPS / max( |a|,|b| ) , where EPS is the machine precision. If Tolerance is less than or equal to zero, then EPS*|T| will be used in its place, where |T| is the 1-norm of the tridiagonal matrix obtained by reducing A to tridiagonal form. Eigenvalues will be computed most accurately when Tolerance is set to twice the underflow threshold, not zero. If this routine returns fails , indicating that some eigenvectors did not converge, try setting Tolerance to UnderflowThreshold. *) function EigSym(D: TVec; V: TMtx; Minimum, Maximum: double; Tolerance: double = 0): TMtx; overload; (*Computes eigenvalues and eigenvectors of a symmetric (Hermitian) matrix between min and max Index. The computation is based on Relatively Robust Representations. Tolerance parameter specifies the absolute error tolerance for the eigenvalues. An approximate eigenvalue is accepted as converged when it is determined to lie in an interval [a,b] of width less than or equal to Tolerance + EPS / max( |a|,|b| ) , where EPS is the machine precision. If Tolerance is less than or equal to zero, then EPS*|T| will be used in its place, where |T| is the 1-norm of the tridiagonal matrix obtained by reducing A to tridiagonal form. Eigenvalues will be computed most accurately when Tolerance is set to twice the underflow threshold, not zero. If this routine returns fails , indicating that some eigenvectors did not converge, try setting Tolerance to UnderflowThreshold. *) function EigSymRange(D: TVec; V: TMtx; LowRange, HighRange: integer; Tolerance: double = 0): TMtx; overload; (*Computes eigenvalues of a symmetric (Hermitian) matrix between min and max Index. The computation is based on Relatively Robust Representations. Tolerance parameter specifies the absolute error tolerance for the eigenvalues. An approximate eigenvalue is accepted as converged when it is determined to lie in an interval [a,b] of width less than or equal to Tolerance + EPS / max( |a|,|b| ) , where EPS is the machine precision. If Tolerance is less than or equal to zero, then EPS*|T| will be used in its place, where |T| is the 1-norm of the tridiagonal matrix obtained by reducing A to tridiagonal form. Eigenvalues will be computed most accurately when Tolerance is set to twice the underflow threshold, not zero. If this routine returns fails , indicating that some eigenvectors did not converge, try setting Tolerance to UnderflowThreshold. *) function EigSymRange(D: TVec; LowRange, HighRange: integer; Tolerance: double = 0): TMtx; overload; (*Computes all eigenvalues of a symmetric (Hermitian) matrix between min and max Index. The computation is based on Relatively Robust Representations. *) function EigSym(D: TVec; V: TMtx): TMtx; overload; (*Computes generalized eigenvalues and eigenvectors of a non-symmetric matrix. A generalized eigenvalue for a pair of matrices (A = Self,B) is a scalar lambda or a ratio alpha/beta = lambda, such that A - lambda*B is singular. It is usually represented as the pair (alpha,beta), as there is a reasonable interpretation for beta = 0, and even for both being zero. The right eigenvector v(j) corresponding to the eigenvalue lambda(j) of (A,B) satisfies: A * v(j] = lambda(j) * B * v(j). The left eigenvector u(j) corresponding to the eigenvalue lambda(j) of (A,B) satisfies: u(j)**H * A = lambda(j) * u(j)**H * B . where u(j)**H is the conjugate-transpose of u(j). The individual eigevalues can be computed as: lambda(j) = dAlpha(j)/dBeta(j); *) procedure EigGen(B: TMtx; DAlpha, DBeta: TVec; VL, VR: TMtx); overload; procedure EigGen(B: TMtx; DAlpha, DBeta: TVec); overload; (*Computes generalized eigenvalues and eigenvectors of a non-symmetric matrix. Computes for a pair of N-by-N real nonsymmetric matrices (A = Self,B) the generalized eigenvalues, and optionally, the left and/or right generalized eigenvectors (VL and/or VR). A generalized eigenvalue for a pair of matrices (A,B) is a scalar lambda or a ratio alpha/beta := lambda, such that A - lambda*B is singular. It is usually represented as the pair (alpha,beta), as there is a reasonable interpretation for beta = 0, and even for both being zero. The right eigenvector v(j) corresponding to the eigenvalue lambda(j) of (A,B) satisfies: A * v(j) = lambda(j) * B * v(j). The left eigenvector u(j) corresponding to the eigenvalue lambda(j) of (A,B) satisfies: u(j)**H * A = lambda(j) * u(j)**H * B . where u(j)**H is the conjugate-transpose of u(j). The individual eigevalues can be computed as: lambda(j) = dAlpha(j)/dBeta(j); Optionally also computes a balancing transformation to improve the conditioning of the eigenvalues and eigenvectors , reciprocal condition numbers for the eigenvalues (rconde), and reciprocal condition numbers for the right eigenvectors (rcondv). *) procedure EigGen(B: TMtx; DAlpha, DBeta: TVec; Balance: TBalanceType; BInfo: TEigBalancing; rconde: TVec = nil; rcondv: TVec = nil; VL: TMtx = nil; VR: TMTx = nil); overload; (*Computes generalized eigenvalues and Schur vectors of a non-symmetric matrix. It gives Schur factorization (A = Self) : (A,B) = ( VL*S*VR^T, VL*T*VR^T ) If only the generalized eigenvalues EigGen is faster. The individual eigevalues can be computed as: lambda(j) = dAlpha(j)/dBeta(j); Optionally the routine also orders the eigenvalues on the diagonal of the Schur form so that selected eigenvalues are at the top left. The Select function parameters accepts a function with four parameters. In case of real data, the first is the real and the second is the imaginary part of the eigenvalue (alpha), the third is the real beta. In case of complex data, first two are complex dAlpha and the second two complex dBeta. The function is to return true, if the specified eigenvalue is to be included in to sorting at the top left of the Schur form. If sorting is not required pass nil (NULL) for this parameter. Optionally computes a reciprocal condition number for the average of the selected eigenvalues (rconde[0], rconde[1]) and computes a reciprocal condition number for the selected deflating subspaces (rcondv[0], rcondv[1]). If condition numbers are not required, pass nil (NULL) for this parameter. *) procedure EigSchureGen(B: TMtx; DAlpha, DBeta: TVec; VL, VR, S, T: TMtx; rconde: TVec; rcondv: TVec; Select: TSelectThreeFunction = nil; cSelect: TSelectTwoFunctionC = nil; SelectSingle: TSelectThreeFunctionSingle = nil; cSelectSingle: TSelectTwoFunctionSingleC = nil); overload; procedure EigSchureGen(B: TMtx; DAlpha, DBeta: TVec; Select: TSelectThreeFunction = nil; cSelect: TSelectTwoFunctionC = nil; SelectSingle: TSelectThreeFunctionSingle = nil; cSelectSingle: TSelectTwoFunctionSingleC = nil); overload; (* Computes generalized singular value decomposition. Computes the generalized singular value decomposition (GSVD) of an M-by-N real matrix A and P-by-N real matrix B: U'*A*Q = D1*( 0 R ), V'*B*Q = D2*( 0 R ) where U, V and Q are orthogonal matrices, and Z' is the transpose of Z. The routine computes optionally the orthogonal transformation matrices U, V and Q. D1 and D2 are diagonal matrices, which on their diagonals contain C and S. K L D1 = K [ I 0 ] L [ 0 C ] M-K-L [ 0 0 ] K L D2 = L [ 0 S ] P-L [ 0 0 ] The generalized singular values, stored in C and S on exit, have the property: sqr(C) + sqr(S) = I The generalized singular value pairs of A and B in case of rank deficiency are stored like this: c(0:k-1) = 1, s(0:k-1) = 0, and if m-k-l = 0, c(k:k+l-1) = C, s(k:k+l-1) = S, or if m-k-l < 0, c(k:m-1)= C, c(m:k+l-1)=0 s(k:m-1) = S, s(m:k+l-1) = 1 and c(k+l:n-1) = 0 s(k+l:n-1) = 0 Effective rank is k + l. If B is an N-by-N nonsingular matrix, then the GSVD of A and B implicitly gives the SVD of A*inv(B): A*inv(B] := U*(D1*inv(D2))*V' If ( A',B')' has orthonormal columns, then the GSVD of A and B is also equal to the CS decomposition of A and B. Furthermore, the GSVD can be used to derive the solution of the eigenvalue problem: A'*A X := lambda* B'*B X In some literature, the GSVD of A and B is presented in the form U'*A*X := ( 0 D1 ), V'*B*X := ( 0 D2 ) where U and V are orthogonal and X is nonsingular, D1 and D2 are "diagonal". The former GSVD form can be converted to the latter form by taking the nonsingular matrix X as: X := Q*( I 0 ) ( 0 inv(R) ) The function returns the effective numerical rank of (A', B') = K + L. Reference: Lapack v3.4 source code *) function SVDGen(B: TMtx; C, S: TVec; U: TMtx; V: TMtx; Q: TMtx): integer; overload; function SVDGen(B: TMtx; C, S: TVec): integer; overload; (* Solves the linear equality-constrained least squares (LSE). Solves the linear equality-constrained least squares (LSE) problem: minimize || c - A*X ||_2 subject to B*X = d where A is an M-by-N matrix, B is a P-by-N matrix, c is a given vector of length M, and d is a given vector of length P. The sign "_2", denotes Norm L2. It is assumed that P <= N <= M+P, and rank(B) = P and rank( (A) ) = N ( (B) ) These conditions ensure that the LSE problem has a unique solution, which is obtained using a generalized RQ factorization of the matrices (B, A) given by B = (0 R)*Q, A = Z*T*Q References: 1.) Lapack v3.4 source code 2.) http://isites.harvard.edu/fs/docs/icb.topic774900.files/lec16.09.pdf 3.) http://www.cs.ucdavis.edu/~bai/publications/andersonbaidongarra92.pdf *) function LSESolve(const B: TMtx; const C, D, X: TVec): double; overload; (* Solves a general Gauss-Markov linear model (GLM) problem. The routine solves a general Gauss-Markov linear model (GLM) problem: minimize || y ||_2 subject to d = A*X + B*y X where A is an N-by-M matrix, B is an N-by-P matrix, and d is a given N-vector. It is assumed that M <= N <= M+P, and rank(A] = M and rank( A B ] = N. Under these assumptions, the constrained equation is always consistent, and there is a unique solution X and a minimal 2-norm solution y, which is obtained using a generalized QR factorization of the matrices (A, B) given by A = Q*(R), B = Q*T*Z (0) In particular, if matrix B is square nonsingular, then the problem GLM is equivalent to the following weighted linear least squares problem minimize || inv(B)*(d-A*X) ||_2 X where inv(B) denotes the inverse of B. The sign _2, denotes Norm L2. References: 1.) Lapack v3.4 source code *) procedure GLMSolve(const B: TMtx; const D, X, Y: TVec); overload; (*Compares two matrices. Compares Mtx with the calling matrix and returns true if the matrices are equal (if all elements match in position and value). Tolerance defines the comparison tolerance. The maximum difference between elements may not exceed: +/-Tolerance. If Tolerance is omitted, a direct comparison algorithm is used. var A,B: Matrix; c: boolean; begin A.SetIt(2,2,false,[1,2, 2,4]); // 2x2, real matrix B.SetIt(2,2,false,[1,2, 2,4]); // 2x2, real matrix c := A.Equal(B,1e-8); // Check for differences bigger than 0.00000001 c := (A = B); // Check for an exact match end; *) function Equal(const Mtx: TMtx; Tolerance: double = 0): boolean; overload; (*Allows to specify the comparison method via the Compare parameter.*) function Equal(const Mtx: TMtx; Tolerance: double; Compare: TCompare):boolean; overload; (*Constructs an eye matrix. Construct an eye matrix. The number of rows and columns of an eye matrix is set by ARows and ACols parameters. The property of an eye matrix is set by AComplex parameter. var A: Matrix; begin A.Eye(3,3); end; *) function Eye(ARows,ACols: integer; AComplex: boolean; AIsDouble: boolean): TMtx; overload; function Eye(ARows,ACols: integer; const aFloatPrecision: TMtxFloatPrecision): TMtx; overload; (* Applies 2D filtering Computes the dot-product between the kernel matrix and underlaying source matrix elements for each possible position of the kernel and stores the result in to the calling object. Typically the kernel is much smaller than the source matrix. The operation is equivalent to the 2D Convolution and is used also for image resampling, image blurring etc.. SrcRect must meet the following condtitions: SrcRect.Width <= (Src.Cols - Kernel.Cols) SrcRect.Height <= (Src.Rows - Kernel.Rows) KernelAnchor defines the value to be written in the destination matrix relative to the corresponding position of the Kernel in the Src matrix. This can be for example center element (Kernel.Rows div 2, Kernel.Cols div 2), top left (0,0), bottom right (Kernel.Rows-1, Kernel.Cols-1) element etc... The X and Y coordinates may not exceed Kernel row or column count. The kernel can be square or not. Symmetric or not. The only requirement is that it is rectangular. It is the users responsability to select such combination of SrcRect, Kernel size and KernelAnchor to get desired border value processing. If the Kernel is 3x3 in size, then it would make sense that SrcRect leaves out 2 rows above and below and also 2 columns left and right in the Src matrix. These regions then need to be initialized to some value for example 0 for black color or use the value of the closest border element. The DstRect defines the area to be overwritten in the destination matrix. The width and height parameters of DstRect and SrcRect need to match. The Size of the destination matrix needs to be big enough to allow DstRect position and dimensions. var H, A, B: Matrix; i: integer; SrcRect, DstRect: TRect; KernelAnchor: TPoint; begin H := [[1, 1, 1], [1, 1, 1], [1, 1, 1]]; // simple average kernel A := [[ 0, 0, 0, 0, 0, 0, 0, 0, 0], [0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5], [ 0, 0, 0, 1, 1, 1, 1, 1, 0], [ 0, 0, 0, 2, 2, 2, 2, 2, 0], [ 0, 0, 0, 3, 3, 3, 3, 3, 0], [ 0, 0, 0, 4, 4, 4, 4, 4, 0], [ 0, 0, 0, 5, 5, 5, 5, 5, 0], [ 0, 0, 0, 6, 6, 6, 6, 6, 0], [0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5]]; SrcRect := TRect.Create(3,2, A.Cols-1, A.Rows-1 ); DstRect := TRect.Create(0,0, SrcRect.Width, SrcRect.Height); KernelAnchor := TPoint.Create(H.Rows div 2, H.Cols div 2); //center element B.Size(DstRect.Height, DstRect.Width); //could be bigger also B.Filter2D( A, H, SrcRect, DstRect, KernelAnchor); // B = [[ 7.5, 10.5, 10.5, 10.5, 7.5], //top left element at Index A[2,3] // [ 12 , 18 , 18 , 18 , 12 ], // [ 18 , 27 , 27 , 27 , 18 ], // [ 24 , 36 , 36 , 36 , 24 ], // [ 30 , 45 , 45 , 45 , 30 ], // [ 23.5, 34.5, 34.5, 34.5, 23.5]] end; *) function Filter2D(const Src, Kernel: TMtx; const SrcRect, DstRect: TMtxRect; const KernelAnchor: TMtxPoint; const Buffer: TVecInt = nil): TMtx; overload; (*Applies 2D filtering. The result is stored in to the calling object. The size of the calling object is set to match SrcRect dimensions. Important: The allocated size of the destination will never be overwritten, but the value of samples on the edge of the Dst matrix could be computed from elements outside of the Src thus making them appear to be random, because uninitialized memory was being referenced, if the parameters are not set carefully. *) function Filter2D(const Src, Kernel: TMtx; const SrcRect: TMtxRect; const KernelAnchor: TMtxPoint; const Buffer: TVecInt = nil): TMtx; overload; (*Applies 2D filtering. The function will assume that Src has a border which is (Kernel.Cols div 2+1) wide on left and right and border which is (Kernel.Rows div 2 + 1) high on top and bottom. Kernel will be applied with its center element as the anchor. The filtered result will be stored in to the calling object without the extra borders. The size of the calling object is set automatically. It is the users responsability to initialize the border elements in the Src. *) function Filter2D(const Src, Kernel: TMtx; const Buffer: TVecInt = nil): TMtx; overload; (*Forward parallel in-place 1D FFT. Performs forward 1D FFT on each row of the matrix. See for more info on the forward FFT. *) function FFT1D: TMtx; overload; (*Forward parallel not in-place 1D FFT. The size of the destination is set automatically.*) function FFT1D(const Mtx: TMtx): TMtx; overload; (*Forward parallel in-place 1D FFT from real to complex. Performs forward 1D FFT from real to complex on each row of the matrix. See for more info on the forward real FFT. *) function FFT1DFromReal: TMtx; overload; (*Forward parallel not in-place 1D real to complex FFT. The size of the destination is set automatically.*) function FFT1DFromReal(const Mtx: TMtx): TMtx; overload; (*Forward two-dimentional Fast Fourier Transformation from real/complex to complex. The transformation is applied in-place. The source matrix may be real or complex. The result will be always complex. The size of the calling matrix is not changed. (rows and cols will not chage). var a: Matrix; begin a.SetIt(2,4,False, [1, 2, 3, 4, -5, 6,-7, 8]); a.FFT2D; // result will be [(12,0), ( 0,4), (-28,0), (0,-4), ( 8,0), (-4,0), ( 24,0), (-4,0)] end; *) function FFT2D: TMtx; overload; (*Forward two-dimentional Fast Fourier Transformation from real/complex to complex. The transformation is applied on data in Mtx matrix and results are saved in the calling matrix. The source matrix may be real or complex. The source matrix is not changed. The calling matrix will be complex and will be of the same size as the source matrix. (rows and cols will not chage). var a,b: Matrix; begin a.SetIt(2,4,False, [1, 2, 3, 4, -5, 6,-7, 8]); b.FFT2D(a); // result will be // [(12,0), ( 0,4), (-28,0), (0,-4), // ( 8,0), (-4,0), ( 24,0), (-4,0)] end; *) function FFT2D(const Mtx: TMtx): TMtx; overload; (*Forward two-dimentional Fast Fourier Transformation for real numbers. The transformation is applied in-place. The source matrix must be real. An exception will be raised, if the source matrix is complex. The calling matrix stays real and does not change it's size, if was set to fsfPack or to fsfPerm. If the property was set to fsfCCS then the calling matrix becomes complex and is resized up to [Rows, Cols div 2], i.e. matrix changes property, but does not reallocate storage for elements. The number of element which are involved in the transformation depends on the property . If that property is set to fsfPerm or to fsfPack, then all elements are involved into the trasformation. If that property is set to fsfCCS (which is default), then number of element which are involved into the transformation depends on the property and these rules will be followed: * Number of source columns must be even and more then two. Number of source rows must be more than two. Exception will be raised otherwise; * if is set to False, elements from range [0..Cols-2] x [0..Rows-2] will be involved into transformation; * if is set to True, elements from range [0..Cols-1] x [0..Rows-2] will be involved into transformation; Note Not all source elements are involved into transformation but all elements in the result matrix are needed for the inverse transformation. var a: Matrix; begin a.SetIt (4,4,False, [1, 2, 3, 4, -5, 6, -7, 8, 9, 12,-11, 10, 16,-15,-14, 0]); a.FFTStorageFormat := fsfCCS; a.FFTOddLength := False; // the next elements are involved into transformation // [1, 2, // -5, 6] a.FFT2DFromReal; // result will be // [(4,0), (-12,0), // (0,0), (0,0), // (2,12), (10,10), // (0,-15), (0,0)] // after inverse transformation (a.IFFT2DToReal) only elements in range // [0..Col-2] x [0..Rows-2] will be reconstructed, other elements will be undefined // [1, 2, undef, undef, // -5, 6, undef, undef, // undef, undef, undef, undef, // undef, undef, undef, undef] // // if a.FFTOddLength is set to true, // then the range of reconstruction would be [0..Col-1] x [0..Rows-2]. end; *) function FFT2DFromReal: TMtx; overload; (*Forward two-dimentional Fast Fourier Transformation from real to complex. The transformation is applied on the Mtx matrix and results are saved in the calling matrix. The Mtx matrix must be real. And exception will be raised if the source matrix is complex. The source matrix will not be changed. The calling matrix will be real and will be resized up to [Mtx.Rows,Mtx.Cols], if is set to fsfPack or to fsfPack. If is set to fsfCCS, calling matrix will be complex and will be resized up to [Mtx.Rows, Mtx.Cols div 2]. The number of element which are involved in transformation depends on the property . If that property is set to fsfPerm or to fsfPack, then all the source elements are involved into the trasformation. If that property is set to fsfCCS (which is default), then the number of elements which are involved into the transformation depends on the property and these rules will be followed: * Number of source columns must be even and more then two. Number of source rows must be more than two. Exception will be raised otherwise; * if is set to False, elements from range [0..Mtx.Cols-2] x [0..Mtx.Rows-2] will be involved into transformation; * if is set to True, elements from range [0..Mtx.Cols-1] x [0..Mtx.Rows-2] will be involved into transformation; Note Not all source elements are involved into transformation but all elements in the result matrix are needed for the inverse transformation. *) function FFT2DFromReal(const Mtx: TMtx): TMtx; overload; (*Flips the matrix elements horizontally. Flip calling matrix elements horizontally - element [row, j] = element [row, Cols-j]. This operation is performed on all calling matrix rows. var A,B: Matrix; begin A.SetIt(2,2,False,[1,2, 2,4]); // 2x2, not complex matrix B.FlipHor(A); // B becomes: // [2,1] // [4,2] end; *) function FlipHor: TMtx; overload; (*Flip all SrcMtx matrix elements horizontally and store the results in the calling matrix. The flip operation is performed on all SrcMtx matrix rows. The , and properties of callign matrix are adjusted automatically. *) function FlipHor(const SrcMtx: TMtx): TMtx; overload; (*Flips the matrix elements vertically Flip calling matrix elements vertically - element [j, col] = element [Rows-j, col]. This operation is performed on all calling matrix columns. var A,B: Matrix; begin A.SetIt(2,2,False,[1,2, 2,4]); // 2x2, not complex matrix B.FlipVert(A); // B becomes: // [2,4] // [1,2] end; *) function FlipVer: TMtx; overload; (*Flip all SrcMtx matrix elements vertically and store the results in the calling matrix. The flip operation is performed on all SrcMtx matrix columns. The , and properties of callign matrix are adjusted automatically. *) function FlipVer(const SrcMtx: TMtx): TMtx; overload; (*Constructs a Hankel matrix. Constructs a Hankel matrix whose first column is FirstColumn and whose elements are zero below the first anti-diagonal. The , and properties of the calling matrix are adjusted automatically. var v: Vector; H: Matrix; begin v.SetIt(False,[1,2,3,4]); H.Hankel(v); // H becomes: //[1 2 3 4] //[2 3 4 0] //[3 4 0 0] //[4 0 0 0] end; *) function Hankel(const FirstColumn: TVec): TMtx; overload; (*Inverse parallel in-place 1D FFT. Performs inverse 1D FFT on each row of the matrix. See for more info on the inverse FFT. NoScale parameter allows the scaling to be turned off. The scaling scales the result by 1/(Length_Of_FFT). *) function IFFT1D(NoScale: boolean = False): TMtx; overload; (*Inverse parallel not in-place 1D FFT. The size of the destination is set automatically. *) function IFFT1D(const Mtx: TMtx; NoScale: boolean = False): TMtx; overload; (*Inverse parallel in-place 1D FFT from complex to real. Performs inverse 1D FFT from complex to real on each row of the matrix. See for more info on the inverse complex to real 1D FFT. NoScale parameter allows the scaling to be turned off. The scaling scales the result by 1/(Length_Of_FFT) *) function IFFT1DToReal(NoScale: boolean = False): TMtx; overload; (*Inverse parallel not in-place 1D complex to real FFT. The size of the destination is set automatically. *) function IFFT1DToReal(const Mtx: TMtx; NoScale: boolean = False): TMtx; overload; (*Inverse two-dimensional Fast Fourier Transformation from complex to complex. Transformation is applied in-place. Source matrix must be complex. If source matrix is real, an exception will be raised. result matrix will be complex. Size of the calling matrix is not changed. NoScale parameter allows the scaling to be turned off. var a: Matrix; begin a.SetIt (2,4,False, [1, 2, 3, 4, -5, 6,-7, 8] ); a.ExtendToComplex; a.IFFT2D; // result will be // [(1.5, 0), (0, -0.5), (-3.5, 0), (0, 0.5), // [1, 0), (-0.5, 0), (3, 0), (-0.5, 0) ] end; *) function IFFT2D(NoScale: boolean = False): TMtx; overload; (*Inverse two-dimensional Fast Fourier Transformation from complex to complex. Transformation is applied on Mtx matrix and results are saved in the calling matrix. The source matrix must be complex. If source matrix is real, an exception will be raised. The source matrix is not changed. Calling matrix will be complex and will have the same size as the source matrix. NoScale parameter allows the scaling to be turned off. var a,b: Matrix; begin a.SetIt (2,4,False, [1, 2, 3, 4, -5, 6,-7, 8] ); a.ExtendToComplex; b.IFFT2D(a); // result will be // [(1.5, 0), (0, -0.5), (-3.5, 0), (0, 0.5), // (1, 0), (-0.5, 0), (3, 0), (-0.5, 0) ] end; *) function IFFT2D(const Mtx: TMtx; NoScale: boolean = False): TMtx; overload; (*Inverse two-dimensional Fast Fourier Transformation from complex to real. Transformation is applied in-place. Source matrix Complex property must be false, if was set to fsfPack or to fsfPack. Source matrix Complex property must be True, if was set to fsfCCS. The calling matrix becomes real. Size of the calling matrix is not changed if was set to fsfPack or to fsfPack. Size of calling matrix will be set to [Rows, 2*Cols], if is set to fsfCCS, i.e. matrix changes property, but does not reallocate storage for elements. All elements are involved into inverse transformation, but number of reconstructed elements depends on the property . If that property is set to fsfPerm or to fsfPack, then all elements will be reconstructed after inverse transformation. If that property is set to fsfCCS (which is default), then the number of element's which will be reconstructed depends on the property and these rules will be followed: * Number of source columns and rows must be more than one. Exception will be raised otherwise; * if is set to False, elements in range [0..Cols-2] x [0..Rows-2] will be reconstructed; * if is set to True, elements in range [0..Cols-1] x [0..Rows-2] will be reconstructed; Here Cols and Rows are the number of columns and rows of the calling matrix after the inverse transformation. Note Both properties and must be set to the same values for forward and inverse transformation to get reversible results. NoScale parameter allows the scaling to be turned off. var a: Matrix; begin a.SetIt (4,4,False, [1, 2, 3, 4, -5, 6, -7, 8, 9, 12,-11, 10, 16,-15,-14, 0]); a.FFTStorageFormat := fsfCCS; a.FFTOddLength := TRUE; // the next elements are involved into transformation // [1, 2, 3, // -5, 6, -7] a.FFT2DFromReal; // result will be // [(0,0), (-6, -10.39), // (0,0), (3, 12.12), // (12,12), (-11,10), // (0,-15), (-14,0)] a.IFFT2DToReal; // [ 1, 2, 3, 0 // -5, 6, -7, 0 // 12, 12,-11, 10 // 0,-15,-14, 0] // the next elements are reconstructed // [ 1, 2, 3, undef, // -5, 6, -7, undef, // undef, undef, undef, undef, // undef, undef, undef, undef] // // if a.FFTOddLength is set to False, // then range of reconstruction would be one column less, i.e. // [ 1, 2, undef, undef, // -5, 6, undef, undef, // undef, undef, undef, undef, // undef, undef, undef, undef] end; *) function IFFT2DToReal(NoScale: boolean = False): TMtx; overload; (*Inverse two-dimensional Fast Fourier Transformation from complex to real. Transformation is applied on source Mtx matrix and results are saved in the calling matrix. Source matrix must be real, if was set to fsfPack or to fsfPack. Check the storage format requirements to see how the complex numbers are to be stored in a real matrix. Source matrix must be complex, if was set to fsfCCS. The source matrix will not be changed. The calling matrix becomes real. Size of the calling matrix will be set to [Mtx.Rows,Mtx.Cols], if was set to fsfPack or to fsfPack. Size of calling matrix will be set to [Mtx.Rows, 2*Mtx.Cols], if is set to fsfCCS. All element are involved into the inverse transformation, but the number of reconstructed elements depends on the property . If that property is set to fsfPerm or to fsfPack, then all elements will be reconstructed after inverse transformation. If that property is set to fsfCCS (which is default), then the number of elements which will be reconstructed depends on the property and these rules will be followed: * Number of source columns and rows must be more than one. An exception will be raised otherwise; * if is set to False, elements in range [0..Cols-2] x [0..Rows-2] will be reconstructed; * if is set to True, elements in range [0..Cols-1] x [0..Rows-2] will be reconstructed; * Here Cols and Rows are the number of columns and rows of the calling matrix after the inverse transformation. Note Both properties and must be set to the same values for forward and inverse transformation to get reversible results. NoScale parameter allows the scaling to be turned off. *) function IFFT2DToReal(const Mtx: TMtx; NoScale: boolean = False): TMtx; overload; (*Calculates matrix inverse (Mtx^-1). Calculate the inverse (Mtx^-1) of the calling matrix. If the calling matrix is not , an exception is raised. Parameter determines which optimized method will be used for calculating the inverse matrix. If MtxType is omitted, the default value mtGeneral (general quadratic matrix) is used. Note The MtxType parameter is not verified. To determine if the calling matrix type is actually MtxType, use the method. var A: Matrix; begin A.SetIt(2,2,False,[1,2, 2,4]); // 2x2, real matrix A.Inv; end; *) function Inv(): TMtx; overload; (*Compute inverse of the matrix. Specify the matrix type to select the most performance efficient algorithm. *) function Inv(MtxType: TMtxType): TMtx; overload; (*The inverse of matrix elements. Calculates the inverse of all matrix elements in place. The computation occurs after first limiting the magnitude of each elements by the lower bound of Treshhold. The limiting operation is performed to avoid division by zero. Since Treshold represents a magnitude, it is always real and must always be positive. For complex versions, the magnitude of the input is limited, but the phase remains unchanged. Zero-valued input is assumed to have zero phase. To bypass the limiting operation set the Threshold to zero. var A: Matrix; begin A.SetIt(2,2,False,[1,2, 2,4]); // 2x2, not complex matrix A.InvElem(1.0e-7); end; *) function InvElem(): TMtx; overload; (*Invert all Mtx elements and store them in the calling matrix.*) function InvElem(Threshold: double): TMtx; overload; (*Invert all Mtx elements and store them in the calling matrix. The , and properties of the calling matrix are set implicitly to match Mtx matrix. If Treshold is omitted then the default value 1/MAXNUM is used. *) function InvElem(const SrcMtx: TMtx; Threshold: double = 1/MAXNUM): TMtx; overload; (*Construct the Kac (Clement) matrix. Constructs the so called Kac (Clement) (n+1)x(n+1) tridiagonal matrix, defined by: | 0, n, 0, ... , 0 | | 1, 0, n-1, 0, ..., 0 | | 0, 2, 0, n-2, 0, ... | | ...........n-1, 0, 1 | | 0, ... ........, n, 0| The eigenvalues of so defined matrix are 2k-n for k=0,1,2,...,n. *) function Kac(n: Integer): TMtx; (*The Kronecker product between two vectors. Calculates the Kronecker product between Vec1 and Vec2 and stores the result in the calling matrix. The , and properties of calling matrix are set automatically. var A: Matrix; V1,V2: Vector; begin V1.SetIt(False,[1,2,3]); V2.SetIt(False,[4,5,6]); A.Kron(V1,V2); // A becomes: // [4 5 6] // [8 10 12] // [12 15 18] end; *) function Kron(const Vec1, Vec2: TVec): TMtx; overload; function Kron(const Mtx1, Mtx2: TMtx): TMtx; overload; function LMinQR(L,Q,R: TMtx): TMtx; overload; (*Constructs lower triangular matrix. The method uses Mtx matrix to construct a lower triangular matrix. The results are stored in the calling matrix. If the ZeroLower parameter is true then the calling matrix superdiagonal elements will be set to zero - otherwise the superdiagonal elements will not be initialized. If the Diagonal boolean parameter is true then the Mtx matrix main diagonal elements will be copied to the calling matrix main diagonal elements. If the Diagonal parameter is false, the calling matrix main diagonal elements will be set to zero. var A,B: Matrix; begin A.SetIt(2,1,True,[1,2, 2,4]); // 2x2, not complex matrix B.LowerTriangle(A,True,True); // B becomes: // [1,0, // [2,4] end; *) function LowerTriangle(const Mtx: TMtx; ZeroUpper, Diagonal: boolean): TMtx; overload; (*QR or LQ factorization. Performs QR or LQ factorization. If is bigger or equal than for the calling matrix, the linear system of equations is overdetermined and the method performs QR factorization. The matrix L is not used and can be nil. If Rows is smaller than Cols, the linear system equations is underdetermined and the method performs LQ factorization. The matrix R is not used and can be nil. If the Matrix Q is nil, then it's not explicitly formed. If the pointer is not nil, the full size Q is computed. If you do not want economy size L, Q and R, set MinSize to false. The calling matrix must have full rank. If the rank is not full, use the method. var Q,R,A: Matrix; begin A.SetIt(3,2,False,[1,2, 3,4, 3,3]); A.LQR(nil,Q,R,false); end; *) function LQR(const L,Q,R: TMtx; Minimized: boolean = true): TMtx; overload; (*QR or LQ factorization. Performs QR factorization with optional pivoting or LQ factorization. The pivoting of columns in the calling matrix is performed only when P is not nil and Rows > Cols. The P[i] holds the permutation of columns in A, so that: P(A) = Q*R *) function LQR(const L,Q,R: TMtx; const P: TVecInt; Minimized: boolean = true): TMtx; overload; (*Solve overdetermined or underdetermined system of real linear equations. Solve overdetermined or underdetermined real linear systems involving a Rows-by-Cols matrix or its transpose, using a QR or LQ factorization of the calling matrix. It is assumed that the calling matrix has full rank. The following options are provided: 1.If Op = opNone and m >= n: find the least squares solution of an overdetermined system, i.e., solve the least squares problem minimize || B - A*X ||. 2.If Op = opNone and m < n: find the minimum norm solution of an underdetermined system A * X = B. 3.If Op = opTrans and m >= n: find the minimum norm solution of an undetermined system A**T * X = B. 4.If Op = opTran and m < n: find the least squares solution of an overdetermined system, i.e., solve the least squares problem minimize || B - A**T * X || 5.If Op = opHerm and m >= n: find the minimum norm solution of an undetermined system A**H * X = B. 6.If Op = opHerm and m < n: find the least squares solution of an overdetermined system, i.e., solve the least squares problem minimize || B - A**H * X ||. Note If the parameters are of TVec type (const Vectors), the routine requires less pre and post processing. *) function LQRSolve(const B, X: TMtx; const R: TMtx = nil; Op: TMtxOperation = opNone): TMtx; overload; (*Matrix version of LQRSolve. Perfroms a LQRSolve for each B and X matrices columns in single pass.*) function LQRSolve(const B, X: TVec; const R: TMtx = nil;Op: TMtxOperation = opNone): TMtx; overload; (*Rank deficient version of LQRSolve. Perfroms LQRSolve for B vector. Computes the minimum-norm solution to a linear least squares problem: minimize || A * X - B || using a complete orthogonal factorization of A. A is an M-by-N matrix which may be rank-deficient. The function returns the effective rank of the matrix A. The effective rank is determined with the rcond parameter. A is factorized in such a way that condition number of leading submatrix of A will be less then 1/rcond. Set value of rcond to 1E-6 for less strict and to 1E-3 for more strict stability conditition. If R is assigned, the function returns the factorization of matrix A. Op parameter specified the operation to be applied to A before the computation. *) function LQRSolve(const B, X: TVec; rcond: double; const R: TMtx = nil; Op: TMtxOperation = opNone): integer; overload; (*Rank deficient version of LQRSolve. Perfroms LQRSolve for each B column in one pass. Computes the minimum-norm solution to a linear least squares problem: minimize || A * X - B || using a complete orthogonal factorization of A. A is an M-by-N matrix which may be rank-deficient. The function returns the effective rank of the matrix A. The effective rank is determined with the rcond parameter. A is factorized in such a way that condition number of leading submatrix of A will be less then 1/rcond. If R is assigned, the function returns the factorization of matrix A. Op parameter specified the operation to be applied to A before the computation. *) function LQRSolve(const B,X: TMtx; rcond: double; const R: TMtx = nil; Op: TMtxOperation = opNone): integer; overload; (*General LU, Cholesky or Bunch-Kaufmann factorization. Performs a general LU, Cholesky or Bunch-Kaufmann factorization on the calling matrix and stores the results in lower triangular matrix L and upper triangular matrix U. The MtxType parameter defines which optimized method will be used to calculate the LU factorization. The P parameter stores the row permutations in the IValues. Depending on the type of the calling matrix the LU method will use specific optimized algorithm to perform the factorization. If you don't know the of the calling matrix, you can omit the MtxType parameter (the default value mtGeneral will be used) or determine the type of matrix with the method. The following methods can be used to calculate the LU factorization: * Matrix type is mtSymmPosDef, mtHermPosDef, mtBandSymmPosDef, mtBandHermPosDef : Cholesky factorization. * mtSymmetric : Bunch-Kaufmann factorization. * mtHermitian : Bunch-Kaufmann factorization (only for complex calling matrix). * mtTriangle : or method. * mtGeneral, mtBandGeneral : general m x n matrix LU factorization. Note An exception will be raised if the calling matrix property is not true and matrix storage format is not banded. var LU,A: Matrix; P: TVec; begin A.SetIt(3,2,False,[1,2, 3,4]); A.LU(LU,P); end; *) function LU(const Dst: TMtx; const P: TVecInt; MtxType: TMtxType = mtGeneral): TMtx; (*Solves system of linear equations by using LU factorization. Uses the LU factorization to solve the system of linear equations. AX = B. The matrix must be full rank. If there are more rows than columns use the least square solver and if the matrix is also rank deficient use the method. MtxType allows the selection of an optimized algorithm and Op defines the operation to be performed on the calling matrix prior to solve. LUSolve also supports banded matrices. The banded matrix storage is defined with the help of two additional properties: and . SubDiag defines the number of non-zero subdiagonals and the SuperDiag the number of non-zero super diagonals. An example of the storage format for the first sub and super diagonal: A.SubDiag := 1; A.SuperDiag := 1; A.Size(3,6); // ... [0 , ud2, ud3, ud4 ,ud5 ,ud6] first upper diagonal [md1, md2, md3, md4, md5, md6] main diagonal [ld1, ld2, ld3, ld4, ld5, 0] first lower diagonal The columns must be aligned. All the diagonals between the SubDiag and SuperDiag diagonals including the main diagonal must always be included. Similarly you can define two sub/super diagonal storage format : aXY = (X Row Index, Y Column Index) [a11, a12, a13, 0, 0, 0] [a21, a22, a23, a24, 0, 0] [a31, a32, a33, a34, a35, 0] [0, a42, a43, a44, a45, a46] [0, 0, a53, a54, a55, a56] [0, 0, 0, a64, a65, a66] A.SubDiag := 2; A.SuperDiag := 2; A.Size(5,6); [0 , 0, a13, a24 ,a35, a46] second upper diagonal [0 , a12, a23, a34, a45, a56] first upper diagonal [a11 , a22, a33, a44, a55, a66] main diagonal [a21 , a32, a43, a54, a65, 0] first lower diagonal [a31 , a42, a53, a64, 0, 0] second lower diagonal If you would like to solve X for several different B vectors (from the formula AX= B), you can pass TMtx objects to LUSolve method. With one call you solve the system for several different B vectors and save time. *) function LUSolve(const B, X: TVec; MtxType: TMtxType = mtGeneral; Operation: TMtxOperation = opNone): TMtx; overload; (*Desc Matrix version of LUSolve. Perfroms a LUSolve for each B and X matrices columns in single pass.*) function LUSolve(const B, X: TMtx; MtxType: TMtxType = mtGeneral; Operation: TMtxOperation = opNone): TMtx; overload; (*Performs factorization for LUSolve. Mtx, origMtx and ipiv contain result of factorization on exit. This result is again to be passed to the LUSolve together with B to obtain solution for X. *) function LUSolve(MtxType: TMtxType; const Mtx, OrigMtx: TMtx; const pipiv: TVecInt): TMtx; overload; (*Finds solution with an already precomputed factorization. Mtx, origMtx and ipiv contain result of factorization on exit. The factorization was obtained with a previous call to LUSolve, which did not require B and X params. *) function LUSolve(const B,X: TVec; MtxType: TMtxType; Operation: TMtxOperation; const Mtx, OrigMtx: TMtx; const pipiv: TVecInt): TMtx; overload; (*Finds solution with an already precomputed factorzation. Mtx, origMtx and ipiv contain result of factorization on exit. The factorization was obtained with a previous call to LUSolve, which did not require B and X params. *) function LUSolve(const B,X: TMtx; MtxType: TMtxType; Operation: TMtxOperation; const Mtx, OrigMtx: TMtx; const pipiv: TVecInt): TMtx; overload; (*Calculates the mean value of each of the matrix columns. Calculate the mean vale of each of the calling matrix columns and store the results in result vector. The and properties of the result vector are adjusted automatically. var A: Matrix; res: Vector; begin A.SetIt(2,2,false,[1,5, -3,6]); A.MeanCols(Res); // res = (-1.0, 5.5) //or Res := MeanCols(A); end; *) procedure MeanCols(const result: TVec); overload; (*Calculates the mean value of each of the matrix rows. Calculate the mean vale of each of the calling matrix rows and store the results in result vector. The and properties of the result vector are adjusted automatically. var A: Matrix; res: Vector; begin A.SetIt(2,2,false,[1,5, -3,6]); A.MeanRows(res); // res = (3, 1.5) end; *) procedure MeanRows(const result: TVec); overload; (*Compute matrix function as a function of matrix. The method allows you to compute any function as a function of the Src matrix. For example, a square of root of the matrix would not compute the square root of the elements of the matrix, but instead, the result would be such, that the matrix product of two resulting matrices would return the original matrix. The Params parameters allow you to specify aditional parameter for the Func function. Because the method is based on the eigenvalue decomposition and the eigenvalue, the SourceType for symmetric and symmetric positive definite matrices has to be defined explicitly. The MtxPower function declaration: function TMtx.MtxPower(Src: TMtx; Exponent: TCplx; SourceType: TMtxType = mtGeneral): TMtx; begin MtxPower := MtxFunction(Src,[Exponent],@DoToPower,SourceType); end; *) function MtxFunction(const Src: TMtx; const Params: array of TCplx; Func: TMtxFunction = nil; SourceType: TMtxType = mtGeneral): TMtx; overload; (*Calculates the matrix to integer power. Calculate the matrix to any integer power. Because the method is based on the eigenvalue decomposition and the eigenvalue, the SourceType for symmetric and symmetric positive definite matrices has to be defined explicitly. Note The algorithm for general matrices will fail on a symmetric matrix. *) function MtxIntPower(const Src: TMtx; Exponent: Integer): TMtx; overload; (*Calculates the matrix to any power, real or integer. Calculate the matrix to any power, real or integer. It can also be used to compute the square root of the matrix. Because the method is based on the eigenvalue decomposition and the eigenvalue, the SourceType for symmetric and symmetric positive definite matrices has to be defined explicitly. Note The algorithm for general matrices will fail on a symmetric matrix. *) function MtxPower(const Src: TMtx; Exponent: double; SourceType: TMtxType = mtGeneral): TMtx; overload; (*Calculate the matrix to complex power Exponent.*) function MtxPower(const Src: TMtx; Exponent: TCplx; SourceType: TMtxType = mtGeneral): TMtx; overload; (*Calculates the square root of the matrix. Calculates the square root of the Src matrix and stores the results to calling matrix. The product of the result with itself will give the original matrix. Because the method is based on the eigenvalue decomposition and the eigenvalue, the SourceType for symmetric and symmetric positive definite matrices has to be defined explicitly. Note The algorithm for general matrices will fail on a symmetric matrix. *) function MtxSqrt(const Src: TMtx; SourceType: TMtxType = mtGeneral): TMtx; overload; (*Matrix multiplication. Performs matrix multiplication, which is JIT-ed (faster) up to size 64 for square matrices. In most general case the matrix multiplication is defined by the following equation (result = calling matrix): where a and b are and variables. The default values for a and b are Cplx(1,0) and Cplx(0,0), so the above equation is reduced to: The Operation1 and Operation2 indicate additional , performed on Mtx1 and Mtx2 respectively. Default value for operation is opNone (no additional operation). The Mtx1Type and Mtx2Type parameters indicate the of Mtx1 and Mtx2 matrices. Depending what type of matrices you are multiplying, the Mul method will choose most optimized multiplication method. So, choosing the correct values for Mtx1Type and Mtx2Type can significantly speed up the multiplication. This overloaded function performs a left side multiply operation Mtx2 with Mtx1 matrix and stores the results in the calling matrix. If Operation1 and/or Operation2 parameters are specified, perform additional operation on Mtx1 or Mtx2. If Operation1 and/or Operation2 parameters are omitted, the default values (no operation) will be used. The , and properties of the calling matrix are adjusted automatically. An exception is raised is Mtx1 Cols property does not match the Mtx2 Rows property (matrix multiplication is not possible). An exception is raised, if property of Mtx1 and Mtx2 does not match. Notes 1. NOTE: If you are not sure, which of matrix are you multiplying, you can use the mtGeneral type (general case). You can also use the method to determine the type of matrix. 2. The routine is multithreaded, if specified by the environment variable. var A,B,C: Matrix; begin A.SetIt(2,2,False,[1,2, 2,4]); B.SetIt(2,2,False,[1,2, 2,4]); C.Mul(A,B); //or C := Mul(a,b); // but this is not the same as: c := a*b; //which is the same as c.MulElem(A,B);s end; *) function Mul(const Mtx1, Mtx2: TMtx): TMtx; overload; (*Left side multiply Mtx2 with Mtx1 matrix and store the results in the calling matrix. If Operation1 and/or Operation2 parameters are specified, perform additional operation on Mtx1 or Mtx2. If Operation1 and/or Operation2 parameters are omitted, the default values (no operation) will be used. The , and properties of the calling matrix are adjusted automatically. An exception is raised is Mtx1 Cols property does not match the Mtx2 Rows property (matrix multiplication is not possible). An exception is raised, if Complex property of Mtx1 and Mtx2 does not match. *) function Mul(const Mtx1, Mtx2: TMtx; Operation1: TMtxOperation; Operation2: TMtxOperation = opNone): TMtx; overload; (*Left side multiply Mtx2 with Mtx1 matrix and store the results in the calling matrix. If parameters Mtx1Type and/or Mtx2Type are specified, the optimized multiplication method will be used. If parameters Mtx1Type and/or Mtx2Type are omitted, default values (general matrix) will be used. If Operation1 and/or Operation2 parameters are specified, perform additional operation on Mtx1 or Mtx2. If Operation1 and/or Operation2 parameters are omitted, the default values (no operation) will be used. The , and properties of the calling matrix are adjusted automatically. An exception is raised is Mtx1 Cols property does not match the Mtx2 Rows property (matrix multiplication is not possible). An exception is raised, if Complex property of Mtx1 and Mtx2 does not match. *) function Mul(const Mtx1, Mtx2: TMtx; Mtx1Type: TMtxType; Mtx2Type: TMtxType = mtGeneral; Operation1: TMtxOperation = opNone; Operation2: TMtxOperation = opNone): TMtx; overload; (*Returns the matrix product of three matrices. Internally calls and does JIT-ed (faster) multiply for small square matrices. *) function Mul(const Mtx1, Mtx2, Mtx3: TMtx): TMtx; overload; (*Returns the matrix product of four matrices. Internally calls and does JIT-ed (faster) multiply for small square matrices. *) function Mul(const Mtx1, Mtx2, Mtx3, Mtx4: TMtx): TMtx; overload; (*Initializes small matrix multiply according to lapacks dgemm api standard. Initializes compute of: C = alpha*opA(A)*opB(B)+ beta*C The routine generates code by using JIT (just in time compilation) to create a kernel, which is optimized for the specified parameters. To release existing kernel and create a new one call this routine again. The process of creating a kernel is about 1000x slower than multiplying two matrices with size 2x2. The JIT targets small matrices and will fallback to standard dgemm for large matrices. The routine will set the size the calling matrix to match the size of the result of the multiplication. The actual matrix multiplication is performed by calling TMtx.MulSmall method. The function returns true, if custom code kernel was created. It returns false, if the code was routed to the default dgemm/zgemm routine, because the two matrices are too big to expect an improvement. *) function MulSmallInit(const A, B: TMtx; opA: TMtxOperation = opNone; opB: TMtxOperation = opNone; const alpha: double = 1; const beta: double = 0): boolean; overload; (*Initializes small matrix multiply according to lapacks dgemm api standard. Initializes compute of: C = alpha*opA(A)*opB(B)+ beta*C The routine generates code by using JIT (just in time compilation) to create a kernel, which is optimized for the specified parameters. To release existing kernel and create a new one call this routine again. The process of creating a kernel is about 1000x slower than multiplying two matrices with size 2x2. The JIT targets small matrices and will fallback to standard dgemm for large matrices. The routine will set the size the calling matrix to match the size of the result of the multiplication. The actual matrix multiplication is performed by calling TMtx.MulSmall method. The function returns true, if custom code kernel was created. It returns false, if the code was routed to the default dgemm/zgemm routine, because the two matrices are too big to expect an improvement. *) function MulSmallInit(const A, B: TMtx; opA: TMtxOperation; opB: TMtxOperation; const alpha: TCplx; const beta: TCplx): boolean; overload; (*Small matrix multiply. Performs arbitrary small matrix multiplication. The routine does no error checking and assumes that both A and B matrix sizes, FloatPrecision and layout do not change between calls. The size of the calling matrix is set automatically. The kernel for the particular precision is initialized with a call to MulSmallInit and released either when a new one is created or when the calling matrix is freed. *) function MulSmall(const A, B: TMtx): TMtx; overload; (*Small matrix multiply. Performs arbitrary small matrix multiplication. The routine does no error checking and assumes that both A and B matrix and for the calling matrix, the sizes, FloatPrecision, the layout and the memory location (!) do not change between calls. The matrices multiplied are those passed to the MulSmallInit routine. You can change the values in the memory allocated by those matrices, but may not resize them or resize the calling matrix. The kernel for the particular configuration is initialized with a call to MulSmallInit and released either when a new one is created or when the calling matrix is freed. *) function MulSmall: TMtx; overload; (*Matrix array multiplication. Multiplies elements in Mtx matrix with the elements in the calling matrix (array multiplication) and stores the results in calling matrix. The , and properties of both matrices must match, otherwise an exception is raised. var A,B,C: Matrix; begin A.SetIt(2,2,False,[1,2, 2,4]); B.SetIt(2,2,False,[1,2, 2,4]); C.MulElem(A,B); // C becomes: // [1, 4, // 4,16] end; *) function MulElem(const Mtx: TMtx): TMtx; overload; (*Multiplies elements in Mtx1 matrix with the elements in Mtx2 matrix (array multiplication) and stores the results in calling matrix. The , and properties of calling matrix are set implicitly to match those of Mtx1 and Mtx2 matrices. Mtx1 and Mtx2 Rows, Cols, and Complex properties must be the same, otherwise an exception is raised. *) function MulElem(const Mtx1, Mtx2: TMtx): TMtx; overload; function MulElem(const Vec: TVec; const Mtx: TMtx): TMtx; overload; function MulElem(const Mtx: TMtx; const Vec: TVec): TMtx; overload; function MulElem(const Vec1: TVec; const Vec2: TVec): TMtx; overload; (*Calculates the matrix norm-1. Calculates calling matrix norm-1. The "norm-1" is defined as the largest column sum. var A: Matrix; b: double; begin A.SetIt(2,2,false,[1,2, 2,4]); // 2x2, not complex matrix b := A.Norm1; end; *) function Norm1: double; overload; (*Calculates the matrix Frobenius norm. Calculate the calling matrix Frobenius norm. The Frobenius norm is defined as the square root of the sum of sums of squared elements of rows. An exception is raised if calling matrix property is true. var A: Matrix; b: double; begin A.SetIt(2,2,false,[1,2, 2,4]); // 2x2, not complex matrix b := A.NormFro; end; *) function NormFro: double; overload; (*Calculates the matrix infinity norm. Calculate the calling matrix infinity norm. The "infinity norm" is defined as the largest row sum. var A: Matrix; b: double; begin A.SetIt(2,2,false,[1,2, 2,4]); // 2x2, not complex matrix b := A.NormInf; // b= 6 end; *) function NormInf: double; overload; (*Constructs a Pascal matrix. Construct a Pascal matrix of order Order with integer elements, taken from the Pascal's triangle. The Pascal matrix is by definition symmetric positive definite. The Pascal matrix is written to the calling matrix. The , and properties of the calling matrix are adjusted automatically. *) function Pascl(Order: integer): TMtx; overload; (*Raises matrix elements to any power. Raises Base matrix elements to the Exponent matrix elements power and stores the results in the calling matrix. The , and properties of the calling matrix are adjusted automatically. The , and properties of Base and Exponent matrices must match otherwise an exception is raised. Note Only positive exponents can be handled if Exponent matrix is not complex. var A,B,C: Matrix; begin A.SetIt(2,2,False,[1,2, 2,4]); B.SetIt(2,2,False,[1,2, 2,4]); C.Power(A,B); // or C := Power(A,B); end; *) function PowerMtx(Base, Exponent: TMtx): TMtx; overload; (*Creates a reduced size dense matrix for screen display (bitmap) to show the matrix pattern. Creates a reduced size dense matrix for screen display (bitmap) to show the matrix pattern. Pixels parameter defines the target number of pixels to reduce and to. The size reduction method depends on what you want to see: * pdsPattern , Returns 1 for all areas with at least one nonzero value regardless of its amplitude. * pdsAverage, Average all values within an area (pixel). * pdsPeak, Return only the maximum absolute value within an area (region will become one pixel). Uses ..., MtxVecTee; var Mtx, ReducedMtx: Matrix; begin Mtx.Size(1000,1000,false); Mtx.RandGauss; // we're interested in averages, not pattern ReducedMtx.PixelDownSample(Mtx,200,pdsAverage); DrawIt(ReducedMtx); end; *) procedure PixelDownSample(Dst: TMtx; Pixels: integer = 500; Mode: TPixelDownSample = pdsPattern); overload; (*Allows to exactly specify the size of the destination matrix with PixelsHeight and PixelsWidth parameters. The source matrix can be bigger or smaller than the destination. *) procedure PixelResample(Dst: TMtx; const ZoomRect: TMtxRect; Mode: TPixelDownSample = pdsPattern); overload; (*Resizes the matrix, while preserving the values in already allocated memory. Sets the property to NewRows, property to NewCols, while preserving the values in already allocated memory. var A,B: Matrix; begin A.SetIt(2,2,False,[1,3, 2,4]); B.Resize(A,3,2,True); // B becomes: // [1,2,0, // 3,4,0]); end; *) function Resize(NewRows , NewCols: integer): TMtx; overload; (*Performs resize of the calling matrix to NewRows and NewCols. Copies the Src matrix values to the calling matrix. The elements outside the newly created matrix size are not referenced. *) function Resize(const Src: TMtx; NewRows, NewCols: integer): TMtx; overload; (*Resize and transpose. Resizes the calling matrix to NewRows and NewCols and then copies the Src matrix values to the calling matrix. The elements outside the newly created matrix size are not referenced. At the end the method also transposes the calling matrix. All this operations are performed in one single pass. *) function ResizeAndTranspose(const Src: TMtx; NewRows, NewCols: integer): TMtx; (*Rotates matrix rows 90 degrees clockwise. Rotates all calling matrix rows 90 degrees clockwise in-place (check the scheme bellow). Note This operation differs from the operation. var A,B: Matrix; begin A.SetIt(2,2,False,[1,3, 2,4]); B.Rotate90(A); end; *) function Rotate90: TMtx; overload; (*Rotate all Mtx matrix rows 90deg clockwise and store the results in calling matrix. The , and properties of the calling matrix are adjusted automatically. *) function Rotate90(const Mtx: TMtx): TMtx; overload; (*Exchanges two matrix rows. Exchange the i-th and j-th rows of the calling matrix in-place. An exception is raised if matrix bounds are overrun. The indexes i and j are zero based. (the first row has Index 0). var A,B: Matrix; begin A.SetIt(2,2,False,[1,3, 2,4]); B.RowExchange(0,1); // B becomes: // [2,4, // 1,3]); end; *) function RowExchange(i, j: integer): TMtx; overload; (*Copies values from vector to matrix column. Copy all Vec elements to the calling matrix Col column. The property of the calling matrix is adjusted automatically. An exception is raised, if array bounds are overrun. var A: Matrix; V: Vector; begin A.Size(2,1,True); V.SetIt(True,[1,2, 2,4]); // complex vector A.SetCol(V,0); end; *) function SetCol(const Vec: TDenseMtxVec; Col: integer): TMtx; overload; (*Copy vector Vec elements [VecIndex]..[VecIndex+Len-1] to the calling matrix elements [Row,Col]..[Row+Len-1,Col]. An exception is raised if condition checking is enabled and array bounds are overrun. An exception is raised, if Vec and the calling matrix complex properties do not match. *) function SetCol(const Vec: TDenseMtxVec; VecIndex, Row, Col, Len: integer): TMtx; overload; (*Sets matrix values. Sets matrix values. This method gives you the possibility to pass large arrays of elements without having to declare constant arrays. Pass all elements in A array to the calling matrix. The and properties of the calling matrix are set to ARows and ACols and the property is set to AComplex. An exception is raised if the matrix size (ARows*ACols) does not match the number of complex numbers in A. var A: Matrix; begin A.SetIt(2,2,False,[1,2, 2,4]); end; *) function SetIt(ARows, ACols: integer; AComplex: Boolean;const A: array of double): TMtx; overload; (*Copies values from vector to matrix row. Copy all Vec elements to the calling matrix Row row. The property of the calling matrix is adjusted automatically. An exception is raised, if array bounds are overrun. var A: Matrix; V: Vector; begin A.Size(1,2,True); V.SetIt(True,[1,2, 2,4]); // complex vector A.SetCol(V,0); end; *) function SetRow(const Vec: TDenseMtxVec; Row: integer): TMtx; overload; (*Copy vector Vec elements [VecIndex]..[VecIndex+Len-1] to the calling matrix elements [Row,Col]..[Row,Col+Len-1]. An exception is raised if condition checking is enabled and array bounds are overrun. An exception is raised, if Vec and the calling matrix complex properties do not match. *) function SetRow(const Vec: TDenseMtxVec; VecIndex, Row, Col, Len: integer): TMtx; overload; (*Initializes matrix values to zero. Sets the calling matrix elements [Row,Col]..[Row+ToRow,Col+ToCol] to zero. An exception is raised if is true and array bounds are overrun. *) function SetZero(Row, Col, ToRow, ToCol: integer): TMtx; overload; (*Initializes matrix values to Value. Sets the calling matrix elements [Row,Col]..[Row+ToRow,Col+ToCol] to Value. An exception is raised if is true and array bounds are overrun. *) function SetVal(const Value: double; Row, Col, ToRow, ToCol: integer): TMtx; overload; (*Sets the calling matrix elements [Row,Col]..[Row+ToRow,Col+ToCol] to complex value Value. properties of the calling object are set to true even before the call it was false. An exception is raised if array bounds are overrun. *) function SetVal(const Value: TCplx; Row, Col, ToRow, ToCol: integer): TMtx; overload; (*Sets the size of matrix. Set the calling matrix properties: = ARows, = ACols and See cref="Complex"/> = AComplex. Calling the Size method does not preserve the contents of the matrix. Use the Resize method, if you want to preserve existing values. The floating point precision is defined with aIsDouble. Note The Size method performs an out-of-memory safe resize, if the matrix already has memory allocated. This prevents out of memory message for example when redefining the size of the matrix from single column to single row: A.Rows := 10000; // matrix size = 0 A.Cols := 1; // matrix size = 10000 // ... A.Cols := 10000; // matrix size = 100 000 000 (problems here) A.Rows := 1; // matrix size = 10 000 var A: Matrix; begin A.Size(2,1,True, true); // 2x1 complex double matrix A.SetZero; // A becomes: // [0,0] // [0,0] end; *) function Size(const ARows, ACols: integer; const AComplex: boolean; const AIsDouble: boolean): TMtx ; overload; (*Specifies size of the matrix. Set the following matrix properties: = ARows, = ACols and See cref="FloatPrecision"/> = aFloatPrecision. Calling the Size method does not preserve the contents of the matrix. Use the Resize method, if you want to preserve existing values. *) function Size(const ARows, ACols: integer; const aFloatPrecision: TMtxFloatPrecision): TMtx ; overload; (*Specifies size of the matrix. Set the following matrix properties: = ARows, = ACols and See cref="FloatPrecision"/> = aFloatPrecisionRef.FloatPrecision. Calling the Size method does not preserve the contents of the matrix. Use the Resize method, if you want to preserve existing values. *) function Size(const ARows, ACols: integer; const aFloatPrecisionRef: TMtxVec): TMtx ; overload; (*Sets the size of matrix. Set the calling matrix properties: = ARows, = ACols and See cref="Complex"/> = AComplex. Existing floating point precision is preserved. Calling the Size method does not preserve the contents of the matrix. Use the Resize method, if you want to preserve existing values. *) function Size(const ARows, ACols: integer; const AComplex: boolean): TMtx ; overload; (*Sets the size of matrix. Set the calling matrix properties: = ARows, = ACols and See cref="Complex"/> = false. Existing floating point precision is preserved. Calling the Size method does not preserve the contents of the matrix. Use the Resize method, if you want to preserve existing values. *) function Size(const ARows, ACols: integer): TMtx ; overload; (*Sorts the elements in a matrix row(s) in ascending order. Sorts the elements in calling matrix row(s) in ascending order in-place. If the calling matrix is complex, then complex values are first compared by the absolute value and then by the argument. Note Wach row is sorted independently from the other. var A: Matrix; begin A.SetIt(2,2,False,[1,2, 4,2]); A.SortAscend; // A becomes: // [1,2] // [2,4] end; *) function SortAscend: TMtx; overload; (*Performs row based sort in ascending order. The Col parameter defines the column based on which the rows are compared with each other.*) function SortAscend(Col: integer): TMtx; overload; (*Sorts the elements in a matrix row(s) in descending order. Sorts the elements in calling matrix row(s) in descending order in-place. If the calling matrix is complex, then complex values are first compared by the absolute value and then by the argument. Note Each row is sorted independently from the other. var A: Matrix; begin A.SetIt(2,2,False,[1,2, 4,2]); A.SortDescend; // A becomes: // [2,1] // [4,2] end; *) function SortDescend: TMtx; overload; (*Performs row based sort in descending order. The Col parameter defines the column based on which the rows are compared with each other.*) function SortDescend(Col: integer): TMtx; overload; (*Standard deviation for matrix columns. Calculates the standard deviation for each of the calling matrix columns and stores the results in vector result. An exception is raised if calling matrix is complex. The Length and Complex properties of the result vector are adjusted automatically. *) procedure StdDevCols(const result: TVec); (*Standard deviation for matrix rows. Calculates the standard deviation for each of the calling matrix rows and stores the results in vector result. An exception is raised if calling matrix is complex. The Length and Complex properties of the result vector are adjusted automatically. *) procedure StdDevRows(const result: TVec); (*Singular value decomposition. Performs a singular value decomposition on a calling matrix (A). U or V can be nil, if not desired. If you do not want economy size U and V set MinSize to False. The singular value decomposition (SVD) of the calling matrix (A, with m rows and n cols) is defined by the following equation: where U and V are unitay (for complex A) or orthogonal (for real A). S is a diagonal matrix with real diagonal elements is: The diagonal elements are singular values of A (calling matrix). The first min(m, n) columns of the matrices U and V are, respectively, left and right singular vectors of calling matrix (A). The singular values and singular vectors satisfy: where ui and vi are the i-th columns of U and V, respectively. One interpretation of the singular values is as follows. If you take a unit sphere in n-dimensional space, and multiply each vector in it by an m x n matrix , you will get an ellipsoid in m-dimensional space. The singular values give the lengths of the principal axes of the ellipsoid. If the matrix is singular in some way, this will be reflected in the shape of the ellipsoid. In fact, the ratio of the largest singular value of a matrix to the smallest one gives a of the matrix, which determines, for example, the accuracy of numerical matrix inverses. Very small singular values are usually numerically meaningless. var A,U,V: Matrix; S: Vector; begin A.SetIt(3,3,True, [2, 5, 12, 1, 5, 2.5, -4, 2, 8, 0, 0, 3, 2, 0, 4, 8, 12, 8]); A.SVD(U,S,V); // S = [21.3406,10.9726,3.7989] end; *) function SVD(S: TVec): TMtx; overload; (*Matrix version of SVD. Perfroms a SVD for each U and V matrices columns in single pass.*) function SVD(U: TMtx; S: TVec; V: TMtx; MinSize: boolean = True): TMtx; overload; (*Calculates the minimum norm solution to a real linear least squares problem. Calculates the minimum norm solution to a real linear least squares problem. Minimize 2-norm(| b - A*x |). using the singular value decomposition (SVD) of the calling matrix A. A is an Rows-by-Cols matrix which may be rank-deficient. Several right hand side vectors b and solution vectors x can be handled in a single call. The effective rank of A is determined by treating as zero those singular values which are less than Threshold times the largest singular value and is returned by the function. The S vector holds the singular values on the output. var X,B,D: Vector; V: Matrix; begin B.SetIt(false,[0,2,3]); V.SetIt(3,3,false,[1,2,3, 3,4,5, 6,7,7]); V.SVDSolve(B,X,D); // matrix V can be non-quadratic end; *) function SVDSolve(B, X, S: TVec; Threshold: double = 1E-9): integer; overload; (*Matrix version of SVDSolve. Perfroms a SVDSolve for each U and V matrices columns in single pass.*) function SVDSolve(B, X: TMtx; S: TVec; Threshold: double = 1E-9): integer; overload; (*Solves the Sylvester equation. Solves the Sylvester's equation for real quasi-triangular or complex triangular matrices A and B. The solution (X) overwrites the C matrix. The AOp and BOp parameters indicate the performed on A and B respectively. The of the Sylvester equation is determined with the ASign parameter (siPlus for +, siMinus for -). The result of a Sylvester function is a scale factor a. The A and B matrices property must be true, otherwise an exception is raised. *) function Sylvester(A, B, C: TMtx; ASign: TSign = siPlus; AOp: TMtxOperation = opNone; BOp: TMtxOperation = opNone): double; overload; (*Saves matrix data to MatrixMarket ASCII file format. Saves matrix data to ASCII file format. *) procedure SaveToMatrixMarketFile(FileName: string); (*Splits matrix in blocks. Splits the calling matrix in blocks. Example: [ A B ] [ C D ] where A,B,C,D are matrices of size 2x2 and the calling matrix is of size 4x4. ARows and ACols define the number of rows and columns of the block based matrix. The matrices passed in the dst array to be filled with values from the calling matrix, must already have matching size and complex properties to cover the calling matrix or an exception will be raised. var A,B,C,D,E: Matrix; begin A.Size(2,2); B.Size(A); C.Size(A); D.Size(A); E.SetIt(4,4,False,[1,2,3,4 5,6,7,8 9,1,2,3 4,5,6,7]); E.Split(2,2,[A,B, C,D]); // A becomes: // [1,2, // 5,6] // B becomes: // [3,4, // 7,8] // C becomes: // [9,1, // 4,5] // D becomes: // [2,3, // 6,7] end; *) procedure Split(ARows, ACols: integer;const Dst: array of TMtx); (*The sum of each of the calling matrix columns. Calculates the sum of each of the calling matrix columns and stores the results in Dst vector. The and properties of the Dst vector are adjusted automatically. var A: Matrix; V: Vector; begin A.Size(2,2,False,[[1,5, 2,3]); A.SumCols(V); // V = [3,8] end; *) procedure SumCols(Dst: TVec); overload; (*The sum of each of the calling matrix rows. Calculates the sum of each of the calling matrix rows and stores the results in Dst vector. The and properties of the Dst vector are adjusted automatically. var A: Matrix; V: Vector; begin A.Size(2,2,False,[[1,2, 2,4]); A.SumRows(V); // V = [3,6] end; *) procedure SumRows(Dst: TVec); overload; (*Calculates the tensor product of two vectors. Calculates the tensor product of Vec1 and Vec2 vectors and stores the results in the calling matrix. The property is set to Vec1. and property is set to Vec2.. The property of the calling matrix is adjusted automatically. var Vec1,Vec2: Vector; V: Matrix; begin Vec1.Size(3); Vec1.SetIt(false,[0,2,3] Vec2.Copy(Vec1); V.TensorProd(Vec1,Vec2); // V becomes: // [0,0,0] // [0,4,6] // [0,6,9] end; *) function TensorProd(const Vec1, Vec2: TVec): TMtx; overload; (*Constructs a Toeplitz matrix. Constructs a Toeplitz matrix with first row equal to FirstRow vector and first column equal to FirstCol vector, but without the first element. The , and properties of the calling matrix are adjusted automatically. An exception is raised if FirstRow and FirstCol Complex properties do not match. var V1,V2: Vector; T: Matrix; begin V1.SetIt(False,[1,2,3,4]); V2.SetIt(False,[2,3,4]); T.Toeplitz(V1,V2); // T becomes: //[1 2 3 4] //[2 1 2 3] //[3 2 1 2] //[4 3 2 1] end; *) function Toeplitz(FirstRow,FirstCol: TVec): TMtx; overload; (*Constructs a Toeplitz matrix with first row equal to FirstRow vector and first column equal to FirstRow vector, but without the first element.*) function Toeplitz(FirstRow: TVec): TMtx; overload; (*Matrix trace. the trace of the calling matrix. If the calling matrix property is false, the imaginary part is set to zero. *) function Trace: TCplx; overload; (*Transposes matrix. Transposes calling matrix in-place. Instead of using transpose directly, try using the parameter of many TMtx methods. If this operation can not be avoided try using the not-in-place version (see bellow) or see the method. var A: Matrix; begin A.Size(2,1,True); // 2x1 complex matrix A.SetVal(Cplx(3,4)); A.Transp; end; *) function Transp: TMtx; overload; (*Transpose the Mtx matrix and write the results to the calling matrix. The , and properties of the calling matrix are adjusted automatically. *) function Transp(const Mtx: TMtx): TMtx; overload; (*Constructs upper triangular matrix. The method uses Mtx matrix to construct an upper triangular matrix. The results are stored in the calling matrix. If the ZeroLower parameter is true then the calling matrix subdiagonal elements will be set to zero - otherwise the subdiagonal elements will not be initialized. If the Diagonal boolean parameter is true then the Mtx matrix main diagonal elements will be copied to the calling matrix main diagonal elements. If the Diagonal parameter is false, the calling matrix main diagonal elements will be set to zero. var A,B: Matrix; begin A.SetIt(2,1,True,[1,2, 2,4]); // 2x2, not complex matrix B.UpperTriangle(A,True,True); // B becomes: // [1,2, // [0,4] end; *) function UpperTriangle(const Mtx: TMtx; ZeroLower, Diagonal: boolean): TMtx; overload; (*Construct VanderMonde matrix. Constructs a VanderMonde matrix with Vec. rows and ACols columns. The second to last column of the VanderMonde matrix is Vec: *) function VanderMonde(ACols: Integer; Vec: TVec): TMtx; overload; (*Transforms matrix into matrix of standardized data. The routine uses Data matrix and transforms it into ZScore matrix of standardized data (the so called Z Scores). The standardization of each column (variable) is made by subtracting its mean and dividing by its standard deviation: Column - Mean(Column) Z(Column) = ----------------------- StdDev(Column) var Data, Res: Matrix; begin Data.SetIt(3,3,false,[1,2,3, 4,5,6, 7,100,12]); Res.ZScore(Data); // Res = (-1 -0,604 -0,873, // 0 -0,55 -0,218 // 1 1,154 1,091) end; *) function ZScore(const Src: TMtx): TMtx; overload; (*Converts the content of the matrix Values array to a list of strings. Convert all elements of the calling matrix to strings with formating real parts with ReFormat, imaginary parts with ImFormat, using the text delimiter Delimiter and store them in aList, by using the Add method of TStrings object. Performance note: This routine will be exceedingly slow, if TRichEdit.Lines or TMemo.Lines are passed as a parameter for dstList. Use TStringList or StringList types and then call TMemo.Lines.AddStrings(yourList) for best results. procedure TForm1.Button1Click(Sender: TObject); var a,b: Matrix; begin a.SetIt(2,2,False,[1,2,3,4]); a.Cos; b.Size(a); b.SetVal(1); a := a + b; Richedit1.Clear; Memo1.Clear; a.ValuesToStrings(Richedit1.Lines); b.ValuesToStrings(Richedit1.Lines); a.ValuesToStrings(Memo1.Lines); b.ValuesToStrings(Memo1.Lines); Memo1.Lines.SaveToFile('C:\Test.txt'); Memo1.Lines.LoadFromFile('C:\Test.txt'); a.StringsToValues(Memo1.Lines); end; *) function ValuesToStrings(const dstList: TStrings; const Delimiter: string = kTab; const Align: TFixedTextAlign = ftaNone; const ReFormat: string = ' 0.###;-0.###'; const ImFormat: string = '+0.###i;-0.###i'; const Headers: boolean = false; const ColumnWidth: integer = -1): integer; overload; (*Convert calling matrix elements, starting with [Row,Col] and converting Len elements to strings with formating real parts with ReFormat, imaginary parts with ImFormat. Uses the text delimiter Delimiter and store them in aList starting at ListIndex. If aList is not large enough, the method will use the add method of aList object. Performance note: This routine will be exceedingly slow, if TRichEdit.Lines or TMemo.Lines are passed as a parameter for dstList. Use TStringList or StringList types and then call TMemo.Lines.AddStrings(yourList) for best results. *) function ValuesToStrings(const dstList: TStrings; ListIndex,Row,Col,RowCount,ColCount: integer; const Delimiter: string = kTab; const Align: TFixedTextAlign = ftaNone; const ReFormat: string = ' 0.###;-0.###'; const ImFormat: string = '+0.###i;-0.###i'; const Headers: boolean = false; const ColumnWidth: integer = -1): integer; overload; (* Converts data to delimited string using Delimiter and number formatting options. Pass empty string to ReFormat and ImFormat to indicate general number formatting. *) function ValuesToText(Delimiter: string = kTab; const ReFormat: string = ' 0.###;-0.###'; const ImFormat: string = '+0.###i;-0.###i'): String; (* Converts text delimited with Delimiter to numbers. *) function TextToValues(Text: String; Delimiter: String = kTab): TMtx; (*Convert strings to double (TCplx) and store them in the Values array. Convert strings in aList to double (real number) and store them in the Values array of the calling matrix. property is set to aList.Count. and propertes are auto-detected. Complex numbers must follow the format: a+bi. All strings must have the same number of columns (numbers). Columns must be separated with a Delimiter. By default the delimiter is the tab charachter. var a,b: Matrix; begin a.SetIt(2,2,False,[1,2,3,4]); b.Size(a); b.SetVal(1); a := Cos(a) + b; Richedit1.Clear; Memo1.Clear; a.ValuesToStrings(Richedit1.Lines); b.ValuesToStrings(Richedit1.Lines); a.ValuesToStrings(Memo1.Lines); b.ValuesToStrings(Memo1.Lines); Memo1.Lines.SaveToFile('C:\Test.txt'); Memo1.Lines.LoadFromFile('C:\Test.txt'); a.StringsToValues(Memo1.Lines); end; *) function StringsToValues(aList: TStrings; const Delimiter: string = kTab): TMtx; overload; (*Convert strings from [ListIndex]..[ListIndex+ListLen-1] in aList to double (TCplx). Store them in the Values array of the calling matrix, starting from element [Row,Cols]. The size of the calling matrix is not changed. If array bounds are overrun an exception is raised. Complex numbers must follow the format: a+bi. *) function StringsToValues(aList: TStrings; ListIndex,ListLen, Row,Col: Integer; Delimiter: string = kTab): TMtx; overload; end; VectorDouble = Vector; MatrixDouble = Matrix; (*Vector matrix multiply returning Vector type result. Internally calls *) function Mul(const Left: TVec; const Right: TMtx): Vector; overload; (*Matrix vector multiply returning Vector type result. Internally calls *) function Mul(const Left: TMtx; const Right: TVec): Vector; overload; (*Tensor product of two vectors returning Matrix type result. Internally calls *) function Mul(const Left: TVec; const Right: TVec): Matrix; overload; (*Divide Left vector with right matrix (matrix division) returning Vector type result. Internally calls *) function Divide(const Left: TVec; const Right: TMtx): Vector; overload; (*Divide Left with Right (matrix division) returning Matrix type result. Internally calls *) function Divide(const Left: TMtx; const Right: TMtx): Matrix; overload; (*Left divide Left with Right (matrix division) returning Vector type result. Internally calls *) function LDivide(const Left: TMtx; const Right: TVec): Vector; overload; (*Left divide Left with Right (matrix division) returning Matrix type result. Internally calls *) function LDivide(const Left: TMtx; const Right: TMtx): Matrix; overload; (*Compute the Inverse of the matrix and return it as result. Internally calls *) function Inverse(const X: TMtx; MtxType: TMtxType = mtGeneral): Matrix; overload; (*Transpose of the matrix and return it as result. Internally calls *) function Transp(const X: TMtx): Matrix; overload; (*Adjungate the matrix and return it as result. Internally calls *) function Adjung(const X: TMtx): Matrix; overload; (*Subrange the source vector. Internally calls *) function Select(const Src: TVec; StartIndex, Step, StopIndex: integer): Vector; overload; (*Subrange the source vector without copy operation. Internally calls *) function Select(const Src: TVec; StartIndex, StopIndex: integer): Vector; overload; (*Subrange the source matrix and return a vector. Internally calls *) function Select(const Src: TMtx; StartIndex, Step, StopIndex: integer): Vector; overload; (*Subrange the source matrix and return a vector without copy operation. Internally calls *) function Select(const Src: TMtx; StartIndex, StopIndex: integer): Vector; overload; (*Compute the sin function from the source and return the result. Internally calls *) function Sin(const X: TVec): Vector; overload; (*Compute the sin function from the source and return the result. Internally calls *) function Sin(const X: TMtx): Matrix; overload; (*Compute the cos function from the source and return the result. Internally calls *) function Cos(const X: TVec): Vector; overload; (*Compute the cos function from the source and return the result. Internally calls *) function Cos(const X: TMtx): Matrix; overload; (*Compute the Tan function from the source and return the result. Internally calls *) function Tan(const X: TVec): Vector; overload; (*Compute the Tan function from the source and return the result. Internally calls *) function Tan(const X: TMtx): Matrix; overload; (*Compute the Cot function from the source and return the result. Internally calls *) function Cot(const X: TVec): Vector; overload; (*Compute the Cot function from the source and return the result. Internally calls *) function Cot(const X: TMtx): Matrix; overload; (*Compute the Sec function from the source and return the result. Internally calls *) function Sec(const X: TVec): Vector; overload; (*Compute the Sec function from the source and return the result. Internally calls *) function Sec(const X: TMtx): Matrix; overload; (*Compute the Csc function from the source and return the result. Internally calls *) function Csc(const X: TVec): Vector; overload; (*Compute the Csc function from the source and return the result. Internally calls *) function Csc(const X: TMtx): Matrix; overload; (*Compute the ArcSin function from the source and return the result. Internally calls *) function ArcSin(const X: TVec): Vector; overload; (*Compute the ArcSin function from the source and return the result. Internally calls *) function ArcSin(const X: TMtx): Matrix; overload; (*Compute the ArcCos function from the source and return the result. Internally calls *) function ArcCos(const X: TVec): Vector; overload; (*Compute the ArcCos function from the source and return the result. Internally calls *) function ArcCos(const X: TMtx): Matrix; overload; (*Compute the ArcTan function from the source and return the result. Internally calls *) function ArcTan(const X: TVec): Vector; overload; (*Compute the ArcTan function from the source and return the result. Internally calls *) function ArcTan(const X: TMtx): Matrix; overload; (*Compute the ArcTan2 function from X and Y and return the result. Internally calls *) function ArcTan2(const Y, X: TVec): Vector; overload; (*Compute the ArcTan2 function from X and Y and return the result. Internally calls *) function ArcTan2(const Y, X: TMtx): Matrix; overload; (*Compute the ArcCot function from the source and return the result. Internally calls *) function ArcCot(const X: TVec): Vector; overload; (*Compute the ArcCot function from the source and return the result. Internally calls *) function ArcCot(const X: TMtx): Matrix; overload; (*Compute the ArcSec function from the source and return the result. Internally calls *) function ArcSec(const X: TVec): Vector; overload; (*Compute the ArcSec function from the source and return the result. Internally calls *) function ArcSec(const X: TMtx): Matrix; overload; (*Compute the ArcCsc function from the source and return the result. Internally calls *) function ArcCsc(const X: TVec): Vector; overload; (*Compute the ArcCsc function from the source and return the result. Internally calls *) function ArcCsc(const X: TMtx): Matrix; overload; (*Compute the Sinh function from the source and return the result. Internally calls *) function Sinh(const X: TVec): Vector; overload; (*Compute the Sinh function from the source and return the result. Internally calls *) function Sinh(const X: TMtx): Matrix; overload; (*Compute the Cosh function from the source and return the result. Internally calls *) function Cosh(const X: TVec): Vector; overload; (*Compute the Cosh function from the source and return the result. Internally calls *) function Cosh(const X: TMtx): Matrix; overload; (*Compute the Tanh function from the source and return the result. Internally calls *) function Tanh(const X: TVec): Vector; overload; (*Compute the Tanh function from the source and return the result. Internally calls *) function Tanh(const X: TMtx): Matrix; overload; (*Compute the Coth function from the source and return the result. Internally calls *) function Coth(const X: TVec): Vector; overload; (*Compute the Coth function from the source and return the result. Internally calls *) function Coth(const X: TMtx): Matrix; overload; (*Compute the Sech function from the source and return the result. Internally calls *) function Sech(const X: TVec): Vector; overload; (*Compute the Sech function from the source and return the result. Internally calls *) function Sech(const X: TMtx): Matrix; overload; (*Compute the Csch function from the source and return the result. Internally calls *) function Csch(const X: TVec): Vector; overload; (*Compute the Csch function from the source and return the result. Internally calls *) function Csch(const X: TMtx): Matrix; overload; (*Compute the ArcSinh function from the source and return the result. Internally calls *) function ArcSinh(const X: TVec): Vector; overload; (*Compute the ArcSinh function from the source and return the result. Internally calls *) function ArcSinh(const X: TMtx): Matrix; overload; (*Compute the ArcCosh function from the source and return the result. Internally calls *) function ArcCosh(const X: TVec): Vector; overload; (*Compute the ArcCosh function from the source and return the result. Internally calls *) function ArcCosh(const X: TMtx): Matrix; overload; (*Compute the ArcTanh function from the source and return the result. Internally calls *) function ArcTanh(const X: TVec): Vector; overload; (*Compute the ArcTanh function from the source and return the result. Internally calls *) function ArcTanh(const X: TMtx): Matrix; overload; (*Compute the ArcCoth function from the source and return the result. Internally calls *) function ArcCoth(const X: TVec): Vector; overload; (*Compute the ArcCoth function from the source and return the result. Internally calls *) function ArcCoth(const X: TMtx): Matrix; overload; (*Compute the ArcSech function from the source and return the result. Internally calls *) function ArcSech(const X: TVec): Vector; overload; (*Compute the ArcSech function from the source and return the result. Internally calls *) function ArcSech(const X: TMtx): Matrix; overload; (*Compute the ArcCsch function from the source and return the result. Internally calls *) function ArcCsch(const X: TVec): Vector; overload; (*Compute the ArcCsch function from the source and return the result. Internally calls *) function ArcCsch(const X: TMtx): Matrix; overload; (*Compute the Abs function from the source and return the result. Internally calls *) function Abs(const X: TVec): Vector; overload; (*Compute the Abs function from the source and return the result. Internally calls *) function Abs(const X: TMtx): Matrix; overload; (*Compute the Cbrt function from the source and return the result. Internally calls *) function Cbrt(const X: TVec): Vector; overload; (*Compute the Cbrt function from the source and return the result. Internally calls *) function Cbrt(const X: TMtx): Matrix; overload; (*Compute the Ceil function from the source and return the result. Internally calls *) function Ceil(const X: TVec): Vector; overload; (*Compute the Ceil function from the source and return the result. Internally calls *) function Ceil(const X: TMtx): Matrix; overload; (*Compute the Ln function from the source and return the result. Internally calls *) function Ln(const X: TVec): Vector; overload; (*Compute the Ln function from the source and return the result. Internally calls *) function Ln(const X: TMtx): Matrix; overload; (*Compute the Log10 function from the source and return the result. Internally calls *) function Log10(const X: TVec): Vector; overload; (*Compute the Log10 function from the source and return the result. Internally calls *) function Log10(const X: TMtx): Matrix; overload; (*Compute the Log2 function from the source and return the result. Internally calls *) function Log2(const X: TVec): Vector; overload; (*Compute the Log2 function from the source and return the result. Internally calls *) function Log2(const X: TMtx): Matrix; overload; (*Compute the Exp function from the source and return the result. Internally calls *) function Exp(const X: TVec): Vector; overload; (*Compute the Exp function from the source and return the result. Internally calls *) function Exp(const X: TMtx): Matrix; overload; (*Compute the Exp2 function from the source and return the result. Internally calls *) function Exp2(const X: TVec): Vector; overload; (*Compute the Exp2 function from the source and return the result. Internally calls *) function Exp2(const X: TMtx): Matrix; overload; (*Compute the Exp10 function from the source and return the result. Internally calls *) function Exp10(const X: TVec): Vector; overload; (*Compute the Exp10 function from the source and return the result. Internally calls *) function Exp10(const X: TMtx): Matrix; overload; (*Returns the imaginary part of the source. Internally calls *) function ImagPart(const X: TVec): Vector; overload; (*Returns the imaginary part of the source. Internally calls *) function Imag(const X: TVec): Vector; overload; (*Returns the imaginary part of the source. Internally calls *) function ImagPart(const X: TMtx): Matrix; overload; (*Returns the imaginary part of the source. Internally calls *) function Imag(const X: TMtx): Matrix; overload; (*Compute the integer power function. Internally calls *) function IntPower(const Base: TVec; Exponent: integer): Vector; overload; (*Compute the integer power function. Internally calls *) function IntPower(const Base: TMtx; Exponent: integer): Matrix; overload; (*Compute 1/X. Internally calls *) function Inv(const X: TVec): Vector; overload; (*Compute 1/X. Internally calls *) function Inv(const X: TMtx): Matrix; overload; (*Compute 1/X. Internally calls *) function Inv(const X: TVec; Threshold: double): Vector; overload; (*Compute 1/X. Internally calls *) function Inv(const X: TMtx; Threshold: double): Matrix; overload; (*Compute (1/X)^2. Internally calls *) function InvSqrt(const X: TVec): Vector; overload; (*Compute (1/X)^2. Internally calls *) function InvSqrt(const X: TMtx): Matrix; overload; (*Compute (1/X)^2. Internally calls *) function InvCbrt(const X: TVec): Vector; overload; (*Compute (1/X)^2. Internally calls *) function InvCbrt(const X: TMtx): Matrix; overload; (*Return complex conjugate of the source. Internally calls *) function Conj(const X: TVec): Vector; overload; (*Return complex conjugate of the source. Internally calls *) function Conj(const X: TMtx): Matrix; overload; (*Extend the source to complex numbers. Internally calls *) function ExtendToComplex(const X: TVec; Zeros: boolean = true): Vector; overload; (*Extend the source to complex numbers. Internally calls *) function ExtendToComplex(const X: TMtx; Zeros: boolean = true): Matrix; overload; (*Make the angle fit within +/- PI. Internally calls *) function FixAngle(const X: TVec): Vector; overload; (*Make the angle fit within +/- PI. Internally calls *) function FixAngle(const X: TMtx): Matrix; overload; (*Compute the floor function from the source. Internally calls *) function Floor(const X: TVec): Vector; overload; (*Compute the floor function from the source. Internally calls *) function Floor(const X: TMtx): Matrix; overload; (*Computes the e^xj function from the source. Internally calls *) function Expj(const X: TVec): Vector; overload; (*Computes the e^xj function from the source. Internally calls *) function Expj(const X: TMtx): Matrix; overload; (*Return the fractional part of a real number in the source. Internally calls *) function Frac(const X: TVec): Vector; overload; (*Return the fractional part of a real number in the source. Internally calls *) function Frac(const X: TMtx): Matrix; overload; (*Exchange the real and imaginary parts of complex numbers. Internally calls *) function Flip(const X: TVec): Vector; overload; (*Exchange the real and imaginary parts of complex numbers. Internally calls *) function Flip(const X: TMtx): Matrix; overload; (*Exchange the real and imaginary parts of complex numbers and conjugate. Internally calls *) function FlipConj(const X: TVec): Vector; overload; (*Exchange the real and imaginary parts of complex numbers and conjugate. Internally calls *) function FlipConj(const X: TMtx): Matrix; overload; (*Return reminder after divison of X by Y. Internally calls *) function Rem(const X,Y: TVec): Vector; overload; (*Return reminder after divison of X by Y. Internally calls *) function Rem(const X,Y: TMtx): Matrix; overload; (*Return reminder after divison of X by Y. Internally calls *) function Rem(const X: TVec; const Y: double): Vector; overload; (*Return reminder after divison of X by Y. Internally calls *) function Rem(const X: TMtx; const Y: double): Matrix; overload; (*Compute magnitude from the source. Internally calls *) function Mag(const X: TVec): Vector; overload; (*Compute magnitude from the source. Internally calls *) function Mag(const X: TMtx): Matrix; overload; (*Compute X^2 from the source. Internally calls *) function Sqr(const X: TVec): Vector; overload; (*Compute X^2 from the source. Internally calls *) function Sqr(const X: TMtx): Matrix; overload; (*Compute X^2 from the source. Internally calls *) function Sqrt(const X: TVec): Vector; overload; (*Compute X^2 from the source. Internally calls *) function Sqrt(const X: TMtx): Matrix; overload; (*Compute X^2 from the source. Internally calls *) function LogN(const X: TVec; N: double): Vector; overload; (*Compute X^2 from the source. Internally calls *) function LogN(const X: TMtx; N: double): Matrix; overload; (*Multiply the source with 1i complex number. Internally calls *) function MulI(const X: TVec): Vector; overload; (*Multiply the source with 1i complex number. Internally calls *) function MulI(const X: TMtx): Matrix; overload; (*Compute (X + Offset)/Factor Internally calls *) function Normalize(const X: TVec; Offset, Factor: double): Vector; overload; (*Compute (X + Offset)/Factor Internally calls *) function Normalize(const X: TVec; const Offset, Factor: TCplx): Vector; overload; (*Compute (X + Offset)/Factor Internally calls *) function Normalize(const X: TVec; const Offset: TCplx; Factor: double): Vector; overload; (*Compute (X + Offset)/Factor Internally calls *) function Normalize(const X: TMtx; Offset, Factor: double): Matrix; overload; (*Compute (X + Offset)/Factor Internally calls *) function Normalize(const X: TMtx; const Offset, Factor: TCplx): Matrix; overload; (*Compute (X + Offset)/Factor Internally calls *) function Normalize(const X: TMtx; const Offset: TCplx; Factor: double): Matrix; overload; (*Compute the power function. Internally calls *) function Power(const Base: TVec; Exponent: double): Vector; overload; (*Compute the power function. Internally calls *) function Power(const Base: TMtx; Exponent: double): Matrix; overload; (*Compute the power function. Internally calls *) function Power(Base: double; const Exponent: TVec): Vector; overload; (*Compute the power function. Internally calls *) function Power(Base: double; const Exponent: TMtx): Matrix; overload; (*Compute the power function. Internally calls *) function Power(const Base: TCplx; const Exponent: TVec): Vector; overload; (*Compute the power function. Internally calls *) function Power(const Base: TCplx; const Exponent: TMtx): Matrix; overload; (*Compute the power function. Internally calls *) function Power(const Base: TVec; const Exponent: TVec): Vector; overload; function Power(const Base: TMtx; const Exponent: TMtx): Matrix; overload; (*Compute the power function. Internally calls *) function Power(const Base: TVec; const Exponent: TCplx): Vector; overload; (*Compute the power function. Internally calls *) function Power(const Base: TMtx; const Exponent: TCplx): Matrix; overload; (*Compute the phase spectrum. Internally calls *) function PhaseSpectrum(const X: TVec): Vector; overload; (*Compute the phase spectrum from the complex source data. Internally calls *) function PhaseSpectrum(const X: TMtx): Matrix; overload; (*Compute the phase from the complex source data. Internally calls *) function Phase(const X: TVec): Vector; overload; (*Compute the phase from the complex source data. Internally calls *) function Phase(const X: TMtx): Matrix; overload; (*Compute the power spectrum from the complex source data. Internally calls *) function PowerSpectrum(const X: TVec): Vector; overload; (*Compute the power spectrum from the complex source data. Internally calls *) function PowerSpectrum(const X: TMtx): Matrix; overload; (*Returns random values with gaussian distribution. Internally calls *) function RandGauss(Len: integer; const FloatPrecision: TMtxFloatPrecision): Vector; overload; (*Returns random values with gaussian distribution. Internally calls *) function RandGauss(Rows, Cols: integer; const FloatPrecision: TMtxFloatPrecision): Matrix; overload; (*Returns random values with gaussian distribution. Internally calls *) function RandGauss(Len: integer; const FloatPrecision: TMtxFloatPrecision; aMean, aStdDev: double): Vector; overload; (*Returns random values with gaussian distribution. Internally calls *) function RandGauss(Rows, Cols: integer; const FloatPrecision: TMtxFloatPrecision; aMean, aStdDev: double): Matrix; overload; (*Returns random values with uniform distribution. Internally calls *) function RandUniform(Len: integer; const FloatPrecision: TMtxFloatPrecision): Vector; overload; (*Returns random values with uniform distribution. Internally calls *) function RandUniform(Rows, Cols: integer; const FloatPrecision: TMtxFloatPrecision): Matrix; overload; (*Returns random values with uniform distribution. Internally calls *) function RandUniform(Len: integer; const FloatPrecision: TMtxFloatPrecision; aLow, aHigh: double): Vector; overload; (*Returns random values with uniform distribution. Internally calls *) function RandUniform(Rows, Cols: integer; const FloatPrecision: TMtxFloatPrecision; aLow, aHigh: double): Matrix; overload; (*Rounds values to the closest integer. Internally calls *) function Round(const X: TVec): Vector; overload; (*Rounds values to the closest integer. Internally calls *) function Round(const X: TMtx): Matrix; overload; (*Returns the real part of the complex number. Internally calls *) function RealPart(const X: TVec): Vector; overload; (*Returns the real part of the complex number. Internally calls *) function RealPart(const X: TMtx): Matrix; overload; (*Returns the real part of the complex number. Internally calls *) function Real(const X: TVec): Vector; overload; (*Returns the real part of the complex number. Internally calls *) function Real(const X: TMtx): Matrix; overload; (*Change the sign of the source data. Internally calls *) function Sign(const X: TVec): Vector; overload; (*Change the sign of the source data. Internally calls *) function Sign(const X: TMtx): Matrix; overload; (*Rounds values towards to zero to integer. Internally calls *) function Trunc(const X: TVec): Vector; overload; (*Rounds values towards zero to integer. Internally calls *) function Trunc(const X: TMtx): Matrix; overload; (*Limit the smallest value in the source data. Internally calls *) function ThreshBottom(const X: TVec; Value: double): Vector; overload; (*Limit the smallest value in the source data. Internally calls *) function ThreshBottom(const X: TMtx; Value: double): Matrix; overload; (*Limit the largest value in the source data. Internally calls *) function ThreshTop(const X: TVec; Value: double): Vector; overload; (*Limit the largest value in the source data. Internally calls *) function ThreshTop(const X: TMtx; Value: double): Matrix; overload; (*Computes X + Y*Ascale Internally calls *) function AddScaled(const X,Y: TVec; aScale: double): Vector; overload; (*Computes X + Y*Ascale Internally calls *) function AddScaled(const X,Y: TMtx; aScale: double): Matrix; overload; (*Computes X + Y*Ascale Internally calls *) function AddScaled(const X,Y: TVec; const aScale: TCplx): Vector; overload; (*Computes X + Y*Ascale Internally calls *) function AddScaled(const X,Y: TMtx; const aScale: TCplx): Matrix; overload; (*Computes X + Y*Z Internally calls *) function AddProduct(const X, Y, Z: TVec): Vector; overload; (*Computes X + Y*Z Internally calls *) function AddProduct(const X, Y, Z: TMtx): Matrix; overload; (*Conjugate Y and multiply with X Internally calls *) function ConjMul(const X, Y: TVec): Vector; overload; (*Conjugate Y and multiply with X Internally calls *) function ConjMul(const X, Y: TMtx): Matrix; overload; (*Returns the sum of all elements in the source data. Internally calls *) function CumSum(const X: TVec): Vector; overload; (*Returns the sum of all elements in the source data. Internally calls *) function CumSum(const X: TMtx): Matrix; overload; (*Returns the discrete cosine transform of the source data. Internally calls *) function DCT(const X: TVec): Vector; overload; (*Returns the inverse discrete cosine transform of the source data. Internally calls *) function IDCT(const X: TVec): Vector; overload; (*Returns the difference of consecutive elements of the source data. Internally calls *) function Difference(const X: TVec): Vector; overload; (*Returns the dot product: sum(X*Y). Internally calls *) function DotProd(const X,Y: TVec): double; overload; (*Returns the dot product: sum(X*Y). Internally calls *) function DotProdc(const X,Y: TVec; ConjY: boolean = false): TCplx; overload; (*Returns the discrete fourier transform of the source data. Internally calls *) function FFT(const X: TVec; ConjugateExtend: boolean = false): Vector; overload; (*Returns the 1D discrete fourier transforms of the source data. Internally calls *) function FFT1D(const X: TMtx): Matrix; overload; (*Returns the 2D discrete fourier transform of the source data. Internally calls *) function FFT2D(const X: TMtx): Matrix; overload; (*Returns the discrete fourier transform of the real source data. Internally calls *) function FFTFromReal(const X: TVec): Vector; overload; (*Returns the discrete fourier transform of the real source data. Internally calls *) function FFT1DFromReal(const X: TMtx): Matrix; overload; (*Returns the discrete fourier transform of the real source data. Internally calls *) function FFT2DFromReal(const X: TMtx): Matrix; overload; (*Computes the real inverse discrete fourier transform of the source data. Internally calls *) function IFFTToReal(const X: TVec; NoScale: boolean=False): Vector; overload; (*Computes the real inverse discrete fourier transform of the source data. Internally calls *) function IFFT1DToReal(const X: TMtx): Matrix; overload; (*Computes the real inverse discrete fourier transform of the source data. Internally calls *) function IFFT2DToReal(const X: TMtx): Matrix; overload; (*Computes the inverse discrete fourier transform of the source data. Internally calls *) function IFFT(const X: TVec; NoScale: boolean=False): Vector; overload; (*Computes the inverse discrete fourier transform of the source data. Internally calls *) function IFFT1D(const X: TMtx; NoScale: boolean=False): Matrix; overload; (*Computes the inverse discrete fourier transform of the source data. Internally calls *) function IFFT2D(const X: TMtx; NoScale: boolean=False): Matrix; overload; (*Reverses the content of the source data. Internally calls *) function Reverse(const X: TVec): Vector; overload; (*Rotates the content of the source data by Offset. Internally calls *) function Rotate(const X: TVec; Offset: integer): Vector; overload; (*Shifts the content of the source data X by Offset left or right. Internally calls *) function Shift(const X: TVec; Offset: integer): Vector; overload; (*Returns biased auto correlation of the source data. Internally calls *) function AutoCorrBiased(const Vec: TVec; Lags: integer): Vector; overload; (*Returns normal auto correlation of the source data. Internally calls *) function AutoCorrNormal(const Vec: TVec; Lags: integer): Vector; overload; (*Returns unbiased auto correlation of the source data. Internally calls *) function AutoCorrUnBiased(const Vec: TVec; Lags: integer): Vector; overload; (*Concatenates multiple Vectors in to a single one. Internally calls *) function Concat(const Src: array of TVec): Vector; overload; (*Concatenates multiple Vectors in to a single one. Internally calls *) function Concat(const X1, X2: TMtxVec): Vector; overload; (*Returns convolution of X with H. Internally calls *) function Convolve(const X, H: TVec): Vector; overload; (*Returns cross correlation between Vec1 and Vec2. Internally calls *) function CrossCorr(const Vec1, Vec2: TVec; HiLag, LoLag: integer): Vector; overload; (*Returns k-th diagonal from the source matrix. Internally calls *) function Diag(const Mtx: TMtx; k: integer): Vector; overload; (*Reduces the sampling frequency without filtering. Internally calls *) function DownSample(const Src: TVec; Factor: integer; Phase: integer = 0): Vector; overload; (*Reduces the sampling frequency without filtering. Internally calls *) function DownSample(const Src: TMtx; Factor: integer; Phase: integer = 0): Vector; overload; (*Returns specified column from the source matrix. Internally calls *) function Col(const Mtx: TMtx; aCol: integer): Vector; overload; (*Returns specified column from the source matrix. Internally calls *) function Col(const Mtx: TMtx; aRow, aCol, Len: integer): Vector; overload; (*Returns specified aRow from the source matrix. Internally calls *) function Row(const Mtx: TMtx; aRow: integer): Vector; overload; (*Returns specified aRow from the source matrix. Internally calls *) function Row(const Mtx: TMtx; aRow, aCol, Len: integer): Vector; overload; (*Computes the hilbert transform of the source data. Internally calls *) function Hilbert(const Vec: TVec): Vector; overload; (*Computes the kronecker product. Internally calls *) function Kron(const Vec1, Vec2: TVec): Vector; overload; (*Computes the Norm from source data. Internally calls *) function Norm(const Vec: TVec): Vector; overload; (*Returns primer numbers up to number n. Internally calls *) function PrimeNumbers(n: integer): Vector; (*Returns a vector of [0, 1, .., Len-1] numbers. Internally calls *) function Ramp(Len: integer; const FloatPrecision: TMtxFloatPrecision): Vector; overload; (*Returns a vector of [0, 1, .., Len-1] numbers. It uses LengthAndFloatPrecisionSrc to obtain Length and FloatPrecision params. Internally calls *) function Ramp(const LengthAndFloatPrecisionSrc: TMtxVec): Vector; overload; (*Returns a vector of [Offset, Offset+Step, .., Offset+(Len-1)*Step] numbers. Internally calls *) function Ramp(Len: integer; const FloatPrecision: TMtxFloatPrecision; const Offset, Step: TCplx): Vector; overload; (*Returns a vector of [0, 1, .., Len-1] numbers. It uses LengthAndFloatPrecisionSrc to obtain Length and FloatPrecision params. Internally calls *) function Ramp(const LengthAndFloatPrecisionSrc: TMtxVec; const Offset, Step: TCplx): Vector; overload; (*Returns a vector of [Offset, Offset+Step, .., Offset+(Len-1)*Step] numbers. Internally calls *) function Ramp(Len: integer; const FloatPrecision: TMtxFloatPrecision; Offset, Step: double): Vector; overload; (*Returns a vector of [0, 1, .., Len-1] numbers. It uses LengthAndFloatPrecisionSrc to obtain Length and FloatPrecision params. Internally calls *) function Ramp(const LengthAndFloatPrecisionSrc: TMtxVec; Offset, Step: double): Vector; overload; (*Returns a vector of [Offset, Offset+Step, .., Offset+(Len-1)*Step] numbers. Internally calls *) function Ramp(Len: integer; const FloatPrecision: TMtxFloatPrecision; const Offset: TCplx; Step: double): Vector; overload; (*Returns a vector of [0, 1, .., Len-1] numbers. It uses LengthAndFloatPrecisionSrc to obtain Length and FloatPrecision params. Internally calls *) function Ramp(const LengthAndFloatPrecisionSrc: TMtxVec; const Offset: TCplx; Step: double): Vector; overload; (*Sorts the source data ascendingly. Internally calls *) function SortAscend(const Src: TVec): Vector; overload; (*Sorts the source data ascendingly. Internally calls *) function SortAscend(const Src: TVec; const IndexVec: TVecInt): Vector; overload; (*Sorts the source data descendingly. Internally calls *) function SortDescend(const Src: TVec): Vector; overload; (*Sorts the source data descendingly. Internally calls *) function SortDescend(const Src: TVec; const IndexVec: TVecInt): Vector; overload; (*Converts a list of strings to vector. Internally calls *) function StringsToValues(const aList: TStrings): Vector; overload; (*Converts a list of strings to vector. Internally calls *) function StringsToValues(const aList: TStrings; ListIndex: integer; Index: integer = 0; Len: integer = MtxVecEOA): Vector; overload; (*Increase sampling frequency without filtering. Internally calls *) function UpSample(const Src: TMtx; Factor: integer; Phase: integer = 0): Vector; overload; (*Increase sampling frequency without filtering. Internally calls *) function UpSample(const Src: TVec; Factor: integer; Phase: integer = 0): Vector; overload; (*Returns Src + Vector1*Vector2' Internally calls *) function AddTensorProd(const Src: TMtx; const Vec1, Vec2: TVec; ConjVec2: boolean = False): Matrix; overload; (*Converts a banded matrix to dense storage. Internally calls *) function BandedToDense(const X: TMtx): Matrix; overload; (*Returns true, if matrix is symmetric and positive definite. Internally calls *) function Cholesky(const X: TMtx): boolean; overload; (*Concatenate a list of matrices in to one big matrix. Internally calls *) function Concat(ARows, ACols: integer; const Src: array of TMtx): Matrix; overload; (*Horizontally concatenate a list of matrices in to one big matrix. Internally calls *) function ConcatHorz(const Src: array of TMtx): Matrix; overload; (*Horizontally concatenate a list of matrices in to one big matrix. Internally calls *) function ConcatHorz(DestRow, DestCol: integer;const Src: array of TMtx): Matrix; overload; (*Vertically concatenate a list of matrices in to one big matrix. Internally calls *) function ConcatVert(const Src: array of TMtx): Matrix; overload; (*Vertically concatenate a list of matrices in to one big matrix. Internally calls *) function ConcatVert(DestRow, DestCol: integer;const Src: array of TMtx): Matrix; overload; (*Convert matrix from dense to banded storage format. Internally calls *) function DenseToBanded(const X: TMtx; MaxElemCount: integer = 10000000): Matrix; overload; (*Computes determinant of the matrix. Internally calls *) function Determinant(const X: TMtx; MtxType: TMtxType = mtGeneral): double; overload; (*Computes determinant of the matrix. Internally calls *) function Determinantc(const X: TMtx; MtxType: TMtxType = mtGeneral): TCplx; overload; (*Computes the eigen-values of the matrix. Internally calls *) function Eig(const X: TMtx; MtxType: TMtxType = mtGeneral): Vector; overload; (*Returns an "eye" matrix with ones on the diagonal and zeros elsewhere. Internally calls *) function Eye(ARows,ACols: integer; const aFloatPrecision: TMtxFloatPrecision): Matrix; overload; (*Flips the source matrix horizontally. Internally calls *) function FlipHor(const SrcMtx: TMtx): Matrix; overload; (*Flips the source matrix vertically. Internally calls *) function FlipVer(const SrcMtx: TMtx): Matrix; overload; (*Returns the matrix inverse A^-1. Internally calls *) function MtxInv(const X: TMtx; MtxType: TMtxType = mtGeneral): Matrix; overload; (*Returns the lower triangle of the matrix. Internally calls *) function LowerTriangle(const Mtx: TMtx; ZeroUpper, Diagonal: boolean): Matrix; overload; (*Returns the X from LQR solving A*X = B. Internally calls *) function LQRSolve(const B,A: TMtx; Op: TMtxOperation = opNone): Matrix; overload; (*Returns the X from LQR solving A*X = B. Internally calls *) function LQRSolve(const B: TVec; const A: TMtx; Op: TMtxOperation = opNone): Vector; overload; (*Returns the X from LU solving A*X = B. Internally calls *) function LUSolve(const B, A: TMtx; MtxType: TMtxType = mtGeneral; Operation: TMtxOperation = opNone): Matrix; overload; (*Returns the X from LU solving A*X = B. Internally calls *) function LUSolve(const B: TVec; const A: TMtx; MtxType: TMtxType = mtGeneral; Operation: TMtxOperation = opNone): Vector; overload; (*Returns the average of columns in the source matrix. Internally calls *) function MeanCols(const X: TMtx): Vector; overload; (*Returns the average of rows in the source matrix. Internally calls *) function MeanRows(const X: TMtx): Vector; overload; (*Computes matrix function of x^n where n is integer. Internally calls *) function MtxIntPower(const Src: TMtx; Exponent: Integer): Matrix; overload; (*Computes matrix function of x^r where r is a real number. Internally calls *) function MtxPower(const Src: TMtx; Exponent: double; SourceType: TMtxType = mtGeneral): Matrix; overload; (*Computes matrix function of x^c where c is a complex number. Internally calls *) function MtxPower(const Src: TMtx; const Exponent: TCplx; SourceType: TMtxType = mtGeneral): Matrix; overload; (*Computes matrix function of x^0.5. Internally calls *) function MtxSqrt(const Src: TMtx; SourceType: TMtxType = mtGeneral): Matrix; overload; (*Returns the matrix product of two matrices. Internally calls and does JIT-ed (faster) multiply for small square matrices. *) function Mul(const Mtx1, Mtx2: TMtx): Matrix; overload; (*Returns the matrix product of three matrices. Internally calls and does JIT-ed (faster) multiply for small square matrices. *) function Mul(const Mtx1, Mtx2, Mtx3: TMtx): Matrix; overload; (*Returns the matrix product of four matrices. Internally calls and does JIT-ed (faster) multiply for small square matrices. *) function Mul(const Mtx1, Mtx2, Mtx3, Mtx4: TMtx): Matrix; overload; (*Returns the matrix product of multiple matrices. Internally calls and does JIT-ed (faster) multiply for small square matrices. var a,b,c,d,e: Matrix; begin a := Mul([b,c,d,e]); end; *) function Mul(const mtxArray: array of TMtx): Matrix; overload; (*Returns the matrix product of multiple matrices. Internally calls and will not use JIT-ed matrix multiply for small square matrices, if transpose is requested for the specified matrix. Both parameters need to be equal in length. var a,b,c,d,e: Matrix; begin a := Mul([b,c,d,e], [0,1,0,0]); // transpose c before multiplying end; *) function Mul(const mtxArray: array of TMtx; const transpArray: array of integer): Matrix; overload; (*Returns the matrix product of two matrices. Internally calls This operation is not JIT-ed. *) function Mul(const Mtx1, Mtx2: TMtx; Operation1: TMtxOperation; Operation2: TMtxOperation = opNone): Matrix; overload; (*Returns the matrix product of two matrices. Internally calls This operation is not JIT-ed. *) function Mul(const Mtx1, Mtx2: TMtx; Mtx1Type: TMtxType; Mtx2Type: TMtxType = mtGeneral; Operation1: TMtxOperation = opNone; Operation2: TMtxOperation = opNone): Matrix; overload; (*Returns the 1-Norm of the matrix. Internally calls *) function Norm1(const X: TMtx): double; overload; (*Returns the Frobenius Norm of the matrix. Internally calls *) function NormFro(const X: TMtx): double; overload; (*Returns the matrix Infinity Norm. Internally calls *) function NormInf(const X: TMtx): double; overload; (*Returns the pascal matrix. Internally calls *) function Pascl(Order: integer): Matrix; overload; (*Returns the resized matrix. Internally calls *) function Resize(const Src: TMtx; NewRows, NewCols: integer): Matrix; overload; (*Returns the resized and transposed matrix. Internally calls *) function ResizeAndTranspose(const Src: TMtx; NewRows, NewCols: integer): Matrix; overload; (*Rotates the matrix by 90 degree. Internally calls *) function Rotate90(const Mtx: TMtx): Matrix; overload; (*Sorts all rows in the matrix descendingly Internally calls *) function SortDescend(const X: TMtx): Matrix; overload; (*Performs row based sort in descending order. Internally calls *) function SortDescend(const X: TMtx; Col: integer): Matrix; overload; (*Converts strings to values. Internally calls *) function StringsToValues(const aList: TStrings; const Delimiter: string = kTab): Matrix; overload; (*Converts strings to values. Internally calls *) function StringsToValues(const aList: TStrings; ListIndex,ListLen, Row,Col: Integer; Delimiter: string = kTab): Matrix; overload; (*Returns singular values. Internally calls *) function SVD(const X: TMtx): Vector; overload; (*Returns the sum of matrix columns. Internally calls *) function SumCols(const X: TMtx): Vector; overload; (*Returns the sum of matrix rows. Internally calls *) function SumRows(const X: TMtx): Vector; overload; (*Returns the Toeplitz matrix. Internally calls *) function Toeplitz(const FirstRow,FirstCol: TVec): Matrix; overload; (*Returns the Trace of the matrix. Internally calls *) function Trace(const X: TMtx): TCplx; overload; (*Returns the upper triangle of the matrix. Internally calls *) function UpperTriangle(const Mtx: TMtx; ZeroLower, Diagonal: boolean): Matrix; overload; (*Constructs VanDerMonde matrix. Internally calls *) function VanderMonde(ACols: Integer; const Vec: TVec): Matrix; overload; (*Multiply two matrices. Internally calls *) function MulDiag(const DiagMtx: TVec; const Mtx: TMtx): Matrix; overload; (*Multiply two matrices. Internally calls *) function MulDiag(const Mtx: TMtx; const DiagMtx: TVec): Matrix; overload; (*Compute maximum of each row. Compute maximum of each row and store the result in to Dst vector. The Dst is sized automatically. *) function MaxRows(const Src: TMtx): Vector; (*Compute minimum of each row. Compute minimum of each row and store the result in to Dst vector. The Dst is sized automatically. *) function MinRows(const Src: TMtx): Vector; (*Compute maximum of each column. Compute maximum of each column and store the result in to Dst vector. The Dst is sized automatically. *) function MaxCols(const Src: TMtx): Vector; (*Compute minimum of each column. Compute minimum of each column and store the result in to Dst vector. The Dst is sized automatically. *) function MinCols(const Src: TMtx): Vector; (* Compute X*xScale + Y*yScale Computes the specified expression without temporary objects and at the same speed as computing only X + Y. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples { void Example() { double xScale = 1.5; double yScale = -1.5; Vector X = (Vector) new double[] { 1, 2, 3, 4 }; Vector Y = (Vector) new double[] { 2, 3, 4, 5 }; Vector A1 = X * xScale + Y * yScale; Vector A2 = AddScaled(X, xScale, Y, yScale); Vector A3 = new Vector(); A3.AddScaled(X, xScale, Y, yScale); if (!A2.IsEqual(A1)) Math387.ERaise("Problem"); if (!A3.IsEqual(A1)) Math387.ERaise("Problem"); } } *) function AddScaled(const X: TVec; const xScale: Double; const Y: TMtxVec; const yScale: Double): Vector; overload; (* Compute X*xScale + Y*yScale, when X is a Matrix The operation does only per-element math. *) function AddScaled(const X: TMtx; const xScale: Double; const Y: TMtxVec; const yScale: Double): Matrix; overload; (* Compute sqr(X*xScale + Y*yScale) Computes the square of the expression X*xScale + Y*yScale without temporary objects. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples { void Example() { double xScale = 1.5, yScale = -1.5; Vector X = (Vector) new double[] { 1, 2, 3, 4 }; Vector Y = (Vector) new double[] { 2, 3, 4, 5 }; Vector A1 = MtxExpr.Sqr(X * xScale + Y * yScale); Vector A2 = AddScaledSqr(X, xScale, Y, yScale); Vector A3 = new Vector(); A3.AddScaledSqr(X, xScale, Y, yScale); if (!A2.IsEqual(A1)) Math387.ERaise("Problem"); if (!A3.IsEqual(A1)) Math387.ERaise("Problem"); } } *) function AddScaledSqr(const X: TVec; const xScale: Double; const Y: TMtxVec; const yScale: Double): Vector; overload; (* Compute sqr(X*xScale + Y*yScale), when X is a Matrix The operation does only per-element math. *) function AddScaledSqr(const X: TMtx; const xScale: Double; const Y: TMtxVec; const yScale: Double): Matrix; overload; (* Compute sqr(X)*xScale + sqr(Y)*yScale Computes the weighted sum of the squares of X and Y without temporary objects. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples { void Example() { double xScale = 2.0, yScale = 3.0; Vector X = (Vector) new double[] { 1, 2, 3, 4 }; Vector Y = (Vector) new double[] { 2, 3, 4, 5 }; Vector A1 = MtxExpr.Sqr(X) * xScale + MtxExpr.Sqr(Y) * yScale; Vector A2 = SqrAddScaled(X, xScale, Y, yScale); Vector A3 = new Vector(); A3.SqrAddScaled(X, xScale, Y, yScale); if (!A2.IsEqual(A1)) Math387.ERaise("Problem"); if (!A3.IsEqual(A1)) Math387.ERaise("Problem"); } } *) function SqrAddScaled(const X: TVec; const xScale: Double; const Y: TMtxVec; const yScale: Double): Vector; overload; (* Compute sqr(X)*xScale + sqr(Y)*yScale, when X is a matrix The operation does only per-element math. *) function SqrAddScaled(const X: TMtx; const xScale: Double; const Y: TMtxVec; const yScale: Double): Matrix; overload; (* Compute sqr(X + Y*yScale) Computes the square of (X + Y*yScale) without temporary objects. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples { void Example() { double yScale = 1.5; Vector X = (Vector) new double[] { 1, 2, 3, 4 }; Vector Y = (Vector) new double[] { 2, 3, 4, 5 }; Vector A1 = MtxExpr.Sqr(X + Y * yScale); Vector A2 = AddScaledSqr(X, Y, yScale); Vector A3 = new Vector(); A3.AddScaledSqr(X, Y, yScale); if (!A2.IsEqual(A1)) Math387.ERaise("Problem"); if (!A3.IsEqual(A1)) Math387.ERaise("Problem"); } } *) function AddScaledSqr(const X: TVec; const Y: TMtxVec; const yScale: Double): Vector; overload; (* Compute sqr(X + Y*yScale) when X is a matrix The operation does only per-element math. *) function AddScaledSqr(const X: TMtx; const Y: TMtxVec; const yScale: Double): Matrix; overload; (* Compute sqr(X) + sqr(Y)*yScale Computes the sum of the square of X and the scaled square of Y without temporary objects. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples { void Example() { double yScale = 2.0; Vector X = (Vector) new double[] { 1, 2, 3, 4 }; Vector Y = (Vector) new double[] { 2, 3, 4, 5 }; Vector A1 = MtxExpr.Sqr(X) + MtxExpr.Sqr(Y) * yScale; Vector A2 = SqrAddScaled(X, Y, yScale); Vector A3 = new Vector(); A3.SqrAddScaled(X, Y, yScale); if (!A2.IsEqual(A1)) Math387.ERaise("Problem"); if (!A3.IsEqual(A1)) Math387.ERaise("Problem"); } } *) function SqrAddScaled(const X: TVec; const Y: TMtxVec; const yScale: Double): Vector; overload; (* Compute sqr(X) + sqr(Y)*yScale, when X is a Matrix. The operation does only per-element math. *) function SqrAddScaled(const X: TMtx; const Y: TMtxVec; const yScale: Double): Matrix; overload; (* Compute X*xScale + Y*yScale + Z*zScale Computes the weighted sum of X, Y, and Z without temporary objects. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples { void Example() { double xScale = 1.0, yScale = 2.0, zScale = 3.0; Vector X = (Vector) new double[] { 1, 2, 3, 4 }; Vector Y = (Vector) new double[] { 2, 3, 4, 5 }; Vector Z = (Vector) new double[] { 3, 4, 5, 6 }; Vector A1 = X * xScale + Y * yScale + Z * zScale; Vector A2 = AddScaled(X, xScale, Y, yScale, Z, zScale); Vector A3 = new Vector(); A3.AddScaled(X, xScale, Y, yScale, Z, zScale); if (!A2.IsEqual(A1)) Math387.ERaise("Problem"); if (!A3.IsEqual(A1)) Math387.ERaise("Problem"); } } *) function AddScaled(const X: TVec; const xScale: Double; const Y: TMtxVec; const yScale: Double; const Z: TMtxVec; const zScale: Double): Vector; overload; (* Compute X*xScale + Y*yScale + Z*zScale *) function AddScaled(const X: TMtx; const xScale: Double; const Y: TMtxVec; const yScale: Double; const Z: TMtxVec; const zScale: Double): Matrix; overload; (* Compute X*xScale + Y*yScale + zScalar Computes X*xScale + Y*yScale plus a scalar zScalar without temporary objects. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples { void Example() { double xScale = 1.0, yScale = 2.0, zScalar = 3.0; Vector X = (Vector) new double[] { 1, 2, 3, 4 }; Vector Y = (Vector) new double[] { 2, 3, 4, 5 }; Vector A1 = X * xScale + Y * yScale + zScalar; Vector A2 = AddScaledC(X, xScale, Y, yScale, zScalar); Vector A3 = new Vector(); A3.AddScaledC(X, xScale, Y, yScale, zScalar); if (!A2.IsEqual(A1)) Math387.ERaise("Problem"); if (!A3.IsEqual(A1)) Math387.ERaise("Problem"); } } *) function AddScaledC(const X: TVec; const xScale: Double; const Y: TMtxVec; const yScale: Double; const Z: Double): Vector; overload; (* Compute X*xScale + Y*yScale + zScalar, when X is a Matrix *) function AddScaledC(const X: TMtx; const xScale: Double; const Y: TMtxVec; const yScale: Double; const Z: Double): Matrix; overload; (* Compute X*xScale - Y*yScale - Z*zScale Computes the expression X*xScale – Y*yScale – Z*zScale without temporary objects, achieving the same speed as an optimized inplace operation. : using Dew.Math; using Dew.Math.Units; namespace Dew.Examples { void Example() { double xScale = 1.0, yScale = 2.0, zScale = 3.0; Vector X = (Vector) new double[] { 5, 6, 7, 8 }; Vector Y = (Vector) new double[] { 1, 2, 3, 4 }; Vector Z = (Vector) new double[] { 1, 1, 1, 1 }; Vector A1 = X * xScale - Y * yScale - Z * zScale; Vector A2 = SubScaled(X, xScale, Y, yScale, Z, zScale); Vector A3 = new Vector(); A3.SubScaled(X, xScale, Y, yScale, Z, zScale); if (!A2.IsEqual(A1)) Math387.ERaise("Problem"); if (!A3.IsEqual(A1)) Math387.ERaise("Problem"); } } *) function SubScaled(const X: TVec; const xScale: Double; const Y: TMtxVec; const yScale: Double; const Z: TMtxVec; const zScale: Double): Vector; overload; (* Compute X*xScale - Y*yScale - Z*zScale, when X is a Matrix. *) function SubScaled(const X: TMtx; const xScale: Double; const Y: TMtxVec; const yScale: Double; const Z: TMtxVec; const zScale: Double): Matrix; overload; (* Compute X*xScale - Y*yScale - zScalar Computes the expression X*xScale – Y*yScale – zScalar without temporary objects. : using Dew.Math; using Dew.Math.Units; namespace Dew.Examples { void Example() { double xScale = 1.0, yScale = 2.0, zScalar = 3.0; Vector X = (Vector) new double[] { 5, 6, 7, 8 }; Vector Y = (Vector) new double[] { 1, 2, 3, 4 }; Vector A1 = X * xScale - Y * yScale - zScalar; Vector A2 = SubScaledC(X, xScale, Y, yScale, zScalar); Vector A3 = new Vector(); A3.SubScaledC(X, xScale, Y, yScale, zScalar); if (!A2.IsEqual(A1)) Math387.ERaise("Problem"); if (!A3.IsEqual(A1)) Math387.ERaise("Problem"); } } *) function SubScaledC(const X: TVec; const xScale: Double; const Y: TMtxVec; const yScale: Double; const Z: Double): Vector; overload; (* Compute X*xScale - Y*yScale - zScalar, when X is a Matrix *) function SubScaledC(const X: TMtx; const xScale: Double; const Y: TMtxVec; const yScale: Double; const Z: Double): Matrix; overload; (* Compute X*Y*Z Computes the product X*Y*Z without temporary objects. : using Dew.Math; using Dew.Math.Units; namespace Dew.Examples { void Example() { Vector X = (Vector) new double[] { 1, 2, 3, 4 }; Vector Y = (Vector) new double[] { 2, 3, 4, 5 }; Vector Z = (Vector) new double[] { 3, 4, 5, 6 }; Vector A1 = X * Y * Z; Vector A2 = MulElem(X, Y, Z); Vector A3 = new Vector(); A3.Mul(X, Y, Z); if (!A2.IsEqual(A1)) Math387.ERaise("Problem"); if (!A3.IsEqual(A1)) Math387.ERaise("Problem"); } } *) function MulElem(const X: TVec; const Y, Z: TMtxVec): Vector; overload; (* Compute X*Y*Z, when X is a Matrix *) function MulElem(const X: TMtx; const Y, Z: TMtxVec): Matrix; overload; (* Compute X*Y*zScalar Computes the product of X and Y multiplied by the scalar zScalar without temporary objects. : using Dew.Math; using Dew.Math.Units; namespace Dew.Examples { void Example() { double zScalar = 2.0; Vector X = (Vector) new double[] { 1, 2, 3, 4 }; Vector Y = (Vector) new double[] { 2, 3, 4, 5 }; Vector A1 = (X * Y) * zScalar; Vector A2 = MulElem(X, Y, zScalar); Vector A3 = new Vector(); A3.Mul(X, Y, zScalar); if (!A2.IsEqual(A1)) Math387.ERaise("Problem"); if (!A3.IsEqual(A1)) Math387.ERaise("Problem"); } } *) function MulElem(const X: TVec; const Y: TMtxVec; const Z: Double): Vector; overload; (* Compute X*Y*zScalar, when X is a Matrix The operation does only per-element math. *) function MulElem(const X: TMtx; const Y: TMtxVec; const Z: Double): Matrix; overload; (* Compute X / (Y*Z) Divides X by the product of Y and Z without temporary objects. : using Dew.Math; using Dew.Math.Units; namespace Dew.Examples { void Example() { Vector X = (Vector) new double[] { 6, 8, 10, 12 }; Vector Y = (Vector) new double[] { 1, 2, 3, 4 }; Vector Z = (Vector) new double[] { 2, 2, 2, 2 }; Vector A1 = X / (Y * Z); Vector A2 = DivideElem(X, Y, Z); Vector A3 = new Vector(); A3.Divide(X, Y, Z); if (!A2.IsEqual(A1)) Math387.ERaise("Problem"); if (!A3.IsEqual(A1)) Math387.ERaise("Problem"); } } *) function DivideElem(const X: TVec; const Y, Z: TMtxVec): Vector; overload; (* Compute X / (Y*Z), when X is a Matrix The operation does only per-element math. *) function DivideElem(const X: TMtx; const Y, Z: TMtxVec): Matrix; overload; (* Compute X / (Y*zScale) Divides X by (Y multiplied by the scalar zScale) without temporary objects. : using Dew.Math; using Dew.Math.Units; namespace Dew.Examples { void Example() { double zScale = 2.0; Vector X = (Vector) new double[] { 10, 20, 30, 40 }; Vector Y = (Vector) new double[] { 2, 4, 6, 8 }; Vector A1 = X / (Y * zScale); Vector A2 = DivideElemC(X, Y, zScale); Vector A3 = new Vector(); A3.DivideC(X, Y, zScale); if (!A2.IsEqual(A1)) Math387.ERaise("Problem"); if (!A3.IsEqual(A1)) Math387.ERaise("Problem"); } } *) function DivideElemC(const X: TVec; const Y: TMtxVec; const Z: Double): Vector; overload; (* Compute X / (Y*zScale), when X is a Matrix. The operation does only per-element math. *) function DivideElemC(const X: TMtx; const Y: TMtxVec; const Z: Double): Matrix; overload; (* Compute X * Y * xyScale / Z Computes the product of X and Y scaled by xyScale, then divided by Z, without temporary objects. : using Dew.Math; using Dew.Math.Units; namespace Dew.Examples { void Example() { double xyScale = 1.5; Vector X = (Vector) new double[] { 2, 4, 6, 8 }; Vector Y = (Vector) new double[] { 1, 1, 1, 1 }; Vector Z = (Vector) new double[] { 2, 2, 2, 2 }; Vector A1 = (X * Y * xyScale) / Z; Vector A2 = MulAndDiv(X, Y, xyScale, Z); Vector A3 = new Vector(); A3.MulAndDiv(X, Y, xyScale, Z); if (!A2.IsEqual(A1)) Math387.ERaise("Problem"); if (!A3.IsEqual(A1)) Math387.ERaise("Problem"); } } *) function MulAndDiv(const X: TVec; const Y: TMtxVec; const xyScale: Double; const Z: TMtxVec): Vector; overload; (* Compute X * Y * xyScale / Z, when X is a Matrix. The operation does only per-element math. *) function MulAndDiv(const X: TMtx; const Y: TMtxVec; const xyScale: Double; const Z: TMtxVec): Matrix; overload; (* Compute X * Y / zScalar Computes the product of X and Y divided by the scalar zScalar without temporary objects. : using Dew.Math; using Dew.Math.Units; namespace Dew.Examples { void Example() { double zScalar = 2.0; Vector X = (Vector) new double[] { 3, 6, 9, 12 }; Vector Y = (Vector) new double[] { 1, 2, 3, 4 }; Vector A1 = (X * Y) / zScalar; Vector A2 = MulAndDiv(X, Y, zScalar); Vector A3 = new Vector(); A3.MulAndDiv(X, Y, zScalar); if (!A2.IsEqual(A1)) Math387.ERaise("Problem"); if (!A3.IsEqual(A1)) Math387.ERaise("Problem"); } } *) function MulAndDiv(const X: TVec; const Y: TMtxVec; const Z: Double): Vector; overload; (* Compute X * Y / zScalar, when X is a Matrix. The operation does only per-element math. *) function MulAndDiv(const X: TMtx; const Y: TMtxVec; const Z: Double): Matrix; overload; (* Compute xScalar / (Y*Z) Divides a scalar xScalar by the product of Y and Z without temporary objects. Since the first parameter is scalar, the overload is provided by splitting the second parameter into TVec and TMtx versions. : using Dew.Math; using Dew.Math.Units; namespace Dew.Examples { void Example() { double xScalar = 100; Vector Y = (Vector) new double[] { 2, 4, 5, 10 }; Vector Z = (Vector) new double[] { 1, 2, 2, 2 }; Vector A1 = xScalar / (Y * Z); Vector A2 = DivideElem(xScalar, Y, Z); Vector A3 = new Vector(); A3.Divide(xScalar, Y, Z); if (!A2.IsEqual(A1)) Math387.ERaise("Problem"); if (!A3.IsEqual(A1)) Math387.ERaise("Problem"); } } *) function DivideElem(const X: Double; const Y: TVec; const Z: TMtxVec): Vector; overload; (* Compute xScalar / (Y*Z), when Y is a Matrix The operation does only per-element math. *) function DivideElem(const X: Double; const Y: TMtx; const Z: TMtxVec): Matrix; overload; (* Compute (X*xScale + Y*yScale)*Z*zScale Computes the expression (X*xScale + Y*yScale) multiplied by Z*zScale without temporary objects. : using Dew.Math; using Dew.Math.Units; namespace Dew.Examples { void Example() { double xScale = 1.0, yScale = 2.0, zScale = 3.0; Vector X = (Vector) new double[] { 1, 2, 3, 4 }; Vector Y = (Vector) new double[] { 2, 3, 4, 5 }; Vector Z = (Vector) new double[] { 3, 4, 5, 6 }; Vector A1 = (X * xScale + Y * yScale) * Z * zScale; Vector A2 = AddAndMul(X, xScale, Y, yScale, Z, zScale); Vector A3 = new Vector(); A3.AddAndMul(X, xScale, Y, yScale, Z, zScale); if (!A2.IsEqual(A1)) Math387.ERaise("Problem"); if (!A3.IsEqual(A1)) Math387.ERaise("Problem"); } } *) function AddAndMul(const X: TVec; const xScale: Double; const Y: TMtxVec; const yScale: Double; const Z: TMtxVec; const zScale: Double): Vector; overload; (* Compute (X*xScale + Y*yScale)*Z*zScale, when X is a Matrix. The operation does only per-element math. *) function AddAndMul(const X: TMtx; const xScale: Double; const Y: TMtxVec; const yScale: Double; const Z: TMtxVec; const zScale: Double): Matrix; overload; (* Compute (X*xScale + yScalar)*Z*zScale Computes the expression where X is scaled by xScale, then added to a scalar yScalar, and the result is multiplied element-wise by Z and finally scaled by zScale. This operation is performed without creating temporary objects. : using Dew.Math; using Dew.Math.Units; namespace Dew.Examples { void Example() { double xScale = 1.0, yScalar = 2.0, zScale = 3.0; Vector X = (Vector) new double[] { 1, 2, 3, 4 }; Vector Z = (Vector) new double[] { 3, 4, 5, 6 }; Vector A1 = (X * xScale + yScalar) * Z * zScale; Vector A2 = AddAndMul(X, xScale, yScalar, Z, zScale); Vector A3 = new Vector(); A3.AddAndMul(X, xScale, yScalar, Z, zScale); if (!A2.IsEqual(A1)) Math387.ERaise("Problem"); if (!A3.IsEqual(A1)) Math387.ERaise("Problem"); } } *) function AddAndMul(const X: TVec; const xScale: Double; Y: Double; const Z: TMtxVec; const zScale: Double): Vector; overload; (* Compute (X*xScale + yScalar)*Z*zScale, when X is a Matrix. The operation does only per-element math. *) function AddAndMul(const X: TMtx; const xScale: Double; Y: Double; const Z: TMtxVec; const zScale: Double): Matrix; overload; (* Compute (X*xScale + Y*yScale)*zScalar Computes the expression (X*xScale + Y*yScale) multiplied by a scalar zScalar without temporary objects. : using Dew.Math; using Dew.Math.Units; namespace Dew.Examples { void Example() { double xScale = 1.0, yScale = 2.0, zScalar = 3.0; Vector X = (Vector) new double[] { 1, 2, 3, 4 }; Vector Y = (Vector) new double[] { 2, 3, 4, 5 }; Vector A1 = (X * xScale + Y * yScale) * zScalar; Vector A2 = AddAndMul(X, xScale, Y, yScale, zScalar); Vector A3 = new Vector(); A3.AddAndMul(X, xScale, Y, yScale, zScalar); if (!A2.IsEqual(A1)) Math387.ERaise("Problem"); if (!A3.IsEqual(A1)) Math387.ERaise("Problem"); } } *) function AddAndMul(const X: TVec; const xScale: Double; const Y: TMtxVec; const yScale: Double; const Z: Double): Vector; overload; (* Compute (X*xScale + Y*yScale)*zScalar, when X is a Matrix. The operation does only per-element math. *) function AddAndMul(const X: TMtx; const xScale: Double; const Y: TMtxVec; const yScale: Double; const Z: Double): Matrix; overload; (* Compute (X*xScale + yScalar)*zScalar Computes the result of multiplying X by xScale, adding a scalar yScalar, and then multiplying the entire result by a scalar zScalar, all without creating temporary objects. : using Dew.Math; using Dew.Math.Units; namespace Dew.Examples { void Example() { double xScale = 1.0, yScalar = 2.0, zScalar = 3.0; Vector X = (Vector) new double[] { 1, 2, 3, 4 }; Vector A1 = (X * xScale + yScalar) * zScalar; Vector A2 = AddAndMul(X, xScale, yScalar, zScalar); Vector A3 = new Vector(); A3.AddAndMul(X, xScale, yScalar, zScalar); if (!A2.IsEqual(A1)) Math387.ERaise("Problem"); if (!A3.IsEqual(A1)) Math387.ERaise("Problem"); } } *) function AddAndMul(const X: TVec; const xScale: Double; Y, Z: Double): Vector; overload; (* Compute (X*xScale + yScalar)*zScalar, when X is a Matrix. The operation does only per-element math. *) function AddAndMul(const X: TMtx; const xScale: Double; Y, Z: Double): Matrix; overload; (* Compute (X*xScale - Y*yScale)*Z*zScale Computes the product of (X scaled by xScale minus Y scaled by yScale) multiplied by Z scaled by zScale, without creating temporary objects. : using Dew.Math; using Dew.Math.Units; namespace Dew.Examples { void Example() { double xScale = 1.0, yScale = 2.0, zScale = 3.0; Vector X = (Vector) new double[] { 1, 2, 3, 4 }; Vector Y = (Vector) new double[] { 2, 3, 4, 5 }; Vector Z = (Vector) new double[] { 3, 4, 5, 6 }; Vector A1 = (X * xScale - Y * yScale) * Z * zScale; Vector A2 = SubAndMul(X, xScale, Y, yScale, Z, zScale); Vector A3 = new Vector(); A3.SubAndMul(X, xScale, Y, yScale, Z, zScale); if (!A2.IsEqual(A1)) Math387.ERaise("Problem"); if (!A3.IsEqual(A1)) Math387.ERaise("Problem"); } } *) function SubAndMul(const X: TVec; const xScale: Double; const Y: TMtxVec; const yScale: Double; const Z: TMtxVec; const zScale: Double): Vector; overload; (* Compute (X*xScale - Y*yScale)*Z*zScale. The operation does only per-element math. *) function SubAndMul(const X: TVec; const xScale: TCplx; const Y: TMtxVec; const yScale: TCplx; const Z: TMtxVec; const zScale: TCplx): Vector; overload; (* Compute (X*xScale - Y*yScale)*Z*zScale, when X is a Matrix. The operation does only per-element math. *) function SubAndMul(const X: TMtx; const xScale: Double; const Y: TMtxVec; const yScale: Double; const Z: TMtxVec; const zScale: Double): Matrix; overload; (* Compute (X*xScale - Y*yScale)*Z*zScale, when X is a Matrix. The operation does only per-element math. *) function SubAndMul(const X: TMtx; const xScale: TCplx; const Y: TMtxVec; const yScale: TCplx; const Z: TMtxVec; const zScale: TCplx): Matrix; overload; (* Compute (X*xScale - Y*yScale)*zScale *) function SubAndMul(const X: TVec; const xScale: TCplx; const Y: TMtxVec; const yScale: TCplx; const Z: TCplx): Vector; overload; (* Compute (X*xScale - Y*yScale)*zScale *) function SubAndMul(const X: TMtx; const xScale: TCplx; const Y: TMtxVec; const yScale: TCplx; const Z: TCplx): Matrix; overload; (* Compute (X*xScale - Y*yScale)*zScalar Computes the product of (X scaled by xScale minus Y scaled by yScale) multiplied by a scalar zScalar, without creating temporary objects. : using Dew.Math; using Dew.Math.Units; namespace Dew.Examples { void Example() { double xScale = 1.0, yScale = 2.0, zScalar = 3.0; Vector X = (Vector) new double[] { 1, 2, 3, 4 }; Vector Y = (Vector) new double[] { 2, 3, 4, 5 }; Vector A1 = (X * xScale - Y * yScale) * zScalar; Vector A2 = SubAndMul(X, xScale, Y, yScale, zScalar); Vector A3 = new Vector(); A3.SubAndMul(X, xScale, Y, yScale, zScalar); if (!A2.IsEqual(A1)) Math387.ERaise("Problem"); if (!A3.IsEqual(A1)) Math387.ERaise("Problem"); } } *) function SubAndMul(const X: TVec; const xScale: Double; const Y: TMtxVec; const yScale: Double; Z: Double): Vector; overload; (* Compute (X*xScale - Y*yScale)*zScalar, when X is a Matrix. The operation does only per-element math. *) function SubAndMul(const X: TMtx; const xScale: Double; const Y: TMtxVec; const yScale: Double; const Z: Double): Matrix; overload; (* Compute (X*xScale - yScalar)*Z*zScale Computes the expression (X*xScale - yScalar) multiplied by Z*zScale without temporary objects. : using Dew.Math; using Dew.Math.Units; namespace Dew.Examples { void Example() { double xScale = 1.0, yScalar = 2.0, zScale = 3.0; Vector X = (Vector) new double[] { 1, 2, 3, 4 }; Vector Z = (Vector) new double[] { 3, 4, 5, 6 }; Vector A1 = (X * xScale - yScalar) * Z * zScale; Vector A2 = SubAndMul(X, xScale, yScalar, Z, zScale); Vector A3 = new Vector(); A3.SubAndMul(X, xScale, yScalar, Z, zScale); if (!A2.IsEqual(A1)) Math387.ERaise("Problem"); if (!A3.IsEqual(A1)) Math387.ERaise("Problem"); } } *) function SubAndMul(const X: TVec; const xScale: Double; Y: Double; const Z: TMtxVec; const zScale: Double): Vector; overload; (* Compute (X*xScale - yScalar)*Z*zScale, where X is a Matrix. The operation does only per-element math. *) function SubAndMul(const X: TMtx; const xScale: Double; Y: Double; const Z: TMtxVec; const zScale: Double): Matrix; overload; (* Compute (X*xScale - yScalar)*Z*zScale, where X is a Matrix. The operation does only per-element math. *) function SubAndMul(const X: TVec; const xScale: TCplx; const Y: TCplx; const Z: TMtxVec; const zScale: TCplx): Vector; overload; (* Compute (X*xScale - yScalar)*Z*zScale, where X is a Matrix. The operation does only per-element math. *) function SubAndMul(const X: TMtx; const xScale: TCplx; const Y: TCplx; const Z: TMtxVec; const zScale: TCplx): Matrix; overload; (* Compute (X*xScale - yScalar)*zScalar Computes the expression (X*xScale - yScalar) multiplied by a scalar zScalar without temporary objects. : using Dew.Math; using Dew.Math.Units; namespace Dew.Examples { void Example() { double xScale = 1.0, yScalar = 2.0, zScalar = 3.0; Vector X = (Vector) new double[] { 1, 2, 3, 4 }; Vector A1 = (X * xScale - yScalar) * zScalar; Vector A2 = SubAndMul(X, xScale, yScalar, zScalar); Vector A3 = new Vector(); A3.SubAndMul(X, xScale, yScalar, zScalar); if (!A2.IsEqual(A1)) Math387.ERaise("Problem"); if (!A3.IsEqual(A1)) Math387.ERaise("Problem"); } } *) function SubAndMul(const X: TVec; const xScale: Double; Y, Z: Double): Vector; overload; (* Compute (X*xScale - yScalar)*zScalar, where X is a Matrix.*) function SubAndMul(const X: TMtx; const xScale: Double; Y, Z: Double): Matrix; overload; (* Compute (X*Y)*xyScale + Z*zScale Computes the product of X and Y scaled by xyScale, and then adds Z scaled by zScale, without creating temporary objects. : using Dew.Math; using Dew.Math.Units; namespace Dew.Examples { void Example() { double xyScale = 1.5, zScale = 2.0; Vector X = (Vector) new double[] { 2, 4, 6, 8 }; Vector Y = (Vector) new double[] { 1, 1, 1, 1 }; Vector Z = (Vector) new double[] { 3, 4, 5, 6 }; Vector A1 = (X * Y * xyScale) + (Z * zScale); Vector A2 = MulAndAdd(X, xyScale, Y, xyScale, Z, zScale); Vector A3 = new Vector(); A3.MulAndAdd(X, xyScale, Y, xyScale, Z, zScale); if (!A2.IsEqual(A1)) Math387.ERaise("Problem"); if (!A3.IsEqual(A1)) Math387.ERaise("Problem"); } } *) function MulAndAdd(const X: TVec; const Y: TMtxVec; const xyScale: Double; const Z: TMtxVec; const zScale: Double): Vector; overload; (* Compute (X*Y)*xyScale + Z*zScale, where X is a Matrix. The operation does only per-element math. *) function MulAndAdd(const X: TMtx; const Y: TMtxVec; const xyScale: Double; const Z: TMtxVec; const zScale: Double): Matrix; overload; (* Compute (X*Y)*xyScale + Z*zScale. The operation does only per-element math. *) function MulAndAdd(const X: TVec; const Y: TMtxVec; const xyScale: TCplx; const Z: TMtxVec; const zScale: TCplx): Vector; overload; (* Compute (X*Y)*xyScale + Z*zScale, where X is a Matrix. The operation does only per-element math. *) function MulAndAdd(const X: TMtx; const Y: TMtxVec; const xyScale: TCplx; const Z: TMtxVec; const zScale: TCplx): Matrix; overload; (* Compute (X*Y)*xyScale + zScalar Computes the product of X and Y scaled by xyScale, then adds a scalar zScalar, without creating temporary objects. : using Dew.Math; using Dew.Math.Units; namespace Dew.Examples { void Example() { double xyScale = 1.5, zScalar = 2.0; Vector X = (Vector) new double[] { 2, 4, 6, 8 }; Vector Y = (Vector) new double[] { 1, 1, 1, 1 }; Vector A1 = (X * Y * xyScale) + zScalar; Vector A2 = MulAndAdd(X, xyScale, Y, xyScale, zScalar); Vector A3 = new Vector(); A3.MulAndAdd(X, xyScale, Y, xyScale, zScalar); if (!A2.IsEqual(A1)) Math387.ERaise("Problem"); if (!A3.IsEqual(A1)) Math387.ERaise("Problem"); } } *) function MulAndAdd(const X: TVec; const Y: TMtxVec; const xyScale: Double; const Z: Double): Vector; overload; (* Compute (X*Y)*xyScale + zScalar, where X is a Matrix. The operation does only per-element math. *) function MulAndAdd(const X: TMtx; const Y: TMtxVec; const xyScale: Double; const Z: Double): Matrix; overload; (* Compute (X*Y)*xyScale + zScalar The operation does only per-element math. *) function MulAndAdd(const X: TVec; const Y: TMtxVec; const xyScale: TCplx; const Z: TCplx): Vector; overload; (* Compute (X*Y)*xyScale + zScalar, where X is a Matrix. The operation does only per-element math. *) function MulAndAdd(const X: TMtx; const Y: TMtxVec; const xyScale: TCplx; const Z: TCplx): Matrix; overload; (* Compute (X*yScalar) + zScalar Computes the result of multiplying X by a scalar yScalar and then adding a scalar zScalar, without creating temporary objects. : using Dew.Math; using Dew.Math.Units; namespace Dew.Examples { void Example() { double yScalar = 2.0, zScalar = 3.0; Vector X = (Vector) new double[] { 2, 4, 6, 8 }; Vector A1 = (X * yScalar) + zScalar; Vector A2 = MulAndAdd(X, yScalar, zScalar); Vector A3 = new Vector(); A3.MulAndAdd(X, yScalar, zScalar); if (!A2.IsEqual(A1)) Math387.ERaise("Problem"); if (!A3.IsEqual(A1)) Math387.ERaise("Problem"); } } *) function MulAndAdd(const X: TVec; const Y, Z: Double): Vector; overload; (* Compute (X*yScalar) + zScalar, where X is a Matrix.*) function MulAndAdd(const X: TMtx; const Y, Z: Double): Matrix; overload; (* Compute (X*yScalar) + zScalar, where X is a Matrix.*) function MulAndAdd(const X: TVec; const Y, Z: TCplx): Vector; overload; (* Compute (X*yScalar) + zScalar, where X is a Matrix.*) function MulAndAdd(const X: TMtx; const Y, Z: TCplx): Matrix; overload; (* Compute X*yScalar - Z*zScale Computes the result of multiplying X by a scalar yScalar and then subtracting Z multiplied by zScale, without creating temporary objects. : using Dew.Math; using Dew.Math.Units; namespace Dew.Examples { void Example() { double yScalar = 2.0, zScale = 3.0; Vector X = (Vector) new double[] { 3, 6, 9, 12 }; Vector Z = (Vector) new double[] { 1, 1, 1, 1 }; Vector A1 = (X * yScalar) - (Z * zScale); Vector A2 = MulAndSub(X, yScalar, Z, zScale); Vector A3 = new Vector(); A3.MulAndSub(X, yScalar, Z, zScale); if (!A2.IsEqual(A1)) Math387.ERaise("Problem"); if (!A3.IsEqual(A1)) Math387.ERaise("Problem"); } } *) function MulAndSub(const X: TVec; const Y: double; const Z: TMtxVec; const zScale: Double): Vector; overload; (* Compute X*yScalar - Z*zScale, where X is a Matrix*) function MulAndSub(const X: TMtx; const Y: double; const Z: TMtxVec; const zScale: Double): Matrix; overload; (* Compute X*yScalar - Z*zScale*) function MulAndSub(const X: TVec; const Y: TCplx; const Z: TMtxVec; const zScale: TCplx): Vector; overload; (* Compute X*yScalar - Z*zScale, where X is a Matrix*) function MulAndSub(const X: TMtx; const Y: TCplx; const Z: TMtxVec; const zScale: TCplx): Matrix; overload; (* Compute (X / Y)*xyScale + Z*zScale Computes the expression (X divided by Y) multiplied by xyScale plus Z multiplied by zScale, without creating temporary objects. : using Dew.Math; using Dew.Math.Units; namespace Dew.Examples { void Example() { double xyScale = 1.5, zScale = 2.0; Vector X = (Vector) new double[] { 8, 10, 12, 14 }; Vector Y = (Vector) new double[] { 2, 2, 2, 2 }; Vector Z = (Vector) new double[] { 1, 1, 1, 1 }; Vector A1 = (X / Y) * xyScale + Z * zScale; Vector A2 = DivAndAdd(X, xyScale, Y, xyScale, Z, zScale); Vector A3 = new Vector(); A3.DivAndAdd(X, xyScale, Y, xyScale, Z, zScale); if (!A2.IsEqual(A1)) Math387.ERaise("Problem"); if (!A3.IsEqual(A1)) Math387.ERaise("Problem"); } } *) function DivAndAdd(const X: TVec; const Y: TMtxVec; const xyScale: Double; const Z: TMtxVec; const zScale: Double): Vector; overload; (* Compute (X / Y)*xyScale + Z*zScale, where X is a Matrix. The operation does only per-element math. *) function DivAndAdd(const X: TMtx; const Y: TMtxVec; const xyScale: Double; const Z: TMtxVec; const zScale: Double): Matrix; overload; (* Compute (X / Y)*xyScale + Z*zScale. The operation does only per-element math. *) function DivAndAdd(const X: TVec; const Y: TMtxVec; const xyScale: TCplx; const Z: TMtxVec; const zScale: TCplx): Vector; overload; (* Compute (X / Y)*xyScale + Z*zScale, where X is a Matrix. The operation does only per-element math. *) function DivAndAdd(const X: TMtx; const Y: TMtxVec; const xyScale: TCplx; const Z: TMtxVec; const zScale: TCplx): Matrix; overload; (* Compute (X / Y)*xyScale + zScalar Computes the expression (X divided by Y) multiplied by xyScale plus a scalar zScalar, without creating temporary objects. : using Dew.Math; using Dew.Math.Units; namespace Dew.Examples { void Example() { double xyScale = 1.5, zScalar = 2.0; Vector X = (Vector) new double[] { 8, 10, 12, 14 }; Vector Y = (Vector) new double[] { 2, 2, 2, 2 }; Vector A1 = (X / Y) * xyScale + zScalar; Vector A2 = DivAndAdd(X, xyScale, Y, xyScale, zScalar); Vector A3 = new Vector(); A3.DivAndAdd(X, xyScale, Y, xyScale, zScalar); if (!A2.IsEqual(A1)) Math387.ERaise("Problem"); if (!A3.IsEqual(A1)) Math387.ERaise("Problem"); } } *) function DivAndAdd(const X: TVec; const Y: TMtxVec; const xyScale: Double; const Z: Double): Vector; overload; (* Compute (X / Y)*xyScale + zScalar, where X is a Matrix The operation does only per-element math. *) function DivAndAdd(const X: TMtx; const Y: TMtxVec; const xyScale: Double; const Z: Double): Matrix; overload; (* Compute (X / Y)*xyScale + zScalar The operation does only per-element math. *) function DivAndAdd(const X: TVec; const Y: TMtxVec; const xyScale: TCplx; const Z: TCplx): Vector; overload; (* Compute (X / Y)*xyScale + zScalar, where X is a Matrix The operation does only per-element math. *) function DivAndAdd(const X: TMtx; const Y: TMtxVec; const xyScale: TCplx; const Z: TCplx): Matrix; overload; (* Compute (X / Y) * xyScale - Z*zScale Divides X by Y, scales the quotient by xyScale, then subtracts Z scaled by zScale, all without temporary objects. : using Dew.Math; using Dew.Math.Units; namespace Dew.Examples { void Example() { double xyScale = 1.5, zScale = 2.0; Vector X = (Vector) new double[] { 8, 10, 12, 14 }; Vector Y = (Vector) new double[] { 2, 2, 2, 2 }; Vector Z = (Vector) new double[] { 1, 1, 1, 1 }; Vector A1 = (X / Y) * xyScale - Z * zScale; Vector A2 = DivAndSub(X, xyScale, Y, xyScale, Z, zScale); Vector A3 = new Vector(); A3.DivAndSub(X, xyScale, Y, xyScale, Z, zScale); if (!A2.IsEqual(A1)) Math387.ERaise("Problem"); if (!A3.IsEqual(A1)) Math387.ERaise("Problem"); } } *) function DivAndSub(const X: TVec; const Y: TMtxVec; const xyScale: Double; const Z: TMtxVec; const zScale: Double): Vector; overload; (* Compute (X / Y) * xyScale - Z*zScale, where X is a Matrix The operation does only per-element math. *) function DivAndSub(const X: TMtx; const Y: TMtxVec; const xyScale: Double; const Z: TMtxVec; const zScale: Double): Matrix; overload; (* Compute (X / Y) * xyScale - Z*zScale The operation does only per-element math. *) function DivAndSub(const X: TVec; const Y: TMtxVec; const xyScale: TCplx; const Z: TMtxVec; const zScale: TCplx): Vector; overload; (* Compute (X / Y) * xyScale - Z*zScale, where X is a Matrix The operation does only per-element math. *) function DivAndSub(const X: TMtx; const Y: TMtxVec; const xyScale: TCplx; const Z: TMtxVec; const zScale: TCplx): Matrix; overload; (* Compute (X / Y) * xyScale - zScalar Computes the expression (X divided by Y) multiplied by xyScale and then subtracts the scalar zScalar, all without temporary objects. : using Dew.Math; using Dew.Math.Units; namespace Dew.Examples { void Example() { double xyScale = 1.5, zScalar = 2.0; Vector X = (Vector) new double[] { 8, 10, 12, 14 }; Vector Y = (Vector) new double[] { 2, 2, 2, 2 }; Vector A1 = (X / Y) * xyScale - zScalar; Vector A2 = DivAndSub(X, xyScale, Y, xyScale, zScalar); Vector A3 = new Vector(); A3.DivAndSub(X, xyScale, Y, xyScale, zScalar); if (!A2.IsEqual(A1)) Math387.ERaise("Problem"); if (!A3.IsEqual(A1)) Math387.ERaise("Problem"); } } *) function DivAndSub(const X: TVec; const Y: TMtxVec; const xyScale: Double; const Z: Double): Vector; overload; (* Compute (X / Y) * xyScale - zScalar, where X is a Matrix The operation does only per-element math. *) function DivAndSub(const X: TMtx; const Y: TMtxVec; const xyScale: Double; const Z: Double): Matrix; overload; (* Compute (X / Y) * xyScale - zScalar The operation does only per-element math. *) function DivAndSub(const X: TVec; const Y: TMtxVec; const xyScale: TCplx; const Z: TCplx): Vector; overload; (* Compute (X / Y) * xyScale - zScalar, where X is a Matrix The operation does only per-element math. *) function DivAndSub(const X: TMtx; const Y: TMtxVec; const xyScale: TCplx; const Z: TCplx): Matrix; overload; (* Compute X + Y*yScale Computes the sum of two vector-based operands, X and Y, where Y is first scaled by yScale. This operation is performed without creating temporary objects. : using Dew.Math; using Dew.Math.Units; namespace Dew.Examples { void Example() { double yScale = 1.5; Vector X = (Vector) new double[] { 1, 2, 3, 4 }; Vector Y = (Vector) new double[] { 2, 3, 4, 5 }; Vector A1 = X + Y * yScale; Vector A2 = AddScaled(X, Y, yScale); Vector A3 = new Vector(); A3.AddScaled(X, Y, yScale); if (!A2.IsEqual(A1)) Math387.ERaise("Problem"); if (!A3.IsEqual(A1)) Math387.ERaise("Problem"); } } *) function AddScaled(const X: TVec; const Y: TMtxVec; const yScale: Double): Vector; overload; (* Compute X + Y*yScale, where X is a Matrix. *) function AddScaled(const X: TMtx; const Y: TMtxVec; const yScale: Double): Matrix; overload; (* Compute X + Y*yScale *) function AddScaled(const X: TVec; const Y: TMtxVec; const yScale: TCplx): Vector; overload; (* Compute X + Y*yScale, where X is a Matrix. *) function AddScaled(const X: TMtx; const Y: TMtxVec; const yScale: TCplx): Matrix; overload; (* Compute X + Y + Z Computes the sum of three vector-based operands, X, Y, and Z, without creating temporary objects. : using Dew.Math; using Dew.Math.Units; namespace Dew.Examples { void Example() { Vector X = (Vector) new double[] { 1, 2, 3, 4 }; Vector Y = (Vector) new double[] { 2, 3, 4, 5 }; Vector Z = (Vector) new double[] { 3, 4, 5, 6 }; Vector A1 = X + Y + Z; Vector A2 = Add(X, Y, Z); Vector A3 = new Vector(); A3.Add(X, Y, Z); if (!A2.IsEqual(A1)) Math387.ERaise("Problem"); if (!A3.IsEqual(A1)) Math387.ERaise("Problem"); } } *) function Add(const X: TVec; const Y, Z: TMtxVec): Vector; overload; (* Compute X + Y + Z, where X is a Matrix. *) function Add(const X: TMtx; const Y, Z: TMtxVec): Matrix; overload; (* Compute X + Y + Z*zScale Computes the sum of X and Y plus Z scaled by zScale without creating temporary objects. : using Dew.Math; using Dew.Math.Units; namespace Dew.Examples { void Example() { double zScale = 2.0; Vector X = (Vector) new double[] { 1, 2, 3, 4 }; Vector Y = (Vector) new double[] { 2, 3, 4, 5 }; Vector Z = (Vector) new double[] { 3, 4, 5, 6 }; Vector A1 = X + Y + Z * zScale; Vector A2 = AddScaled(X, Y, Z, zScale); Vector A3 = new Vector(); A3.AddScaled(X, Y, Z, zScale); if (!A2.IsEqual(A1)) Math387.ERaise("Problem"); if (!A3.IsEqual(A1)) Math387.ERaise("Problem"); } } *) function AddScaled(const X: TVec; const Y, Z: TMtxVec; const zScale: Double): Vector; overload; (* Compute X + Y + Z*zScale, where X is a Matrix. *) function AddScaled(const X: TMtx; const Y, Z: TMtxVec; const zScale: Double): Matrix; overload; (* Compute X + Y + Z*zScale *) function AddScaled(const X: TVec; const Y, Z: TMtxVec; const zScale: TCplx): Vector; overload; (* Compute X + Y + Z*zScale, where X is a Matrix. *) function AddScaled(const X: TMtx; const Y, Z: TMtxVec; const zScale: TCplx): Matrix; overload; (* Compute X + Y*yScale + Z*zScale Computes the sum of X and Y scaled by yScale plus Z scaled by zScale without temporary objects. : using Dew.Math; using Dew.Math.Units; namespace Dew.Examples { void Example() { double yScale = 1.5, zScale = 2.0; Vector X = (Vector) new double[] { 1, 2, 3, 4 }; Vector Y = (Vector) new double[] { 2, 3, 4, 5 }; Vector Z = (Vector) new double[] { 3, 4, 5, 6 }; Vector A1 = X + Y * yScale + Z * zScale; Vector A2 = AddScaled(X, Y, yScale, Z, zScale); Vector A3 = new Vector(); A3.AddScaled(X, Y, yScale, Z, zScale); if (!A2.IsEqual(A1)) Math387.ERaise("Problem"); if (!A3.IsEqual(A1)) Math387.ERaise("Problem"); } } *) function AddScaled(const X: TVec; const Y: TMtxVec; const yScale: Double; const Z: TMtxVec; const zScale: Double): Vector; overload; (* Compute X + Y*yScale + Z*zScale, where X is a Matrix. *) function AddScaled(const X: TMtx; const Y: TMtxVec; const yScale: Double; const Z: TMtxVec; const zScale: Double): Matrix; overload; (* Compute X + Y*yScale + Z*zScale*) function AddScaled(const X: TVec; const Y: TMtxVec; const yScale: TCplx; const Z: TMtxVec; const zScale: TCplx): Vector; overload; (* Compute X + Y*yScale + Z*zScale, where X is a Matrix. *) function AddScaled(const X: TMtx; const Y: TMtxVec; const yScale: TCplx; const Z: TMtxVec; const zScale: TCplx): Matrix; overload; (* Compute X + Y + zScalar Computes the sum of X and Y with an added scalar zScalar without temporary objects. : using Dew.Math; using Dew.Math.Units; namespace Dew.Examples { void Example() { double zScalar = 3.0; Vector X = (Vector) new double[] { 1, 2, 3, 4 }; Vector Y = (Vector) new double[] { 2, 3, 4, 5 }; Vector A1 = X + Y + zScalar; Vector A2 = Add(X, Y, zScalar); Vector A3 = new Vector(); A3.Add(X, Y, zScalar); if (!A2.IsEqual(A1)) Math387.ERaise("Problem"); if (!A3.IsEqual(A1)) Math387.ERaise("Problem"); } } *) function Add(const X: TVec; const Y: TMtxVec; const Z: Double): Vector; overload; (* Compute X + Y + zScalar, where X is a Matrix. *) function Add(const X: TMtx; const Y: TMtxVec; const Z: Double): Matrix; overload; (* Compute X + Y + zScalar *) function Add(const X: TVec; const Y: TMtxVec; const Z: TCplx): Vector; overload; (* Compute X + Y + zScalar, where X is a Matrix. *) function Add(const X: TMtx; const Y: TMtxVec; const Z: TCplx): Matrix; overload; (* Compute X + Y*yScale + zScalar Computes the sum of X and Y scaled by yScale, with an added scalar zScalar, without creating temporary objects. : using Dew.Math; using Dew.Math.Units; namespace Dew.Examples { void Example() { double yScale = 1.5, zScalar = 3.0; Vector X = (Vector) new double[] { 1, 2, 3, 4 }; Vector Y = (Vector) new double[] { 2, 3, 4, 5 }; Vector A1 = X + Y * yScale + zScalar; Vector A2 = AddScaledC(X, Y, yScale, zScalar); Vector A3 = new Vector(); A3.AddScaledC(X, Y, yScale, zScalar); if (!A2.IsEqual(A1)) Math387.ERaise("Problem"); if (!A3.IsEqual(A1)) Math387.ERaise("Problem"); } } *) function AddScaledC(const X: TVec; const Y: TMtxVec; const yScale: Double; const Z: Double): Vector; overload; (* Compute X + Y*yScale + zScalar, where X is a Matrix. *) function AddScaledC(const X: TMtx; const Y: TMtxVec; const yScale: Double; const Z: Double): Matrix; overload; (* Compute X + Y*yScale + zScalar*) function AddScaledC(const X: TVec; const Y: TMtxVec; const yScale: TCplx; const Z: TCplx): Vector; overload; (* Compute X + Y*yScale + zScalar, where X is a Matrix. *) function AddScaledC(const X: TMtx; const Y: TMtxVec; const yScale: TCplx; const Z: TCplx): Matrix; overload; (* Compute X - Y - Z Computes the difference of three vector-based operands (X, Y, and Z) without creating temporary objects. : using Dew.Math; using Dew.Math.Units; namespace Dew.Examples { void Example() { Vector X = (Vector) new double[] { 5, 6, 7, 8 }; Vector Y = (Vector) new double[] { 1, 2, 3, 4 }; Vector Z = (Vector) new double[] { 1, 1, 1, 1 }; Vector A1 = X - Y - Z; Vector A2 = Sub(X, Y, Z); Vector A3 = new Vector(); A3.Sub(X, Y, Z); if (!A2.IsEqual(A1)) Math387.ERaise("Problem"); if (!A3.IsEqual(A1)) Math387.ERaise("Problem"); } } *) function Sub(const X: TVec; const Y, Z: TMtxVec): Vector; overload; (* Compute X - Y - Z, where X is a Matrix *) function Sub(const X: TMtx; const Y, Z: TMtxVec): Matrix; overload; (* Compute X - Y*yScale - Z*zScale Computes the difference between X and Y scaled by yScale, then subtracts Z scaled by zScale, without creating temporary objects. : using Dew.Math; using Dew.Math.Units; namespace Dew.Examples { void Example() { double yScale = 1.5, zScale = 2.0; Vector X = (Vector) new double[] { 5, 6, 7, 8 }; Vector Y = (Vector) new double[] { 1, 2, 3, 4 }; Vector Z = (Vector) new double[] { 1, 1, 1, 1 }; Vector A1 = X - Y * yScale - Z * zScale; Vector A2 = SubScaled(X, Y, yScale, Z, zScale); Vector A3 = new Vector(); A3.SubScaled(X, Y, yScale, Z, zScale); if (!A2.IsEqual(A1)) Math387.ERaise("Problem"); if (!A3.IsEqual(A1)) Math387.ERaise("Problem"); } } *) function SubScaled(const X: TVec; const Y: TMtxVec; const yScale: Double; const Z: TMtxVec; const zScale: Double): Vector; overload; (* Compute X - Y*yScale - Z*zScale, where X is a Matrix. *) function SubScaled(const X: TMtx; const Y: TMtxVec; const yScale: Double; const Z: TMtxVec; const zScale: Double): Matrix; overload; (* Compute X - Y*yScale - Z*zScale *) function SubScaled(const X: TVec; const Y: TMtxVec; const yScale: TCplx; const Z: TMtxVec; const zScale: TCplx): Vector; overload; (* Compute X - Y*yScale - Z*zScale, where X is a Matrix. *) function SubScaled(const X: TMtx; const Y: TMtxVec; const yScale: TCplx; const Z: TMtxVec; const zScale: TCplx): Matrix; overload; (* Compute X - Y - Z*zScale Computes the difference between X and Y, then subtracts Z scaled by zScale, without creating temporary objects. : using Dew.Math; using Dew.Math.Units; namespace Dew.Examples { void Example() { double zScale = 2.0; Vector X = (Vector) new double[] { 5, 6, 7, 8 }; Vector Y = (Vector) new double[] { 1, 2, 3, 4 }; Vector Z = (Vector) new double[] { 1, 1, 1, 1 }; Vector A1 = X - Y - Z * zScale; Vector A2 = SubScaled(X, Y, Z, zScale); Vector A3 = new Vector(); A3.Sub(X, Y, Z * zScale); // Or via a dedicated overload if available. if (!A2.IsEqual(A1)) Math387.ERaise("Problem"); if (!A3.IsEqual(A1)) Math387.ERaise("Problem"); } } *) function SubScaled(const X: TVec; const Y, Z: TMtxVec; const zScale: Double): Vector; overload; (* Compute X - Y - Z*zScale, where X is a Matrix. *) function SubScaled(const X: TMtx; const Y, Z: TMtxVec; const zScale: Double): Matrix; overload; (* Compute X - Y - Z*zScale *) function SubScaled(const X: TVec; const Y, Z: TMtxVec; const zScale: TCplx): Vector; overload; (* Compute X - Y - Z*zScale, where X is a Matrix. *) function SubScaled(const X: TMtx; const Y, Z: TMtxVec; const zScale: TCplx): Matrix; overload; (* Compute X - Y - zScalar Computes the difference between X and Y and then subtracts a scalar zScalar, without creating temporary objects. : using Dew.Math; using Dew.Math.Units; namespace Dew.Examples { void Example() { double zScalar = 3.0; Vector X = (Vector) new double[] { 5, 6, 7, 8 }; Vector Y = (Vector) new double[] { 1, 2, 3, 4 }; Vector A1 = X - Y - zScalar; Vector A2 = Sub(X, Y, zScalar); Vector A3 = new Vector(); A3.Sub(X, Y, zScalar); if (!A2.IsEqual(A1)) Math387.ERaise("Problem"); if (!A3.IsEqual(A1)) Math387.ERaise("Problem"); } } *) function Sub(const X: TVec; const Y: TMtxVec; const Z: Double): Vector; overload; (* Compute X - Y - zScalar, where X is a Matrix. *) function Sub(const X: TMtx; const Y: TMtxVec; const Z: Double): Matrix; overload; (* Compute X - Y - zScalar *) function Sub(const X: TVec; const Y: TMtxVec; const Z: TCplx): Vector; overload; (* Compute X - Y - zScalar, where X is a Matrix. *) function Sub(const X: TMtx; const Y: TMtxVec; const Z: TCplx): Matrix; overload; (* Compute X - Y*yScale - zScalar Computes the result of subtracting Y scaled by yScale and a scalar zScalar from X, without creating temporary objects. : using Dew.Math; using Dew.Math.Units; namespace Dew.Examples { void Example() { double yScale = 1.5, zScalar = 3.0; Vector X = (Vector) new double[] { 5, 6, 7, 8 }; Vector Y = (Vector) new double[] { 1, 2, 3, 4 }; Vector A1 = X - Y * yScale - zScalar; Vector A2 = SubScaledC(X, yScale, Y, zScalar); // Adjust parameter order if needed. Vector A3 = new Vector(); A3.SubScaledC(X, yScale, Y, zScalar); if (!A2.IsEqual(A1)) Math387.ERaise("Problem"); if (!A3.IsEqual(A1)) Math387.ERaise("Problem"); } } *) function SubScaledC(const X: TVec; const Y: TMtxVec; const yScale: Double; const Z: Double): Vector; overload; (* Compute X - Y*yScale - zScalar, where X is a Matrix *) function SubScaledC(const X: TMtx; const Y: TMtxVec; const yScale: Double; const Z: Double): Matrix; overload; (* Compute X - Y*yScale - zScalar *) function SubScaledC(const X: TVec; const Y: TMtxVec; const yScale: TCplx; const Z: TCplx): Vector; overload; (* Compute X - Y*yScale - zScalar, where X is a Matrix*) function SubScaledC(const X: TMtx; const Y: TMtxVec; const yScale: TCplx; const Z: TCplx): Matrix; overload; (* Compute X * Y / Z Computes the element-wise product of X and Y, then divides the result by Z, all without creating temporary objects. : using Dew.Math; using Dew.Math.Units; namespace Dew.Examples { void Example() { Vector X = (Vector) new double[] { 4, 8, 12, 16 }; Vector Y = (Vector) new double[] { 2, 2, 2, 2 }; Vector Z = (Vector) new double[] { 2, 4, 6, 8 }; Vector A1 = (X * Y) / Z; Vector A2 = MulAndDiv(X, Y, Z); Vector A3 = new Vector(); A3.MulAndDiv(X, Y, Z); if (!A2.IsEqual(A1)) Math387.ERaise("Problem"); if (!A3.IsEqual(A1)) Math387.ERaise("Problem"); } } *) function MulAndDiv(const X: TVec; const Y, Z: TMtxVec): Vector; overload; (* Compute X * Y / Z, where X is a Matrix The operation does only per-element math. *) function MulAndDiv(const X: TMtx; const Y, Z: TMtxVec): Matrix; overload; (* Compute (X + Y)*Z Computes the product of the sum of X and Y multiplied by Z without temporary objects. : using Dew.Math; using Dew.Math.Units; namespace Dew.Examples { void Example() { Vector X = (Vector) new double[] { 1, 2, 3, 4 }; Vector Y = (Vector) new double[] { 2, 3, 4, 5 }; Vector Z = (Vector) new double[] { 3, 4, 5, 6 }; Vector A1 = (X + Y) * Z; Vector A2 = AddAndMul(X, Y, Z); Vector A3 = new Vector(); A3.AddAndMul(X, Y, Z); if (!A2.IsEqual(A1)) Math387.ERaise("Problem"); if (!A3.IsEqual(A1)) Math387.ERaise("Problem"); } } *) function AddAndMul(const X: TVec; const Y, Z: TMtxVec): Vector; overload; (* Compute (X + Y)*Z, where X is a Matrix The operation does only per-element math. *) function AddAndMul(const X: TMtx; const Y, Z: TMtxVec): Matrix; overload; (* Compute (X + Y)*Z*zScale Computes the product of (X + Y) multiplied by Z and then by the scalar zScale, all without creating temporary objects. : using Dew.Math; using Dew.Math.Units; namespace Dew.Examples { void Example() { double zScale = 2.0; Vector X = (Vector) new double[] { 1, 2, 3, 4 }; Vector Y = (Vector) new double[] { 2, 3, 4, 5 }; Vector Z = (Vector) new double[] { 3, 4, 5, 6 }; Vector A1 = (X + Y) * Z * zScale; Vector A2 = AddAndMul(X, Y, Z, zScale); Vector A3 = new Vector(); A3.AddAndMul(X, Y, Z, zScale); if (!A2.IsEqual(A1)) Math387.ERaise("Problem"); if (!A3.IsEqual(A1)) Math387.ERaise("Problem"); } } *) function AddAndMul(const X: TVec; const Y, Z: TMtxVec; const zScale: double): Vector; overload; (* Compute (X + Y)*Z*zScale, where X is a Matrix The operation does only per-element math. *) function AddAndMul(const X: TMtx; const Y, Z: TMtxVec; const zScale: double): Matrix; overload; (* Compute (X + Y*yScale)*Z*zScale Computes the product of (X plus Y scaled by yScale) multiplied by Z and then by zScale, without temporary objects. : using Dew.Math; using Dew.Math.Units; namespace Dew.Examples { void Example() { double yScale = 1.5, zScale = 2.0; Vector X = (Vector) new double[] { 1, 2, 3, 4 }; Vector Y = (Vector) new double[] { 2, 3, 4, 5 }; Vector Z = (Vector) new double[] { 3, 4, 5, 6 }; Vector A1 = (X + Y * yScale) * Z * zScale; Vector A2 = AddAndMul(X, yScale, Y, yScale, Z, zScale); Vector A3 = new Vector(); A3.AddAndMul(X, yScale, Y, yScale, Z, zScale); if (!A2.IsEqual(A1)) Math387.ERaise("Problem"); if (!A3.IsEqual(A1)) Math387.ERaise("Problem"); } } *) function AddAndMul(const X: TVec; const Y: TMtxVec; const yScale: double; const Z: TMtxVec; const zScale: double): Vector; overload; (* Compute (X + Y*yScale)*Z*zScale, where X is a Matrix The operation does only per-element math. *) function AddAndMul(const X: TMtx; const Y: TMtxVec; const yScale: double; const Z: TMtxVec; const zScale: double): Matrix; overload; (* Compute (X + Y)*zScalar Computes the sum of X and Y multiplied by the scalar zScalar without temporary objects. : using Dew.Math; using Dew.Math.Units; namespace Dew.Examples { void Example() { double zScalar = 3.0; Vector X = (Vector) new double[] { 1, 2, 3, 4 }; Vector Y = (Vector) new double[] { 2, 3, 4, 5 }; Vector A1 = (X + Y) * zScalar; Vector A2 = AddAndMul(X, Y, zScalar); Vector A3 = new Vector(); A3.AddAndMul(X, Y, zScalar); if (!A2.IsEqual(A1)) Math387.ERaise("Problem"); if (!A3.IsEqual(A1)) Math387.ERaise("Problem"); } } *) function AddAndMul(const X: TVec; const Y: TMtxVec; const Z: Double): Vector; overload; (* Compute (X + Y)*zScalar, where X is a Matrix *) function AddAndMul(const X: TMtx; const Y: TMtxVec; const Z: Double): Matrix; overload; (* Compute (X + Y*yScale)*zScalar Computes the expression (X + Y*yScale) multiplied by a scalar zScalar without temporary objects. : using Dew.Math; using Dew.Math.Units; namespace Dew.Examples { void Example() { double yScale = 1.5, zScalar = 3.0; Vector X = (Vector) new double[] { 1, 2, 3, 4 }; Vector Y = (Vector) new double[] { 2, 3, 4, 5 }; Vector A1 = (X + Y * yScale) * zScalar; Vector A2 = AddAndMul(X, yScale, Y, yScale, zScalar); Vector A3 = new Vector(); A3.AddAndMul(X, yScale, Y, yScale, zScalar); if (!A2.IsEqual(A1)) Math387.ERaise("Problem"); if (!A3.IsEqual(A1)) Math387.ERaise("Problem"); } } *) function AddAndMul(const X: TVec; const Y: TMtxVec; const yScale, Z: Double): Vector; overload; (* Compute (X + Y*yScale)*zScalar, where X is a Matrix. *) function AddAndMul(const X: TMtx; const Y: TMtxVec; const yScale, Z: Double): Matrix; overload; (* Compute (X + yScalar)*Z*zScale Computes the expression (X + yScalar) multiplied by Z and then by zScale, without creating temporary objects. : using Dew.Math; using Dew.Math.Units; namespace Dew.Examples { void Example() { double yScalar = 2.0, zScale = 3.0; Vector X = (Vector) new double[] { 1, 2, 3, 4 }; Vector Z = (Vector) new double[] { 3, 4, 5, 6 }; Vector A1 = (X + yScalar) * Z * zScale; Vector A2 = AddAndMul(X, yScalar, Z, zScale); Vector A3 = new Vector(); A3.AddAndMul(X, yScalar, Z, zScale); if (!A2.IsEqual(A1)) Math387.ERaise("Problem"); if (!A3.IsEqual(A1)) Math387.ERaise("Problem"); } } *) function AddAndMul(const X: TVec; Y: Double; const Z: TMtxVec; const zScale: Double): Vector; overload; (* Compute (X + yScalar)*Z*zScale, where X is a Matrix The operation does only per-element math. *) function AddAndMul(const X: TMtx; Y: Double; const Z: TMtxVec; const zScale: Double): Matrix; overload; (* Compute (X*xScale + yScalar)*Z Computes the expression (X scaled by xScale plus the scalar yScalar) multiplied by Z, without creating temporary objects. : using Dew.Math; using Dew.Math.Units; namespace Dew.Examples { void Example() { double xScale = 1.0, yScalar = 2.0; Vector X = (Vector) new double[] { 1, 2, 3, 4 }; Vector Z = (Vector) new double[] { 3, 4, 5, 6 }; Vector A1 = (X * xScale + yScalar) * Z; Vector A2 = AddAndMul(X, xScale, yScalar, Z); Vector A3 = new Vector(); A3.AddAndMul(X, xScale, yScalar, Z); if (!A2.IsEqual(A1)) Math387.ERaise("Problem"); if (!A3.IsEqual(A1)) Math387.ERaise("Problem"); } } *) function AddAndMul(const X: TVec; const xScale, Y: Double; const Z: TMtxVec): Vector; overload; (* Compute (X*xScale + yScalar)*Z, where X is a Matrix. The operation does only per-element math. *) function AddAndMul(const X: TMtx; const xScale, Y: Double; const Z: TMtxVec): Matrix; overload; (* Compute (X + yScalar)*Z Computes the expression (X plus the scalar yScalar) multiplied by Z, without creating temporary objects. : using Dew.Math; using Dew.Math.Units; namespace Dew.Examples { void Example() { double yScalar = 2.0; Vector X = (Vector) new double[] { 1, 2, 3, 4 }; Vector Z = (Vector) new double[] { 3, 4, 5, 6 }; Vector A1 = (X + yScalar) * Z; Vector A2 = AddAndMul(X, yScalar, Z); Vector A3 = new Vector(); A3.AddAndMul(X, yScalar, Z); if (!A2.IsEqual(A1)) Math387.ERaise("Problem"); if (!A3.IsEqual(A1)) Math387.ERaise("Problem"); } } *) function AddAndMul(const X: TVec; Y: Double; const Z: TMtxVec): Vector; overload; (* Compute (X + yScalar)*Z, where X is a Matrix The operation does only per-element math. *) function AddAndMul(const X: TMtx; Y: Double; const Z: TMtxVec): Matrix; overload; (* Compute (X + yScalar)*zScalar Computes the result of adding the scalar yScalar to X and then multiplying by the scalar zScalar, without creating temporary objects. : using Dew.Math; using Dew.Math.Units; namespace Dew.Examples { void Example() { double yScalar = 2.0, zScalar = 3.0; Vector X = (Vector) new double[] { 1, 2, 3, 4 }; Vector A1 = (X + yScalar) * zScalar; Vector A2 = AddAndMul(X, yScalar, zScalar); Vector A3 = new Vector(); A3.AddAndMul(X, yScalar, zScalar); if (!A2.IsEqual(A1)) Math387.ERaise("Problem"); if (!A3.IsEqual(A1)) Math387.ERaise("Problem"); } } *) function AddAndMul(const X: TVec; Y, Z: Double): Vector; overload; (* Compute (X + yScalar)*zScalar, where X is a Matrix*) function AddAndMul(const X: TMtx; Y, Z: Double): Matrix; overload; (* Compute (X - Y)*Z Computes the product of the difference between X and Y multiplied by Z without creating temporary objects. : using Dew.Math; using Dew.Math.Units; namespace Dew.Examples { void Example() { Vector X = (Vector) new double[] { 5, 6, 7, 8 }; Vector Y = (Vector) new double[] { 1, 2, 3, 4 }; Vector Z = (Vector) new double[] { 2, 2, 2, 2 }; Vector A1 = (X - Y) * Z; Vector A2 = SubAndMul(X, Y, Z); Vector A3 = new Vector(); A3.SubAndMul(X, Y, Z); if (!A2.IsEqual(A1)) Math387.ERaise("Problem"); if (!A3.IsEqual(A1)) Math387.ERaise("Problem"); } } *) function SubAndMul(const X: TVec; const Y, Z: TMtxVec): Vector; overload; (* Compute (X - Y)*Z, where X is a Matrix The operation does only per-element math. *) function SubAndMul(const X: TMtx; const Y, Z: TMtxVec): Matrix; overload; (* Compute (X - Y)*Z*zScale Computes the product of (X - Y) multiplied by Z and then scaled by zScale, without creating temporary objects. : using Dew.Math; using Dew.Math.Units; namespace Dew.Examples { void Example() { double zScale = 3.0; Vector X = (Vector) new double[] { 5, 6, 7, 8 }; Vector Y = (Vector) new double[] { 1, 2, 3, 4 }; Vector Z = (Vector) new double[] { 2, 2, 2, 2 }; Vector A1 = (X - Y) * Z * zScale; Vector A2 = SubAndMul(X, Y, Z, zScale); Vector A3 = new Vector(); A3.SubAndMul(X, Y, Z, zScale); if (!A2.IsEqual(A1)) Math387.ERaise("Problem"); if (!A3.IsEqual(A1)) Math387.ERaise("Problem"); } } *) function SubAndMul(const X: TVec; const Y, Z: TMtxVec; const zScale: Double): Vector; overload; (* Compute (X - Y)*Z*zScale, where X is a Matrix The operation does only per-element math. *) function SubAndMul(const X: TMtx; const Y, Z: TMtxVec; const zScale: Double): Matrix; overload; (* Compute (X - Y*yScale)*Z*zScale Computes the product of (X minus Y scaled by yScale) multiplied by Z and then by zScale, without creating temporary objects. : using Dew.Math; using Dew.Math.Units; namespace Dew.Examples { void Example() { double yScale = 1.5, zScale = 2.0; Vector X = (Vector) new double[] { 5, 6, 7, 8 }; Vector Y = (Vector) new double[] { 1, 2, 3, 4 }; Vector Z = (Vector) new double[] { 2, 2, 2, 2 }; Vector A1 = (X - Y * yScale) * Z * zScale; Vector A2 = SubAndMul(X, yScale, Y, yScale, Z, zScale); Vector A3 = new Vector(); A3.SubAndMul(X, yScale, Y, yScale, Z, zScale); if (!A2.IsEqual(A1)) Math387.ERaise("Problem"); if (!A3.IsEqual(A1)) Math387.ERaise("Problem"); } } *) function SubAndMul(const X: TVec; const Y: TMtxVec; const yScale: Double; const Z: TMtxVec; const zScale: Double): Vector; overload; function SubAndMul(const X: TMtx; const Y: TMtxVec; const yScale: Double; const Z: TMtxVec; const zScale: Double): Matrix; overload; function SubAndMul(const X: TVec; const Y: TMtxVec; const Z: Double): Vector; overload; function SubAndMul(const X: TMtx; const Y: TMtxVec; const Z: Double): Matrix; overload; function SubAndMul(const X: TVec; const Y: TMtxVec; const yScale: Double; const Z: Double): Vector; overload; function SubAndMul(const X: TMtx; const Y: TMtxVec; const yScale: Double; const Z: Double): Matrix; overload; function SubAndMul(const X: TVec; Y: Double; const Z: TMtxVec; const zScale: Double): Vector; overload; function SubAndMul(const X: TMtx; Y: Double; const Z: TMtxVec; const zScale: Double): Matrix; overload; function SubAndMul(const X: TVec; const xScale, Y: Double; const Z: TMtxVec): Vector; overload; function SubAndMul(const X: TMtx; const xScale, Y: Double; const Z: TMtxVec): Matrix; overload; function SubAndMul(const X: TVec; Y: Double; const Z: TMtxVec): Vector; overload; function SubAndMul(const X: TMtx; Y: Double; const Z: TMtxVec): Matrix; overload; function SubAndMul(const X: TVec; Y, Z: Double): Vector; overload; function SubAndMul(const X: TMtx; Y, Z: Double): Matrix; overload; function MulAndSub(const X: TVec; const Y, Z: TMtxVec): Vector; overload; function MulAndSub(const X: TMtx; const Y, Z: TMtxVec): Matrix; overload; function MulAndSub(const X: TVec; const Y: TMtxVec; const xyScale: Double; const Z: TMtxVec): Vector; overload; function MulAndSub(const X: TMtx; const Y: TMtxVec; const xyScale: Double; const Z: TMtxVec): Matrix; overload; function MulAndSub(const X: TVec; const Y, Z: TMtxVec; const zScale: Double): Vector; overload; function MulAndSub(const X: TMtx; const Y, Z: TMtxVec; const zScale: Double): Matrix; overload; function MulAndSub(const X: TVec; const Y: TMtxVec; const Z: Double): Vector; overload; function MulAndSub(const X: TMtx; const Y: TMtxVec; const Z: Double): Matrix; overload; function DivAndAdd(const X: TVec; const Y, Z: TMtxVec): Vector; overload; function DivAndAdd(const X: TMtx; const Y, Z: TMtxVec): Matrix; overload; function DivAndAdd(const X: TVec; const Y: TMtxVec; const xyScale: double; const Z: TMtxVec): Vector; overload; function DivAndAdd(const X: TMtx; const Y: TMtxVec; const xyScale: double; const Z: TMtxVec): Matrix; overload; function DivAndAdd(const X: TVec; const Y, Z: TMtxVec; const zScale: double): Vector; overload; function DivAndAdd(const X: TMtx; const Y, Z: TMtxVec; const zScale: double): Matrix; overload; function DivAndAdd(const X: TVec; const Y: TMtxVec; const Z: Double): Vector; overload; function DivAndAdd(const X: TMtx; const Y: TMtxVec; const Z: Double): Matrix; overload; function DivAndSub(const X: TVec; const Y, Z: TMtxVec): Vector; overload; function DivAndSub(const X: TMtx; const Y, Z: TMtxVec): Matrix; overload; function DivAndSub(const X: TVec; const Y: TMtxVec; const xyScale: double; const Z: TMtxVec): Vector; overload; function DivAndSub(const X: TMtx; const Y: TMtxVec; const xyScale: double; const Z: TMtxVec): Matrix; overload; function DivAndSub(const X: TVec; const Y, Z: TMtxVec; const zScale: double): Vector; overload; function DivAndSub(const X: TMtx; const Y, Z: TMtxVec; const zScale: double): Matrix; overload; function DivAndSub(const X: TVec; const Y: TMtxVec; const Z: Double): Vector; overload; function DivAndSub(const X: TMtx; const Y: TMtxVec; const Z: Double): Matrix; overload; function AddScaled(const X: TVec; const xScale: TCplx; const Y: TMtxVec; const yScale: TCplx): Vector; overload; function AddScaled(const X: TMtx; const xScale: TCplx; const Y: TMtxVec; const yScale: TCplx): Matrix; overload; function AddScaledSqr(const X: TVec; const xScale: TCplx; const Y: TMtxVec; const yScale: TCplx): Vector; overload; function AddScaledSqr(const X: TMtx; const xScale: TCplx; const Y: TMtxVec; const yScale: TCplx): Matrix; overload; function SqrAddScaled(const X: TVec; const xScale: TCplx; const Y: TMtxVec; const yScale: TCplx): Vector; overload; function SqrAddScaled(const X: TMtx; const xScale: TCplx; const Y: TMtxVec; const yScale: TCplx): Matrix; overload; function AddScaledSqr(const X: TVec; const Y: TMtxVec; const yScale: TCplx): Vector; overload; function AddScaledSqr(const X: TMtx; const Y: TMtxVec; const yScale: TCplx): Matrix; overload; function SqrAddScaled(const X: TVec; const Y: TMtxVec; const yScale: TCplx): Vector; overload; function SqrAddScaled(const X: TMtx; const Y: TMtxVec; const yScale: TCplx): Matrix; overload; function AddScaled(const X: TVec; const xScale: TCplx; const Y: TMtxVec; const yScale: TCplx; const Z: TMtxVec; const zScale: TCplx): Vector; overload; function AddScaled(const X: TMtx; const xScale: TCplx; const Y: TMtxVec; const yScale: TCplx; const Z: TMtxVec; const zScale: TCplx): Matrix; overload; function AddScaledC(const X: TVec; const xScale: TCplx; const Y: TMtxVec; const yScale: TCplx; const Z: TCplx): Vector; overload; function AddScaledC(const X: TMtx; const xScale: TCplx; const Y: TMtxVec; const yScale: TCplx; const Z: TCplx): Matrix; overload; function SubScaled(const X: TVec; const xScale: TCplx; const Y: TMtxVec; const yScale: TCplx; const Z: TMtxVec; const zScale: TCplx): Vector; overload; function SubScaled(const X: TMtx; const xScale: TCplx; const Y: TMtxVec; const yScale: TCplx; const Z: TMtxVec; const zScale: TCplx): Matrix; overload; function SubScaledC(const X: TVec; const xScale: TCplx; const Y: TMtxVec; const yScale: TCplx; const Z: TCplx): Vector; overload; function SubScaledC(const X: TMtx; const xScale: TCplx; const Y: TMtxVec; const yScale: TCplx; const Z: TCplx): Matrix; overload; function MulElem(const X: TVec; const Y: TMtxVec; const Z: TCplx): Vector; overload; function MulElem(const X: TMtx; const Y: TMtxVec; const Z: TCplx): Matrix; overload; function DivideElem(const X: TCplx; const Y: TVec; const Z: TMtxVec): Vector; overload; function DivideElem(const X: TCplx; const Y: TMtx; const Z: TMtxVec): Matrix; overload; function DivideElemC(const X: TVec; const Y: TMtxVec; const Z: TCplx): Vector; overload; function DivideElemC(const X: TMtx; const Y: TMtxVec; const Z: TCplx): Matrix; overload; function MulAndDiv(const X: TVec; const Y: TMtxVec; const xyScale: TCplx; const Z: TMtxVec): Vector; overload; function MulAndDiv(const X: TMtx; const Y: TMtxVec; const xyScale: TCplx; const Z: TMtxVec): Matrix; overload; function MulAndDiv(const X: TVec; const Y: TMtxVec; const Z: TCplx): Vector; overload; function MulAndDiv(const X: TMtx; const Y: TMtxVec; const Z: TCplx): Matrix; overload; function AddAndMul(const X: TVec; const xScale: TCplx; const Y: TMtxVec; const yScale: TCplx; const Z: TMtxVec; const zScale: TCplx): Vector; overload; function AddAndMul(const X: TMtx; const xScale: TCplx; const Y: TMtxVec; const yScale: TCplx; const Z: TMtxVec; const zScale: TCplx): Matrix; overload; function AddAndMul(const X: TVec; const xScale: TCplx; Y: TCplx; const Z: TMtxVec; const zScale: TCplx): Vector; overload; function AddAndMul(const X: TMtx; const xScale: TCplx; Y: TCplx; const Z: TMtxVec; const zScale: TCplx): Matrix; overload; function AddAndMul(const X: TVec; const xScale: TCplx; const Y: TMtxVec; const yScale: TCplx; const Z: TCplx): Vector; overload; function AddAndMul(const X: TMtx; const xScale: TCplx; const Y: TMtxVec; const yScale: TCplx; const Z: TCplx): Matrix; overload; function AddAndMul(const X: TVec; const xScale: TCplx; Y, Z: TCplx): Vector; overload; function AddAndMul(const X: TMtx; const xScale: TCplx; Y, Z: TCplx): Matrix; overload; function SubAndMul(const X: TVec; const Y: TMtxVec; const yScale: TCplx; const Z: TMtxVec; const zScale: TCplx): Vector; overload; function SubAndMul(const X: TMtx; const Y: TMtxVec; const yScale: TCplx; const Z: TMtxVec; const zScale: TCplx): Matrix; overload; function SubAndMul(const X: TVec; const Y, Z: TMtxVec; const zScale: TCplx): Vector; overload; function SubAndMul(const X: TMtx; const Y, Z: TMtxVec; const zScale: TCplx): Matrix; overload; function SubAndMul(const X: TVec; const Y: TMtxVec; const Z: TCplx): Vector; overload; function SubAndMul(const X: TMtx; const Y: TMtxVec; const Z: TCplx): Matrix; overload; function SubAndMul(const X: TVec; const Y: TMtxVec; const yScale: TCplx; const Z: TCplx): Vector; overload; function SubAndMul(const X: TMtx; const Y: TMtxVec; const yScale: TCplx; const Z: TCplx): Matrix; overload; function SubAndMul(const X: TVec; Y: TCplx; const Z: TMtxVec; const zScale: TCplx): Vector; overload; function SubAndMul(const X: TMtx; Y: TCplx; const Z: TMtxVec; const zScale: TCplx): Matrix; overload; function SubAndMul(const X: TVec; const xScale, Y: TCplx; const Z: TMtxVec): Vector; overload; function SubAndMul(const X: TMtx; const xScale, Y: TCplx; const Z: TMtxVec): Matrix; overload; function SubAndMul(const X: TVec; const Y: TCplx; const Z: TMtxVec): Vector; overload; function SubAndMul(const X: TMtx; const Y: TCplx; const Z: TMtxVec): Matrix; overload; function SubAndMul(const X: TVec; const Y, Z: TCplx): Vector; overload; function SubAndMul(const X: TMtx; const Y, Z: TCplx): Matrix; overload; function MulAndSub(const X: TVec; const Y: TMtxVec; const xyScale: TCplx; const Z: TMtxVec): Vector; overload; function MulAndSub(const X: TMtx; const Y: TMtxVec; const xyScale: TCplx; const Z: TMtxVec): Matrix; overload; function MulAndSub(const X: TVec; const Y, Z: TMtxVec; const zScale: TCplx): Vector; overload; function MulAndSub(const X: TMtx; const Y, Z: TMtxVec; const zScale: TCplx): Matrix; overload; function MulAndSub(const X: TVec; const Y: TMtxVec; const Z: TCplx): Vector; overload; function MulAndSub(const X: TMtx; const Y: TMtxVec; const Z: TCplx): Matrix; overload; function DivAndAdd(const X: TVec; const Y: TMtxVec; const xyScale: TCplx; const Z: TMtxVec): Vector; overload; function DivAndAdd(const X: TMtx; const Y: TMtxVec; const xyScale: TCplx; const Z: TMtxVec): Matrix; overload; function DivAndAdd(const X: TVec; const Y, Z: TMtxVec; const zScale: TCplx): Vector; overload; function DivAndAdd(const X: TMtx; const Y, Z: TMtxVec; const zScale: TCplx): Matrix; overload; function DivAndAdd(const X: TVec; const Y: TMtxVec; const Z: TCplx): Vector; overload; function DivAndAdd(const X: TMtx; const Y: TMtxVec; const Z: TCplx): Matrix; overload; function DivAndSub(const X: TVec; const Y: TMtxVec; const xyScale: TCplx; const Z: TMtxVec): Vector; overload; function DivAndSub(const X: TMtx; const Y: TMtxVec; const xyScale: TCplx; const Z: TMtxVec): Matrix; overload; function DivAndSub(const X: TVec; const Y, Z: TMtxVec; const zScale: TCplx): Vector; overload; function DivAndSub(const X: TMtx; const Y, Z: TMtxVec; const zScale: TCplx): Matrix; overload; function DivAndSub(const X: TVec; const Y: TMtxVec; const Z: TCplx): Vector; overload; function DivAndSub(const X: TMtx; const Y: TMtxVec; const Z: TCplx): Matrix; overload; function GatherSplit(const MaskVec, NotMaskVec: TVec; const Mask: TVecInt): Vector; function SortAscend(const X: TMtx): Matrix; overload; function SortAscend(const X: TMtx; Col: integer): Matrix; overload; function Sqr(const X :double): double; overload; function Round(const X: double): Int64; overload; function Roundf(const X: single): Int64; overload; function Trunc(const X: double): Int64; overload; function Truncf(const X: single): Int64; overload; function Abs(const X :double): double; overload; function Abs(const X :integer): integer; overload; function Sgn(const Src: TVec): Vector; overload; function Sgn(const Src: TMtx): Matrix; overload; (*Adds operator overloading support. The unit declares Vector and Matrix types for +, -, *, / operator support. *) unit MtxExprInt; interface {$I bdsppdefs.inc} uses MtxVec, Math387, AbstractMtxVec, MtxVecInt, AbstractMtxVecInt, MtxVecBase ,Classes ,Types ; {$HPPEMIT END '#include "MtxExprInt.h"'} {$HPPEMIT '#include '} {$HPPEMIT '#include '} type (*Integer vector class for operator overloading (Delphi 2006 and later). Declare VectorInt instead of TVecInt to take advantage ofoperator overloading. Be carefull to declare VectorInt only for local variables with short lifetime. Call the Create method for VectorInt, if the variable is a global variable or a variable with a longer life. It also makes sense to continue to use TVecInt for global vars. If the Create method (constuctor) is not called, the VectorInt record obtains TVecInt object from object cache (fastest create). If the Create mehod is called, the TVecInt object is created in the usual way (slower). Object cache has limited size. var b, c: VectorInt; bv: TVecInt; begin b := VectorInt(TIntegerArray.Create(1,1,1,1)); //b = [1,1,1,1]; bv := b; //b and bv point to same data object bv.Multiply(2); bv.Bits[76] := true; //set 76th bit in the array to 1 TVecInt(b).Multiply(2); //an alternative way to scale c := b*2 + 3; //c := b*2 + 2 + 3i c := b*bv; //mix VectorInt and TVecInt bv.Add(c); //pass VectorInt type and implicitely convert to TVecInt pointer b.PackBits(c); // store bit 1 in b for all elements in c which are different from zero. Bit 0 otherwise. end; *) VectorInt = record strict private FData: TVecInt; private function get_Data: TVecInt ; property Data: TVecInt read get_Data; private function get_BlockEnd: boolean; function get_IsSubRange: boolean; function get_Caption: string; function get_ConditionCheck: boolean; function get_Length: integer; function get_Tag: integer; procedure set_Caption(const value: string); procedure set_ConditionCheck(const value: boolean); procedure set_Length(const value: integer); procedure set_Tag(const value: integer); procedure set_ScaleFactor(const value: integer); function get_ScaleFactor: integer; procedure set_IntPrecision(const value: TIntPrecision); function get_IntPrecision: TIntPrecision; function get_IntegerValues: string; function get_IValues(const Indx: integer): integer; procedure set_IValues(const Indx: integer; const Value: integer); function get_SValues(const Indx: integer): SmallInt; procedure set_SValues(const Indx: integer; const Value: SmallInt); function get_BValues(const Indx: integer): Byte; procedure set_BValues(const Indx: integer; const Value: Byte); function GetSelect(const Indx, Len: integer): VectorInt; procedure SetSelect(const Indx, Len: integer; const Value: VectorInt); function GetSelectIndex(const startIndex, Step, stopIndex: integer): VectorInt; procedure SetSelectIndex(const startIndex, Step, stopIndex: integer; const Value: VectorInt); function GetBits(const Indx: integer): boolean; procedure SetBits(const Indx: integer; const Value: boolean); function get_BitCount: Int64; procedure set_BitCount(const value: Int64); function get_Capacity: Int64; procedure set_Capacity(const value: Int64); function get_CapacityStep: double; procedure set_CapacityStep(const value: double); function get_First: integer; function get_Last: integer; public (*Adopts TVecInt object. Src object will be adopted by VectorInt. When the Vector gets out of scope, the object will be freed. *) procedure Adopt(const Src: TVecInt); (*Sets the following properties Vec.Length := ALength; and preserves IntPrecision value. Default IntPrecision when object is created is prInt32. *) function Size(const aLength: integer): TVecInt; overload; (*Sets the following properties Vec.Precision := aPrecision; Vec.Length := ALength; *) procedure Size(const aLength: integer; const aPrecision: TIntPrecision); overload; (*Returns true, if Left and Right are of equal Length and Values. var a,b: VectorInt; c: TDoubleArray; begin c := TDoubleArray.Create(1,1,1,1,1); TVecInt(a).CopyFromArray(c); TVecInt(a).Copy(b); if a = b then ERaise('a and b are equal!'); if a = 1 then ERaise('a equals 1!'); //compare to real value if a = Cplx(1,0) then ERaise('a equals 1!'); //compare to complex value end; *) class operator Equal(const Left, Right: VectorInt): Boolean; (*Returns true, if all elements of Left are equal to Right.*) class operator Equal(const Left: VectorInt; const Right: integer): Boolean; (*Returns true, if all elements of Right are equal to Left.*) class operator Equal(const Left: integer;const Right: VectorInt): Boolean; (*Returns true, if Left and Right are of equal Length and Values.*) class operator Equal(const Left: TMtxVecInt; const Right: VectorInt): Boolean; (*Returns true, if Left and Right are of equal Length and Values.*) class operator Equal(const Left: VectorInt; const Right: TMtxVecInt): Boolean; (*Returns true, if Left and Right are not equal. Returns true, if Left and Right do not have equal Length and Values. var a,b: VectorInt; begin a := VectorInt(TIntegerArray.Create(1,1,1,1,1)); if a <> b then ERaise('a and b are not equal!'); if a <> 1 then ERaise('a does not equals 1!'); //compare to integer value end; *) class operator NotEqual(const Left, Right: VectorInt): Boolean; (*Returns true, if any elements of Left are not equal to Right.*) class operator NotEqual(const Left: VectorInt; const Right: integer): Boolean; (*Returns true, if any elements of Right are not equal to Left.*) class operator NotEqual(const Left: integer;const Right: VectorInt): Boolean; (*Returns true, if Left and Right do not have equal Length and Values.*) class operator NotEqual(const Left: TMtxVecInt; const Right: VectorInt): Boolean; (*Returns true, if Left and Right do not have equal Length and Values.*) class operator NotEqual(const Left: VectorInt; const Right: TMtxVecInt): Boolean; (*Returns true, if all elements of ALeft are smaller from ARight.*) class operator LessThan(const ALeft: VectorInt; const ARight: integer): Boolean; (*Returns true, if ALeft is smaller from all elements in ARight.*) class operator LessThan(const ALeft: integer; const ARight: VectorInt): Boolean; (*Returns true, if coresponding elements in ALeft are greater than coresponding elements in ARight.*) class operator LessThan(const ALeft: VectorInt; const ARight: VectorInt): Boolean; (*Returns true, if all elements of ALeft are smaller or equal from ARight.*) class operator LessThanOrEqual(const ALeft: VectorInt; const ARight: integer): Boolean; (*Returns true, if ALeft is smaller or equal from all elements in ARight.*) class operator LessThanOrEqual(const ALeft: integer; const ARight: VectorInt): Boolean; (*Returns true, if coresponding elements in ALeft are smaller than or equal from coresponding elements in ARight.*) class operator LessThanOrEqual(const ALeft: VectorInt; const ARight: VectorInt): Boolean; (*Returns true, if all elements of ALeft are greater or equal from ARight.*) class operator GreaterThanOrEqual(const ALeft: VectorInt; const ARight: integer): Boolean; (*Returns true, if ALeft is greater or equal from all elements in ARight.*) class operator GreaterThanOrEqual(const ALeft: integer; const ARight: VectorInt): Boolean; (*Returns true, if coresponding elements in ALeft are greater or equal from coresponding elements in ARight.*) class operator GreaterThanOrEqual(const ALeft: VectorInt; const ARight: VectorInt): Boolean; (*Returns true, if all elements of ALeft are greater from ARight.*) class operator GreaterThan(const ALeft: VectorInt; const ARight: integer): Boolean; (*Returns true, if ALeft is greater from all elements in ARight.*) class operator GreaterThan(const ALeft: integer; const ARight: VectorInt): Boolean; (*Returns true, if coresponding elements in ALeft are greater than coresponding elements in ARight.*) class operator GreaterThan(const ALeft: VectorInt; const ARight: VectorInt): Boolean; (*Add Left to all elements in Right and return result.*) class operator Add(const Left: integer;const Right: VectorInt): VectorInt; (*Add Right to all elements in Left and return result.*) class operator Add(const Left: VectorInt; const Right: integer): VectorInt; (*Add coresponding elements in Left and Right.*) class operator Add(const Left: TVecInt; const Right: VectorInt): VectorInt; (*Add coresponding elements in Left and Right.*) class operator Add(const Left: VectorInt; const Right: TVecInt): VectorInt; (*Add coresponding elements in Left and Right.*) class operator Add(const Left: VectorInt;const Right: VectorInt): VectorInt; (*Subtract all elements in Right from Left.*) class operator Subtract(const Left: integer; const Right: VectorInt): VectorInt; (*Subtract Right from all elements in Left.*) class operator Subtract(const Left: VectorInt; const Right: integer): VectorInt; (*Subtract coresponding elements in Right from Left.*) class operator Subtract(const Left: VectorInt; const Right: TVecInt): VectorInt; (*Subtract coresponding elements in Right from Left.*) class operator Subtract(const Left: TVecInt; const Right: VectorInt): VectorInt; (*Subtract coresponding elements in Right from Left.*) class operator Subtract(const Left: VectorInt;const Right: VectorInt): VectorInt; (*Multiply all elements in Left with Right.*) class operator Multiply(const Left: VectorInt; const Right: integer): VectorInt; (*Multiply all elements in Right with Left.*) class operator Multiply(const Left: integer; const Right: VectorInt): VectorInt; (*Multiply all elements in Left with corresponding elements in Right.*) class operator Multiply(const Left: VectorInt; const Right: TVecInt): VectorInt; (*Multiply all elements in Left with corresponding elements in Right.*) class operator Multiply(const Left: TVecInt; const Right: VectorInt): VectorInt; (*Multiply all elements in Left with corresponding elements in Right.*) class operator Multiply(const Left: VectorInt; const Right: VectorInt): VectorInt; (*Divide all elements in Left with Right.*) class operator Divide(const Left: VectorInt; const Right: integer): VectorInt; (*Divide Left with all elements Right.*) class operator Divide(const Left: integer; const Right: VectorInt): VectorInt; (*Divide all elements in Left with coresponding elements in Right.*) class operator Divide(const Left: VectorInt; const Right: TVecInt): VectorInt; (*Divide all elements in Left with coresponding elements in Right.*) class operator Divide(const Left: TVecInt; const Right: VectorInt): VectorInt; (*Divide all elements in Left with coresponding elements in Right.*) class operator Divide(const Left: VectorInt; const Right: VectorInt): VectorInt; (*Negates all values inside AValue.*) class operator Negative(const AValue: VectorInt): VectorInt; (*Explicitely convert array of complex values to VectorInt. Copies all values from the complex array to the result with precision set at 32bit signed integer. *) class operator Explicit(const AValue: TCplxArray): VectorInt; (*Explicitely convert array of double values to VectorInt. Copies all values from the double array to the result with precision set at 32bit signed integer; *) class operator Explicit(const AValue: TDoubleArray): VectorInt; (*Explicitely convert array of single values to VectorInt. Copies all values from the AValue array to the result with precision set at 32bit signed integer. *) class operator Explicit(const AValue: TSingleArray): VectorInt; (*Explicitely convert TMtxVec to VectorInt. Copies all values from AValue to the result with precision set at 32bit signed integer. *) class operator Explicit(const AValue: TMtxVec): VectorInt; (*Explicitely convert VectorInt to array of doubles. Copies all values from AVector to an array of double. *) class operator Explicit(const AValue: VectorInt): TDoubleArray; (*Explicitely convert VectorInt to array of doubles. Copies all values from AVector to an array of single. *) class operator Explicit(const AValue: VectorInt): TSingleArray; (*Explicitely convert VectorInt to array of integer. Copies all values from AVector to an array of 32bit signed integers. If Precision does not match conversion will be performed. *) class operator Explicit(const AValue: VectorInt): TIntegerArray; (*Explicitely convert VectorInt to array of integer. Copies all values from AVector to an array of 16bit signed integers. If Precision does not match conversion will be performed. *) class operator Explicit(const AValue: VectorInt): TSmallIntArray; (*Explicitely convert VectorInt to array of integer. Copies all values from AVector to an array of 16bit signed integers. If Precision does not match conversion will be performed. *) class operator Explicit(const AValue: VectorInt): Math387.TByteArray; (*Implicit type conversion from VectorInt to an array of 32bit signed integer. Returns a pointer to the internal array of values. If the Precision does not match an exception will be raised. *) class operator Implicit(const AValue: VectorInt): TIntegerArray; (*Implicit type conversion from VectorInt to an array of 32bit signed integer. Returns a pointer to the internal array of values. If the Precision does not match an exception will be raised. This conversion avoids all range checking, which would be broken, if VectorInt.IsSubRange = True. PInteger type is also defined in Windows.pas unit and sometimes the type needs to be specified with the unit name (Math387.PInteger) for this overload to work. *) class operator Implicit(const AValue: VectorInt): Math387.PInteger; (*Implicit type conversion from VectorInt to an array of 16bit signed integer. Returns a pointer to the internal array of values. If the Precision does not match an exception will be raised. *) class operator Implicit(const AValue: VectorInt): TSmallIntArray; (*Implicit type conversion from VectorInt to an array of 16bit signed integer. Returns a pointer to the internal array of values. If the Precision does not match an exception will be raised. This conversion avoids all range checking, which would be broken, if VectorInt.IsSubRange = True. *) class operator Implicit(const AValue: VectorInt): Math387.PSmallInt; (*Implicit type conversion from VectorInt to an array of 8bit unsigned integer. Returns a pointer to the internal array of values. If the Precision does not match an exception will be raised. *) class operator Implicit(const AValue: VectorInt): Math387.TByteArray; (*Implicit type conversion from VectorInt to an array of 8bit unsigned integer. Returns a pointer to the internal array of values. If the Precision does not match an exception will be raised. This conversion avoids all range checking, which would be broken, if VectorInt.IsSubRange = True. *) class operator Implicit(const AValue: VectorInt): Math387.PByte; (*Implicit type conversion from VectorInt to TVecInt. Returns a pointer to the internal TVecInt object. *) class operator Implicit(const AValue: VectorInt): TVecInt; (*Implicit type conversion from VectorInt to TMtxVecInt. Returns a pointer to the internal TVecInt object. *) class operator Implicit(const AValue: VectorInt): TMtxVecInt; (*Implicit type conversion from VectorInt to TMtxVecBase. Returns a pointer to the internal TVecInt object. *) class operator Implicit(const AValue: VectorInt): TMtxVecBase; (*Implicit type conversion from VectorInt to TMtxVecBase. Returns a pointer to the internal TVecInt object. *) class operator Implicit(const AValue: VectorInt): TObject; (*Computes bitwise "and" between Left and right.*) class operator BitwiseAnd(const Left: TVecInt; const Right: VectorInt): VectorInt; (*Computes bitwise "and" between Left and right.*) class operator BitwiseAnd(const Left: VectorInt; const Right: TVecInt): VectorInt; (*Computes bitwise "and" between Left and right.*) class operator BitwiseAnd(const Left: VectorInt; const Right: VectorInt): VectorInt; (*Computes logical "and" between Left and right.*) class operator LogicalAnd(const Left: TVecInt; const Right: VectorInt): VectorInt; (*Computes logical "and" between Left and right.*) class operator LogicalAnd(const Left: VectorInt; const Right: TVecInt): VectorInt; (*Computes logical "and" between Left and right.*) class operator LogicalAnd(const Left: VectorInt; const Right: VectorInt): VectorInt; (*Computes logical "or" between Left and right.*) class operator LogicalOr(const Left: TVecInt; const Right: VectorInt): VectorInt; (*Computes logical "or" between Left and right.*) class operator LogicalOr(const Left: VectorInt; const Right: TVecInt): VectorInt; (*Computes logical "or" between Left and right.*) class operator LogicalOr(const Left: VectorInt; const Right: VectorInt): VectorInt; (*Computes bitwise "or" between Left and right.*) class operator BitwiseOr(const Left: TVecInt; const Right: VectorInt): VectorInt; (*Computes bitwise "or" between Left and right.*) class operator BitwiseOr(const Left: VectorInt; const Right: TVecInt): VectorInt; (*Computes bitwise "or" between Left and right.*) class operator BitwiseOr(const Left: VectorInt; const Right: VectorInt): VectorInt; (*Performs bitwise left shift of aValue.*) class operator LeftShift(const aValue: VectorInt; Bits: integer): VectorInt; (*Performs bitwise right shift of aValue. The shift preserves the sign of the numbers. *) class operator RightShift(const aValue: VectorInt; BitCount: integer): VectorInt; (*Performs logical "xor" between Left and Right.*) class operator BitwiseXor(const Left: TVecInt; const Right: VectorInt): VectorInt; (*Performs logical "xor" between Left and Right.*) class operator BitwiseXor(const Left: VectorInt; const Right: TVecInt): VectorInt; (*Performs logical "xor" between Left and Right.*) class operator BitwiseXor(const Left: VectorInt; const Right: VectorInt): VectorInt; (*Performs logical (and bitwise) "not" on the Value.*) class operator LogicalNot(const Value: VectorInt): VectorInt; procedure CreateFromCache(Value: boolean); (*Constructor of the record. Returns a Vector with internal TVecInt object created explicitely with Length property set to aLength and IntPrecision property set to int32. Call this constructor, if the Vector type variable is a global variable with a long life span. var a,b: VectorInt; bvec: TVecInt; begin a := VectorInt.Create(true); //create from object cache via CreateIt //this constructor can be omitted, because it is implicitly called //the first time that the variable is used. //However: b := VectorInt.Create(10); //Similar to bvec := TVecInt.Create; try bvec.Size(10); finally bvec.Free; //b is freed on the exit from the procedure end; end; *) constructor Create(aLength: integer); overload; (*Internally creates TVecInt object without using object cache. Creates TVecInt object without using object cache. Suitable for declaring global variables. *) constructor Create(aLength: integer; aPrecision: TIntPrecision); overload; (*Uses TVecInt object as internal storage. The resulting Vector will own Src object of TVecInt type and will release it once Vector gets out of scope. *) constructor Create(const Src: TVecInt); overload; (*Constructor of the record. Returns a Vector with internal TVecInt object created from object cache (CreateIt), if FromObjectCache is True. Pass false to the constructor or do not call it at all, if the variable is a local variable. Object cache has limited size. *) constructor Create(FromObjectCache: boolean); overload; public (*Defines the length in number of samples. Defines the number of samples that the Vector can store. The length property does not map directly to memory reallocation when it is changed. Until the amount of preallocated memory is not exceed, there is no reallocation going on. Changing the Length property will preserve the existing values, but only if the new property value is smaller than the amount of preallocated memory. To properly resize the memory allocated use the method. It is recommended that vector sizes do not exceed the size of preallocated memory to increase overall performance. The size of preallocated memory can be controlled via the Controller global variable which is defined in the MtxVec unit. *) property Length: integer read get_Length write set_Length; (*Enables/disable inline condition checking. Enables/disables inline condition checking. When true, TVecInt methods perform additional (range) checking before operations are executed. The drawback is slight loss of speed. If ConditionCheck is set to false then no additional checking is performed. This speeds up the execution but disables some safeguards. For short vectors the loss of speed can be significant. The more parameters the method requires the more error checking is performed. Some methods (parameterless) don't use the ConditionCheck property at all. ConditionCheck property is initially True. This property is an additional safeguard against array overrun or underrun errors. It allows you to work with explicit range checking while writing and debugging the application and once your code is running you can turn it off. By functionality it is similar to assertions. (See Assert Delphi procedure). You can also use compiler directives to check, if assertions are on and then set ConditionCheck to True. *) property ConditionCheck: boolean read get_ConditionCheck write set_ConditionCheck; (*Vector Caption. Use this property to set/get the string caption for the VectorInt. This can be usefull for associating description with data when making a user interface. *) property Caption: string read get_Caption write set_Caption; (*Stores an integer value as a part of the object. Tag has no predefined meaning. The Tag property is provided for the convenience of developers. It can be used for storing an additional integer value or it can be typecast to any 32-bit value such as a component reference or even a pointer. *) property Tag: integer read get_Tag write set_Tag; (*Sizing the object will not allocate less than Capacity samples. To free memory allocated before, first set Capacity to 0. *) property Capacity: Int64 read get_Capacity write set_Capacity; (*Specifies increment step for the Capacity property. If this property is 0, the Capacity will never be modified on its own. When the value 1, the capacity will continue increasing to match largest value requested. When the value is more than 1, the capacity will be increasing with the factor specified. *) property CapacityStep: double read get_CapacityStep write set_CapacityStep; public (*Obtains a pointer to the integer value of the vector at Index. The function returns @IValues[i]. Under .NET this is a pointer to pinned managed memory. *) function PIValues(const Index: integer): PAPointer; (*Obtains a pointer to the integer value of the vector at Index. The function returns @SValues[i]. Under .NET this is a pointer to unmanaged memory or pinned managed memory. *) function PSValues(const Index: integer): PAPointer; (*Obtains a pointer to the integer value of the vector at Index. The function returns @BValues[i]. Under .NET this is a pointer to unmanaged memory or pinned managed memory. *) function PBValues(const Index: integer): PAPointer; (* Defines internal storage precision which can be either 32, 16 or 8 bit.*) property IntPrecision: TIntPrecision read get_IntPrecision write set_IntPrecision; (*Returns true, if the currrent subrange of the vector was also the last subrange in the VectorInt. Returns true, if the currrent subrange of the vector was also the last subrange in the VectorInt. This property be used together with and . *) property BlockEnd: boolean read Get_BlockEnd; (*Set to true after the SetSubIndex or SetSubRange call. This property is set to true after the or call. If IsSubRange is true then the TVecInt method/function will be performed on subrange of values. Use to set IsSubRange back to False and thus reset sub range to full vector length. *) property IsSubRange: boolean read get_IsSubRange; (*Allows setting/getting the signed 32bit integer value at position Indx. Allows setting/getting the real value at position Indx. This property reads/writes to the same memory as and properties. *) property IValues[const Indx: integer]: integer read get_IValues write set_IValues; default; (*Allows setting/getting the signed 16bit integer value at position Indx. Allows setting/getting the signed 16bit integer value at position Indx. This property reads/writes to the same memory as and properties. *) property SValues[const Indx: integer]: smallint read get_SValues write set_SValues; (*Allows setting/getting the 8bit unsigned integer value at position Indx. Allows setting/getting the 8bit unsigned integer value at position Indx. This property reads/writes to the same memory as and properties. *) property BValues[const Indx: integer]: byte read get_BValues write set_BValues; (*Allows copying/assignment of subranges. Reading this property will return a sub-ranged Vector. Similar to calling b.SetSubRange(a, Indx, Len); Writing this property will copy source to the specified subrange. The size of the value being assigned needs to match the range specified. *) property Select[const Indx, Len: integer]: VectorInt read GetSelect write SetSelect; (*Allows copying/assignment of subranges. Reading this property will return a copied selection of subranged vector by calling Dst.GatherByIncr(Src, startIndex, Step); Writing this property will copy source to the specified range by using Data.ScatterByIncr. The size of the value being assigned needs to match the index range specified. This property does not obtain a "view" unless Step equals to 1. *) property SelectIndex[const startIndex, Step, stopIndex: integer]: VectorInt read GetSelectIndex write SetSelectIndex; procedure AssignWithoutCopy(const Src: VectorInt); procedure Assign(const Src: VectorInt); (*Initializes block processing. Initializes block processing. Because the size of the CPU cache is limited, significant performance gains can be obtained by splitting long vectors in to a series of short ones, which can all fit in the CPU cache entirely. The BlockInit method is to be used together with and methods to initialize a block processing while loop. BlockInit will call to obtain subrange of the data in TVecInt. The of the subranged vector is determined by the global variable declared in unit. Default value of MtxVecBlockSize is preset to 800 vector elements for double precision and 1600 elements for single precision. BlockInit supports nested calls and from witihin a blocked while loop you can call procedures and functions which are also blocked. If you use block processing, typical performance gains will range from 2 to a maximum of 6. Block processing can not be used, or it is difficult to apply, in cases where vector elements are not independent of each other. The block processing while loop must be written like this: a.BlockInit; while not A.BlockEnd do begin // .... user defined function a.BlockNext; end; The differences with block processing will be more noticable on older CPU's without support for SSE2/SSE3/SSE4/AVX when using FPU instructions. *) procedure BlockInit; overload; (*Initializes block processing with specified ABLockSize.*) procedure BlockInit(ABlockSize: integer); overload; (*Initializes block processing.*) procedure BlockInit(const Src: TMtxVecInt); overload; (*Initializes block processing. Block processing can be applied on possibly already subranged Src object. Src may not be freed or go out of scope until block processing loop has finished. There would be no error raised other than AV. *) procedure BlockInit(const Src: TMtxVecInt; ABlockSize: integer); overload; (*Obtains the next subrange of the data. Obtains the next subrange of the data in TVecInt. The routine must be used together with and methods. *) procedure BlockNext; (*Deinitializes block processing before the final block is processed. Call this routine before breaking out of a while-loop prematurely. Vec.BlockInit While not Vec.BlockEnd do Begin If Vec.Min < 0 then //check some condition, if you need to exit begin Vec.BlockFinish; //finish the loop Break; //and break out end; Vec.BlockNext; end *) procedure BlockFinish; (*Returns number of values within the interval. Returns number of values which fullfill condition LowValue < Value[i] < HighValue. The function only supports prInt32 precision. *) function CountInRange(const LowValue, HighValue: integer): integer; overload; (*Returns number of values within the interval. Returns number of values which fullfill condition LowValue < Value[i] < HighValue, for i traversing the range [Index]..[Index+Len-1] The function only supports prInt32 precision. *) function CountInRange(const LowValue, HighValue: integer; const Index: integer; Len: integer): integer; overload; (*Prevents calls to . Prevents calls to method. This can be usefull guard when an object is already working on a subrange and the user would like to further subrange an already subranged object. var a,b: VectorInt; begin a.SetIt([1,2,3,4,5,6,7,8,9]); a.SetSubRange(0,2); //a = [1,2] a.DisableSubrange; a.SetSubRange(2,2); //exception raised here b.SetSubRange(a,2,2); //but this will work a.SetFullRange; //b is not changed, it still points to [4,5] end; *) procedure DisableSubrange; (*Enables calls to . Enables calls to by removing the block set by . *) procedure EnableSubrange; (*Prevents calls to . Prevents calls to method. This can be usefull guard when an object is already working on a subrange and the user would like to further subrange an already subranged object. var a,b: VectorInt; begin a.SetIt(false, [1,2,3,4,5,6,7,8,9]); a.Select(0,2); //a = [1,2] a.DisableSelect; a.Select(2,2); //exception raised here b.Select(a,2,2); //but this will work a.SelectAll; //b is not changed, it still points to [4,5] end; *) procedure DisableSelect; (*Enables calls to . Enables calls to by removing the block set by . *) procedure EnableSelect; (*First element in object Values array. first integer element in object Values array. *) property First: integer read get_First; (*Last element in object Values array. the last integer element in calling object Values array. *) property Last: integer read get_Last; (*Sets the size of the vector to match an array. Sets the Length of the calling vector to match the length of the array. *) procedure SizeFromArray(const Src: TCplxArray); overload; (*Sets the size of the vector to match an array. Sets the Length of the calling vector to match the length of the array. *) procedure SizeFromArray(const Src: TDoubleArray); overload; (*Sets the size of the vector to match an array. Sets the Length of the calling vector to match the length of the array. *) procedure SizeFromArray(const Src: TSingleArray); overload; (*Sets the size of the vector to match an array. Sets the Length of the calling vector to match the length of the array. *) procedure SizeFromArray(const Src: TIntegerArray); overload; (*Sets the size of the vector to match an array. Sets the Length of the calling vector to match the length of the array. *) procedure SizeFromArray(const Src: TSmallIntArray); overload; (*Sets the size of the vector to match an array. Sets the size (Length) of the caling vector to match the length of the array. *) procedure SizeFromArray(const Src: Math387.TByteArray); overload; (*Sizes complex array.*) procedure SizeToArray(var Dst: TCplxArray); overload; (*Sizes double precision array.*) procedure SizeToArray(var Dst: TDoubleArray); overload; (*Size single precision array.*) procedure SizeToArray(var Dst: TSingleArray); overload; (*Sizes 4 byte signed integer array.*) procedure SizeToArray(var Dst: TIntegerArray); overload; (*Sizes 2 byte unsigned integer array.*) procedure SizeToArray(var Dst: Math387.TWordArray); overload; (*Sizes 2 byte signed integer array.*) procedure SizeToArray(var Dst: TSmallIntArray); overload; (*Sizes 1 byte unsigned integer array.*) procedure SizeToArray(var Dst: Math387.TByteArray); overload; (*Resets any defined selection. *) procedure SelectAll; overload; (*Resets any defined subrange. *) procedure SetFullRange; (*Resets last defined subrange and pops the subrange stack. *) procedure SetFullRangeLevel; (*Defines a subarray. The method will define a sub array starting at BeginIndex and ending at EndIndex (inclusive). All values of the original vector/matrix will be preserved. An exception will be raised if an attempt is made to change the size of calling vector/matrix. A subarray is array which does not have its own memory allocated. Instead it adopts the memory of the source object and all operations done on the either of the objects affect the same elements. The use of subarrays increases CPU cache reuse, lower's memory requirements, increases application performance and improves code readability. To again obtain a view of the full vector see *) procedure SetSubIndex(const BeginIndex, EndIndex: integer); overload; (*Defines a sub vector/matrix. The method will define a subarray starting at Index and ending at Index+Len-1. No copying will occur, only pointers will be shifted. All values of the original will be preserved. An exception will be raised if an attempt is made to change the size of calling object. A sub-vector/matrix is vector/matrix which does not neccessarily have its own memory allocated. Instead it adopts the memory of the source object and all operations done on the either of the objects affect the same elements. The use of subvectors/submatrices increases CPU cache reuse, lower's memory requirements, increases application performance and improves code readability. Note To again obtain a view of the full vector/matrix, see *) procedure SetSubRange(const Index: integer; const Len: integer); overload; (*Defines a sub vector/matrix and pushes any previous subranges on to a stack. The method will define a subarray starting at Index and ending at Index+Len-1. No copying will occur, only pointers will be shifted or indices adjusted. The routine allows for stack based pushing and poping of sub-ranges with the additional constraint that each deepening of the sub-range is strictly within the bounds of the previous one. The pairs of SetSubRangeLevel/SetFullRangeLevel need to match. All values of the original will be preserved. An exception will be raised, if an attempt is made to change the size of calling object. It is possible to call SetSubRange/SetFullRange on the object, which has been subranged with SetSubRangeLevel. To again obtain a view of the previous subrange level on the vector/matrix, call The Index parameter of the SetSubRange is absolute for the original memory or current stack level. The Index parameter for the SetSubRangeLevel is relative to the previous SetSubRangeLevel call. *) procedure SetSubRangeLevel(const Index: integer; const Len: integer); overload; (*Defines the calling vector to have the view of the same memory as Src. Src vector's Length property may not change while any other object has it's own view of it. a.SetSubRange(b,..); This SetSubRange method must be handled with great care. Namely: * b can be freed before "a" and accessing "a" gives AV. * a can be further subranged with c and same problem occurs when b is freed before c. * If you resize b, all objects which have subranged b are no longer pointing to valid memory. * b can Subrange other objects. Similar problem as when changing the size of b. Again all objects which have subranged b are not longer pointing to valid memory. All this can lead to hard to find bugs. It is therefore recommended to contstrain the use of the Subrange within the scope of one routine. *) procedure SetSubRange(const Src: TMtxVecInt); overload; (*Define a subvector of the Src vector. The method will define a subarray starting at Index and ending at Index+Len-1 of Src. No copying will occur, only pointers will be shifted or indices adjusted. A sub-vector/matrix is vector/matrix which does not neccessarily have its own memory allocated. Instead it adopts the memory of the source object and all operations done on the either of the objects affect the same elements. The use of subvectors/submatrices increases CPU cache reuse, lower's memory requirements, increases application performance and improves code readability. All values of the original will be preserved. An exception will be raised, if an attempt is made to change the size of calling object. No exception will be raised, if Src is resized while subranged. (possibly leading to memory overwrites) To again obtain a view of the original vector/matrix, call *) procedure SetSubRange(const Src: TMtxVecInt; const Index: integer; const Len: integer = MtxVecEOA); overload; (*Defines a sub vector/matrix of Src and pushes any previous subranges on to a stack. The method will define a subarray starting at Index and ending at Index+Len-1 of Src. No copying will occur, only pointers will be shifted or indices adjusted. The routine allows for stack based pushing and poping of sub-ranges with the additional constraint that each deepening of the sub-range is strictly within the bounds of the previous one. The pairs of SetSubRangeLevel/SetFullRangeLevel need to match. All values of the original will be preserved. An exception will be raised, if an attempt is made to change the size of calling object. No exception will be raised, if Src is resized while subranged. (possibly leading to memory overwrites) It is possible to call SetSubRange/SetFullRange on the object, which has been subranged with SetSubRangeLevel. To again obtain a view of the previous subrange level on the vector/matrix, call The Index parameter of the SetSubRange is always relative to the previous, if any, stack level. The Index parameter for the SetSubRangeLevel is relative to the current stack level. *) procedure SetSubRangeLevel(const Src: TMtxVecInt; const Index: integer; const Len: integer = MtxVecEOA); overload; (*Sets the subarray size to full size. This method is the same as the method. *) procedure SetSubRange; overload; (*Defines a sub-vector. Define a subvector of the Src vector starting at BeginIndex and ending at EndIndex (inclusive). *) procedure SetSubIndex(const Src: TMtxVecInt; const BeginIndex, EndIndex: integer); overload; (*Sets vector size to zero. Calling Clear sets property to 0. *) procedure Clear; (*Saves the current value of ConditionCheck property and sets it to false. You can restore back to the original setting by calling method. *) procedure CondDisable; (*Sets the ConditionCheck property to whatever it was before the CondDisable was used. Sets the property to whatever it was before the was used. *) procedure CondEnable; (*Concatenates an array of TVecInt objects. Concatenates an array of TVecInt objects. The method copies the contents of all TVecInt objects from the Src array to the calling object. The and Complex properties of the calling vector are set implicitly. An exception is raised, if Complex properties of TVecInt objects do not match. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples { void Example() { TVecInt a,b,c,d; MtxVec.CreateIt(out a, out b, out c, out d); try { a.SetIt(new int[] {1,2,3}); b.Copy(a); c.Concat([a,b]); // c = [1,2,3,1,2,3] d.Size(10); d.SetZero(0,4); d.Concat(4,[c]); // d = [0,0,0,0,1,2,3,1,2,3] } finally { MtxVec.FreeIt(ref a, ref b, ref c, ref d); } } } *) function Concat(const Src: array of TVecInt): TVecInt; overload; (*Copies the contents of all TVecInt objects from the Src array to the calling vector elements, starting with at Index. The and properties of the calling vector must be set explicitly. An exception is raised, if Complex properties of TVecInt objects do not match or if the sum of Length's exceeds the Length property of the calling object. *) function Concat(Index: integer; const Src: array of TVecInt): TVecInt; overload; (* Stores distinct values from Src in to Dst. *) function Distinct(const Src: TMtxVecInt): TVecInt; (*Absolute values. Calculate the absolute value of all calling object elemets in-place. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TVecInt a; MtxVecInt.CreateIt(out a); try { a.SetIt(new int[] {1,-2,3,4}); a.Abs(); // a = [1,2,3,4] } finally { MtxVecInt.FreeIt(ref a); } } } *) function Abs(): TMtxVecInt; overload; (*Absolute values of calling object elements [Index]..[Index+Len-1]. calling vector elements [Index]..[Index+Len-1] ansolute vslues. An exception is raised if array borders are overrun/underrun. Note Please note the calling vector elements [Index]..[Index+Len-1] are overwritten with result of routine call. *) function Abs(const Index, Len: integer): TMtxVecInt; overload; (*Absolute values of all Src vector elements. Src vector elements ansolute vslues.*) function Abs(const Src: TMtxVecInt): TMtxVecInt; overload; (*Absolute values of Src vector elements [VecIndex]..[VecIndex+Len-1]. Src vector elements [VecIndex]..[VecIndex+Len-1] absolute values in calling vector elements [Index]..[Index+Len-1]. An exception is raised if array borders are overrun/underrun. Note Please note the calling vector elements [Index]..[Index+Len-1] are overwritten with result of routine call. *) function Abs(const Src: TMtxVecInt; const SrcIndex, Index, Len: integer): TMtxVecInt; overload; (*Apply binary "and" between coresponding elements in Src1 and Src2. the result of binary "and" of Src1 values with coresponding Src2 values stored in the calling object.*) function BinaryAnd(const Src1, Src2: TMtxVecInt): TMtxVecInt; overload; (* Apply binary "and" between coresponding elements in Src1 and Src2. the result of binary "and" of Src1 values [SrcIndex1]..[SrcIndex1+Len-1] with coresponding Src2 values [SrcIndex2]..[SrcIndex2+Len-1] stored in the calling object at locations [Index]..[Index+Len-1]. *) function BinaryAnd(const Src1, Src2: TMtxVecInt; const SrcIndex1, SrcIndex2, Index, Len: integer): TMtxVecInt; overload; (*Apply binary "and" between coresponding elements in Src and Self. the result of binary "and" of Src values with coresponding values in Self (this).*) function BinaryAnd(const Src: TMtxVecInt): TMtxVecInt; overload; (*Apply binary "and" between coresponding elements in Src and Self. the result of binary "and" of Src values [SrcIndex]...[SrcIndex+Len-1] with coresponding values in Self (this) [Index]..[Index+Len-1].*) function BinaryAnd(const Src: TMtxVecInt; const SrcIndex, Index, Len: integer): TMtxVecInt; overload; (*Apply binary "and" between elements in Src and Value. the result of binary "and" of Value with coresponding values in Src [SrcIndex]..[SrcIndex+Len-1] stored in the calling object at locations [Index]..[Index+Len-1].*) function BinaryAnd(const Src: TMtxVecInt; const Value, SrcIndex, Index, Len: integer): TMtxVecInt; overload; (*Apply binary "and" between elements in the calling object and Value. the result of binary "and" between Value and values in the calling object.*) function BinaryAnd(const Value: integer): TMtxVecInt; overload; (*Apply binary "and" between elements in the calling object and Value. the result of binary "and" between Value and values in the calling object at locations [Index]..[Index+Len-1].*) function BinaryAnd(const Value, Index, Len: integer): TMtxVecInt; overload; (*Apply binary "and" between elements in Src and Value. the result of binary "and" of Value with coresponding values in Src stored in the calling object.*) function BinaryAnd(const Src: TMtxVecInt; const Value: integer): TMtxVecInt; overload; (*Apply binary "or" between coresponding elements in Src1 and Src2. the result of binary "and" of Src1 values with coresponding Src2 values stored in the calling object.*) function BinaryOr(const Src1, Src2: TMtxVecInt): TMtxVecInt; overload; (* Apply binary "or" between coresponding elements in Src1 and Src2. the result of binary "or" of Src1 values [SrcIndex1]..[SrcIndex1+Len-1] with coresponding Src2 values [SrcIndex2]..[SrcIndex2+Len-1] stored in the calling object at locations [Index]..[Index+Len-1]. *) function BinaryOr(const Src1, Src2: TMtxVecInt; const SrcIndex1, SrcIndex2, Index, Len: integer): TMtxVecInt; overload; (*Apply binary "or" between coresponding elements in Src and Self. the result of binary "or" of Src values with coresponding values in Self (this).*) function BinaryOr(const Src: TMtxVecInt): TMtxVecInt; overload; (*Apply binary "or" between coresponding elements in Src and Self. the result of binary "or" of Src values [SrcIndex]...[SrcIndex+Len-1] with coresponding values in Self (this) [Index]..[Index+Len-1].*) function BinaryOr(const Src: TMtxVecInt; const SrcIndex, Index, Len: integer): TMtxVecInt; overload; (*Apply binary "or" between elements in Src and Value. the result of binary "or" of Value with coresponding values in Src [SrcIndex]..[SrcIndex+Len-1] stored in the calling object at locations [Index]..[Index+Len-1].*) function BinaryOr(const Src: TMtxVecInt; const Value, SrcIndex, Index, Len: integer): TMtxVecInt; overload; (*Apply binary "or" between elements in Src and Value. the result of binary "or" of Value with coresponding values in Src stored in the calling object.*) function BinaryOr(const Src: TMtxVecInt; const Value: integer): TMtxVecInt; overload; (*Apply binary "or" between elements in the calling object and Value. the result of binary "or" between Value and values in the calling object at locations [Index]..[Index+Len-1] stored back in the calling object.*) function BinaryOr(const Value, Index, Len: integer): TMtxVecInt; overload; (*Apply binary "or" between elements in the calling object and Value. the result of binary "or" between Value and values in the calling object.*) function BinaryOr(const Value: integer): TMtxVecInt; overload; (*Apply binary "xor" between elements in the calling object and Value. the result of binary "xor" between Value and values in the calling object.*) function BinaryXor(const Value: integer): TMtxVecInt; overload; (*Apply binary "xor" between elements in the calling object and Value. the result of binary "xor" between Value and values in the calling object at locations [Index]..[Index+Len-1] stored back in the calling object.*) function BinaryXor(const Value, Index, Len: integer): TMtxVecInt; overload; (*Apply binary "xor" between elements in Src and Value. the result of binary "xor" of Value with coresponding values in Src stored in the calling object.*) function BinaryXor(const Src: TMtxVecInt; const Value: integer): TMtxVecInt; overload; (*Apply binary "xor" between elements in Src and Value. the result of binary "xor" of Value with coresponding values in Src [SrcIndex]..[SrcIndex+Len-1] stored in the calling object at locations [Index]..[Index+Len-1].*) function BinaryXor(const Src: TMtxVecInt; const Value, SrcIndex, Index, Len: integer): TMtxVecInt; overload; (*Apply binary "xor" between coresponding elements in Src1 and Src2. the result of binary "xor" of Src1 values with coresponding Src2 values stored in the calling object.*) function BinaryXor(const Src1, Src2: TMtxVecInt): TMtxVecInt; overload; (* Apply binary "xor" between coresponding elements in Src1 and Src2. the result of binary "xor" of Src1 values [SrcIndex1]..[SrcIndex1+Len-1] with coresponding Src2 values [SrcIndex2]..[SrcIndex2+Len-1] stored in the calling object at locations [Index]..[Index+Len-1]. *) function BinaryXor(const Src1, Src2: TMtxVecInt; const SrcIndex1, SrcIndex2, Index, Len: integer): TMtxVecInt; overload; (*Apply binary "xor" between coresponding elements in Src and Self. the result of binary "xor" of Src values with coresponding values in Self (this).*) function BinaryXor(const Src: TMtxVecInt): TMtxVecInt; overload; (*Apply binary "xor" between coresponding elements in Src and Self. the result of binary "xor" of Src values [SrcIndex]...[SrcIndex+Len-1] with coresponding values in Self (this) [Index]..[Index+Len-1] stored back in the calling object.*) function BinaryXor(const Src: TMtxVecInt; const SrcIndex, Index, Len: integer): TMtxVecInt; overload; (*Apply binary shift by number of Bits to the left for all elements in the calling object. the result of binary shift to left by number of Bits applied to values in the calling object and stored back in the calling object.*) function BitShiftLeft(const Bits: integer): TMtxVecInt; overload; (*Apply binary shift by number of Bits to the left to elements in the calling object. the result of binary shift to left by number of Bits applied to values [Index]..[Index+Len-1] in the calling object and stored back in the calling object.*) function BitShiftLeft(const Bits, Index, Len: integer): TMtxVecInt; overload; (*Apply binary shift by number of Bits to the left to elements in Src. the result of binary shift to left by number of Bits applied to Src values [SrcIndex]..[SrcIndex+Len-1] and stored in the calling object (Self) value [Index]..[Index+Len-1].*) function BitShiftLeft(const Src: TMtxVecInt; const Bits: integer; const SrcIndex, Index, Len: integer): TMtxVecInt; overload; (*Apply binary shift by number of Bits to the left to elements in Src. the result of binary shift to left by number of Bits applied to Src values and stored in the calling object (Self).*) function BitShiftLeft(const Src: TMtxVecInt; const Bits: integer): TMtxVecInt; overload; (*Apply binary shift by number of Bits to the right for all elements in the calling object. the result of binary shift to right by number of Bits applied to values in the calling object and stored back in the calling object. The sign of the numbers is preserved.*) function BitShiftRight(const Bits: integer): TMtxVecInt; overload; (*Apply binary shift by number of Bits to the right to elements in the calling object. the result of binary shift to right by number of Bits applied to values [Index]..[Index+Len-1] in the calling object and stored back in the calling object. The sign of the numbers is preserved. *) function BitShiftRight(const Bits, Index, Len: integer): TMtxVecInt; overload; (*Apply binary shift by number of Bits to the right to elements in Src. the result of binary shift to right by number of Bits applied to Src values [SrcIndex]..[SrcIndex+Len-1] and stored in the calling object (Self) value [Index]..[Index+Len-1]. The sign of the numbers is preserved. *) function BitShiftRight(const Src: TMtxVecInt; const Bits: integer; const SrcIndex, Index, Len: integer): TMtxVecInt; overload; (*Apply binary shift by number of Bits to the right to elements in Src. the result of binary shift to right by number of Bits applied to Src values and stored in the calling object (Self). The sign of the numbers is preserved. *) function BitShiftRight(const Src: TMtxVecInt; const Bits: integer): TMtxVecInt; overload; (*Apply binary shift by number of Bits to the left (positive) or right (negative) for all elements in the calling object. the result of binary shift to the left or right by number of Bits applied to values in the calling object and stored back in the calling object. The sign of the numbers is preserved when doing right shift. *) function BitShift(const Bits: integer): TMtxVecInt; overload; (*Apply binary shift by number of Bits to the left (positive) or right (negative) to elements in the calling object. the result of binary shift to the left or right by number of Bits applied to values [Index]..[Index+Len-1] in the calling object and stored back in the calling object. The sign of the numbers is preserved when doing right shift. *) function BitShift(const Bits, Index, Len: integer): TMtxVecInt; overload; (*Apply binary shift by number of Bits to the left (positive) or right (negative) to elements in Src. the result of binary shift to the left or right by number of Bits applied to Src values [SrcIndex]..[SrcIndex+Len-1] and stored in the calling object (Self) value [Index]..[Index+Len-1]. The sign of the numbers is preserved when doing right shift. *) function BitShift(const Src: TMtxVecInt; const Bits: integer; const SrcIndex, Index, Len: integer): TMtxVecInt; overload; (*Apply binary shift by number of Bits to the left (positive) or right (negative) to elements in Src. the result of binary shift to the left or right by number of Bits applied to Src values and stored in the calling object (Self). The sign of the numbers is preserved when doing right shift. *) function BitShift(const Src: TMtxVecInt; const Bits: integer): TMtxVecInt; overload; (* Converts Src to packed bit storage. If Src[i] <> 0 then bit at index "i" in the calling vector is set to 1. If Src.Length is not divisable with 32, the remaining bits in the last sample are left at 0. The storage precision of the calling object is set to prInt32. The size of the calling object is adjusted automatically. Packing if array with precision other than Int32 is 8x slower. Packing of array with precision other than Int32 is 8x slower. *) function BitPack(const Src: TVecInt): TVecInt; overload; (* Converts Src to packed bit storage. Returns the result of bit packing the Src values [SrcIndex]..[SrcIndex+Len-1] and stored in the calling object bits from [0]..[0+Len-1]. If Len is not divisable with 32, the remaining bits in the last sample are left at 0. The storage precision of the calling object is set to prInt32. The size of the calling object is adjusted automatically. Packing of array with precision other than Int32 is 8x slower. *) function BitPack(const Src: TMtxVecInt; const SrcIndex, Index, Len: integer): TMtxVecInt; overload; (* Converts Src to packed bit storage. If bit at Src[i] <> 0 then Integer (32, 16 or 8bit) at index "i" in the calling vector is set to 1. The storage precision of the calling object is preserved. The size of the calling object is adjusted automatically. Unpack to array with precision other than Int32 is 8x slower. *) function BitUnpack(const Src: TVecInt; dstPrecision: TIntPrecision = prInt32): TVecInt; overload; (* Converts Src to unpacked bit storage. If bit at Src[i] <> 0 then Integer (32, 16 or 8bit) at index "i" in the calling vector is set to 1. Returns the result of bit unpacking the bits stred Src values [0]..[Len-1] and stored in the calling object (Self) values [Index]..[Index+Len-1]. The storage precision of the calling object is preserved. The Len parameter specifies the number of bits that will be unpacked from Src. Unpack to array with precision other than Int32 is 8x slower. *) function BitUnpack(const Src: TMtxVecInt; SrcIndex, Index, Len: integer): TMtxVecInt; overload; (*Applies binary "not" operation to elements stored in the object. Calculate the binary "not" value of all calling object elemets in-place. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TMtxVecInt a; MtxVecInt.CreateIt(out a); try { a.SetIt(new int[] {1,0,1,0}); a.BinaryNot(); // // a = [-2,-1,-2,-1] } finally { MtxVecInt.FreeIt(ref a); } } } *) function BinaryNot(): TMtxVecInt; overload; (*Apply binary "not" to elements stored in Self (this). the result of binary "not" of values stored in Self (this).*) function BinaryNot(const Index, Len: integer): TMtxVecInt; overload; (*Apply binary "not" to Src elements and store the result in Self (this). the result of binary "not" of Src values stored in Self (this).*) function BinaryNot(const Src: TMtxVecInt): TMtxVecInt; overload; (*Apply binary "not" to Src elements and store the result in Self (this). the result of binary "not" of Src values [SrcIndex]..[SrcIndex+Len-1] stored in Self (this) values [Index]..[Index+Len-1].*) function BinaryNot(const Src: TMtxVecInt; const SrcIndex, Index, Len: integer): TMtxVecInt; overload; (*Applies logical "not" operation to elements stored in the object. Calculate the logical "not" value of all calling object elemets in-place. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TVecInt a; MtxVecInt.CreateIt(out a); try { a.SetIt(new int[] {1,0,1,0}); a.LogicalNot(); // a = [0,1,0,1] } finally { MtxVec.FreeIt(ref a); } } } *) function LogicalNot(): TMtxVecInt; overload; (*Apply logical "not" to elements stored in Self (this). the result of logical "not" of values stored in Self (this).*) function LogicalNot(Index, Len: integer): TMtxVecInt; overload; (*Apply logical "not" to Src elements and store the result in Self (this). the result of logical "not" of Src values stored in Self (this).*) function LogicalNot(const Src: TMtxVecInt): TMtxVecInt; overload; (*Apply logical "not" to Src elements and store the result in Self (this). the result of logical "not" of Src values [SrcIndex]..[SrcIndex+Len-1] stored in Self (this) values [Index]..[Index+Len-1].*) function LogicalNot(const Src: TMtxVecInt; SrcIndex, Index, Len: integer): TMtxVecInt; overload; function LoadFromStream(const SrcStream: TStream): Int64; overload; procedure SaveToStream(DstStream: TStream); overload; (*Copies values from a real Src array. The size of the calling object is set implicitely. The integer precision of the calling object is preserved. *) function CopyFromArray(const Src: TCplxArray; const Rounding: TRounding): TMtxVecInt; overload; (*Copies values from the double precision floating point Src array [SrcIndex]..[SrcIndex+Len-1] to the calling object values [Index]..[Index+2*Len-1]. The size of the calling object is not changed. If the array border are overrun an exception will be raised. *) function CopyFromArray(const Src: TCplxArray; const Rounding: TRounding; const SrcIndex,Index,Len: integer): TMtxVecInt; overload; (*Copies values from Src array. The size of the calling object is set implicitely. The precision is preserved. *) function CopyFromArray(const Src: Math387.TWordArray): TMtxVecInt; overload; (*Copies values from a 2 byte unsigned integer type Src array [SrcIndex]..[SrcIndex+Len-1] to the calling object values [Index]..[Index+len-1]. The size of the calling object is not changed. If the array border are overrun an exception will be raised. *) function CopyFromArray(const Src: Math387.TWordArray; const SrcIndex, Index, Len: integer): TMtxVecInt; overload; (*Copies values from a real Src array. The size of the calling object is set implicitely. The precision is preserved. *) function CopyFromArray(const Src: TDoubleArray; const Rounding: TRounding): TMtxVecInt; overload; (*Copies values from the double precision floating point Src array [SrcIndex]..[SrcIndex+Len-1] to the calling object values [Index]..[Index+len-1]. The size of the calling object is not changed. If the array border are overrun an exception will be raised. *) function CopyFromArray(const Src: TDoubleArray; const Rounding: TRounding; const SrcIndex,Index,Len: integer): TMtxVecInt; overload; (*Copies values from a real single precision floating point Src array. The size property of the calling object is set implicitely. *) function CopyFromArray(const Src: TSingleArray; const Rounding: TRounding): TMtxVecInt; overload; (*Copies values from the single precision floating point Src array [SrcIndex]..[SrcIndex+Len-1] to the calling object values [Index]..[Index+len-1]. The size of the calling object is not changed. If the array border are overrun an exception will be raised. *) function CopyFromArray(const Src: TSingleArray; const Rounding: TRounding; const SrcIndex,Index,Len: integer): TMtxVecInt; overload; (*Copies values from an integer type Src array.*) function CopyFromArray(const Src: TIntegerArray): TMtxVecInt; overload; (*Copies values from a 4 byte signed integer type Src array [SrcIndex]..[SrcIndex+Len-1]. Store the results to the calling object values [Index]..[Index+len-1]. The size of the calling object is not changed. If the array border are overrun an exception will be raised. *) function CopyFromArray(const Src: TIntegerArray; const SrcIndex,Index,Len: integer): TMtxVecInt; overload; (*Copies values from an 2 byte signed integer type Src array. The size property of the calling object is set implicitely. *) function CopyFromArray(const Src: TSmallIntArray): TMtxVecInt; overload; (*Copies values from a 2 byte signed integer type Src array [SrcIndex]..[SrcIndex+Len-1] to the calling object values [Index]..[Index+len-1]. The size of the calling object is not changed. If the array border are overrun an exception will be raised. *) function CopyFromArray(const Src: TSmallIntArray; const SrcIndex,Index,Len: integer): TMtxVecInt; overload; (*Copies values from a 1 byte unsigned integer type Src array.*) function CopyFromArray(const Src: Math387.TByteArray): TMtxVecInt; overload; (*Copies values from a 1 byte unsigned integer type Src array [SrcIndex]..[SrcIndex+Len-1] to the calling object values [Index]..[Index+len-1]. The size of the calling object is not changed. If the array border are overrun an exception will be raised. *) function CopyFromArray(const Src: Math387.TByteArray; const SrcIndex,Index,Len: integer): TMtxVecInt; overload; (*Copies values from the calling object to the Dst array and converts data to double precision numbers. Consecutive elements are converted to real and imaginary parts. *) function CopyToArray(var Dst: TCplxArray): TMtxVecInt; overload; (*Copy values from the calling object [Index]..[Index+len-1] to the Dst integer array at positions [DstIndex]...[DstIndex+Len-1]. The size of the Dst array is not changed. The method converts calling object values to double precision floating point values. Consecutive elements are converted to real and imaginary parts. *) function CopyToArray(var Dst: TCplxArray; const DstIndex, Index,Len: integer): TMtxVecInt; overload; (*Copy values to Dst array. The size of the array is set automatically.*) function CopyToArray(var Dst: TDoubleArray): TMtxVecInt; overload; (*Copy values from the calling object [Index]..[Index+len-1] to the Dst array at positions [DstIndex]...[DstIndex+Len-1]. The size of the Dst array is not changed. *) function CopyToArray(var Dst: TDoubleArray; const DstIndex, Index,Len: integer): TMtxVecInt; overload; (*Copies the calling object data to an array of single precision floating point data. Any values exceeding the range are clipped. *) function CopyToArray(var Dst: TSingleArray): TMtxVecInt; overload; (*Copy values from the calling object [Index]..[Index+len-1] to the Dst single precision floating point array at positions [DstIndex]...[DstIndex+Len-1]. The size of the Dst array is not changed. *) function CopyToArray(var Dst: TSingleArray; const DstIndex, Index,Len: integer): TMtxVecInt; overload; (*Copies values from the calling object to the Dst array and converts data to 4 byte signed integer numbers.*) function CopyToArray(var Dst: TIntegerArray): TMtxVecInt; overload; (*Copy values from the calling object [Index]..[Index+len-1] to the Dst integer array at positions [DstIndex]...[DstIndex+Len-1]. The size of the Dst array is not changed. The method converts calling object values to 4 byte signed integers. Values exceeding the range of a 4 byte signed integer type are clipped. *) function CopyToArray(var Dst: TIntegerArray; const DstIndex, Index,Len: integer): TMtxVecInt; overload; (*Copies values from the calling object to the Dst array and converts data to 2 byte signed integer numbers. Values exceeding the range of a 2 byte signed integer type are clipped. *) function CopyToArray(var Dst: TSmallIntArray): TMtxVecInt; overload; (*Copy values from the calling object [Index]..[Index+len-1] to the Dst integer array at positions [DstIndex]...[DstIndex+Len-1]. The size of the Dst array is not changed. Values exceeding the range of a 2 byte signed integer type are clipped. *) function CopyToArray(var Dst: TSmallIntArray; const DstIndex, Index,Len: integer): TMtxVecInt; overload; (*Copies values from the calling object to the Dst array and converts data to 2 byte unsigned integer type. Values exceeding the range of a 2 byte unsigned integer type are clipped. *) function CopyToArray(var Dst: Math387.TWordArray): TMtxVecInt; overload; (*Copy values from the calling object [Index]..[Index+len-1] to the Dst integer array at positions [DstIndex]...[DstIndex+Len-1]. The size of the Dst array is not changed. Values exceeding the range of a 2 byte unsigned integer type are clipped. *) function CopyToArray(var Dst: Math387.TWordArray; const DstIndex, Index,Len: integer): TMtxVecInt; overload; (*Copies values from the calling object to the Dst array and converts data to 1 byte unsigned integer numbers. Values exceeding the range of 1 byte unsigned integer type are clipped. *) function CopyToArray(var Dst: Math387.TByteArray): TMtxVecInt; overload; (*Copy values from the calling object [Index]..[Index+len-1] to the Dst integer array at positions [DstIndex]...[DstIndex+Len-1]. The size of the Dst array is not changed. Values exceeding the range of 1 byte unsigned integer type are clipped. *) function CopyToArray(var Dst: Math387.TByteArray; const DstIndex,Index,Len: integer): TMtxVecInt; overload; (*Finds a match for X in object values using binary search. The data in the vector must be sorted in ascending order for this function to work correctly. the index of last matched element. If no matching elements are found, the result is -1.*) function BinarySearch(const X: Integer): Integer; overload; function BinarySearch(const X: Integer; const Index: integer; const Len: integer): Integer; overload; (*Finds exact or closest index match for X in object values using binary search. The data in the vector must be sorted in ascending order for this function to work correctly. The closest match is the index of first bigger or smaller value in the array. To ensure bigger value write: Data := [0,2,3]; Data.BinarySearch(Value, XIndex); if Data[XIndex] > Value then Dec(XIndex); To ensure smaller value write: Data := [0,2,3]; Data.BinarySearch(1, XIndex); if Data[XIndex] < Value then Inc(XIndex); True, if found and the index of the next bigger or smaller value in XIndex, if not found. *) function BinarySearch(const X: Integer; var XIndex: integer): boolean; overload; function BinarySearch(const X: Integer; var XIndex: integer; const Index: integer; Len: integer): boolean; overload; (*Finds a match for X in object values. the index of last matched element. If no matching elements are found, the result is -1. Compare real value X with all calling object elements. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TVecInt a; MtxVecInt.CreateIt(out a); try { a.SetIt(false, new int[] {2,5,1,6}); int ind = a.Find(1); // returns 2 (the arrays are zero based) } finally { MtxVecInt.FreeIt(ref a); } } } *) function Find(const X: integer): integer; overload; function Find(const X: integer; const Index: integer; const Len: integer = MtxVecEOA): integer; overload; (*Finds the masks for a vector and splits it. The method splits the a vector in two vectors. The MaskVec will hold the those elements where the Op comparison between a and b is True. Op string parameter can be '<', '>', '>=','<=','=' or '<>'. NotMaksVec will hold all those elements where the Op comparison between a and b is false. The calling vector will store the mask, 1 at those index locations where the Op comparison was True and 0 at those index locations where the Op comparison was false. *) function FindAndSplit(const a: TMtxVec; const op: string; const b: TMtxVec; const MaskVec, NotMaskVec: TVec): TMtxVecInt; overload; (*The b parameter is of type.*) function FindAndSplit(const a: TMtxVec; const op: string; const b: TCplx; const MaskVec, NotMaskVec: TVec): TMtxVecInt; overload; (*The b parameter is of double type.*) function FindAndSplit(const a: TMtxVec; const op: string; const b: double; const MaskVec,NotMaskVec: TVec): TMtxVecInt; overload; (*Fills the calling vector with indexes, where the logical expression is true. Fills the calling vector with indexes, where the Op comparison between a and b is True. Op string parameter can be '<', '>', '>=','<=','=' or '<>'. Ensure that the power function will return 0, if the exponent is 0. CreateIt(a,b); With TVec(Self) do try Ln(Base); //First do it the normal way then fix the anomalies Mul(Exponent); Exp; a.FindIndexes(Exponent,'=',0); b.Size(a.Length,Complex); b.Setval(1); Scatter(b,a); finally FreeIt(a,b); end; *) function FindIndexes(const a: TMtxVec; const op: string; const b: TCplx): TMtxVecInt; overload; (*The b parameter is of double type.*) function FindIndexes(const a: TMtxVec; const op: string; const b: double): TMtxVecInt; overload; (*The b parameter is of type.*) function FindIndexes(const a: TMtxVec; const op: string; const b: TMtxVec): TMtxVecInt; overload; (*Finds a vector mask. The calling vector will hold the those elements where the Op comparison between a and b is True. Op string parameter can be '<', '>', '>=','<=','=' or '<>'. The calling vector will store the mask, 1 at those index locations * where the Op comparison was True and 0 at those index locations * where the Op comparison was false. The calling vector stores the mask as Integers in to the memory location occupied by Values array. *) function FindMask(const a: TMtxVec; const op: string; const b: TCplx): TMtxVecInt; overload; (*The b parameter is of double type.*) function FindMask(const a: TMtxVec; const op: string; const b: double): TMtxVecInt; overload; (*The b parameter is of type.*) function FindMask(const a: TMtxVec; const op: string; const b: TMtxVec): TMtxVecInt; overload; (*Fills the calling vector with indexes, where the logical expression is true. ills the calling vector with indexes, where the Op comparison between a and b is True. Op string parameter can be '<', '>', '>=','<=','=' or '<>'. *) (*The b parameter is of integer type.*) function FindIndexes(const a: TMtxVecInt; const op: string; const b: integer): TMtxVecInt; overload; (*The b parameter is of type.*) function FindIndexes(const a: TMtxVecInt; const op: string; const b: TMtxVecInt): TMtxVecInt; overload; (*The b parameter is of integer type.*) function FindIndexesAndLength(const a: TMtxVecInt; const op: string; const b: Integer): integer; overload; (*The b parameter is of type.*) function FindIndexesAndLength(const a: TMtxVecInt; const op: string; const b: TMtxVecInt): integer; overload; (*Finds a vector mask. The calling vector will hold the those elements where the Op comparison between a and b is True. Op string parameter can be < , > , >= , <= , = or <> . The calling vector will store the mask, 1 at those index locations where the Op comparison was True and 0 at those index locations where the Op comparison was false. *) (*The b parameter is of integer type.*) function FindMask(const a: TMtxVecInt; const op: string; const b: integer): TMtxVecInt; overload; (*The b parameter is of type.*) function FindMask(const a: TMtxVecInt; const op: string; const b: TMtxVecInt): TMtxVecInt; overload; (*Finds and gathers vector elements. Fills the Indexes vector with indexes, of those elements where the Op comparison between a and b is True. Op string parameter can be '<', '>', '>=','<=','=' or '<>'. The method also copies or "gathers" the matched elements to the calling vector. The Length and complex property of the calling vector are set automatically. *) (*The b parameter is of integer type.*) function FindAndGather(const a: TMtxVecInt; const op: string; const b: integer; const Indexes: TVecInt = nil): TVecInt; overload; (*The b parameter is of type.*) function FindAndGather(const a: TMtxVecInt; const op: string; const b: TMtxVecInt; const Indexes: TVecInt = nil): TVecInt; overload; (*Copies a column from matrix. Copies the Col-th column from Mtx matrix to calling vector. The and properties of calling vector are adjusted automatically. An exception is raised if condition checking is enabled and Col is greater than Mtx.Cols-1. var a: TVecInt; b: TMtxInt; begin CreateIt(a); CreateIt(b); try b.SetIt(2,2,[1,2, 3,4]); a.GetCol(b,0); // a now contains [1,3] finally FreeIt(a); FreeIt(b); end; end; *) function GetCol(const Mtx: TMtxInt; Col: integer): TVecInt; overload; (*Copy the Col-th column elements [Row]..[Row+Len-1] to calling vector elements [Index]..[Index+Len-1]. The property of calling vector must be set explicitly. An exception is raised if condition checking is enabled and column array borders are overrun. *) function GetCol(const Mtx: TMtxInt; Row, Col, Index, Len: integer): TVecInt; overload; (*Copy the Col-th column elements [Row]..[Row+Len-1] to calling vector. The and properties of calling vector are adjusted automatically. An exception is raised if condition checking is enabled and column array borders are overrun. *) function GetCol(const Mtx: TMtxInt; Row, Col, Len: integer): TVecInt; overload; (*Gather vector elements. Gather the elements of vector X and store them to the calling vector according to the IndexType, Increment and Offset parameters. The Indexes vector is used only if IndexType is either indVector or indMask. If IndexType is indVector, the values from the Indexes vector denote the index positions in the X vector from which the values should be copied to the calling vector. The Indexes vector must have the indexes stored in the IValues array. The IValues integer arrays points the same memory as Values array. The Increment and Offset parameters are used only if TIndexType is indIncrement. They define the initial offset and a fixed step (increment) between elements to be gathered. If IndexType is indMaks the Indexes vector must have the same size as the X vector. The routine will copy only those elements from the X vector to the calling vector, for which there is a 1 at the coresponding index in the Indexes vector. The elements copied from the X vector will be stored consecutively in the calling vector. See the method to see how to undo the gathering. The performance of the CPU heavily depends on the assumption that elements are stored at consecutive memory locations. If it is neccessary to apply a set of operations only to elements at specific indexes, performance-wise it can proof to be very helpfull, if the elements are gathered first. *) function Gather(const X: TMtxVecInt; const Indexes: TVecInt =nil; IndexType: TIndexType = indVector; Increment: integer = 1; Offset: integer = 0): TVecInt; overload; (* Gathers elements from X starting at Offset and with Increment to the calling object. *) function GatherByIncr (const X: TMtxVecInt; Increment: integer = 1; Offset: integer = 0): TVecInt; overload; (* Gathers elements from X specified by indices stored in Indexes the calling object. *) function GatherByIndex(const X: TMtxVecInt; const Indexes: TVecInt): TVecInt; overload; (* Gathers elements from X specified by non-zero values stored in the Mask to the calling object. *) function GatherByMask (const X: TMtxVecInt; const Mask: TMtxVecInt; const MaskNonZeroCount: integer = -1): TVecInt; overload; (* Scatters Src elements defined with the Mask to the calling object. *) function ScatterByMask(const Src: TMtxVecInt; const Mask: TMtxVecInt; allow_resizing: boolean = False): TMtxVecInt; overload; (*Scatter object elements. Scatter the elements of the Src and store them in the calling object according to the IndexType, Increment and Offset parameters. The Indexes vector is used only if IndexType is either indVector or indMask. If IndexType is indVector, the values from the Indexes object denote the index positions in the calling object to which the values should be copied from the Src. The Indexes vector must have the indexes stored in the IValues array. The IValues integer arrays points the same memory as Values array. The Increment and Offset parameters are used only if TIndexType is indIncrement. They define the target offset and a fixed step (increment) between calling vector elements. If IndexType is indMaks the Indexes object must have the same size as the Src object. The routine will copy only those elements from the Src to the calling object, for which there is a 1 at the coresponding index in the Indexes object.The elements in the calling object are stored consecutively. See the method to see how to perform gathering. The performance of the CPU heavily depends on the assumption that elements are stored at consecutive memory locations. If it is neccessary to apply a set of operations only to elements at specific indexes, performance-wise it can prove to be very helpfull, if the elements are gathered first. *) function Scatter(const Src: TMtxVecInt; const Indexes: TMtxVecInt = nil; IndexType: TIndexType = indVector; Increment: integer = 1; Offset: integer = 0): TMtxVecInt; overload; (* Scatters Src elements starting at Offset and with Increment to the calling object. *) function ScatterByIncr(const Src: TMtxVecInt; Increment: integer = 1; Offset: integer = 0): TMtxVecInt; overload; (* Scatters Src elements defined with indices stored in Indexes to the calling object. *) function ScatterByIndexes(const Src: TMtxVecInt; const Indexes: TMtxVecInt): TMtxVecInt; overload; (*Copies the k-th diagonal from the TMtxInt object. Copies the k-th diagonal from the TMtxInt object. If k = 0 then the main diagonal is copied, if k < 0 then the subdiagonal is copied and if k > 0 then the k-th super diagonal is copied to the calling vector. In the following example we setup a matrix, populate it with values and then extract it's main diagonal to a vector. var a: TVecInt; d: TMtxInt; begin CreateIt(a); CreateIt(d); try // setup matrix d.SetIt(2,2,[1,-2, 3, 4]); // get main diagonal from matrix a.Diag(d,0); // a now containes [1,4]; finally FreeIt(a); FreeIt(d); end; end; *) function Diag(const Mtx: TMtxInt; k: integer): TVecInt; (*Copies a row from matrix. Copies the Row-th row from Mtx matrix to calling vector. The and properties of calling vector are adjusted automatically. An exception is raised if condition checking is enabled and Row is greater than Mtx.Rows-1. var a: TVecInt; b: TMtxInt; begin CreateIt(a); CreateIt(b); try b.SetIt(2,2,[1,2, 3,4]); a.GetRow(b,0); // a now contains [1,2] finally FreeIt(a); FreeIt(b); end; end; *) function GetRow(const Mtx: TMtxInt; Row: integer): TVecInt; overload; (*Copy the Row-th column elements [Col]..[Col+Len-1] to calling vector elements [Index]..[Index+Len-1]. The property of calling vector must be set explicitly. An exception is raised if condition checking is enabled and column array borders are overrun. *) function GetRow(const Mtx: TMtxInt; Row, Col, Index, Len: integer): TVecInt; overload; (*Copy the Row-th column elements [Col]..[Col+Len-1] to calling vector. The and properties of calling vector are adjusted automatically. An exception is raised if condition checking is enabled and column array borders are overrun. *) function GetRow(const Mtx: TMtxInt; Row, Col, Len: integer): TVecInt; overload; (*Add coresponding elements in Src2 to Src1. the result of adding Src2 values from coresponding Src1 values.*) function Add(const Src1, Src2: TMtxVecInt): TMtxVecInt; overload; (*Add coresponding elements in Src2 to Src1. Add Src1 elements [Src1Index..Src1Index+Len-1] to corrresponding Src2 elements [Src2Index..Src12ndex+Len] and store the results in calling vector elements [Index..Index+Len-1]. An exception is raised if array borders are overrun. *) function Add(const Src1, Src2: TMtxVecInt; const Src1Index, Src2Index, Index, Len: integer): TMtxVecInt; overload; (*Add Src elements to calling vector elements.*) function Add(const Src: TMtxVecInt): TMtxVecInt; overload; (*Add Src elements [SrcIndex..SrcIndex+Len-1] to calling vector elements. Add Src elements [SrcIndex..SrcIndex+Len-1] to calling vector elements [Index..Index+Len-1]. An exception is raised if array borders are overrun. *) function Add(const Src: TMtxVecInt; const SrcIndex, Index, Len: integer): TMtxVecInt; overload; (*Add integer Value to all Src elements. Add integer Value to all Src elements and store the results in calling vector. Size of calling vector is adjusted automatically. *) function Add(const Src: TMtxVecInt; const Value: integer): TMtxVecInt; overload; (*Add integer Value to Src elements [SrcIndex..SrcIndex+Len-1]. Add integer Value to Src elements [SrcIndex..SrcIndex+Len-1] and store the results in calling vector elements [Index..Index+Len-1]. An exception is raised if array borders are overrun. *) function Add(const Src: TMtxVecInt; const Value, SrcIndex, Index, Len: integer): TMtxVecInt; overload; (*Add integer value to all calling vector elements.*) function Add(const Value: integer): TMtxVecInt; overload; (*Add integer value to calling vector elements [Index..Index+Len-1]. An exception is raised if array borders are overrun. *) function Add(const Value, Index, Len: integer): TMtxVecInt; overload; (*Subtract coresponding elements in Src2 from Src1. the result of subtracting Src2 values from coresponding Src1 values.*) function Subtract(const Src1, Src2: TMtxVecInt): TMtxVecInt; overload; (*Add coresponding elements in Src1 from Src1. Subtract Src2 elements [Src2Index..Src2Index+Len-1] from corrresponding Src1 elements [Src1Index..Src1ndex+Len] and store the results in calling vector elements [Index..Index+Len-1]. An exception is raised if array borders are overrun. *) function Subtract(const Src1, Src2: TMtxVecInt; const Src1Index, Src2Index, Index, Len: integer): TMtxVecInt; overload; (*Subtract all Src elements from calling vector elements.*) function Subtract(const Src: TMtxVecInt): TMtxVecInt; overload; (*Subtract Src elements [SrcIndex..SrcIndex+Len-1] from calling vector elements. Subtract Src elements [SrcIndex..SrcIndex+Len-1] from calling vector elements [Index..Index+Len-1]. An exception is raised if array borders are overrun. *) function Subtract(const Src: TMtxVecInt; const SrcIndex, Index, Len: integer): TMtxVecInt; overload; (*Subtract integer Value from all Src elements. Subtract integer Value from all Src elements and store the results in calling vector. Size of calling vector is adjusted automatically. *) function Subtract(const Src: TMtxVecInt; const Value: integer): TMtxVecInt; overload; (*Subtract integer Value from Src elements [SrcIndex..SrcIndex+Len-1]. Subtract integer Value from Src elements [SrcIndex..SrcIndex+Len-1] and store the results in calling vector elements [Index..Index+Len-1]. An exception is raised if array borders are overrun. *) function Subtract(const Src: TMtxVecInt; const Value, SrcIndex, Index, Len: integer): TMtxVecInt; overload; (*Subtract integer value from all calling vector elements.*) function Subtract(const Value: integer): TMtxVecInt; overload; (*Subtract integer value from calling vector elements [Index..Index+Len-1]. An exception is raised if array borders are overrun. *) function Subtract(const Value, Index, Len: integer): TMtxVecInt; overload; (*Subtract all calling vector elements from integer Value.*) function SubtractFrom(const Value: integer): TMtxVecInt; overload; (*Subtract calling vector elements [Index..Index+Len-1] from integer Value. An exception is raised if array borders are overrun. *) function SubtractFrom(const Value, Index, Len: integer): TMtxVecInt; overload; (*Subtract all Src vector elements from integer Value. and store thje results in calling vector. Size of calling vector is adjusted automatically. *) function SubtractFrom(const Value: integer; const Src: TMtxVecInt): TMtxVecInt; overload; (*Subtract Src vector elements [SrcIndex..SrcIndex+Len-1] from integer Value. and store thje results in calling vector elements [Index..Index+Len-1]. Size of calling vector is adjusted automatically. An exception is raised if array borders are overrun. *) function SubtractFrom(const Value: integer; const Src: TMtxVecInt; const SrcIndex, Index, Len: integer): TMtxVecInt; overload; (*Multiplies coresponding elements in Src2 with Src1. the result of multipliing Src2 values with coresponding Src1 values.*) function Multiply(const Src1, Src2: TMtxVecInt): TMtxVecInt; overload; (*Multiply coresponding elements in Src2 with Src1. Multiply Src1 elements [Src1Index..Src1Index+Len-1] with corrresponding Src2 elements [Src2Index..Src2ndex+Len] and store the results in calling vector elements [Index..Index+Len-1]. An exception is raised if array borders are overrun. *) function Multiply(const Src1, Src2: TMtxVecInt; const SrcIndex1, SrcIndex2,Index, Len: integer): TMtxVecInt; overload; (*Multiply Src elements with calling vector elements.*) function Multiply(const Src: TMtxVecInt): TMtxVecInt; overload; (*Mjultiply Src elements [SrcIndex..SrcIndex+Len-1] with calling vector elements. Multiply Src elements [SrcIndex..SrcIndex+Len-1] with calling vector elements [Index..Index+Len-1]. An exception is raised if array borders are overrun. *) function Multiply(const Src: TMtxVecInt; const SrcIndex, Index, Len: integer): TMtxVecInt; overload; (*Multiply integer Value with all Src elements. Multiply integer Value with all Src elements and store the results in calling vector. Size of calling vector is adjusted automatically. *) function Multiply(const Src: TMtxVecInt; const Value: integer): TMtxVecInt; overload; (*Multiply integer value with Src vector elements [SrcIndex..SrcIndex+Len-1]. Store the results in calling vector elements [Index..Index+Len-1]. An exception is raised if array borders are overrun. *) function Multiply(const Src: TMtxVecInt; const Value, SrcIndex, Index, Len: integer): TMtxVecInt; overload; (*Multiply integer value with all calling vector elements.*) function Multiply(const Value: integer): TMtxVecInt; overload; (*Multiply integer value with calling vector elements [Index..Index+Len-1]. An exception is raised if array borders are overrun. *) function Multiply(const Value,Index, Len: integer): TMtxVecInt; overload; (*Divides coresponding elements in Num with Den. the result of dividing Num values with coresponding Den values.*) function Divide(const Num, Den: TMtxVecInt): TMtxVecInt; overload; (*Divide coresponding elements in Num with Den. Divide Num elements [NumIndex..NumIndex+Len-1] with corrresponding Deb elements [DenIndex..DenIndex+Len-1] and store the results in calling vector elements [Index..Index+Len-1]. An exception is raised if array borders are overrun. *) function Divide(const Num, Den: TMtxVecInt; const NumIndex, DenIndex, Index, Len: integer): TMtxVecInt; overload; (*Divide calling object elements with Src elements.*) function Divide(const Src: TMtxVecInt): TMtxVecInt; overload; (*Divide calling object elements with Src elements [SrcIndex..SrcIndex+Len-1]. Divide calling object elements [Index..Index+Len ] with Src elements [SrcIndex..SrcIndex+Len-1]. An exception is raised if array borders are overrun. *) function Divide(const Src: TMtxVecInt; const SrcIndex, Index, Len: integer): TMtxVecInt; overload; (*Divide all Src vector elements with integer Value. Size of calling vector is adjusted automatically. *) function Divide(const Src: TMtxVecInt; const Value: integer): TMtxVecInt; overload; (*Divide Src vector elements [SrcIndex..SrcIndex+Len-1] with integer Value. Divide Src elements [SrcIndex..SrcIndex+Len-1] with integer Value and store tje results in calling vector elements [Index..Index+Len-1]. An exception is raised if array borders are overrun. *) function Divide(const Src: TMtxVecInt; const Value, SrcIndex, Index, Len: integer): TMtxVecInt; overload; (*Divide all calling vector elements with integer value.*) function Divide(const Value: integer): TMtxVecInt; overload; (*Divide calling vector elements [Index..Index+Len-1] with integer value. An exception is raised if array borders are overrun. *) function Divide(const Value, Index, Len: integer): TMtxVecInt; overload; (*Divide Value with calling vector elements. Teh result is stored in the calling vector. *) function DivideBy(const Value: integer): TMtxVecInt; overload; (*Divide Value with calling vector elements [Index..Index+Len-1]. An exception is raised if array borders are overrun. *) function DivideBy(const Value, Index, Len: integer): TMtxVecInt; overload; (*Divide Value with Src vector elements and store the result in the calling vector. An exception is raised if array borders are overrun. *) function DivideBy(const Value: integer; const Src: TMtxVecInt): TMtxVecInt; overload; (*Divide Value with Src vector elements [SrcIndex+SrcIndex+Len-1] and store the result in the calling vector [Index...Index+Len-1]. An exception is raised if array borders are overrun. *) function DivideBy(const Value: integer; const Src: TMtxVecInt; const SrcIndex, Index, Len: integer): TMtxVecInt; overload; (* Compute X + Y*yScale *) function AddScaled(const X, Y: TMtxVecInt; const yScale: integer): TMtxVecInt; overload; (* Compute X + Y*yScale on sub arrays *) function AddScaled(const X: TMtxVecInt; xIndex: integer; const Y: TMtxVecInt; yIndex: integer; const yScale: integer; Index, Len: integer): TMtxVecInt; overload; (* Compute sqr(X + Y*yScale) By making use of yScale, it is also possible to compute the following (at the same or higher speed): (X - Y)^2 = X^2 - 2XY +Y^2 *) function AddScaledSqr(const X, Y: TMtxVecInt; const yScale: integer): TMtxVecInt; overload; (* Compute sqr(X + Y*yScale) on sub arrays *) function AddScaledSqr(const X: TMtxVecInt; xIndex: integer; const Y: TMtxVecInt; yIndex: integer; const yScale: integer; Index, Len: integer): TMtxVecInt; overload; (* Compute sqr(X) + sqr(Y)*yScale By making use of yScale, it is also possible to compute the following (at the same or higher speed): X^2 - Y^2 *) function SqrAddScaled(const X, Y: TMtxVecInt; const yScale: integer): TMtxVecInt; overload; (* Compute sqr(X) + sqr(Y)*yScale on sub arrays *) function SqrAddScaled(const X: TMtxVecInt; xIndex: integer; const Y: TMtxVecInt; yIndex: integer; const yScale: integer; Index, Len: integer): TMtxVecInt; overload; (* Compute X + Y + Z *) function Add(const X, Y, Z: TMtxVecInt): TMtxVecInt; overload; (* Compute X + Y + Z on sub arrays *) function Add(const X: TMtxVecInt; xIndex: integer; const Y: TMtxVecInt; yIndex: integer; const Z: TMtxVecInt; zIndex: integer; Index, Len: integer): TMtxVecInt; overload; (* Compute X + Y + Z*zScale *) function AddScaled(const X, Y, Z: TMtxVecInt; const zScale: integer): TMtxVecInt; overload; (* Compute X + Y + Z*zScale on sub arrays *) function AddScaled(const X: TMtxVecInt; xIndex: integer; const Y: TMtxVecInt; yIndex: integer; const Z: TMtxVecInt; zIndex: integer; const zScale: integer; Index, Len: integer): TMtxVecInt; overload; (* Compute X + Y*yScale + Z*zScale *) function AddScaled(const X, Y: TMtxVecInt; const yScale: integer; const Z: TMtxVecInt; const zScale: integer): TMtxVecInt; overload; (* Compute X + Y*yScale + Z*zScale on sub arrays *) function AddScaled(const X: TMtxVecInt; xIndex: integer; const Y: TMtxVecInt; yIndex: integer; const yScale: integer; const Z: TMtxVecInt; zIndex: integer; const zScale: integer; Index, Len: integer): TMtxVecInt; overload; (* Compute X + Y + zScalar *) function Add(const X, Y: TMtxVecInt; const Z: integer): TMtxVecInt; overload; (* Compute X + Y + zScalar on sub arrays *) function Add(const X: TMtxVecInt; xIndex: integer; const Y: TMtxVecInt; yIndex: integer; const Z: integer; Index, Len: integer): TMtxVecInt; overload; (* Compute X + Y*yScale + zScalar *) function AddScaledC(const X, Y: TMtxVecInt; const yScale: integer; const Z: integer): TMtxVecInt; overload; (* Compute X + Y*yScale + zScalar on sub arrays *) function AddScaledC(const X: TMtxVecInt; xIndex: integer; const Y: TMtxVecInt; yIndex: integer; const yScale: integer; const Z: integer; Index, Len: integer): TMtxVecInt; overload; (* Compute X - Y - Z *) function Sub(const X, Y, Z: TMtxVecInt): TMtxVecInt; overload; (* Compute X - Y - Z on sub array*) function Sub(const X: TMtxVecInt; xIndex: integer; const Y: TMtxVecInt; yIndex: integer;const Z: TMtxVecInt; zIndex: integer; Index, Len: integer): TMtxVecInt; overload; (* Compute X - Y*yScale - Z*zScale *) function SubScaled(const X, Y: TMtxVecInt; const yScale: integer; const Z: TMtxVecInt; const zScale: integer): TMtxVecInt; overload; (* Compute X - Y*yScale - Z*zScale on sub array*) function SubScaled(const X: TMtxVecInt; xIndex: integer; const Y: TMtxVecInt; yIndex: integer; const yScale: integer; const Z: TMtxVecInt; zIndex: integer; const zScale: integer; Index, Len: integer): TMtxVecInt; overload; (* Compute X - Y - Z*zScale *) function SubScaled(const X, Y, Z: TMtxVecInt; const zScale: integer): TMtxVecInt; overload; (* Compute X - Y - Z*zScale on sub array*) function SubScaled(const X: TMtxVecInt; xIndex: integer; const Y: TMtxVecInt; yIndex: integer; const Z: TMtxVecInt; zIndex: integer; const zScale: integer; Index, Len: integer): TMtxVecInt; overload; (* Compute X - Y - zScalar *) function Sub(const X, Y: TMtxVecInt; const Z: integer): TMtxVecInt; overload; (* Compute X - Y - zScalar on sub array*) function Sub(const X: TMtxVecInt; xIndex: integer; const Y: TMtxVecInt; yIndex: integer; const Z: integer; Index, Len: integer): TMtxVecInt; overload; (* Compute X - Y*yScale - zScalar *) function SubScaledC(const X, Y: TMtxVecInt; const yScale: integer; const Z: integer): TMtxVecInt; overload; (* Compute X - Y*yScale - zScalar on sub array*) function SubScaledC(const X: TMtxVecInt; xIndex: integer; const Y: TMtxVecInt; yIndex: integer; const yScale: integer; const Z: integer; Index, Len: integer): TMtxVecInt; overload; (* Compute X * Y / Z *) function MulAndDiv(const X, Y, Z: TMtxVecInt): TMtxVecInt; overload; (* Compute X * Y / Z on sub array*) function MulAndDiv(const X: TMtxVecInt; xIndex: integer; const Y: TMtxVecInt; yIndex: integer; const Z: TMtxVecInt; zIndex: integer; Index, Len: integer): TMtxVecInt; overload; (* Compute (X + Y)*Z *) function AddAndMul(const X, Y, Z: TMtxVecInt): TMtxVecInt; overload; (* Compute (X + Y)*Z on sub array*) function AddAndMul(const X: TMtxVecInt; xIndex: Integer; const Y: TMtxVecInt; yIndex: Integer; const Z: TMtxVecInt; zIndex: Integer; Index, Len: Integer): TMtxVecInt; overload; (* Compute (X + Y)*Z*zScale *) function AddAndMul(const X, Y, Z: TMtxVecInt; zScale: integer): TMtxVecInt; overload; (* Compute (X + Y)*Z*zScale on sub array*) function AddAndMul(const X: TMtxVecInt; xIndex: Integer; const Y: TMtxVecInt; yIndex: Integer; const Z: TMtxVecInt; zIndex: Integer; zScale: integer; Index, Len: Integer): TMtxVecInt; overload; (* Compute (X + Y*yScale)*Z*zScale *) function AddAndMul(const X, Y: TMtxVecInt; yScale: integer; const Z: TMtxVecInt; zScale: integer): TMtxVecInt; overload; (* Compute (X + Y*yScale)*Z*zScale on sub array*) function AddAndMul(const X: TMtxVecInt; xIndex: Integer; const Y: TMtxVecInt; yIndex: Integer; yScale: integer; const Z: TMtxVecInt; zIndex: Integer; zScale: integer; Index, Len: Integer): TMtxVecInt; overload; (* Compute (X + Y)*zScalar *) function AddAndMul(const X, Y: TMtxVecInt; Z: integer): TMtxVecInt; overload; (* Compute (X + Y)*zScalar on sub array*) function AddAndMul(const X: TMtxVecInt; xIndex: Integer; const Y: TMtxVecInt; yIndex: Integer; Z: integer; Index, Len: Integer): TMtxVecInt; overload; (* Compute (X + Y*yScale)*zScalar *) function AddAndMul(const X, Y: TMtxVecInt; yScale, Z: integer): TMtxVecInt; overload; (* Compute (X + Y*yScale)*zScalar on sub array*) function AddAndMul(const X: TMtxVecInt; xIndex: Integer; const Y: TMtxVecInt; yIndex: Integer; yScale, Z: integer; Index, Len: Integer): TMtxVecInt; overload; (* Compute (X + yScalar)*Z*zScale *) function AddAndMul(const X: TMtxVecInt; Y: integer; const Z: TMtxVecInt; zScale: integer): TMtxVecInt; overload; (* Compute (X + yScalar)*Z*zScale on sub-array*) function AddAndMul(const X: TMtxVecInt; xIndex: integer; Y: integer; const Z: TMtxVecInt; zIndex: integer; zScale: integer; Index, Len: integer): TMtxVecInt; overload; (* Compute (X*xScale + yScalar)*Z *) function AddAndMul(const X: TMtxVecInt; xScale, Y: integer; const Z: TMtxVecInt): TMtxVecInt; overload; (* Compute (X*xScale + yScalar)*Z on sub-array*) function AddAndMul(const X: TMtxVecInt; xIndex: integer; xScale, Y : integer; const Z: TMtxVecInt; zIndex: integer; Index, Len: integer): TMtxVecInt; overload; (* Compute (X + yScalar)*Z *) function AddAndMul(const X: TMtxVecInt; Y: integer; const Z: TMtxVecInt): TMtxVecInt; overload; (* Compute (X + yScalar)*Z on sub-array*) function AddAndMul(const X: TMtxVecInt; xIndex: integer; Y: integer; const Z: TMtxVecInt; zIndex: integer; Index, Len: integer): TMtxVecInt; overload; (* Compute (X + yScalar)*zScalar *) function AddAndMul(const X: TMtxVecInt; Y, Z: integer): TMtxVecInt; overload; (* Compute (X + yScalar)*zScalar on sub-array*) function AddAndMul(const X: TMtxVecInt; xIndex: integer; Y, Z: integer; Index, Len: integer): TMtxVecInt; overload; (* Compute (X - Y)*Z *) function SubAndMul(const X, Y, Z: TMtxVecInt): TMtxVecInt; overload; (* Compute (X - Y)*Z on sub array*) function SubAndMul(const X: TMtxVecInt; xIndex: Integer; const Y: TMtxVecInt; yIndex: Integer; const Z: TMtxVecInt; zIndex: Integer; Index, Len: Integer): TMtxVecInt; overload; (* Compute (X - Y)*Z*zScale *) function SubAndMul(const X, Y, Z: TMtxVecInt; zScale: integer): TMtxVecInt; overload; (* Compute (X - Y)*Z*zScale on sub array*) function SubAndMul(const X: TMtxVecInt; xIndex: Integer; const Y: TMtxVecInt; yIndex: Integer; const Z: TMtxVecInt; zIndex: Integer; zScale: integer; Index, Len: Integer): TMtxVecInt; overload; (* Compute (X - Y*yScale)*Z*zScale *) function SubAndMul(const X, Y: TMtxVecInt; yScale: integer; const Z: TMtxVecInt; zScale: integer): TMtxVecInt; overload; (* Compute (X - Y*yScale)*Z*zScale on sub array*) function SubAndMul(const X: TMtxVecInt; xIndex: Integer; const Y: TMtxVecInt; yIndex: Integer; yScale: integer; const Z: TMtxVecInt; zIndex: Integer; zScale: integer; Index, Len: Integer): TMtxVecInt; overload; (* Compute (X - Y)*zScalar *) function SubAndMul(const X, Y: TMtxVecInt; Z: integer): TMtxVecInt; overload; (* Compute (X - Y)*zScalar on sub array*) function SubAndMul(const X: TMtxVecInt; xIndex: Integer; const Y: TMtxVecInt; yIndex: Integer; Z: integer; Index, Len: Integer): TMtxVecInt; overload; (* Compute (X - Y*yScale)*zScalar *) function SubAndMul(const X, Y: TMtxVecInt; yScale, Z: integer): TMtxVecInt; overload; (* Compute (X - Y*yScale)*zScalar on sub array*) function SubAndMul(const X: TMtxVecInt; xIndex: Integer; const Y: TMtxVecInt; yIndex: Integer; yScale, Z: integer; Index, Len: Integer): TMtxVecInt; overload; (* Compute (X - yScalar)*Z*zScale *) function SubAndMul(const X: TMtxVecInt; Y: integer; const Z: TMtxVecInt; zScale: integer): TMtxVecInt; overload; (* Compute (X - yScalar)*Z*zScale on sub-array*) function SubAndMul(const X: TMtxVecInt; xIndex: integer; Y: integer; const Z: TMtxVecInt; zIndex: integer; zScale: integer; Index, Len: integer): TMtxVecInt; overload; (* Compute (X*xScale - yScalar)*Z *) function SubAndMul(const X: TMtxVecInt; xScale, Y: integer; const Z: TMtxVecInt): TMtxVecInt; overload; (* Compute (X*xScale - yScalar)*Z on sub-array*) function SubAndMul(const X: TMtxVecInt; xIndex: integer; xScale, Y : integer; const Z: TMtxVecInt; zIndex: integer; Index, Len: integer): TMtxVecInt; overload; (* Compute (X - yScalar)*Z *) function SubAndMul(const X: TMtxVecInt; Y: integer; const Z: TMtxVecInt): TMtxVecInt; overload; (* Compute (X - yScalar)*Z on sub-array*) function SubAndMul(const X: TMtxVecInt; xIndex: integer; Y: integer; const Z: TMtxVecInt; zIndex: integer; Index, Len: integer): TMtxVecInt; overload; (* Compute (X - yScalar)*zScalar *) function SubAndMul(const X: TMtxVecInt; Y, Z: integer): TMtxVecInt; overload; (* Compute (X - yScalar)*zScalar on sub-array*) function SubAndMul(const X: TMtxVecInt; xIndex: integer; Y, Z: integer; Index, Len: integer): TMtxVecInt; overload; (* Compute X*Y + Z *) function MulAndAdd(const X, Y, Z: TMtxVecInt): TMtxVecInt; overload; (* Compute X*Y + Z on sub array*) function MulAndAdd(const X: TMtxVecInt; xIndex: Integer; const Y: TMtxVecInt; yIndex: Integer; const Z: TMtxVecInt; zIndex: Integer; Index, Len: Integer): TMtxVecInt; overload; (* Compute X*Y*xyScale + Z *) function MulAndAdd(const X, Y: TMtxVecInt; xyScale: integer; const Z: TMtxVecInt): TMtxVecInt; overload; (* Compute X*Y*xyScale + Z on sub array*) function MulAndAdd(const X: TMtxVecInt; xIndex: Integer; const Y: TMtxVecInt; yIndex: Integer; xyScale: integer; const Z: TMtxVecInt; zIndex: Integer; Index, Len: Integer): TMtxVecInt; overload; (* Compute X*Y + Z*zScale *) function MulAndAdd(const X, Y, Z: TMtxVecInt; zScale: integer): TMtxVecInt; overload; (* Compute X*Y + Z*zScale on sub array*) function MulAndAdd(const X: TMtxVecInt; xIndex: Integer; const Y: TMtxVecInt; yIndex: Integer; const Z: TMtxVecInt; zIndex: Integer; zScale: integer; Index, Len: Integer): TMtxVecInt; overload; (* Compute X*Y + zScalar *) function MulAndAdd(const X, Y: TMtxVecInt; Z: integer): TMtxVecInt; overload; (* Compute X*Y + zScalar on sub array*) function MulAndAdd(const X: TMtxVecInt; xIndex: Integer; const Y: TMtxVecInt; yIndex: Integer; Z: integer; Index, Len: Integer): TMtxVecInt; overload; (* Compute X*Y - Z *) function MulAndSub(const X, Y, Z: TMtxVecInt): TMtxVecInt; overload; (* Compute X*Y - Z on sub array*) function MulAndSub(const X: TMtxVecInt; xIndex: Integer; const Y: TMtxVecInt; yIndex: Integer; const Z: TMtxVecInt; zIndex: Integer; Index, Len: Integer): TMtxVecInt; overload; (* Compute X*Y*xyScale - Z *) function MulAndSub(const X, Y: TMtxVecInt; xyScale: integer; const Z: TMtxVecInt): TMtxVecInt; overload; (* Compute X*Y*xyScale + Z on sub array*) function MulAndSub(const X: TMtxVecInt; xIndex: Integer; const Y: TMtxVecInt; yIndex: Integer; xyScale: integer; const Z: TMtxVecInt; zIndex: Integer; Index, Len: Integer): TMtxVecInt; overload; (* Compute X*Y - Z*zScale *) function MulAndSub(const X, Y, Z: TMtxVecInt; zScale: integer): TMtxVecInt; overload; (* Compute X*Y - Z*zScale on sub array*) function MulAndSub(const X: TMtxVecInt; xIndex: Integer; const Y: TMtxVecInt; yIndex: Integer; const Z: TMtxVecInt; zIndex: Integer; zScale: integer; Index, Len: Integer): TMtxVecInt; overload; (* Compute X*Y - zScalar *) function MulAndSub(const X, Y: TMtxVecInt; Z: integer): TMtxVecInt; overload; (* Compute X*Y - zScalar on sub array*) function MulAndSub(const X: TMtxVecInt; xIndex: Integer; const Y: TMtxVecInt; yIndex: Integer; Z: integer; Index, Len: Integer): TMtxVecInt; overload; (* Compute X/Y + Z *) function DivAndAdd(const X, Y, Z: TMtxVecInt): TMtxVecInt; overload; (* Compute X/Y + Z on sub array*) function DivAndAdd(const X: TMtxVecInt; xIndex: Integer; const Y: TMtxVecInt; yIndex: Integer; const Z: TMtxVecInt; zIndex: Integer; Index, Len: Integer): TMtxVecInt; overload; (* Compute X/Y*xyScale + Z *) function DivAndAdd(const X, Y: TMtxVecInt; xyScale: integer; const Z: TMtxVecInt): TMtxVecInt; overload; (* Compute X/Y*xyScale + Z on sub array*) function DivAndAdd(const X: TMtxVecInt; xIndex: Integer; const Y: TMtxVecInt; yIndex: Integer; xyScale: integer; const Z: TMtxVecInt; zIndex: Integer; Index, Len: Integer): TMtxVecInt; overload; (* Compute X/Y + Z*zScale *) function DivAndAdd(const X, Y, Z: TMtxVecInt; zScale: integer): TMtxVecInt; overload; (* Compute X/Y + Z*zScale on sub array*) function DivAndAdd(const X: TMtxVecInt; xIndex: Integer; const Y: TMtxVecInt; yIndex: Integer; const Z: TMtxVecInt; zIndex: Integer; zScale: integer; Index, Len: Integer): TMtxVecInt; overload; (* Compute X/Y + zScalar *) function DivAndAdd(const X, Y: TMtxVecInt; Z: integer): TMtxVecInt; overload; (* Compute X/Y + zScalar on sub array*) function DivAndAdd(const X: TMtxVecInt; xIndex: Integer; const Y: TMtxVecInt; yIndex: Integer; Z: integer; Index, Len: Integer): TMtxVecInt; overload; (* Compute X/Y - Z *) function DivAndSub(const X, Y, Z: TMtxVecInt): TMtxVecInt; overload; (* Compute X/Y - Z on sub array*) function DivAndSub(const X: TMtxVecInt; xIndex: Integer; const Y: TMtxVecInt; yIndex: Integer; const Z: TMtxVecInt; zIndex: Integer; Index, Len: Integer): TMtxVecInt; overload; (* Compute X/Y*xyScale - Z *) function DivAndSub(const X, Y: TMtxVecInt; xyScale: integer; const Z: TMtxVecInt): TMtxVecInt; overload; (* Compute X/Y*xyScale - Z on sub array*) function DivAndSub(const X: TMtxVecInt; xIndex: Integer; const Y: TMtxVecInt; yIndex: Integer; xyScale: integer; const Z: TMtxVecInt; zIndex: Integer; Index, Len: Integer): TMtxVecInt; overload; (* Compute X/Y - Z*zScale *) function DivAndSub(const X, Y, Z: TMtxVecInt; zScale: integer): TMtxVecInt; overload; (* Compute X/Y - Z*zScale on sub array*) function DivAndSub(const X: TMtxVecInt; xIndex: Integer; const Y: TMtxVecInt; yIndex: Integer; const Z: TMtxVecInt; zIndex: Integer; zScale: integer; Index, Len: Integer): TMtxVecInt; overload; (* Compute X/Y - zScalar *) function DivAndSub(const X, Y: TMtxVecInt; Z: integer): TMtxVecInt; overload; (* Compute X/Y - zScalar on sub array*) function DivAndSub(const X: TMtxVecInt; xIndex: Integer; const Y: TMtxVecInt; yIndex: Integer; Z: integer; Index, Len: Integer): TMtxVecInt; overload; (* Compute X*xScale + Y*yScale *) function AddScaled(const X: TMtxVecInt; const xScale: integer; const Y: TMtxVecInt; const yScale: integer): TMtxVecInt; overload; (* Compute X*xScale + Y*yScale on sub arrays *) function AddScaled(const X: TMtxVecInt; xIndex: integer; const xScale: integer; const Y: TMtxVecInt; yIndex: integer; const yScale: integer; Index, Len: integer): TMtxVecInt; overload; (* Compute sqr(X*xScale + Y*yScale) *) function AddScaledSqr(const X: TMtxVecInt; const xScale: integer; const Y: TMtxVecInt; const yScale: integer): TMtxVecInt; overload; (* Compute sqr(X*xScale + Y*yScale) on sub arrays *) function AddScaledSqr(const X: TMtxVecInt; xIndex: integer; const xScale: integer; const Y: TMtxVecInt; yIndex: integer; const yScale: integer; Index, Len: integer): TMtxVecInt; overload; (* Compute sqr(X)*xScale + sqr(Y)*yScale *) function SqrAddScaled(const X: TMtxVecInt; const xScale: integer; const Y: TMtxVecInt; const yScale: integer): TMtxVecInt; overload; (* Compute sqr(X)*xScale + sqr(Y)*yScale on sub arrays *) function SqrAddScaled(const X: TMtxVecInt; xIndex: integer; const xScale: integer; const Y: TMtxVecInt; yIndex: integer; const yScale: integer; Index, Len: integer): TMtxVecInt; overload; (* Compute X*xScale + Y*yScale + Z*zScale *) function AddScaled(const X: TMtxVecInt; const xScale: integer; const Y: TMtxVecInt; const yScale: integer; const Z: TMtxVecInt; const zScale: integer): TMtxVecInt; overload; (* Compute X*xScale + Y*yScale + Z*zScale on sub arrays *) function AddScaled(const X: TMtxVecInt; xIndex: integer; const xScale: integer; const Y: TMtxVecInt; yIndex: integer; const yScale: integer; const Z: TMtxVecInt; zIndex: integer; const zScale: integer; Index, Len: integer): TMtxVecInt; overload; (* Compute X*xScale + Y*yScale + zScalar *) function AddScaledC(const X: TMtxVecInt; const xScale: integer; const Y: TMtxVecInt; const yScale: integer; const Z: integer): TMtxVecInt; overload; (* Compute X*xScale + Y*yScale + z on sub arrays *) function AddScaledC(const X: TMtxVecInt; xIndex: integer; const xScale: integer; const Y: TMtxVecInt; yIndex: integer; const yScale: integer; const Z: integer; Index, Len: integer): TMtxVecInt; overload; (* Compute X*xScale - Y*yScale - Z*zScale *) function SubScaled(const X: TMtxVecInt; const xScale: integer; const Y: TMtxVecInt; const yScale: integer; const Z: TMtxVecInt; const zScale: integer): TMtxVecInt; overload; (* Compute X*xScale - Y*yScale - zScalar *) function SubScaledC(const X: TMtxVecInt; const xScale: integer; const Y: TMtxVecInt; const yScale: integer; const Z: integer): TMtxVecInt; overload; (* Compute X*xScale - Y*yScale - Z*zScale on sub array*) function SubScaled(const X: TMtxVecInt; xIndex: integer; const xScale: integer; const Y: TMtxVecInt; yIndex: integer; const yScale: integer; const Z: TMtxVecInt; zIndex: integer; const zScale: integer; Index, Len: integer): TMtxVecInt; overload; (* Compute X*xScale - Y*yScale - zScalar on sub array*) function SubScaledC(const X: TMtxVecInt; xIndex: integer; const xScale: integer; const Y: TMtxVecInt; yIndex: integer; const yScale: integer; const Z: integer; Index, Len: integer): TMtxVecInt; overload; (* Compute X*Y*Z The following expression would also run at the same or higher speed, when passing X also for the Z parameter: X^2*Y *) function Mul(const X, Y,Z: TMtxVecInt): TMtxVecInt; overload; (* Compute X*Y*zScalar The following expression would also run at the same or higher speed, when passing X also for the Z parameter: X^2*zScalar *) function Mul(const X,Y: TMtxVecInt; const Z: integer): TMtxVecInt; overload; (* Compute X*Y*Z on sub array*) function Mul(const X: TMtxVecInt; xIndex: integer; const Y: TMtxVecInt; yIndex: integer; const Z: TMtxVecInt; zIndex: integer; Index, Len: integer): TMtxVecInt; overload; (* Compute X*Y*zScalar on sub array*) function Mul(const X: TMtxVecInt; xIndex: integer; const Y: TMtxVecInt; yIndex: integer; const Z: integer; Index, Len: integer): TMtxVecInt; overload; (* Compute X / (Y*Z) The following expression would also run at the same or higher speed, when passing Y also for the Z parameter: X / (Y^2) *) function Divide(const X, Y, Z: TMtxVecInt): TMtxVecInt; overload; (* Compute X / (Y*zScale) *) function DivideC(const X, Y: TMtxVecInt; const Z: integer): TMtxVecInt; overload; (* Compute X/( Y*Z ) on sub array*) function Divide(const X: TMtxVecInt; xIndex: integer; const Y: TMtxVecInt; yIndex: integer; const Z: TMtxVecInt; zIndex: integer; Index, Len: integer): TMtxVecInt; overload; (* Compute X / (Y*zScalar) on sub array*) function DivideC(const X: TMtxVecInt; xIndex: integer; const Y: TMtxVecInt; yIndex: integer; const Z: integer; Index, Len: integer): TMtxVecInt; overload; (* Compute X * Y * xyScale / Z The following expression would also run at the same or higher speed, when passing X also for the Y parameter: X^2 * xyScale/ Z *) function MulAndDiv(const X, Y: TMtxVecInt; const xyScale: integer; const Z: TMtxVecInt): TMtxVecInt; overload; (* Compute X * Y / zScalar *) function MulAndDiv(const X, Y: TMtxVecInt; const Z: integer): TMtxVecInt; overload; (* Compute xScalar / (Y*Z) *) function Divide(const X: integer; const Y, Z: TMtxVecInt): TMtxVecInt; overload; (* Compute X * Y xyScale / Z on sub array*) function MulAndDiv(const X: TMtxVecInt; xIndex: integer; const Y: TMtxVecInt; yIndex: integer; const xyScale: integer; const Z: TMtxVecInt; zIndex: integer; Index, Len: integer): TMtxVecInt; overload; (* Compute X * Y / zScalar on sub array*) function MulAndDiv(const X: TMtxVecInt; xIndex: integer; const Y: TMtxVecInt; yIndex: integer; const Z: integer; Index, Len: integer): TMtxVecInt; overload; (* Compute xScalar / (Y*Z) on sub array*) function Divide(const X: integer; const Y: TMtxVecInt; yIndex: integer; const Z: TMtxVecInt; zIndex: integer; Index, Len: integer): TMtxVecInt; overload; (* Compute (X*xScale + Y*yScale)*Z*zScale The following is also possible at the same or higher speed: X^2 * xScale + XY * yScale by passing X also for the Z parameter. *) function AddAndMul(const X: TMtxVecInt; xScale: integer; const Y: TMtxVecInt; yScale: integer; const Z: TMtxVecInt; zScale: integer): TMtxVecInt; overload; (* Compute (X*xScale + Y*yScale)*zScalar*) function AddAndMul(const X: TMtxVecInt; xScale: integer; const Y: TMtxVecInt; yScale: integer; Z: integer): TMtxVecInt; overload; (* Compute (X*xScale + Y*yScale)*Z*Scale on sub array*) function AddAndMul(const X: TMtxVecInt; xIndex: Integer; xScale: integer; const Y: TMtxVecInt; yIndex: Integer; yScale: integer; const Z: TMtxVecInt; zIndex: Integer; zScale: integer; Index, Len: Integer): TMtxVecInt; overload; (* Compute (X*xScale + Y*yScale)*zScalar on sub array*) function AddAndMul(const X: TMtxVecInt; xIndex: Integer; xScale: integer; const Y: TMtxVecInt; yIndex: Integer; yScale: integer; Z: integer; Index, Len: Integer): TMtxVecInt; overload; (* Compute (X*xScale + yScalar)*Z*zScale*) function AddAndMul(const X: TMtxVecInt; xScale: integer; Y: integer; const Z: TMtxVecInt; zScale: integer): TMtxVecInt; overload; (* Compute (X*xScale + yScalar)*zScalar*) function AddAndMul(const X: TMtxVecInt; xScale: integer; Y, Z: integer): TMtxVecInt; overload; (* Compute (X*xScale + yScalar)*Z*zScale on sub-array*) function AddAndMul(const X: TMtxVecInt; xIndex: integer; xScale: integer; Y: integer; const Z: TMtxVecInt; zIndex: integer; zScale: integer; Index, Len: integer): TMtxVecInt; overload; (* Compute (X*xScale + yScalar)*zScalar on sub array*) function AddAndMul(const X: TMtxVecInt; xIndex: integer; xScale: integer; Y, Z: integer; Index, Len: integer): TMtxVecInt; overload; (* Compute (X*xScale - Y*yScale)*Z*zScale*) function SubAndMul(const X: TMtxVecInt; xScale: integer; const Y: TMtxVecInt; yScale: integer; const Z: TMtxVecInt; zScale: integer): TMtxVecInt; overload; (* Compute (X*xScale - Y*yScale)*zScalar*) function SubAndMul(const X: TMtxVecInt; xScale: integer; const Y: TMtxVecInt; yScale: integer; Z: integer): TMtxVecInt; overload; (* Compute (X*xScale - Y*yScale)*Z*Scale on sub array*) function SubAndMul(const X: TMtxVecInt; xIndex: Integer; xScale: integer; const Y: TMtxVecInt; yIndex: Integer; yScale: integer; const Z: TMtxVecInt; zIndex: Integer; zScale: integer; Index, Len: Integer): TMtxVecInt; overload; (* Compute (X*xScale - Y*yScale)*zScalar on sub array*) function SubAndMul(const X: TMtxVecInt; xIndex: Integer; xScale: integer; const Y: TMtxVecInt; yIndex: Integer; yScale: integer; Z: integer; Index, Len: Integer): TMtxVecInt; overload; (* Compute (X*xScale - yScalar)*Z*zScale*) function SubAndMul(const X: TMtxVecInt; xScale: integer; Y: integer; const Z: TMtxVecInt; zScale: integer): TMtxVecInt; overload; (* Compute (X*xScale - yScalar)*zScalar*) function SubAndMul(const X: TMtxVecInt; xScale: integer; Y, Z: integer): TMtxVecInt; overload; (* Compute (X*xScale - yScalar)*Z*zScale on sub-array*) function SubAndMul(const X: TMtxVecInt; xIndex: integer; xScale: integer; Y: integer; const Z: TMtxVecInt; zIndex: integer; zScale: integer; Index, Len: integer): TMtxVecInt; overload; (* Compute (X*xScale - yScalar)*zScalar on sub array*) function SubAndMul(const X: TMtxVecInt; xIndex: integer; xScale: integer; Y, Z: integer; Index, Len: integer): TMtxVecInt; overload; (* Compute (X*Y)*xyScale + Z*zScale The following expression would also run at the same or higher speed, when passing X also for the Y parameter: X^2*xyScale + Z*zScale *) function MulAndAdd(const X: TMtxVecInt; const Y: TMtxVecInt; xyScale: integer; const Z: TMtxVecInt; zScale: integer): TMtxVecInt; overload; (* Compute (X*Y)*xyScale + zScalar*) function MulAndAdd(const X: TMtxVecInt; const Y: TMtxVecInt; xyScale: integer; Z: integer): TMtxVecInt; overload; (* Compute (X*Y)*xyScale + Z*zScale on sub array*) function MulAndAdd(const X: TMtxVecInt; xIndex: Integer; const Y: TMtxVecInt; yIndex: Integer; xyScale: integer; const Z: TMtxVecInt; zIndex: Integer; zScale: integer; Index, Len: Integer): TMtxVecInt; overload; (* Compute (X*Y)*xyScale + zScalar on sub array The following expression would also run at the same or higher speed, when passing X also for the Y parameter: X^2*xyScale + zScale *) function MulAndAdd(const X: TMtxVecInt; xIndex: Integer; const Y: TMtxVecInt; yIndex: Integer; xyScale: integer; Z: integer; Index, Len: Integer): TMtxVecInt; overload; (* Compute (X*yScalar) + zScalar*) function MulAndAdd(const X: TMtxVecInt; Y, Z: integer): TMtxVecInt; overload; (* Compute (X*yScalar) + zScalar*) function MulAndAdd(const X: TMtxVecInt; xIndex: integer; Y, Z: integer; Index, Len: integer): TMtxVecInt; overload; (* Compute (X*Y)*xyScale - Z*zScale*) function MulAndSub(const X: TMtxVecInt; const Y: TMtxVecInt; xyScale: integer; const Z: TMtxVecInt; zScale: integer): TMtxVecInt; overload; (* Compute (X*Y)*xyScale - zScalar*) function MulAndSub(const X: TMtxVecInt; const Y: TMtxVecInt; xyScale, Z: integer): TMtxVecInt; overload; (* Compute (X*Y)*xyScale - Z*zScale on sub array*) function MulAndSub(const X: TMtxVecInt; xIndex: Integer; const Y: TMtxVecInt; yIndex: Integer; xyScale: integer; const Z: TMtxVecInt; zIndex: Integer; zScale: integer; Index, Len: Integer): TMtxVecInt; overload; (* Compute (X*Y)*xyScale - zScalar on sub array*) function MulAndSub(const X: TMtxVecInt; xIndex: Integer; const Y: TMtxVecInt; yIndex: Integer; xyScale: integer; Z: integer; Index, Len: Integer): TMtxVecInt; overload; (* Compute X*yScalar - Z*zScale*) function MulAndSub(const X: TMtxVecInt; Y: integer; const Z: TMtxVecInt; zScale: integer): TMtxVecInt; overload; (* Compute X*yScalar - Z*zScale on sub array*) function MulAndSub(const X: TMtxVecInt; xIndex: integer; Y: integer; const Z: TMtxVecInt; zIndex: integer; zScale: integer; Index, Len: integer): TMtxVecInt; overload; (* Compute (X / Y)*xyScale + Z*zScale The following expression would also run at the same or higher speed, when passing Z also for the Y parameter: (X / Z) * xyScale + Z * zScale *) function DivAndAdd(const X: TMtxVecInt; const Y: TMtxVecInt; xyScale: integer; const Z: TMtxVecInt; zScale: integer): TMtxVecInt; overload; (* Compute (X / Y) * xyScale + zScalar*) function DivAndAdd(const X: TMtxVecInt; const Y: TMtxVecInt; xyScale: integer; Z: integer): TMtxVecInt; overload; (* Compute (X / Y)*xyScale + Z*zScale on sub array*) function DivAndAdd(const X: TMtxVecInt; xIndex: Integer; const Y: TMtxVecInt; yIndex: Integer; xyScale: integer; const Z: TMtxVecInt; zIndex: Integer; zScale: integer; Index, Len: Integer): TMtxVecInt; overload; (* Compute (X / Y) * xyScale + zScalar*) function DivAndAdd(const X: TMtxVecInt; xIndex: Integer; const Y: TMtxVecInt; yIndex: Integer; xyScale: integer; Z: integer; Index, Len: Integer): TMtxVecInt; overload; (* Compute (X / Y) * xyScale - Z y*) function DivAndSub(const X: TMtxVecInt; const Y: TMtxVecInt; xyScale: integer; const Z: TMtxVecInt; zScale: integer): TMtxVecInt; overload; (* Compute (X / Y) * xyScale - zScalar*) function DivAndSub(const X: TMtxVecInt; const Y: TMtxVecInt; xyScale: integer; Z: integer): TMtxVecInt; overload; (* Compute (X / Y) * xyScale - Z on sub array*) function DivAndSub(const X: TMtxVecInt; xIndex: Integer; const Y: TMtxVecInt; yIndex: Integer; xyScale: integer; const Z: TMtxVecInt; zIndex: Integer; zScale: integer; Index, Len: Integer): TMtxVecInt; overload; (* Compute (X / Y) * xyScale - zScalar on sub array*) function DivAndSub(const X: TMtxVecInt; xIndex: Integer; const Y: TMtxVecInt; yIndex: Integer; xyScale: integer; Z: integer; Index, Len: Integer): TMtxVecInt; overload; (*Copy object values. Copy each of Vec elements to the calling object. Size and precision properties of the calling object are set implicitly to match Vec object. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TMtxVecInt a,b,c; a = new TMtxVecInt(); b = new TMtxVecInt(); a.SetIt(new int[] {1,2,3,4}); // a = [1,2,3,4] i.e 1+2i ; 3+4i b.Copy(a); // b = [1,2,3,4] } } *) function Copy(const Src: TMtxVecInt): TMtxVecInt; overload; (*Copy Src elements [SrcIndex]..[SrcIndex+Len-1] in the calling object elements [Index]..[Index+Len-1]. Vector must be set explicitly. An exception is raised if array borders are overrun or underrun. *) function Copy(const Src: TMtxVecInt; const SrcIndex, Index, Len: integer): TMtxVecInt; overload; (* Copy each of Vec elements to the calling object. The Size property of the calling object is set implicitly to match Vec object. The storage precision of the calling object is set to DstIntPrecision. *) function Convert(const Src: TMtxVecInt; DstIntPrecision: TIntPrecision): TMtxVecInt; overload; (*Copy Src elements [SrcIndex]..[SrcIndex+Len-1] in the calling object elements [Index]..[Index+Len-1]. Calling vector must be set explicitly. An exception is raised if array borders are overrun or underrun. If the precision of the calling does not match DstIntPrecision, an exception will be raised. *) function Convert(const Src: TMtxVecInt; DstIntPrecision: TIntPrecision; SrcIndex, Index, Len: integer): TMtxVecInt; overload; (*Compares Value with all calling object elements.*) function IsEqual(const Value: integer): boolean; overload; (*Compares Value with all calling object elements.*) function IsEqual(const Value, Index, Len: integer): boolean; overload; (*Compares two objects. True, if they are equal. Compares two objects and returns True, if they are equal. The method compares and properties and coresponding values. *) function IsEqual(const Vec: TMtxVecInt): boolean; overload; (*Compares Vec elements [VecIndex]..[VecIndex+Len-1] with calling object elements [Index]..[Index+Len-1].*) function IsEqual(const Vec: TMtxVecInt; const VecIndex, Index, Len: integer): boolean; overload; (*Vectorised maximum. Compares Vec values with corresponding elements in the calling object and stores the bigger value in Self. Size and properties need to match. *) function MaxEvery(const Vec: TMtxVecInt): TMtxVecInt; overload; (*Compare Vec elements [VecIndex]..[VecIndex+Len-1] with calling object elements [Index]..[Index+Len-1] and store result in Self. An exception is raised if Vec and calling object property do not match or if array borders are overrun/underrun. *) function MaxEvery(const Vec: TMtxVecInt; VecIndex, Index, Len: integer): TMtxVecInt; overload; (*Compare all Vec1 elements with corresponding Vec2 elements and store bigger value in Self. Stores the results in to the calling object. Size and property of calling object are adjusted automatically to match those of Vec1 and Vec2. An exception is raised if Vec1 and Vec2 size and property do not match. *) function MaxEvery(const Vec1, Vec2: TMtxVecInt): TMtxVecInt; overload; (*Compare Vec1 elements [Vec1Index]..[Vec1Index+Len-1] with Vec2 object elements [Vec2Index]..[Vec2Index+Len-1] and store bigger value in Self. Stores the results in to the calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if ConditionCheck is True and array borders are overrun or underrun. *) function MaxEvery(const Vec1, Vec2: TMtxVecInt; Vec1Index, Vec2Index, Index, Len: integer): TMtxVecInt; overload; (*Vectorised minimum. Compares Vec values with corresponding elements in the calling object and stores the smaller value in Self. Size and property of the calling object are set automatically. *) function MinEvery(const Vec: TMtxVecInt): TMtxVecInt; overload; (*Compare Vec elements [VecIndex]..[VecIndex+Len-1] with calling object elements [Index]..[Index+Len-1] and store result in Self. An exception is raised, if Vec and calling object property do not match or if array borders are overrun/underrun. *) function MinEvery(const Vec: TMtxVecInt; VecIndex, Index, Len: integer): TMtxVecInt; overload; (*Compare all Vec1 elements with corresponding Vec2 elements and store the smaller value in Self. Stores the results in to the calling object. Size and property of calling object are adjusted automatically to match those of Vec1 and Vec2. An exception is raised if Vec1 and Vec2 size and property do not match. *) function MinEvery(const Vec1, Vec2: TMtxVecInt): TMtxVecInt; overload; (*Compare Vec1 elements [Vec1Index]..[Vec1Index+Len-1] with Vec2 object elements [Vec2Index]..[Vec2Index+Len-1] and store the smaller value in Self. Stores the results in to the calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if ConditionCheck is True and array borders are overrun or underrun. *) function MinEvery(const Vec1, Vec2: TMtxVecInt; Vec1Index, Vec2Index, Index, Len: integer): TMtxVecInt; overload; (*Maximum value. The maximum value of all calling object elements. The result is an integer value. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TVecInt a; MtxVecInt.CreateIt(out a); try { a.SetIt(new int[] {1,2,3,4}); int b = a.Max(); // 4 } finally { MtxVecInt.FreeIt(ref a); } } } *) function Max(): integer; overload; (*Calculate the maximum value from calling object elements [Index]..[Index+Len-1]. The result is an integer value. An exception is raised if array borders are overrun. *) function Max(const Index, Len: integer): integer; overload; (*Minimum value. The minimum value of all calling object elements. The result is an integer value. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TVecInt a; MtxVecInt.CreateIt(out a); try { a.SetIt(new int[] {1,2,3,4}); int b = a.Min(); // 1 } finally { MtxVecInt.FreeIt(ref a); } } } *) function Min(): integer; overload; (*Calculate the minimum value from calling object elements [Index]..[Index+Len-1]. The result is an integer value. An exception is raised if array borders are overrun. *) function Min(const Index, Len: integer): integer; overload; (*Calculate minimum and maximum in one procedure call. Returns calling vector maximum value. Returns calling vector monimum value.*) procedure MaxMin(out aMax, aMin: integer); overload; (*Calculate minimum and maximum in one procedure call. Returns calling vector elements [Index..Index+Len-1] maximum value. Returns calling vector elements [Index..Index+Len-1] minimum value. The starting index at which to start the search. The number of elements to search starting from Index. An exception is raised if array borders are overrun/underrun. *) procedure MaxMin(out aMax, aMin: integer; const Index, Len: integer); overload; (*Calculate the maximum value of all calling object elements. the maximum of all calling vector integer elements in-place. Stores maximum value index. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TVecInt a; int ind; MtxVecInt.CreateIt(out a); try { a.SetIt(new int[] {1,2,3,4}); int max = a.Max(out ind); //max=3, ind = 3 } finally { MtxVecInt.FreeIt(ref a); } } } *) function Max(out aIndex: integer): integer; overload; (*Calculate the maximum value of calling object elements [Index..Index+Len-1]. the maximum of calling vector integer elements [Index..Index+Len-1]. Returns maximum value index. The starting index at which to start the search. The number of elements to search starting from Index. An exception is raised if array borders are overrun/underrun. *) function Max(out aIndex: integer; const Index, Len: integer): integer; overload; (*Calculate the minimum value of all calling object elements. the minimum of all calling vector integer elements in-place. Stores minimum value index. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TVecInt a; int ind; MtxVecInt.CreateIt(out a); try { a.SetIt(new int[] {1,2,3,4); int min = a.Min(out ind); //min=1, ind = 0 } finally { MtxVecInt.FreeIt(ref a); } } } *) function Min(out aIndex: integer): integer; overload; (*Calculate the maximum value of calling object elements [Index..Index+Len-1]. the minimum of calling vector integer elements [Index..Index+Len-1]. Returns minimum value index. The starting index at which to start the search. The number of elements to search starting from Index. An exception is raised if array borders are overrun/underrun. *) function Min(out aIndex: integer; const Index, Len: integer): integer; overload; (*Calculate minimum, maximum and their indices in one procedure call. Returns calling vector maximum value. Returns calling vector maximum value index. Returns calling vector monimum value. Returns calling vector minimum value index.*) procedure MaxMinIdx(out aMax, aMaxIdx, aMin, aMinIdx: integer); overload; (*Calculate minimum, maximum and their indices in one procedure call. Returns calling vector elements [Index..Index+Len-1] maximum value. Returns calling vector maximum value index. Returns calling vector elements [Index..Index+Len-1] minimum value. Returns calling vector minimum value index. The starting index at which to start the search. The number of elements to search starting from Index. An exception is raised if array borders are overrun/underrun. *) procedure MaxMinIdx(out aMax, aMaxIdx, aMin, aMinIdx: integer; const Index, Len: integer); overload; (*Applies median filter with size Mask to the calling vector. Median filter is a nonlinear filter which replaces each element of the calling vector with the median value, calculated over the fixed range (mask) centered around that element. *) function Median(const MaskSize: integer): TMtxVecInt; overload; (*Applies median filter with size Mask to the calling vector elements [Index.. Index+Len-1]. Median filter is a nonlinear filter which replaces each element of the calling vector with the median value, calculated over the fixed range (mask) centered around that element. *) function Median(const MaskSize, Index, Len: integer): TMtxVecInt; overload; (*Applies median filter with size Mask to data in Src and stores the result in the calling vector. Median filter is a nonlinear filter which replaces each element of the calling vector with the median value, calculated over the fixed range (mask) centered around that element and stores the result in the calling vector. *) function Median(const Src: TMtxVecInt; const MaskSize: integer): TMtxVecInt; overload; (*Applies median filter with size Mask to Src object elements [SrcIndex..SrcIndex+Len-1] and stores the result in the calling vector elements [Index..Index+Len-1]. Median filter is a nonlinear filter which replaces each element of the Src vector with the median value, calculated over the fixed range (mask) centered around that element and stores the result in the calling vector. *) function Median(const Src: TMtxVecInt; const MaskSize, SrcIndex, Index, Len: integer): TMtxVecInt; overload; (*Resizes vector size while preserving values. Resizes calling vector to Len and fills it with Src vector first Len values. If Src length is less than Len and ZeroIt parameter is true, the remaining calling vector values are set to zero. var a, b: TVecInt; begin CreateIt(a,b); try a.SetIt([1,2,3]); b.SetIt([9]); b.Resize(a,7,True); // b=(9,1,2,3,4,0,0,0) finally FreeIt(a,b); end; end; *) function Resize(const Src: TVecInt; const Len: integer; const ZeroIt: boolean = False): TVecInt; overload; (*Resizes calling vector Length to Len. If is less than Len and ZeroIt parameter is true, the remaining calling vector values are set to zero. var a: TVecInt; begin CreateIt(a); try a.SetIt([1,2,3]); a.Resize(7,True); // a= [1,2,3,0,0,0,0] finally FreeIt(a); end; end; *) function Resize(const Len: integer; const ZeroIt: boolean = False): TVecInt; overload; (*Fills the calling vector elements with linear rule and randomly shuffles the indexes. Fills the calling vector with a series following the rule: Values[k] := k and then scrambles the contents of the vector randomly by using the Fisher–Yates shuffle. *) function RandomRamp: TVecInt; overload; (*Randomly shuffles the content of the vector. Scrambles the contents of the vector randomly by using the Fisher–Yates shuffle. *) function RandomShuffle: TVecInt; overload; (*Fills the calling vector with a series following linear rule. Fills the calling vector with a series following the rule: Values[k] := k (Offset is zero and Step is one). var a: TVecInt; begin CreateIt(a); try a.Size(5,int32); a.Ramp(0,2); // [0, 2, 4, 6, 8] finally FreeIt(a); end; end; which is identical to: CreateIt(a); try a.Size(5,int32); for i:= 0 to a.Length-1 do a[i] := i*2; finally FreeIt(a); end; *) function Ramp: TVecInt; overload; (*Fills the calling vector. Method uses the following rule: Values[k] := Offset + k*Step. *) function Ramp(const Offset, Step: double): TVecInt; overload; (*Fills the calling vector elements [Index]..[Index+Len-1]. Method uses the following rule: Values[k] := Offset + k*Step. An exception is raised if calling vector array borders are overrun. *) function Ramp(const Offset,Step: double; const Index,Len: integer): TVecInt; overload; (*A cyclic shift on all calling vector elements. Performs cyclic shift on all calling vector elements. Offset can be any integer number, positive or negative. *) function Rotate(const Offset: integer): TMtxVecInt; overload; (*A cyclic shift on vector elements in range. Performs cyclic shift on vector elements in specified range [Index..Index+Len-1]. The number of elements to shift is specified in the Offset parameter. Offset can be any integer number, positive or negative. An exception is raised if array borders are overrun/underrun. *) function Rotate(const Offset, Index, Len: integer): TMtxVecInt; overload; (*A cyclic shift on vector elements in range. Performs cyclic shift on all source vector elements and stores them to calling vector elements [Index .. Index+Len-1]. The number of elements to shift is specified in the Offset parameter. Offset can be any integer number, positive or negative. An exception is raised if array borders are overrun/underrun. *) function Rotate(const Src: TMtxVecInt; const Offset: integer): TMtxVecInt; overload; (*A cyclic shift on vector elements in range. Performs cyclic shift on source vector elements in specified range [SrcIndex .. SrcIndex+Len-1] and stores them to calling vector elements [Index .. Index+Len-1]. The number of elements to shift is specified in the Offset parameter. Offset can be any integer number, positive or negative. An exception is raised if array borders are overrun/underrun. *) function Rotate(const Src: TMtxVecInt; const Offset, SrcIndex, Index, Len: integer): TMtxVecInt; overload; (*Reverse vector elements. The method reverses vector elements by using the following equation: This overload reverses all calling vector elements in-place. var a: TVecInt; begin CreateIt(a); try a.SetIt([1,2,3,4]); a.Reverse; // a = [4,3,2,1] finally FreeIt(a); end; end; *) function Reverse: TVecInt; overload; (*Reverse all Vec elements. Xtore the result in the calling vector elements. The property of the calling vector is set to implicitly match Vec vector. *) function Reverse(const Vec: TMtxVecInt): TVecInt; overload; (*Reverse vector elements. The method reverses Vec vector elements from [VecIndex].. [VecIndex+Len-1] and stores them in the calling vector from [Index]...[Index+Len-1] by using the following equation: This overload reverses calling vector elements in-place. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TVecInt a; MtxVecInt.CreateIt(out a); try { a.SetIt(new int[] {1,2,3,4); a.Reverse(); // a = [4,3,2,1] } finally { MtxVecInt.FreeIt(ref a); } } } *) function Reverse(const Vec: TMtxVecInt; const VecIndex, Index, Len: integer): TMtxVecInt; overload; (*Reverses the calling object elements [Index]..[Index+Len-1]. An exception is raised if array borders are overrun. *) function Reverse(const Index, Len: integer): TMtxVecInt; overload; (*Divide all Src elements with Value elements and store result of division in the calling object and reminder in RemDst. Size and properties of the calling object and of RemDst are adjusted automatically. *) function RemDiv(Src, Value: TMtxVecInt; RemDst: TMtxVecInt): TMtxVecInt; overload; (*Divide all Src elements with Value and store result of division in the calling object and reminder in RemDst. Store the result of division in the calling object elements [Index]..[Index+Len-1] and remainder in to [RemDstIndex] .. [RemDstIndex+ Len-1]. Size and properties of the calling object and RemDst must be set explicitly. An exception is raised if is true and array borders are overrun/underrun. *) function RemDiv(Src, Value: TMtxVecInt; RemDst: TMtxVecInt; SrcIndex, ValueIndex, RemDstIndex, Index, Len: integer): TMtxVecInt; overload; (*Divide all Src elements with Value and store result of division in the calling object and reminder in RemDst. Size and properties of the calling object and of RemDst are adjusted automatically. *) function RemDiv(Src: TMtxVecInt; Value: integer; RemDst: TMtxVecInt): TMtxVecInt; overload; (*Divide all Src elements with Value and store result of division in the calling object and reminder in RemDst. Store the result of division in the calling object elements [Index]..[Index+Len-1] and remainder in to [RemDstIndex] .. [RemDstIndex+ Len-1]. Size and properties of the calling object and RemDst must be set explicitly. An exception is raised if is true and array borders are overrun/underrun. *) function RemDiv(Src: TMtxVecInt; Value: integer; RemDst: TMtxVecInt; SrcIndex, RemDstIndex, Index, Len: integer): TMtxVecInt; overload; (*Divide Src with all Value elements and store result of division in the calling object and reminder in RemDst. Size and properties of the calling object and of RemDst are adjusted automatically. *) function RemDiv(Src: integer; Value: TMtxVecInt; RemDst: TMtxVecInt): TMtxVecInt; overload; (*Divide Src with Value elements and store result of division in the calling object and reminder in RemDst. Store the result of division in the calling object elements [Index]..[Index+Len-1] and remainder in to [RemDstIndex] .. [RemDstIndex+ Len-1]. Size and properties of the calling object and RemDst must be set explicitly. An exception is raised if is true and array borders are overrun/underrun. *) function RemDiv(Src: integer; Value: TMtxVecInt; RemDst: TMtxVecInt; ValueIndex, RemDstIndex, Index, Len: integer): TMtxVecInt; overload; (*Write object header and values to a file. Write the header describing the calling object and the values array of the calling object to the file, specified by the FileName. If the file already exist, the data is overwritten by default. If Append is True, the data is appended to the end of the file. Note It is recommended you use a *.mtx extension when you're saving/loading matrix to/from file. Similarly, you should use a *.Vec extension when you're saving/loading vector to/from file. var Mtx: TMtxInt; begin CreateIt(Mtx); try Mtx.SetIt(2,2,[3,1,-1,5]); Mtx.SaveToFile('c:\test.mtx'); // Write info and header for Mtx to file finally FreeIt(Mtx); end; end; *) procedure SaveToFile(const FileName: string; const Append: boolean = False); (*Reads the header information and the values array content from the file. Reads the header information and the values array content from the file specified by FileName parameter. var b: TVecInt; begin CreateIt(b); try b.LoadFromFile('c:\test.Vec'); // Read header and values for b finally FreeIt(b); end; end; *) procedure LoadFromFile(const FileName: string); (*Sets object values. Set object values. Method call does not change object's size, but it does check for array overrun. The elements of A array are copied to the calling object elements, starting at Index. The IntPrecision property of the calling object is not changed. *) function SetIt(const Index: integer; const A: array of integer): TMtxVecInt; overload; (*Sets object values. Set object values. The size of the calling object is adjusted to match the length of the array. The elements of A array are copied to the calling object elements. The IntPrecision property of the calling object is not changed. *) function SetIt(const A: array of integer): TMtxVecInt; overload; (*Set calling object element Index to Value. An exception is raised if array borders are overrun/underrun. *) function SetVal(const Value: integer): TMtxVecInt; overload; (*Set all calling object elements [Index]..[Index+Len-1] to Value. An exception is raised if array borders are overrun/underrun. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TVecInt a; MtxVecInt.CreateIt(out a); try { a.SezIt(new int[] {1,2,3,4} ); a.SetVal(5,2,2); // a = [1,1,5,5] } finally { MtxVecInt.FreeIt(ref a); } } } *) function SetVal(const Value, Index, Len: integer): TMtxVecInt; overload; (*Do a shift on all calling vector elements. Performs shift on all calling vector elements. Offset can be any integer number, positive or negative. *) function Shift(const Offset: integer): TMtxVecInt; overload; (*Perform a shift on vector elements in range. Performs shift on vector elements in specified range [Index..Index+Len-1]. The number of elements to shift is specified in the Offset parameter. Offset can be any integer number, positive or negative. An exception is raised if array borders are overrun/underrun. *) function Shift(const Offset, Index, Len: integer): TMtxVecInt; overload; (*Do a shift on vector elements in range. Performs shift on all source vector elements and stores them to calling vector elements [Index .. Index+Len-1]. The number of elements to shift is specified in the Offset parameter. Offset can be any integer number, positive or negative. An exception is raised if array borders are overrun/underrun. *) function Shift(const Src: TVecInt; const Offset: integer): TVecInt; overload; (*A shift on vector elements in range. Performs a shift on source vector elements in specified range [SrcIndex .. SrcIndex+Len-1] and stores them to calling vector elements [Index .. Index+Len-1]. The number of elements to shift is specified in the Offset parameter. Offset can be any integer number, positive or negative. An exception is raised if array borders are overrun/underrun. *) function Shift(const Src: TMtxVecInt; const Offset, SrcIndex, Index, Len: integer): TMtxVecInt; overload; (*Set all calling vector elements to zero.*) function SetZero(): TMtxVecInt; overload; (*Set calling vector elements [Index..Index+Len-1] to zero. An exception is raised if array borders are overrun/underrun. *) function SetZero(const Index, Len: integer): TMtxVecInt; overload; (*Size the object. Assigns the size of the Src object to the calling object. If both objects have a matching property, only the property of the calling object will changed, while all other properties describing the size of the object will be preserved. *) function Size(const Src: TMtxVecBase): TMtxVecInt; overload; (*Sort all calling vector elements in ascending order in-place. *) function SortAscend: TMtxVecInt; overload; (*Sort calling vector elements [Index..Index+Len-1] in ascending order in-place.*) function SortAscend(const Index, Len: integer): TMtxVecInt; overload; (*Sort all calling vector elements in ascending order in-place. calling vector, storing sorted values. After execution stores sorted values indices. Size of DstSortIdx and calling vector are adjusted automatically. *) function SortAscend(const DstSortIdx: TVecInt): TVecInt; overload; function SortAscend(const DstSortIdx: TMtxVecInt; const SortIdxIndex, Index, Len: integer): TMtxVecInt; overload; (*Sort all calling vector elements in descending order in-place. *) function SortDescend: TMtxVecInt; overload; (*Sort calling vector elements [Index..Index+Len-1] in descending order in-place.*) function SortDescend(const Index, Len: integer): TMtxVecInt; overload; (*Sort all calling vector elements in descending order in-place. calling vector, storing sorted values. After execution stores sorted values indices. Size of DstSortIdx and calling vector are adjusted automatically. *) function SortDescend(const DstSortIdx: TVecInt): TVecInt; overload; function SortDescend(const DstSortIdx: TMtxVecInt; const SortIdxIndex, Index, Len: integer): TMtxVecInt; overload; (*Sums vector values. the sum of all calling object elements. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TVecInt a; MtxVecInt.CreateIt(out a); try { a.SetIt(new int[] {1,3,-2}); int s = a.Sum(); // s = 2 } finally { MtxVecInt.FreeIt(ref a); } } } *) function Sum(): integer; overload; (*Returns the sum of calling object elements [Index]..[Index+Len-1]. An exception is raised if array borders are overrun/underrun. *) function Sum(const Index, Len: integer): integer; overload; (*Threshold bottom operation. Perform threshold operation on all calling object values. The Value parameter is a lower bound for threshold operation. All values smaller than Value will be replaced with Value. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TVecInt a; MtxVecInt.CreateIt(out a); try { a.SetIt(new int[] {2, 0, 3, 4}); a.ThreshBottom(1); // a = [2,1,3,4] } finally { MtxVecInt.FreeIt(ref a); } } } *) function ThreshBottom(const Value: integer): TMtxVecInt; overload; (*Perform the threshold operation on calling object values [Index]..[Index+Len-1]. An exception is raised if array borders are overrun/underrun. *) function ThreshBottom(const Value: integer; Index, Len: integer): TMtxVecInt; overload; (*Perform threshold operation on all Src object values. Store the results in calling object. Size and properties of the calling object are adjusted automatically. *) function ThreshBottom(const Src: TMtxVecInt; const Value: integer): TMtxVecInt; overload; (*Perform a threshold operation on Vec elements [VecIndex]..[VecIndex+Len-1]. Store the results in the calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if is true and array borders are overrun/underrun. *) function ThreshBottom(const Vec: TMtxVecInt; const Value: integer; VecIndex, Index, Len: integer): TMtxVecInt; overload; (*Threshold top operation. Perform threshold operation on all calling object values. The Value parameter is an upper bound for threshold operation. All values bigger than Value will be replaced with Value. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TVecInt a; MtxVecInt.CreateIt(out a); try { a.SetIt(new int[] {2, 0, 3, 4}); a.ThreshTop(1); // a = [1, 0, 1, 1] } finally { MtxVec.FreeIt(ref a); } } } *) function ThreshTop(const Value: integer): TMtxVecInt; overload; (*Perfrom the threshold operation on calling object values [Index]..[Index+Len-1]. An exception is raised if array borders are overrun/underrun. *) function ThreshTop(const Value: integer; Index, Len: integer): TMtxVecInt; overload; (*Perform threshold operation on all Src object values. Store the results in calling object. Size and properties of the calling object are adjusted automatically. *) function ThreshTop(const Src: TMtxVecInt; const Value: integer): TMtxVecInt; overload; (*Perform a threshold operation Vec elements [VecIndex]..[VecIndex+Len-1]. Store the results in the calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if is true and array borders are overrun/underrun. *) function ThreshTop(const Vec: TMtxVecInt; const Value: integer; VecIndex, Index, Len: integer): TMtxVecInt; overload; (*Threshold top and bottom centered around zero. Perform threshold operation on all calling object values. The Value parameter is an upper bound for threshold operation. All values smaller than Value will be replaced with Value and all values bigger than -Value will be replaced with -Value. The comparison checks if abs(Values[i]) < Value. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TVecInt a; MtxVecInt.CreateIt(out a); try { a.SetIt(new int[] {2,-1,3,4}); a.ThreshAbsLT(2); // a = [2,-2,3,4] } finally { MtxVec.FreeIt(ref a); } } } *) function ThreshAbsLT(const Value: Integer): TMtxVecInt; overload; (*Perfrom the threshold operation on calling object values [Index]..[Index+Len-1]. An exception is raised if array borders are overrun/underrun. *) function ThreshAbsLT(const Value: Integer; Index, Len: integer): TMtxVecInt; overload; (*Perform threshold operation on all Src object values. Store the results in calling object. Size and properties of the calling object are adjusted automatically. *) function ThreshAbsLT(const Src: TMtxVecInt; const Value: Integer): TMtxVecInt; overload; (*Perform a threshold operation Vec elements [VecIndex]..[VecIndex+Len-1]. Store the results in the calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if is true and array borders are overrun/underrun. *) function ThreshAbsLT(const Vec: TMtxVecInt; const Value: Integer; VecIndex, Index, Len: integer): TMtxVecInt; overload; (*Threshold top and bottom centered around zero. Perform threshold operation on all calling object values. The Value parameter is an upper bound for threshold operation. All values bigger than Value will be replaced with Value and all values smaller than -Value will be replaced with -Value. The comparison checks if abs(Values[i]) > Value. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TVecInt a; MtxVec.CreateIt(out a); try { a.SetIt(new int[] {2, -1, 3, 4}); a.ThreshAbsGT(2); // a = [2, -1, 2, 2] } finally { MtxVec.FreeIt(ref a); } } } *) function ThreshAbsGT(const Value: Integer): TMtxVecInt; overload; (*Perfrom the threshold operation on calling object values [Index]..[Index+Len-1]. An exception is raised if array borders are overrun/underrun. *) function ThreshAbsGT(const Value: Integer; Index, Len: integer): TMtxVecInt; overload; (*Perform threshold operation on all Src object values. Store the results in calling object. Size and properties of the calling object are adjusted automatically. *) function ThreshAbsGT(const Src: TMtxVecInt; const Value: Integer): TMtxVecInt; overload; (*Perform a threshold operation Vec elements [VecIndex]..[VecIndex+Len-1]. Store the results in the calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if is true and array borders are overrun/underrun. *) function ThreshAbsGT(const Vec: TMtxVecInt; const Value: Integer; VecIndex, Index, Len: integer): TMtxVecInt; overload; (*Threshold greater than and less than operation. Perform operation on all calling object values. The LTValue parameter is an lower bound for threshold operation. The GTValue parameter is an upper bound for threshold operation. All values less than LTLevel will be replaced with LTValue. All values bigger than GTLevel will be replaced with GTValue. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TVecInt a; MtxVecInt.CreateIt(out a); try { a.SetIt(new int[] {20,1,30,40}); a.ThresholdGT_LT(23,34,10,5); // a = [20,5,34,34] } finally { MtxVecInt.FreeIt(ref a); } } } *) function ThresholdGT_LT (const GTLevel, GTValue, LTLevel, LTValue: Integer): TMtxVecInt; overload; (*Perfrom "greater than and less than" threshold operation on the calling object values in range [Index]..[Index+Len-1]. An exception is raised if array borders are overrun/underrun. *) function ThresholdGT_LT (const GTLevel, GTValue, LTLevel, LTValue: Integer; Index, Len: integer): TMtxVecInt; overload; (*Perform "greater than and less than" threshold operation on all Vec object values. Store the results in calling object. Size of the calling object is adjusted automatically. *) function ThresholdGT_LT (const Vec: TMtxVecInt; const GTLevel, GTValue, LTLevel, LTValue: Integer): TMtxVecInt; overload; (*Perform "greater than and less than" threshold operation on Vec elements from range [VecIndex]..[VecIndex+Len-1]. Store the results in the calling object elements [Index]..[Index+Len-1]. Size of the calling object must be set explicitly. An exception is raised if is true and array borders are overrun/underrun. *) function ThresholdGT_LT(const Vec: TMtxVecInt; const GTLevel, GTValue, LTLevel, LTValue: Integer; VecIndex, Index, Len: integer): TMtxVecInt; overload; (*Obtains a pointer to the integer value of the vector at Index. The function returns @Values[i]. Under .NET this is a pointer to unmanaged memory. *) function PValues(const Index: integer): PAPointer; (*Read values content from stream to object. Reads values content from SrcStream stream to calling objct. No other values describing the data type or length are read from the DstStream. Number type is defined by the Precision parameter, which can be obtained from method call. The function returns the number of bytes read. Note Use this method separately only, if you want user defined storage format. var b: TVecInt; AStream: TFileStream; Precision: TPrecision; begin CreateIt(b); AStream := TFileStream.Create('C:\test.bin',fmOpenRead); try Precision := b.ReadHeader(AStream); // Read info for b b.ReadValues(AStream,Precision); // Read values of b finally AStream.Free; FreeIt(b); end; end; *) function ReadValues(const SrcStream: TStream; const aPrecision: TPrecision = prInteger): Int64; overload; (*Writes object Values content to a stream. Writes the calling object Values content to the DstStream stream. No other values describing the data type or length are written to the DstStream. Number type is defined by the Precision parameter, but only integer formats are accepted. Attempt to save single (float) precision or double precision will raise an exception. The paramateres must be the same as for the method. Use this method separately only, if you want user defined storage format. var b: TVecInt; AStream: TFileStream; begin CreateIt(b); b.SetIt([0,0,1,3,2]); AStream := TFileStream.Create('C:\test.Vec',fmCreate); try b.WriteHeader(AStream); // Write info for b b.WriteValues(AStream); // Write values of b finally AStream.Free; end; FreeIt(b); end; *) procedure WriteValues(DstStream: TStream; const aPrecision: TPrecision = prInteger); overload; (*Writes the header information for the calling vector to a stream. Writes the header information for the calling object to a DstStream stream. The header information contains information about object (size, type of values in Values array, ...) which all define the state of the object. Number type is defined by the Precision parameter. Attempt to save single precision or double precision will raise an exception. var b: TVecInt; AStream: TFileStream; begin CreateIt(b); b.SetIt([0,0,1,3,2]); AStream := TFileStream.Create('C:\test.bin',fmCreate); try b.WriteHeader(AStream); // Write info for b b.WriteValues(AStream); // Write values of b finally AStream.Free; FreeIt(b); end; end; *) procedure WriteHeader(DstStream: TStream; const aPrecision: TPrecision = prInteger); overload; (*Reads the header information from a stream to object. Reads the header information from a DstStream stream to calling object. The header information contains all necessary information defining the object. The function returns the precision in which the data was stored. This information is required for the method. var b: TVecInt; AStream: TFileStream; Precision: TPrecision; begin CreateIt(b); AStream := TFileStream.Create('C:\test.bin',fmOpenRead); try Precision := b.ReadHeader(AStream); // Read info for b b.ReadValues(AStream,Precision); // Read values of b finally AStream.Free; FreeIt(b); end; end; *) function ReadHeader(const SrcStream: TStream): TPrecision; overload; (*Convert strings in aList to integers. Convert strings in aList to integers according to the IntPrecision property and store them in the Values array of the calling vector. The of the calling vector is set to aList.Count. var a,b: TVecInt; begin CreateIt(a,b); try a.SetIt([1,2,3,4]); a.Add(1) b.Size(a); b.SetVal(1); a.Add(b); Richedit1.Clear; Memo1.Clear; a.ValuesToStrings(Richedit1.Lines); b.ValuesToStrings(Richedit1.Lines); a.ValuesToStrings(Memo1.Lines); b.ValuesToStrings(Memo1.Lines); Memo1.Lines.SaveToFile('C:\Test.txt'); Memo1.Lines.LoadFromFile('C:\Test.txt'); a.StringsToValues(Memo1.Lines); finally FreeIt(a,b); end; end; *) procedure StringsToValues(const aList: TStrings); overload; (*Convert strings in aList to integers starting at ListIndex. Store them in the Values array of the calling vector from Index to Index+Len-1. The Length property of the calling vector is not changed. If array bounds are overrun and exception is raised. *) function StringsToValues(const aList: TStrings; const ListIndex: integer; const Index: integer = 0; const Len: integer = MtxVecEOA): TVecInt; overload; (*Converts the content of the Values array of the calling vector to a list of strings. Converts all elements of the calling vector to strings with specified formating and stores them in dstList, by using the Add method of TStrings object. Values are appended to existing content of dstList. Set Equidistant to True, if you are using fixed width font and need to have the text right aligned. Performance note: This routine will be exceedingly slow, if TRichEdit.Lines or TMemo.Lines are passed as a parameter for dstList. Use TStringList or StringList types and then call TMemo.Lines.AddStrings(yourList) for best results. procedure TForm1.Button1Click(Sender: TObject); var a,b: TVecInt; begin CreateIt(a,b); try a.SetIt([1,2,3,4]); a.Cos; b.Size(a); b.SetVal(1); a.Add(b); Richedit1.Clear; Memo1.Clear; a.ValuesToStrings(Richedit1.Lines); b.ValuesToStrings(Richedit1.Lines); a.ValuesToStrings(Memo1.Lines); b.ValuesToStrings(Memo1.Lines); Memo1.Lines.SaveToFile('C:\Test.txt'); Memo1.Lines.LoadFromFile('C:\Test.txt'); a.StringsToValues(Memo1.Lines); finally FreeIt(a,b); end; end; *) procedure ValuesToStrings(const dstList: TStrings; const Align: TFixedTextAlign = ftaNone; const Headers: boolean = false; const ColumnWidth: integer = -1); overload; (*Convert elements from Index to Index+Len-1 of the calling vector to strings. Store values in dstList starting at ListIndex. If dstList is not large enough, the method will use the add method of dstList object. Set Equidistant to True, if you are using fixed width font and need to have the text right aligned. *) procedure ValuesToStrings(const dstList: TStrings; ListIndex, Index, Len: integer; const Align: TFixedTextAlign = ftaNone; const Headers: boolean = false; const ColumnWidth: integer = -1); overload; (*Convert all vector elements to text.*) procedure ValuesToText(out AText: String); overload; (*Convert Index..Index+Len-1 vector elements to text.*) procedure ValuesToText(out AText: String; const Index, Len: integer); overload; (*Cumulative sum. Calculate the cumulative sum for calling object elements [Index]..[Index+Len-1] in-place. An exception is raised if is true and array borders are overrun. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TVecInt a; MtxVecInt.CreateIt(out a); try { a.SetIt(true,new double[] {1,2,3,4}); a.CumSum(); // a = [1,3,6,10] } finally { MtxVecInt.FreeIt(ref a); } } } *) function CumSum(Index, Len: Integer): TMtxVecInt; overload; (*Calculate the cumulative sum for Vec elements [VecIndex]..[VecIndex+Len-1]. Store the results in calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. Exception is raised if property is True and array borders are overrun. *) function CumSum(const Vec: TMtxVecInt; VecIndex,Index,Len: Integer): TMtxVecInt; overload; (*Cumulative sum. Calculate the cumulative sum for all calling object elements in-place. var a: TVecIn; begin CreateIt(a); try a.SetIt([1,2,3,4]); a.CumSum; // a = [1,3,6,10] finally FreeIt(a); end; end; *) function CumSum: TVecInt; overload; (*Calculate the cumulative sum for all Vec elements. Store the results in calling object. Size and properties of the calling object are set implicitly. *) function CumSum(const Vec: TVecInt): TVecInt; overload; (*Difference. Calculate the difference for Vec elements [VecIndex]..[VecIndex+Len-1] and store the results in the calling object elements [Index]..[Index+Len-1]. Size of the calling vector must be set explicitly. The following formula is used to calculate the difference: An exception is raised if is True and array borders are overrun or underrun. *) function Difference(const Vec: TMtxVecInt; VecIndex, Index, Len: integer): TMtxVecInt; overload; (*The difference between two succesive vector elements. Calculate the difference for all calling vector elements. The following formula is used to calculate the difference: The Length of calling vector is automatically decremented by one. *) function Difference(Lag: Integer = 1): TVecInt; overload; (*Calculate the difference for all Vec elements. Store the results in the calling vector. The of the calling vector is set to one less the length of Vec. *) function Difference(const Vec: TMtxVecInt; Lag: Integer = 1): TVecInt; overload; (*Returns content as a string. Values will be separated by line breaks. *) function ToString: string; (*Parses string content as vector. Values need to be separated by line breaks. For other parsing options call StringToValues. The Parse method works in pair with the ToString method both meant to be a reverse of the other, but do not preserve any other property of the vector except only values. Use SaveToStream/LoadFromStream methods for binary storage option, which uses up to 10x less memory and is a lot faster to save and load. *) class function Parse(const Src: string): VectorInt; static; public (*Allows sizing the internal storage to accomodate desired number of bits. Use BitPack and BitUnpack for much faster access to bit data or Bits[i] property for individual bit access. Setting BitCount will also call the Size method. The Length of the internal arrays will be adjusted so that all bits can be stored with padding of the last (32bit, 16bit or 8bit integer) element. The value of BitCount, which is not an integer multiple of the IntPrecision is preserved only by certain methods where applicable and where it is not ambiguous. The value of the property affects only the results of BitPack and BitUnpack routines. *) property BitCount: Int64 read get_BitCount write set_BitCount; (*Allows reading/writing individual bits of the array. Use BitPack and BitUnpack for much faster access to bit data. *) property Bits[const Indx: integer]: boolean read GetBits write SetBits; (* Returns data for inspection by the debugger. *) property IntegerValues: string read Get_IntegerValues; (* Specifies the power of two for the scale factor used by some methods.*) property ScaleFactor: integer read get_ScaleFactor write set_ScaleFactor; end; (*Integer vector class for operator overloading (Delphi 2006 and later). Declare VectorInt instead of TVecInt to take advantage ofoperator overloading. Be carefull to declare VectorInt only for local variables with short lifetime. Call the Create method for VectorInt, if the variable is a global variable or a variable with a longer life. It also makes sense to continue to use TVecInt for global vars. If the Create method (constuctor) is not called, the VectorInt record obtains TVecInt object from object cache (fastest create). If the Create mehod is called, the TVecInt object is created in the usual way (slower). Object cache has limited size. var b, c: VectorInt; bv: TVecInt; begin b := VectorInt(TIntegerArray.Create(1,1,1,1)); //b = [1,1,1,1]; bv := b; //b and bv point to same data object bv.Multiply(2); bv.Bits[76] := true; //set 76th bit in the array to 1 TVecInt(b).Multiply(2); //an alternative way to scale c := b*2 + 3; //c := b*2 + 2 + 3i c := b*bv; //mix VectorInt and TVecInt bv.Add(c); //pass VectorInt type and implicitely convert to TVecInt pointer b.PackBits(c); // store bit 1 in b for all elements in c which are different from zero. Bit 0 otherwise. end; *) MatrixInt = record strict private FData: TMtxInt; private function get_Data: TMtxInt ; property Data: TMtxInt read get_Data; private function get_BlockEnd: boolean; function get_IsSubRange: boolean; function get_Caption: string; function get_ConditionCheck: boolean; function get_Length: Integer; function get_Tag: Integer; procedure set_Caption(const value: string); procedure set_ConditionCheck(const value: boolean); procedure set_Length(const value: integer); procedure set_Tag(const value: Integer); procedure set_ScaleFactor(const value: integer); function get_ScaleFactor: integer; procedure set_IntPrecision(const value: TIntPrecision); function get_IntPrecision: TIntPrecision; function get_IntegerValues: string; function get_First: integer; function get_Last: integer; function get_IValues1D(const Indx: integer): integer; procedure set_IValues1D(const Indx: integer; const Value: integer); function get_SValues1D(const Indx: integer): SmallInt; procedure set_SValues1D(const Indx: integer; const Value: SmallInt); function get_BValues1D(const Indx: integer): Byte; procedure set_BValues1D(const Indx: integer; const Value: Byte); function get_IValues(const rowIdx, colIdx: integer): integer; procedure set_IValues(const rowIdx, colIdx: integer; const Value: integer); function get_SValues(const rowIdx, colIdx: integer): SmallInt; procedure set_SValues(const rowIdx, colIdx: integer; const Value: SmallInt); function get_BValues(const rowIdx, colIdx: integer): Byte; procedure set_BValues(const rowIdx, colIdx: integer; const Value: Byte); function GetSelect(const Indx, Len: integer): VectorInt; procedure SetSelect(const Indx, Len: integer; const Value: VectorInt); function GetSelectIndex(const startIndex, Step, stopIndex: integer): VectorInt; procedure SetSelectIndex(const startIndex, Step, stopIndex: integer; const Value: VectorInt); function GetSelect2D(const RowIdx, ColIdx, RowLen, ColLen: integer): MatrixInt; function GetSelectIndex2D(const StartRowIdx, StartColIdx, StopRowIdx, StopColIdx: integer): MatrixInt; procedure SetSelect2D(const RowIdx, ColIdx, RowLen, ColLen: integer; const Value: MatrixInt); procedure SetSelectIndex2D(const StartRowIdx, StartColIdx, StopRowIdx, StopColIdx: integer; const Value: MatrixInt); function get_Bits(const row, col: integer): boolean; procedure set_Bits(const row, col: integer; const Value: boolean); function get_ColsBitCount: integer; procedure set_ColsBitCount(const value: integer); procedure SetCols(const Value: integer); procedure SetLeadingCols(const Value: integer); procedure SetRows(const Value: integer); function GetCols: integer; function GetLeadingCols: integer; function GetRows: integer; function get_Capacity: Int64; procedure set_Capacity(const value: Int64); function get_CapacityStep: double; procedure set_CapacityStep(const value: double); public (*Returns number of values within the interval. Returns number of values which fullfill condition LowValue < Value[i] < HighValue. *) function CountInRange(const LowValue, HighValue: integer): integer; overload; (*Returns number of values within the interval. Returns number of values which fullfill condition LowValue < Value[i] < HighValue, for i traversing the range [Index]..[Index+Len-1] *) function CountInRange(const LowValue, HighValue: integer; const Index: integer; Len: integer): integer; overload; (*Cumulative sum. Calculate the cumulative sum for calling object elements [Index]..[Index+Len-1] in-place. An exception is raised if is true and array borders are overrun. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TVecInt a; MtxVecInt.CreateIt(out a); try { a.SetIt(true,new double[] {1,2,3,4}); a.CumSum(); // a = [1,3,6,10] } finally { MtxVecInt.FreeIt(ref a); } } } *) function CumSum(Index, Len: Integer): TMtxVecInt; overload; (*Calculate the cumulative sum for Vec elements [VecIndex]..[VecIndex+Len-1]. Store the results in calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. Exception is raised if property is True and array borders are overrun. *) function CumSum(const Vec: TMtxVecInt; VecIndex,Index,Len: Integer): TMtxVecInt; overload; (*Difference. Calculate the difference for Vec elements [VecIndex]..[VecIndex+Len-1] and store the results in the calling object elements [Index]..[Index+Len-1]. Size of the calling vector must be set explicitly. The following formula is used to calculate the difference: An exception is raised if is True and array borders are overrun or underrun. *) function Difference(const Vec: TMtxVecInt; VecIndex, Index, Len: integer): TMtxVecInt; overload; (*Adopts TMtxInt object. Src object will be adopted by MatrixInt. When the MatrixInt gets out of scope, the object will be freed. *) procedure Adopt(const Src: TMtxInt); overload; (*Defines a subarray. The method will define a sub array starting at BeginIndex and ending at EndIndex (inclusive). All values of the original MatrixInt will be preserved. An exception will be raised if an attempt is made to change the size of calling MatrixInt. A subarray is array which does not have its own memory allocated. Instead it adopts the memory of the source object and all operations done on the either of the objects affect the same elements. The use of subarrays increases CPU cache reuse, lower's memory requirements, increases application performance and improves code readability. Note To again obtain a view of the full Matrix see *) procedure SetSubIndex(BeginIndex, EndIndex: integer); overload; (*Resets any defined selection. *) procedure SelectAll; (*Prevents calls to . Prevents calls to method. This can be usefull guard when an object is already working on a subrange and the user would like to further subrange an already subranged object. When subranging matrices in-place, they are temporariliy converted to a vector by settings Rows to 1 and Cols to Length. var a: MatrixInt; b: VectorInt; begin a.SetIt(3,3, [1,2,3,4,5,6,7,8,9]); a.SetSubRange(0,2); //a = [1,2] a.DisableSubrange; a.SetSubRange(2,2); //exception raised here b.SetSubRange(a,2,2); //but this will work a.SetFullRange; //b is not changed, it still points to [4,5] end; *) procedure DisableSubrange; (*Enables calls to . Enables calls to by removing the block set by . *) procedure EnableSubrange; (*Prevents calls to . Prevents calls to method. This can be usefull guard when an object is already working on a subrange and the user would like to further subrange an already subranged object. var a: MatrixInt; b: VectorInt; begin a.SetIt(3,3,[1,2,3,4,5,6,7,8,9]); a.Select(0,2); //a = [1,2] a.DisableSelect; a.Select(2,2); //exception raised here b.Select(a,2,2); //but this will work a.SelectAll; //b is not changed, it still points to [4,5] end; *) procedure DisableSelect; (*Enables calls to . Enables calls to by removing the block set by . *) procedure EnableSelect; (*Returns true, if Left and Right are of equal Length and Values. var a,b: MatrixInt; c: TDoubleArray; begin c := TDoubleArray.Create(1,1,1,1,1,0); a.Size(3,3); a.CopyFromArray(c); b.Copy(a); if a = b then ERaise('a and b are equal!'); if a = 1 then ERaise('a equals 1!'); //compare to real value end; *) class operator Equal(const Left, Right: MatrixInt): Boolean; (*Returns true, if all elements of Left are equal to Right.*) class operator Equal(const Left: MatrixInt; const Right: integer): Boolean; (*Returns true, if all elements of Right are equal to Left.*) class operator Equal(const Left: integer;const Right: MatrixInt): Boolean; (*Returns true, if Left and Right have equal Rows, Cols, IntPrecision and Values.*) class operator Equal(const Left: TMtxInt; const Right: MatrixInt): Boolean; (*Returns true, if Left and Right have equal Rows, Cols, IntPrecision and Values.*) class operator Equal(const Left: MatrixInt; const Right: TMtxInt): Boolean; (*Returns true, if Left and Right are of equal Length, IntPrecision and Values.*) class operator Equal(const Left: TVecInt; const Right: MatrixInt): Boolean; (*Returns true, if Left and Right are of equal Length, IntPrecision and Values.*) class operator Equal(const Left: MatrixInt; const Right: TVecInt): Boolean; (*Returns true, if Left and Right are not equal. Returns true, if Left and Right do not have equal Length and Values. var a,b: MatrixInt; begin a := MatrixInt(TIntegerArray.Create(1,1,1,1,1)); if a <> b then ERaise('a and b are not equal!'); if a <> 1 then ERaise('a does not equals 1!'); //compare to integer value end; *) class operator NotEqual(const Left, Right: MatrixInt): Boolean; (*Returns true, if any elements of Left are not equal to Right.*) class operator NotEqual(const Left: MatrixInt; const Right: integer): Boolean; (*Returns true, if any elements of Right are not equal to Left.*) class operator NotEqual(const Left: integer;const Right: MatrixInt): Boolean; (*Returns true, if Left and Right do not have equal Rows, Cols, IntPrecision and Values.*) class operator NotEqual(const Left: TMtxInt; const Right: MatrixInt): Boolean; (*Returns true, if Left and Right do not have equal Rows, Cols, IntPrecision and Values.*) class operator NotEqual(const Left: MatrixInt; const Right: TMtxInt): Boolean; (*Returns true, if Left and Right do not have equal Length, IntPrecision and Values.*) class operator NotEqual(const Left: TVecInt; const Right: MatrixInt): Boolean; (*Returns true, if Left and Right do not have equal Length, IntPrecision and Values.*) class operator NotEqual(const Left: MatrixInt; const Right: TVecInt): Boolean; (*Returns true, if all elements of ALeft are smaller from ARight.*) class operator LessThan(const ALeft: MatrixInt; const ARight: integer): Boolean; (*Returns true, if ALeft is smaller from all elements in ARight.*) class operator LessThan(const ALeft: integer; const ARight: MatrixInt): Boolean; (*Returns true, if coresponding elements in ALeft are greater than coresponding elements in ARight.*) class operator LessThan(const ALeft: MatrixInt; const ARight: MatrixInt): Boolean; (*Returns true, if all elements of ALeft are smaller or equal from ARight.*) class operator LessThanOrEqual(const ALeft: MatrixInt; const ARight: integer): Boolean; (*Returns true, if ALeft is smaller or equal from all elements in ARight.*) class operator LessThanOrEqual(const ALeft: integer; const ARight: MatrixInt): Boolean; (*Returns true, if coresponding elements in ALeft are smaller than or equal from coresponding elements in ARight.*) class operator LessThanOrEqual(const ALeft: MatrixInt; const ARight: MatrixInt): Boolean; (*Returns true, if all elements of ALeft are greater or equal from ARight.*) class operator GreaterThanOrEqual(const ALeft: MatrixInt; const ARight: integer): Boolean; (*Returns true, if ALeft is greater or equal from all elements in ARight.*) class operator GreaterThanOrEqual(const ALeft: integer; const ARight: MatrixInt): Boolean; (*Returns true, if coresponding elements in ALeft are greater or equal from coresponding elements in ARight.*) class operator GreaterThanOrEqual(const ALeft: MatrixInt; const ARight: MatrixInt): Boolean; (*Returns true, if all elements of ALeft are greater from ARight.*) class operator GreaterThan(const ALeft: MatrixInt; const ARight: integer): Boolean; (*Returns true, if ALeft is greater from all elements in ARight.*) class operator GreaterThan(const ALeft: integer; const ARight: MatrixInt): Boolean; (*Returns true, if coresponding elements in ALeft are greater than coresponding elements in ARight.*) class operator GreaterThan(const ALeft: MatrixInt; const ARight: MatrixInt): Boolean; (*Add Left to all elements in Right and return result.*) class operator Add(const Left: integer;const Right: MatrixInt): MatrixInt; (*Add Right to all elements in Left and return result.*) class operator Add(const Left: MatrixInt; const Right: integer): MatrixInt; (*Add coresponding elements in Left and Right.*) class operator Add(const Left: TMtxInt; const Right: MatrixInt): MatrixInt; (*Add coresponding elements in Left and Right.*) class operator Add(const Left: MatrixInt; const Right: TMtxInt): MatrixInt; (*Add coresponding elements in Left and Right.*) class operator Add(const Left: MatrixInt;const Right: MatrixInt): MatrixInt; (*Subtract all elements in Right from Left.*) class operator Subtract(const Left: integer; const Right: MatrixInt): MatrixInt; (*Subtract Right from all elements in Left.*) class operator Subtract(const Left: MatrixInt; const Right: integer): MatrixInt; (*Subtract coresponding elements in Right from Left.*) class operator Subtract(const Left: MatrixInt; const Right: TMtxInt): MatrixInt; (*Subtract coresponding elements in Right from Left.*) class operator Subtract(const Left: TMtxInt; const Right: MatrixInt): MatrixInt; (*Subtract coresponding elements in Right from Left.*) class operator Subtract(const Left: MatrixInt;const Right: MatrixInt): MatrixInt; (*Multiply all elements in Left with Right.*) class operator Multiply(const Left: MatrixInt; const Right: integer): MatrixInt; (*Multiply all elements in Right with Left.*) class operator Multiply(const Left: integer; const Right: MatrixInt): MatrixInt; (*Multiply all elements in Left with corresponding elements in Right.*) class operator Multiply(const Left: MatrixInt; const Right: TMtxInt): MatrixInt; (*Multiply all elements in Left with corresponding elements in Right.*) class operator Multiply(const Left: TMtxInt; const Right: MatrixInt): MatrixInt; (*Multiply all elements in Left with corresponding elements in Right.*) class operator Multiply(const Left: MatrixInt; const Right: MatrixInt): MatrixInt; (*Divide all elements in Left with Right.*) class operator Divide(const Left: MatrixInt; const Right: integer): MatrixInt; (*Divide Left with all elements Right.*) class operator Divide(const Left: integer; const Right: MatrixInt): MatrixInt; (*Divide all elements in Left with coresponding elements in Right.*) class operator Divide(const Left: MatrixInt; const Right: TMtxInt): MatrixInt; (*Divide all elements in Left with coresponding elements in Right.*) class operator Divide(const Left: TMtxInt; const Right: MatrixInt): MatrixInt; (*Divide all elements in Left with coresponding elements in Right.*) class operator Divide(const Left: MatrixInt; const Right: MatrixInt): MatrixInt; (*Negates all values inside AValue.*) class operator Negative(const AValue: MatrixInt): MatrixInt; (*Explicitely convert array of complex values to MatrixInt. Copies all values from the complex array to the result with precision set at 32bit signed integer. *) class operator Explicit(const AValue: TCplxArray): MatrixInt; (*Explicitely convert array of double values to MatrixInt. Copies all values from the double array to the result with precision set at 32bit signed integer; *) class operator Explicit(const AValue: TDoubleArray): MatrixInt; (*Explicitely convert array of single values to MatrixInt. Copies all values from the AValue array to the result with precision set at 32bit signed integer. *) class operator Explicit(const AValue: TSingleArray): MatrixInt; (*Explicitely convert TMtxVec to MatrixInt. Copies all values from AValue to the result with precision set at 32bit signed integer. *) class operator Explicit(const AValue: TMtxVec): MatrixInt; (*Explicitely convert MatrixInt to array of doubles. Copies all values from AVector to an array of double. *) class operator Explicit(const AValue: MatrixInt): TDoubleArray; (*Explicitely convert MatrixInt to array of doubles. Copies all values from AVector to an array of single. *) class operator Explicit(const AValue: MatrixInt): TSingleArray; (*Explicitely convert MatrixInt to array of integer. Copies all values from AVector to an array of 32bit signed integers. If Precision does not match conversion will be performed. *) class operator Explicit(const AValue: MatrixInt): TIntegerArray; (*Explicitely convert MatrixInt to array of integer. Copies all values from AVector to an array of 16bit signed integers. If Precision does not match conversion will be performed. *) class operator Explicit(const AValue: MatrixInt): TSmallIntArray; (*Explicitely convert MatrixInt to array of integer. Copies all values from AVector to an array of 16bit signed integers. If Precision does not match conversion will be performed. *) class operator Explicit(const AValue: MatrixInt): Math387.TByteArray; (*Implicit type conversion from MatrixInt to an array of 32bit signed integer. Returns a pointer to the internal array of values. If the Precision does not match an exception will be raised. *) class operator Implicit(const AValue: MatrixInt): TIntegerArray; (*Implicit type conversion from MatrixInt to an array of 32bit signed integer. Returns a pointer to the internal array of values. If the Precision does not match an exception will be raised. This conversion avoids all range checking, which would be broken, if MatrixInt.IsSubRange = True. PInteger type is also defined in Windows.pas unit and sometimes the type needs to be specified with the unit name (Math387.PInteger) for this overload to work. *) class operator Implicit(const AValue: MatrixInt): Math387.PInteger; (*Implicit type conversion from MatrixInt to an array of 16bit signed integer. Returns a pointer to the internal array of values. If the Precision does not match an exception will be raised. *) class operator Implicit(const AValue: MatrixInt): TSmallIntArray; (*Implicit type conversion from MatrixInt to an array of 16bit signed integer. Returns a pointer to the internal array of values. If the Precision does not match an exception will be raised. This conversion avoids all range checking, which would be broken, if MatrixInt.IsSubRange = True. *) class operator Implicit(const AValue: MatrixInt): Math387.PSmallInt; (*Implicit type conversion from MatrixInt to an array of 8bit unsigned integer. Returns a pointer to the internal array of values. If the Precision does not match an exception will be raised. *) class operator Implicit(const AValue: MatrixInt): Math387.TByteArray; (*Implicit type conversion from MatrixInt to an array of 8bit unsigned integer. Returns a pointer to the internal array of values. If the Precision does not match an exception will be raised. This conversion avoids all range checking, which would be broken, if MatrixInt.IsSubRange = True. *) class operator Implicit(const AValue: MatrixInt): Math387.PByte; (*Implicit type conversion from MatrixInt to TMtxInt. Returns a pointer to the internal TMtxInt object. *) class operator Implicit(const AValue: MatrixInt): TMtxInt; (*Implicit type conversion from MatrixInt to TMtxInt. Returns a pointer to the internal TMtxInt object. *) class operator Implicit(const AValue: MatrixInt): TMtxVecInt; (*Implicit type conversion from MatrixInt to TMtxInt. Returns a pointer to the internal TMtxInt object. *) class operator Implicit(const AValue: MatrixInt): TMtxVecBase; (*Implicit type conversion from MatrixInt to TMtxInt. Returns a pointer to the internal TMtxInt object. *) class operator Implicit(const AValue: MatrixInt): TObject; (*Computes bitwise "and" between Left and right.*) class operator BitwiseAnd(const Left: TMtxInt; const Right: MatrixInt): MatrixInt; (*Computes bitwise "and" between Left and right.*) class operator BitwiseAnd(const Left: MatrixInt; const Right: TMtxInt): MatrixInt; (*Computes bitwise "and" between Left and right.*) class operator BitwiseAnd(const Left: MatrixInt; const Right: MatrixInt): MatrixInt; (*Computes logical "and" between Left and right.*) class operator LogicalAnd(const Left: TMtxInt; const Right: MatrixInt): MatrixInt; (*Computes logical "and" between Left and right.*) class operator LogicalAnd(const Left: MatrixInt; const Right: TMtxInt): MatrixInt; (*Computes logical "and" between Left and right.*) class operator LogicalAnd(const Left: MatrixInt; const Right: MatrixInt): MatrixInt; (*Computes logical "or" between Left and right.*) class operator LogicalOr(const Left: TMtxInt; const Right: MatrixInt): MatrixInt; (*Computes logical "or" between Left and right.*) class operator LogicalOr(const Left: MatrixInt; const Right: TMtxInt): MatrixInt; (*Computes logical "or" between Left and right.*) class operator LogicalOr(const Left: MatrixInt; const Right: MatrixInt): MatrixInt; (*Computes bitwise "or" between Left and right.*) class operator BitwiseOr(const Left: TMtxInt; const Right: MatrixInt): MatrixInt; (*Computes bitwise "or" between Left and right.*) class operator BitwiseOr(const Left: MatrixInt; const Right: TMtxInt): MatrixInt; (*Computes bitwise "or" between Left and right.*) class operator BitwiseOr(const Left: MatrixInt; const Right: MatrixInt): MatrixInt; (*Performs bitwise left shift of aValue.*) class operator LeftShift(const aValue: MatrixInt; Bits: integer): MatrixInt; (*Performs bitwise right shift of aValue. The shift preserves the sign of the numbers. *) class operator RightShift(const aValue: MatrixInt; const Bits: integer): MatrixInt; (*Performs logical "xor" between Left and Right.*) class operator BitwiseXor(const Left: TMtxInt; const Right: MatrixInt): MatrixInt; (*Performs logical "xor" between Left and Right.*) class operator BitwiseXor(const Left: MatrixInt; const Right: TMtxInt): MatrixInt; (*Performs logical "xor" between Left and Right.*) class operator BitwiseXor(const Left: MatrixInt; const Right: MatrixInt): MatrixInt; (*Performs logical (and bitwise) "not" on the Value.*) class operator LogicalNot(const Value: MatrixInt): MatrixInt; procedure CreateFromCache(Value: boolean); (*Constructor of the record. Returns a Vector with internal TMtxInt object created explicitely with Length property set to aLength and IntPrecision property set to int32. Call this constructor, if the Vector type variable is a global variable with a long life span. var a,b: MatrixInt; bvec: TMtxInt; begin a := MatrixInt.Create(true); //create from object cache via CreateIt //this constructor can be omitted, because it is implicitly called //the first time that the variable is used. //However: b := MatrixInt.Create(10); //Similar to bvec := TMtxInt.Create; try bvec.Size(10); finally bvec.Free; //b is freed on the exit from the procedure end; end; *) constructor Create(const aRows, aCols: integer); overload; (*Internally creates TMtxInt object without using object cache. Creates TMtxInt object without using object cache. Suitable for declaring global variables. *) constructor Create(const aRows, aCols: integer; const aPrecision: TIntPrecision); overload; (*Uses TMtxInt object as internal storage. The resulting Vector will own Src object of TMtxInt type and will release it once Vector gets out of scope. *) constructor Create(const Src: TMtxInt); overload; (*Constructor of the record. Returns a Vector with internal TMtxInt object created from object cache (CreateIt), if FromObjectCache is True. Pass false to the constructor or do not call it at all, if the variable is a local variable. Object cache has limited size. *) constructor Create(FromObjectCache: boolean); overload; public (*Defines the length in number of samples. Defines the number of samples that the Vector can store. The length property does not map directly to memory reallocation when it is changed. Until the amount of preallocated memory is not exceed, there is no reallocation going on. Changing the Length property will preserve the existing values, but only if the new property value is smaller than the amount of preallocated memory. To properly resize the memory allocated use the method. It is recommended that vector sizes do not exceed the size of preallocated memory to increase overall performance. The size of preallocated memory can be controlled via the Controller global variable which is defined in the MtxVec unit. *) property Length: integer read get_Length write set_Length; (*Enables/disable inline condition checking. Enables/disables inline condition checking. When true, TMtxInt methods perform additional (range) checking before operations are executed. The drawback is slight loss of speed. This speeds up the execution but disables some safeguards. For short vectors the loss of speed can be significant. Some methods (parameterless) don't use the ConditionCheck property at all. ConditionCheck property is initially True. This property is an additional safeguard against array overrun or underrun errors. It allows to work with explicit range checking while writing and debugging the application and once your code is running you can turn it off. By functionality it is similar to assertions. (See Assert Delphi procedure). *) property ConditionCheck: boolean read get_ConditionCheck write set_ConditionCheck; (*Vector Caption. Use this property to set/get the string caption for the MatrixInt. This can be usefull for associating description with data when making a user interface. *) property Caption: string read get_Caption write set_Caption; (*Stores an integer value as a part of the object. Tag has no predefined meaning. The Tag property is provided for the convenience of developers. It can be used for storing an additional integer value or it can be typecast to any 32-bit value such as a component reference or even a pointer. *) property Tag: Integer read get_Tag write set_Tag; (*Sizing the object will not allocate less than Capacity samples. To free memory allocated before, first set Capacity to 0. *) property Capacity: Int64 read get_Capacity write set_Capacity; (*Specifies increment step for the Capacity property. If this property is 0, the Capacity will never be modified on its own. When the value 1, the capacity will continue increasing to match largest value requested. When the value is more than 1, the capacity will be increasing with the factor specified. *) property CapacityStep: double read get_CapacityStep write set_CapacityStep; public (*Obtains a pointer to the integer value of the vector at Index. The function returns @IValues[i]. Under .NET this is a pointer to unmanaged memory or pinned managed memory. *) function PIValues(const Index: integer): PPInteger; overload; (*Obtains a pointer to the integer value of the vector at Index. The function returns @SValues[i]. Under .NET this is a pointer to unmanaged memory or pinned managed memory. *) function PSValues(const Index: integer): PPSmallInt; overload; (*Obtains a pointer to the integer value of the vector at Index. The function returns @BValues[i]. Under .NET this is a pointer to unmanaged memory or pinned managed memory. *) function PBValues(const Index: integer): PPByte; overload; (*Returns a pointer to the real value stored at Row and Col.*) function PIValues(const Row, Col: integer): PPInteger; overload; (*Returns a pointer to the real value stored at Row and Col.*) function PSValues(const Row, Col: integer): PPSmallInt; overload; (*Returns a pointer to the real value stored at Row and Col.*) function PBValues(const Row, Col: integer): PPByte; overload; (* Defines internal storage precision which can be either 32, 16 or 8 bit.*) property IntPrecision: TIntPrecision read get_IntPrecision write set_IntPrecision; (*Returns true, if the currrent subrange of the vector was also the last subrange in the MatrixInt. Returns true, if the currrent subrange of the vector was also the last subrange in the MatrixInt. This property be used together with and . *) property BlockEnd: boolean read Get_BlockEnd; (*Set to true after the SetSubIndex or SetSubRange call. This property is set to true after the or call. If IsSubRange is true then the TMtxInt method/function will be performed on subrange of values. Use to set IsSubRange back to False and thus reset sub range to full vector length. *) property IsSubRange: boolean read get_IsSubRange; (*Allows setting/getting the signed 32bit integer value at position Indx. Allows setting/getting the real value at position Indx. This property reads/writes to the same memory as and properties. *) property IValues[const rowIdx, colIdx: integer]: integer read get_IValues write set_IValues; default; (*Allows setting/getting the signed 16bit integer value at position Indx. Allows setting/getting the signed 16bit integer value at position Indx. This property reads/writes to the same memory as and properties. *) property SValues[const rowIdx, colIdx: integer]: smallint read get_SValues write set_SValues; (*Allows setting/getting the 8bit unsigned integer value at position Indx. Allows setting/getting the 8bit unsigned integer value at position Indx. This property reads/writes to the same memory as and properties. *) property BValues[const rowIdx, colIdx: integer]: byte read get_BValues write set_BValues; (*Allows setting/getting the signed 32bit integer value at position Indx. Allows setting/getting the real value at position Indx. This property reads/writes to the same memory as and properties. *) property IValues1D[const Indx: integer]: integer read get_IValues1D write set_IValues1D; (*Allows setting/getting the signed 16bit integer value at position Indx. Allows setting/getting the signed 16bit integer value at position Indx. This property reads/writes to the same memory as and properties. *) property SValues1D[const Indx: integer]: smallint read get_SValues1D write set_SValues1D; (*Allows setting/getting the 8bit unsigned integer value at position Indx. Allows setting/getting the 8bit unsigned integer value at position Indx. This property reads/writes to the same memory as and properties. *) property BValues1D[const Indx: integer]: byte read get_BValues1D write set_BValues1D; (*Allows copying/assignment of subranges. Reading this property will return a sub-ranged Vector. Similar to calling b.SetSubRange(a, Indx, Len); Writing this property will copy source to the specified subrange. The size of the value being assigned needs to match the range specified. *) property Select[const Indx, Len: integer]: VectorInt read GetSelect write SetSelect; (*Allows copying/assignment of subranges. Reading this property will return a copied selection of subranged VectorInt by calling Dst.GatherByIncr(Src, startIndex, Step); Writing this property will copy source to the specified range by using Data.ScatterByIncr. The size of the value being assigned needs to match the index range specified. This property does not obtain a "view" unless Step equals to 1. *) property SelectIndex[const startIndex, Step, stopIndex: integer]: VectorInt read GetSelectIndex write SetSelectIndex; (*Allows copying/assignment of subranges. Reading this property will copy MatrixInt from the specified location. Writing this property will copy the Source to the specified location. This property does not obtain a "view". *) property Select2D[const RowIdx, ColIdx, RowLen, ColLen: integer]: MatrixInt read GetSelect2D write SetSelect2D; (*Allows copying/assignment of subranges. Reading this property will copy MatrixInt from the specified location. Writing this property will copy the Source to the specified location. This property does not obtain a "view". *) property SelectIndex2D[const StartRowIdx, StartColIdx, StopRowIdx, StopColIdx: integer]: MatrixInt read GetSelectIndex2D write SetSelectIndex2D; procedure AssignWithoutCopy(const Src: MatrixInt); procedure Assign(const Src: MatrixInt); (*Initializes block processing. Initializes block processing. Because the size of the CPU cache is limited, significant performance gains can be obtained by splitting long vectors in to a series of short ones, which can all fit in the CPU cache entirely. The BlockInit method is to be used together with and methods to initialize a block processing while loop. BlockInit will call to obtain subrange of the data in TMtxInt. The of the subranged vector is determined by the global variable declared in unit. Default value of MtxVecBlockSize is preset to 800 vector elements for double precision and 1600 elements for single precision. BlockInit supports nested calls and from witihin a blocked while loop you can call procedures and functions which are also blocked. If you use block processing, typical performance gains will range from 2 to a maximum of 6. Block processing can not be used, or it is difficult to apply, in cases where vector elements are not independent of each other. The block processing while loop must be written like this: a.BlockInit; while not A.BlockEnd do begin // .... user defined function a.BlockNext; end; The differences with block processing will be more noticable on older CPU's without support for SSE2/SSE3/SSE4/AVX when using FPU instructions. *) procedure BlockInit; overload; (*Initializes block processing with specified ABLockSize.*) procedure BlockInit(ABlockSize: integer); overload; (*Initializes block processing.*) procedure BlockInit(const Src: TMtxVecInt); overload; (*Initializes block processing. Block processing can be applied on possibly already subranged Src object. Src may not be freed or go out of scope until block processing loop has finished. There would be no error raised other than AV. *) procedure BlockInit(const Src: TMtxVecInt; ABlockSize: integer); overload; (*Obtains the next subrange of the data. Obtains the next subrange of the data in TMtxInt. The routine must be used together with and methods. *) procedure BlockNext; (*Deinitializes block processing before the final block is processed. Call this routine before breaking out of a while-loop prematurely. Vec.BlockInit While not Vec.BlockEnd do Begin If Vec.Min < 0 then //check some condition, if you need to exit begin Vec.BlockFinish; //finish the loop Break; //and break out end; Vec.BlockNext; end *) procedure BlockFinish; (*First element in object Values array. first integer element in object Values array. *) property First: integer read get_First; (*Last element in object Values array. the last integer element in calling object Values array. *) property Last: integer read get_Last; (*Sets the size of the vector to match an array. Sets the Length of the calling vector to match the length of the array. *) procedure SizeFromArray(const Src: T2DIntegerArray); overload; (*Sets the size of the vector to match an array. Sets the Length of the calling vector to match the length of the array. *) procedure SizeFromArray(const Src: T2DSmallIntArray); overload; (*Sets the size of the vector to match an array. Sets the size (Length) of the caling vector to match the length of the array. *) procedure SizeFromArray(const Src: Math387.T2DByteArray); overload; (*Sizes complex array.*) procedure SizeToArray(var Dst: TCplxArray); overload; (*Sizes double precision array.*) procedure SizeToArray(var Dst: TDoubleArray); overload; (*Size single precision array.*) procedure SizeToArray(var Dst: TSingleArray); overload; (*Sizes 4 byte signed integer array.*) procedure SizeToArray(var Dst: TIntegerArray); overload; (*Sizes 2 byte unsigned integer array.*) procedure SizeToArray(var Dst: Math387.TWordArray); overload; (*Sizes 2 byte signed integer array.*) procedure SizeToArray(var Dst: TSmallIntArray); overload; (*Sizes 1 byte unsigned integer array.*) procedure SizeToArray(var Dst: Math387.TByteArray); overload; (*Resets any defined subrange. *) procedure SetFullRange; (*Resets last defined subrange and pops the subrange stack. *) procedure SetFullRangeLevel; (*Defines a sub vector/matrix. The method will define a subarray starting at Index and ending at Index+Len-1. No copying will occur, only pointers will be shifted. All values of the original will be preserved. An exception will be raised if an attempt is made to change the size of calling object. A sub-vector/matrix is vector/matrix which does not neccessarily have its own memory allocated. Instead it adopts the memory of the source object and all operations done on the either of the objects affect the same elements. The use of subvectors/submatrices increases CPU cache reuse, lower's memory requirements, increases application performance and improves code readability. Note To again obtain a view of the full vector/matrix, see *) procedure SetSubRange(const Index: integer; const Len: integer); overload; (*Defines a sub vector/matrix and pushes any previous subranges on to a stack. The method will define a subarray starting at Index and ending at Index+Len-1. No copying will occur, only pointers will be shifted or indices adjusted. The routine allows for stack based pushing and poping of sub-ranges with the additional constraint that each deepening of the sub-range is strictly within the bounds of the previous one. The pairs of SetSubRangeLevel/SetFullRangeLevel need to match. All values of the original will be preserved. An exception will be raised, if an attempt is made to change the size of calling object. It is possible to call SetSubRange/SetFullRange on the object, which has been subranged with SetSubRangeLevel. To again obtain a view of the previous subrange level on the vector/matrix, call The Index parameter of the SetSubRange is absolute for the original memory or current stack level. The Index parameter for the SetSubRangeLevel is relative to the previous SetSubRangeLevel call. *) procedure SetSubRangeLevel(const Index: integer; const Len: integer); overload; (*Define a subvector of the Src vector. The method will define a subarray starting at Index and ending at Index+Len-1 of Src. No copying will occur, only pointers will be shifted or indices adjusted. A sub-vector/matrix is vector/matrix which does not neccessarily have its own memory allocated. Instead it adopts the memory of the source object and all operations done on the either of the objects affect the same elements. The use of subvectors/submatrices increases CPU cache reuse, lower's memory requirements, increases application performance and improves code readability. All values of the original will be preserved. An exception will be raised, if an attempt is made to change the size of calling object. No exception will be raised, if Src is resized while subranged. (possibly leading to memory overwrites) To again obtain a view of the original vector/matrix, call *) procedure SetSubRange(const Src: TMtxVecInt; const Index: integer; const Len: integer = MtxVecEOA); overload; (*Defines a sub vector/matrix. The method will define a subarray starting at Index and ending at Index + (aRows*aCols)-1. No copying will occur, only pointers will be shifted or indices adjusted. The subranged matrix will have the size aRows and aCols. Length will be equal to aRows*aCols. All values of the original will be preserved. An exception will be raised if an attempt is made to change the size of calling object. A sub-vector/matrix is vector/matrix, which does not have its own memory allocated. Instead it adopts the memory of the source object and all operations done on either of the objects affect the same elements. The use of subvectors/submatrices increases CPU cache reuse, lower's memory requirements, increases application performance and improves code readability. To again obtain a view of the full vector/matrix, see The routine only makes sense to be used where aCols matches Src.Cols. MtxVec has only limited support for matrices where the matrix rows are not stored strictly consecutively. This overload is to be used with great caution. The routine should not be mixed with other SetSubRange routines or subrange stack. *) procedure SetSubRange(const Src: TMtxVecInt; Index: integer; aRows, aCols: integer); overload; (*Defines a sub vector/matrix of Src and pushes any previous subranges on to a stack. The method will define a subarray starting at Index and ending at Index+Len-1 of Src. No copying will occur, only pointers will be shifted or indices adjusted. The routine allows for stack based pushing and poping of sub-ranges with the additional constraint that each deepening of the sub-range is strictly within the bounds of the previous one. The pairs of SetSubRangeLevel/SetFullRangeLevel need to match. All values of the original will be preserved. An exception will be raised, if an attempt is made to change the size of calling object. No exception will be raised, if Src is resized while subranged. (possibly leading to memory overwrites) It is possible to call SetSubRange/SetFullRange on the object, which has been subranged with SetSubRangeLevel. To again obtain a view of the previous subrange level on the vector/matrix, call The Index parameter of the SetSubRange is always relative to the previous, if any, stack level. The Index parameter for the SetSubRangeLevel is relative to the current stack level. *) procedure SetSubRangeLevel(const Src: TMtxVecInt; const Index: integer; const Len: integer = MtxVecEOA); overload; (*Sets the subarray size to full size. This method is the same as the method. *) procedure SetSubRange; overload; (*Sets vector size to zero. Calling Clear sets property to 0. *) procedure Clear; (*Saves the current value of ConditionCheck property and sets it to false. You can restore back to the original setting by calling method. *) procedure CondDisable; (*Sets the ConditionCheck property to whatever it was before the CondDisable was used. Sets the property to whatever it was before the was used. *) procedure CondEnable; (*Absolute values. Calculate the absolute value of all calling object elemets in-place. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TMtxInt a; MtxVecInt.CreateIt(out a); try { a.SetIt(new int[] {1,-2,3,4}); a.Abs(); // a = [1,2,3,4] } finally { MtxVecInt.FreeIt(ref a); } } } *) function Abs(): TMtxVecInt; overload; (*Absolute values of calling object elements [Index]..[Index+Len-1]. calling vector elements [Index]..[Index+Len-1] ansolute vslues. An exception is raised if array borders are overrun/underrun. Note Please note the calling vector elements [Index]..[Index+Len-1] are overwritten with result of routine call. *) function Abs(const Index, Len: integer): TMtxVecInt; overload; (*Absolute values of all Src vector elements. Src vector elements ansolute vslues.*) function Abs(const Src: TMtxVecInt): TMtxVecInt; overload; (*Absolute values of Src vector elements [VecIndex]..[VecIndex+Len-1]. Src vector elements [VecIndex]..[VecIndex+Len-1] absolute values in calling vector elements [Index]..[Index+Len-1]. An exception is raised if array borders are overrun/underrun. Note Please note the calling vector elements [Index]..[Index+Len-1] are overwritten with result of routine call. *) function Abs(const Src: TMtxVecInt; const SrcIndex, Index, Len: integer): TMtxVecInt; overload; (*Apply binary "and" between coresponding elements in Src1 and Src2. the result of binary "and" of Src1 values with coresponding Src2 values stored in the calling object.*) function BinaryAnd(const Src1, Src2: TMtxVecInt): TMtxVecInt; overload; (* Apply binary "and" between coresponding elements in Src1 and Src2. the result of binary "and" of Src1 values [SrcIndex1]..[SrcIndex1+Len-1] with coresponding Src2 values [SrcIndex2]..[SrcIndex2+Len-1] stored in the calling object at locations [Index]..[Index+Len-1]. *) function BinaryAnd(const Src1, Src2: TMtxVecInt; const SrcIndex1, SrcIndex2, Index, Len: integer): TMtxVecInt; overload; (*Apply binary "and" between coresponding elements in Src and Self. the result of binary "and" of Src values with coresponding values in Self (this).*) function BinaryAnd(const Src: TMtxVecInt): TMtxVecInt; overload; (*Apply binary "and" between coresponding elements in Src and Self. the result of binary "and" of Src values [SrcIndex]...[SrcIndex+Len-1] with coresponding values in Self (this) [Index]..[Index+Len-1].*) function BinaryAnd(const Src: TMtxVecInt; const SrcIndex, Index, Len: integer): TMtxVecInt; overload; (*Apply binary "and" between elements in Src and Value. the result of binary "and" of Value with coresponding values in Src [SrcIndex]..[SrcIndex+Len-1] stored in the calling object at locations [Index]..[Index+Len-1].*) function BinaryAnd(const Src: TMtxVecInt; const Value, SrcIndex, Index, Len: integer): TMtxVecInt; overload; (*Apply binary "and" between elements in the calling object and Value. the result of binary "and" between Value and values in the calling object.*) function BinaryAnd(const Value: integer): TMtxVecInt; overload; (*Apply binary "and" between elements in the calling object and Value. the result of binary "and" between Value and values in the calling object at locations [Index]..[Index+Len-1].*) function BinaryAnd(const Value, Index, Len: integer): TMtxVecInt; overload; (*Apply binary "and" between elements in Src and Value. the result of binary "and" of Value with coresponding values in Src stored in the calling object.*) function BinaryAnd(const Src: TMtxVecInt; const Value: integer): TMtxVecInt; overload; (*Apply binary "or" between coresponding elements in Src1 and Src2. the result of binary "and" of Src1 values with coresponding Src2 values stored in the calling object.*) function BinaryOr(const Src1, Src2: TMtxVecInt): TMtxVecInt; overload; (* Apply binary "or" between coresponding elements in Src1 and Src2. the result of binary "or" of Src1 values [SrcIndex1]..[SrcIndex1+Len-1] with coresponding Src2 values [SrcIndex2]..[SrcIndex2+Len-1] stored in the calling object at locations [Index]..[Index+Len-1]. *) function BinaryOr(const Src1, Src2: TMtxVecInt; const SrcIndex1, SrcIndex2, Index, Len: integer): TMtxVecInt; overload; (*Apply binary "or" between coresponding elements in Src and Self. the result of binary "or" of Src values with coresponding values in Self (this).*) function BinaryOr(const Src: TMtxVecInt): TMtxVecInt; overload; (*Apply binary "or" between coresponding elements in Src and Self. the result of binary "or" of Src values [SrcIndex]...[SrcIndex+Len-1] with coresponding values in Self (this) [Index]..[Index+Len-1].*) function BinaryOr(const Src: TMtxVecInt; const SrcIndex, Index, Len: integer): TMtxVecInt; overload; (*Apply binary "or" between elements in Src and Value. the result of binary "or" of Value with coresponding values in Src [SrcIndex]..[SrcIndex+Len-1] stored in the calling object at locations [Index]..[Index+Len-1].*) function BinaryOr(const Src: TMtxVecInt; const Value, SrcIndex, Index, Len: integer): TMtxVecInt; overload; (*Apply binary "or" between elements in Src and Value. the result of binary "or" of Value with coresponding values in Src stored in the calling object.*) function BinaryOr(const Src: TMtxVecInt; const Value: integer): TMtxVecInt; overload; (*Apply binary "or" between elements in the calling object and Value. the result of binary "or" between Value and values in the calling object at locations [Index]..[Index+Len-1] stored back in the calling object.*) function BinaryOr(const Value, Index, Len: integer): TMtxVecInt; overload; (*Apply binary "or" between elements in the calling object and Value. the result of binary "or" between Value and values in the calling object.*) function BinaryOr(const Value: integer): TMtxVecInt; overload; (*Apply binary "xor" between elements in the calling object and Value. the result of binary "xor" between Value and values in the calling object.*) function BinaryXor(const Value: integer): TMtxVecInt; overload; (*Apply binary "xor" between elements in the calling object and Value. the result of binary "xor" between Value and values in the calling object at locations [Index]..[Index+Len-1] stored back in the calling object.*) function BinaryXor(const Value, Index, Len: integer): TMtxVecInt; overload; (*Apply binary "xor" between elements in Src and Value. the result of binary "xor" of Value with coresponding values in Src stored in the calling object.*) function BinaryXor(const Src: TMtxVecInt; const Value: integer): TMtxVecInt; overload; (*Apply binary "xor" between elements in Src and Value. the result of binary "xor" of Value with coresponding values in Src [SrcIndex]..[SrcIndex+Len-1] stored in the calling object at locations [Index]..[Index+Len-1].*) function BinaryXor(const Src: TMtxVecInt; const Value, SrcIndex, Index, Len: integer): TMtxVecInt; overload; (*Apply binary "xor" between coresponding elements in Src1 and Src2. the result of binary "xor" of Src1 values with coresponding Src2 values stored in the calling object.*) function BinaryXor(const Src1, Src2: TMtxVecInt): TMtxVecInt; overload; (* Apply binary "xor" between coresponding elements in Src1 and Src2. the result of binary "xor" of Src1 values [SrcIndex1]..[SrcIndex1+Len-1] with coresponding Src2 values [SrcIndex2]..[SrcIndex2+Len-1] stored in the calling object at locations [Index]..[Index+Len-1]. *) function BinaryXor(const Src1, Src2: TMtxVecInt; const SrcIndex1, SrcIndex2, Index, Len: integer): TMtxVecInt; overload; (*Apply binary "xor" between coresponding elements in Src and Self. the result of binary "xor" of Src values with coresponding values in Self (this).*) function BinaryXor(const Src: TMtxVecInt): TMtxVecInt; overload; (*Apply binary "xor" between coresponding elements in Src and Self. the result of binary "xor" of Src values [SrcIndex]...[SrcIndex+Len-1] with coresponding values in Self (this) [Index]..[Index+Len-1] stored back in the calling object.*) function BinaryXor(const Src: TMtxVecInt; const SrcIndex, Index, Len: integer): TMtxVecInt; overload; (*Apply binary shift by number of Bits to the left for all elements in the calling object. the result of binary shift to left by number of Bits applied to values in the calling object and stored back in the calling object.*) function BitShiftLeft(const Bits: integer): TMtxVecInt; overload; (*Apply binary shift by number of Bits to the left to elements in the calling object. the result of binary shift to left by number of Bits applied to values [Index]..[Index+Len-1] in the calling object and stored back in the calling object.*) function BitShiftLeft(const Bits, Index, Len: integer): TMtxVecInt; overload; (*Apply binary shift by number of Bits to the left to elements in Src. the result of binary shift to left by number of Bits applied to Src values [SrcIndex]..[SrcIndex+Len-1] and stored in the calling object (Self) value [Index]..[Index+Len-1].*) function BitShiftLeft(const Src: TMtxVecInt; const Bits: integer; const SrcIndex, Index, Len: integer): TMtxVecInt; overload; (*Apply binary shift by number of Bits to the left to elements in Src. the result of binary shift to left by number of Bits applied to Src values and stored in the calling object (Self).*) function BitShiftLeft(const Src: TMtxVecInt; const Bits: integer): TMtxVecInt; overload; (*Apply binary shift by number of Bits to the right for all elements in the calling object. the result of binary shift to right by number of Bits applied to values in the calling object and stored back in the calling object. The sign of the numbers is preserved.*) function BitShiftRight(const Bits: integer): TMtxVecInt; overload; (*Apply binary shift by number of Bits to the right to elements in the calling object. the result of binary shift to right by number of Bits applied to values [Index]..[Index+Len-1] in the calling object and stored back in the calling object. The sign of the numbers is preserved. *) function BitShiftRight(const Bits, Index, Len: integer): TMtxVecInt; overload; (*Apply binary shift by number of Bits to the right to elements in Src. the result of binary shift to right by number of Bits applied to Src values [SrcIndex]..[SrcIndex+Len-1] and stored in the calling object (Self) value [Index]..[Index+Len-1]. The sign of the numbers is preserved. *) function BitShiftRight(const Src: TMtxVecInt; const Bits: integer; const SrcIndex, Index, Len: integer): TMtxVecInt; overload; (*Apply binary shift by number of Bits to the right to elements in Src. the result of binary shift to right by number of Bits applied to Src values and stored in the calling object (Self). The sign of the numbers is preserved. *) function BitShiftRight(const Src: TMtxVecInt; const Bits: integer): TMtxVecInt; overload; (*Apply binary shift by number of Bits to the left (positive) or right (negative) for all elements in the calling object. the result of binary shift to the left or right by number of Bits applied to values in the calling object and stored back in the calling object. The sign of the numbers is preserved when doing right shift. *) function BitShift(const Bits: integer): TMtxVecInt; overload; (*Apply binary shift by number of Bits to the left (positive) or right (negative) to elements in the calling object. the result of binary shift to the left or right by number of Bits applied to values [Index]..[Index+Len-1] in the calling object and stored back in the calling object. The sign of the numbers is preserved when doing right shift. *) function BitShift(const Bits, Index, Len: integer): TMtxVecInt; overload; (*Apply binary shift by number of Bits to the left (positive) or right (negative) to elements in Src. the result of binary shift to the left or right by number of Bits applied to Src values [SrcIndex]..[SrcIndex+Len-1] and stored in the calling object (Self) value [Index]..[Index+Len-1]. The sign of the numbers is preserved when doing right shift. *) function BitShift(const Src: TMtxVecInt; const Bits: integer; const SrcIndex, Index, Len: integer): TMtxVecInt; overload; (*Apply binary shift by number of Bits to the left (positive) or right (negative) to elements in Src. the result of binary shift to the left or right by number of Bits applied to Src values and stored in the calling object (Self). The sign of the numbers is preserved when doing right shift. *) function BitShift(const Src: TMtxVecInt; const Bits: integer): TMtxVecInt; overload; (* Converts Src to packed bit storage. If Src[i] <> 0 then bit at index "i" in the calling vector is set to 1. If Src.Length is not divisable with 32, the remaining bits in the last sample are left at 0. The storage precision of the calling object is set to prInt32. The size of the calling object is adjusted automatically. Packing if array with precision other than Int32 is 8x slower. Packing of array with precision other than Int32 is 8x slower. *) function BitPack(const Src: TMtxInt): TMtxInt; overload; (* Converts Src to packed bit storage. Returns the result of bit packing the Src values [SrcIndex]..[SrcIndex+Len-1] and stored in the calling object bits from [0]..[0+Len-1]. If Len is not divisable with 32, the remaining bits in the last sample are left at 0. The storage precision of the calling object is set to prInt32. The size of the calling object is adjusted automatically. Packing of array with precision other than Int32 is 8x slower. *) function BitPack(const Src: TMtxVecInt; const SrcIndex, Index, Len: integer): TMtxVecInt; overload; (* Converts Src to packed bit storage. If bit at Src[i] <> 0 then Integer (32, 16 or 8bit) at index "i" in the calling vector is set to 1. The storage precision of the calling object is preserved. The size of the calling object is adjusted automatically. Unpack to array with precision other than Int32 is 8x slower. *) function BitUnpack(const Src: TMtxInt; const dstPrecision: TIntPrecision = prInt32): TMtxInt; overload; (* Converts Src to unpacked bit storage. If bit at Src[i] <> 0 then Integer (32, 16 or 8bit) at index "i" in the calling vector is set to 1. Returns the result of bit unpacking the bits stred Src values [0]..[Len-1] and stored in the calling object (Self) values [Index]..[Index+Len-1]. The storage precision of the calling object is preserved. The Len parameter specifies the number of bits that will be unpacked from Src. Unpack to array with precision other than Int32 is 8x slower. *) function BitUnpack(const Src: TMtxVecInt; SrcIndex, Index, Len: integer): TMtxVecInt; overload; (*Applies binary "not" operation to elements stored in the object. Calculate the binary "not" value of all calling object elemets in-place. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TMtxVecInt a; MtxVecInt.CreateIt(out a); try { a.SetIt(new int[] {1,0,1,0}); a.BinaryNot(); // a = [-2,-1,-2,-1] } finally { MtxVecInt.FreeIt(ref a); } } } *) function BinaryNot(): TMtxVecInt; overload; (*Apply binary "not" to elements stored in Self (this). the result of binary "not" of values stored in Self (this).*) function BinaryNot(const Index, Len: integer): TMtxVecInt; overload; (*Apply binary "not" to Src elements and store the result in Self (this). the result of binary "not" of Src values stored in Self (this).*) function BinaryNot(const Src: TMtxVecInt): TMtxVecInt; overload; (*Apply binary "not" to Src elements and store the result in Self (this). the result of binary "not" of Src values [SrcIndex]..[SrcIndex+Len-1] stored in Self (this) values [Index]..[Index+Len-1].*) function BinaryNot(const Src: TMtxVecInt; const SrcIndex, Index, Len: integer): TMtxVecInt; overload; (*Applies logical "not" operation to elements stored in the object. Calculate the logical "not" value of all calling object elemets in-place. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TVecInt a; MtxVecInt.CreateIt(out a); try { a.SetIt(new int[] {1,0,1,0}); a.LogicalNot(); // a = [0,1,0,1] } finally { MtxVec.FreeIt(ref a); } } } *) function LogicalNot(): TMtxVecInt; overload; (*Apply logical "not" to elements stored in Self (this). the result of logical "not" of values stored in Self (this).*) function LogicalNot(Index, Len: integer): TMtxVecInt; overload; (*Apply logical "not" to Src elements and store the result in Self (this). the result of logical "not" of Src values stored in Self (this).*) function LogicalNot(const Src: TMtxVecInt): TMtxVecInt; overload; (*Apply logical "not" to Src elements and store the result in Self (this). the result of logical "not" of Src values [SrcIndex]..[SrcIndex+Len-1] stored in Self (this) values [Index]..[Index+Len-1].*) function LogicalNot(const Src: TMtxVecInt; SrcIndex, Index, Len: integer): TMtxVecInt; overload; function LoadFromStream(const SrcStream: TStream): Int64; overload; procedure SaveToStream(DstStream: TStream); overload; (*Copies values from a real Src array. The size of the calling object is set implicitely. The integer precision of the calling object is preserved. *) function CopyFromArray(const Src: TCplxArray; const Rounding: TRounding): TMtxVecInt; overload; (*Copies values from the double precision floating point Src array [SrcIndex]..[SrcIndex+Len-1] to the calling object values [Index]..[Index+2*Len-1]. The size of the calling object is not changed. If the array border are overrun an exception will be raised. *) function CopyFromArray(const Src: TCplxArray; const Rounding: TRounding; const SrcIndex,Index,Len: integer): TMtxVecInt; overload; (*Fills the calling vector elements [Index]..[Index+Len-1]. Method uses the following rule: Values[k] := Offset + k*Step. An exception is raised if calling vector array borders are overrun. *) function Ramp(const Offset,Step: double; const Index,Len: integer): TMtxInt; overload; (*Copies values from Src array. The size of the calling object is set implicitely. The precision is preserved. *) function CopyFromArray(const Src: Math387.TWordArray): TMtxVecInt; overload; (*Copies values from a 2 byte unsigned integer type Src array [SrcIndex]..[SrcIndex+Len-1] to the calling object values [Index]..[Index+len-1]. The size of the calling object is not changed. If the array border are overrun an exception will be raised. *) function CopyFromArray(const Src: Math387.TWordArray; const SrcIndex, Index, Len: integer): TMtxVecInt; overload; (*Copies values from a real Src array. The size of the calling object is set implicitely. The precision is preserved. *) function CopyFromArray(const Src: TDoubleArray; const Rounding: TRounding): TMtxVecInt; overload; (*Copies values from the double precision floating point Src array [SrcIndex]..[SrcIndex+Len-1] to the calling object values [Index]..[Index+len-1]. The size of the calling object is not changed. If the array border are overrun an exception will be raised. *) function CopyFromArray(const Src: TDoubleArray; const Rounding: TRounding; const SrcIndex,Index,Len: integer): TMtxVecInt; overload; (*Copies values from a real single precision floating point Src array. The size property of the calling object is set implicitely. *) function CopyFromArray(const Src: TSingleArray; const Rounding: TRounding): TMtxVecInt; overload; (*Copies values from the single precision floating point Src array [SrcIndex]..[SrcIndex+Len-1] to the calling object values [Index]..[Index+len-1]. The size of the calling object is not changed. If the array border are overrun an exception will be raised. *) function CopyFromArray(const Src: TSingleArray; const Rounding: TRounding; const SrcIndex,Index,Len: integer): TMtxVecInt; overload; (*Copies values from an integer type Src array.*) function CopyFromArray(const Src: TIntegerArray): TMtxVecInt; overload; (*Copies values from a 4 byte signed integer type Src array [SrcIndex]..[SrcIndex+Len-1]. Store the results to the calling object values [Index]..[Index+len-1]. The size of the calling object is not changed. If the array border are overrun an exception will be raised. *) function CopyFromArray(const Src: TIntegerArray; const SrcIndex,Index,Len: integer): TMtxVecInt; overload; (*Copies values from an 2 byte signed integer type Src array. The size property of the calling object is set implicitely. *) function CopyFromArray(const Src: TSmallIntArray): TMtxVecInt; overload; (*Copies values from a 2 byte signed integer type Src array [SrcIndex]..[SrcIndex+Len-1] to the calling object values [Index]..[Index+len-1]. The size of the calling object is not changed. If the array border are overrun an exception will be raised. *) function CopyFromArray(const Src: TSmallIntArray; const SrcIndex,Index,Len: integer): TMtxVecInt; overload; (*Copies values from a 1 byte unsigned integer type Src array.*) function CopyFromArray(const Src: Math387.TByteArray): TMtxVecInt; overload; (*Copies values from a 1 byte unsigned integer type Src array [SrcIndex]..[SrcIndex+Len-1] to the calling object values [Index]..[Index+len-1]. The size of the calling object is not changed. If the array border are overrun an exception will be raised. *) function CopyFromArray(const Src: Math387.TByteArray; const SrcIndex,Index,Len: integer): TMtxVecInt; overload; (*Copies values from the calling object to the Dst array and converts data to double precision numbers. Consecutive elements are converted to real and imaginary parts. *) function CopyToArray(var Dst: TCplxArray): TMtxVecInt; overload; (*Copy values from the calling object [Index]..[Index+len-1] to the Dst integer array at positions [DstIndex]...[DstIndex+Len-1]. The size of the Dst array is not changed. The method converts calling object values to double precision floating point values. Consecutive elements are converted to real and imaginary parts. *) function CopyToArray(var Dst: TCplxArray; const DstIndex, Index,Len: integer): TMtxVecInt; overload; (*Copy values to Dst array. The size of the array is set automatically.*) function CopyToArray(var Dst: TDoubleArray): TMtxVecInt; overload; (*Copy values from the calling object [Index]..[Index+len-1] to the Dst array at positions [DstIndex]...[DstIndex+Len-1]. The size of the Dst array is not changed. *) function CopyToArray(var Dst: TDoubleArray; const DstIndex, Index,Len: integer): TMtxVecInt; overload; (*Copies the calling object data to an array of single precision floating point data. Any values exceeding the range are clipped. *) function CopyToArray(var Dst: TSingleArray): TMtxVecInt; overload; (*Copy values from the calling object [Index]..[Index+len-1] to the Dst single precision floating point array at positions [DstIndex]...[DstIndex+Len-1]. The size of the Dst array is not changed. *) function CopyToArray(var Dst: TSingleArray; const DstIndex, Index,Len: integer): TMtxVecInt; overload; (*Copies values from the calling object to the Dst array and converts data to 4 byte signed integer numbers.*) function CopyToArray(var Dst: TIntegerArray): TMtxVecInt; overload; (*Copy values from the calling object [Index]..[Index+len-1] to the Dst integer array at positions [DstIndex]...[DstIndex+Len-1]. The size of the Dst array is not changed. The method converts calling object values to 4 byte signed integers. Values exceeding the range of a 4 byte signed integer type are clipped. *) function CopyToArray(var Dst: TIntegerArray; const DstIndex, Index,Len: integer): TMtxVecInt; overload; (*Copies values from the calling object to the Dst array and converts data to 2 byte signed integer numbers. Values exceeding the range of a 2 byte signed integer type are clipped. *) function CopyToArray(var Dst: TSmallIntArray): TMtxVecInt; overload; (*Copy values from the calling object [Index]..[Index+len-1] to the Dst integer array at positions [DstIndex]...[DstIndex+Len-1]. The size of the Dst array is not changed. Values exceeding the range of a 2 byte signed integer type are clipped. *) function CopyToArray(var Dst: TSmallIntArray; const DstIndex, Index,Len: integer): TMtxVecInt; overload; (*Copies values from the calling object to the Dst array and converts data to 2 byte unsigned integer type. Values exceeding the range of a 2 byte unsigned integer type are clipped. *) function CopyToArray(var Dst: Math387.TWordArray): TMtxVecInt; overload; (*Copy values from the calling object [Index]..[Index+len-1] to the Dst integer array at positions [DstIndex]...[DstIndex+Len-1]. The size of the Dst array is not changed. Values exceeding the range of a 2 byte unsigned integer type are clipped. *) function CopyToArray(var Dst: Math387.TWordArray; const DstIndex, Index,Len: integer): TMtxVecInt; overload; (*Copies values from the calling object to the Dst array and converts data to 1 byte unsigned integer numbers. Values exceeding the range of 1 byte unsigned integer type are clipped. *) function CopyToArray(var Dst: Math387.TByteArray): TMtxVecInt; overload; (*Copy values from the calling object [Index]..[Index+len-1] to the Dst integer array at positions [DstIndex]...[DstIndex+Len-1]. The size of the Dst array is not changed. Values exceeding the range of 1 byte unsigned integer type are clipped. *) function CopyToArray(var Dst: Math387.TByteArray; const DstIndex,Index,Len: integer): TMtxVecInt; overload; (*Finds a match for X in object values using binary search. The data in the vector must be sorted in ascending order for this function to work correctly. the index of last matched element. If no matching elements are found, the result is -1.*) function BinarySearch(const X: Integer): Integer; overload; function BinarySearch(const X: Integer; const Index: integer; const Len: integer): Integer; overload; (*Finds a closest match for X in object values using binary search. The data in the vector must be sorted in ascending order for this function to work correctly. True, if found and the index of the closest match in XIndex. *) function BinarySearch(const X: Integer; var XIndex: integer): boolean; overload; function BinarySearch(const X: Integer; var XIndex: integer; const Index: integer; Len: integer): boolean; overload; (*Finds a match for X in object values. the index of last matched element. If no matching elements are found, the result is -1. Compare real value X with all calling object elements. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TMtxInt a; MtxVecInt.CreateIt(out a); try { a.SetIt(false, new int[] {2,5,1,6}); int indes = a.Find(1); // returns 2 (the arrays are zero based) } finally { MtxVecInt.FreeIt(ref a); } } } *) function Find(const X: integer): integer; overload; function Find(const X: integer; const Index: integer; const Len: integer = MtxVecEOA): integer; overload; (*Scatter object elements. Scatter the elements of the Src and store them in the calling object according to the IndexType, Increment and Offset parameters. The Indexes vector is used only if IndexType is either indVector or indMask. If IndexType is indVector, the values from the Indexes object denote the index positions in the calling object to which the values should be copied from the Src. The Indexes vector must have the indexes stored in the IValues array. The IValues integer arrays points the same memory as Values array. The Increment and Offset parameters are used only if TIndexType is indIncrement. They define the target offset and a fixed step (increment) between calling vector elements. If IndexType is indMaks the Indexes object must have the same size as the Src object. The routine will copy only those elements from the Src to the calling object, for which there is a 1 at the coresponding index in the Indexes object.The elements in the calling object are stored consecutively. See the method to see how to perform gathering. The performance of the CPU heavily depends on the assumption that elements are stored at consecutive memory locations. If it is neccessary to apply a set of operations only to elements at specific indexes, performance-wise it can prove to be very helpfull, if the elements are gathered first. *) function Scatter(const Src: TMtxVecInt; const Indexes: TMtxVecInt = nil; IndexType: TIndexType = indVector; Increment: integer = 1; Offset: integer = 0): TMtxVecInt; overload; (* Scatters Src elements starting at Offset and with Increment to the calling object. *) function ScatterByIncr(const Src: TMtxVecInt; Increment: integer = 1; Offset: integer = 0): TMtxVecInt; overload; (* Scatters Src elements defined with indices stored in Indexes to the calling object. *) function ScatterByIndexes(const Src: TMtxVecInt; const Indexes: TMtxVecInt): TMtxVecInt; overload; (*Finds the masks for a vector and splits it. The method splits the a vector in two vectors. The MaskVec will hold the those elements where the Op comparison between a and b is True. Op string parameter can be < , > , >= , <= , = or <> . NotMaksVec will hold all those elements where the Op comparison between a and b is false. The calling vector will store the mask, 1 at those index locations where the Op comparison was True and 0 at those index locations where the Op comparison was false. *) function FindAndSplit(const a: TMtxVec; const op: string; const b: TMtxVec; const MaskVec, NotMaskVec: TVec): TMtxVecInt; overload; (*The b parameter is of type.*) function FindAndSplit(const a: TMtxVec; const op: string; const b: TCplx; const MaskVec, NotMaskVec: TVec): TMtxVecInt; overload; (*The b parameter is of double type.*) function FindAndSplit(const a: TMtxVec; const op: string; const b: double; const MaskVec, NotMaskVec: TVec): TMtxVecInt; overload; (*Finds a vector mask. The calling vector will hold the those elements where the Op comparison between a and b is True. Op string parameter can be < , > , >= , <= , = or <> . The calling vector will store the mask, 1 at those index locations where the Op comparison was True and 0 at those index locations where the Op comparison was false. *) function FindMask(const a: TMtx; const op: string; const b: TCplx): TMtxVecInt; overload; (*The b parameter is of double type.*) function FindMask(const a: TMtx; const op: string; const b: double): TMtxVecInt; overload; (*The b parameter is of type.*) function FindMask(const a: TMtxVec; const op: string; const b: TMtxVec): TMtxVecInt; overload; (*Finds a vector mask. The calling vector will hold the those elements where the Op comparison between a and b is True. Op string parameter can be < , > , >= , <= , = or <> . The calling vector will store the mask, 1 at those index locations where the Op comparison was True and 0 at those index locations where the Op comparison was false. *) function FindMask(const a: TMtxVecInt; const op: string; const b: integer): TMtxVecInt; overload; (*The b parameter is of type.*) function FindMask(const a: TMtxVecInt; const op: string; const b: TMtxVecInt): TMtxVecInt; overload; (*Add coresponding elements in Src2 to Src1. the result of adding Src2 values from coresponding Src1 values.*) function Add(const Src1, Src2: TMtxVecInt): TMtxVecInt; overload; (*Add coresponding elements in Src2 to Src1. Add Src1 elements [Src1Index..Src1Index+Len-1] to corrresponding Src2 elements [Src2Index..Src12ndex+Len] and store the results in calling vector elements [Index..Index+Len-1]. An exception is raised if array borders are overrun. *) function Add(const Src1, Src2: TMtxVecInt; const Src1Index, Src2Index, Index, Len: integer): TMtxVecInt; overload; (*Add Src elements to calling vector elements.*) function Add(const Src: TMtxVecInt): TMtxVecInt; overload; (*Add Src elements [SrcIndex..SrcIndex+Len-1] to calling vector elements. Add Src elements [SrcIndex..SrcIndex+Len-1] to calling vector elements [Index..Index+Len-1]. An exception is raised if array borders are overrun. *) function Add(const Src: TMtxVecInt; const SrcIndex, Index, Len: integer): TMtxVecInt; overload; (*Add integer Value to all Src elements. Add integer Value to all Src elements and store the results in calling vector. Size of calling vector is adjusted automatically. *) function Add(const Src: TMtxVecInt; const Value: integer): TMtxVecInt; overload; (*Add integer Value to Src elements [SrcIndex..SrcIndex+Len-1]. Add integer Value to Src elements [SrcIndex..SrcIndex+Len-1] and store the results in calling vector elements [Index..Index+Len-1]. An exception is raised if array borders are overrun. *) function Add(const Src: TMtxVecInt; const Value, SrcIndex, Index, Len: integer): TMtxVecInt; overload; (*Add integer value to all calling vector elements.*) function Add(const Value: integer): TMtxVecInt; overload; (*Add integer value to calling vector elements [Index..Index+Len-1]. An exception is raised if array borders are overrun. *) function Add(const Value, Index, Len: integer): TMtxVecInt; overload; (*Subtract coresponding elements in Src2 from Src1. the result of subtracting Src2 values from coresponding Src1 values.*) function Subtract(const Src1, Src2: TMtxVecInt): TMtxVecInt; overload; (*Add coresponding elements in Src1 from Src1. Subtract Src2 elements [Src2Index..Src2Index+Len-1] from corrresponding Src1 elements [Src1Index..Src1ndex+Len] and store the results in calling vector elements [Index..Index+Len-1]. An exception is raised if array borders are overrun. *) function Subtract(const Src1, Src2: TMtxVecInt; const Src1Index, Src2Index, Index, Len: integer): TMtxVecInt; overload; (*Subtract all Src elements from calling vector elements.*) function Subtract(const Src: TMtxVecInt): TMtxVecInt; overload; (*Subtract Src elements [SrcIndex..SrcIndex+Len-1] from calling vector elements. Subtract Src elements [SrcIndex..SrcIndex+Len-1] from calling vector elements [Index..Index+Len-1]. An exception is raised if array borders are overrun. *) function Subtract(const Src: TMtxVecInt; const SrcIndex, Index, Len: integer): TMtxVecInt; overload; (*Subtract integer Value from all Src elements. Subtract integer Value from all Src elements and store the results in calling vector. Size of calling vector is adjusted automatically. *) function Subtract(const Src: TMtxVecInt; const Value: integer): TMtxVecInt; overload; (*Subtract integer Value from Src elements [SrcIndex..SrcIndex+Len-1]. Subtract integer Value from Src elements [SrcIndex..SrcIndex+Len-1] and store the results in calling vector elements [Index..Index+Len-1]. An exception is raised if array borders are overrun. *) function Subtract(const Src: TMtxVecInt; const Value, SrcIndex, Index, Len: integer): TMtxVecInt; overload; (*Subtract integer value from all calling vector elements.*) function Subtract(const Value: integer): TMtxVecInt; overload; (*Subtract integer value from calling vector elements [Index..Index+Len-1]. An exception is raised if array borders are overrun. *) function Subtract(const Value, Index, Len: integer): TMtxVecInt; overload; (*Subtract all calling vector elements from integer Value.*) function SubtractFrom(const Value: integer): TMtxVecInt; overload; (*Subtract calling vector elements [Index..Index+Len-1] from integer Value. An exception is raised if array borders are overrun. *) function SubtractFrom(const Value, Index, Len: integer): TMtxVecInt; overload; (*Subtract all Src vector elements from integer Value. and store thje results in calling vector. Size of calling vector is adjusted automatically. *) function SubtractFrom(const Value: integer; const Src: TMtxVecInt): TMtxVecInt; overload; (*Subtract Src vector elements [SrcIndex..SrcIndex+Len-1] from integer Value. and store thje results in calling vector elements [Index..Index+Len-1]. Size of calling vector is adjusted automatically. An exception is raised if array borders are overrun. *) function SubtractFrom(const Value: integer; const Src: TMtxVecInt; const SrcIndex, Index, Len: integer): TMtxVecInt; overload; (*Compute maximum of each row. Compute maximum of each row and store the result in to Dst vector. The Dst is sized automatically. *) procedure MaxRows(const Dst: TVecInt); overload; (*Compute minimum of each row. Compute mniimum of each row and store the result in to Dst vector. The Dst is sized automatically. *) procedure MinRows(const Dst: TVecInt); overload; (*Compute maximum of each column. Compute maximum of each column and store the result in to Dst vector. The Dst is sized automatically. *) procedure MaxCols(const Dst: TVecInt); overload; (*Compute minimum of each column. Compute minimum of each column and store the result in to Dst vector. The Dst is sized automatically. *) procedure MinCols(const Dst: TVecInt); overload; (*Compute maximum and minimum of each row. Compute maximum and minimum of each row and store the result in to Dst vectors. The Dst's are sized automatically. *) procedure MaxMinRows(const DstMaxRows, DstMinRows: TVecInt); overload; (*Compute maximum and minimum of each column. Compute maximum and minimum of each column and store the result in to Dst vectors. The Dst's are sized automatically. *) procedure MaxMinCols(const DstMaxCols, DstMinCols: TVecInt); overload; (*Multiplies coresponding elements in Src2 with Src1. the result of multipliing Src2 values with coresponding Src1 values.*) function Multiply(const Src1, Src2: TMtxVecInt): TMtxVecInt; overload; (*Multiply coresponding elements in Src2 with Src1. Multiply Src1 elements [Src1Index..Src1Index+Len-1] with corrresponding Src2 elements [Src2Index..Src2ndex+Len] and store the results in calling vector elements [Index..Index+Len-1]. An exception is raised if array borders are overrun. *) function Multiply(const Src1, Src2: TMtxVecInt; const SrcIndex1, SrcIndex2,Index, Len: integer): TMtxVecInt; overload; (*Multiply Src elements with calling vector elements.*) function Multiply(const Src: TMtxVecInt): TMtxVecInt; overload; (*Mjultiply Src elements [SrcIndex..SrcIndex+Len-1] with calling vector elements. Multiply Src elements [SrcIndex..SrcIndex+Len-1] with calling vector elements [Index..Index+Len-1]. An exception is raised if array borders are overrun. *) function Multiply(const Src: TMtxVecInt; const SrcIndex, Index, Len: integer): TMtxVecInt; overload; (*Multiply integer Value with all Src elements. Multiply integer Value with all Src elements and store the results in calling vector. Size of calling vector is adjusted automatically. *) function Multiply(const Src: TMtxVecInt; const Value: integer): TMtxVecInt; overload; (*Multiply integer value with Src vector elements [SrcIndex..SrcIndex+Len-1]. Store the results in calling vector elements [Index..Index+Len-1]. An exception is raised if array borders are overrun. *) function Multiply(const Src: TMtxVecInt; const Value, SrcIndex, Index, Len: integer): TMtxVecInt; overload; (*Multiply integer value with all calling vector elements.*) function Multiply(const Value: integer): TMtxVecInt; overload; (*Multiply integer value with calling vector elements [Index..Index+Len-1]. An exception is raised if array borders are overrun. *) function Multiply(const Value,Index, Len: integer): TMtxVecInt; overload; (*Divides coresponding elements in Num with Den. the result of dividing Num values with coresponding Den values.*) function Divide(const Num, Den: TMtxVecInt): TMtxVecInt; overload; (*Divide coresponding elements in Num with Den. Divide Num elements [NumIndex..NumIndex+Len-1] with corrresponding Deb elements [DenIndex..DenIndex+Len-1] and store the results in calling vector elements [Index..Index+Len-1]. An exception is raised if array borders are overrun. *) function Divide(const Num, Den: TMtxVecInt; const NumIndex, DenIndex, Index, Len: integer): TMtxVecInt; overload; (*Divide calling object elements with Src elements.*) function Divide(const Src: TMtxVecInt): TMtxVecInt; overload; (*Divide calling object elements with Src elements [SrcIndex..SrcIndex+Len-1]. Divide calling object elements [Index..Index+Len ] with Src elements [SrcIndex..SrcIndex+Len-1]. An exception is raised if array borders are overrun. *) function Divide(const Src: TMtxVecInt; const SrcIndex, Index, Len: integer): TMtxVecInt; overload; (*Divide all Src vector elements with integer Value. Size of calling vector is adjusted automatically. *) function Divide(const Src: TMtxVecInt; const Value: integer): TMtxVecInt; overload; (*Divide Src vector elements [SrcIndex..SrcIndex+Len-1] with integer Value. Divide Src elements [SrcIndex..SrcIndex+Len-1] with integer Value and store tje results in calling vector elements [Index..Index+Len-1]. An exception is raised if array borders are overrun. *) function Divide(const Src: TMtxVecInt; const Value, SrcIndex, Index, Len: integer): TMtxVecInt; overload; (*Divide all calling vector elements with integer value.*) function Divide(const Value: integer): TMtxVecInt; overload; (*Divide calling vector elements [Index..Index+Len-1] with integer value. An exception is raised if array borders are overrun. *) function Divide(const Value, Index, Len: integer): TMtxVecInt; overload; (*Divide Value with calling vector elements. Teh result is stored in the calling vector. *) function DivideBy(const Value: integer): TMtxVecInt; overload; (*Divide Value with calling vector elements [Index..Index+Len-1]. An exception is raised if array borders are overrun. *) function DivideBy(const Value, Index, Len: integer): TMtxVecInt; overload; (*Divide Value with Src vector elements and store the result in the calling vector. An exception is raised if array borders are overrun. *) function DivideBy(const Value: integer; const Src: TMtxVecInt): TMtxVecInt; overload; (*Divide Value with Src vector elements [SrcIndex+SrcIndex+Len-1] and store the result in the calling vector [Index...Index+Len-1]. An exception is raised if array borders are overrun. *) function DivideBy(const Value: integer; const Src: TMtxVecInt; const SrcIndex, Index, Len: integer): TMtxVecInt; overload; (* Compute X + Y*yScale *) function AddScaled(const X, Y: TMtxVecInt; const yScale: integer): TMtxVecInt; overload; (* Compute X + Y*yScale on sub arrays *) function AddScaled(const X: TMtxVecInt; xIndex: integer; const Y: TMtxVecInt; yIndex: integer; const yScale: integer; Index, Len: integer): TMtxVecInt; overload; (* Compute sqr(X + Y*yScale) By making use of yScale, it is also possible to compute the following (at the same or higher speed): (X - Y)^2 = X^2 - 2XY +Y^2 *) function AddScaledSqr(const X, Y: TMtxVecInt; const yScale: integer): TMtxVecInt; overload; (* Compute sqr(X + Y*yScale) on sub arrays *) function AddScaledSqr(const X: TMtxVecInt; xIndex: integer; const Y: TMtxVecInt; yIndex: integer; const yScale: integer; Index, Len: integer): TMtxVecInt; overload; (* Compute sqr(X) + sqr(Y)*yScale By making use of yScale, it is also possible to compute the following (at the same or higher speed): X^2 - Y^2 *) function SqrAddScaled(const X, Y: TMtxVecInt; const yScale: integer): TMtxVecInt; overload; (* Compute sqr(X) + sqr(Y)*yScale on sub arrays *) function SqrAddScaled(const X: TMtxVecInt; xIndex: integer; const Y: TMtxVecInt; yIndex: integer; const yScale: integer; Index, Len: integer): TMtxVecInt; overload; (* Compute X + Y + Z *) function Add(const X, Y, Z: TMtxVecInt): TMtxVecInt; overload; (* Compute X + Y + Z on sub arrays *) function Add(const X: TMtxVecInt; xIndex: integer; const Y: TMtxVecInt; yIndex: integer; const Z: TMtxVecInt; zIndex: integer; Index, Len: integer): TMtxVecInt; overload; (* Compute X + Y + Z*zScale *) function AddScaled(const X, Y, Z: TMtxVecInt; const zScale: integer): TMtxVecInt; overload; (* Compute X + Y + Z*zScale on sub arrays *) function AddScaled(const X: TMtxVecInt; xIndex: integer; const Y: TMtxVecInt; yIndex: integer; const Z: TMtxVecInt; zIndex: integer; const zScale: integer; Index, Len: integer): TMtxVecInt; overload; (* Compute X + Y*yScale + Z*zScale *) function AddScaled(const X, Y: TMtxVecInt; const yScale: integer; const Z: TMtxVecInt; const zScale: integer): TMtxVecInt; overload; (* Compute X + Y*yScale + Z*zScale on sub arrays *) function AddScaled(const X: TMtxVecInt; xIndex: integer; const Y: TMtxVecInt; yIndex: integer; const yScale: integer; const Z: TMtxVecInt; zIndex: integer; const zScale: integer; Index, Len: integer): TMtxVecInt; overload; (* Compute X + Y + zScalar *) function Add(const X, Y: TMtxVecInt; const Z: integer): TMtxVecInt; overload; (* Compute X + Y + zScalar on sub arrays *) function Add(const X: TMtxVecInt; xIndex: integer; const Y: TMtxVecInt; yIndex: integer; const Z: integer; Index, Len: integer): TMtxVecInt; overload; (* Compute X + Y*yScale + zScalar *) function AddScaledC(const X, Y: TMtxVecInt; const yScale: integer; const Z: integer): TMtxVecInt; overload; (* Compute X + Y*yScale + zScalar on sub arrays *) function AddScaledC(const X: TMtxVecInt; xIndex: integer; const Y: TMtxVecInt; yIndex: integer; const yScale: integer; const Z: integer; Index, Len: integer): TMtxVecInt; overload; (* Compute X - Y - Z *) function Sub(const X, Y, Z: TMtxVecInt): TMtxVecInt; overload; (* Compute X - Y - Z on sub array*) function Sub(const X: TMtxVecInt; xIndex: integer; const Y: TMtxVecInt; yIndex: integer;const Z: TMtxVecInt; zIndex: integer; Index, Len: integer): TMtxVecInt; overload; (* Compute X - Y*yScale - Z*zScale *) function SubScaled(const X, Y: TMtxVecInt; const yScale: integer; const Z: TMtxVecInt; const zScale: integer): TMtxVecInt; overload; (* Compute X - Y*yScale - Z*zScale on sub array*) function SubScaled(const X: TMtxVecInt; xIndex: integer; const Y: TMtxVecInt; yIndex: integer; const yScale: integer; const Z: TMtxVecInt; zIndex: integer; const zScale: integer; Index, Len: integer): TMtxVecInt; overload; (* Compute X - Y - Z*zScale *) function SubScaled(const X, Y, Z: TMtxVecInt; const zScale: integer): TMtxVecInt; overload; (* Compute X - Y - Z*zScale on sub array*) function SubScaled(const X: TMtxVecInt; xIndex: integer; const Y: TMtxVecInt; yIndex: integer; const Z: TMtxVecInt; zIndex: integer; const zScale: integer; Index, Len: integer): TMtxVecInt; overload; (* Compute X - Y - zScalar *) function Sub(const X, Y: TMtxVecInt; const Z: integer): TMtxVecInt; overload; (* Compute X - Y - zScalar on sub array*) function Sub(const X: TMtxVecInt; xIndex: integer; const Y: TMtxVecInt; yIndex: integer; const Z: integer; Index, Len: integer): TMtxVecInt; overload; (* Compute X - Y*yScale - zScalar *) function SubScaledC(const X, Y: TMtxVecInt; const yScale: integer; const Z: integer): TMtxVecInt; overload; (* Compute X - Y*yScale - zScalar on sub array*) function SubScaledC(const X: TMtxVecInt; xIndex: integer; const Y: TMtxVecInt; yIndex: integer; const yScale: integer; const Z: integer; Index, Len: integer): TMtxVecInt; overload; (* Compute X * Y / Z *) function MulAndDiv(const X, Y, Z: TMtxVecInt): TMtxVecInt; overload; (* Compute X * Y / Z on sub array*) function MulAndDiv(const X: TMtxVecInt; xIndex: integer; const Y: TMtxVecInt; yIndex: integer; const Z: TMtxVecInt; zIndex: integer; Index, Len: integer): TMtxVecInt; overload; (* Compute (X + Y)*Z *) function AddAndMul(const X, Y, Z: TMtxVecInt): TMtxVecInt; overload; (* Compute (X + Y)*Z on sub array*) function AddAndMul(const X: TMtxVecInt; xIndex: Integer; const Y: TMtxVecInt; yIndex: Integer; const Z: TMtxVecInt; zIndex: Integer; Index, Len: Integer): TMtxVecInt; overload; (* Compute (X + Y)*Z*zScale *) function AddAndMul(const X, Y, Z: TMtxVecInt; zScale: integer): TMtxVecInt; overload; (* Compute (X + Y)*Z*zScale on sub array*) function AddAndMul(const X: TMtxVecInt; xIndex: Integer; const Y: TMtxVecInt; yIndex: Integer; const Z: TMtxVecInt; zIndex: Integer; zScale: integer; Index, Len: Integer): TMtxVecInt; overload; (* Compute (X + Y*yScale)*Z*zScale *) function AddAndMul(const X, Y: TMtxVecInt; yScale: integer; const Z: TMtxVecInt; zScale: integer): TMtxVecInt; overload; (* Compute (X + Y*yScale)*Z*zScale on sub array*) function AddAndMul(const X: TMtxVecInt; xIndex: Integer; const Y: TMtxVecInt; yIndex: Integer; yScale: integer; const Z: TMtxVecInt; zIndex: Integer; zScale: integer; Index, Len: Integer): TMtxVecInt; overload; (* Compute (X + Y)*zScalar *) function AddAndMul(const X, Y: TMtxVecInt; Z: integer): TMtxVecInt; overload; (* Compute (X + Y)*zScalar on sub array*) function AddAndMul(const X: TMtxVecInt; xIndex: Integer; const Y: TMtxVecInt; yIndex: Integer; Z: integer; Index, Len: Integer): TMtxVecInt; overload; (* Compute (X + Y*yScale)*zScalar *) function AddAndMul(const X, Y: TMtxVecInt; yScale, Z: integer): TMtxVecInt; overload; (* Compute (X + Y*yScale)*zScalar on sub array*) function AddAndMul(const X: TMtxVecInt; xIndex: Integer; const Y: TMtxVecInt; yIndex: Integer; yScale, Z: integer; Index, Len: Integer): TMtxVecInt; overload; (* Compute (X + yScalar)*Z*zScale *) function AddAndMul(const X: TMtxVecInt; Y: integer; const Z: TMtxVecInt; zScale: integer): TMtxVecInt; overload; (* Compute (X + yScalar)*Z*zScale on sub-array*) function AddAndMul(const X: TMtxVecInt; xIndex: integer; Y: integer; const Z: TMtxVecInt; zIndex: integer; zScale: integer; Index, Len: integer): TMtxVecInt; overload; (* Compute (X*xScale + yScalar)*Z *) function AddAndMul(const X: TMtxVecInt; xScale, Y: integer; const Z: TMtxVecInt): TMtxVecInt; overload; (* Compute (X*xScale + yScalar)*Z on sub-array*) function AddAndMul(const X: TMtxVecInt; xIndex: integer; xScale, Y : integer; const Z: TMtxVecInt; zIndex: integer; Index, Len: integer): TMtxVecInt; overload; (* Compute (X + yScalar)*Z *) function AddAndMul(const X: TMtxVecInt; Y: integer; const Z: TMtxVecInt): TMtxVecInt; overload; (* Compute (X + yScalar)*Z on sub-array*) function AddAndMul(const X: TMtxVecInt; xIndex: integer; Y: integer; const Z: TMtxVecInt; zIndex: integer; Index, Len: integer): TMtxVecInt; overload; (* Compute (X + yScalar)*zScalar *) function AddAndMul(const X: TMtxVecInt; Y, Z: integer): TMtxVecInt; overload; (* Compute (X + yScalar)*zScalar on sub-array*) function AddAndMul(const X: TMtxVecInt; xIndex: integer; Y, Z: integer; Index, Len: integer): TMtxVecInt; overload; (* Compute (X - Y)*Z *) function SubAndMul(const X, Y, Z: TMtxVecInt): TMtxVecInt; overload; (* Compute (X - Y)*Z on sub array*) function SubAndMul(const X: TMtxVecInt; xIndex: Integer; const Y: TMtxVecInt; yIndex: Integer; const Z: TMtxVecInt; zIndex: Integer; Index, Len: Integer): TMtxVecInt; overload; (* Compute (X - Y)*Z*zScale *) function SubAndMul(const X, Y, Z: TMtxVecInt; zScale: integer): TMtxVecInt; overload; (* Compute (X - Y)*Z*zScale on sub array*) function SubAndMul(const X: TMtxVecInt; xIndex: Integer; const Y: TMtxVecInt; yIndex: Integer; const Z: TMtxVecInt; zIndex: Integer; zScale: integer; Index, Len: Integer): TMtxVecInt; overload; (* Compute (X - Y*yScale)*Z*zScale *) function SubAndMul(const X, Y: TMtxVecInt; yScale: integer; const Z: TMtxVecInt; zScale: integer): TMtxVecInt; overload; (* Compute (X - Y*yScale)*Z*zScale on sub array*) function SubAndMul(const X: TMtxVecInt; xIndex: Integer; const Y: TMtxVecInt; yIndex: Integer; yScale: integer; const Z: TMtxVecInt; zIndex: Integer; zScale: integer; Index, Len: Integer): TMtxVecInt; overload; (* Compute (X - Y)*zScalar *) function SubAndMul(const X, Y: TMtxVecInt; Z: integer): TMtxVecInt; overload; (* Compute (X - Y)*zScalar on sub array*) function SubAndMul(const X: TMtxVecInt; xIndex: Integer; const Y: TMtxVecInt; yIndex: Integer; Z: integer; Index, Len: Integer): TMtxVecInt; overload; (* Compute (X - Y*yScale)*zScalar *) function SubAndMul(const X, Y: TMtxVecInt; yScale, Z: integer): TMtxVecInt; overload; (* Compute (X - Y*yScale)*zScalar on sub array*) function SubAndMul(const X: TMtxVecInt; xIndex: Integer; const Y: TMtxVecInt; yIndex: Integer; yScale, Z: integer; Index, Len: Integer): TMtxVecInt; overload; (* Compute (X - yScalar)*Z*zScale *) function SubAndMul(const X: TMtxVecInt; Y: integer; const Z: TMtxVecInt; zScale: integer): TMtxVecInt; overload; (* Compute (X - yScalar)*Z*zScale on sub-array*) function SubAndMul(const X: TMtxVecInt; xIndex: integer; Y: integer; const Z: TMtxVecInt; zIndex: integer; zScale: integer; Index, Len: integer): TMtxVecInt; overload; (* Compute (X*xScale - yScalar)*Z *) function SubAndMul(const X: TMtxVecInt; xScale, Y: integer; const Z: TMtxVecInt): TMtxVecInt; overload; (* Compute (X*xScale - yScalar)*Z on sub-array*) function SubAndMul(const X: TMtxVecInt; xIndex: integer; xScale, Y : integer; const Z: TMtxVecInt; zIndex: integer; Index, Len: integer): TMtxVecInt; overload; (* Compute (X - yScalar)*Z *) function SubAndMul(const X: TMtxVecInt; Y: integer; const Z: TMtxVecInt): TMtxVecInt; overload; (* Compute (X - yScalar)*Z on sub-array*) function SubAndMul(const X: TMtxVecInt; xIndex: integer; Y: integer; const Z: TMtxVecInt; zIndex: integer; Index, Len: integer): TMtxVecInt; overload; (* Compute (X - yScalar)*zScalar *) function SubAndMul(const X: TMtxVecInt; Y, Z: integer): TMtxVecInt; overload; (* Compute (X - yScalar)*zScalar on sub-array*) function SubAndMul(const X: TMtxVecInt; xIndex: integer; Y, Z: integer; Index, Len: integer): TMtxVecInt; overload; (* Compute X*Y + Z *) function MulAndAdd(const X, Y, Z: TMtxVecInt): TMtxVecInt; overload; (* Compute X*Y + Z on sub array*) function MulAndAdd(const X: TMtxVecInt; xIndex: Integer; const Y: TMtxVecInt; yIndex: Integer; const Z: TMtxVecInt; zIndex: Integer; Index, Len: Integer): TMtxVecInt; overload; (* Compute X*Y*xyScale + Z *) function MulAndAdd(const X, Y: TMtxVecInt; xyScale: integer; const Z: TMtxVecInt): TMtxVecInt; overload; (* Compute X*Y*xyScale + Z on sub array*) function MulAndAdd(const X: TMtxVecInt; xIndex: Integer; const Y: TMtxVecInt; yIndex: Integer; xyScale: integer; const Z: TMtxVecInt; zIndex: Integer; Index, Len: Integer): TMtxVecInt; overload; (* Compute X*Y + Z*zScale *) function MulAndAdd(const X, Y, Z: TMtxVecInt; zScale: integer): TMtxVecInt; overload; (* Compute X*Y + Z*zScale on sub array*) function MulAndAdd(const X: TMtxVecInt; xIndex: Integer; const Y: TMtxVecInt; yIndex: Integer; const Z: TMtxVecInt; zIndex: Integer; zScale: integer; Index, Len: Integer): TMtxVecInt; overload; (* Compute X*Y + zScalar *) function MulAndAdd(const X, Y: TMtxVecInt; Z: integer): TMtxVecInt; overload; (* Compute X*Y + zScalar on sub array*) function MulAndAdd(const X: TMtxVecInt; xIndex: Integer; const Y: TMtxVecInt; yIndex: Integer; Z: integer; Index, Len: Integer): TMtxVecInt; overload; (* Compute X*Y - Z *) function MulAndSub(const X, Y, Z: TMtxVecInt): TMtxVecInt; overload; (* Compute X*Y - Z on sub array*) function MulAndSub(const X: TMtxVecInt; xIndex: Integer; const Y: TMtxVecInt; yIndex: Integer; const Z: TMtxVecInt; zIndex: Integer; Index, Len: Integer): TMtxVecInt; overload; (* Compute X*Y*xyScale - Z *) function MulAndSub(const X, Y: TMtxVecInt; xyScale: integer; const Z: TMtxVecInt): TMtxVecInt; overload; (* Compute X*Y*xyScale + Z on sub array*) function MulAndSub(const X: TMtxVecInt; xIndex: Integer; const Y: TMtxVecInt; yIndex: Integer; xyScale: integer; const Z: TMtxVecInt; zIndex: Integer; Index, Len: Integer): TMtxVecInt; overload; (* Compute X*Y - Z*zScale *) function MulAndSub(const X, Y, Z: TMtxVecInt; zScale: integer): TMtxVecInt; overload; (* Compute X*Y - Z*zScale on sub array*) function MulAndSub(const X: TMtxVecInt; xIndex: Integer; const Y: TMtxVecInt; yIndex: Integer; const Z: TMtxVecInt; zIndex: Integer; zScale: integer; Index, Len: Integer): TMtxVecInt; overload; (* Compute X*Y - zScalar *) function MulAndSub(const X, Y: TMtxVecInt; Z: integer): TMtxVecInt; overload; (* Compute X*Y - zScalar on sub array*) function MulAndSub(const X: TMtxVecInt; xIndex: Integer; const Y: TMtxVecInt; yIndex: Integer; Z: integer; Index, Len: Integer): TMtxVecInt; overload; (* Compute X/Y + Z *) function DivAndAdd(const X, Y, Z: TMtxVecInt): TMtxVecInt; overload; (* Compute X/Y + Z on sub array*) function DivAndAdd(const X: TMtxVecInt; xIndex: Integer; const Y: TMtxVecInt; yIndex: Integer; const Z: TMtxVecInt; zIndex: Integer; Index, Len: Integer): TMtxVecInt; overload; (* Compute X/Y*xyScale + Z *) function DivAndAdd(const X, Y: TMtxVecInt; xyScale: integer; const Z: TMtxVecInt): TMtxVecInt; overload; (* Compute X/Y*xyScale + Z on sub array*) function DivAndAdd(const X: TMtxVecInt; xIndex: Integer; const Y: TMtxVecInt; yIndex: Integer; xyScale: integer; const Z: TMtxVecInt; zIndex: Integer; Index, Len: Integer): TMtxVecInt; overload; (* Compute X/Y + Z*zScale *) function DivAndAdd(const X, Y, Z: TMtxVecInt; zScale: integer): TMtxVecInt; overload; (* Compute X/Y + Z*zScale on sub array*) function DivAndAdd(const X: TMtxVecInt; xIndex: Integer; const Y: TMtxVecInt; yIndex: Integer; const Z: TMtxVecInt; zIndex: Integer; zScale: integer; Index, Len: Integer): TMtxVecInt; overload; (* Compute X/Y + zScalar *) function DivAndAdd(const X, Y: TMtxVecInt; Z: integer): TMtxVecInt; overload; (* Compute X/Y + zScalar on sub array*) function DivAndAdd(const X: TMtxVecInt; xIndex: Integer; const Y: TMtxVecInt; yIndex: Integer; Z: integer; Index, Len: Integer): TMtxVecInt; overload; (* Compute X/Y - Z *) function DivAndSub(const X, Y, Z: TMtxVecInt): TMtxVecInt; overload; (* Compute X/Y - Z on sub array*) function DivAndSub(const X: TMtxVecInt; xIndex: Integer; const Y: TMtxVecInt; yIndex: Integer; const Z: TMtxVecInt; zIndex: Integer; Index, Len: Integer): TMtxVecInt; overload; (* Compute X/Y*xyScale - Z *) function DivAndSub(const X, Y: TMtxVecInt; xyScale: integer; const Z: TMtxVecInt): TMtxVecInt; overload; (* Compute X/Y*xyScale - Z on sub array*) function DivAndSub(const X: TMtxVecInt; xIndex: Integer; const Y: TMtxVecInt; yIndex: Integer; xyScale: integer; const Z: TMtxVecInt; zIndex: Integer; Index, Len: Integer): TMtxVecInt; overload; (* Compute X/Y - Z*zScale *) function DivAndSub(const X, Y, Z: TMtxVecInt; zScale: integer): TMtxVecInt; overload; (* Compute X/Y - Z*zScale on sub array*) function DivAndSub(const X: TMtxVecInt; xIndex: Integer; const Y: TMtxVecInt; yIndex: Integer; const Z: TMtxVecInt; zIndex: Integer; zScale: integer; Index, Len: Integer): TMtxVecInt; overload; (* Compute X/Y - zScalar *) function DivAndSub(const X, Y: TMtxVecInt; Z: integer): TMtxVecInt; overload; (* Compute X/Y - zScalar on sub array*) function DivAndSub(const X: TMtxVecInt; xIndex: Integer; const Y: TMtxVecInt; yIndex: Integer; Z: integer; Index, Len: Integer): TMtxVecInt; overload; (* Compute X*xScale + Y*yScale *) function AddScaled(const X: TMtxVecInt; const xScale: integer; const Y: TMtxVecInt; const yScale: integer): TMtxVecInt; overload; (* Compute X*xScale + Y*yScale on sub arrays *) function AddScaled(const X: TMtxVecInt; xIndex: integer; const xScale: integer; const Y: TMtxVecInt; yIndex: integer; const yScale: integer; Index, Len: integer): TMtxVecInt; overload; (* Compute sqr(X*xScale + Y*yScale) *) function AddScaledSqr(const X: TMtxVecInt; const xScale: integer; const Y: TMtxVecInt; const yScale: integer): TMtxVecInt; overload; (* Compute sqr(X*xScale + Y*yScale) on sub arrays *) function AddScaledSqr(const X: TMtxVecInt; xIndex: integer; const xScale: integer; const Y: TMtxVecInt; yIndex: integer; const yScale: integer; Index, Len: integer): TMtxVecInt; overload; (* Compute sqr(X)*xScale + sqr(Y)*yScale *) function SqrAddScaled(const X: TMtxVecInt; const xScale: integer; const Y: TMtxVecInt; const yScale: integer): TMtxVecInt; overload; (* Compute sqr(X)*xScale + sqr(Y)*yScale on sub arrays *) function SqrAddScaled(const X: TMtxVecInt; xIndex: integer; const xScale: integer; const Y: TMtxVecInt; yIndex: integer; const yScale: integer; Index, Len: integer): TMtxVecInt; overload; (* Compute X*xScale + Y*yScale + Z*zScale *) function AddScaled(const X: TMtxVecInt; const xScale: integer; const Y: TMtxVecInt; const yScale: integer; const Z: TMtxVecInt; const zScale: integer): TMtxVecInt; overload; (* Compute X*xScale + Y*yScale + Z*zScale on sub arrays *) function AddScaled(const X: TMtxVecInt; xIndex: integer; const xScale: integer; const Y: TMtxVecInt; yIndex: integer; const yScale: integer; const Z: TMtxVecInt; zIndex: integer; const zScale: integer; Index, Len: integer): TMtxVecInt; overload; (* Compute X*xScale + Y*yScale + zScalar *) function AddScaledC(const X: TMtxVecInt; const xScale: integer; const Y: TMtxVecInt; const yScale: integer; const Z: integer): TMtxVecInt; overload; (* Compute X*xScale + Y*yScale + z on sub arrays *) function AddScaledC(const X: TMtxVecInt; xIndex: integer; const xScale: integer; const Y: TMtxVecInt; yIndex: integer; const yScale: integer; const Z: integer; Index, Len: integer): TMtxVecInt; overload; (* Compute X*xScale - Y*yScale - Z*zScale *) function SubScaled(const X: TMtxVecInt; const xScale: integer; const Y: TMtxVecInt; const yScale: integer; const Z: TMtxVecInt; const zScale: integer): TMtxVecInt; overload; (* Compute X*xScale - Y*yScale - zScalar *) function SubScaledC(const X: TMtxVecInt; const xScale: integer; const Y: TMtxVecInt; const yScale: integer; const Z: integer): TMtxVecInt; overload; (* Compute X*xScale - Y*yScale - Z*zScale on sub array*) function SubScaled(const X: TMtxVecInt; xIndex: integer; const xScale: integer; const Y: TMtxVecInt; yIndex: integer; const yScale: integer; const Z: TMtxVecInt; zIndex: integer; const zScale: integer; Index, Len: integer): TMtxVecInt; overload; (* Compute X*xScale - Y*yScale - zScalar on sub array*) function SubScaledC(const X: TMtxVecInt; xIndex: integer; const xScale: integer; const Y: TMtxVecInt; yIndex: integer; const yScale: integer; const Z: integer; Index, Len: integer): TMtxVecInt; overload; (* Compute X*Y*Z The following expression would also run at the same or higher speed, when passing X also for the Z parameter: X^2*Y *) function Mul(const X, Y,Z: TMtxVecInt): TMtxVecInt; overload; (* Compute X*Y*zScalar The following expression would also run at the same or higher speed, when passing X also for the Z parameter: X^2*zScalar *) function Mul(const X,Y: TMtxVecInt; const Z: integer): TMtxVecInt; overload; (* Compute X*Y*Z on sub array*) function Mul(const X: TMtxVecInt; xIndex: integer; const Y: TMtxVecInt; yIndex: integer; const Z: TMtxVecInt; zIndex: integer; Index, Len: integer): TMtxVecInt; overload; (* Compute X*Y*zScalar on sub array*) function Mul(const X: TMtxVecInt; xIndex: integer; const Y: TMtxVecInt; yIndex: integer; const Z: integer; Index, Len: integer): TMtxVecInt; overload; (* Compute X / (Y*Z) The following expression would also run at the same or higher speed, when passing Y also for the Z parameter: X / (Y^2) *) function Divide(const X, Y, Z: TMtxVecInt): TMtxVecInt; overload; (* Compute X / (Y*zScale) *) function DivideC(const X, Y: TMtxVecInt; const Z: integer): TMtxVecInt; overload; (* Compute X/( Y*Z ) on sub array*) function Divide(const X: TMtxVecInt; xIndex: integer; const Y: TMtxVecInt; yIndex: integer; const Z: TMtxVecInt; zIndex: integer; Index, Len: integer): TMtxVecInt; overload; (* Compute X / (Y*zScalar) on sub array*) function DivideC(const X: TMtxVecInt; xIndex: integer; const Y: TMtxVecInt; yIndex: integer; const Z: integer; Index, Len: integer): TMtxVecInt; overload; (* Compute X * Y * xyScale / Z The following expression would also run at the same or higher speed, when passing X also for the Y parameter: X^2 * xyScale/ Z *) function MulAndDiv(const X, Y: TMtxVecInt; const xyScale: integer; const Z: TMtxVecInt): TMtxVecInt; overload; (* Compute X * Y / zScalar *) function MulAndDiv(const X, Y: TMtxVecInt; const Z: integer): TMtxVecInt; overload; (* Compute xScalar / (Y*Z) *) function Divide(const X: integer; const Y, Z: TMtxVecInt): TMtxVecInt; overload; (* Compute X * Y xyScale / Z on sub array*) function MulAndDiv(const X: TMtxVecInt; xIndex: integer; const Y: TMtxVecInt; yIndex: integer; const xyScale: integer; const Z: TMtxVecInt; zIndex: integer; Index, Len: integer): TMtxVecInt; overload; (* Compute X * Y / zScalar on sub array*) function MulAndDiv(const X: TMtxVecInt; xIndex: integer; const Y: TMtxVecInt; yIndex: integer; const Z: integer; Index, Len: integer): TMtxVecInt; overload; (* Compute xScalar / (Y*Z) on sub array*) function Divide(const X: integer; const Y: TMtxVecInt; yIndex: integer; const Z: TMtxVecInt; zIndex: integer; Index, Len: integer): TMtxVecInt; overload; (* Compute (X*xScale + Y*yScale)*Z*zScale The following is also possible at the same or higher speed: X^2 * xScale + XY * yScale by passing X also for the Z parameter. *) function AddAndMul(const X: TMtxVecInt; xScale: integer; const Y: TMtxVecInt; yScale: integer; const Z: TMtxVecInt; zScale: integer): TMtxVecInt; overload; (* Compute (X*xScale + Y*yScale)*zScalar*) function AddAndMul(const X: TMtxVecInt; xScale: integer; const Y: TMtxVecInt; yScale: integer; Z: integer): TMtxVecInt; overload; (* Compute (X*xScale + Y*yScale)*Z*Scale on sub array*) function AddAndMul(const X: TMtxVecInt; xIndex: Integer; xScale: integer; const Y: TMtxVecInt; yIndex: Integer; yScale: integer; const Z: TMtxVecInt; zIndex: Integer; zScale: integer; Index, Len: Integer): TMtxVecInt; overload; (* Compute (X*xScale + Y*yScale)*zScalar on sub array*) function AddAndMul(const X: TMtxVecInt; xIndex: Integer; xScale: integer; const Y: TMtxVecInt; yIndex: Integer; yScale: integer; Z: integer; Index, Len: Integer): TMtxVecInt; overload; (* Compute (X*xScale + yScalar)*Z*zScale*) function AddAndMul(const X: TMtxVecInt; xScale: integer; Y: integer; const Z: TMtxVecInt; zScale: integer): TMtxVecInt; overload; (* Compute (X*xScale + yScalar)*zScalar*) function AddAndMul(const X: TMtxVecInt; xScale: integer; Y, Z: integer): TMtxVecInt; overload; (* Compute (X*xScale + yScalar)*Z*zScale on sub-array*) function AddAndMul(const X: TMtxVecInt; xIndex: integer; xScale: integer; Y: integer; const Z: TMtxVecInt; zIndex: integer; zScale: integer; Index, Len: integer): TMtxVecInt; overload; (* Compute (X*xScale + yScalar)*zScalar on sub array*) function AddAndMul(const X: TMtxVecInt; xIndex: integer; xScale: integer; Y, Z: integer; Index, Len: integer): TMtxVecInt; overload; (* Compute (X*xScale - Y*yScale)*Z*zScale*) function SubAndMul(const X: TMtxVecInt; xScale: integer; const Y: TMtxVecInt; yScale: integer; const Z: TMtxVecInt; zScale: integer): TMtxVecInt; overload; (* Compute (X*xScale - Y*yScale)*zScalar*) function SubAndMul(const X: TMtxVecInt; xScale: integer; const Y: TMtxVecInt; yScale: integer; Z: integer): TMtxVecInt; overload; (* Compute (X*xScale - Y*yScale)*Z*Scale on sub array*) function SubAndMul(const X: TMtxVecInt; xIndex: Integer; xScale: integer; const Y: TMtxVecInt; yIndex: Integer; yScale: integer; const Z: TMtxVecInt; zIndex: Integer; zScale: integer; Index, Len: Integer): TMtxVecInt; overload; (* Compute (X*xScale - Y*yScale)*zScalar on sub array*) function SubAndMul(const X: TMtxVecInt; xIndex: Integer; xScale: integer; const Y: TMtxVecInt; yIndex: Integer; yScale: integer; Z: integer; Index, Len: Integer): TMtxVecInt; overload; (* Compute (X*xScale - yScalar)*Z*zScale*) function SubAndMul(const X: TMtxVecInt; xScale: integer; Y: integer; const Z: TMtxVecInt; zScale: integer): TMtxVecInt; overload; (* Compute (X*xScale - yScalar)*zScalar*) function SubAndMul(const X: TMtxVecInt; xScale: integer; Y, Z: integer): TMtxVecInt; overload; (* Compute (X*xScale - yScalar)*Z*zScale on sub-array*) function SubAndMul(const X: TMtxVecInt; xIndex: integer; xScale: integer; Y: integer; const Z: TMtxVecInt; zIndex: integer; zScale: integer; Index, Len: integer): TMtxVecInt; overload; (* Compute (X*xScale - yScalar)*zScalar on sub array*) function SubAndMul(const X: TMtxVecInt; xIndex: integer; xScale: integer; Y, Z: integer; Index, Len: integer): TMtxVecInt; overload; (* Compute (X*Y)*xyScale + Z*zScale The following expression would also run at the same or higher speed, when passing X also for the Y parameter: X^2*xyScale + Z*zScale *) function MulAndAdd(const X: TMtxVecInt; const Y: TMtxVecInt; xyScale: integer; const Z: TMtxVecInt; zScale: integer): TMtxVecInt; overload; (* Compute (X*Y)*xyScale + zScalar*) function MulAndAdd(const X: TMtxVecInt; const Y: TMtxVecInt; xyScale: integer; Z: integer): TMtxVecInt; overload; (* Compute (X*Y)*xyScale + Z*zScale on sub array*) function MulAndAdd(const X: TMtxVecInt; xIndex: Integer; const Y: TMtxVecInt; yIndex: Integer; xyScale: integer; const Z: TMtxVecInt; zIndex: Integer; zScale: integer; Index, Len: Integer): TMtxVecInt; overload; (* Compute (X*Y)*xyScale + zScalar on sub array The following expression would also run at the same or higher speed, when passing X also for the Y parameter: X^2*xyScale + zScale *) function MulAndAdd(const X: TMtxVecInt; xIndex: Integer; const Y: TMtxVecInt; yIndex: Integer; xyScale: integer; Z: integer; Index, Len: Integer): TMtxVecInt; overload; (* Compute (X*yScalar) + zScalar*) function MulAndAdd(const X: TMtxVecInt; Y, Z: integer): TMtxVecInt; overload; (* Compute (X*yScalar) + zScalar*) function MulAndAdd(const X: TMtxVecInt; xIndex: integer; Y, Z: integer; Index, Len: integer): TMtxVecInt; overload; (* Compute (X*Y)*xyScale - Z*zScale*) function MulAndSub(const X: TMtxVecInt; const Y: TMtxVecInt; xyScale: integer; const Z: TMtxVecInt; zScale: integer): TMtxVecInt; overload; (* Compute (X*Y)*xyScale - zScalar*) function MulAndSub(const X: TMtxVecInt; const Y: TMtxVecInt; xyScale, Z: integer): TMtxVecInt; overload; (* Compute (X*Y)*xyScale - Z*zScale on sub array*) function MulAndSub(const X: TMtxVecInt; xIndex: Integer; const Y: TMtxVecInt; yIndex: Integer; xyScale: integer; const Z: TMtxVecInt; zIndex: Integer; zScale: integer; Index, Len: Integer): TMtxVecInt; overload; (* Compute (X*Y)*xyScale - zScalar on sub array*) function MulAndSub(const X: TMtxVecInt; xIndex: Integer; const Y: TMtxVecInt; yIndex: Integer; xyScale: integer; Z: integer; Index, Len: Integer): TMtxVecInt; overload; (* Compute X*yScalar - Z*zScale*) function MulAndSub(const X: TMtxVecInt; Y: integer; const Z: TMtxVecInt; zScale: integer): TMtxVecInt; overload; (* Compute X*yScalar - Z*zScale on sub array*) function MulAndSub(const X: TMtxVecInt; xIndex: integer; Y: integer; const Z: TMtxVecInt; zIndex: integer; zScale: integer; Index, Len: integer): TMtxVecInt; overload; (* Compute (X / Y)*xyScale + Z*zScale The following expression would also run at the same or higher speed, when passing Z also for the Y parameter: (X / Z) * xyScale + Z * zScale *) function DivAndAdd(const X: TMtxVecInt; const Y: TMtxVecInt; xyScale: integer; const Z: TMtxVecInt; zScale: integer): TMtxVecInt; overload; (* Compute (X / Y) * xyScale + zScalar*) function DivAndAdd(const X: TMtxVecInt; const Y: TMtxVecInt; xyScale: integer; Z: integer): TMtxVecInt; overload; (* Compute (X / Y)*xyScale + Z*zScale on sub array*) function DivAndAdd(const X: TMtxVecInt; xIndex: Integer; const Y: TMtxVecInt; yIndex: Integer; xyScale: integer; const Z: TMtxVecInt; zIndex: Integer; zScale: integer; Index, Len: Integer): TMtxVecInt; overload; (* Compute (X / Y) * xyScale + zScalar*) function DivAndAdd(const X: TMtxVecInt; xIndex: Integer; const Y: TMtxVecInt; yIndex: Integer; xyScale: integer; Z: integer; Index, Len: Integer): TMtxVecInt; overload; (* Compute (X / Y) * xyScale - Z y*) function DivAndSub(const X: TMtxVecInt; const Y: TMtxVecInt; xyScale: integer; const Z: TMtxVecInt; zScale: integer): TMtxVecInt; overload; (* Compute (X / Y) * xyScale - zScalar*) function DivAndSub(const X: TMtxVecInt; const Y: TMtxVecInt; xyScale: integer; Z: integer): TMtxVecInt; overload; (* Compute (X / Y) * xyScale - Z on sub array*) function DivAndSub(const X: TMtxVecInt; xIndex: Integer; const Y: TMtxVecInt; yIndex: Integer; xyScale: integer; const Z: TMtxVecInt; zIndex: Integer; zScale: integer; Index, Len: Integer): TMtxVecInt; overload; (* Compute (X / Y) * xyScale - zScalar on sub array*) function DivAndSub(const X: TMtxVecInt; xIndex: Integer; const Y: TMtxVecInt; yIndex: Integer; xyScale: integer; Z: integer; Index, Len: Integer): TMtxVecInt; overload; (*Copy object values. Copy each of Vec elements to the calling object. Size and precision properties of the calling object are set implicitly to match Vec object. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TMtxVecInt a,b,c; a = new TMtxVecInt(); b = new TMtxVecInt(); a.SetIt(new int[] {1,2,3,4}); // a = [1,2,3,4] i.e 1+2i ; 3+4i b.Copy(a); // b = [1,2,3,4] } } *) function Copy(const Src: TMtxVecInt): TMtxVecInt; overload; (*Copy Src elements [SrcIndex]..[SrcIndex+Len-1] in the calling object elements [Index]..[Index+Len-1]. Caèèing vector must be set explicitly. An exception is raised if array borders are overrun or underrun. *) function Copy(const Src: TMtxVecInt; const SrcIndex, Index, Len: integer): TMtxVecInt; overload; (* Copy each of Vec elements to the calling object. The Size property of the calling object is set implicitly to match Vec object. The storage precision of the calling object is set to DstIntPrecision. *) function Convert(const Src: TMtxVecInt; DstIntPrecision: TIntPrecision): TMtxVecInt; overload; (*Copy Src elements [SrcIndex]..[SrcIndex+Len-1] in the calling object elements [Index]..[Index+Len-1]. Calling vector must be set explicitly. An exception is raised if array borders are overrun or underrun. If the precision of the calling does not match DstIntPrecision, an exception will be raised. *) function Convert(const Src: TMtxVecInt; DstIntPrecision: TIntPrecision; SrcIndex, Index, Len: integer): TMtxVecInt; overload; (*Compares Value with all calling object elements.*) function IsEqual(const Value: integer): boolean; overload; (*Compares Value with all calling object elements.*) function IsEqual(const Value, Index, Len: integer): boolean; overload; (*Compares two matrices. Compares Mtx with the calling matrix and returns true if the matrices are equal (if all elements match in position and value). var A,B: TMtxInt; c: boolean; begin CreateIt(A,B); try A.SetIt(2,2,prInt32, [1,2, 2,4]); // 2x2, int matrix B.SetIt(2,2,prInt32, [1,2, 2,4]); // 2x2, real matrix c := A.Equal(B); // Check for an exact match finally FreeIt(A,B); end; end; *) function Equal(const Mtx: TMtxInt): boolean; overload; (*Compares two objects. True, if they are equal. Compares two objects and returns True, if they are equal. The method compares and properties and coresponding values. *) function IsEqual(const Vec: TMtxVecInt): boolean; overload; (*Compares Vec elements [VecIndex]..[VecIndex+Len-1] with calling object elements [Index]..[Index+Len-1].*) function IsEqual(const Vec: TMtxVecInt; const VecIndex, Index, Len: integer): boolean; overload; (*Maximum value. The maximum value of all calling object elements. The result is an integer value. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TMtxInt a; MtxVecInt.CreateIt(out a); try { a.SetIt(false, new double[] {1,2,3,4}); int b = a.Max(); // 4 } finally { MtxVecInt.FreeIt(ref a); } } } *) function Max(): integer; overload; (*Calculate the maximum value from calling object elements [Index]..[Index+Len-1]. The result is an integer value. An exception is raised if array borders are overrun. *) function Max(const Index, Len: integer): integer; overload; (*Minimum value. The minimum value of all calling object elements. The result is an integer value. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TMtxInt a; MtxVecInt.CreateIt(out a); try { a.SetIt(false, new double[] {1,2,3,4}); int b = a.Min(); // 1 } finally { MtxVecInt.FreeIt(ref a); } } } *) function Min(): integer; overload; (*Calculate the minimum value from calling object elements [Index]..[Index+Len-1]. The result is an integer value. An exception is raised if array borders are overrun. *) function Min(const Index, Len: integer): integer; overload; (*Calculate minimum and maximum in one procedure call. Returns calling vector maximum value. Returns calling vector monimum value.*) procedure MaxMin(out aMax, aMin: integer); overload; (*Calculate minimum and maximum in one procedure call. Returns calling vector elements [Index..Index+Len-1] maximum value. Returns calling vector elements [Index..Index+Len-1] minimum value. The starting index at which to start the search. The number of elements to search starting from Index. An exception is raised if array borders are overrun/underrun. *) procedure MaxMin(out aMax, aMin: integer; const Index, Len: integer); overload; (*Calculate the maximum value of all calling object elements. the maximum of all calling vector integer elements in-place. Stores maximum value index. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TMtxInt a; int ind; MtxVecInt.CreateIt(out a); try { a.SetIt(new int[] {1,2,3,4) int max = a.Max(out ind); //max=3, ind = 3 } finally { MtxVecInt.FreeIt(ref a); } } } *) function Max(out aIndex: integer): integer; overload; (*Calculate the maximum value of calling object elements [Index..Index+Len-1]. the maximum of calling vector integer elements [Index..Index+Len-1]. Returns maximum value index. The starting index at which to start the search. The number of elements to search starting from Index. An exception is raised if array borders are overrun/underrun. *) function Max(out aIndex: integer; const Index, Len: integer): integer; overload; (*Calculate the minimum value of all calling object elements. the minimum of all calling vector integer elements in-place. Stores minimum value index. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TMtxInt a; int ind; MtxVecInt.CreateIt(out a); try { a.SetIt(new int[] {1,2,3,4); int min = a.Min(out ind); //min=1, ind = 0 } finally { MtxVecInt.FreeIt(ref a); } } } *) function Min(out aIndex: integer): integer; overload; (*Calculate the maximum value of calling object elements [Index..Index+Len-1]. the minimum of calling vector integer elements [Index..Index+Len-1]. Returns minimum value index. The starting index at which to start the search. The number of elements to search starting from Index. An exception is raised if array borders are overrun/underrun. *) function Min(out aIndex: integer; const Index, Len: integer): integer; overload; (*Calculate minimum, maximum and their indices in one procedure call. Returns calling vector maximum value. Returns calling vector maximum value index. Returns calling vector monimum value. Returns calling vector minimum value index.*) procedure MaxMinIdx(out aMax, aMaxIdx, aMin, aMinIdx: integer); overload; (*Calculate minimum, maximum and their indices in one procedure call. Returns calling vector elements [Index..Index+Len-1] maximum value. Returns calling vector maximum value index. Returns calling vector elements [Index..Index+Len-1] minimum value. Returns calling vector minimum value index. The starting index at which to start the search. The number of elements to search starting from Index. An exception is raised if array borders are overrun/underrun. *) procedure MaxMinIdx(out aMax, aMaxIdx, aMin, aMinIdx: integer; const Index, Len: integer); overload; (*Applies median filter with size Mask to the calling vector elements [Index.. Index+Len-1]. Median filter is a nonlinear filter which replaces each element of the calling vector with the median value, calculated over the fixed range (mask) centered around that element. *) function Median(const MaskSize, Index, Len: integer): TMtxVecInt; overload; (*Applies median filter with size Mask to Src object elements [SrcIndex..SrcIndex+Len-1] and stores the result in the calling vector elements [Index..Index+Len-1]. Median filter is a nonlinear filter which replaces each element of the Src vector with the median value, calculated over the fixed range (mask) centered around that element and stores the result in the calling vector. *) function Median(const Src: TMtxVecInt; const MaskSize, SrcIndex, Index, Len: integer): TMtxVecInt; overload; (*Sizes the calling matrix to NewRows and NewCols. Copies the Src matrix values to the calling matrix. The elements outside the newly created matrix size are not referenced. *) function Resize(const Src: TMtxInt; NewRows, NewCols: integer): TMtxInt; overload; (*Resizes the matrix, while preserving the values in already allocated memory. Sets the property to NewRows, property to NewCols, while preserving the values in already allocated memory. var A,B: TMtxInt; begin CreateIt(A,B); try A.SetIt(2,2,[1,3, 2,4]); B.Resize(A,3,2); // B becomes: // [1,2,0, // 3,4,0]); finally FreeIt(A,B); end; end; *) function Resize(NewRows, NewCols: integer): TMtxInt; overload; (*Resize and transpose. Resizes the calling matrix to NewRows and NewCols and then copies the Src matrix values to the calling matrix. The elements outside the newly created matrix size are not referenced. At the end the method also transposes the Src matrix. All this operations are performed in one single pass. *) function ResizeAndTranspose(const Src: TMtxInt; NewRows, NewCols: integer): TMtxInt; (*A cyclic shift on vector elements in range. Performs cyclic shift on vector elements in specified range [Index..Index+Len-1]. The number of elements to shift is specified in the Offset parameter. Offset can be any integer number, positive or negative. An exception is raised if array borders are overrun/underrun. *) function Rotate(const Offset, Index, Len: integer): TMtxInt; overload; (*A cyclic shift on vector elements in range. Performs cyclic shift on source vector elements in specified range [SrcIndex .. SrcIndex+Len-1] and stores them to calling vector elements [Index .. Index+Len-1]. The number of elements to shift is specified in the Offset parameter. Offset can be any integer number, positive or negative. An exception is raised if array borders are overrun/underrun. *) function Rotate(const Src: TMtxVecInt; const Offset, SrcIndex, Index, Len: integer): TMtxInt; overload; (*Reverse vector elements. The method reverses Vec vector elements from [VecIndex].. [VecIndex+Len-1] and stores them in the calling vector from [Index]...[Index+Len-1] by using the following equation: This overload reverses calling vector elements in-place. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TMtxInt a; MtxVecInt.CreateIt(out a); try { a.SetIt(2,2, new int[] {1,2,3,4); a.Reverse(); // a = [2,1,3,4] } finally { MtxVecInt.FreeIt(ref a); } } } *) function Reverse(const Vec: TMtxVecInt; const VecIndex, Index, Len: integer): TMtxVecInt; overload; (*Reverses the calling object elements [Index]..[Index+Len-1]. An exception is raised if array borders are overrun. *) function Reverse(const Index, Len: integer): TMtxVecInt; overload; (*Divide all Src elements with Value elements and store result of division in the calling object and reminder in RemDst. Size and properties of the calling object and of RemDst are adjusted automatically. *) function RemDiv(Src, Value: TMtxVecInt; RemDst: TMtxVecInt): TMtxVecInt; overload; (*Divide all Src elements with Value and store result of division in the calling object and reminder in RemDst. Store the result of division in the calling object elements [Index]..[Index+Len-1] and remainder in to [RemDstIndex] .. [RemDstIndex+ Len-1]. Size and properties of the calling object and RemDst must be set explicitly. An exception is raised if is true and array borders are overrun/underrun. *) function RemDiv(Src, Value: TMtxVecInt; RemDst: TMtxVecInt; SrcIndex, ValueIndex, RemDstIndex, Index, Len: integer): TMtxVecInt; overload; (*Divide all Src elements with Value and store result of division in the calling object and reminder in RemDst. Size and properties of the calling object and of RemDst are adjusted automatically. *) function RemDiv(Src: TMtxVecInt; Value: integer; RemDst: TMtxVecInt): TMtxVecInt; overload; (*Divide all Src elements with Value and store result of division in the calling object and reminder in RemDst. Store the result of division in the calling object elements [Index]..[Index+Len-1] and remainder in to [RemDstIndex] .. [RemDstIndex+ Len-1]. Size and properties of the calling object and RemDst must be set explicitly. An exception is raised if is true and array borders are overrun/underrun. *) function RemDiv(Src: TMtxVecInt; Value: integer; RemDst: TMtxVecInt; SrcIndex, RemDstIndex, Index, Len: integer): TMtxVecInt; overload; (*Divide Src with all Value elements and store result of division in the calling object and reminder in RemDst. Size and properties of the calling object and of RemDst are adjusted automatically. *) function RemDiv(Src: integer; Value: TMtxVecInt; RemDst: TMtxVecInt): TMtxVecInt; overload; (*Divide Src with Value elements and store result of division in the calling object and reminder in RemDst. Store the result of division in the calling object elements [Index]..[Index+Len-1] and remainder in to [RemDstIndex] .. [RemDstIndex+ Len-1]. Size and properties of the calling object and RemDst must be set explicitly. An exception is raised if is true and array borders are overrun/underrun. *) function RemDiv(Src: integer; Value: TMtxVecInt; RemDst: TMtxVecInt; ValueIndex, RemDstIndex, Index, Len: integer): TMtxVecInt; overload; (*Write object header and values to a file. Write the header describing the calling object and the values array of the calling object to the file, specified by the FileName. If the file already exist, the data is overwritten by default. If Append is True, the data is appended to the end of the file. The data is always saved with IntPrecision precision. Note It is recommended you use a *.mtx extension when you're saving/loading matrix to/from file. Similarly, you can use a *.Vec extension when you're saving/loading vector to/from file. var Mtx: TMtxInt; begin CreateIt(Mtx); try Mtx.SetIt(2,2,[3,1,-1,5]); Mtx.SaveToFile('c:\test.mtx'); // Write info and header for Mtx to file finally FreeIt(Mtx); end; end; *) procedure SaveToFile(const FileName: string; const Append: boolean = False); (*Reads the header information and the values array content from the file. Reads the header information and the values array content from the file specified by FileName parameter. var b: TMtxInt; begin CreateIt(b); try b.LoadFromFile('c:\test.Vec'); // Read header and values for b finally FreeIt(b); end; end; *) procedure LoadFromFile(const FileName: string); (* Scatters Src elements defined with the Mask to the calling object. *) function ScatterByMask(const Src: TMtxVecInt; const Mask: TMtxVecInt; allow_resizing: boolean = False): TMtxVecInt; overload; (*Sets object values. Set object values. Method call does not change object's size, but it does check for array overrun. The elements of A array are copied to the calling object elements, starting at Index. The IntPrecision property of the calling object is not changed. *) function SetIt(const Rows, Cols: integer; const A: array of integer): TMtxInt; overload; (*Sets matrix values. Pass all elements in A array to the calling matrix. The and properties of the calling matrix are set to ARows and ACols and the property is set to aPrecision. An exception is raised if the matrix size(ARows*ACols) does not match the number of integer numbers in A. var A: TMtxInt; begin CreateIt(A); try A.SetIt(2,2,[1,2, 2,4]); finally FreeIt(A); end; end; *) function SetIt(const Rows, Cols: integer; aPrecision: TIntPrecision; const A: array of integer): TMtxInt; overload; (*Set all calling object elements to Value.*) function SetVal(const Value: integer): TMtxInt; overload; (*Set calling object elements [Index]..[Index+Len-1] to Value. An exception is raised if array borders are overrun/underrun. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TMtxInt a; MtxVecInt.CreateIt(out a); try { a.SetIt(2,2,new int[] {1,2,3,4); a.SetVal(5,2,2); // a = [1,1,5,5] } finally { MtxVecInt.FreeIt(ref a); } } } *) function SetVal(const Value, Index, Len: integer): TMtxVecInt; overload; (*Perform a shift on vector elements in range. Performs shift on vector elements in specified range [Index..Index+Len-1]. The number of elements to shift is specified in the Offset parameter. Offset can be any integer number, positive or negative. An exception is raised if array borders are overrun/underrun. *) function Shift(const Offset, Index, Len: integer): TMtxVecInt; overload; (*A shift on vector elements in range. Performs a shift on source vector elements in specified range [SrcIndex .. SrcIndex+Len-1] and stores them to calling vector elements [Index .. Index+Len-1]. The number of elements to shift is specified in the Offset parameter. Offset can be any integer number, positive or negative. An exception is raised if array borders are overrun/underrun. *) function Shift(const Src: TMtxVecInt; const Offset, SrcIndex, Index, Len: integer): TMtxVecInt; overload; (*Set all calling vector elements to zero.*) function SetZero(): TMtxVecInt; overload; (*Set calling vector elements [Index..Index+Len-1] to zero. An exception is raised if array borders are overrun/underrun. *) function SetZero(const Index, Len: integer): TMtxVecInt; overload; (*Sort calling vector elements [Index..Index+Len-1] in ascending order in-place.*) function SortAscend(const Index, Len: integer): TMtxVecInt; overload; (*Sort all calling vector elements in ascending order in-place. calling vector, storing sorted values. After execution stores sorted values indices. The starting index for the DstSortIdx parameter. The starting index at which to start the sort. The number of elements to sort starting from including zero-based Index. Size of DstSortIdx and calling vector are adjusted automatically. *) function SortAscend(const DstSortIdx: TMtxVecInt; const SortIdxIndex, Index, Len: integer): TMtxVecInt; overload; (*Sort calling vector elements [Index..Index+Len-1] in descending order in-place.*) function SortDescend(const Index, Len: integer): TMtxVecInt; overload; (*Sort all calling vector elements in descending order in-place. calling vector, storing sorted values. After execution stores sorted values indices. The starting index for the DstSortIdx parameter. The starting index at which to start the sort. The number of elements to sort starting from including zero-based Index. Size of DstSortIdx and calling vector are adjusted automatically. *) function SortDescend(const DstSortIdx: TMtxVecInt; const SortIdxIndex, Index, Len: integer): TMtxVecInt; overload; (*Sorts the elements in a matrix row(s) in ascending order. Sorts the elements in calling matrix row(s) in ascending order in-place. If the calling matrix is complex, then complex values are first compared by the absolute value and then by the argument. Note Each row is sorted independently from the other. var A: TMtxInt; begin CreateIt(A); try A.SetIt(2,2,[1,2, 4,2]); A.SortAscend; // A becomes: // [1,2] // [2,4] finally FreeIt(A); end; end; *) function SortAscend: TMtxInt; overload; (*Performs row based sort in ascending order. The Col parameter defines the column based on which the Rows are compared with each other.*) function SortAscend(Col: integer): TMtxInt; overload; (*Sorts the elements in a matrix row(s) in descending order. Sorts the elements in calling matrix row(s) in descending order in-place. If the calling matrix is complex, then complex values are first compared by the absolute value and then by the argument. Note Each row is sorted independently from the other. var A: TMtxInt; begin CreateIt(A); try A.SetIt(2,2,[1,2, 4,2]); A.SortDescend; // A becomes: // [2,1] // [4,2] finally FreeIt(A); end; end; *) function SortDescend: TMtxInt; overload; (*Performs row based sort in descending order. The Col parameter defines the column based on which the Rows are compared with each other.*) function SortDescend(Col: integer): TMtxInt; overload; (*Sums vector values. the sum of all calling object elements. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TMtxInt a; MtxVecInt.CreateIt(out a); try { a.SetIt(2,2,new int[] {1,3,-2}); int s = a.Sum(); // s = 2 } finally { MtxVecInt.FreeIt(ref a); } } } *) function Sum(): integer; overload; (*Returns the sum of calling object elements [Index]..[Index+Len-1]. An exception is raised if array borders are overrun/underrun. *) function Sum(const Index, Len: integer): integer; overload; (*Threshold bottom operation. Perform threshold operation on all calling object values. The Value parameter is a lower bound for threshold operation. All values smaller than Value will be replaced with Value. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TMtxInt a; MtxVecInt.CreateIt(out a); try { a.SetIt(2,2, new int[] {2, 0, 3, 4}); a.ThreshBottom(1); // a = [2,1,3,4] } finally { MtxVecInt.FreeIt(ref a); } } } *) function ThreshBottom(const Value: integer): TMtxVecInt; overload; (*Perform the threshold operation on calling object values [Index]..[Index+Len-1]. An exception is raised if array borders are overrun/underrun. *) function ThreshBottom(const Value: integer; Index, Len: integer): TMtxVecInt; overload; (*Perform threshold operation on all Src object values. Store the results in calling object. Size and properties of the calling object are adjusted automatically. *) function ThreshBottom(const Src: TMtxVecInt; const Value: integer): TMtxVecInt; overload; (*Perform a threshold operation on Vec elements [VecIndex]..[VecIndex+Len-1]. Store the results in the calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if is true and array borders are overrun/underrun. *) function ThreshBottom(const Vec: TMtxVecInt; const Value: integer; VecIndex, Index, Len: integer): TMtxVecInt; overload; (*Threshold top operation. Perform threshold operation on all calling object values. The Value parameter is an upper bound for threshold operation. All values bigger than Value will be replaced with Value. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TMtxInt a; MtxVecInt.CreateIt(out a); try { a.SetIt(2,2,new int[] {2, 0, 3, 4}); a.ThreshTop(1); // a = [1, 0, 1, 1] } finally { MtxVec.FreeIt(ref a); } } } *) function ThreshTop(const Value: integer): TMtxVecInt; overload; (*Perfrom the threshold operation on calling object values [Index]..[Index+Len-1]. An exception is raised if array borders are overrun/underrun. *) function ThreshTop(const Value: integer; Index, Len: integer): TMtxVecInt; overload; (*Perform threshold operation on all Src object values. Store the results in calling object. Size and properties of the calling object are adjusted automatically. *) function ThreshTop(const Src: TMtxVecInt; const Value: integer): TMtxVecInt; overload; (*Perform a threshold operation Vec elements [VecIndex]..[VecIndex+Len-1]. Store the results in the calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if is true and array borders are overrun/underrun. *) function ThreshTop(const Vec: TMtxVecInt; const Value: integer; VecIndex, Index, Len: integer): TMtxVecInt; overload; (*Threshold top and bottom centered around zero. Perform threshold operation on all calling object values. The Value parameter is an upper bound for threshold operation. All values smaller than Value will be replaced with Value and all values bigger than -Value will be replaced with -Value. The comparison checks if abs(Values[i]) < Value. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TMtxInt a; MtxVecInt.CreateIt(out a); try { a.SetIt(2,2, int[] {2,-1,3,4}); a.ThreshAbsLT(2); // a = [2,-2,3,4] } finally { MtxVec.FreeIt(ref a); } } } *) function ThreshAbsLT(const Value: Integer): TMtxVecInt; overload; (*Perfrom the threshold operation on calling object values [Index]..[Index+Len-1]. An exception is raised if array borders are overrun/underrun. *) function ThreshAbsLT(const Value: Integer; Index, Len: integer): TMtxVecInt; overload; (*Perform threshold operation on all Src object values. Store the results in calling object. Size and properties of the calling object are adjusted automatically. *) function ThreshAbsLT(const Src: TMtxVecInt; const Value: Integer): TMtxVecInt; overload; (*Perform a threshold operation Vec elements [VecIndex]..[VecIndex+Len-1]. Store the results in the calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if is true and array borders are overrun/underrun. *) function ThreshAbsLT(const Vec: TMtxVecInt; const Value: Integer; VecIndex, Index, Len: integer): TMtxVecInt; overload; (*Threshold top and bottom centered around zero. Perform threshold operation on all calling object values. The Value parameter is an upper bound for threshold operation. All values bigger than Value will be replaced with Value and all values smaller than -Value will be replaced with -Value. The comparison checks if abs(Values[i]) > Value. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TMtxInt a; MtxVec.CreateIt(out a); try { a.SetIt(2,2, int[] {2, -1, 3, 4}); a.ThreshAbsGT(2); // a = [2, -1, 2, 2] } finally { MtxVec.FreeIt(ref a); } } } *) function ThreshAbsGT(const Value: Integer): TMtxVecInt; overload; (*Perfrom the threshold operation on calling object values [Index]..[Index+Len-1]. An exception is raised if array borders are overrun/underrun. *) function ThreshAbsGT(const Value: Integer; Index, Len: integer): TMtxVecInt; overload; (*Perform threshold operation on all Src object values. Store the results in calling object. Size and properties of the calling object are adjusted automatically. *) function ThreshAbsGT(const Src: TMtxVecInt; const Value: Integer): TMtxVecInt; overload; (*Perform a threshold operation Vec elements [VecIndex]..[VecIndex+Len-1]. Store the results in the calling object elements [Index]..[Index+Len-1]. Size and properties of the calling object must be set explicitly. An exception is raised if is true and array borders are overrun/underrun. *) function ThreshAbsGT(const Vec: TMtxVecInt; const Value: Integer; VecIndex, Index, Len: integer): TMtxVecInt; overload; (*Threshold greater than and less than operation. Perform operation on all calling object values. The LTValue parameter is an lower bound for threshold operation. The GTValue parameter is an upper bound for threshold operation. All values less than LTLevel will be replaced with LTValue. All values bigger than GTLevel will be replaced with GTValue. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TMtxInt a; MtxVecInt.CreateIt(out a); try { a.SetIt(2,2, new int[] {20,1,30,40}); a.ThresholdGT_LT(23,34,10,5); // a = [20,5,34,34] } finally { MtxVecInt.FreeIt(ref a); } } } *) function ThresholdGT_LT (const GTLevel, GTValue, LTLevel, LTValue: Integer): TMtxVecInt; overload; (*Perfrom "greater than and less than" threshold operation on the calling object values in range [Index]..[Index+Len-1]. An exception is raised if array borders are overrun/underrun. *) function ThresholdGT_LT (const GTLevel, GTValue, LTLevel, LTValue: Integer; Index, Len: integer): TMtxVecInt; overload; (*Perform "greater than and less than" threshold operation on all Vec object values. Store the results in calling object. Size of the calling object is adjusted automatically. *) function ThresholdGT_LT (const Vec: TMtxVecInt; const GTLevel, GTValue, LTLevel, LTValue: Integer): TMtxVecInt; overload; (*Perform "greater than and less than" threshold operation on Vec elements from range [VecIndex]..[VecIndex+Len-1]. Store the results in the calling object elements [Index]..[Index+Len-1]. Size of the calling object must be set explicitly. An exception is raised if is true and array borders are overrun/underrun. *) function ThresholdGT_LT(const Vec: TMtxVecInt; const GTLevel, GTValue, LTLevel, LTValue: Integer; VecIndex, Index, Len: integer): TMtxVecInt; overload; (*Obtains a pointer to the integer value of the vector at Index. The function returns @Values[i]. Under .NET this is a pointer to unmanaged memory. *) function PValues1D(const Index: integer): PAPointer; (*Read values content from stream to object. Reads values content from SrcStream stream to calling objct. No other values describing the data type or length are read from the DstStream. Number type is defined by the Precision parameter, which can be obtained from method call. The function returns the number of bytes read. Note Use this method separately only, if you want user defined storage format. var b: TMtxInt; AStream: TFileStream; Precision: TPrecision; begin CreateIt(b); AStream := TFileStream.Create('C:\test.bin',fmOpenRead); try Precision := b.ReadHeader(AStream); // Read info for b b.ReadValues(AStream,Precision); // Read values of b finally AStream.Free; FreeIt(b); end; end; *) function ReadValues(const SrcStream: TStream; const aPrecision: TPrecision = prInteger): Int64; overload; (*Writes object Values content to a stream. Writes the calling object Values content to the DstStream stream. No other values describing the data type or length are written to the DstStream. Number type is defined by the Precision parameter, but only integer formats are accepted. Attempt to save single (float) precision or double precision will raise an exception. The paramateres must be the same as for the method. Use this method separately only, if you want user defined storage format. var b: TMtxInt; AStream: TFileStream; begin CreateIt(b); b.SetIt(2,2,[0,1,3,2]); AStream := TFileStream.Create('C:\test.Vec',fmCreate); try b.WriteHeader(AStream); // Write info for b b.WriteValues(AStream); // Write values of b finally AStream.Free; end; FreeIt(b); end; *) procedure WriteValues(DstStream: TStream; const aPrecision: TPrecision = prInteger); overload; (*Writes the header information for the calling vector to a stream. Writes the header information for the calling object to a DstStream stream. The header information contains information about object (size, type of values in Values array, ...) which all define the state of the object. Number type is defined by the Precision parameter. Attempt to save single precision or double precision will raise an exception. var b: TMtxInt; AStream: TFileStream; begin CreateIt(b); b.SetIt(2,2,[0,1,3,2]); AStream := TFileStream.Create('C:\test.bin',fmCreate); try b.WriteHeader(AStream); // Write info for b b.WriteValues(AStream); // Write values of b finally AStream.Free; FreeIt(b); end; end; *) procedure WriteHeader(DstStream: TStream; const aPrecision: TPrecision = prInteger); overload; (*Reads the header information from a stream to object. Reads the header information from a DstStream stream to calling object. The header information contains all necessary information defining the object. The function returns the precision in which the data was stored. This information is required for the method. var b: TMtxInt; AStream: TFileStream; Precision: TPrecision; begin CreateIt(b); AStream := TFileStream.Create('C:\test.bin',fmOpenRead); try Precision := b.ReadHeader(AStream); // Read info for b b.ReadValues(AStream,Precision); // Read values of b finally AStream.Free; FreeIt(b); end; end; *) function ReadHeader(const SrcStream: TStream): TPrecision; overload; (*Convert strings to integers and store them in the Values array. Convert strings in aList to an integer number and stores them in the Values array of the calling matrix. property is set to aList.Count. and propertes are auto-detected. Complex numbers must follow the format: a+bi. All strings must have the same number of columns (numbers). Columns must be separated with a Delimiter. By default the delimiter is the tab charachter. var a,b: TMtxInt; begin CreateIt(a,b); try a.SetIt(2,2,[1,2,3,4]); a.Cos; b.Size(a); b.SetVal(1); a.Add(b); Richedit1.Clear; Memo1.Clear; a.ValuesToStrings(Richedit1.Lines); b.ValuesToStrings(Richedit1.Lines); a.ValuesToStrings(Memo1.Lines); b.ValuesToStrings(Memo1.Lines); Memo1.Lines.SaveToFile('C:\Test.txt'); Memo1.Lines.LoadFromFile('C:\Test.txt'); a.StringsToValues(Memo1.Lines); finally FreeIt(a,b); end; end; *) function StringsToValues(const aList: TStrings; const Delimiter: string = kTab): TMtxInt; overload; (*Convert strings from [ListIndex]..[ListIndex+ListLen-1] in aList to integers. Store them in the Values array of the calling matrix, starting from element [Row,Cols]. The size of the calling matrix is not changed. If array bounds are overrun an exception is raised. Complex numbers must follow the format: a+bi. *) function StringsToValues(const aList: TStrings; const ListIndex, ListLen, Row,Col: Integer; Delimiter: string = kTab): TMtxInt; overload; (*Converts the content of the matrix Values array to a list of strings. Convert all elements of the calling matrix to strings with text delimiter Delimiter and store them in aList, by using the Add method of TStrings object. Set Align to have columns aligned left or right when using fixed width font (like Courier New). Specifiy Headers to be "true", if row and column labels are to be printed. Performance note: This routine will be exceedingly slow, if TRichEdit.Lines or TMemo.Lines are passed as a parameter for dstList. Use TStringList or StringList types and then call TMemo.Lines.AddStrings(yourList) for best results. procedure TForm1.Button1Click(Sender: TObject); var a,b: TMtxInt; begin CreateIt(a,b); try a.SetIt(2,2,[1,2,3,4]); a.Cos; b.Size(a); b.SetVal(1); a.Add(b); Richedit1.Clear; Memo1.Clear; a.ValuesToStrings(Richedit1.Lines); b.ValuesToStrings(Richedit1.Lines); a.ValuesToStrings(Memo1.Lines); b.ValuesToStrings(Memo1.Lines); Memo1.Lines.SaveToFile('C:\Test.txt'); Memo1.Lines.LoadFromFile('C:\Test.txt'); a.StringsToValues(Memo1.Lines); finally FreeIt(a,b); end; end; *) procedure ValuesToStrings(const dstList: TStrings; const Delimiter: string = kTab; const Align: TFixedTextAlign = ftaNone; const Headers: boolean = false; const ColumnWidth: integer = -1); overload; (*Convert calling matrix elements, starting with [Row,Col] and up to [Row+RowCount-1,Col+ColCount-1] elements to strings. Use text Delimiter for columns and store the resulting strings in aList starting at ListIndex. If aList is not large enough, the method will use the Add method of aList object. Existing items will be overwritten. Set Align to have columns aligned left or right when using fixed width font (like Courier New). Specifiy Headers to be "true", if row and column labels are to be printed. Performance note: This routine will be exceedingly slow, if TRichEdit.Lines or TMemo.Lines are passed as a parameter for dstList. Use TStringList or StringList types and then call TMemo.Lines.AddStrings(yourList) for best results. *) procedure ValuesToStrings(const dstList: TStrings; const ListIndex, Row, Col, RowCount, ColCount: integer; const Delimiter: string = kTab; const Align: TFixedTextAlign = ftaNone; const Headers: boolean = false; const ColumnWidth: integer = -1); overload; (*Converts all calling matrix elements to string.*) procedure ValuesToText(out Text: String; Delimiter: string = kTab);overload; (*Converts Row..Col to Row+RowCount..Col+ColCount matrix elements to string.*) procedure ValuesToText(out Text: String; Row,Col,RowCount,ColCount: integer; Delimiter: string = kTab); overload; function TextToValues(Text: String; Delimiter: String = kTab): TMtxInt; (*Returns content as a string. Values will be separated by line breaks. *) function ToString: string; (*Parses string content as vector. Values need to be separated by line breaks. For other parsing options call StringToValues. The Parse method works in pair with the ToString method both meant to be a reverse of the other, but do not preserve any other property of the vector except only values. Use SaveToStream/LoadFromStream methods for binary storage option, which uses up to 10x less memory and is a lot faster to save and load. *) class function Parse(const Src: string): MatrixInt; static; function DataIndex(aRow, aCol: integer; aPrecision: TIntPrecision): integer; overload; function DataIndex(aRow, aCol: integer): integer; overload; (*Sizes the matrix according to bit storage required.*) function BitSize(const bitRows, bitCols: integer): TMtxInt; (*Copies matrix values to a 2D array. Copies all matrix values to a 2D array. *) procedure CopyToArray(var Dst: T2DIntegerArray); overload; (*Copies all matrix values to a 2D array.*) procedure CopyToArray(var Dst: T2DSmallIntArray); overload; (*Copies all matrix values to a 2D array.*) procedure CopyToArray(var Dst: T2DByteArray); overload; (*Copies the matrix from a 2D array. Sizes the matrix to match the size of the 2D array and copies all the values. *) procedure CopyFromArray(const Src: T2DIntegerArray); overload; (*Sizes the matrix to match the size of the 2D array and copies all the values.*) procedure CopyFromArray(const Src: T2DSmallIntArray); overload; (*Sizes the matrix to match the size of the 2D array and copies all the values.*) procedure CopyFromArray(const Src: T2DByteArray); overload; (*Sizes the Dst array to match the matrix. Sizes the Dst array to match the size of the matrix. *) procedure SizeToArray(var Dst: T2DIntegerArray); overload; (*Sizes the Dst array to match the size of the matrix.*) procedure SizeToArray(var Dst: T2DSmallIntArray); overload; (*Sizes the Dst array to match the size of the matrix.*) procedure SizeToArray(var Dst: T2DByteArray); overload; (*Sets the size of matrix. Set the calling matrix properties: * = ARows, * = ACols Calling the Size method does not preserve the contents of the matrix. Use the Resize method, if you want to preserve existing values. Note The Size method performs an out-of-memory safe resize, if the matrix already has memory allocated. This prevents out of memory message for example when redefining the size of the matrix from single column to single row: A.Rows := 10000; // matrix size = 0 A.Cols := 1; // matrix size = 10000 // ... A.Cols := 10000; // matrix size = 100 000 000 (problems here) A.Rows := 1; // matrix size = 10 000 var A: TMtxInt; begin CreateIt(A); try A.Size(2,1); // 2x1 integer matrix A.SetZero; // A becomes: // [0] // [0] finally FreeIt(A); end; end; *) function Size(const ARows, ACols: integer; const aPrecision: TIntPrecision): TMtxInt; overload; (*Specifies size of an integer matrix. The Value of IntPrecision property is preserved. *) function Size(const ARows, ACols: integer): TMtxInt; overload; (*Size the object. Assigns the size of the Src object to the calling object and changes the IntPrecision to new value. *) function Size(const Src: TMtxVecBase; const aPrecision: TIntPrecision): TMtxInt; overload; (*Size the object. Assigns the size of the Src object to the calling object. If both objects have a matching , , properties, only the property of the calling object will changed, while all other properties describing the size of the object will be preserved. *) function Size(const Src: TMtxVecBase): TMtxInt; overload; (*Returns the 1D index in to the matrix. Returns: Row*Mtx.Cols + Col *) function IndexOf(const Row, Col: integer): integer; (*Adopts a pointer to one dimensional array. Addopts a pointer to AArray array. The method sets the calling matrix property to IsComplex, to ARows, to ACols and Values1D and CValues1D to Pointer(AArray). Note You must call the method, before you destroy the matrix. Use this method to save a copy operation. You should be very careful never to resize the calling matrix while it contains the adopted memory or call any routines that would require the matrix to reallocate the memory. *) procedure Adopt(const AArray: PAPointer; const ARows, ACols: integer; const aIntPrecision: TIntPrecision); overload; (*Exchange matrix columns. Exchange the i-tj and j-th columns of the calling matrix in-place. An exception is raised if matrix bounds are overrun. *) function ColExchange(i, j: integer): TMtxInt; overload; (*Permute the columns of the Src matrix. The parameter PermuteIdx contains indexes of columns P[i] to which column at index "i" is to be moved. The result of the permutation is stored in the calling matrix. Only entire matrix can be copied. *) function ColPermute(const Src: TMtxInt; const PermuteIdx: TVecInt): TMtxInt; overload; (*Permute the Rows of the Src matrix. The parameter PermuteIdx contains indexes of columns P[i] to which row at index "i" is to be moved. The result of the permutation is stored in the calling matrix. Only entire matrix can be copied. *) function RowPermute(const Src: TMtxInt; const PermuteIdx: TVecInt): TMtxInt; overload; (*Concatenate an array of matrices to single matrix. Concatenate an array of matrices to form one big matrix and store the result in the calling matrix. The dimensions of the block matrices in the Src array must match, to form the new matrix. The block matrices must be all real or all complex, otherwise an exception will be raised. You must specify Arows*ACols block matrices in the Src array. The , and properties of the calling matrix are adjusted automatically. var A,B,C,D,E: TMtxInt; begin CreateIt(A,B,C,D); CreateIt(E); try A.Size(2,2); B.Size(A); C.Size(A); D.Size(A); E.Concat(2,2[A,B C,D]); // form one 4x4 matrix finally FreeIt(E); FreeIt(A,B,C,D); end; end; *) function Concat(ARows, ACols: integer;const Src: array of TMtxInt): TMtxInt; overload; (*Concenates an array of matrices horizontally. Concenate the Src matrices horizontally and store the results in the calling matrix. The , and properties of the calling matrix are adjusted automatically. An exception is raised if any of the Src matrices Complex or Rows property does not match. var A,B,C,D,E: TMtxInt; begin CreateIt(A,B,C,D); CreateIt(E); try A.Size(2,2); B.Size(A); E.Size(4,4); // overwrite the lower part of the E matrix // with values from A and B E.ConcatHorz(2,2,[A,B]); //E becomes: //[E11 E12 E13 E14] //[E21 E22 E23 E24] //[A11 A12 B11 B12] //[A21 A22 B21 B22] finally FreeIt(E); FreeIt(A,B,C,D); end; end; *) function ConcatHorz(const Src: array of TMtxInt): TMtxInt; overload; (*Concenate the Src matrices horizontally and store the results in the calling matrix. The DestRow and DestCol parameters indicate the starting position (in the calling matrix) for concenating. An exception is raised, if the calling matrix array bounds are overrun. An exception is raised, if any of the Src matrices Complex or Rows properties do not match. *) function ConcatHorz(DestRow, DestCol: integer;const Src: array of TMtxInt): TMtxInt; overload; (*Concenates an array of matrices vertically. Concenate the Src matrices vertically and store the results in calling matrix. The , and properties of the calling matrix are adjusted automatically. An exception is raised, if any of the Src matrices Complex or Cols properties do not match. var A,B,C,D,E: TMtxInt; begin CreateIt(A,B,C,D); CreateIt(E); try A.Size(1,2); B.Size(A); E.Size(4,4); // overwrite the lower part of the E matrix // with values from A and B E.ConcatVert(2,2,[A,B]); // E becomes: //[E11 E12 E13 E14] //[E21 E22 E23 E24] //[A11 A12 E33 E34] //[B11 B12 E43 E44] finally FreeIt(E); FreeIt(A,B,C,D); end; end; *) function ConcatVert(const Src: array of TMtxInt): TMtxInt; overload; (*Concenate the Src matrices vertically and store the results in calling matrix. The DestRow and DestCol parameters indicate the starting position (in the calling matrix) for concatenating. An exception is raised, if the calling matrix array bounds are overrun. An exception is raised, if any of the Src matrices Complex or Cols properties do not match. *) function ConcatVert(DestRow, DestCol: integer;const Src: array of TMtxInt): TMtxInt; overload; (*Copy the Mtx elements [MtxRow,MtxCol]..[MtxRow+NrRows-1,MtxCol+NrCols-1] to the calling matrix elements [Row,Col],,[Row+NrRows-1,Col+NrCols-1]. An exception is raised if is true and bounds are overrun. If Transpose is true, the matrix is transposed as well. *) function Copy(const Mtx: TMtxInt; MtxRow, MtxCol, Row, Col, NrRows, NrCols: integer; Transpose: boolean = false): TMtxInt; overload; (*Copies values from vector to a matrix. Copy all Vec elements to the calling matrix. Set the calling matrix property to NrRows. Set the calling matrix property to Vec.Length div NrRow (Length = Rows*Cols). The calling matrix property is adjusted automatically. An exception is raised if Vec.Length mod NrRows <> 0. var A: TMtxInt; v: TVecInt; begin CreateIt(A); Create(v); try v.SetIt([1, 0, 2, -1, 5, 1.2]) ; A.CopyVec(v); finally FreeIt(A); FreeIt(v); end; end; *) function CopyVec(const Vec: TVecInt; NrRows: Integer): TMtxInt; overload; (*Copy Vec elements [VecIndex]..[VecIndex+Len-1] to the calling matrix elements starting with [Row,Col]. An exception is raised if is true and bounds are overrun or if properties of the calling matrix and Vec do not match. *) function CopyVec(const Vec: TVecInt; VecIndex, Len, Row, Col: Integer): TMtxInt; overload; (*Cumulative sum for each of the matrix columns. Calculate the cumulative sum for each of the calling matrix columns in-place. Function performs no overflow checking. It is users responsibility to ensure that the sum does not overflow the range of the used integer storage type. var Mtx: TMtxInt; begin Mtx := TMtxInt.Create; try Mtx.Size(3,2,[1,2, 2,5, 3,1]); Mtx.CumSum; // Mtx becomes: // 1, 2 // 3, 7 // 6, 8 finally Mtx.Free; end; end; *) function CumSum: TMtxInt; overload; (*Calculate the cumulative sum for each of the X matrix columns. Store the results in calling matrix. The , and properties of the callig matrix are adjusted implicitly to match those of Mtx matrix. *) function CumSum(const Mtx: TMtxInt): TMtxInt; overload; (*Disowns a pointer to an array from matrix Values1D. The method does the opposite of the method. It will set the AArrays to Pointer(Values), ARows and ACols to matrix's and and IsComplex to matrix property. Use the Disown method to "disconnect" AArray from the TMtx.Values1D. Disown sets Values1D and CValues1D array pointers to nil and Rows, Cols properties to ACols, but without freeing the allocated memory. The allocated memory can be disowned only, if it was adopted with a call to the method. *) procedure Disown(out AArray: PAPointer; out ARows, ACols: integer; out aIntPrecision: TIntPrecision); overload; (*Disowns a pointer to an array from calling matrix Values1D. It dismisses the Values, Values1D, CValues1D array and sets the and to zero. *) procedure Disown; overload; (*Sets the matrix diagonal to values from the vector. Sets the k-th diagonal of the calling matrix to values from from the Vec object. If k = 0 then the main diagonal matrix is set, if k < 0 then the k-th subdiagonal matrix is set and if k > 0 the then the k-th super diagonal is set. The matrix must be large enough to hold diagonal or an exception is raised. var A: TMtxInt; D: TVecInt; begin CreateIt(A); CreateIt(D); try A.SetIt(2,2,[1,1, 1,2]); D.SetIt([3,4]); A.Diag(D,0); // A becomes: // [3,1] // [1,4] finally FreeIt(D); FreeIt(A); end; end; *) function Diag(const Vec: TVecInt; k: integer): TMtxInt; overload; (*Constructs an eye matrix. Construct an eye matrix with ones only on main diagonal and zeros elsewhere. The number of Rows and columns of an eye matrix are set by ARows and ACols parameters. The property of an eye matrix is set by aIntPrecision parameter. var A,B: TMtxInt; begin CreateIt(A); try A.Eye(3,3); // ... finally FreeIt(A); end; end; *) function Eye(ARows,ACols: integer; aIntPrecision: TIntPrecision = prInt32): TMtxInt; overload; (*Flips the matrix elements horizontally. Flip calling matrix elements horizontally - element [row, j] = element [row, Cols-j]. This operation is performed on all calling matrix Rows. var A,B: TMtxInt; begin CreateIt(A,B); try A.SetIt(2,2,[1,2, 2,4]); // 2x2, not complex matrix B.FlipHor(A); // B becomes: // [2,1] // [4,2] finally FreeIt(A,B); end; end; *) function FlipHor: TMtxInt; overload; (*Flip all SrcMtx matrix elements horizontally. Store the results in the calling matrix. The flip operation is performed on all SrcMtx matrix Rows. The , and properties of callign matrix are adjusted automatically. *) function FlipHor(const SrcMtx: TMtxInt): TMtxInt; overload; (*Flips the matrix elements vertically Flip calling matrix elements vertically - element [j, col] = element [Rows-j, col]. This operation is performed on all calling matrix columns. var A,B: TMtxInt; begin CreateIt(A,B); try A.SetIt(2,2,[1,2, 2,4]); // 2x2, not complex matrix B.FlipVert(A); // B becomes: // [2,4] // [1,2] finally FreeIt(A,B); end; end; *) function FlipVer: TMtxInt; overload; (*Flip all SrcMtx matrix elements vertically. Store the results in the calling matrix. The flip operation is performed on all SrcMtx matrix columns. The , and properties of callign matrix are adjusted automatically. *) function FlipVer(const SrcMtx: TMtxInt): TMtxInt; overload; (*The Kronecker product between two vectors. Calculates the Kronecker product between Vec1 and Vec2 and stores the result in the calling matrix. The , and properties of calling matrix are set automatically. var A: TMtxInt; V1,V2: TVecInt; begin CreateIt(A); CreateIt(V1,V2); try V1.SetIt([1,2,3]); V2.SetIt([4,5,6]); A.Kron(V1,V2); // A becomes: // [4 5 6] // [8 10 12] // [12 15 18] finally FreeIt(A); FreeIt(V1,V2); end; end; *) function Kron(const Vec1, Vec2: TVecInt): TMtxInt; overload; (*Constructs lower triangular matrix. The method uses Mtx matrix to construct a lower triangular matrix. The results are stored in the calling matrix. If the ZeroLower parameter is true then the calling matrix superdiagonal elements will be set to zero - otherwise the superdiagonal elements will not be initialized. If the Diagonal boolean parameter is true then the Mtx matrix main diagonal elements will be copied to the calling matrix main diagonal elements. If the Diagonal parameter is false, the calling matrix main diagonal elements will be set to zero. var A,B: TMtxInt; begin CreateIt(A,B); try A.SetIt(2,1,[1,2, 2,4]); // 2x2, not complex matrix B.LowerTriangle(A,True,True); // B becomes: // [1,0, // [2,4] finally FreeIt(A,B); end; end; *) function LowerTriangle(const Mtx: TMtxInt; ZeroUpper, Diagonal: boolean): TMtxInt; overload; (*Matrix array multiplication. Multiplies elements in Mtx matrix with the elements in the calling matrix (array multiplication) and stores the results in calling matrix. The , and properties of both matrices must match, otherwise an exception is raised. var A,B,C: TMtxInt; begin CreateIt(A,B,C); try A.SetIt(2,2,[1,2, 2,4]); B.SetIt(2,2,[1,2, 2,4]); C.MulElem(A,B); // C becomes: // [1, 4, // 4,16] finally FreeIt(A,B,C); end; end; *) function MulElem(const Mtx: TMtxInt): TMtxInt; overload; (*Multiplies elements in Mtx1 matrix with the elements in Mtx2 matrix (array multiplication) and stores the results in calling matrix. The , and properties of calling matrix are set implicitly to match those of Mtx1 and Mtx2 matrices. Mtx1 and Mtx2 Rows, Cols, and Complex properties must be the same, otherwise an excetion is raised. raised. *) function MulElem(const Mtx1, Mtx2: TMtxInt): TMtxInt; overload; (*Resets object properties to default values. Resets object properties to default values. The method is used by the Object cache management to reset the properties of the object freed with a call to . *) procedure Reset; overload; (*Rotates matrix Rows 90 degrees clockwise. Rotates all calling matrix Rows 90 degrees clockwise in-place (check the scheme bellow). Note This operation differs from the operation. var A,B: TMtxInt; begin CreateIt(A,B); A.SetIt(2,2,[1,3, 2,4]); B.Rotate90(A); FreeIt(A,B); end; *) function Rotate90: TMtxInt; overload; (*Rotate all Mtx matrix Rows 90deg clockwise. Store the results in calling matrix. The , and properties of the calling matrix are adjusted automatically. *) function Rotate90(const Mtx: TMtxInt): TMtxInt; overload; (*Exchanges two matrix Rows. Exchange the i-th and j-th Rows of the calling matrix in-place. An exception is raised if matrix bounds are overrun. The indexes i and j are zero based. (the first row has index 0). var A,B: TMtxInt; begin CreateIt(A,B); try A.SetIt(2,2,[1,3, 2,4]); B.RowExchange(0,1); // B becomes: // [2,4, // 1,3]); finally FreeIt(A,B); end; end; *) function RowExchange(i, j: integer): TMtxInt; overload; (*Copies values from vector to matrix column. Copy all Vec elements to the calling matrix Col column. An exception is raised, if array bounds are overrun. var A: TMtxInt; V: TVecInt; begin CreateIt(A); CreateIt(V); try A.Size(2,1,True); V.SetIt([1,2, 2,4]); // complex vector A.SetCol(V,0); finally FreeIt(V); FreeIt(A); end; end; *) function SetCol(const Vec: TMtxVecInt; Col: integer): TMtxInt; overload; (*Copy vector Vec elements [VecIndex]..[VecIndex+Len-1] to the calling matrix elements [Row,Col]..[Row+Len-1,Col]. An exception is raised if condition checking is enabled and array bounds are overrun. *) function SetCol(const Vec: TMtxVecInt; VecIndex, Row, Col, Len: integer): TMtxInt; overload; (*Copies values from vector to matrix row. Copy all Vec elements to the calling matrix Row row. The property of the calling matrix is adjusted automatically. An exception is raised, if array bounds are overrun. var A: TMtxInt; V: TVecInt; begin CreateIt(A); CreateIt(V); try A.Size(1,2); V.SetIt([1,2, 2,4]); A.SetCol(V,0); finally FreeIt(V); FreeIt(A); end; end; *) function SetRow(const Vec: TMtxVecInt; Row: integer): TMtxInt; overload; (*Copy vector Vec elements [VecIndex]..[VecIndex+Len-1] to the calling matrix elements [Row,Col]..[Row,Col+Len-1]. An exception is raised if condition checking is enabled and array bounds are overrun. *) function SetRow(const Vec: TMtxVecInt; VecIndex, Row, Col, Len: integer): TMtxInt; overload; (*Initializes matrix values to zero. Sets the calling matrix elements [Row,Col]..[ToRow,ToCol] to zero. An exception is raised if is true and array bounds are overrun. *) function SetZero(Row, Col, ToRow, ToCol: integer): TMtxInt; overload; (*Initializes matrix values to Value. Sets the calling matrix elements [Row,Col]..[ToRow,ToCol] to Value. An exception is raised if is true and array bounds are overrun. *) function SetVal(const Value: integer; Row, Col, ToRow, ToCol: integer): TMtxInt; overload; (*Saves matrix data to MatrixMarket ASCII file format. Saves matrix data to MatrixMarket ASCII file format. *) procedure SaveToMatrixMarketFile(FileName: string); (*Splits matrix in blocks. Splits he calling matrix in blocks. Example: [ A B ] [ C D ] where A,B,C,D are matrices of size 2x2 and the calling matrix is of size 4x4. ARows and ACols define the number of Rows and columns of the block based matrix. The matrices passed in the dst array to be filled with values from the calling matrix, must already have matching size and complex properties to cover the calling matrix or an exception will be raised. var A,B,C,D,E: TMtxInt; begin CreateIt(A,B,C,D); CreateIt(E); try A.Size(2,2); B.Size(A); C.Size(A); D.Size(A); E.SetIt(4,4,[1,2,3,4 5,6,7,8 9,1,2,3 4,5,6,7]); E.Split(2,2,[A,B, C,D]); // A becomes: // [1,2, // 5,6] // B becomes: // [3,4, // 7,8] // C becomes: // [9,1, // 4,5] // D becomes: // [2,3, // 6,7] finally FreeIt(A,B,C,D); FreeIt(E); end; end; *) procedure Split(ARows, ACols: integer;const Dst: array of TMtxInt); (*Calculates the sum of each of the calling matrix columns. Calculates the sum of each of the calling matrix columns and stores the results in Dst vector. The and properties of the Dst vector are adjusted automatically. var A: TMtxInt; V: TVecInt; begin CreateIt(A); CreateIt(V); A.Size(2,2,[1,5, 2,3]); A.SumCols(V); // V = [3,8] FreeIt(V); FreeIt(A); end; *) procedure SumCols(const Dst: TVecInt); overload; (*Calculates the sum of each of the calling matrix Rows. Calculates the sum of each of the calling matrix Rows and stores the results in Dst vector. The and properties of the Dst vector are adjusted automatically. var A: TMtxInt; V: TVecInt; begin CreateIt(A); CreateIt(V); A.Size(2,2, [1,2, 2,4]); A.SumRows(V); // V = [3,6] FreeIt(V); FreeIt(A); end; *) procedure SumRows(const Dst: TVecInt); overload; (*Calculates the tensor product of two vectors. Calculates the tensor product of Vec1 and Vec2 vectors and stores the results in the calling matrix. The property is set to Vec1. and property is set to Vec2.. The property of the calling matrix is adjusted automatically. var Vec1,Vec2: TVecInt; V: TMtxInt; begin CreateIt(Vec1,Vec2); CreateIt(V); try Vec1.Size(3); Vec1.SetIt([0,2,3] Vec2.Copy(Vec1); V.TensorProd(Vec1,Vec2); // V becomes: // [0,0,0] // [0,4,6] // [0,6,9] finally FreeIt(Vec1,Vec2); FreeIt(V); end; end; *) function TensorProd(const Vec1, Vec2: TVecInt): TMtxInt; overload; (*Transposes matrix. Transposes calling matrix in-place. Instead of using transpose directly, try using the parameter of many TMtxInt methods. If this operation can not be avoided try using the not-in-place version (see bellow) or see the method. var A: TMtxInt; begin CreateIt(A); A.Size(2,1,True); // 2x1 complex matrix A.SetVal(Cplx(3,4)); A.Transp; FreeIt(A); end; *) function Transp: TMtxInt; overload; (*Transpose the Mtx matrix. Write the results to the calling matrix. The , and properties of the calling matrix are adjusted automatically. *) function Transp(const Mtx: TMtxInt): TMtxInt; overload; (*Constructs upper triangular matrix. The method uses Mtx matrix to construct an upper triangular matrix. The results are stored in the calling matrix. If the ZeroLower parameter is true then the calling matrix subdiagonal elements will be set to zero - otherwise the subdiagonal elements will not be initialized. If the Diagonal boolean parameter is true then the Mtx matrix main diagonal elements will be copied to the calling matrix main diagonal elements. If the Diagonal parameter is false, the calling matrix main diagonal elements will be set to zero. var A,B: TMtxInt; begin CreateIt(A,B); A.SetIt(2,1,[1,2, 2,4]); // 2x2, not complex matrix B.UpperTriangle(A,True,True); // B becomes: // [1,2, // [0,4] FreeIt(A,B); end; *) function UpperTriangle(const Mtx: TMtxInt; ZeroLower, Diagonal: boolean): TMtxInt; overload; public (*Allows sizing the internal storage to accomodate desired number of bits. Use BitPack and BitUnpack for much faster access to bit data or Bits[i] property for individual bit access. Setting BitCount will also call the Size method. The Length of the internal arrays will be adjusted so that all bits can be stored with padding of the last (32bit, 16bit or 8bit integer) element. The value of BitCount, which is not an integer multiple of the IntPrecision is preserved only by certain methods where applicable and where it is not ambiguous. The value of the property affects only the results of BitPack and BitUnpack routines. *) (*Allows reading/writing individual bits of the array. Use BitPack and BitUnpack for much faster access to bit data. *) property Bits[const row, col: integer]: boolean read get_Bits write set_Bits; (* Returns data for inspection by the debugger. *) property IntegerValues: string read Get_IntegerValues; (* Specifies the power of two for the scale factor used by some methods.*) property ScaleFactor: integer read get_ScaleFactor write set_ScaleFactor; (*Defines number of bits stored in one row.*) property ColsBitCount: integer read Get_ColsBitCount write Set_ColsBitCount; (*Defines the number of leading columns. This value defines the spacing in number of samples between Rows. It is fixed to be the same to the value of (for now). *) property LeadingCols: integer read GetLeadingCols write SetLeadingCols; (*Defines the number of matrix columns. Use this property to set or get the number of the calling matrix columns. Setting the Cols does not affect the actual amount of memory allocated unless Rows*Cols is bigger than . *) property Cols: integer read GetCols write SetCols; (*Defines the number of matrix Rows. Use this property to set or get the number of the calling matrix Rows. Setting the Rows does not affect the actual amount of memory allocated unless Rows*Cols is bigger than . *) property Rows: integer read GetRows write SetRows; end; (*Returns the abs of elements in the source data. Internally calls *) function Abs(const X: TVecInt): VectorInt; overload; (*Subrange the source VectorInt without copy operation. Internally calls *) function Select(const Src: TVecInt; const StartIndex, StopIndex: integer): VectorInt; overload; (*Compute magnitude from the source. Internally calls *) function Mag(const X: TVecInt): VectorInt; overload; (*Returns the sum of elements in the source data. Internally calls *) function Sum(const X: TMtxVecInt): integer; overload; (*Computes the Median from the source data. Internally calls *) function Median(const X: TMtxVecInt): double; overload; (*Returns the maximum of the source data. Internally calls *) function Max(const X: TMtxVecInt): integer; overload; (*Returns the maximum of the source data. Internally calls *) (*Returns the minimum of the source data. Internally calls *) function Min(const X: TMtxVecInt): integer; overload; (*Returns the average value of the source data. Internally calls and divides with vector length. *) function Mean(const X: TMtxVecInt): double; overload; (*Reverses the content of the source data. Internally calls *) function Reverse(const X: TVecInt): VectorInt; overload; (*Rotates the content of the source data by Offset. Internally calls *) function Rotate(const X: TVecInt; const Offset: integer): VectorInt; overload; (*Shifts the content of the source data X by Offset left or right. Internally calls *) function Shift(const X: TVecInt; const Offset: integer): VectorInt; overload; (*Returns a VectorInt of [0, 1, .., Len-1] numbers. Internally calls *) function Ramp(const Len: integer): VectorInt; overload; (*Returns a VectorInt of [Offset, Offset+Step, .., Offset+(Len-1)*Step] numbers. Internally calls *) function Ramp(const Len: integer; const Offset, Step: double): VectorInt; overload; (*Sorts the source data ascendingly. Internally calls *) function SortAscend(const Src: TVecInt): VectorInt; overload; (*Sorts the source data ascendingly. Internally calls *) function SortAscend(const Src, IndexVec: TVecInt): VectorInt; overload; (*Sorts the source data descendingly. Internally calls *) function SortDescend(const Src: TVecInt): VectorInt; overload; (*Sorts the source data descendingly. Internally calls *) function SortDescend(const Src, IndexVec: TVecInt): VectorInt; overload; (*Converts a list of strings to VectorInt. Internally calls *) function StringsToValues(const aList: TStrings): VectorInt; overload; (*Converts a list of strings to VectorInt. Internally calls *) function StringsToValues(const aList: TStrings; const ListIndex: integer; const Index: integer = 0; const Len: integer = MtxVecEOA): VectorInt; overload; (*Returns the abs of elements in the source data. Internally calls *) function Abs(const X: TMtxInt): MatrixInt; overload; (*Subrange the source MatrixInt without copy operation. Internally calls *) function Select(const Src: TMtxInt; const StartIndex, StopIndex: integer): VectorInt; overload; (*Compute magnitude from the source. Internally calls *) function Mag(const X: TMtxInt): MatrixInt; overload; (*Compute maximum of each row. Compute maximum of each row and store the result in to Dst VectorInt. The Dst is sized automatically. *) function MaxRows(const Src: TMtxInt): VectorInt; (*Compute minimum of each row. Compute minimum of each row and store the result in to Dst VectorInt. The Dst is sized automatically. *) function MinRows(const Src: TMtxInt): VectorInt; (*Compute maximum of each column. Compute maximum of each column and store the result in to Dst VectorInt. The Dst is sized automatically. *) function MaxCols(const Src: TMtxInt): VectorInt; (*Compute minimum of each column. Compute minimum of each column and store the result in to Dst VectorInt. The Dst is sized automatically. *) function MinCols(const Src: TMtxInt): VectorInt; (*Sort in ascending order all Rows. Internally calls *) function SortAscend(const Src: TMtxInt): MatrixInt; overload; (*Sort in ascending order all Rows from Src according to column Col. Internally calls *) function SortAscend(const Src: TMtxInt; const Col: integer): MatrixInt; overload; (*Sort in descending order all Rows from Src. Internally calls *) function SortDescend(const Src: TMtxInt): MatrixInt; overload; (*Sort in descending order all Rows from Src according to column Col. Internally calls *) function SortDescend(const Src: TMtxInt; const Col: integer): MatrixInt; overload; (*Converts a list of strings to MatrixInt. Internally calls *) function StringsToValues(const aList: TStrings; const Delimiter: string): MatrixInt; overload; (*Converts a list of strings to MatrixInt. Internally calls *) function StringsToValues(const aList: TStrings; const ListIndex, ListLen, Row,Col: Integer; Delimiter: string = kTab): MatrixInt; overload; (* Compute X + Y*yScale *) function AddScaled(const X: TVecInt; const Y: TMtxVecInt; const yScale: integer): VectorInt; overload; (* Compute X + Y*yScale *) function AddScaled(const X: TMtxInt; const Y: TMtxVecInt; const yScale: integer): MatrixInt; overload; (* Compute sqr(X + Y*yScale) *) function AddScaledSqr(const X: TVecInt; const Y: TMtxVecInt; const yScale: integer): VectorInt; overload; (* Compute sqr(X + Y*yScale) *) function AddScaledSqr(const X: TMtxInt; const Y: TMtxVecInt; const yScale: integer): MatrixInt; overload; (* Compute sqr(X) + sqr(Y)*yScale *) function SqrAddScaled(const X: TVecInt; const Y: TMtxVecInt; const yScale: integer): VectorInt; overload; (* Compute sqr(X) + sqr(Y)*yScale *) function SqrAddScaled(const X: TMtxInt; const Y: TMtxVecInt; const yScale: integer): MatrixInt; overload; (* Compute X + Y + Z *) function Add(const X: TVecInt; const Y, Z: TMtxVecInt): VectorInt; overload; (* Compute X + Y + Z *) function Add(const X: TMtxInt; const Y, Z: TMtxVecInt): MatrixInt; overload; (* Compute X + Y + Z*zScale *) function AddScaled(const X: TVecInt; const Y, Z: TMtxVecInt; const zScale: integer): VectorInt; overload; (* Compute X + Y + Z*zScale *) function AddScaled(const X: TMtxInt; const Y, Z: TMtxVecInt; const zScale: integer): MatrixInt; overload; (* Compute X + Y*yScale + Z*zScale *) function AddScaled(const X: TVecInt; const Y: TMtxVecInt; const yScale: integer; const Z: TMtxVecInt; const zScale: integer): VectorInt; overload; (* Compute X + Y*yScale + Z*zScale *) function AddScaled(const X: TMtxInt; const Y: TMtxVecInt; const yScale: integer; const Z: TMtxVecInt; const zScale: integer): MatrixInt; overload; (* Compute X + Y + zScalar *) function Add(const X: TVecInt; const Y: TMtxVecInt; const Z: integer): VectorInt; overload; (* Compute X + Y + zScalar *) function Add(const X: TMtxInt; const Y: TMtxVecInt; const Z: integer): MatrixInt; overload; (* Compute X + Y*yScale + zScalar *) function AddScaledC(const X: TVecInt; const Y: TMtxVecInt; const yScale: integer; const Z: integer): VectorInt; overload; (* Compute X + Y*yScale + zScalar *) function AddScaledC(const X: TMtxInt; const Y: TMtxVecInt; const yScale: integer; const Z: integer): MatrixInt; overload; (* Compute X - Y - Z *) function Sub(const X: TVecInt; const Y, Z: TMtxVecInt): VectorInt; overload; (* Compute X - Y - Z *) function Sub(const X: TMtxInt; const Y, Z: TMtxVecInt): MatrixInt; overload; (* Compute X - Y*yScale - Z*zScale *) function SubScaled(const X: TVecInt; const Y: TMtxVecInt; const yScale: integer; const Z: TMtxVecInt; const zScale: integer): VectorInt; overload; (* Compute X - Y*yScale - Z*zScale *) function SubScaled(const X: TMtxInt; const Y: TMtxVecInt; const yScale: integer; const Z: TMtxVecInt; const zScale: integer): MatrixInt; overload; (* Compute X - Y - Z*zScale *) function SubScaled(const X: TVecInt; const Y, Z: TMtxVecInt; const zScale: integer): VectorInt; overload; (* Compute X - Y - Z*zScale *) function SubScaled(const X: TMtxInt; const Y, Z: TMtxVecInt; const zScale: integer): MatrixInt; overload; (* Compute X - Y - zScalar *) function Sub(const X: TVecInt; const Y: TMtxVecInt; const Z: integer): VectorInt; overload; (* Compute X - Y - zScalar *) function Sub(const X: TMtxInt; const Y: TMtxVecInt; const Z: integer): MatrixInt; overload; (* Compute X - Y*yScale - zScalar *) function SubScaledC(const X: TVecInt; const Y: TMtxVecInt; const yScale: integer; const Z: integer): VectorInt; overload; (* Compute X - Y*yScale - zScalar *) function SubScaledC(const X: TMtxInt; const Y: TMtxVecInt; const yScale: integer; const Z: integer): MatrixInt; overload; (* Compute X * Y / Z *) function MulAndDiv(const X: TVecInt; const Y, Z: TMtxVecInt): VectorInt; overload; (* Compute X * Y / Z *) function MulAndDiv(const X: TMtxInt; const Y, Z: TMtxVecInt): MatrixInt; overload; (* Compute (X + Y)*Z *) function AddAndMul(const X: TVecInt; const Y, Z: TMtxVecInt): VectorInt; overload; (* Compute (X + Y)*Z *) function AddAndMul(const X: TMtxInt; const Y, Z: TMtxVecInt): MatrixInt; overload; (* Compute (X + Y)*Z*zScale *) function AddAndMul(const X: TVecInt; const Y, Z: TMtxVecInt; zScale: integer): VectorInt; overload; (* Compute (X + Y)*Z*zScale *) function AddAndMul(const X: TMtxInt; const Y, Z: TMtxVecInt; zScale: integer): MatrixInt; overload; (* Compute (X + Y*yScale)*Z*zScale *) function AddAndMul(const X: TVecInt; const Y: TMtxVecInt; yScale: integer; const Z: TMtxVecInt; zScale: integer): VectorInt; overload; (* Compute (X + Y*yScale)*Z*zScale *) function AddAndMul(const X: TMtxInt; const Y: TMtxVecInt; yScale: integer; const Z: TMtxVecInt; zScale: integer): MatrixInt; overload; (* Compute (X + Y)*zScalar *) function AddAndMul(const X: TVecInt; const Y: TMtxVecInt; Z: integer): VectorInt; overload; (* Compute (X + Y)*zScalar *) function AddAndMul(const X: TMtxInt; const Y: TMtxVecInt; Z: integer): MatrixInt; overload; (* Compute (X + Y*yScale)*zScalar *) function AddAndMul(const X: TVecInt; const Y: TMtxVecInt; yScale, Z: integer): VectorInt; overload; (* Compute (X + Y*yScale)*zScalar *) function AddAndMul(const X: TMtxInt; const Y: TMtxVecInt; yScale, Z: integer): MatrixInt; overload; (* Compute (X + yScalar)*Z*zScale *) function AddAndMul(const X: TVecInt; Y: integer; const Z: TMtxVecInt; zScale: integer): VectorInt; overload; (* Compute (X + yScalar)*Z*zScale *) function AddAndMul(const X: TMtxInt; Y: integer; const Z: TMtxVecInt; zScale: integer): MatrixInt; overload; (* Compute (X*xScale + yScalar)*Z *) function AddAndMul(const X: TVecInt; xScale, Y: integer; const Z: TMtxVecInt): VectorInt; overload; (* Compute (X*xScale + yScalar)*Z *) function AddAndMul(const X: TMtxInt; xScale, Y: integer; const Z: TMtxVecInt): MatrixInt; overload; (* Compute (X + yScalar)*Z *) function AddAndMul(const X: TVecInt; Y: integer; const Z: TMtxVecInt): VectorInt; overload; (* Compute (X + yScalar)*Z *) function AddAndMul(const X: TMtxInt; Y: integer; const Z: TMtxVecInt): MatrixInt; overload; (* Compute (X + yScalar)*zScalar *) function AddAndMul(const X: TVecInt; Y, Z: integer): VectorInt; overload; (* Compute (X + yScalar)*zScalar *) function AddAndMul(const X: TMtxInt; Y, Z: integer): MatrixInt; overload; (* Compute (X - Y)*Z *) function SubAndMul(const X: TVecInt; const Y, Z: TMtxVecInt): VectorInt; overload; (* Compute (X - Y)*Z *) function SubAndMul(const X: TMtxInt; const Y, Z: TMtxVecInt): MatrixInt; overload; (* Compute (X - Y)*Z*zScale *) function SubAndMul(const X: TVecInt; const Y, Z: TMtxVecInt; zScale: integer): VectorInt; overload; (* Compute (X - Y)*Z*zScale *) function SubAndMul(const X: TMtxInt; const Y, Z: TMtxVecInt; zScale: integer): MatrixInt; overload; (* Compute (X - Y*yScale)*Z*zScale *) function SubAndMul(const X: TVecInt; const Y: TMtxVecInt; yScale: integer; const Z: TMtxVecInt; zScale: integer): VectorInt; overload; (* Compute (X - Y*yScale)*Z*zScale *) function SubAndMul(const X: TMtxInt; const Y: TMtxVecInt; yScale: integer; const Z: TMtxVecInt; zScale: integer): MatrixInt; overload; (* Compute (X - Y)*zScalar *) function SubAndMul(const X: TVecInt; const Y: TMtxVecInt; Z: integer): VectorInt; overload; (* Compute (X - Y)*zScalar *) function SubAndMul(const X: TMtxInt; const Y: TMtxVecInt; Z: integer): MatrixInt; overload; (* Compute (X - Y*yScale)*zScalar *) function SubAndMul(const X: TVecInt; const Y: TMtxVecInt; yScale, Z: integer): VectorInt; overload; (* Compute (X - Y*yScale)*zScalar *) function SubAndMul(const X: TMtxInt; const Y: TMtxVecInt; yScale, Z: integer): MatrixInt; overload; (* Compute (X - yScalar)*Z*zScale *) function SubAndMul(const X: TVecInt; Y: integer; const Z: TMtxVecInt; zScale: integer): VectorInt; overload; (* Compute (X - yScalar)*Z*zScale *) function SubAndMul(const X: TMtxInt; Y: integer; const Z: TMtxVecInt; zScale: integer): MatrixInt; overload; (* Compute (X*xScale - yScalar)*Z *) function SubAndMul(const X: TVecInt; xScale, Y: integer; const Z: TMtxVecInt): VectorInt; overload; (* Compute (X*xScale - yScalar)*Z *) function SubAndMul(const X: TMtxInt; xScale, Y: integer; const Z: TMtxVecInt): MatrixInt; overload; (* Compute (X - yScalar)*Z *) function SubAndMul(const X: TVecInt; Y: integer; const Z: TMtxVecInt): VectorInt; overload; (* Compute (X - yScalar)*Z *) function SubAndMul(const X: TMtxInt; Y: integer; const Z: TMtxVecInt): MatrixInt; overload; (* Compute (X - yScalar)*zScalar *) function SubAndMul(const X: TVecInt; Y, Z: integer): VectorInt; overload; (* Compute (X - yScalar)*zScalar *) function SubAndMul(const X: TMtxInt; Y, Z: integer): MatrixInt; overload; (* Compute X*Y + Z *) function MulAndAdd(const X: TVecInt; const Y, Z: TMtxVecInt): VectorInt; overload; (* Compute X*Y + Z *) function MulAndAdd(const X: TMtxInt; const Y, Z: TMtxVecInt): MatrixInt; overload; (* Compute X*Y*xyScale + Z *) function MulAndAdd(const X: TVecInt; const Y: TMtxVecInt; xyScale: integer; const Z: TMtxVecInt): VectorInt; overload; (* Compute X*Y*xyScale + Z *) function MulAndAdd(const X: TMtxInt; const Y: TMtxVecInt; xyScale: integer; const Z: TMtxVecInt): MatrixInt; overload; (* Compute X*Y + Z*zScale *) function MulAndAdd(const X: TVecInt; const Y, Z: TMtxVecInt; zScale: integer): VectorInt; overload; (* Compute X*Y + Z*zScale *) function MulAndAdd(const X: TMtxInt; const Y, Z: TMtxVecInt; zScale: integer): MatrixInt; overload; (* Compute X*Y + zScalar *) function MulAndAdd(const X: TVecInt; const Y: TMtxVecInt; Z: integer): VectorInt; overload; (* Compute X*Y + zScalar *) function MulAndAdd(const X: TMtxInt; const Y: TMtxVecInt; Z: integer): MatrixInt; overload; (* Compute X*Y - Z *) function MulAndSub(const X: TVecInt; const Y, Z: TMtxVecInt): VectorInt; overload; (* Compute X*Y - Z *) function MulAndSub(const X: TMtxInt; const Y, Z: TMtxVecInt): MatrixInt; overload; (* Compute X*Y*xyScale - Z *) function MulAndSub(const X: TVecInt; const Y: TMtxVecInt; xyScale: integer; const Z: TMtxVecInt): VectorInt; overload; (* Compute X*Y*xyScale - Z *) function MulAndSub(const X: TMtxInt; const Y: TMtxVecInt; xyScale: integer; const Z: TMtxVecInt): MatrixInt; overload; (* Compute X*Y - Z*zScale *) function MulAndSub(const X: TVecInt; const Y, Z: TMtxVecInt; zScale: integer): VectorInt; overload; (* Compute X*Y - Z*zScale *) function MulAndSub(const X: TMtxInt; const Y, Z: TMtxVecInt; zScale: integer): MatrixInt; overload; (* Compute X*Y - zScalar *) function MulAndSub(const X: TVecInt; const Y: TMtxVecInt; Z: integer): VectorInt; overload; (* Compute X*Y - zScalar *) function MulAndSub(const X: TMtxInt; const Y: TMtxVecInt; Z: integer): MatrixInt; overload; (* Compute X/Y + Z *) function DivAndAdd(const X: TVecInt; const Y, Z: TMtxVecInt): VectorInt; overload; (* Compute X/Y + Z *) function DivAndAdd(const X: TMtxInt; const Y, Z: TMtxVecInt): MatrixInt; overload; (* Compute X/Y*xyScale + Z *) function DivAndAdd(const X: TVecInt; const Y: TMtxVecInt; xyScale: integer; const Z: TMtxVecInt): VectorInt; overload; (* Compute X/Y*xyScale + Z *) function DivAndAdd(const X: TMtxInt; const Y: TMtxVecInt; xyScale: integer; const Z: TMtxVecInt): MatrixInt; overload; (* Compute X/Y + Z*zScale *) function DivAndAdd(const X: TVecInt; const Y, Z: TMtxVecInt; zScale: integer): VectorInt; overload; (* Compute X/Y + Z*zScale *) function DivAndAdd(const X: TMtxInt; const Y, Z: TMtxVecInt; zScale: integer): MatrixInt; overload; (* Compute X/Y + zScalar *) function DivAndAdd(const X: TVecInt; const Y: TMtxVecInt; Z: integer): VectorInt; overload; (* Compute X/Y + zScalar *) function DivAndAdd(const X: TMtxInt; const Y: TMtxVecInt; Z: integer): MatrixInt; overload; (* Compute X/Y - Z *) function DivAndSub(const X: TVecInt; const Y, Z: TMtxVecInt): VectorInt; overload; (* Compute X/Y - Z *) function DivAndSub(const X: TMtxInt; const Y, Z: TMtxVecInt): MatrixInt; overload; (* Compute X/Y*xyScale - Z *) function DivAndSub(const X: TVecInt; const Y: TMtxVecInt; xyScale: integer; const Z: TMtxVecInt): VectorInt; overload; (* Compute X/Y*xyScale - Z *) function DivAndSub(const X: TMtxInt; const Y: TMtxVecInt; xyScale: integer; const Z: TMtxVecInt): MatrixInt; overload; (* Compute X/Y - Z*zScale *) function DivAndSub(const X: TVecInt; const Y, Z: TMtxVecInt; zScale: integer): VectorInt; overload; (* Compute X/Y - Z*zScale *) function DivAndSub(const X: TMtxInt; const Y, Z: TMtxVecInt; zScale: integer): MatrixInt; overload; (* Compute X/Y - zScalar *) function DivAndSub(const X: TVecInt; const Y: TMtxVecInt; Z: integer): VectorInt; overload; (* Compute X/Y - zScalar *) function DivAndSub(const X: TMtxInt; const Y: TMtxVecInt; Z: integer): MatrixInt; overload; (* Compute X*xScale + Y*yScale *) function AddScaled(const X: TVecInt; const xScale: integer; const Y: TMtxVecInt; const yScale: integer): VectorInt; overload; (* Compute X*xScale + Y*yScale *) function AddScaled(const X: TMtxInt; const xScale: integer; const Y: TMtxVecInt; const yScale: integer): MatrixInt; overload; (* Compute sqr(X*xScale + Y*yScale) *) function AddScaledSqr(const X: TVecInt; const xScale: integer; const Y: TMtxVecInt; const yScale: integer): VectorInt; overload; (* Compute sqr(X*xScale + Y*yScale) *) function AddScaledSqr(const X: TMtxInt; const xScale: integer; const Y: TMtxVecInt; const yScale: integer): MatrixInt; overload; (* Compute sqr(X)*xScale + sqr(Y)*yScale *) function SqrAddScaled(const X: TVecInt; const xScale: integer; const Y: TMtxVecInt; const yScale: integer): VectorInt; overload; (* Compute sqr(X)*xScale + sqr(Y)*yScale *) function SqrAddScaled(const X: TMtxInt; const xScale: integer; const Y: TMtxVecInt; const yScale: integer): MatrixInt; overload; (* Compute X*xScale + Y*yScale + Z*zScale *) function AddScaled(const X: TVecInt; const xScale: integer; const Y: TMtxVecInt; const yScale: integer; const Z: TMtxVecInt; const zScale: integer): VectorInt; overload; (* Compute X*xScale + Y*yScale + Z*zScale *) function AddScaled(const X: TMtxInt; const xScale: integer; const Y: TMtxVecInt; const yScale: integer; const Z: TMtxVecInt; const zScale: integer): MatrixInt; overload; (* Compute X*xScale + Y*yScale + zScalar *) function AddScaledC(const X: TVecInt; const xScale: integer; const Y: TMtxVecInt; const yScale: integer; const Z: integer): VectorInt; overload; (* Compute X*xScale + Y*yScale + zScalar *) function AddScaledC(const X: TMtxInt; const xScale: integer; const Y: TMtxVecInt; const yScale: integer; const Z: integer): MatrixInt; overload; (* Compute X*xScale - Y*yScale - Z*zScale *) function SubScaled(const X: TVecInt; const xScale: integer; const Y: TMtxVecInt; const yScale: integer; const Z: TMtxVecInt; const zScale: integer): VectorInt; overload; (* Compute X*xScale - Y*yScale - Z*zScale *) function SubScaled(const X: TMtxInt; const xScale: integer; const Y: TMtxVecInt; const yScale: integer; const Z: TMtxVecInt; const zScale: integer): MatrixInt; overload; (* Compute X*xScale - Y*yScale - zScalar *) function SubScaledC(const X: TVecInt; const xScale: integer; const Y: TMtxVecInt; const yScale: integer; const Z: integer): VectorInt; overload; (* Compute X*xScale - Y*yScale - zScalar *) function SubScaledC(const X: TMtxInt; const xScale: integer; const Y: TMtxVecInt; const yScale: integer; const Z: integer): MatrixInt; overload; (* Compute X*Y*Z *) function Mul(const X: TVecInt; const Y, Z: TMtxVecInt): VectorInt; overload; (* Compute X*Y*Z *) function Mul(const X: TMtxInt; const Y, Z: TMtxVecInt): MatrixInt; overload; (* Compute X*Y*zScalar *) function Mul(const X: TVecInt; const Y: TMtxVecInt; const Z: integer): VectorInt; overload; (* Compute X*Y*zScalar *) function Mul(const X: TMtxInt; const Y: TMtxVecInt; const Z: integer): MatrixInt; overload; (* Compute X / (Y*Z) *) function Divide(const X: TVecInt; const Y, Z: TMtxVecInt): VectorInt; overload; (* Compute X / (Y*Z) *) function Divide(const X: TMtxInt; const Y, Z: TMtxVecInt): MatrixInt; overload; (* Compute X / (Y*zScale) *) function DivideC(const X: TVecInt; const Y: TMtxVecInt; const Z: integer): VectorInt; overload; (* Compute X / (Y*zScale) *) function DivideC(const X: TMtxInt; const Y: TMtxVecInt; const Z: integer): MatrixInt; overload; (* Compute X * Y * xyScale / Z *) function MulAndDiv(const X: TVecInt; const Y: TMtxVecInt; const xyScale: integer; const Z: TMtxVecInt): VectorInt; overload; (* Compute X * Y * xyScale / Z *) function MulAndDiv(const X: TMtxInt; const Y: TMtxVecInt; const xyScale: integer; const Z: TMtxVecInt): MatrixInt; overload; (* Compute X * Y / zScalar *) function MulAndDiv(const X: TVecInt; const Y: TMtxVecInt; const Z: integer): VectorInt; overload; (* Compute X * Y / zScalar *) function MulAndDiv(const X: TMtxInt; const Y: TMtxVecInt; const Z: integer): MatrixInt; overload; (* Compute xScalar / (Y*Z) *) function Divide(const X: integer; const Y: TVecInt; const Z: TMtxVecInt): VectorInt; overload; (* Compute xScalar / (Y*Z) *) function Divide(const X: integer; const Y: TMtxInt; const Z: TMtxVecInt): MatrixInt; overload; (* Compute (X*xScale + Y*yScale)*Z*zScale *) function AddAndMul(const X: TVecInt; xScale: integer; const Y: TMtxVecInt; yScale: integer; const Z: TMtxVecInt; zScale: integer): VectorInt; overload; (* Compute (X*xScale + Y*yScale)*Z*zScale *) function AddAndMul(const X: TMtxInt; xScale: integer; const Y: TMtxVecInt; yScale: integer; const Z: TMtxVecInt; zScale: integer): MatrixInt; overload; (* Compute (X*xScale + Y*yScale)*zScalar *) function AddAndMul(const X: TVecInt; xScale: integer; const Y: TMtxVecInt; yScale: integer; Z: integer): VectorInt; overload; (* Compute (X*xScale + Y*yScale)*zScalar *) function AddAndMul(const X: TMtxInt; xScale: integer; const Y: TMtxVecInt; yScale: integer; Z: integer): MatrixInt; overload; (* Compute (X*xScale + yScalar)*Z*zScale *) function AddAndMul(const X: TVecInt; xScale: integer; Y: integer; const Z: TMtxVecInt; zScale: integer): VectorInt; overload; (* Compute (X*xScale + yScalar)*Z*zScale *) function AddAndMul(const X: TMtxInt; xScale: integer; Y: integer; const Z: TMtxVecInt; zScale: integer): MatrixInt; overload; (* Compute (X*xScale + yScalar)*zScalar *) function AddAndMul(const X: TVecInt; xScale: integer; Y, Z: integer): VectorInt; overload; (* Compute (X*xScale + yScalar)*zScalar *) function AddAndMul(const X: TMtxInt; xScale: integer; Y, Z: integer): MatrixInt; overload; (* Compute (X*xScale - Y*yScale)*Z*zScale *) function SubAndMul(const X: TVecInt; xScale: integer; const Y: TMtxVecInt; yScale: integer; const Z: TMtxVecInt; zScale: integer): VectorInt; overload; (* Compute (X*xScale - Y*yScale)*Z*zScale *) function SubAndMul(const X: TMtxInt; xScale: integer; const Y: TMtxVecInt; yScale: integer; const Z: TMtxVecInt; zScale: integer): MatrixInt; overload; (* Compute (X*xScale - Y*yScale)*zScalar *) function SubAndMul(const X: TVecInt; xScale: integer; const Y: TMtxVecInt; yScale: integer; Z: integer): VectorInt; overload; (* Compute (X*xScale - Y*yScale)*zScalar *) function SubAndMul(const X: TMtxInt; xScale: integer; const Y: TMtxVecInt; yScale: integer; Z: integer): MatrixInt; overload; (* Compute (X*xScale - yScalar)*Z*zScale *) function SubAndMul(const X: TVecInt; xScale: integer; Y: integer; const Z: TMtxVecInt; zScale: integer): VectorInt; overload; (* Compute (X*xScale - yScalar)*Z*zScale *) function SubAndMul(const X: TMtxInt; xScale: integer; Y: integer; const Z: TMtxVecInt; zScale: integer): MatrixInt; overload; (* Compute (X*xScale - yScalar)*zScalar *) function SubAndMul(const X: TVecInt; xScale: integer; Y, Z: integer): VectorInt; overload; (* Compute (X*xScale - yScalar)*zScalar *) function SubAndMul(const X: TMtxInt; xScale: integer; Y, Z: integer): MatrixInt; overload; (* Compute (X*Y)*xyScale + Z*zScale *) function MulAndAdd(const X: TVecInt; const Y: TMtxVecInt; xyScale: integer; const Z: TMtxVecInt; zScale: integer): VectorInt; overload; (* Compute (X*Y)*xyScale + Z*zScale *) function MulAndAdd(const X: TMtxInt; const Y: TMtxVecInt; xyScale: integer; const Z: TMtxVecInt; zScale: integer): MatrixInt; overload; (* Compute (X*Y)*xyScale + zScalar *) function MulAndAdd(const X: TVecInt; const Y: TMtxVecInt; xyScale: integer; Z: integer): VectorInt; overload; (* Compute (X*Y)*xyScale + zScalar *) function MulAndAdd(const X: TMtxInt; const Y: TMtxVecInt; xyScale: integer; Z: integer): MatrixInt; overload; (* Compute (X*yScalar) + zScalar *) function MulAndAdd(const X: TVecInt; Y, Z: integer): VectorInt; overload; (* Compute (X*yScalar) + zScalar *) function MulAndAdd(const X: TMtxInt; Y, Z: integer): MatrixInt; overload; (* Compute (X*Y)*xyScale - Z*zScale *) function MulAndSub(const X: TVecInt; const Y: TMtxVecInt; xyScale: integer; const Z: TMtxVecInt; zScale: integer): VectorInt; overload; (* Compute (X*Y)*xyScale - Z*zScale *) function MulAndSub(const X: TMtxInt; const Y: TMtxVecInt; xyScale: integer; const Z: TMtxVecInt; zScale: integer): MatrixInt; overload; (* Compute (X*Y)*xyScale - zScalar *) function MulAndSub(const X: TVecInt; const Y: TMtxVecInt; xyScale, Z: integer): VectorInt; overload; (* Compute (X*Y)*xyScale - zScalar *) function MulAndSub(const X: TMtxInt; const Y: TMtxVecInt; xyScale, Z: integer): MatrixInt; overload; (* Compute X*yScalar - Z*zScale *) function MulAndSub(const X: TVecInt; Y: integer; const Z: TMtxVecInt; zScale: integer): VectorInt; overload; (* Compute X*yScalar - Z*zScale *) function MulAndSub(const X: TMtxInt; Y: integer; const Z: TMtxVecInt; zScale: integer): MatrixInt; overload; (* Compute (X / Y)*xyScale + Z*zScale *) function DivAndAdd(const X: TVecInt; const Y: TMtxVecInt; xyScale: integer; const Z: TMtxVecInt; zScale: integer): VectorInt; overload; (* Compute (X / Y)*xyScale + Z*zScale *) function DivAndAdd(const X: TMtxInt; const Y: TMtxVecInt; xyScale: integer; const Z: TMtxVecInt; zScale: integer): MatrixInt; overload; (* Compute (X / Y) * xyScale + zScalar *) function DivAndAdd(const X: TVecInt; const Y: TMtxVecInt; xyScale: integer; Z: integer): VectorInt; overload; (* Compute (X / Y) * xyScale + zScalar *) function DivAndAdd(const X: TMtxInt; const Y: TMtxVecInt; xyScale: integer; Z: integer): MatrixInt; overload; (* Compute (X / Y) * xyScale - Z y *) function DivAndSub(const X: TVecInt; const Y: TMtxVecInt; xyScale: integer; const Z: TMtxVecInt; zScale: integer): VectorInt; overload; (* Compute (X / Y) * xyScale - Z y *) function DivAndSub(const X: TMtxInt; const Y: TMtxVecInt; xyScale: integer; const Z: TMtxVecInt; zScale: integer): MatrixInt; overload; (* Compute (X / Y) * xyScale - zScalar *) function DivAndSub(const X: TVecInt; const Y: TMtxVecInt; xyScale: integer; Z: integer): VectorInt; overload; (* Compute (X / Y) * xyScale - zScalar *) function DivAndSub(const X: TMtxInt; const Y: TMtxVecInt; xyScale: integer; Z: integer): MatrixInt; overload; (* Copy each of Vec elements to the calling object. The Size property of the calling object is set implicitly to match Vec object. The storage precision of the calling object is set to DstIntPrecision. *) function Convert(const Src: TVecInt; DstIntPrecision: TIntPrecision): VectorInt; overload; (*Compare all Vec1 elements with corresponding Vec2 elements and return bigger value as result. Size and property of result object are adjusted automatically to match those of Vec1 and Vec2. An exception is raised if Vec1 and Vec2 size and property do not match. *) function MaxEvery(const Vec1: TVecInt; const Vec2: TMtxVecInt): VectorInt; overload; (*Compare all Vec1 elements with corresponding Vec2 elements and return the smaller value as the result.*) function MinEvery(const Vec1: TVecInt; const Vec2: TMtxVecInt): VectorInt; overload; (*Applies median filter with size Mask to data in Src and returns result. Median filter is a nonlinear filter which replaces each element from Src vector with the median value, calculated over a fixed range (mask) centered around that element and returns this as result. *) function Median(const Src: TVecInt; const MaskSize: integer): VectorInt; overload; (*Fills the resulting vector elements with linear rule and randomly shuffles the indexes. Fills the resulting vector with a series following the rule: Values[k] := k and then scrambles the contents of the vector randomly by using the Fisher–Yates shuffle. *) function RandomRamp(Len: integer; aIntPrecision: TIntPrecision): VectorInt; overload; (*Randomly shuffles the content of the vector. Scrambles the contents of the vector randomly by using the Fisher–Yates shuffle. *) function RandomShuffle(const Src: TVecInt): VectorInt; overload; (*Perform threshold operation on all Src object values. Size and properties of the result are adjusted automatically. *) function ThreshBottom(const Src: TVecInt; const Value: integer): VectorInt; overload; (*Perform threshold operation on all Src object values. Size and properties of the result are adjusted automatically. *) function ThreshTop(const Src: TVecInt; const Value: integer): VectorInt; overload; (*Perform threshold operation on all Src object values. Size and properties of the result are adjusted automatically. *) function ThreshAbsLT(const Src: TVecInt; const Value: Integer): VectorInt; overload; (*Perform threshold operation on all Src object values. Size and properties of the result are adjusted automatically. *) function ThreshAbsGT(const Src: TVecInt; const Value: Integer): VectorInt; overload; (*Perform "greater than and less than" threshold operation on all Vec object values. Size and properties of the result are adjusted automatically. *) function ThresholdGT_LT(const Vec: TVecInt; const GTLevel, GTValue, LTLevel, LTValue: Integer): VectorInt; overload; (*Calculate the cumulative sum for all Vec elements. Size and properties of the result are adjusted automatically. *) function CumSum(const Vec: TVecInt): VectorInt; overload; (*Calculate the difference for all Vec elements. The of the result is set to one less than the Vec.length. *) function Difference(const Vec: TVecInt; Lag: Integer = 1): VectorInt; overload; (*Copies a row from matrix.*) function GetRow(const Mtx: TMtxInt; Row: integer): VectorInt; overload; (*Copies the k-th diagonal from the TMtxInt object.*) function Diag(const Mtx: TMtxInt; k: integer): VectorInt; (* Scatters Src elements defined with the Mask to the calling object. *) function ScatterByMask(const Src: TVecInt; const Mask: TMtxVecInt): VectorInt; overload; (* Gathers elements from X starting at Offset and with Increment in to the result. *) function GatherByIncr(const X: TVecInt; Increment: integer = 1; Offset: integer = 0): VectorInt; overload; (* Gathers elements from X specified by indices stored in Indexes in to the result. *) function GatherByIndex(const X: TVecInt; const Indexes: TVecInt): VectorInt; overload; (* Gathers elements from X specified by non-zero values stored in the Mask in to the result. *) function GatherByMask(const X: TVecInt; const Mask: TMtxVecInt; const MaskNonZeroCount: integer = -1): VectorInt; overload; (* Copies a column from matrix.*) function GetCol(const Mtx: TMtxInt; Col: integer): VectorInt; overload; (*The b parameter is of integer type.*) function FindMask(const a: TMtxVecInt; const op: string; const b: integer): VectorInt; overload; (*The b parameter is of type. The op can be "<", ">", "=", "<=",">=". *) function FindMask(const a: TMtxVecInt; const op: string; const b: TMtxVecInt): VectorInt; overload; (*Fills the resulting vector with indexes, where the logical expression is true. The op can be "<", ">", "=", "<=",">=". The b parameter is of integer type. *) function FindIndexes(const a: TMtxVecInt; const op: string; const b: integer): VectorInt; overload; (*Fills the resulting vector with indexes, where the logical expression is true. The op can be "<", ">", "=", "<=",">=". The b parameter is of type. *) function FindIndexes(const a: TMtxVecInt; const op: string; const b: TMtxVecInt): VectorInt; overload; (*Fills the resulting vector with indexes, where the logical expression is true. The op can be "<", ">", "=", "<=",">=". *) function FindIndexes(const a: TMtxVec; const op: string; const b: TCplx): VectorInt; overload; (*Fills the resulting vector with indexes, where the logical expression is true. The op can be "<", ">", "=", "<=",">=". The b parameter is of double type. *) function FindIndexes(const a: TMtxVec; const op: string; const b: double): VectorInt; overload; (*Fills the resulting vector with indexes, where the logical expression is true. The b parameter is of type. *) function FindIndexes(const a: TMtxVec; const op: string; const b: TMtxVec): VectorInt; overload; (*Finds and returns a vector mask. The op can be "<", ">", "=", "<=",">=". *) function FindMask(const a: TMtxVec; const op: string; const b: TCplx): VectorInt; overload; (*Finds and returns a vector mask. The op can be "<", ">", "=", "<=",">=". The b parameter is of double type. *) function FindMask(const a: TMtxVec; const op: string; const b: double): VectorInt; overload; (*Finds and returns a vector mask. The op can be "<", ">", "=", "<=",">=". The b parameter is of type. *) function FindMask(const a: TMtxVec; const op: string; const b: TMtxVec): VectorInt; overload; (*Finds the masks for a vector and splits it. The op can be "<", ">", "=", "<=",">=". Use ScatterByMask to distribute MaskVec and NotMaskVec back to its location. *) function FindAndSplit(const a: TMtxVec; const op: string; const b: TMtxVec; const MaskVec, NotMaskVec: TVec): VectorInt; overload; (*Finds the masks for a vector and splits it. The op can be "<", ">", "=", "<=",">=". The b parameter is of type. Use ScatterByMask to distribute MaskVec and NotMaskVec back to its location. *) function FindAndSplit(const a: TMtxVec; const op: string; const b: TCplx; const MaskVec, NotMaskVec: TVec): VectorInt; overload; (*Finds the masks for a vector and splits it. The op can be "<", ">", "=", "<=",">=". The b parameter is of double type. Use ScatterByMask to distribute MaskVec and NotMaskVec back to its location. *) function FindAndSplit(const a: TMtxVec; const op: string; const b: double; const MaskVec, NotMaskVec: TVec): VectorInt; overload; (*Concatenates an array of TVecInt (VectorInt) objects and returns a combined array.*) function Concat(const Src: array of TVecInt): VectorInt; overload; (* Returns distinct values from Src. *) function Distinct(const Src: TVecInt): VectorInt; (* Threading support classes. *) unit MtxForLoop; interface {$I BdsppDefs.inc} uses Math387 ,Windows ,Forms ,Classes ,SysUtils ,SyncObjs ; type MaskInt = Cardinal; (*Specifies threading mode for TMtxForLoop. Before starting threads, check first what threading mode would you like to use that would serve your application best. LoopIndex mentioned below is the counter, which runs from Min to Max and each LoopIndex value can be called by a different thread. The multithreaded job is finished when all threads together covered all LoopIndex values. *) TThreadingMode = ( (*Call the functions and methods assigned to the for loop even properties. The mode assumes symmetric loads being distributed among threads. For each LoopIndex the computational load is expected to remain relatively constant. Further vectorization across a range of LoopIndex values within threads is still possible. This mode allows highest performance.*) tmForLoop, (*Call the functions and methods assigned to the while loop event properties. This mode requires that each thread is signaled as finished by the user. The callback has a Stop parameter for this purpose.*) tmWhileLoop, (*Call the functions and methods assigned to the for loop event properties. This mode is designed for asymmetric loads being distributed among threads. For each LoopIndex the computational load is allowed to vary (possibly by a lot). Further vectorization across a range of LoopIndex values within threads is not possible.*) tmGreedyForLoop); (* Defines how the threads can be assigned to specific CPU cores. *) TThreadAffinityMode = ( (*Threads are assigned to individual CPU cores by the OS.*) tamDefault, (*Thread count is split half/half between CPU cores. Eight core example with two threads: Thread0: 11110000, can run on any of the first 4 cores. Thread1: 00001111, can run on any of the last 4 cores Eight core example with four threads: Thread0: 11110000 Thread1: 11110000, first two threads can run on any of the first four cores. Thread2: 00001111 Thread3: 00001111, Last two threads can run on any of the last four cores. Four core example with four threads: Thread0: 1100 Thread1: 1100, first two threads can run on any of the first four cores. Thread2: 0011, Thread3: 0011, Last two threads can run on any of the last four cores. Eight core example with eight threads: Thread0: 11110000 Thread1: 11110000 Thread2: 11110000 Thread3: 11110000 Thread4: 00001111 Thread5: 00001111 Thread6: 00001111 Thread7: 00001111 This setup is suitable for a two-way NUMA (two socket system) or a CPU with two memory channels. It gives the OS full control how to assign threads within each NUMA node, but threads cant be moved from one node to the other.*) tamSplit2, (*Thread count is split four ways between CPU cores. Eight core example with two threads: Thread0: 11110000, can run on any of the first 4 cores. Thread1: 00001111, can run on any of the last 4 cores Eight core example with four threads: Thread0: 11000000 Thread1: 00110000 Thread2: 00001100 Thread3: 00000011 This setup is suitable for: a four-way NUMA (four socket system) or a single CPU with four separate memory channels.*) tamSplit4, (*Thread count is split eight-ways between CPU cores. Eight core example with two threads: Thread0: 11110000, can run on any of the first 4 cores. Thread1: 00001111, can run on any of the last 4 cores The two threads always on distinct CPU cores, but in case of hyper-threading can land on the same physical cpu core. Eight core example with four threads: Thread0: 11000000 Thread1: 00110000 Thread1: 00001100 Thread3: 00000011 Eight core example with eight threads: Thread0: 10000000 Thread1: 01000000 Thread2: 00100000 Thread3: 00010000 Thread4: 00001000 Thread5: 00000100 Thread6: 00000010 Thread7: 00000001 *) tamSplit8); (* Internal event state used by TMtxForLoop. *) TEventState = (esAccepted, esSignaled); (* Thread type used by TMtxForLoop. *) TLoopThread = class (TThread) strict private ProcessingIdle: integer; ProcessingFinished: integer; StartState: integer; FOnExecute: TNotifyEvent; procedure SetOnExecute(const Value: TNotifyEvent); function GetCancelProcessing: boolean; procedure SetCancelProcessing(const Value: boolean); protected StopTime: double; StartTime: Int64; Min: integer; Max: integer; Owner: TObject; Context: TObjectArray; ThreadIndex: integer; HeapIndex: integer; LoopIndex: integer; StartEvent: TEvent; ProcessingIdleEvent: TEvent; FinishEvent: TEvent; ErrorMessage: string; MessageTrigger: boolean; procedure ResetStart; procedure ResetProcessingIdle; procedure ResetProcessingFinished; function ProcessingIdleSignaled: boolean; function ProcessingFinishSignaled: boolean; strict private fCancelProcessing: integer; function StartSignaled: boolean; protected procedure Execute; override; public procedure ResetContext; procedure SignalStart; procedure SignalIdle; procedure SignalProcessingFinished; procedure SetAffinityMask(const Mask: MaskInt); constructor Create(CreateSuspended: Boolean); destructor Destroy; override; property OnExecute: TNotifyEvent read FOnExecute write SetOnExecute; property CancelProcessing: boolean read GetCancelProcessing write SetCancelProcessing; end; TLoopThreadArray = array of TLoopThread; (* Event type to implement threaded for loop within a function. LoopIndex specifies the current iteration of the for-loop between IterMin and IterMax as specified by the DoForLoop function. The context contains any parameters passed to the DoForLoop function,when threading was initialized. ThreadIndex parameter will vary from 0 to ThreadCount-1 depending on the thread that is running. ThreadIndex can be used to partition the data within the event. *) TForLoopFunEvent = procedure (LoopIndex: integer; const Context: TObjectArray; ThreadIndex: integer); (* Event type to implement threaded for-loop within a function. IdxMin specifies the starting and IdxMax the final iteration of the for-loop for the current thread and is between IterMin and IterMax as passed to the DoForLoop function. The context contains any parameters passed to the DoForLoop function,when threading was initialized. The advantage of having both start and stop index available is the possiblity for additional code vectorization within the threaded function. ThreadIndex parameter will vary from 0 to ThreadCount-1 depending on the thread that is running. ThreadIndex can be used to partition the data within the event. *) TForLoopRangeFunEvent = procedure (IdxMin, IdxMax: integer; const Context: TObjectArray; ThreadIndex: integer); (* Event type to implement threaded while-loop within a function. The while loop will not terminate until Stop variable will return True. The context contain's any parameters passed to the DoWhileLoop function, when threading was initialized. ThreadIndex parameter will vary from 0 to ThreadCount-1 depending on the thread that is running. ThreadIndex can be used to partition the data within the event. *) TWhileLoopFunEvent = procedure (var Stop: boolean; const Context: TObjectArray; ThreadIndex: integer); (* Event type to implement threaded for-loop within a method of object. LoopIndex specifies the current iteration of the for-loop and context contains any parameters passed to the DoForLoop function, when threading was initialized. ThreadIndex parameter will vary from 0 to ThreadCount-1 depending on the thread, that is running. ThreadIndex can be used to partition the data within the event. *) TForLoopEvent = procedure (LoopIndex: integer; const Context: TObjectArray; ThreadIndex: integer) of object; (* Event type to implement threaded for-loop within a function. IdxMin specifies the starting and IdxMax the final iteration of the for-loop from the [IterMin ... IterMax] range defined when DoForLoop was called. The function is called only once for each thread, because TMtxForLoop component partitions the [IterMin ... IterMax] range as equaly as possible across the threads. The context contains any parameters passed to the DoForLoop function,when threading was initialized. The advantage of having both starting and final index available is the possiblity for additional code vectorization within the threaded function. ThreadIndex parameter will vary from 0 to ThreadCount-1 depending on the thread, that is running. ThreadIndex can be used to partition the data within the event. *) TForLoopRangeEvent = procedure (IdxMin, IdxMax: integer; const Context: TObjectArray; ThreadIndex: integer) of object; (* Event type to implement threaded while-loop within a method of object. The while-loop will not terminate until Stop variable will return True. The context contain's any parameters passed to the DoWhileLoop function, when threading was initialized. ThreadIndex parameter will vary from 0 to ThreadCount-1 depending on the thread, that is running. ThreadIndex can be used to partition the data within the event. *) TWhileLoopEvent = procedure (var Stop: boolean; const Context: TObjectArray; ThreadIndex: integer) of object; (* The object implements everything neccessary to simplify threading of loops. MtxForLoop is specifically designed to make threading of computational routines which use MtxVec simpler and to make the code run faster. Multi-threading is only meaningful, if it takes more time for processing than to start and stop the threads (which should do the processing). The start/stop time defines how "short" processing tasks can still be speeded up further by using multiple threads. A TMtxForLoop variable would typically be a global variable created only once, but multiple instances are also possible. By default it will initialize Cpu Core count number of threads in its thread pool, but that can be changed via its ThreadCount property. The threads will be in standby (waiting) when not used and processing can be initiated very quickly. The cost to start and detect the end of the processing is about 50us. Jobs taking less than about 0.1ms thus can't be speed up with threading. By default the threads allocated by TMtxForLoop are super-conductive with relation to MtxVec object cache. If multiple objects of TMtxForLoop type are instantiated or thread count to be launced is more than CPU Core Count, then the size of the object cache Controller.ThreadDimension needs to adjusted as well. This value needs to be more than the combined expected concurrently executing thread count. The default value for Controller.ThreadDimension is CPU Core Count plus one. It is still the users responsibility to guard all variables from being concurrently modified by multiple threads with critical sections. TMtxForLoop has two methods for this purpose: Enter and Leave, which are unused internally. The following loop can achive about 50% faster execution on (quad) Core i7: for i := 0 to 1000-1 do a[i] := a[i] + 1; That can be used as a guide about how "fat" does the code we want to thread has to be to make it worthwile for multi-threading. To make code future proof, recommended minimum job running time per thread is 5ms. This will ensure that when the number of CPU cores increase, the minimum running time per one core will remain well above 0.1ms allowing linear scaling of performance. //not threaded code (yet to be threaded): var am: Matrix; begin am.Size(1001,100); for LoopIndex := 0 to a.Rows - 1 do begin for j := 0 to a.Cols - 1 do begin a[LoopIndex, j] := a[LoopIndex, j] + 1; end; end; end; //threaded code using TMtxForLoop: procedure MyLoop(LoopIndex: integer; const Context: TObjectArray; ThreadIndex: integer); var j: integer; a: TMtx; begin a := TMtx(Context[0]); for j := 0 to a.Cols - 1 do begin a[LoopIndex, j] := a[LoopIndex, j] + 1; end; end; procedure TMainForm.OnButtonClick(Sender: TObject); var am: Matrix; forLoop: TMtxForLoop begin forLoop := TMtxForLoop.Create; //local var only in this example, allocate globaly for performance am.Size(1001,100); am.SetVal(1); //Start the threads: DoForLoop(0,1000, MyLoop, forLoop,[TMtx(am)]); //blocking call for i := 0 to 1000 do //Code execution will not continue until all threads have finished. ViewValues(am); forLoop.Free; End; //alternative method (unused here), called only once per each started thread: procedure MyLoopRange(IdxStart, IdxEnd: integer; const Context: TObjectArray; ThreadIndex: integer); var j, k: integer; a: TMtx; begin a := TMtx(Context[0]); for k := IdxStart to IdxEnd do //additional vectorization possible inside these two loops for j := 0 to a.Cols - 1 do begin a[k, j] := a[k, j] + 1; end; end; *) TMtxForLoop = class(TPersistent) strict private ThreadList: TLoopThreadArray; IdleEvents: THandleObjectArray; StartEvents: THandleObjectArray; FinishEvents: THandleObjectArray; FStep: integer; FMax: integer; FMin: integer; FOnForLoop: TForLoopEvent; FOnWhileLoop: TWhileLoopEvent; FThreadCount: integer; FThreadingMode: TThreadingMode; fShutdown: integer; FPriority: TThreadPriority; FNameOfThreadSet: string; FOnForLoopFun: TForLoopFunEvent; FOnWhileLoopFun: TWhileLoopFunEvent; FOnForLoopRangeFun: TForLoopRangeFunEvent; FOnForLoopRange: TForLoopRangeEvent; GlobalLoopIndex: integer; FThreadAffinityMode: TThreadAffinityMode; FBlockGranularity: integer; procedure SetBlockGranularity(const Value: integer); procedure SetMax(const Value: integer); procedure SetMin(const Value: integer); procedure SetThreadCount(const Value: integer); procedure DoExecute(Sender: TObject); procedure SetThreadingMode(const Value: TThreadingMode); procedure WaitFor; procedure SetPriority(const Value: TThreadPriority); function GetErrorMessage(i: integer): string; procedure SetErrorMessage(i: integer; const Value: string); procedure SetNameOfThreadSet(const Value: string); function IsProcessingFinished: boolean; procedure SetOnForLoopFun(const Value: TForLoopFunEvent); procedure SetOnWhileLoopFun(const Value: TWhileLoopFunEvent); procedure SetOnForLoopRangeFun(const Value: TForLoopRangeFunEvent); procedure SetOnForLoop(const Value: TForLoopEvent); procedure SetOnWhileLoop(const Value: TWhileLoopEvent); procedure SetOnForLoopRange(const Value: TForLoopRangeEvent); procedure ResetFunctions; procedure ResetContext; procedure SetThreadAffinityMode(const Value: TThreadAffinityMode); procedure UpdateThreadAffinity; function GetThread(thrdIndex: integer): TLoopThread; procedure SetShutdown(const Value: boolean); function GetShutdown: boolean; private FOnControllerMarkThread: TNotifyEvent; FOnControllerUnmarkThread: TNotifyEvent; procedure SetOnControllerMarkThread(const Value: TNotifyEvent); procedure SetOnControllerUnmarkThread(const Value: TNotifyEvent); strict protected property Shutdown: boolean read GetShutdown write SetShutdown; public (* Block granularity for TThreadingMode.tmForLoop. Use this property to address asymetric multi-processing. By default the for-loop range will be split equally among all available threads. Within each thread a further split of the assigned indexed range can be specified with BlockGranularity. When this parameter is 1, each thread will call the compute event/callback once, when it is 2, then twice, etc... of course with the adjusted index parameters in the callback event. This is usefull when: The load can vary depending on the values to be processed. The threads are running on CPU architectures with particulary large turbo frequencies for individual cores. The threads are running on asymetric CPU architectures like Intel Alder Lake, where not all CPU cores are equally fast (P+E). It is not possible to completely accurately predict the amount of computation to be done within the threads. If some threads will finish faster than others, they can start to work on other unfinished sections without waiting for the slowest thread to finish. The drawback is that some threads may never get to be launched at all, because the job will be finished, before each thread will be able to get their piece of it and other threads will process multiple pieces. Do not assume that all "ThreadIndex" values in the callback event will be used, when BlockGranularity is specified to be more than 1. An alternative solution to this parameter is to specify ThreadCount, which is 2x, 4x, etc... bigger than CPU core count. Increasing ThreadCount beyond CPU core count however is not recommended. Running more threads will also put additional pressure on any shared resources protected with critical sections like memory managers and MtxVec object cache. This parameter applies only to: When this value is bigger than 1, a "greedy" job distribution approach is used to distribute work among threads. The default value is 1 (disabled). The value of 4 allows 4x shorter average job running time in compare to 1 with smaller spread of running times and is recommended for real-time processing of audio and video. *) property BlockGranularity: integer read FBlockGranularity write SetBlockGranularity default 1; (* Provides access to internal thread objects. *) property Thread[thrdIndex: integer]: TLoopThread read GetThread; default; (* Specifies how the threads will be distributed between physical CPU cores. *) property ThreadAffinityMode: TThreadAffinityMode read FThreadAffinityMode write SetThreadAffinityMode; (* Returns error message associated with thread number i. Returns any error message associated with thread at Index i. Total number of threads to browse through is defined with ThreadCount property. *) property ErrorMessage[i: integer]: string read GetErrorMessage write SetErrorMessage; (* Loop starting index when computing for loop. *) property Min: integer read FMin write SetMin; (* Final Loop index when computing for loop. *) property Max: integer read FMax write SetMax; (* Specifies if we are threading for or while loop. *) property ThreadingMode: TThreadingMode read FThreadingMode write SetThreadingMode; (* Defines the number of threads to use processing. ThreadCount should typically not be larger than Controller.CpuCores. *) property ThreadCount: integer read FThreadCount write SetThreadCount; (* Defines thread priority for all internal threads. *) property Priority: TThreadPriority read FPriority write SetPriority; (* Specifies the name base for naming the threads in the debugger. Threads will be named as : NameOfThreadSet + IntToStr(ThreadIndex); *) property NameOfThreadSet: string read FNameOfThreadSet write SetNameOfThreadSet; (* Returns true when threads are idle and waiting for a job. *) function IsProcessingIdle: boolean; (* Returns true when threads have encountered and error while processing. *) function HasRaisedErrors: boolean; (* Returns concatenated list of errors from all threads using ';' as the separator. *) function ErrorMessages: string; (* Returns combined loop iteration Index to determine the progress of the computation. When processing a range loop (threaded function has min and max parameters) it is the users responsability to update Thread.LoopIndex variable, if this indicator is required. Example: IntInterlockedIncrement(Thread.LoopIndex); This is because the actual loop runs within the users code. This function will return the sum of iterations added to the starting Min value. In case of a while-loop, the CombinedLoopIndex and CombinedLoopCount returns the same result. The user is not allowed to increase Thread.LoopIndex In case of a for-loop without specified range the function will return the sum of iterations added to the starting Min value. The user is not allowed to increase Thread.LoopIndex *) function CombinedLoopIndex: integer; (* Returns combined loop iteration count to determine the progress of the computation. When processing a range loop (threaded function has min and max parameters) it is the users responsability to update Thread.LoopIndex variable, if this indicator is required. Example: IntInterlockedIncrement(Thread.LoopIndex); This is because the actual loop runs within the users code. This function will return the count of all local thread iterations. The user is not allowed to increase Thread.LoopIndex In case of a while-loop or a for-loop without range the function will return combined number of iterations performed by all threads from the start of computation. The user is not allowed to increase Thread.LoopIndex *) function CombinedLoopCount: integer; (* Blocking call which will not return until all threads are idle. Calling Stop will signal threads to break out of for or while loop. The call will block until all threads are idle. *) procedure Stop; (* Non-blocking call which start the processing. Calling Start will initiate processing of a for or wile loop. The call will not block. To wait for processing to finish call WaitForProcessingFinish method. *) procedure Start; overload; (* Non-blocking call which start the processing. Calling Start will initiate processing of a for or wile loop. The call will not block. To wait for processing to finish call WaitForProcessingFinish method. The Context will be passed to the threaded function as the parameter allowing any localy declared variables to be used by the threaded function, without the need to rely only on global vars. *) procedure Start(const Context: array of TObject); overload; (* Blocking which will not return until all threads have done processing and are running idle. If ProcessMessages is true, the main thread will not be blocked. However, the recommended method to allow monitoring of the progress of the computation is not to call Start from the main thread. Use a separate thread for that purpose. See example below. procedure TExecuteThread.Execute; var am: Matrix; begin am.Size(1001,100); am.SetVal(1); DoForLoop(0,1000, ForLoopForm.MyLoop, forLoop,[TMtx(am)]); end; procedure TForLoopForm.Button2Click(Sender: TObject); var aThread: TThread; //needed only to allow monitoring of execution begin Timer.OnTimer := Timer1Timer; Timer.Enabled := true; //start the timer which will update the display aThread := TExecuteThread.Create(true); aThread.FreeOnTerminate := True; aThread.OnTerminate := OnComputationEnded; aThread.Resume; end; procedure TForLoopForm.Timer1Timer(Sender: TObject); begin Label1.Caption := 'Loop running time: ' + IntToStr(ForLoop.LoopRunningTime) + 'ms'; end; *) procedure WaitForProcessingFinish(ProcessMessages: boolean = false); (* Returns number of ms for which the processing has been running. *) function LoopRunningTime: double; (* Call to cancel the processing. This will indicate that looping should stop, but to quit any processing within threaded procedure has to be checked by the procedure explicitely. procedure MyLoopRange(IdxStart, IdxEnd: integer; const Context: TObjectArray; ThreadIndex: integer); var j, k: integer; a: TMtx; begin a := TMtx(Context[0]); for k := IdxStart to IdxEnd do //additional vectorization possible inside these two loops begin for j := 0 to a.Cols - 1 do begin a[k, j] := a[k, j] + 1; end; //Check, if we need to finish prematurely mtxForLoop[ThreadIndex].CancelProcessing then Exit; end; end; *) procedure CancelProcessing; constructor Create; destructor Destroy; override; (* Assign method pointer to be called by multiple threads to compute a for loop. *) property OnForLoop: TForLoopEvent read FOnForLoop write SetOnForLoop; (* Assign method pointer to be called by multiple threads to compute a for loop. *) property OnForLoopRange: TForLoopRangeEvent read FOnForLoopRange write SetOnForLoopRange; (* Assign method pointer to be called by multiple threads to compute a while loop. *) property OnWhileLoop: TWhileLoopEvent read FOnWhileLoop write SetOnWhileLoop; (* Assign function pointer to be called by multiple threads to compute a for loop. *) property OnForLoopFun: TForLoopFunEvent read FOnForLoopFun write SetOnForLoopFun; (* Assign function pointer to be called by multiple threads to compute a for loop. *) property OnForLoopRangeFun: TForLoopRangeFunEvent read FOnForLoopRangeFun write SetOnForLoopRangeFun; (* Assign function pointer to be called by multiple threads to compute a while loop. *) property OnWhileLoopFun: TWhileLoopFunEvent read FOnWhileLoopFun write SetOnWhileLoopFun; property OnControllerMarkThread: TNotifyEvent read FOnControllerMarkThread write SetOnControllerMarkThread; property OnControllerUnmarkThread: TNotifyEvent read FOnControllerUnmarkThread write SetOnControllerUnmarkThread; end; (* Call this function to initiate threaded for-loop. The MyLoop method pointer must be a method. This is the function that will be called once by each thread. Threads parameter requires a TMtxForLoop object and the Context parameter can be used to pass any parameters to the threaded function. The threading engine will attempt to equaly partition the job between available threads assuming constant computational load for each Iteration in the range from IterMin to IterMax. However, further vectorization is possible within each threaded function call. Use MtxVec.DoForLoop to take advantage of super-conductive MtxVec object cache. Calling ThreadedForLoop in parallel from multiple threads will not work. The call is to be protected with a critical section or otherwise. *) function ThreadedForLoop(IterMin, IterMax: integer; MyLoop: TForLoopRangeEvent; Threads: TMtxForLoop; const Context: array of TObject): boolean; overload; (* Call this function to initiate threaded for-loop. The MyLoop method pointer must be a method. This is the function that will be called (IterMax - IterMin + 1) times. Threads parameter requires a TMtxForLoop object and Context can be used to pass any parameters to the threaded function. Computational load for each Iteration in the range from IterMin to IterMax is allowed to vary (possibly by a lot). Further vectorization within each threaded function call is not possible across the working Iteration range. Use MtxVec.DoForLoop to take advantage of super-conductive MtxVec object cache. Calling ThreadedForLoop in parallel from multiple threads will not work. The call is to be protected with a critical section or otherwise. *) function ThreadedForLoop(IterMin, IterMax: integer; MyLoop: TForLoopEvent; Threads: TMtxForLoop; const Context: array of TObject): boolean; overload; (* Call this function to initiate threaded while-loop. The MyLoop method pointer must be a function (not object method). This is the function that will be called until Stop parameter of MyLoop will be returned as True. Threads parameter requires a TMtxForLoop object and Context can be used to pass any parameters to the threaded function. Use MtxVec.DoWhileLoop to take advantage of super-conductive MtxVec object cache. Calling ThreadedWhileLoop in parallel from multiple threads will not work. The call is to be protected with a critical section or otherwise. *) function ThreadedWhileLoop(MyLoop: TWhileLoopEvent; Threads: TMtxForLoop; const Context: array of TObject): boolean; overload; (* Call this function to initiate threaded for-loop. The MyLoop method pointer must be a function (not object method). This is the function that will be called (IterMax - IterMin + 1) times. Threads parameter requires a TMtxForLoop object and Context can be used to pass any parameters to the threaded function. The computational load of MyLoop function is allowed to vary from one iteration to the next. Use MtxVec.DoForLoop to take advantage of super-conductive MtxVec object cache. Calling ThreadedForLoop in parallel from multiple threads will not work. The call is to be protected with a critical section or otherwise. *) function ThreadedForLoop(IterMin, IterMax: integer; MyLoop: TForLoopFunEvent; Threads: TMtxForLoop; const Context: array of TObject): boolean; overload; (* Call this function to initiate threaded for-loop. The MyLoop method pointer must be a function (not object method). This is the function that will be called once and will allow further code vectorization inside the thread. Threads parameter requires a TMtxForLoop object and Context can be used to pass any parameters to the threaded function. Use MtxVec.DoForLoop to take advantage of super-conductive MtxVec object cache. Calling ThreadedForLoop in parallel from multiple threads will not work. The call is to be protected with a critical section or otherwise. *) function ThreadedForLoop(IterMin, IterMax: integer; MyLoop: TForLoopRangeFunEvent; Threads: TMtxForLoop; const Context: array of TObject): boolean; overload; (* Call this function to initiate threaded while loop. The MyLoop method pointer must be a method (of object). This is the function that will be called until Stop parameter of MyLoop will be True. Threads parameter requires a TMtxForLoop object and Context can be used to pass any parameters to the threaded function. Use MtxVec.DoWhileLoop to take advantage of super-conductive MtxVec object cache. Calling ThreadedWhileLoop in parallel from multiple threads will not work. The call is to be protected with a critical section or otherwise. *) function ThreadedWhileLoop(MyLoop: TWhileLoopFunEvent; Threads: TMtxForLoop; const Context: array of TObject): boolean; overload; (* Returns initialized global thread pool. The (singleton) thread pool will be created, if it does not yet exists. *) procedure CheckGlobalThreadPool(var Threads: TMtxForLoop); var mtxThreadPool: TMtxForLoop; (*Adds support for numerical integration and differentiation.*) unit MtxIntDiff; interface {$I BdsppDefs.inc} uses MtxVec, MtxVecInt, Math387 ,Types ; type (*Defines numerical integration algorithm exit reason.*) TIntStopReason = ( (*The result converged within given tolerance.*)intConverged, (*The result did not converge within given tolerance.*)intNotConverged); (*Defines weight type for Gauss quadrature integration algorithm. *) TQuadMethod = ( (*Use the Gauss quadrature formula for calculating weights and base points.*)qmGauss, (*Use the Chebyshew-Gauss formula to calculate base points and weight.*)qmChebyshevGauss, (*Use thd Newron-Cotes formula to calculate base points and weights.*)qmNewtonCotes); (*Defines integration algorithm.*) TIntegrateAlgo = ( (*Traapez rule method.*)intAlgoTrapez, (*Simpson algorithm.*)intAlgoSimpson, (*Boole integration method.*)intAlgoSimpson38, (*Gauss integration algorithm.*)intAlgoGauss, (*Romberg method.*)ntAlgoRomberg, (*Monte-Carlo method.*)intAlgoMonteCarlo ); (*Numerical gradient approximation methods. Defines different numerical gradient approximation methods. *) TNumericGradMethod = ( (*High precision numerical differentiation. The algorithm uses Richardson extrapolation of three values of the symmetric difference quotient.*)numRichardson, (*Numerical differentiation using the forward difference quotient.*)numDifference); (*Numerical gradient by high precision numerical differentiation. Real function of several variables. Function variables. Array of additional constants which can be used in math formula. Array of additional constants (pointers) which can be used in math formula. Returns calculated gradient. If needed, Grad Length and Complex properties are adjusted automatically. Calculates the numerical gradient by high precision numerical differentiation. The algorithm uses Richardson extrapolation of three values of the symmetric difference quotient. The gradient step size is defined by global variable. Normally the optimal stepsize depends on seventh partial derivatives of the function. Since they are not available, the initial value for GradientStepSize is Exp(Ln(EPS)/7)*0.25, as suggested by Spellucci. *) procedure NumericGradRichardson(Fun : TRealFunction; const Pars: TVec; const Consts: TVec; const ObjConst: Array of TObject; const Grad: TVec); (*Numerical gradient by numerical differentiation using the forward difference quotient. Real function of several variables. Function variables. Array of additional constants which can be used in math formula. Array of additional constants (pointers) which can be used in math formula. Returns calculated gradient. If needed, Grad Length and Complex properties are adjusted automatically. Calculates the numerical gradient by numerical differentiation using the forward difference quotient. The NumericGradDifference procedure can be used with a very moderate ( >= 1.0e-4) precision requirement. *) procedure NumericGradDifference(Fun : TRealFunction; const Pars: TVec;const Consts: TVec; Const ObjConst: Array of TObject; const Grad: TVec); (*Numerical gradient and Hessian matrix. Real function of several variables. Function variables. Array of additional constants which can be used in math formula. Array of additional constants (pointers) which can be used in math formula. Returns calculated gradient. If needed, Grad Length and Complex properties are adjusted automatically. Returns calculated Hessian matrix. If needed, Hess matrix size and complex properties are adjusted automatically. Calculates the numerical gradient and Hessian matrix. *) procedure NumericGradHess(Fun: TRealFunction; const Pars: TVec;const Consts: TVec; Const ObjConst: Array of TObject; const Grad: TVec; const Hess: TMtx); (*Gauss base points and weights. Calculates base points and weight factors by using the so called Gauss algorithm given by Davis and Rabinowitz in 'Methods of Numerical Integration', page 365, Academic Press, 1975. Use a ten point Gauss formula to evaluate six(x) on interval [0,PI]. For start use only one subsection. private double IntFun(TVec x, TVec c, params object[] o) { double x = x[0]; return System.Math.Sin(x)*System.Math.Exp(-x*x); } private void Example() { Vector bpoints = new Vector(0); Vector weights = new Vector(0); MtxIntDiff.WeightsGauss(10,bpoints,weights); double area = MtxIntDif.QuadGauss(IntFun,-0.5*System.Math.PI,System.Math.PI,bpoints,weights,64); } *) procedure WeightsGauss(NumPoints: Integer; const Points, Weights: TVec; const FloatPrecision: TMtxFloatPrecision = mvDouble ); (*Chebyshev-Gauss base points and weights. Calculates base points and weights for numerical integration by using the Chebyshev-Gauss scheme. Check the following link to learn more about this algorithm *) procedure WeightsChebyshevGauss(NumPoints: Integer; const Points, Weights: TVec; const FloatPrecision: TMtxFloatPrecision = mvDouble ); (*Newton-Cotes base points and weights. Defines the interpolating polynomial order. Returns base points coordinate. Returns weights. Specifies the precision of the weights to be returned. Uses the Newton-Cotes formulas to calculate base points and weights for numerical integration. Check the following link to learn more about Newton-Cotes formulas. Use Simpson rule to evaluate sin(x) on interval [0,PI]. // Integrating function private double IntFunc(TVec Parameters, TVec c, params object[] o) { double x = Parameters[0]; return System.Math.Sin(x); } // Integrate private void DoIntegrate() { Vector bpoints = new Vector(0); Vector weights = new Vector(0); MtxIntDiff.WeightsNewtonCotes(2,bpoints,weights); // 2 means Simpson double area = QuadGauss(IntFunc,0,System.Math.PI,bpoints,weights,1); } *) procedure WeightsNewtonCotes(PolyOrder: Integer; const Points, Weights: TVec; const FloatPrecision: TMtxFloatPrecision = mvDouble ); (*Numerical integration by using regular Gaussian quadrature scheme. the numerical approximate on integral of function Fun between limits lb and ub. Check the following link to learn more about this algorithm Evaluate fuction Sin(x)*Exp(-x^2) on interval -PI/2, PI. private double IntFun(TVec x, TVec c, params object[] o) { double x = x[0]; return System.Math.Sin(x)*System.Math.Exp(-x*x); } private void Example() { Vector bpoints = new Vector(0); Vector weights = new Vector(0); MtxIntDiff.WeightsGauss(10,bpoints,weights); double area = MtxIntDif.QuadGauss(IntFun,-0.5*System.Math.PI,System.Math.PI,bpoints,weights,64); } *) function QuadGauss(Fun: TRealFunction; lb, ub: double; const BasePoints, Weights: TVec; Parts: Integer):double; overload; (*Numerical integration by using regular Gaussian quadrature scheme (Fun defined only with double(s)).*) function QuadGauss(Fun: TRealFunction; lb, ub: double; const Constants: TVec; Const ObjConst: Array of TObject; const BasePoints, Weights: TVec; Parts: Integer):double; overload; (*Evaluate the numerical integral between lower and upper bound using Gauss quadrature algorithm. the numerical approximate on integral of function Fun between limits lb and ub. This version calculates base points and weights on the fly. *) function QuadGauss(Fun: TRealFunction; lb, ub: double; const Constants: TVec; Const ObjConst: Array of TObject; out StopReason: TIntStopReason; const FloatPrecision: TMtxFloatPrecision; QMethod: TQuadMethod = qmGauss; Tolerance: double = 1.0E-4; MaxIter:Integer = 8):double; overload; (*Integration by using Gauss quadrature algorithm with no additional parameters for Fun. the numerical approximate on integral of function Fun between limits lb and ub. This version calculates base points and weights on the fly. Note Use this overload if integrating function is defined only by double parameter(s). Evaluate fuction Sin(x)*Exp(-x^2) on interval [-PI/2, PI]. Use default Gauss base points and weights. private double IntFun(TVec x, TVec c, params object[] o) { double x = x[0]; return System.Math.Sin(x)*System.Math.Exp(-x*x); } private void Example() { TIntStopReason sr; double area = MtxIntDif.QuadGauss(IntFun,-0.5*System.Math.PI, System.Math.PI, out sr, 1.0e-4, 8); } *) function QuadGauss(Fun: TRealFunction; lb, ub: double; out StopReason: TIntStopReason; const FloatPrecision: TMtxFloatPrecision; QMethod: TQuadMethod = qmGauss; Tolerance: double = 1.0E-4; MaxIter:Integer = 8):double; overload; (*Numerical integration by using recursive Romberg algorithm. the numerical approximate on integral of function Fun between limits lb and ub. Integrating function. Additional constants defining Fun function, usually nil/null. Additional objects defining Fun function, usually nil/null. Defines lower bound. Defines upper bound. Returns algorithm stop reason. Defines integration tolerance. Defines maximum number of alorithm iterations. Defines the computational precision to be used by the routine. Evaluate fuction Sin(x)*Exp(-x^2) on interval [0,PI/2] by using Romberg algorithm. private double IntFun(TVec x, TVec c, params object[] o) { double x = x[0]; return System.Math.Sin(x)*System.Math.Exp(-x*x); } private void Example() { TIntStopReason sr; double area = MtxIntDif.Romberg(IntFun,0.0,5*System.Math.PI,out sr, 1.0e-4, 100); } *) function Romberg(Fun: TRealFunction; lb, ub: double; const FloatPrecision: TMtxFloatPrecision; Const Constants: TVec; Const ObjConst: Array of TObject; out StopReason: TIntStopReason; Tolerance: double = 1.0e-4; MaxIter:Integer = 100):double; (*Numerical integration by using optimized quadrature formula. the numerical approximate on integral of function Fun between limits lb and ub. *) function QuadRegular(Fun: TRealFunction; lb, ub: double; const FloatPrecision: TMtxFloatPrecision; Const Constants: TVec; Const ObjConst: Array of TObject; X0, F0: TVec; out StopReason: TIntStopReason; Tolerance: double = 1.0E-4; MaxIter:Integer = 8; MaxNInsert: Integer = 7): double; (*Numerical integration by Monte Carlo method. the numerical approximate on integral of function Fun between limits lb and ub. Integrating function. Additional constants defining Fun function, usually nil/null. Additional objects defining Fun function, usually nil/null. Defines lower bound. Defines pper bound. Number of random points in [lb,ub] interval (see comments above). Defines the computational precision to be used by the routine. Performs a numerical integration of function of single variable by using Monte Carlo method. Evaluate fuction Sin(x) on interval [0,PI] by using Monte Carlo algorithm. private double IntFun(TVec x, TVec c, params object[] o) { double x = x[0]; return System.Math.Sin(x); } private void Example() { TIntStopReason sr; double area = MtxIntDif.MonteCarlo(IntFun,0.0,System.Math.PI,null,null,65536); } *) function MonteCarlo(Fun: TRealFunction; lb, ub: double; const FloatPrecision: TMtxFloatPrecision; Const Constants: TVec; Const ObjConst: Array of TObject; N: Integer = 65536): double; (*Class and type definitions for the expression parser. Addapted from TExpressionParser. Written by Egbert van Nes (Egbert.vanNes@Aqec.WKAO.WAU.NL). *) unit MtxParseClass; interface {$I BdsppDefs.inc} uses Math387, MtxVec, MtxVecInt, MtxBaseComp, MtxVecBase, AbstractMtxVec ,Contnrs ,Classes, SysUtils ; const HEX_PREFIX = '$'; ARGUMENT_SEPARATOR = ','; EXPRESSION_SEPARATOR: string = sLineBreak; LEFT_BRACKET = '('; RIGHT_CLOSED_BRACKET = ']'; LEFT_CLOSED_BRACKET = '['; RIGHT_BRACKET = ')'; DECIMAL_SEPARATOR = '.'; SEMICOLON = ';'; COLON = ':'; const (*Maximum number of function arguments.*) MaxArg = 18; UnknownExprWord: string = 'Unrecognized function or value select called on undefined variable!'; type (*Defines value type.*) TExprValueType = ( (*Undefined value.*) vtUndefined = 0, (*Double value.*) vtDoubleValue = 1, (*Range*) vtRangeValue = 2, (*String.*) vtString = 3, (*Complex value.*) vtComplexValue = 4, (*Vector.*) vtVectorValue = 5, (*Integer*) vtIntegerValue = 6, (*Int vector*) vtIntVectorValue = 7, (*Int Matrix*) vtIntMatrixValue = 8, (*Bool.*) vtBoolValue = 9, (*Bool vector.*) vtBoolVectorValue = 10, (*Bool matrix.*) vtBoolMatrixValue = 11, (*Matrix.*) vtMatrixValue = 12, (*List of strings.*) vtStringListValue = 13, (*Custom object.*) vtCustomValue = 14 ); type TSimpleType = ( stUndefined, stInt8, stInt16, stInt32, stInt64, stUInt8, stUInt16, stUInt32, stUInt64, stFloat, stDouble, stFloatComplex, stDoubleComplex, stBoolean, stString ); const ValTypeAsStr: array [TExprValueType] of string = ( 'undefined', 'double', 'range', 'string', 'complex', 'vector', 'integer', 'integer vector', 'integer matrix', 'bool', 'bool vector', 'bool matrix', 'matrix','string list','custom object'); (* Types of lexems. Does not include operators. *) type TLexemeType = Cardinal; const ltConstant = 1; const ltVariable = 2; const ltFunction = 4; const ltVaryingFunction = 8; const ltOperator = 16; const ltLeftBracket = 32; const ltRightBracket = 64; const ltLeftSquareBracket = 128; const ltRightSquareBracket = 256; const ltSemicolon = 512; const ltComma = 1024; type TLexemeTypes = Cardinal; (*Parser exception error class.*) EMtxParseError = class(EMtxVecException) end; TExprRec = class; TExprWord = class; (*Function type for custom function definition. Any custome defined function must be of this type to be used in the expression parser. void _log10x(TExprRec Param); { } void Example() { TMtxExpression ep = new TMtxExpression(); ep.DefineFunction("Log10x",_log10x,1); ep.Add("Log10x(1.2)+3"); *) TExprFunc = procedure(const Expr: TExprRec); TOperVector = array [vtUndefined..vtCustomValue] of TExprFunc; TOperMatrix = array [vtUndefined..vtCustomValue, vtUndefined..vtCustomValue] of TExprFunc; (**) TValueRec = class(TPersistent) strict private FRangeIntPrecision: TIntPrecision; FTag: NativeInt; procedure SetRangeIntPrecision(const Value: TIntPrecision); procedure SetTag(const Value: NativeInt); procedure ReadBinData(Stream: TStream); overload; procedure WriteBinData(Stream: TStream); overload; strict protected fOwned: boolean; fExtRange: Boolean; fBoolValue: boolean; fIntegerValue: Int64; fValueType: TExprValueType; fDoubleValue: double; fComplexValue: TCplx; fIntVectorValue: TVecInt; fIntMatrixValue: TMtxInt; fVectorValue: TVec; fMatrixValue: TMtx; FStringValue: string; fCustomValue: TObject; FStringListValue: TStringList; FOnUndefine: TNotifyEvent; FValueTypeLock: boolean; procedure SetOnUndefine(const Value: TNotifyEvent); procedure SetValueTypeLock(const Value: boolean); procedure SetStringListValue(const Value: TStringList); procedure SetCustomValue(const Value: TObject); procedure SetIntegerValue(const Value: Int64); procedure SetValueType(vtype: TExprValueType); procedure SetMatrixValue(const Value: TMtx); procedure SetVectorValue(const Value: TVec); procedure SetBoolValue(const Value: boolean); procedure SetStringValue(const Value: string); procedure SetIntVectorValue(const Value: TVecInt); procedure SetIntMatrixValue(const Value: TMtxInt); function getVectorValue: TVec; function GetIntVectorValue: TVecInt; procedure InternalUndefine(vtype: TExprValueType); strict protected procedure DefineProperties(Filer: TFiler); override; procedure AssignTo (Dest: TPersistent); override; function GetAsString: string; virtual; public fRange: TIntegerArray; property IsOwned: boolean read fOwned; constructor Create; destructor Destroy; override; procedure AssignOper (const vrec: TValueRec); procedure Copy (const vrec: TValueRec); (* Returns object in which the data is stored. Returns TVec, TVecInt, TMtx, TMtxInt or Custom object depending on ValueType property. *) function ValueObject: TObject; (*Returns True, if valueType is vtDoubleValue or vtIntegerValue.*) function IsRealValue: boolean; (*Define value as custom object value with initial value of nil.*) procedure DefineCustomValue; overload; (*Define value as range.*) procedure DefineInteger; overload; (*Define value as integer vector.*) procedure DefineIntVector; overload; (*Define value as integer vector.*) procedure DefineIntVector(const Vec: TVecInt; aIsOwned: boolean = false); overload; (*Define value as integer matrix.*) procedure DefineIntMatrix; overload; (*Define value as integer matrix.*) procedure DefineIntMatrix(const mtx: TMtxInt; aIsOwned: boolean = false); overload; (*Define value as string.*) procedure DefineString; overload; (*Define value as a boolean.*) procedure DefineBool; overload; (*Define value as a vector of boolean values.*) procedure DefineBoolVector; overload; (*Define value as a vector of boolean values. If IsOwned is true, the var will be owned by TValueRec and released when TValueRec is freed.*) procedure DefineBoolVector(const Vec: TVecInt; aIsOwned: boolean = false); overload; (*Define value as a matrix of boolean values.*) procedure DefineBoolMatrix; overload; (*Define value as a matrix boolean values. If IsOwned is true, the var will be owned by TValueRec and released when TValueRec is freed.*) procedure DefineBoolMatrix(const mtx: TMtxInt; aIsOwned: boolean = false); overload; (*Define value as range.*) procedure DefineRange; overload; (*Define value as string list.*) procedure DefineStringList; overload; (*Define value as string list.*) procedure DefineStringList(const aList: TStringList; aIsOwned: boolean = false); overload; (*Define value as range.*) procedure DefineExtRange; overload; (*Define value as double.*) procedure DefineDouble; overload; (*Define value as complex.*) procedure DefineComplex; overload; (*Define value as vector.*) procedure DefineVector; overload; (*Define value as custom object.*) procedure DefineCustomValue(const obj: TObject; aIsOwned: boolean = false); overload; (*Define value as vector using existing vector.*) procedure DefineVector(const Vec: TVec; aIsOwned: boolean = false); overload; (*Define range value as vector using existing vector.*) procedure DefineExtRange(const Vec: TVec; aIsOwned: boolean = false); overload; (*Define value as matrix.*) procedure DefineMatrix; overload; (*Define value as matrix using existing matrix.*) procedure DefineMatrix (const mtx: TMtx; aIsOwned: boolean = false); overload; procedure Undefine; procedure InternalDefineOwned(const srcRec: TValueRec); property CustomValue: TObject read fCustomValue write SetCustomValue; (*Returns value as string.*) property AsString: string read GetAsString; (*Gets or sets value type.*) property ValueType: TExprValueType read fValueType write SetValueType; (*Returns value as double.*) property DoubleValue: double read fDoubleValue write fDoubleValue; (*Returns value as complex.*) property ComplexValue: TCplx read fComplexValue write fComplexValue; (*Returns value as vector.*) property VectorValue: TVec read GetVectorValue write SetVectorValue; (*Returns value as matrix.*) property MatrixValue: TMtx read fMatrixValue write SetMatrixValue; (*Returns value as range.*) property ExtRangeValue: TVec read fVectorValue write SetVectorValue; (*Returns value as string value.*) property StringValue: string read FStringValue write fStringValue; (*Returns value as Bool vector.*) property BoolValue: boolean read fBoolValue write fBoolValue; (*Returns value as Bool vector.*) property BoolVectorValue: TVecInt read FIntVectorValue write SetIntVectorValue; (*Returns value as Bool vector.*) property BoolMatrixValue: TMtxInt read FIntMatrixValue write SetIntMatrixValue; (*Returns value as integer.*) property IntegerValue: Int64 read fIntegerValue write SetIntegerValue; (*Returns value as Bool vector.*) property IntVectorValue: TVecInt read GetIntVectorValue write SetIntVectorValue; (*Returns value as Bool vector.*) property IntMatrixValue: TMtxInt read fIntMatrixValue write SetIntMatrixValue; property StringListValue: TStringList read FStringListValue write SetStringListValue; (*For internal use.*) property Tag: NativeInt read FTag write SetTag; (*Causes an exception, if undefine is called. Prevents ValueType to be reset. Usefull for externally defined types. *) property ValueTypeLock: boolean read FValueTypeLock write SetValueTypeLock; property RangeIntPrecision: TIntPrecision read FRangeIntPrecision write SetRangeIntPrecision; property ExtRange: boolean read fExtRange write fExtRange; property OnUndefine: TNotifyEvent read FOnUndefine write SetOnUndefine; procedure PromoteRangeToVector; end; TExprGridVariable = class; TExprGridSetProc = procedure(const Sender: TExprGridVariable; const Src: string; const row, col: integer) of object; TExprGridGetProc = procedure(const Sender: TExprGridVariable; var Dst: string; const row, col: integer) of object; (*Custom variable object type. Define TExprGridVariable object with TValueRec.DefineCustomValue. The object provides callbacks used when reading or writing to the variable. These callbacks can be used for example to read and write from a string grid or to some external large storage. *) TExprGridVariable = class(TObject) strict private FOnGetValue: TExprGridGetProc; FOnSetValue: TExprGridSetProc; FReFormat: string; FImFormat: string; FScientific: boolean; FCols: integer; FRows: integer; procedure SetOnGetValue(const Value: TExprGridGetProc); procedure SetOnSetValue(const Value: TExprGridSetProc); procedure SetImFormat(const Value: string); procedure SetReFormat(const Value: string); procedure SetScientific(const Value: boolean); procedure SetCols(const Value: integer); procedure SetRows(const Value: integer); strict protected procedure SetValue(const Src: TValueRec; const Index: integer); overload; virtual; procedure SetValue(const Src: TValueRec; const IndexStart, Step, IndexStop: integer); overload; virtual; procedure GetValue(const Dst: TValueRec; const Index: integer); overload; virtual; procedure GetValue(const Dst: TValueRec; const IndexStart, Step, IndexStop: integer); overload; virtual; procedure SetValue(const Src: TValueRec; const row, col: integer); overload; virtual; procedure SetRowValue(const Src: TValueRec; const row, colStart, colStep, colStop: integer); overload; virtual; procedure SetColValue(const Src: TValueRec; const rowStart, rowStep, RowStop, col: integer); overload; virtual; procedure SetValue(const Src: TValueRec; const rowStart, rowStep, RowStop, colStart, colStep, colStop: integer); overload; virtual; procedure GetValue(const Dst: TValueRec; const row, col: integer); overload; virtual; procedure GetRowValue(const Dst: TValueRec; const row, colStart, colStep, colStop: integer); overload; virtual; procedure GetColValue(const Dst: TValueRec; const rowStart, rowStep, RowStop, col: integer); overload; virtual; procedure GetValue(const Dst: TValueRec; const rowStart, rowStep, RowStop, colStart, colStep, colStop: integer); overload; virtual; public function getLength: integer; public (*Specifies formating of real and complex numbers to use full scientific notation (1.2313E+20 for example).*) property Scientific: boolean read FScientific write SetScientific; (*Specifies formating for real numbers and real part of complex numbers.*) property ReFormat: string read FReFormat write SetReFormat; (*Specifies formating for imaginary part f complex numbers.*) property ImFormat: string read FImFormat write SetImFormat; (*Event triggered when value of an external structure is to be set.*) property OnSetValue: TExprGridSetProc read FOnSetValue write SetOnSetValue; (*Event triggered when value of an external structure is to be fetched from.*) property OnGetValue: TExprGridGetProc read FOnGetValue write SetOnGetValue; (*Specifies row count of the grid object. Set this value to the limit to which the user can set this value, its usable range, or leave at 0. *) property Rows: integer read FRows write SetRows; (*Specifies column count of the grid object. Set this value to the limit to which the user can set this value, its usable range, or leave at 0. *) property Cols: integer read FCols write SetCols; (*Returns total number of values. Returns total number of values computed with Rows*Cols. *) property Length: integer read getLength; end; TStringValue = class (TValueRec) public constructor Create; property Value: string read fStringValue write SetStringValue; end; TIntegerValue = class (TValueRec) public constructor Create; property Value: Int64 read fIntegerValue write fIntegerValue; end; TRangeValue = class (TValueRec) public constructor Create; property Value: TIntegerArray read fRange write fRange; end; TDoubleValue = class (TValueRec) public constructor Create; property Value: double read fDoubleValue write fDoubleValue; end; TBoolValue = class (TValueRec) public constructor Create; property Value: boolean read fBoolValue write fBoolValue; end; TComplexValue = class (TValueRec) public constructor Create; property Value: TCplx read fComplexValue write fComplexValue; end; TIntVectorValue = class (TValueRec) public constructor Create; overload; constructor Create(const Vec: TVecInt); overload; property Value: TVecInt read fIntVectorValue write SetIntVectorValue; end; TStringListValue = class (TValueRec) public constructor Create; overload; constructor Create(const strList: TStringList); overload; property Value: TStringList read fStringListValue write SetStringListValue; end; TIntMatrixValue = class (TValueRec) public constructor Create; overload; constructor Create(const mtx: TMtxInt); overload; property Value: TMtxInt read fIntMatrixValue write SetIntMatrixValue; end; TBoolVectorValue = class (TValueRec) public constructor Create; overload; constructor Create(const Vec: TVecInt); overload; property Value: TVecInt read fIntVectorValue write SetIntVectorValue; end; TBoolMatrixValue = class (TValueRec) public constructor Create; overload; constructor Create(const mtx: TMtxInt); overload; property Value: TMtxInt read fIntMatrixValue write SetIntMatrixValue; end; TVectorValue = class (TValueRec) public constructor Create; overload; constructor Create(const Vec: TVec); overload; property Value: TVec read fVectorValue write SetVectorValue; end; TCustomValue = class (TValueRec) public constructor Create; overload; constructor Create(const obj: TObject); overload; property Value: TObject read fCustomValue write SetCustomValue; end; TMatrixValue = class (TValueRec) public constructor Create; overload; constructor Create(const mtx: TMtx); overload; property Value: TMtx read fMatrixValue write SetMatrixValue; end; TExprFuncObj = procedure (const Param: TExprRec) of object; TExprRec = class public Oper: TExprFunc; OperObj: TExprFuncObj; Next: TExprRec; Res: TValueRec; tmpRes: TValueRec; ExprWord: TExprWord; ArgCount: integer; Args: array of TValueRec; ArgList: array of TExprRec; procedure ResizeArgs(NewArgs: integer); constructor Create; destructor Destroy; override; end; TExprWord = class strict protected fName: string; fLexemeType: TLexemeType; FMaxArgCount: integer; FVariableArgCount: boolean; function GetFunc: TExprFunc; function GetHelp: string; function GetFuncObj: TExprFuncObj; procedure SetMaxArgCount(const Value: integer); procedure SetVariableArgCount(const Value: boolean); procedure SetNResultArg(const Value: integer); procedure SetVRecOwned(const Value: boolean); strict protected fFunc: array [0..MaxArg - 1] of TExprFunc; fFuncObj: array [0..MaxArg - 1] of TExprFuncObj; fHelp: array [0..MaxArg - 1] of string; fNFuncArg: integer; fNResultArg: integer; fOperPrec: integer; fVRec: TValueRec; fVRecIsOwned: boolean; procedure SetNFuncArg(ANFuncArg: integer); virtual; public constructor Create (const AName: string; ALexemeType: TLexemeType); overload; constructor Create (const AName: char; ALexemeType: TLexemeType); overload; destructor Destroy; override; function HasOverload(ArgCount: integer): boolean; function CanHaveZeroArguments: boolean; procedure DefineExternalVariable(const Src: TValueRec; const IsSrcOwned: boolean = false); property Name: string read fName; property Func: TExprFunc read GetFunc; property LexemeType: TLexemeType read fLexemeType; property OperPrec: Integer read fOperPrec; property VRec: TValueRec read fVRec; property VRecOwned: boolean read FVRecIsOwned; property Help: string read GetHelp; property FuncObj: TExprFuncObj read GetFuncObj; property MaxArgCount: integer read FMaxArgCount write SetMaxArgCount; property NFuncArg: Integer read fNFuncArg write SetNFuncArg; property NResultArg: integer read FNResultArg write SetNResultArg; property VariableArgCount: boolean read FVariableArgCount write SetVariableArgCount; end; TExprSemicolon = class (TExprWord) public constructor Create; end; TExprLeftBracket = class (TExprWord) public constructor Create; end; TExprRightBracket = class (TExprWord) public constructor Create; end; TExprLeftSquareBracket = class (TExprWord) public constructor Create; end; TExprRightSquareBracket = class (TExprWord) public constructor Create; end; TExprComma = class (TExprWord) public constructor Create; end; TExprConstant = class (TExprWord) public constructor Create (const AName: string; const AValue: string; const ConstantsAlwaysReal: boolean); end; TExprStringConstant = class (TExprWord) public constructor Create(const AValue: string); overload; constructor Create(const AName: string; const AValue: string; const Help: string); overload; end; TExprDoubleConstant = class (TExprWord) public constructor Create (const AName: string; AValue: double; const Help: string); end; TExprComplexConstant = class (TExprWord) public constructor Create (const AName: string; AValue: TCplx; const Help: string); end; TExprBoolConstant = class (TExprWord) public constructor Create (const AName: string; AValue: boolean; const Help: string); end; TExprIntegerConstant = class (TExprWord) public constructor Create (const AName: string; AValue: Int64; const Help: string); end; TExprRangeConstant = class (TExprWord) public constructor Create (const AName: string; const AValue: TIntegerArray; const Help: string); end; TExprVectorConstant = class (TExprWord) public constructor Create (const AName: string; AValue: TVec; const Help: string); end; TExprStringListConstant = class (TExprWord) public constructor Create (const AName: string; AValue: TStringList; const Help: string); end; TExprExtRangeConstant = class (TExprWord) public constructor Create (const AName: string; AValue: TVec; const Help: string); end; TExprBoolVectorConstant = class (TExprWord) public constructor Create (const AName: string; AValue: TVecInt; const Help: string); end; TExprIntVectorConstant = class (TExprWord) public constructor Create (const AName: string; AValue: TVecInt; const Help: string); end; TExprMatrixConstant = class (TExprWord) public constructor Create (const AName: string; AValue: TMtx; const Help: string); end; TExprIntMatrixConstant = class (TExprWord) public constructor Create (const AName: string; AValue: TMtxInt; const Help: string); end; TExprBoolMatrixConstant = class (TExprWord) public constructor Create (const AName: string; AValue: TMtxInt; const Help: string); end; TExprVariable = class (TExprWord) public constructor Create (const AName: string); end; TExprDoubleVariable = class (TExprWord) public constructor Create (const AName: string); end; TExprIntegerVariable = class (TExprWord) public constructor Create (const AName: string); end; TExprBoolVariable = class (TExprWord) public constructor Create (const AName: string); end; TExprRangeVariable = class (TExprWord) public constructor Create (const AName: string); end; TExprStringVariable = class (TExprWord) public constructor Create (const AName: string); end; TExprComplexVariable = class (TExprWord) public constructor Create (const AName: string); end; TExprVectorVariable = class (TExprWord) public constructor Create (const AName: string); overload; constructor Create (const AName: string; const Vec: TVec); overload; end; TExprCustomValueVariable = class (TExprWord) public constructor Create (const AName: string); overload; constructor Create (const AName: string; const obj: TObject); overload; end; TExprIntVectorVariable = class (TExprWord) public constructor Create (const AName: string); overload; constructor Create (const AName: string; const Vec: TVecInt); overload; end; TExprBoolVectorVariable = class (TExprWord) public constructor Create (const AName: string); overload; constructor Create (const AName: string; const Vec: TVecInt); overload; end; TExprMatrixVariable = class (TExprWord) public constructor Create (const AName: string); overload; constructor Create (const AName: string; const mtx: TMtx); overload; end; TExprIntMatrixVariable = class (TExprWord) public constructor Create (const AName: string); overload; constructor Create (const AName: string; const mtx: TMtxInt); overload; end; TExprBoolMatrixVariable = class (TExprWord) public constructor Create (const AName: string); overload; constructor Create (const AName: string; const mtx: TMtxInt); overload; end; TExprFunction = class (TExprWord) strict protected procedure SetNFuncArg(ANFuncArg: integer); override; public constructor Create (const AName: string; AFunc: TExprFunc; ANFuncArg, ANResultArg: Integer; const Help: string); overload; constructor Create (const AName: string; ANFuncArg, ANResultArg: Integer; const AFunc: TExprFuncObj; const Help: string); overload; procedure AddOverload(const Src: TExprWord); procedure RemoveOverload(ANFuncArg: integer); end; TExprVaryingFunction = class (TExprWord) strict protected procedure SetNFuncArg(ANFuncArg: integer); override; public constructor Create(const AName: string; AFunc: TExprFunc;ANFuncArg, ANResultArg: Integer; const Help: string); overload; constructor Create(const AName: string; const ANFuncArg, ANResultArg: Integer; const AFunc: TExprFuncObj; const Help: string); overload; procedure AddOverload(const Src: TExprWord); procedure RemoveOverload(ANFuncArg: integer); end; TExprOperator = class (TExprWord) strict protected procedure SetNFuncArg(ANFuncArg: integer); override; public constructor Create (const AName: string; AFunc: TExprFunc; ANFuncArg: Integer; AOperPrec: Integer; const Help: string); overload; end; (*Named variables collection item.*) TNamedVariable = class (TMtxCollectionItem) private fVarName: string; strict private fValue: TValueRec; procedure SetValue(const Value: TValueRec); procedure SetVarName(const Value: string); strict protected procedure AssignTo (Dest: TPersistent); override; public constructor Create(Collection: TCollection); override; destructor Destroy; override; published (*Variable name.*) property VarName: string read fVarName write SetVarName; (*Variable properties. *) property Value: TValueRec read fValue write SetValue; end; (*Collection of s.*) TVariableCollection = class (TMtxCollection) strict private function GetItems(Idx: integer): TNamedVariable; procedure SetItems(Idx: integer; const Value: TNamedVariable); public constructor Create; (*Adds new named variable.*) function Add (const var_name: string): TNamedVariable; overload; function Insert (Idx: integer): TNamedVariable; overload; (*Find named variable by it's property.*) function FindByName (const var_name: string): TNamedVariable; (*Access named variable by it's index in collection.*) property Items[Idx: integer]: TNamedVariable read GetItems write SetItems; default; end; (* Expression context, holding expression list and variables with type and the data they hold. *) TExprContext = class(TPersistent) strict private fExpression: string; fVariables: TVariableCollection; procedure SetVariables(const Value: TVariableCollection); protected procedure AssignTo (dest: TPersistent); override; public constructor Create; destructor Destroy; override; procedure SaveToStream(const Dst: TStream); procedure LoadFromStream(const Src: TStream); procedure SaveToFile(const Dst: string; const Append: boolean = false); procedure LoadFromFile(const Src: string); published (*Returns expression as string.*) property Expression: string read fExpression write fExpression; (*Variables collection. *) property Variables: TVariableCollection read fVariables write SetVariables; end; (* Stores workspace for expression parser. The workspace includes command line history, names and values of named variables, script names and corresponding scripts (list of expressions). All data properties need to be assigned by the programmer. Use the object to load and save the workspace to/from files. *) TExprWorkspace = class(TPersistent) strict private FName: string; FHistory: TStringList; FScripts: TStringList; FVariables: TExprContext; FScriptNames: TStringList; procedure SetHistory(const Value: TStringList); procedure SetName(const Value: string); procedure SetScripts(const Value: TStringList); procedure SetVariables(const Value: TExprContext); procedure SetScriptNames(const Value: TStringList); public procedure Assign(Src: TPersistent); override; constructor Create; destructor Destroy; override; procedure SaveToStream(const Dst: TStream); procedure LoadFromStream(const Src: TStream); procedure SaveToFile(const Dst: string; const Append: boolean = false); procedure LoadFromFile(const Src: string); (* The name of the workspace. *) property Name: string read FName write SetName; (* List of strings to store command line history. *) property History: TStringList read FHistory write SetHistory; (* Stores lists of scripts. Each item in the list holds delimited list of one script. To retreive the script assign the Scripts[i] to TStringList.Text. Equally, assign TStrignList.Text to Scripts[i] to store a specific script. It is programmers responsability to maintain coherence between both lists: Scripts and ScriptNames. *) property Scripts: TStringList read FScripts write SetScripts; (* Stores the names of scripts in the Script property. It is programmers responsability to maintain coherence between both lists: Scripts and ScriptNames. *) property ScriptNames: TStringList read FScriptNames write SetScriptNames; (* Stores names and data of named variables. TExprContext can be filled with a call to TMtxExpression.SaveContext/LoadContext. *) property Variables: TExprContext read FVariables write SetVariables; end; TExprWordList = class(TObjectsList) strict private procedure SetItems(i: integer; const Value: TExprWord); function GetItems(i: integer): TExprWord; public property Item[i: integer]: TExprWord read GetItems write SetItems; default; function Find(const Name: string; var Index: integer): boolean; procedure Sort; overload; procedure CheckForDuplicates; virtual; constructor Create(AOwnsObjects: Boolean); overload; constructor Create; overload; end; TWordList = class; TWordPopulate = procedure(const Sender: TWordList); TExprTest = procedure(Sender: TObject); TWordList = class(TExprWordList) strict private FOnDelete: TNotifyEvent; procedure SetOnDelete(const Value: TNotifyEvent); strict private class var FOnProbabilities: TWordPopulate; class var FOnStatistics: TWordPopulate; class var FOnSignal: TWordPopulate; class var FOnCustom: TWordPopulate; class var FOnTestProbabilities: TExprTest; class var FOnTestCustom: TExprTest; class var FOnTestStatistics: TExprTest; class var FOnTestSignal: TExprTest; class procedure SetOnSignal(const Value: TWordPopulate); static; class procedure SetOnStatistics(const Value: TWordPopulate); static; class procedure SetOnCustom(const Value: TWordPopulate); static; class procedure SetOnProbabilities(const Value: TWordPopulate); static; class procedure SetOnTestCustom(const Value: TExprTest); static; class procedure SetOnTestProbabilities(const Value: TExprTest); static; class procedure SetOnTestSignal(const Value: TExprTest); static; class procedure SetOnTestStatistics(const Value: TExprTest); static; strict protected public function DefineFunctionUnsorted(const AFunctName: string; AFuncAddress: TExprFunc; NArguments, NResults: Integer; const Help: string; OverloadIdx: integer = -1): integer; overload; function DefineFunctionUnsorted(const AFunctName: string; AFuncAddress: TExprFunc; NArguments: Integer; const Help: string; OverloadIdx: integer = -1): integer; overload; function DefineFunctionUnsorted(const AFunctName: string; AFuncAddress: TExprFunc; NArguments: Integer; OverloadIdx: integer = -1): integer; overload; function DefineFunctionUnsorted(const AFunctName: string; NArguments: Integer; const AFuncAddress: TExprFuncObj; OverloadIdx: integer = -1): integer; overload; function DefineFunctionUnsorted(const AFunctName: string; NArguments, NResults: Integer; const AFuncAddress: TExprFuncObj; const Help: string; OverloadIdx: integer = -1): integer; overload; function DefineVaryingFunctionUnsorted(const AFunctName: string; NArguments, NResults: Integer; const AFuncAddress: TExprFuncObj; const Help: string; OverloadIdx: integer = -1): integer; overload; function DefineVaryingFunctionUnsorted(const AFunctName: string; NArguments: Integer; const AFuncAddress: TExprFuncObj; const Help: string; OverloadIdx: integer = -1): integer; overload; function DefineVaryingFunctionUnsorted(const AFunctName: string; NArguments: Integer; const AFuncAddress: TExprFuncObj; OverloadIdx: integer = -1): integer; overload; function DefineVaryingFunctionUnsorted(const AFunctName: string; AFuncAddress: TExprFunc; NArguments: Integer; const Help: string; OverloadIdx: integer = -1): integer; overload; function DefineVaryingFunctionUnsorted(const AFunctName: string; AFuncAddress: TExprFunc; NArguments, NResults: Integer; const Help: string; OverloadIdx: integer = -1): integer; overload; function DefineVaryingFunctionUnsorted(const AFunctName: string; AFuncAddress: TExprFunc; NArguments: Integer; OverloadIdx: integer = -1): integer; overload; function DefineOperatorUnsorted(const AOperatorSign: string; AFuncAddress: TExprFunc; NArguments: Integer; Precedence: Integer; const Help: string): integer; overload; function DefineOperatorUnsorted(const AOperatorSign: char; AFuncAddress: TExprFunc; NArguments: Integer; Precedence: Integer; const Help: string): integer; overload; function DefineOperatorUnsorted(const AOperatorSign: string; AFuncAddress: TExprFunc; NArguments: Integer; Precedence: Integer): integer; overload; procedure DefineDoubleConstantUnsorted(const AConstName: string; Value: double; const Help: string); overload; procedure DefineDoubleConstantUnsorted(const AConstName: string; Value: double); overload; procedure DefineComplexConstantUnsorted(const AConstName: string; const Value: TCplx; const Help: string); overload; procedure DefineComplexConstantUnsorted(const AConstName: string; const Value: TCplx); overload; function DefineBoolConstantUnsorted(const AConstName: string; Value: boolean): integer; overload; function DefineBoolConstantUnsorted (const AConstName: string; Value: boolean; const Help: string): integer; overload; function DefineIntegerConstantUnsorted(const AConstName: string; Value: Integer): integer; overload; function DefineIntegerConstantUnsorted (const AConstName: string; Value: Integer; const Help: string): integer; overload; (* Adds and item maintains the sorting order Finds the position where to insert and potentially also removes existing item and replaces. The bisection based search is faster than linear, but when adding large amounts of Item use the AddUnsorted overload and sort explicitely after the adding. *) function Add(const Item: TExprWord): integer; (* Adds, but requires sorting. Usefull for adding large amounts of Items in batch mode. *) function AddUnsorted(const Item: TExprWord; OverloadParentIdx: integer = -1): integer; property OnDelete: TNotifyEvent read FOnDelete write SetOnDelete; procedure DoOnProbabilities; procedure DoOnStatistics; procedure DoOnSignal; procedure DoOnCustom; constructor Create(AOwnsObjects: Boolean); overload; constructor Create; overload; public class property OnProbabilities: TWordPopulate read FOnProbabilities write SetOnProbabilities; class property OnStatistics: TWordPopulate read FOnStatistics write SetOnStatistics; class Property OnSignal: TWordPopulate read FOnSignal write SetOnSignal; class property OnCustom: TWordPopulate read FOnCustom write SetOnCustom; class property OnTestProbabilities: TExprTest read FOnTestProbabilities write SetOnTestProbabilities; class property OnTestStatistics: TExprTest read FOnTestStatistics write SetOnTestStatistics; class Property OnTestSignal: TExprTest read FOnTestSignal write SetOnTestSignal; class property OnTestCustom: TExprTest read FOnTestCustom write SetOnTestCustom; end; TExprFlowControl = ( efcNone, efcConditionalJump, efcUnconditionalJump ); TExprFlowKeyword = ( eccNone, eccIf, eccElse, eccEnd, eccWhile, eccFor, eccEndFor, eccBreak, eccContinue ); TSingleExpression = class public Str: string; Rec: TExprRec; Res: TExprRec; Words: TExprWordList; ResultName: string; FlowControl: TExprFlowControl; NextLineIndex: integer; JumpLineIndex: integer; NestingDepth: integer; FlowKeyword: TExprFlowKeyword; destructor Destroy; override; end; TExprList = class(TObjectsList) strict private procedure SetItems(i: integer; const Value: TSingleExpression); function GetItems(i: integer): TSingleExpression; public property Item[i: integer]: TSingleExpression read GetItems write SetItems; default; end; procedure UnsupportedValueTypesError(const Param: TExprRec; const vt: TExprValueType); overload; procedure UnsupportedValueTypesError(const Param: TExprRec; const vt1, vt2: TExprValueType); overload; procedure UnsupportedValueTypesError(const Param: TExprRec; const vt1, vt2, vt3: TExprValueType); overload; procedure UnsupportedValueTypesError(const Param: TExprRec; const vt1, vt2, vt3, vt4: TExprValueType); overload; procedure UnsupportedValueTypesError(const Param: TExprRec; const vt1, vt2, vt3, vt4, vt5: TExprValueType); overload; function StrToSimpleType(const Src: string): TSimpleType; procedure DisposeList(var ARec: TExprRec); (*Expression parser and function evaluator. Holds classes and components for math expression parser, evaluator and scripter. *) unit MtxParseExpr; interface {$I BdsppDefs.inc} {$WARN SYMBOL_DEPRECATED OFF} uses Classes, Contnrs, Math387, MtxVec, MtxParseClass, MtxBaseComp, MtxVecInt, Probabilities ,Polynoms, MtxVecBase, AbstractMtxVec, AbstractMtxVecInt ,Types ,Windows ; type TMtxExpression = class; TVarByNameIndexer = class strict private fOwner: TMtxExpression; function GetVarByName(const varname: string): TValueRec; public property Value[const varname: string]: TValueRec read GetVarByName; default; constructor Create(aOwner: TMtxExpression); destructor Destroy; override; end; TExprResultIndexer = class strict private fOwner: TMtxExpression; function GetExprResult(const i: integer): TValueRec; public property Value[const i: integer]: TValueRec read GetExprResult; default; constructor Create(aOwner: TMtxExpression); destructor Destroy; override; end; (*Event type for the preprocessor. *) TOnPreprocessor = procedure (Sender: TObject; Expr: TExprWordList) of object; (*Expression evaluator. The object is a compiler for mathematical expressions. It holds the lists of all compiled expression and all recognized symbols. The user can define any number of user defined variables and functions. The functions can be overloaded by specifying different parameter count. Parameters to functions and result of functions can also be strings. User defined functions can be functions or methods (of object). The math expressions can mix scalar, vector or matrix type. The following standard operators are supported: * ', the transpose/adjungate operator for matrices * power operator ^ * standard operators working on vector, matrix and scalar *, /, + , - * The per element operators working on matrices and vectors *. , /. If you dont specify per element operation, linear algebra logic will be used for * and / when operands are matrices * factorial operator ! * percentage operator % * back divison operator for matrices \ , A\B = A^(-1)*B, which comes from A*X = B and gives a solution to the system of linear equations. If matrices are not square LQR (minimum norm) solution is computed. * div and mod for integer division * comparison operators < , <= , > , >= , == * binary operators: and, not, or, xor * assign operator, = * colon operator (see below) The "i" defines a complex number: a = 2+3i; All operations support complex numbers. When using expressions which can result in a complex number like: (-1)^(1/3), the result will be complex, only if arguments are complex. The expression will also not auto reduce to a real number, even if imaginary part of the complex number is 0. To reduce the result to the real number part only, you have to call function real(x). To explicitely form a complex number use the cplx(re, im) function. The iscomplex(x) function returns 1 if the variable is complex and 0 otherwise. The type of variable is determined at compile time and may not change at run time. Vectors and matrices can be accessed by individual elements: a(i) m(r,c) or in ranges by using the colon operator: a(0:9), returns elements from index 0 to including 9. m(1:2,2:3), returns sub matrix. First element is referenced with index 0. The colon can also be used on the left side during assignment: a(0:9) = b(1:10); Optionally the colon operator also allows a step definition: a = 20:-1:-20; To return the matrix as a vector: v = m(:); Expressions with the colon operator are tightly optimized. The colon expression is only expanded to vector if needed. The variable returning result of colon expression uses . Consequently: b = a(1:10); Translates to one single TVec.Copy(..) method call. In expressions there is also no "copy" overhead. The following expression requires one call to TVec.Mul(..) and one TVec.Copy(..): c = a(1:10)*b(11:20); Vectors and matrices can also return elements from conditions: a = m(m > 4); Despite the advanced vector/matrix syntax the single scalar syntax like: c = Log(b) + d; will still execute at top speed because type resolution is done at compile time. The constant expressions like 4*4 and 2^3 or even: sin(3.2) - sqrt(cos(1.5)) are also evaluated at compile time. It is of course possible to evaluate a list of expressions: a = 1; b = 2; c = a + b; where the variables will remain in the memory until cleared. Currently there is no support for "for" and "while" loops or in-script function definitions. Other operands included: * comparison: > < <> = <= >= * *., /., +., -. to indicate per element operation on vector matrix pairs * factorial: ! * percentage: % Assignment operator is always required to be a simple " = " char, but in general the user can customize everything else. The precedence of the operands is little different from Pascal (Delphi), giving a lower precedence to logical operands, as these only act on booleans (and not on integers like in Pascal) 1. (highest): ! -x +x % 2. ^ 3. * / div mod 4. + - 5. > >= < <= <> = 6. not 7. or and xor 8. (lowest) = This precedence order is easily customizable by overriding/changing InitSymbols Optionally the operators can be redefined, but the assignment (equal) operator can not be overriden. The following class properties: MtxParseClass.TWordList.OnProbabilities MtxParseClass.TWordList.OnStatistics MtxParseClass.TWordList.OnSignal MtxParseClass.TWordList.OnCustom hold the callback functions to declare functions from the corresponding software packages. If you dont want for example the Probabilities functions to be avaialble when creating new TMtxExpression, set that property to nil. The callbacks are of type MtxParseClass.TWordPopulate. You can assign your own callback to OnCustom event for custom defined function domains. The following units need to be included in your project for the first three callbacks to be populated: MtxParseProbabilities, MtxParseSignal, MtxParseStatistics. A large set of functions and constants is already predefined. Note: Originally adapted from TExpressionParser written by Egbert van Nes (Egbert.vanNes@Aqec.WKAO.WAU.NL) with permission. Use parser to evaluate the "Sqrt(X*X + Y*Y)" formula where x=3 and y=4. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { // 1. Define variables TDoubleValue x = MyParser.DefineDouble("x"); TDoubleValue y = MyParser.DefineDouble("y"); // 2. Set values x.DoubleValue = 3.0; y.DoubleValue = 4.0; // 3. Add formula and evaluate, MyParser.AddExpr("Sqrt(x*x+y*y)"); double res = MyParser.EvaluateDouble(); // res = 5 } } *) TMtxExpression = class(TPersistent) strict private fExprList: TExprList; fWordList: TWordList; fConstList: TExprWordList; FOnPreprocessor: TOnPreprocessor; ReturnLine: TIntegerArray; BreakContinueLine: T2DIntegerArray; ewWhile, ewEnd, ewIf, ewElse, ewFor, ewEndFor, ewBreak, ewContinue, ewTrue, ewMtxVecEOA: TExprWord; ewComma, ewLeftBracket, ewRightBracket, ewRowConcat, ewColConcat, ewAssign, ewAssignOp, ewSelect, ewColonOp: TExprWord; FTestIntPrecision: TIntPrecision; fIsCompiled: boolean; FConstantsAlwaysReal: boolean; FConcatsAlwaysReal: boolean; fvarByNameIndexer: TVarByNameIndexer; fExprResultIndexer: TExprResultIndexer; FEvaluatedLine: integer; function ParseString(const AnExpression: string): TExprWordList; function MakeTree(const Expr: TExprWordList): TExprRec; function MakeLinkedList(ExprRec: TExprRec): TExprRec; procedure Check(const Expr: TExprWordList); function CheckArguments(const ExprRec: TExprRec): Boolean; procedure DisposeTree(var ExprRec: TExprRec); function EvaluateList(ARec: TExprRec): TExprRec; function RemoveConstants(ExprRec: TExprRec): TExprRec; function ResultCanVary(const ExprRec: TExprRec): Boolean; procedure GetSymbolList (const names,help: TStrings; lexeme_type: TLexemeTypes; arg_list: boolean); function GetExpression(Index: integer): string; function GetExprCount: integer; function GetExpressions: string; procedure SetExpression(Index: integer; const Value: string); procedure SetExpressions(const Value: string); procedure CreateExprRec(const se: TSingleExpression); procedure InitConsts; procedure InitSymbols; procedure InitControlWords; procedure InitFileManagement; procedure Preprocessor(const Expr: TExprWordList); procedure SetOnPreprocessor(const Value: TOnPreprocessor); function EvaluateResultName(const a: TExprRec): string; procedure SetTestIntPrecision(const Value: TIntPrecision); function EvaluateFlowKeyword(const aList: TExprWordList): TExprFlowKeyword; procedure CreateExprWords(const se: TSingleExpression); procedure CreateExprRec2(const se: TSingleExpression); procedure Run(const anExpr: string); procedure SetConstantsAlwaysReal(const Value: boolean); procedure SetConcatsAlwaysReal(const Value: boolean); function GetLastResult: TValueRec; procedure SetEvaluatedLine(const Value: integer); protected procedure TestFileFunctions; procedure TestSelectAssign; procedure DoDeleteWord(Sender: TObject); procedure CompileInternal; property TestIntPrecision: TIntPrecision read FTestIntPrecision write SetTestIntPrecision; public function GetExprResult(Index: integer): TValueRec; function GetVarByName(const aVarName: string): TValueRec; public (*Returns True, if the expressions were already compiled. Compile pass determines variables and checks program flow, but variable type is not set until the first run. *) property IsCompiled: boolean read fIsCompiled; (*Prints the value "a" of variable with "aName" to Dst. Adds lines to Dst to display the contents of variable in a on a command line like user interface. LenLimit defines the maximum number of values that will be printed, if the structure contains more than LenLimit items. *) procedure VarPrint(a: TValueRec; const aName: string; const Dst: TStrings; const LenLimit: integer = 2147483647); (*Returns TExprWord, if a symbol with aName already exists. Usefull for testing unique var names, which dont overlapp with other elements like constants, functions etc... Returns nil, if not found. *) function FindSymbol(const AName: string): TExprWord; (*Returns a word from Src string close to charIdx. The function expects one code line in Src parameter and will return the word or the variable which is close to char at charIdx. *) function ExpandCharToWord(const Src: string; charIdx: integer): string; (*Returns Tool-Tip or the Hint string to be displayed for the variable with aName. The value of the variable needs to be passed as param "a" and the name of the variable as "aName". Typically one would write: aVal := expr.VarByName[aName]; if Assigned(aVal) then //var was found begin ShowHint := True; Hint := expr.VarToolTip(aVal, aName); end ShowHint := False; The returned string will contain the name of the variable, its type and the value(s). *) function VarToolTip(const aName: string; const a: TValueRec): string; (*Performs compile of all the expressions in the list. Most of the time not needed, because functions compile automatically, if the compile was not yet performed. *) procedure Compile; (*Runs the compiled script.*) function EvaluateCompiled: TValueRec; (*Evaluates one line of compiled script. Evaluates one line of compiled script and returns the number of next line to be evaluated. If the value returned contains an index greater or equal to the line count, then the end of the script has been reached. *) function EvaluateStep(aLine: integer): integer; (*Evaluates all lines of compiled script from specified Line forward. The function returns the result of the last line. *) function EvaluateRun(aLine: integer): TValueRec; (*Specifies an expression, which must fail, underwise an exception is raised.*) procedure NegativeTest(const anExpr: string); (*Specifies a single expression, which must match ResultValue, underwise an exception is raised. Test "+" operator procedure TestAddOperator(aParser: TMtxExpression); begin aParser.Test('1+2',3); //no exception will be raised, if result is a match end; *) procedure Test(const anExpr: string; ResultValue: double; AllowNanInf: boolean = false); overload; (*Specifies a single expression, which must match ResultValue, underwise an exception is raised.*) procedure Test(const anExpr: string; ResultValue: TCplx; AllowNanInf: boolean = false); overload; procedure Test(const anExpr: string; ResultValue: boolean); overload; (*Specifies a single expression, which must match ResultValue, underwise an exception is raised.*) procedure TestVec(const anExpr: string; const ResultValue: array of double; AllowNanInf: boolean); overload; procedure TestVec(const anExpr: string; const ResultValue: array of double); overload; procedure TestVec(const anExpr: string; const ResultValue: TVec; AllowNanInf: boolean = false); overload; (*Specifies a single expression, which must match ResultValue, underwise an exception is raised.*) procedure TestMtx(const anExpr: string; const ResultValue: array of double; AllowNanInf: boolean); overload; procedure TestMtx(const anExpr: string; const ResultValue: array of double); overload; procedure TestMtx(const anExpr: string; const ResultValue: TMtx; AllowNanInf: boolean = false); overload; procedure TestMtxInt(const anExpr: string; const ResultValue: array of integer); overload; procedure TestVecInt(const anExpr: string; const ResultValue: array of integer); overload; (*Runs all registered tests and raises an exception, if one fails.*) procedure SelfTest; (*Returns the name of the result variable for expression at Index. Use this method to retreive the name of result variable of the expression stored at position Index. In case of a = b + c, the name of the result variable is "a". In case of b + c, the result variable has no name. The object stores a list of expressions and therefore requires an index to specify the name of the result of which expression is desired. *) function EvaluatedVarName(Index: integer): string; constructor Create; destructor Destroy; override; (*Clears all expressions and all defined variables. Clear everything. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example(TMtxExpression myParser) { // 1. Example myParser.DefineDouble("omega"); myParser.DefineDoubleConstant("hbar"); myParser.AddExpr("hbar*omega"); // 2. Clear everything myParser.ClearAll(); // 3. What happened ? int eCount = myParser.ExprCount() // returns 0 // Also, all defined the variable, constant varying function, operator, // etc.. lists are cleared. } } *) procedure ClearAll; (*Clears all defined variables only. Use this method if you do not want to delete parser expressions and only want to delete defined variables. *) procedure ClearVariables; (*Clears all expressions only. Use this method if you do not want to delete parser defined variables and only want to delete parser expressions. Manipulation of vars of compiled expressions can lead to memory leaks. Call ClearExpressions first, if the variables are to be kept and/or added, but the expressions will change. *) procedure ClearExpressions; (*Removes symbol from defined symbols. Defines the name of removed symbol. True, if removing symbol AName was successful. Note: Any variables, constanst, functions and operators may be undefined. This is different from the "undefine" function called from the script, which will simply undefine the type of the variable thus allowing it to have its type defined again. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example(TMtxExpression myParser) { bool success = myParser.Undefine("x"); } } *) function Undefine (const AName: string): boolean; (*Defines new variable. Defines variable name. Type of variable (double/complex/vector/matrix) must be defined before any Evaluate method will be called. If variable with name AVarName was already defined, it will be redefined and all expressions which contain the symbol AVarName will be recompiled before the next evaluation. *) function DefineVariable (const AVarName: string): TValueRec; overload; (*Defines new double variable. If variable with name AVarName already was definded, it will be redefined and all expressions which contain the symbol AVarName will be recompiled before the next evaluation. Use parser to evaluate the "Sqrt(X*X + Y*Y)" formula where x=3 and y=4. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { // 1. Define variables TDoubleValue x = MyParser.DefineDouble("x"); TDoubleValue y = MyParser.DefineDouble("y"); // 2. Set values x.DoubleValue = 3.0; y.DoubleValue = 4.0; // 3. Add formula and evaluate, MyParser.AddExpr("Sqrt(x*x+y*y)"); double res = MyParser.EvaluateDouble(); // res = 5 } } *) function DefineDouble (const AVarName: string): TDoubleValue; (*Defines new boolean variable.*) function DefineBool (const AVarName: string): TBoolValue; (*Defines new integer variable.*) function DefineInteger (const AVarName: string): TIntegerValue; (*Defines new string variable.*) function DefineString(const AVarName: string): TStringValue; (*Defines new range variable.*) function DefineRange(const AVarName: string): TRangeValue; (*Defines new variable of arbitrary type. Use this method to define Global variables, which are shared between multiple expression objects. aVar can be constructed externally and then passed to multiple TMtxExpression objects. The name of the variable can be equal or different between TMtxExpression objects, but the value will be modified concurrently and be the same in all. This value is stored in the aVar object. The type does not need to be defined upfront, but once defined an attempt for the script to change the type will be blocked. The type can be reset to undefined with a call to aVar.Undefine. *) function DefineVariable(const AVarName: string; const aVar: TValueRec): TValueRec; overload; (*Defines new complex variable. If variable with name AVarName already was definded, it will be redefined and all expressions which contain the symbol AVarName will be recompiled before the next evaluation. Use parser to evaluate the "(2*i*z)" formula where z=-2+3*i. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { // 1. Define variables TComplexValue z = MyParser.DefineComplex("z"); // 2. Set values z.ComplexValue = Math387.Cplx(-2,3); // 3. Add formula and evaluate, MyParser.AddExpr("2*i*z"); TCplx res = MyParser.EvaluateComplex(); // res = -6-4*i } } *) function DefineComplex (const AVarName: string): TComplexValue; (*Defines new vector variable. If variable with name AVarName already was definded, it is redefined and all expressions which contain the symbol AVarName will be recompiled before the next evaluation. External vector may be assigned as values holder. If external vector is not assigned, internal vector will be used. Use parser to evaluate the "-s*x" formula where x(1,-1,1) is vector and s=0.5 scalar. To evaluate vector, use automatically generated vector. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { // 1. Define variables TVectorValue = MyParser.DefineVector("x"); TDoubleValue s = MyParser.DefineDouble('s'); // 2. Set values x.Value.SetIt(false,new double[] {1,-1,1}); s.DoubleValue = 0.5; // 3. Add formula and evaluate, MyParser.AddExpr("-s*x"); Vector res = new Vector(0); res = MyParser.EvaluateVector(); // res = (-0.5,0.5, -0.5) } } *) function DefineVector (const AVarName: string; const Vec: TVec): TVectorValue; overload; (*Use internal vector.*) function DefineVector (const AVarName: string): TVectorValue; overload; (*Define new custom object variable. The function receiving this variable needs to check for correct type of object and report an error if not as expected. *) function DefineCustomValue(const AVarName: string; const obj: TObject): TCustomValue; overload; (*Define type and initialize to nil.*) function DefineCustomValue(const AVarName: string): TCustomValue; overload; function DefineIntVector (const AVarName: string; const Vec: TVecInt): TIntVectorValue; overload; (*Use internal vector.*) function DefineIntVector (const AVarName: string): TIntVectorValue; overload; function DefineBoolVector (const AVarName: string; const Vec: TVecInt): TBoolVectorValue; overload; (*Use internal vector.*) function DefineBoolVector (const AVarName: string): TBoolVectorValue; overload; (*DefineMatrix defines new matrix variable. If variable with name AVarName already was definded, it will be redefined and all expressions which contain the symbol AVarName will be recompiled before the next evaluation. External matrix may be assigned as values holder. If external matrix is not assigned, internal matrix will be used. Use parser to evaluate the "A+2*B" formula where A=(2,1; 3, 0) B=(1,0; 1,1) are 2x2 matrices. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example(TMtxExpression MyParser) { // 1. Define variables TMatrixValue A = MyParser.DefineMatrix("A"); TMatrixValue B = MyParser.DefineDouble("B"); // 2. Set values A.Value.SetIt(2,2, false,new double[] {2,1,3,0}); B.Value.SetIt(2,2, false,new double[] {1,0,1,1}); // 3. Add formula and evaluate, MyParser.AddExpr("A+2*B"); Matrix res = new Matrix(false,0,0) res = MyParser.EvaluateMatrix; // res = (4,1; 5,2) } } *) function DefineMatrix (const AVarName: string; const mtx: TMtx): TMatrixValue; overload; (*Use internal matrix.*) function DefineMatrix (const AVarName: string): TMatrixValue; overload; function DefineIntMatrix (const AVarName: string; const mtx: TMtxInt): TIntMatrixValue; overload; (*Use internal matrix.*) function DefineIntMatrix (const AVarName: string): TIntMatrixValue; overload; function DefineBoolMatrix (const AVarName: string; const mtx: TMtxInt): TBoolMatrixValue; overload; (*Use internal matrix.*) function DefineBoolMatrix (const AVarName: string): TBoolMatrixValue; overload; (*Defines new function. Defines function name. If a function with the same name was already definded, it is redefined and all expressions which contain the symbol AFuncName will be recompiled before the next evaluation. Defines number of arguments for function. Defines number of arguments, which are treated as results. NResults <= NArguments Function help text. Add factorial function to the function list. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { void _Factorial_D (TExprRec Param) { Param.Res.DefineDouble; Param.Res.DoubleValue = Fact(System.Math.Round(Param.Args[0].DoubleValue)); } void Example(TMtxExpression MyParser); { myParser.DefineFunction("fact_double", _Factorial_D, 1, "fact_double(x): factorial function"); } } } *) function DefineFunction(const AFunctName: string; AFuncAddress: TExprFunc; NArguments, NResults: Integer; const Help: string): integer; overload; function DefineFunction(const AFunctName: string; AFuncAddress: TExprFunc; NArguments: Integer; const Help: string): integer; overload; function DefineFunction(const AFunctName: string; AFuncAddress: TExprFunc; NArguments: Integer): integer; overload; function DefineFunction(const AFunctName: string; NArguments: Integer; const AFuncAddress: TExprFuncObj): integer; overload; function DefineFunction(const AFunctName: string; NArguments: Integer; const AFuncAddress: TExprFuncObj; const Help: string): integer; overload; function DefineFunction(const AFunctName: string; NArguments, NResults: Integer; const AFuncAddress: TExprFuncObj; const Help: string): integer; overload; (*Defines new varying function. *) function DefineVaryingFunction(const AFunctName: string; AFuncAddress: TExprFunc; NArguments: Integer; const Help: string): integer; overload; function DefineVaryingFunction(const AFunctName: string; AFuncAddress: TExprFunc; NArguments: Integer): integer; overload; function DefineVaryingFunction(const AFunctName: string; NArguments: Integer; const AFuncAddress: TExprFuncObj; const Help: string): integer; overload; function DefineVaryingFunction(const AFunctName: string; NArguments: Integer; const AFuncAddress: TExprFuncObj): integer; overload; (*Defines new operator. *) procedure DefineOperator(const AOperatorSign: string; AFuncAddress: TExprFunc; NArguments: Integer; Precedence: Integer; const Help: string); overload; procedure DefineOperator(const AOperatorSign: string; AFuncAddress: TExprFunc; NArguments: Integer; Precedence: Integer); overload; (*Defines new double constant. *) procedure DefineDoubleConstant (const AConstName: string; Value: double; const Help: string); overload; procedure DefineDoubleConstant (const AConstName: string; Value: double); overload; (*Defines new boolean constant.*) procedure DefineBoolConstant (const AConstName: string; Value: boolean; const Help: string); overload; procedure DefineBoolConstant (const AConstName: string; Value: boolean); overload; (*Defines new complex constant. *) procedure DefineComplexConstant (const AConstName: string; const Value: TCplx; const Help: string); overload; procedure DefineComplexConstant (const AConstName: string; const Value: TCplx); overload; (*Retrieves list of functions. *) procedure GetFuncList (const names, help: TStrings; arg_list: boolean); (*Retrieves list of operators. *) procedure GetOperList (const names, help: TStrings); (*Retrieves list of constants. *) procedure GetConstList (const names, help: TStrings); (*Retrieves list of variables. The TValueRec values, holding the type of the variable etc.. , are stored in names.Objects[i] after the function returns. *) procedure GetVarList (const names: TStrings); (*Returns variable by name or nil, if variable does not exist. Use parser to evaluate the "(2*i*z)" formula where z=-2+3*i. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { // 1. Add formula and evaluate, MyParser.AddExpr("2*i*z"); // 2. Get defined variable z = MyParser.VarByName["z"]; // 3. Specify the type z.DefineComplex(); // 4. Set values z.ComplexValue = Math387.Cplx(-2,3); // 5. Evaluate TCplx res = MyParser.EvaluateComplex(); // res = -6-4*i } } *) property VarByName: TVarByNameIndexer read fVarByNameIndexer; (*Gets/sets several expressions separated by semicolon at once. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example(TMtxExpression myParser) { myParser.Expressions = "x+y;sqrt(x);x/y"; myParsers.ExprCount(); // 3 } } *) property Expressions: string read GetExpressions write SetExpressions; (*Number of expressions. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example(TMtxExpression myParser) { myParser.Expressions = "x+y;sqrt(x);x/y"; myParsers.ExprCount(); // 3 } } *) property ExprCount: integer read GetExprCount; (*If True, all constants will be double type even if number is integer. This setting is usefull, when the parser is to be used for a calculator style application. When used for Scripting type application, it makes more sense to have this setting set to false. Default value is false. *) property ConstantsAlwaysReal: boolean read FConstantsAlwaysReal write SetConstantsAlwaysReal; (*If True, all [ ..] type of expression will be double type even, if all items are integer. Default value is true. *) property ConcatsAlwaysReal: boolean read FConcatsAlwaysReal write SetConcatsAlwaysReal default True; (*Returns expression by index. *) property Expression[Index: integer]: string read GetExpression write SetExpression; default; (*Appends new expression at the end of list. index of added expression. *) function AddExpr (const expr: string): integer; overload; (*Appends new expressions at the end of list.*) function AddExpr(const exprList: TStrings): integer; overload; (*Inserts new expression at specified index. *) procedure InsertExpr (Index: integer; const expr: string); (*Deletes expression at specified index. *) procedure DeleteExpr (Index: integer); (*Returns expression result at specified index. *) property ExprResult: TExprResultIndexer read fExprResultIndexer; (*Returns result of the latest expression from the list. *) property LastResult: TValueRec read GetLastResult; (*Sets new context (expressions and variable values).*) procedure LoadContext (const contextSrc: TExprContext); (*Retrives current context (expressions and variable values). *) procedure SaveContext (const contextDst: TExprContext); (*Evaluates all expressions from the list. result of the latest expression. *) function Evaluate: TValueRec; overload; (*Evaluates expression at the specified index. result of the expression, evaluated at specific index. If the Index parameter is specified to be -1, the method will evaluate all expressions in the list starting with the first and return the result of the last expression in the list. The function returns TValueRec. This object contains information about the type of the result and the result itself. To determine the type read the TValueRec.ValueType property. The types in the expression are resolved at compile time and may not change after the first call to the Evalute function. The result of a given expression will therefore always have the same type. This allows for omission of certain checks and further increase of code speed. Instead of calling EvaluateDouble method, it would be faster to call just: myDouble := myParser.Evaluate.DoubleValue; ,if you know that the result of the expression is a variable of type double. uses MtxParseExpr, MtxParseClass; function TMtxExpression.EvaluateDouble(Index :integer): Double; var vr :TValueRec; begin vr:= Evaluate(Index); case vr.ValueType of vtDoubleValue: begin result:= vr.DoubleValue; Exit; end; vtComplexValue: if vr.ComplexValue.Im = 0 then begin result:= vr.ComplexValue.Re; Exit; end; end; raise EMtxParseError.Create ('TMtxExpression.EvaluateDouble: double value expected'); end; *) function Evaluate(Index: integer): TValueRec; overload; (*Evaluates all expressions from the list. the result of the latest expression as double value. Use parser to evaluate the "Sqrt(X*X + Y*Y)" formula where x=3 and y=4. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { // 1. Define variables TDoubleValue x = MyParser.DefineDouble("x"); TDoubleValue y = MyParser.DefineDouble("y"); // 2. Set values x.DoubleValue = 3.0; y.DoubleValue = 4.0; // 3. Add formula and evaluate, MyParser.AddExpr("Sqrt(x*x+y*y)"); double res = MyParser.EvaluateDouble(); // res = 5 } } *) function EvaluateDouble: Double; overload; (*Evaluates expression at the specified index. the result as double value. *) function EvaluateDouble(Index: integer): Double; overload; (*Evaluates expression at the specified index. the result as a boolean value. *) function EvaluateBool(Index: integer): Boolean; overload; (*Evaluates all expressions from the list. the result of the last expression as a single boolean value.*) function EvaluateBool: boolean; overload; (*Evaluates all expressions from the list. the result of the latest expression as complex value. *) function EvaluateComplex: TCplx; overload; (*Evaluates expression at the specified index. the result as complex value. *) function EvaluateComplex(Index: integer): TCplx; overload; (*Evaluates all expressions from the list. result of the latest expression as vector value. Use parser to evaluate the "-s*x" formula where x(1,-1,1) is vector and s=0.5 scalar. To evaluate vector, use automatically generated vector. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { // 1. Define variables TVectorValue = MyParser.DefineVector("x"); TDoubleValue s = MyParser.DefineDouble('s'); // 2. Set values x.Value.SetIt(false,new double[] {1,-1,1}); s.DoubleValue = 0.5; // 3. Add formula and evaluate, MyParser.AddExpr("-s*x"); Vector res = new Vector(0); res = MyParser.EvaluateVector(); // res = (-0.5,0.5, -0.5) } } *) function EvaluateVector: TVec; overload; (*Evaluates vector expression at the specified index. result as vector value. *) function EvaluateVector(Index: integer): TVec; overload; function EvaluateVectorInt: TVecInt; overload; function EvaluateVectorInt(Index: integer): TVecInt; overload; function EvaluateMatrixInt: TMtxInt; overload; function EvaluateMatrixInt(Index: integer): TMtxInt; overload; (*Evaluates all expressions from the list. result of the latest expression as matrix value. Use parser to evaluate the "A+2*B" formula where A=(2,1; 3, 0) B=(1,0; 1,1) are 2x2 matrices. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example(TMtxExpression MyParser) { // 1. Define variables TMatrixValue A = MyParser.DefineMatrix("A"); TMatrixValue B = MyParser.DefineDouble("B"); // 2. Set values A.Value.SetIt(2,2, false,new double[] {2,1,3,0}); B.Value.SetIt(2,2, false,new double[] {1,0,1,1}); // 3. Add formula and evaluate, MyParser.AddExpr("A+2*B"); Matrix res = new Matrix(false,0,0) res = MyParser.EvaluateMatrix; // res = (4,1; 5,2) } } *) function EvaluateMatrix: TMtx; overload; (*Evalutes expression at the specified index. result as matrix value. *) function EvaluateMatrix(Index: integer): TMtx; overload; (*The preprocessor event is called after the preprocessor has already applied any substitions and patched the parsed expression. All modifications must be made to the Expr list parameter. This is the list of lexems forming the expression. For example abc(2 + 3) is formed with 'abc', '(', '2', '+', '3', ')'. The parser already assigns the type of lexeme to each entry. May that be a variable, a constant or a function. This preprocessor allows you to easily parse individual expression elements further in to form understandable to the compiler. An example of the preprocessor purpose is the ability to pass spreadsheet cells or ranges to the expression parser. This expressions could be of type: A2:B3, A3, A$2:$B3 and so on. You can replace these expression with custom function specifications like: spreadsheet('A',2,'B',3); which could be hard for the user to write. The "spradsheet" function itself however still has to be declared and implemented. *) property OnPreprocessor: TOnPreprocessor read FOnPreprocessor write SetOnPreprocessor; (*Returns the line (expression number) of the last evaluation, where a runtime error occured. The property will return -1, if evaluation completed without errors. *) property EvaluatedLine: integer read FEvaluatedLine write SetEvaluatedLine; end; (*Function evaluator. The component offers a simple interface to evaluate expressions. The expressions are assigned to the property and are compiled, prepared for execution and stored in the property. The expression parser can handle real and complex numbers, logical variables, variable assignments and more. The expression engine is fully customizable supporting user defined variables and functions. To evalute the expression(s) in the property again, set the property again or call the method. In either case the expression will not be parsed again, just evaluated once more. *) TMtxFunctionEvaluator = class(TMtxComponent) strict private fExpr: TMtxExpression; fContext: TExprContext; function GetResultAsString: string; procedure SetContext(const Value: TExprContext); public constructor Create(aOwner: TComponent); overload; override; destructor Destroy; overload; override; (*Re-evaluates expression in Context. the result of expression stored in as . The procedure loads context from property, uses internal parser to evaluate expressions (now stored in property and returns result of expression evaluation. *) function Recalculate: TValueRec; (*Returns the compiled expressions from the class.*) property Expressions: TMtxExpression read fExpr; (*Returns the result of evaluation as string.*) property ResultAsString: string read GetResultAsString; published (*Expression context. *) property Context: TExprContext read fContext write SetContext; end; function TerminatedWithSemicolon(const aStr: string): boolean; overload; var AssignOperator: string = '='; EqualOperator: string = '=='; (*TStrings and TStringList classes. Note: Code taken from CodeGear RAD. *) unit MtxStrings; interface {$I BdsppDefs.inc} uses System.IO, System.Text, Math387, System.Globalization, System.Collections, System.ComponentModel ,System.Diagnostics ,Classes ; const sdDelimiter = 1; const sdQuoteChar = 2; const sdNameValueSeparator = 4; const sdLineBreak = 8; const sdStrictDelimiter = 16; type TStringsDefined = cardinal; TStrings = class; TStringsEnumerator = class strict private FIndex: Integer; FStrings: TStrings; public constructor Create(AStrings: TStrings); function GetCurrent: string; function MoveNext: Boolean; property Current: string read GetCurrent; end; TNameItem = class strict private fOwner: TStrings; function GetItem(Index: Integer): string; public property Items[Index: Integer]: string read GetItem; default; constructor Create(aOwner: TStrings); end; TValueFromIndexItem = class strict private fOwner: TStrings; function GetItem(Index: Integer): string; procedure SetItem(Index: Integer; const Value: string); public property Items[Index: Integer]: string read GetItem write SetItem; default; constructor Create(aOwner: TStrings); end; TValueItem = class strict private fOwner: TStrings; function GetItem(const Name: string): string; procedure SetItem(const Name, Value: string); public property Items[const Name: string]: string read GetItem write SetItem; default; constructor Create(aOwner: TStrings); end; TObjectItem = class strict private fOwner: TStrings; function GetItem(Index: Integer): TObject; procedure PutItem(Index: Integer; const Value: TObject); public property Items[Index: Integer]: TObject read GetItem write PutItem; default; constructor Create(aOwner: TStrings); end; [DebuggerDisplay('{DelimitedText, nq}')] TStrings = class(TPersistent) strict private FDefined: TStringsDefined; FDelimiter: Char; FLineBreak: string; FQuoteChar: Char; FNameValueSeparator: Char; FStrictDelimiter: Boolean; FUpdateCount: Integer; FTrailingLineBreak: boolean; function GetCommaText: string; function GetDelimitedText: string; procedure SetCommaText(const Value: string); procedure SetDelimitedText(const Value: string); function GetDelimiter: Char; procedure SetDelimiter(const Value: Char); function GetLineBreak: string; procedure SetLineBreak(const Value: string); function GetQuoteChar: Char; procedure SetQuoteChar(const Value: Char); function GetNameValueSeparator: Char; procedure SetNameValueSeparator(const Value: Char); function GetStrictDelimiter: Boolean; procedure SetStrictDelimiter(const Value: Boolean); strict protected procedure SetTrailingLineBreak(const Value: boolean); procedure Error(const Msg: string; Data: Integer); overload; function ExtractName(const S: string): string; function GetString(Index: Integer): string; virtual; function GetCapacity: Integer; virtual; function GetCount: Integer; virtual; function GetTextStr: string; virtual; procedure PutString(Index: Integer; const S: string); virtual; procedure SetCapacity(NewCapacity: Integer); virtual; procedure SetTextStr(const Value: string); virtual; procedure SetUpdateState(Updating: Boolean); virtual; property UpdateCount: Integer read FUpdateCount; public Names: TNameItem; ValueFromIndex: TValueFromIndexItem; Values: TValueItem; Objects: TObjectItem; function GetName(Index: Integer): string; function GetValueFromIndex(Index: Integer): string; procedure SetValueFromIndex(Index: Integer; const Value: string); procedure SetValue(const Name, Value: string); function GetValue(const Name: string): string; function GetObject(Index: Integer): TObject; virtual; procedure PutObject(Index: Integer; AObject: TObject); virtual; function CompareStrings(const S1, S2: string): Integer; virtual; public constructor Create; virtual; destructor Destroy; override; function Add(const S: string): Integer; virtual; function AddObject(const S: string; AObject: TObject): Integer; virtual; procedure Append(const S: string); procedure AddStrings(Strings: TStrings); virtual; procedure Assign(Source: TPersistent); virtual; procedure BeginUpdate; procedure Clear; virtual; procedure Delete(Index: Integer); virtual; procedure EndUpdate; function Equals(Strings: TStrings): Boolean; procedure Exchange(Index1, Index2: Integer); virtual; function GetEnumerator: TStringsEnumerator; function IndexOf(const S: string): Integer; virtual; function IndexOfName(const Name: string): Integer; virtual; function IndexOfObject(AObject: TObject): Integer; virtual; procedure Insert(Index: Integer; const S: string); virtual; abstract; procedure InsertObject(Index: Integer; const S: string; AObject: TObject); virtual; procedure LoadFromFile(const FileName: string); overload; virtual; procedure LoadFromFile(const FileName: string; Encoding: System.Text.Encoding); overload; virtual; procedure LoadFromStream(Stream: Stream); overload; virtual; procedure LoadFromStream(Stream: Stream; Encoding: System.Text.Encoding); overload; virtual; procedure Move(CurIndex, NewIndex: Integer); virtual; procedure SaveToFile(const FileName: string); overload; virtual; procedure SaveToFile(const FileName: string; Encoding: System.Text.Encoding); overload; virtual; procedure SaveToStream(Stream: Stream); overload; virtual; procedure SaveToStream(Stream: Stream; Encoding: System.Text.Encoding); overload; virtual; property Capacity: Integer read GetCapacity write SetCapacity; property CommaText: string read GetCommaText write SetCommaText; property Count: Integer read GetCount; property Delimiter: Char read GetDelimiter write SetDelimiter; property DelimitedText: string read GetDelimitedText write SetDelimitedText; property LineBreak: string read GetLineBreak write SetLineBreak; property TrailingLineBreak: boolean read FTrailingLineBreak write SetTrailingLineBreak; property QuoteChar: Char read GetQuoteChar write SetQuoteChar; property NameValueSeparator: Char read GetNameValueSeparator write SetNameValueSeparator; property StrictDelimiter: Boolean read GetStrictDelimiter write SetStrictDelimiter; property Strings[Index: Integer]: string read GetString write PutString; default; property Text: string read GetTextStr write SetTextStr; end; TStringList = class; TStringItem = record FString: string; FObject: TObject; end; TStringItemArray = array of TStringItem; TStringListSortCompare = function(List: TStringList; Index1, Index2: Integer): Integer; TDuplicates = (dupIgnore, dupAccept, dupError); TStringList = class(TStrings) strict private FList: TStringItemArray; FCount: Integer; FSorted: Boolean; FDuplicates: TDuplicates; FCaseSensitive: Boolean; FOnChange: TMtxNotifyEvent; FOnChanging: TMtxNotifyEvent; procedure ExchangeItems(Index1, Index2: Integer); procedure Grow; procedure QuickSort(L, R: Integer; SCompare: TStringListSortCompare); procedure SetSorted(Value: Boolean); procedure SetCaseSensitive(const Value: Boolean); strict protected procedure Changed; virtual; procedure Changing; virtual; function GetString(Index: Integer): string; override; function GetCapacity: Integer; override; function GetCount: Integer; override; procedure PutString(Index: Integer; const S: string); override; procedure SetCapacity(NewCapacity: Integer); override; procedure SetUpdateState(Updating: Boolean); override; procedure InsertItem(Index: Integer; const S: string; AObject: TObject); virtual; procedure SetOnChange(const aValue: TMtxNotifyEvent); procedure SetOnChanging(const aValue: TMtxNotifyEvent); public procedure PutObject(Index: Integer; AObject: TObject); override; function GetObject(Index: Integer): TObject; override; public function CompareStrings(const S1, S2: string): Integer; override; function Add(const S: string): Integer; overload; override; function Add(const C: char): Integer; reintroduce; overload; function AddObject(const S: string; AObject: TObject): Integer; override; constructor Create; override; procedure Clear; override; procedure Delete(Index: Integer); override; procedure Exchange(Index1, Index2: Integer); override; function Find(const S: string; var Index: Integer): Boolean; virtual; function IndexOf(const S: string): Integer; override; procedure Insert(Index: Integer; const S: string); override; procedure InsertObject(Index: Integer; const S: string; AObject: TObject); override; procedure Sort; virtual; procedure CustomSort(Compare: TStringListSortCompare); virtual; property Duplicates: TDuplicates read FDuplicates write FDuplicates; property Sorted: Boolean read FSorted write SetSorted; property CaseSensitive: Boolean read FCaseSensitive write SetCaseSensitive; property OnChange: TMtxNotifyEvent read FOnChange write SetOnChange; property OnChanging: TMtxNotifyEvent read FOnChanging write SetOnChanging; end; TListSortCompare = function (Item1, Item2: System.Object): Integer; TListNotification = (lnAdded, lnExtracted, lnDeleted); TListAssignOp = (laCopy, laAnd, laOr, laXor, laSrcUnique, laDestUnique); TList = class; TListEnumerator = class strict private FIndex: Integer; FList: TList; public constructor Create(aList: TList); function GetCurrent: System.Object; function MoveNext: Boolean; property Current: System.Object read GetCurrent; end; TList = class(TObject) strict private FList: ArrayList; strict protected function GetItem(Index: Integer): System.Object; function GetCount: Integer; function GetCapacity: Integer; procedure Grow; virtual; procedure SetItem(Index: Integer; Item: System.Object); procedure Notify(Instance: System.Object; Action: TListNotification); virtual; procedure SetCapacity(NewCapacity: Integer); procedure SetCount(NewCount: Integer); function getFirst: System.Object; function getLast: System.Object; public constructor Create; destructor Destroy; override; function Add(Item: System.Object): Integer; procedure Clear; virtual; procedure Delete(Index: Integer); class procedure Error(const Msg: string; Data: Integer); overload; procedure Exchange(Index1, Index2: Integer); function Expand: TList; function Extract(Item: System.Object): System.Object; function GetEnumerator: TListEnumerator; function IndexOf(Item: System.Object): Integer; procedure Insert(Index: Integer; Item: System.Object); procedure Move(CurIndex, NewIndex: Integer); function Remove(Item: System.Object): Integer; procedure Pack; procedure Sort(Compare: TListSortCompare); procedure Assign(ListA: TList; AOperator: TListAssignOp = laCopy; ListB: TList = nil); property First: System.Object read getFirst; property Last: System.Object read getLast; property Capacity: Integer read GetCapacity write SetCapacity; property Count: Integer read GetCount write SetCount; property Items[Index: Integer]: System.Object read GetItem write SetItem; default; property List: ArrayList read FList; end; TObjectList = class(TList) strict private FOwnsObjects: Boolean; strict protected procedure Notify(Instance: System.Object; Action: TListNotification); override; public constructor Create; overload; constructor Create(AOwnsObjects: Boolean); overload; property OwnsObjects: Boolean read FOwnsObjects write FOwnsObjects; end; procedure aSetLength(var a: TStringItemArray; Len: integer); overload; function aGetLength(const a: TStringItemArray): integer; overload; (*Implements TVec and TMtx objects. This unit implements two key objects in linear algebra, namely the vector and matrix . *) unit MtxVec; interface {$I BdsppDefs.inc} {$WARN SYMBOL_DEPRECATED OFF} uses Math387, AbstractMtxVec, MtxVecBase, MtxVecInt, AbstractMtxVecInt, MtxForLoop ,Nmkl ,NmklSingle ,IppsplTypes ,Dialogs ,Forms ,Windows ,Types ,Classes, SysUtils, SyncObjs ; {$Z4} {$HPPEMIT END '#include "MtxVec.h"'} type TVec = class; TMtx = class; TSmallMatrixMultiply = class; (*Defines real scalar function of several variables. Function variables. Array of additional constants which can be used in math formula. Array of additional constants (pointers) which can be used in math formula. Defines real scalar function of several variables. What's the PConsts parameter for? Constants can also be stored in a vector (or even matrix). In this case you could use the following code: function YMul(const Pars: TVec; const Consts: TVec; const OConsts: Array of TObject): double; begin YMul := Consts[0]*Sin(Consts[1] + 2.0*Pars[0]) + Sqr(Pars[1]); end; ... var constVec, parsVec: Vector; begin constVec := [2,3]; parsVec := [1,1]; ... // calculate YMul=YMul(1,1) and set a,b constants to 2 and 3 respectively. result := yMul(parsVec, constVec, []); or even: function YMul(const Pars: TVec; const Consts: TVec; const ObjConsts: Array of TObject): double; var CVec0 : TVec; begin CVec0 := ObjConsts[0] as TVec; YMul := CVec0.Values[0]*Sin(CVec0.Values[1]+2.0*Pars[0])+ Sqr(Pars[1]); end; var constVec, parsVec: Vector; begin ... constVec := [2,3]; parsVec := [1,1]; // calculate YMul=YMul(1,1) and set a,b constants to 2 and 3 respectively. yMul(parsVec,nil,[ConstVec]); Function of one variable.Suppose we have a function of one variable: y = a*Sin(b+2*x), where x is a variable and a,b are two additional constants. Here is how we would define function y: TRealFunction: function y(const Pars: TVec; const Consts: TVec; Const Objects: Array of TObject): double; begin y := Consts[0]*Sin(Consts[1]+2.0*Pars[0]); end; ... // calculate y=y(2.5) and set a,b, constants to 3 and 2 respectively var constVec, parsVec: Vector; constVec := [3,2]; parsVec := [2.5]; y(parsVec,constsVec,[]); double __fastcall y(const TVec * Parameters, const TVec * Constants, System::TObject* const * ObjConst, const int ObjConst_Size) { return Consts[0]*Sin(Consts[1]+2.0*Parameters[0]); } ... // calculate y=y(2.5) and set a,b, constants to 3 and 2 respectively sVector parsVec, constVec; parsVec.SetIt(1, false, OPENARRAY(double,(2.5))); constVec.SetIt(2, false, OPENARRAY(double,(3,2))); y(parsVec, constVec, NULL,-1); Function of several variablesSuppose we have a function of several variables: YMul = a*Sin(b+2*x1)+Sqr(x2), where x1,x2 are two variables and a,b are two additional constants. Here is how we would define function yMul: TRealFunction; function y(const Pars: TVec; const Consts: TVec; const OConsts: Array of TObject): double; begin y := Consts[0]*Sin(Consts[1]+2.0*Pars[0])+ Sqr(Pars[1]); end; ... // calculate YMul=YMul(1,1) and set a,b constants to 2 and 3 respectively. var constVec, parsVec: Vector; begin constVec := [3,2]; parsVec := [1,1]; result := yMul(parsVec,constVec,[]); *) TRealFunction = function(const Parameters: TVec; const Constants: TVec; Const ObjConst: Array of TObject): double; (*Defines type of correlation norm used for Cross-Correlation and Auto-Correlation. *) TCorrNorm = ( (*Without normalization.*) cnDefault, (*Biased normalized will be applied.*) cnBiased, (*Unbiased normalized will be applied.*) cnUnbiased); (*Defines type of size reduction used in PixelDownSample method.*) TPixelDownSample = ( (*Use 1 for all areas with at least one nonzero value regardless of its amplitude.*) pdsPattern, (*Samples are averaged together.*) pdsAverage, (*Use average of all absolute values within an area (pixel).*) pdsAverageMagnitude, (*Use only the maximum absolute value within an area (region will become one pixel).*) pdsPeak, (*First magnitude is computed and maximum value is searched for.*) pdsPeakMagnitude ); (*Defines type of matrix. *) TMtxType = ( (*symmetric positive definite matrix*) mtSymmPosDef, (*symmetric matrix*) mtSymmetric, (*Hermitian positive definite matrix*) mtHermPosDef, (*Hermitian matrix*) mtHermitian, (*triangular matrix, with unit or non unit main diagonal*) mtTriangle, (*general matrix (none of the above)*) mtGeneral, (*symmetric positive definite matrix in banded storage forma*) mtBandSymmPosDef, (*Hermitian positive definite matrix in banded storage format*) mtBandHermPosDef, (*general matrix in banded storage format*) mtBandGeneral ); (*Defines the type of operation on matrix.*) TMtxOperation = ( (*no operation*)opNone, (*transpose operation*)opTran, (*transpose and conjugate*)opHerm ); (*Defines the type of operation on matrix.*) TJITedMul = ( (*JIT-ed matrix multiply is disabled*) jtmDisabled, (*JIT-ed matrix multiply is enabled*) jtmEnabled ); (*Defines the type of pixel downsampling. If the X axis is equidistantly sampled, the pixel downsample routine can be much faster. To downsample an already downsampled data specify eqsXDownsampled. *) TEquidistantSample = ( (*Data is not sampled equidistantly on X axis.*)eqsXNotEquidistant, (*Data is sampled equidistantly on X axis.*)eqsXEquidistant, (*Data is already downsampled.*)eqsXDownsampled ); (*Specifies if and which condition numbers for eigenvalues are to be computed.*) TEigCondition = ( (*Do not compute condition numbers.*) eicNone, (*Computed for average of selected eigenvalues only.*) eicSelectedEigs, (*Computed for selected right invariant subspace only.*) eicSelectedRight, (*Computed for both.*) eicBoth); (*Fast Hilbert Transform computation method.*) THilbertMethod = ( (*Compute forward real to complex FFT, FlipConj, sets DC to zero and Inverse complex to complex.*) hmMethod1, (*Compute forward real to complex FFT with symmetric conjugate part, set second half to zero, first half scaled by 2 and Inverse complex to complex. Refeference: S. Lawrence Marple, Jr., Computing the discrete-time "analytic" signal via FFT, IEEE Transactions on Signal Processing ( Volume: 47 , Issue: 9 , Sep 1999 ), pp.2600-2603*) hmMethod2 ); (*Class used to store matrix balancing information and results returned by TMtx.Eig.. functions.*) TEigBalancing = class public ilo: integer; ihi: Integer; (*Details of the permutations and scaling factors applied when balancing the matrix. If P(j) is the index of the row and column interchanged with row and column j, and D(j) is the scaling factor applied to row and column j, then SCALE(J) = P(J), for J = 1,...,ILO-1 = D(J), for J = ILO,...,IHI = P(J) for J = IHI+1,...,N. The order in which the interchanges are made is N to IHI+1, then 1 to ILO-1. In case of generalized Eigenvalue calcuation this is the scaling from left. *) lscale: TVec; (*Details of the permutations and scaling factors applied when balancing the matrix. If P(j) is the index of the row and column interchanged with row and column j, and D(j) is the scaling factor applied to row and column j, then SCALE(J) = P(J), for J = 1,...,ILO-1 = D(J), for J = ILO,...,IHI = P(J) for J = IHI+1,...,N. The order in which the interchanges are made is N to IHI+1, then 1 to ILO-1. In case of generalized Eigenvalue calcuation this is the scaling from right. *) rscale: TVec; (* The one-norm of the balanced matrix The maximum of the sum of absolute values of elements of any column of the balanced matrix. In case of generalized Eigenvalue calculation, this is the norm of A. *) abnrm: double; (* The one-norm of the balanced matrix The maximum of the sum of absolute values of elements of any column of the balanced matrix. In case of generalized Eigenvalue calculation, this is the norm of B. *) bbnrm: double; constructor Create; destructor Destroy; override; end; (* Injects additional methods in to TMtxVecInt. The helper class is declared for the abstract class of TMtxVecInt to allow additional helper classes to be defined by the user for TVecInt and TMtxInt. *) TMtxVecIntHelper = class helper for TMtxVecInt public (*Finds the masks for a vector and splits it. The method splits the a vector in two vectors. The MaskVec will hold the those elements where the Op comparison between a and b is True. Op string parameter can be < , > , >= , <= , = or <> . NotMaksVec will hold all those elements where the Op comparison between a and b is false. The calling vector will store the mask, 1 at those index locations where the Op comparison was True and 0 at those index locations where the Op comparison was false. *) function FindAndSplit(const a: TMtxVec; const op: string; const b: TMtxVec; const MaskVec, NotMaskVec: TVec): TMtxVecInt; overload; (*The b parameter is of type.*) function FindAndSplit(const a: TMtxVec; const op: string; const b: TCplx; const MaskVec, NotMaskVec: TVec): TMtxVecInt; overload; (*The b parameter is of double type.*) function FindAndSplit(const a: TMtxVec; const op: string; const b: double; const MaskVec, NotMaskVec: TVec): TMtxVecInt; overload; (*Fills the calling vector with indexes, where the logical expression is true. Fills the calling vector with indexes, where the Op comparison between a and b is True. Op string parameter can be '<', '>', '>=','<=','=' or '<>'. The calling vector will be sized to match a.Length. On return it will be subranged to reflect actual number of matching elements. The method will not raise an exception, if the calling vector (Self) is already subranged. Check the TVec.SetSubRange routine to learn more about subranges. Ensure that the power function will return 0, if the exponent is 0. CreateIt(a,b); With TVec(Self) do try Ln(Base); //First do it the normal way then fix the anomalies Mul(Exponent); Exp; a.FindIndexes(Exponent,'=',0); b.Size(a.Length,Complex); b.Setval(1); Scatter(b,a); finally FreeIt(a,b); end; *) function FindIndexes(const a: TMtxVec; const op: string; const b: TCplx): TMtxVecInt; overload; (*The b parameter is of double type.*) function FindIndexes(const a: TMtxVec; const op: string; const b: double): TMtxVecInt; overload; (*The b parameter is of type.*) function FindIndexes(const a: TMtxVec; const op: string; const b: TMtxVec): TMtxVecInt; overload; function FindIndexesAndLength(const a: TMtxVec; const op: string; const b: TCplx): integer; overload; (*The b parameter is of double type.*) function FindIndexesAndLength(const a: TMtxVec; const op: string; const b: double): integer; overload; (*The b parameter is of type.*) function FindIndexesAndLength(const a: TMtxVec; const op: string; const b: TMtxVec): integer; overload; (*Finds a vector mask. The calling vector will hold the those elements where the Op comparison between a and b is True. Op string parameter can be < , > , >= , <= , = or <> The calling vector will store the mask, 1 at those index locations where the Op comparison was True and 0 at those index locations where the Op comparison was false. *) function FindMask(const a: TMtxVec; const op: string; const b: TCplx): TMtxVecInt; overload; function FindMask(const a: TMtxVec; const op: char; const b: TCplx): TMtxVecInt; overload; (*The b parameter is of double type.*) function FindMask(const a: TMtxVec; const op: string; const b: double): TMtxVecInt; overload; function FindMask(const a: TMtxVec; const op: char; const b: double): TMtxVecInt; overload; (*The b parameter is of type.*) function FindMask(const a: TMtxVec; const op: string; const b: TMtxVec): TMtxVecInt; overload; function FindMask(const a: TMtxVec; const op: char; const b: TMtxVec): TMtxVecInt; overload; end; (*One dimensional array - vector. Encapsulates routines for vector specific operations. This include 1D FFt's, autocorrelation, cross-correlation, convolution, sorting, discrete cosine and Hilbert transform's and many other utility funcitons. *) TVec = class(TDenseMtxVec ) strict private procedure TensorProdInt(const Vec: TVec; const Mtx: TMtx; MtxType: TMtxType = mtGeneral; Operation: TMtxOperation = opNone); procedure PixelDownSample1(Width: integer; const Y: TVec; Index,Len: integer; const X,NX: TVec); procedure PixelDownSampleInternal(Width: integer; const Y: TVec; Index, Len: integer; const X: TVec = nil; const NX: TVec = nil; Equidistant: TEquidistantSample = eqsXEquidistant); procedure PixelDownSampleHighInternal(Width: integer; const Y: TVec; Index, Len: integer; const X: TVec = nil; const NX: TVec = nil); procedure PixelDownSampleLowInternal(Width: integer; const Y: TVec; Index, Len: integer; const X: TVec = nil; const NX: TVec = nil); strict protected function GetRealValues: string; override; function GetComplexValues: string; override; function DoubleCachePointer: TDoubleArray; override; function DoubleCacheOffset: integer; override; function CplxDoubleCachePointer: TCplxDoubleArray; override; function CplxDoubleCacheOffset: integer; override; function SingleCachePointer: TSingleArray; override; function SingleCacheOffset: integer; override; function CplxSingleCachePointer: TCplxSingleArray; override; function CplxSingleCacheOffset: integer; override; procedure SubRangeSaveState; override; procedure SetSubRangeDirect(Index, Len: integer); override; procedure SetSubRangeDirect(const Src: TMtxVecBase; Index, Len: integer); override; function HilbertInternal1(const Vec: TVec): TVec; overload; function HilbertInternal2(const Vec: TVec): TVec; overload; procedure setActualSize(const byteCount: Int64); override; procedure DoSetComplex; override; function CacheLength: integer; override; function CacheLengthInBytes: Int64; override; function StringsToValuesInternal(const srcList: TStrings; const aDelimiter: string): TMtxVecBase; overload; override; function ValuesToStringsInternal(const dstList: TStrings; const aDelimiter: string; const Align: TFixedTextAlign; const Headers: boolean; const ColumnWidth: integer): integer; overload; override; strict protected procedure SetLength(const Value: integer); override; public function ToolTip: string; constructor Create; overload; override; destructor Destroy; override; (*Obtains a pointer to a precreated object from cache. This class method does the same as the CreateIt function. *) class function CreateFromCache: TVec; (*Releases this object back to cache. This method does the same as the FreeIt function. *) procedure FreeToCache; override; (*Adopts a pointer to one dimensional array. Adopts a pointer to AArray array. The method sets the calling vector property to aFloatPrecision, and Values1D and CValues1D to Pointer(AArray). Notes: * Required to call the method, before freeing the object * do not resize the vector * do not call any routines relying on Lapack when "Core edition" is used (not linking dlls), because Lapack will assume that adopted memory is a dynamic array and will modify array index -2. *) procedure Adopt(AArray: PAPointer; ALength: integer; aFloatPrecision: TMtxFloatPrecision); overload; procedure Adopt(AArray: PAPointer; ALength: integer; aIsComplex, aIsDouble: boolean); overload; procedure Assign(Src: TPersistent); override; (*Biased auto-correlation. Calculates the biased auto-correlation of the vector Vec. The result of Length = Lags is stored in the calling vector (V). The Lags parameter must be equal or smaller than the calling vector length. The biased auto-correlation is defined by the following equation: The Buffer parameter allows the same work memory to be used between consecutive calls to this and other functions. The Buffer object will not be resized, if sufficient memory is present. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples { void Example() { TVec a,b; MtxVec.CreateIt(out a, aut b); try { a.SetIt(false, new double[] {1,2,3,4}); b.AutoCorrBiased(a,2); } finally { MtxVec.FreeIt(ref a, ref b); } } } *) function AutoCorrBiased(const Vec: TVec; Lags: integer; const Buffer: TVecInt = nil): TVec; (*Normal auto-corellation. Calculates the normal auto-correlation of the vector Vec. The result of Length = Lags is stored in the calling vector (V). The Lags parameter must be equal or smaller than the calling vector (V) length. The normal auto-correlation is defined by the following equation: The Buffer parameter allows the same work memory to be used between consecutive calls to this and other functions. The Buffer object will not be resized, if sufficient memory is present. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples { void Example() { TVec a,b; MtxVec.CreateIt(out a, aut b); try { a.SetIt(false, new double[] {1,2,3,4}); b.AutoCorrNormal(a,2); } finally { MtxVec.FreeIt(ref a, ref b); } } } *) function AutoCorrNormal(const Vec: TVec; Lags: integer; const Buffer: TVecInt = nil): TVec; (*Unbiased auto-correlation. Calculate the unbiased auto-correlation of the vector Vec. The result of Length = Lags is stored in the calling vector (V). The Lags parameter must be equal or smaller than the calling vector (V) length. The unbiased auto-correlation is defined by the following equation: The Buffer parameter allows the same work memory to be used between consecutive calls to this and other functions. The Buffer object will not be resized, if sufficient memory is present. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples { void Example() { TVec a,b; MtxVec.CreateIt(out a, aut b); try { a.SetIt(false, new double[] {1,2,3,4}); b.AutoCorrUnBiased(a,2); } finally { MtxVec.FreeIt(ref a, ref b); } } } *) function AutoCorrUnBiased(const Vec: TVec; Lags: integer; const Buffer: TVecInt = nil): TVec; procedure Clear; override; (*Concatenates an array of TVec objects. Concatenates an array of TVec objects. The method copies the contents of all TVec objects from the Src array to the calling object. The and Complex properties of the calling vector are set implicitly. An exception is raised, if Complex properties of TVec objects do not match. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples { void Example() { TVec a,b,c,d; MtxVec.CreateIt(out a, out b, out c, out d); try { a.SetIt(false, new double[] {1,2,3}); b.Copy(a); c.Concat([a,b]); // c = [1,2,3,1,2,3] d.Size(10,true); d.SetZero(0,4); d.Concat(4,[c]); // d = [0,0,0,0,1,2,3,1,2,3] } finally { MtxVec.FreeIt(ref a, ref b, ref c, ref d); } } } *) function Concat(const Src: array of TVec): TVec; overload; (*Copies the contents of all TVec objects from the Src array to the calling vector elements, starting with at Index. The and properties of the calling vector must be set explicitly. An exception is raised, if Complex properties of TVec objects do not match or if the sum of Length's exceeds the Length property of the calling object. *) function Concat(Index: integer; const Src: array of TVec): TVec; overload; (*Single-rate finite, linear convolution of two sequences. Calculate the single-rate finite, linear convolution of two sequences. The results are stored in the calling vector. The argument names X and H ar chosen to suggest FIR filtering. The result of the convolution is defined as follows: This finite-length convolution is related to infinite-length by: In the above equations, x'[n] and h'[n] are the zero-padded (infinite-length) versions of x[n] and h[n]; y'[n] is the infinite-length output version of y[n]. Then y'[n] is zero everywhere except over: The optional Buffer parameter can be specified to prevent repeated allocation and freeing of memory by the function when both X and H are not complex. If the Buffer parameter is left to be nil, the function will allocate and free required memory internally. If the parameter is not null, the object will be sized and can be reused on consecutive calls without triggering memory reallocation. Avoding memory reallocations is crucial for multithreaded algorithms. *) function Convolve(const X,H: TVec; const Buffer: TVecInt = nil): TVec; (*Copies values from Vec1 and Vec2 (concatenate). Copy each of Vec1 and Vec2 elements to the calling vector (concatenate). The and Complex properties of the calling vector are set implicitly to match Vec1 and Vec2 vector. var a,b,c: TVec; begin CreateIt(a,b,c); try a.SetIt(True,[1,2,3,4]); b.Copy(a); c.Copy(a,b); //concatenate a and b and store in c // c = [1,2,3,4,1,2,3,4] finally FreeIt(a,b,c); end; end; *) function Copy(const Vec1,Vec2: TMtxVec): TVec; overload; function Copy(const Src: TMtxVecInt; const dstFloatPrecision: TMtxFloatPrecision):TMtxVec; override; (*Copy values from matrix. Copy each of Mtx elements to the calling vector. The and Complex properties of the calling vector are set implicitly to match Mtx matrix. The same can be achieved by calling the method. var b,c: TVec; A: TMtx; begin CreateIt(b,c); CreateIt(A); try a.SetIt(2,2,False,[1,2,3,4]); b.CopyMtx(a); // b = [1,2,3,4] finally FreeIt(A); FreeIt(b,c); end; end; *) procedure CopyMtx(const Mtx: TMtx); overload; deprecated; (*Desc Copy Mtx elements Values1D[Row*fCols+Col]..Values1D[Row*fCols+Col+Len] in the calling vector elements [Index]..[Index+Len-1]. The and Complex properties must be set explicitly. An exception is raised if is True and array borders are overrun or underrun. The same can be achieved by calling the Copy method. *) function CopyMtx(const Mtx: TMtx; Index, Row, Col, Len: Integer): TVec; overload; deprecated; (*The cross-correlation of two vectors. Calculate the cross-correlation of two vectors Vec1 and Vec2. The parameter HiLag indicates the top of the range of lags at which the correlation estimates should be computed. The parameter LoLag indicates the bottom of the range of lags at which the correlation estimates should be computed. The results are stored in calling vector. The resulting elements are defined by the equation: The Buffer parameter allows the same work memory to be used between consecutive calls to this and other functions. The Buffer object will not be resized, if sufficient memory is present. var a,b,c: TVec; begin CreateIt(a,b,c); a.SetIt(False,[1,-2,3,4]); b.SetIt(False,[2,-2,3,4]); c.CrossCorr(a,b,2,2); FreeIt(a,b,c); end; *) function CrossCorr(const Vec1, Vec2: TVec; HiLag, LoLag: integer; CorrelationNorm: TCorrNorm = cnDefault; const Buffer: TVecInt = nil): TVec; (*Cumulative sum. Calculate the cumulative sum for all calling object elements in-place. var a: TVec; begin CreateIt(a); try a.SetIt(false,[1,2,3,4]; a.CumSum; // a = [1,3,6,10] finally FreeIt(a); end; end; *) function CumSum: TVec; overload; (*Calculate the cumulative sum for all Vec elements. Store the results in calling object. Size and Complex properties of the calling object are set implicitly. *) function CumSum(const Vec: TVec): TVec; overload; (*Calculate the cumulative product for all Vec elements. The size must be set by the user. The function will store all powers of Value in Values[i] := IntPower(Value, i) at corresponding array index. *) function CumProduct(Value: Double): TMtxVec; overload; (*Calculate the cumulative product for all Vec elements. The size must be set by the user. The function will store all powers of Value in CValues[i] := IntPower(Value, i) at corresponding array index. *) function CumProduct(const Value: TCplx): TMtxVec; overload; (*The forward discrete cosine transform (DCT). Calculates the forward discrete cosine transform (DCT) of all calling vector elements in-place. If vector is a power of 2, the function uses an efficient algorithm that is significantly faster than the direct computation of DCT. For different lengths this function uses the direct formulas given below; however, the symmetry of cosine function is taken into account, which allows to perform about half of the multiplication operations in the formulas. In the following definition of DCT, N=Vec.Length and V is the calling vector: var a,b: TVec; begin CreateIt(a,b); a.SetIt(False,[1,-2,3,4]); b.DCT(a); FreeIt(a,b); end; *) function DCT: TVec; overload; (*Calculates the forward discrete cosine transform (DCT) of the Vec. Writes the result in the calling vector. If Vec.Length is a power of 2, the function uses an efficient algorithm that is significantly faster than the direct computation of DCT. For other values of Vec Length, this function uses the direct formulas. *) function DCT(const Vec: TVec): TVec; overload; (*Copies the k-th diagonal from the TMtx object. Copies the k-th diagonal from the TMtx object. If k = 0 then the main diagonal is copied, if k < 0 then the subdiagonal is copied and if k > 0 then the k-th super diagonal is copied to the calling vector. In the following example we setup a matrix, populate it with values and then extract it's main diagonal to a vector. var a: TVec; d: TMtx; begin CreateIt(a); CreateIt(d); try // setup matrix d.SetIt(2,2,False,[1,-2, 3, 4]); // get main diagonal from matrix a.Diag(d,0); // a now containes [1,4]; finally FreeIt(a); FreeIt(d); end; end; *) function Diag(const Mtx: TMtx; k: integer): TVec; (*The difference between two succesive vector elements. Calculate the difference for all calling vector elements. The following formula is used to calculate the difference: The Length of calling vector is automatically decremented by one. *) function Difference(Lag: Integer = 1): TVec; overload; (*Calculate the difference for all Vec elements. Store the results in the calling vector. The of the calling vector is set to one less the length of Vec and property is set to Vec.Complex. *) function Difference(const Vec: TMtxVec; Lag: Integer = 1): TVec; overload; (*Disowns a values pointer. Disowns a values pointer. The Disown method is the opposite of the method. It will set the AArrays to Pointer(Values), ALength to vector's and IsComplex to Complex property. Use the Disown method to "disconnect" AArray from the TVec.Values. Disown sets Values and CValues array pointers to nil and Length property to zero, but without freeing the allocated memory. The allocated memory can be disowned only, if it was adopted with a call to the method. *) procedure Disown(out AArray: PAPointer; out ALength: integer; out aFloatPrecision: TMtxFloatPrecision); overload; procedure Disown(out AArray: PAPointer; out ALength: integer; out aIsComplex, aIsDouble: boolean); overload; (*Disowns a calling vector values pointer by setting Values, CValues to nil and to 0.*) procedure Disown; overload; (*Downsamples vector values. The methods copies only every Factor sample from the Src vector to the calling vector. The and Complex properties of the calling vector are set implicitly. The phase parameter determines the initial sample offset. Phase must be less than Factor. var a,b: TVec; begin CreateIt(a,b); try b.SetIt(False,[0,0,0,0,1,2,3,4,5,6]); a.DownSample(b,2); // a = [0,0,1,3,5] finally FreeIt(a,b); end; end; *) function DownSample(const Src: TMtxVec; Factor: integer; Phase: integer = 0): TVec; overload; (*Compares vector elements and returns true if vectors are equal. Compares vector elements and returns true if vectors are equal, that is if all elements match in position and value. The Tolerance parameter defines the comparison tolerance. The maximum difference between elements may not exceed: +/-Tolerance. var A,B: TMtx; c: boolean; begin CreateIt(A,B); A.SetIt(2,2,false,[1,2, 2,4]); // 2x2 real matrix B.SetIt(2,2,false,[1,2, 2,4]); // 2x2 real matrix c := A.Equal(B,1e-8); // Check for differences bigger than 0.00000001 c := A.Equal(B); // Check for exact match FreeIt(A,B); end; *) function Equal(const Vec: TMtxVec; Tolerance: double = 0): boolean; overload; (*Optionally it is also possible to specify the Compare method.*) function Equal(const Vec: TMtxVec; Tolerance: double; Compare: TCompare): boolean; overload; (*Fast Furier Transformation (FFT) from complex to complex or from real to complex. Fast Furier Transformation (FFT) from complex to complex or from real to complex. Calculate the FFT from all calling vector elements in-place. If the calling vector is complex then complex to complex forward FFT is performed. If the calling vector is real then real to complex FFT is performed. The of the transforming vector can be any number but highest performance will be achieved if it is a power of two. Note When performing FFT from real to complex the conjugated symmetric part is also generated by conjugating and mirroring the first half of the spectrum. If Complex is false, the operation will not be performed in-place, if the Length of the destination will allocate more than amount of the memory preallocated for the TVec object. Instead, the data will be copied first to allocate enough space to store the result. There are two important parameters to consider that affect how will the FFT be computed: and . The default storage format is fsfCCS. var a,b: TVec; begin CreateIt(a,b); try a.SetIt(False,[1,2,3,4]); b.FFT(a); a.FFT; // a = [(10, 0),( -2,2), (-2, 0), (-2,-2)] if not a.Equal(b) then ERaise('Not equal'); finally FreeIt(a,b); end; end; *) function FFT(ConjugateExtend: boolean = false): TVec; overload; function CopyToComplex(const Src: TVec): TVec; overload; function CopyToComplex(const Src: TVec; SrcIndex, Index, Len: integer): TVec; overload; (*Calculate the FFT from all Vec elements. Store the results in the calling vector. Vec must not be a power of two, but highest performance will be achieved if it is a power of two. Length and Complex properties of the calling vector are set implicitly to match Vec vector. If Vec is complex then complex to complex forward FFT is performed. If Vec is real then real to complex FFT is performed and the conjugate symmetric part is appended. *) function FFT(const Vec: TVec; ConjugateExtend: boolean = false): TVec; overload; (*The forward Fast Fourier Transformation (FFT) from real to complex. Calculates the forward Fast Fourier Transformation (FFT) from real to complex for the calling vector in-place. The transform should be used, when the conjugate symmetric part of the frequency spectrum is not desired. If the calling vector is complex an exception will be raised. The operation implicitly sets the calling vector Complex property to True. The highest performance will be achieved if the transform length will be a power of two. The transform length is equal to , when the is fsfPack or fsfPerm. The default storage format is fsfCCS. In-place fsfCCS complication The transform length in case of fsfCCS will be equal to Length-2, because the result is bigger than the source data by 2 real samples, if the source data is even. If the source data length is odd, then must be set to True and only Length-1 samples will be used, but Length must of course in that case be even, or Length-1 will not be odd. The last two (one) samples in the vector will be ignored and will be overwritten with the result. var a,b: TVec; begin CreateIt(a,b); try //Even a.SetIt(false,[1,2,3,4]); b.FFTFromReal(a); // b = [(10, 0),( -2,2), (-2, 0)] a.SetIt(false,[1,2,3,4, 0, 0]); //result requires 3 complex (or 6 real values) a.FFTFromReal; // b = [(10, 0),( -2,2), (-2, 0)] //Odd length a.SetIt(false,[1,2,3]); b.FFTOddLength := True; //use only Length-1 samples b.FFTFromReal(a); // b = [(6,0),( -1.5,0.8660)] //result requires 2 complex (= 4 real numbers) a.SetIt(false,[1,2,3,0]); a.FFTOddLength := True; //use only Length-1 samples a.FFTFromReal; // b = [(6,0),( -1.5,0.8660)] //result requires 2 complex (= 4 real numbers) finally FreeIt(a,b); end; end; *) function FFTFromReal: TVec; overload; (*Calculate the FFT from all Vec elements. Store the result in the calling vector. of the calling vector is set to match the length of the result. *) function FFTFromReal(const Vec: TVec): TVec; overload; (*Finds and gathers vector elements. Fills the Indexes vector with indexes, of those elements where the Op comparison between a and b is True. Op string parameter can be '<', '>', '>=','<=','=' or '<>'. The method also copies or "gathers" the matched elements to the calling vector. Both the calling vector and Indexes will be sized to match a.Length. On return, both will be subranged to reflect actual number of matching elements. The method will not raise an exception, if the calling vector (Self) or Indexes parameter are already subranged. *) function FindAndGather(const a: TMtxVec; const op: string; const b: TCplx; const Indexes: TVecInt = nil): TVec; overload; (*The b parameter is of double type.*) function FindAndGather(const a: TMtxVec; const op: string; const b: double; const Indexes: TVecInt = nil): TVec; overload; (*The b parameter is of type.*) function FindAndGather(const a: TMtxVec; const op: string; const b: TMtxVec; const Indexes: TVecInt = nil): TVec; overload; (*Gather vector elements. Gather the elements of vector X and store them to the calling vector according to the IndexType, Increment and Offset parameters. The Indexes vector is used only if IndexType is either indVector or indMask. If IndexType is indVector, the values from the Indexes vector denote the index positions in the X vector from which the values should be copied to the calling vector. The Indexes vector must have the indexes stored in the IValues array. The IValues integer arrays points the same memory as Values array. The Increment and Offset parameters are used only if TIndexType is indIncrement. They define the initial offset and a fixed step (increment) between elements to be gathered. If IndexType is indMaks the Indexes vector must have the same size as the X vector. The routine will copy only those elements from the X vector to the calling vector, for which there is a 1 at the coresponding index in the Indexes vector. The elements copied from the X vector will be stored consecutively in the calling vector. See the method to see how to undo the gathering. The performance of the CPU heavily depends on the assumption that elements are stored at consecutive memory locations. If it is neccessary to apply a set of operations only to elements at specific indexes, performance-wise it can proof to be very helpfull, if the elements are gathered first. *) function Gather(const X: TMtxVec; const Indexes: TMtxVecInt =nil; IndexType: TIndexType = indVector; Increment: integer = 1; Offset: integer = 0): TVec; overload; function GatherByIncr (const X: TMtxVec; Increment: integer = 1; Offset: integer = 0): TVec; overload; function GatherByIndex(const X: TMtxVec; const Indexes: TVecInt): TVec; overload; function GatherByMask (const X: TMtxVec; const Mask: TMtxVecInt; const MaskNonZeroCount: integer = -1): TVec; overload; (*Gather a vector, split to two vectors. If the elements of a vector have been split with a Mask and the "positive" elements have been stored in the MaskVec and "negative" elements have been stored in the NotMaskVec, this routine will restore the original vector. The Mask vector stores the mask as Integers in to the memory location occupied by Values array. The memory is typecasted to an array of integers via IValues pointer. Other TVec methods can not be used to perform operations on an array of integers unless explicitly specified. The length of the MaskVec vector must be equal to the number of ones in the Mask vector. The length of the NotMaskVec vector must be equal to the number of zeroes in the Mask vector. *) function GatherSplit(const MaskVec, NotMaskVec: TMtxVec; const Mask: TVecInt): TVec; overload; (*Copies a column from matrix. Copies the Col-th column from Mtx matrix to calling vector. The and properties of calling vector are adjusted automatically. An exception is raised if condition checking is enabled and Col is greater than Mtx.Cols-1. var a: TVec; b: TMtx; begin CreateIt(a); CreateIt(b); try b.SetIt(2,2,False,[1,2, 3,4]); a.GetCol(b,0); // a now contains [1,3] finally FreeIt(a); FreeIt(b); end; end; *) function GetCol(const Mtx: TMtx; Col: integer): TVec; overload; (*Copy the Col-th column elements [Row]..[Row+Len-1] to calling vector elements [Index]..[Index+Len-1]. The Complex property of calling vector must be set explicitly. An exception is raised if condition checking is enabled and column array borders are overrun. *) function GetCol(const Mtx: TMtx; Row, Col, Index, Len: integer): TVec; overload; (*Copy the Col-th column elements [Row]..[Row+Len-1] to calling vector. The and Complex properties of calling vector are adjusted automatically. An exception is raised if condition checking is enabled and column array borders are overrun. *) function GetCol(const Mtx: TMtx; Row, Col, Len: integer): TVec; overload; (*Copies a row from matrix. Copies the Row-th row from Mtx matrix to calling vector. The and Complex properties of calling vector are adjusted automatically. An exception is raised if condition checking is enabled and Row is greater than Mtx.Rows-1. var a: TVec; b: TMtx; begin CreateIt(a); CreateIt(b); try b.SetIt(2,2,False,[1,2, 3,4]); a.GetRow(b,0); // a now contains [1,2] finally FreeIt(a); FreeIt(b); end; end; *) function GetRow(const Mtx: TMtx; Row: integer): TVec; overload; (*Copy the Row-th column elements [Col]..[Col+Len-1] to calling vector elements [Index]..[Index+Len-1]. The Complex property of calling vector must be set explicitly. An exception is raised if condition checking is enabled and column array borders are overrun. *) function GetRow(const Mtx: TMtx; Row, Col, Index, Len: integer): TVec; overload; (*Copy the Row-th column elements [Col]..[Col+Len-1] to calling vector. The and Complex properties of calling vector are adjusted automatically. An exception is raised if condition checking is enabled and column array borders are overrun. *) function GetRow(const Mtx: TMtx; Row, Col, Len: integer): TVec; overload; (*The fast hilbert transform (FFT based). The method forms the imaginary orthogonal part (90 degrees phase shifted version of the original) from the real series by using the fast hilbert transform (FFT based) and saves the complex result in the calling vector. No windowing is performed. Vec must be a real vector or an exception is raised. The and Complex properties of the calling vector are set implicitly to match Vec vector. var a,b,Re,Im: TVec; azero: double; begin CreateIt(a,b,Re,Im); try a.SetIt(false,[1,2,3,4,5,6,7,8]); b.Hilbert(a); Re.RealPart(b); Im.ImagPart(b); azero := Re.DotProd(Im); // if Re is orthogonal to Im, azero becomes 0 finally FreeIt(a,b,Re,Im); end; end; *) function Hilbert(const Vec: TVec; const method: THilbertMethod = hmMethod1): TVec; overload; (* Sums items from Data with matching corresponding indexes from Bins and places result in self. The size of self is set to BinsMax+1 provided that sufficient memory is available. BinsMax with default value of -1 indicates that Bins.Max call is to be made internally. The routine does not perform additional range checking, if BinsMax is provided explicitely (memory overwrite is possible). *) function GroupSum(const Bins: TMtxVecInt; const Data: TMtxVec; const BinsMax: integer = -1): TVec; overload; (* Sums items from Data with matching corresponding indexes from Bins and places result in self. The size of self is checked to be BinsMax+1. The routine does not initialize the calling vector to 0. The routine does not perform additional range checking, because BinsMax is provided explicitely (memory overwrite is possible). *) function GroupSumIteration(const Bins: TMtxVecInt; const Data: TMtxVec; const BinsMax: integer): TVec; overload; (*The inverse discrete cosine transform (DCT). Calculates the inverse discrete cosine transform (DCT) of a Vec and writes the results in the calling vector. If Vec is a power of 2, the function uses an efficient algorithm that is significantly faster than the direct computation of DCT. For other values of Vec length, this function uses the direct formulas given below; however, the symmetry of cosine function is taken into account, which allows to perform about half of the multiplication operations in the formulas. In the following definition of inverse DCT, N=Vec.Length and V is the calling vector: var a,b: TVec; begin CreateIt(a,b); try a.SetIt(False,[1,-2,3,4]); b.IDCT(a); finally FreeIt(a,b); end; end; *) function IDCT(const Vec: TVec): TVec; overload; (*Calculate the inverse DCT in-pllace. The length of the calling vector is adjusted automatically. *) function IDCT: TVec; overload; (*The inverse backward FFT from complex to complex. Calculates the inverse (backward) Fast Fourier Transformation (FFT) from complex to complex for all calling vector elements in-place. If the NoScale parameter is true, then no scaling is performed for the calling vector. The results can be erroneous if overflow or underflow occurs. var a,b: TVec; begin CreateIt(a,b); try a.SetIt(True,[1,2,3,4]); b.IFFT(a,True); finally FreeIt(a,b); end; end; *) function IFFT(NoScale: boolean = False): TVec; overload; (*Calculate the inverse FFT from all Vec elements. Store the results in the calling vector. If the NoScale parameter is true then no scaling is performed for the calling vector. Vec must not be the power of two. and Complex properties of the calling vector are set implicitly to match Vec vector. *) function IFFT(const Vec: TVec; NoScale: boolean = False): TVec; overload; (*The inverse FFT from complex to real. Calculates the inverse Fast Fourier Transformation (FFT) from complex to real from all calling vector elements. The result is a real type vector. Input vector must be a complex vector or an exception is raised. If the NoScale parameter is true then no scaling is performed for the calling vector. The results can be erroneous if overflow or underflow occurs. In-place fsfCCS complication When is equal to fsfCCS the Length of the result will be equal to Length-2, because the source data is bigger than the result data by 2 real samples, if is false. If is True the result will fill up Length-1 samples. var a,b: TVec; begin CreateIt(a,b); try //Even a.SetIt(True,[1,2,3,4]); b.FFTFromReal(a); // b = [(10, 0),( -2,2), (-2, 0)] b.IFFTToReal; // b = [1, 2, 3, 4, -2, 0)] //Odd length a.SetIt(True,[1,2,3,0]); b.FFTOddLength := True; //use only Length-1 samples b.FFTFromReal(a); // b = [(6,0),( -1.5,0.8660)] //result requires 2 complex (= 4 real numbers) b.IFFTToReal; //b = [1, 2, 3, 0.8660] //Event length a.SetIt(True,[1,2,3,4, 0,0]); //allocate two more elements a.FFTOddLength := false; //use only Length-2 samples a.FFTFromReal; // a = [(10, 0),( -2,2), (-2, 0)] //result requires 3 complex (= 6 real numbers) a.IFFToReal; // a = [1, 2, 3, 4, -2, 0)] finally FreeIt(a,b); end; end; *) function IFFTToReal(NoScale: boolean = False): TVec; overload; (*Calculate the inverse FFT from all Vec elements. Store the results in the calling vector. Vec must not be the power of two. and Complex properties of the calling vector are set implicitly the size and type of the result. *) function IFFTToReal(const Vec: TVec; NoScale: boolean = False): TVec; overload; (*Integrate calling vector values. Perform d-times integration of calling vector values, where d is equal to Init length. Definies initial values for integration. Size of Init vector determines how many times calling vector values will be integrated.*) function Integrate(const aInit: TVec): TVec; overload; (*Integrate all Vec elements using initial values in Init. Store the results in calling vector. and Complex properties of the calling vector are set implicitly the size and type of the result. *) function Integrate(const Vec: TVec; aInit: TVec):TVec; overload; (*The Kronecker product between two vectors. Calculates the Kronecker product between vectors Vec1 and Vec2 and stores the results in calling vector. var a,b,c: TVec; begin CreateIt(a,b,c); try a.SetIt(False,[1,2,3,4]); b.SetIt(False,[1,2,3,4]); c.Kron(a,b); // c = [1,2,3,4, 2,4,6,8, 3,6,9,12, 4,8,12,16] finally FreeIt(a,b,c); end; end; *) function Kron(const Vec1, Vec2: TVec): TVec; overload; (*The norm of a vector. Calculates the norm of a Vec vector and stores the results in calling vector. This functions works the same as . *) function Norm(const Vec: TMtxVec): TMtxVec; (*Downsamples (reduces) the number of vector elements. This method speeds up drawing of huge amounts of data (>> 2000 samples). You should pass your data to the PixelDownSample method before you pass the values to the Charting routine. The X and Y vectors contain the values for X and Y axis, that you would normally pass to the charting procedure. The downsampled Y is stored in the calling vector and downsampled X is stored in the NX vector. If your data is equidistant on X axis, you can omit the X vector or, if you are in doubt, allow the routine to downsample the X vector also. If your data is not equidistant on the X axis, you must indicate that by specifying the Equidistant parameter as False and provide X and NX vectors, where X containes the step on the X axis and NX will contain the downsampled result for X axis. With Width parameter you specify the width of the charting region in pixels. (Example: Chart.Width). The routine will reduce the number of samples in vectors Y and X in such a way that there will be no visual difference between the original and downsampled data. That however will no longer be true, if you will zoom-in on the data. The performance gain can be as big as 100x depending on the charting tool that you use. You can easily draw data series from vectors with length of over 1.000.000 samples in real time. var a,b: TVec; begin CreateIt(a,b); try a.SetIt(False,[0,0,0,1,2,3,1,2,3]); b.PixelDownSample(3,a); finally FreeIt(a,b); end; end; *) procedure PixelDownSample(Width: integer; Y: TVec; Index,Len: integer; X: TVec = nil; NX: TVec = nil; Equidistant: TEquidistantSample = eqsXEquidistant); overload; (*Downsample the vectors Y and (optionaly) X starting at position Index and for Len samples. Store result for Y in the calling vector and the result for X in the NX vector. If X axis is equidistant, you can omit X and NX parameters. Set Width to the number of target pixels. An exception is raised, if any of the vectors is complex or if array borders are overrun/underrun. *) procedure PixelDownSample(Width: integer; Y: TVec; X: TVec = nil; NX: TVec = nil; Equidistant: TEquidistantSample = eqsXEquidistant); overload; (*Downsample the vectors Y and (optionaly) X starting at position Index and for Len samples. The method downsamples only the maximum values. This can be usefull, if the input is already a downsampled signal which has to be further downsampled. var a,b,c,d,High,Low: TVec; begin CreateIt(a,b,c,d); CreateIt(High,Low); try a.SetIt(False,[0,0,0,1,2,3,1,2,3]); b.PixelDownSample(4,a); High.Demultiplex(b,2,0); Low.Demultiplex(b,2,1); c.PixelDownSampleHigh(2,High); //further downsample d.PixelDownSampleLow(2,Low); //further downsample b.Size(2*c.Length); b.Multiplex(c,2,0); b.Multiplex(d,2,1); //b now contains the same result, as if we would have called //on the start: b.PixelDownSample(2,a); finally FreeIt(a,b,c,d); FreeIt(High,Low); end; end; *) procedure PixelDownSampleHigh(Width: integer; Y: TVec; Index, Len: integer; X: TVec = nil; NX: TVec = nil); overload; procedure PixelDownSampleHigh(Width: integer; Y: TVec; X: TVec = nil; NX: TVec = nil); overload; (*Downsample the vectors Y and (optionaly) X starting at position Index and for Len samples. The method downsamples only the minimum values. This can be usefull, if the input is already a downsampled signal which has to be further downsampled. *) procedure PixelDownSampleLow(Width: integer; Y: TVec; Index, Len: integer; X: TVec = nil; NX: TVec = nil); overload; procedure PixelDownSampleLow(Width: integer; Y: TVec; X: TVec = nil; NX: TVec = nil); overload; (*Fills vector with prime numbers, starting from 2 up to the value of n. Fills calling vector with prime numbers, starting from 2 up to the value of n. The memory for at least n elements is allocated. The maximum value of n is 1000. The prime numbers are fetched from a precreated table. var a: TVec; begin CreateIt(a); try a.PrimeNumbers(10); // a = [2,3,5,7] finally FreeIt(a); end; end; *) function PrimeNumbers(n: integer): TVec; (*Fills the calling vector with a series following linear rule. Fills the calling vector with a series following the rule: Values[k] := k (Offset is zero and Step is one). If the calling vector is complex, only the real part is set. var a: TVec; begin CreateIt(a); try a.Size(5,True); a.Ramp(0,Pi); a.Sin; finally FreeIt(a); end; end; which is identical to: CreateIt(a); try a.Size(5,True); for i:= 0 to a.Length-1 do a[i] := sin(i*Pi); finally FreeIt(a); end; *) function Ramp: TVec; overload; (*Fills the calling vector with a series. Method follow the rule: CValues[k] := Offset + k*Step. *) function Ramp(const Offset, Step: TCplx): TVec; overload; (*Fills the calling vector. Method uses the following rule: Values[k] := Offset + k*Step. If the calling vector is complex, only the real part is set. *) function Ramp(const Offset, Step: double): TVec; overload; (*Fills the calling vector elements [Index]..[Index+Len-1]. Method uses the following rule: Values[k] := Offset + k*Step. If the calling vector is complex, only the real part is set. An exception is raised if calling vector array borders are overrun. *) function Ramp(const Offset,Step: double; Index,Len: integer): TVec; overload; (*Fills the calling vector elements [Index]..[Index+Len-1]. Following the rule: Values[k] := Offset + k*Step. If the calling vector is complex, only the real part is set. An exception is raised if array borders of the calling vector are overrun. *) function Ramp(const Offset, Step: TCplx; Index,Len: integer): TVec; overload; (*The Offset is complex, but the step is real.*) function Ramp(const Offset: TCplx; const Step: double): TVec; overload; (*Fills the calling vector elements [Index]..[Index+Len-1]. Following the rule: Values[k] := Offset + k*Step. The Offset is complex, but the step is real. *) function Ramp(const Offset: TCplx; const Step: double; Index,Len: integer): TVec; overload; function ReadValues(const SrcStream: TStream; Precision: TPrecision; Endian: TEndianness = boLittleEndian): Int64; override; procedure Reset; override; (*Resizes vector size while preserving values. Resizes calling vector to Len and fills it with Src vector first Len values. If Src length is less than Len and ZeroIt parameter is true, the remaining calling vector values are set to zero. var a, b: Tvec; begin CreateIt(a,b); try a.SetIt(false,[1,2,3]); b.SetIt(false,[9]); b.Resize(a,7,True); // b=(9,1,2,3,4,0,0,0) finally FreeIt(a,b); end; end; *) function Resize(const Src: TMtxVec; Len: integer; ZeroIt: boolean = False): TVec; overload; (*Resizes calling vector Length to Len. If is less than Len and ZeroIt parameter is true, the remaining calling vector values are set to zero. var a: Tvec; begin CreateIt(a); try a.SetIt(false,[1,2,3]); a.Resize(7,True); // a= [1,2,3,0,0,0,0] finally FreeIt(a); end; end; *) function Resize(Len: integer; ZeroIt: boolean = False): TMtxVec; overload; (*Reverse vector elements. The method reverses vector elements by using the following equation: This overload reverses all calling vector elements in-place. var a: TVec; begin CreateIt(a); try a.SetIt(False,[1,2,3,4]); a.Reverse; // a = [4,3,2,1] finally FreeIt(a); end; end; *) function Reverse: TVec; overload; (*Reverse all Vec elements. Xtore the result in the calling vector elements. The and Complex roperties of the calling vector are set implicitly to match Vec vector. *) function Reverse(const Vec: TMtxVec): TVec; overload; (*A cyclic shift on vector elements. Performs cyclic shift on vector elements. The number of elements to shift is specified in the Offset parameter. Offset can be any integer number, positive or negative. var a: TVec; begin CreateIt(a); try a.SetIt(False,[1,2,3,4]); a.Rotate(2); // a = [3,4,1,2] finally FreeIt(a); end; end; *) function Rotate(Offset: integer): TVec; overload; function Rotate(const Src: TMtxVec; Offset: integer): TVec; overload; (*Sets vector values (double). Sets the property of the calling vector to (High(A)+1) and the Complex property to AComplex. The double elements of A array are copied to the calling vector. If AComplex is True then real parts of complex numbers are on even (0,2,4..)and imaginary parts on odd indexes.(1,3,5,..) Note Use this method for setting a double array only. *) function SetDouble(AComplex: boolean; const A: array of double): TVec; overload; (*Sets vector values (integer). Sets the property of the calling vector to (High(A)+1) and the Complex property to AComplex. The integer elements of A array are copied to the calling vector. If AComplex is True then real parts of complex numbers are on even (0,2,4..)and imaginary parts on odd indexes.(1,3,5,..). Note Use this method for integer array only. *) function SetInteger(AComplex: boolean;const A: array of Integer): TVec; overload; (*Sets vector values (single). Sets the property of the calling vector to (High(A)+1) and the Complex property to AComplex. The single elements of A array are copied to the calling vector. If AComplex is True then real parts of complex numbers are on even (0,2,4..)and imaginary parts on odd indexes.(1,3,5,..) Note Use this method for single array only. *) function SetSingle(AComplex: boolean; const A: array of single): TVec; overload; (*Sets vector values. SetIt makes the use of open array construction, to set the values of the calling vector. It gives you the possibility to pass large arrays of elements without having to declare constant arrays. Sets the property of the calling vector to (High(A)+1) and the property to AComplex. The elements of A array are copied to the calling vector. If AComplex is True then real parts of complex numbers are on even (0,2,4..) and imaginary parts on odd indexes (1,3,5,..). var a: TVec; begin CreateIt(a); try a.SetIt(False,[1,2,3,4]); // a = [1,2,3,4] finally FreeIt(a); end; end; *) function SetIt(AComplex: boolean;const A: array of double): TVec; overload; (*Sets vector values (double). Does not change the or Complex properties of the calling vector, but it does check for array overrun. The elements of A array are copied to the calling vector, starting at index 0. If the calling vector is complex then real parts of complex numbers are on even (0,2,4..)and imaginary parts on odd indexes.(1,3,5,..) *) function SetIt(const A: array of double): TVec; overload; (*Sets vector values (complex). Sets the property of the calling vector to (High(A)+1) and the Complex property to true. The complex elements of A array are copied to the calling vector CValues. Note Use this method for complex array only. *) function SetCplx(const A: array of TCplx): TVec; (*Defines a sub-vector. Define a subvector of the Src vector starting at BeginIndex and ending at EndIndex (inclusive). *) procedure SetSubIndex(const Src: TMtxVec; BeginIndex, EndIndex: integer); overload; (*Defines the calling vector to have the view of the same memory as Src. Src vector's Length property may not change while any other object has it's own view of it. a.SetSubRange(b,..); This SetSubRange method must be handled with great care. Namely: * b can be freed before "a" and accessing "a" gives AV. * a can be further subranged with c and same problem occurs when b is freed before c. * If you resize b, all objects which have subranged b are no longer pointing to valid memory. * b can Subrange other objects. Similar problem as when changing the size of b. Again all objects which have subranged b are not longer pointing to valid memory. All this can lead to hard to find bugs. *) procedure SetSubRange(const Src: TMtxVec); overload; (*Shift vector elements left or right in the array. Shifts calling vector elements. The number of elements to shift is specified in the Offset parameter. Offset can be any integer number, positive or negative. var a: TVec; begin CreateIt(a); try a.SetIt(False,[1,-2,3,0]); a.Shift(1); // a = 1,1,-2,3 finally FreeIt(a); end; end; *) function Shift(Offset: integer): TVec; overload; (*Shift vector elements left or right in the array. Shifts Src vector elements and stores the result in the calling object. The number of elements to shift is specified in the Offset parameter. Offset can be any integer number, positive or negative. *) function Shift(const Src: TMtxVec; Offset: integer): TVec; overload; (*Sets the size of the vector to match an array. Sets the Length of the calling vector to match the length of the array. The Complex is set to True. FloatPrecision property is preserved. *) procedure SizeFromArray(const Src: TCplxArray); overload; (*Sets the size of the vector to match an array. Sets the Length of the calling vector to match the length of the array. The Complex is set to True. FloatPrecision property is preserved. *) procedure SizeFromArray(const Src: TSCplxArray); overload; (*Sets the size of the vector to match an array. Sets the Length of the calling vector to match the length of the array. The Complex is set to false. *) procedure SizeFromArray(const Src: TDoubleArray); overload; (*Sets the size of the vector to match an array. Sets the Length of the calling vector to match the length of the array. The Complex is set to false. *) procedure SizeFromArray(const Src: TSingleArray); overload; (*Sets the size of the vector to match an array. Sets the Length of the calling vector to match the length of the array. The Complex is set to false. *) procedure SizeFromArray(const Src: TIntegerArray); overload; (*Sets the size of the vector to match an array. Sets the Length of the calling vector to match the length of the array. The Complex is set to false. *) procedure SizeFromArray(const Src: TSmallIntArray); overload; (*Sets the size of the vector to match an array. Sets the size (Length) of the caling vector to match the length of the array. The Complex is set to false. *) procedure SizeFromArray(const Src: Math387.TByteArray); overload; (*Sets the size of the vector. Same as the following code:

        if aIsDouble then
        begin
            if aComplex then Size(aLength, mvDoubleComplex)
                        else Size(aLength, mvDouble);
        end else
        begin
            if aComplex then Size(aLength, mvSingleComplex)
                        else Size(aLength, mvSingle);
        end;
        
Calling the Size method does not preserve the contents of the vector. Use the Resize method, if you want to preserve existing values.
*) function Size(ALength: integer; AComplex: boolean; aIsDouble: boolean): TVec ; overload; (*Sets the size of the vector. Same as the following code:
        Vec.Length := ALength;
        Vec.Complex := AComplex;
        
Calling the Size method does not preserve the contents of the vector. Use the Resize method, if you want to preserve existing values. Existing floating point precision is preserved.
*) function Size(ALength: integer; AComplex: boolean): TVec ; overload; (*Sizes the vector. Sets the following properties:
        Length := ALength;
        Complex := false;
        
Existing floating point precision is preserved. Calling the Size method does not preserve the contents of the vector. Use the Resize method, if you want to preserve existing values.
*) function Size(ALength: integer): TVec ; overload; (*Sets the size of the vector. Same as the following code:
        Vec.FloatPrecision := aFloatPrecision;
        Vec.Length := ALength;
        
Calling the Size method does not preserve the contents of the vector. Use the Resize method, if you want to preserve existing values.
*) function Size(ALength: integer; const aFloatPrecision: TMtxFloatPrecision): TVec; overload; (*Sets the size of the vector. Same as the following code:
        Vec.FloatPrecision := FloatRef.FloatPrecision;
        Vec.Length := ALength;
        
Calling the Size method does not preserve the contents of the vector. Use the Resize method, if you want to preserve existing values.
*) function Size(ALength: integer; const FloatRef: TMtxVec): TVec; overload; (*Sets vector size. Length is set to Src.Length and Complex property to AComplex. Floating point precision is obtained from Src. If Src is integer type (TVecInt, TMtxInt), the existing floating point precision is preserved. *) function Size(const Src: TMtxVecBase; AComplex: boolean): TMtxVec ; override; (*Sets vector size. Length is set to Src.Length and precision is set to aFloatPrecision. *) function Size(const Src: TMtxVecBase; const aFloatPrecision: TMtxFloatPrecision): TMtxVec; override; (*Sorts vector elements in ascending order. Sort all calling vector elements. Note If the vector is complex, the complex values are first compared by the absolute value and then (if absolute value is equal) by the argument. var a: TVec; begin CreateIt(a); a.SetIt(True,[2,1,3,4]); a.SortAscend; // a = [1,2,3,4] FreeIt(a); end; *) function SortAscend: TVec; overload; (*Sort calling vector elements [Index]..[Index+Len-1]. An exception is raised if is True and array borders are overrun. *) function SortAscend(Index,Len: integer): TVec; overload; (*Sort calling vector elements [Index]..[Index+Len-1]. An exception is raised if is True and array borders are overrun. IndexVec contains the new order of elements. The order is stored in an array of integers which are accessible via the IValues property. *) function SortAscend(Index,Len: integer; const IndexVec: TVecInt): TVec; overload; (*Sort all calling vector elements. IndexVec contains the new (zero based) order of elements. The order is stored in an array of integers which are accessible via the IValues property. *) function SortAscend(const IndexVec: TVecInt): TVec; overload; (*Sorts vector elements in descending order. Sort all calling vector elements in descending order. Note If the vector is complex, the complex values are first compared by the absolute value and then by the argument. var a: TVec; begin CreateIt(a); try a.SetIt(True,[2,1,3,4]); a.SortDescend; // a = [4,3,2,1] finally FreeIt(a); end; *) function SortDescend: TVec; overload; (*Sort calling vector elements [Index]..[Index+Len-1]. An exception is raised if is True and array borders are overrun. *) function SortDescend(Index,Len: integer): TVec; overload; (*Sort calling vector elements [Index]..[Index+Len-1]. An exception is raised if is True and array borders are overrun. IndexVec contains the new order of elements. *) function SortDescend(Index,Len: integer; const IndexVec: TVecInt): TVec; overload; (*Sort all calling vector elements. IndexVec contains contains the new order of elements.*) function SortDescend(const IndexVec: TVecInt): TVec; overload; (*Splits the calling vector to an array of TVec objects. Copy the contents of the calling TVec object to the TVec objects in Dst array. The and Complex properties of vectors in Dst array must be set explicitly. An exception is raised, if Complex properties of TVec objects do not match or the sum of TVec lengths exceeds the of the calling vector. var a,b,c,d: TVec; begin CreateIt(a,b,c,d); try a.SetIt(False,[0,0,0,0,1,2,3,1,2,3]); a.Split([b,c,d],[4,3,3]); // b = [0,0,0,0], c = [1,2,3], d = [1,2,3] finally FreeIt(a,b,c,d); end; end; *) function Split(const Dst: array of TVec): TVec; overload; (*Copy the contents of the calling TVec object to the TVec objects in Dst array. The Length of objects in Dst array is defined in the DstSize array. The and properties of vectors in Dst array are set implicitly. An exception is raised if the sum of DstSize lengths exceeds the of the calling vector. *) procedure Split(const Dst: array of TVec;const DstSize: array of integer); overload; (*Copy the contents of the calling TVec object to Vec1 and Vec2 objects. The and Complex properties of are set implicitly. An exception is raised, if Offset parameter exceeds the length of the calling vector. The property of Vec1 object is set to Offset and the Length of Vec2 is set to the rest. *) procedure Split(const Vec1: TVec; Offset: integer; const Vec2: TVec); overload; (*Convert strings in aList to double or TCplx. Convert strings in aList to double. () and store them in the Values array of the calling vector. If AComplex is True, then the Complex property is set to True and strings are converted by using the function. The of the calling vector is set to aList.Count and the complex property is auto-detected by looking at the first string. var a,b: TVec; begin CreateIt(a,b); try a.SetIt(False,[1,2,3,4]); a.cos; b.Size(a); b.SetVal(1); a.Add(b); Richedit1.Clear; Memo1.Clear; a.ValuesToStrings(Richedit1.Lines); b.ValuesToStrings(Richedit1.Lines); a.ValuesToStrings(Memo1.Lines); b.ValuesToStrings(Memo1.Lines); Memo1.Lines.SaveToFile('C:\Test.txt'); Memo1.Lines.LoadFromFile('C:\Test.txt'); a.StringsToValues(Memo1.Lines); finally FreeIt(a,b); end; end; *) procedure StringsToValues(const srcList: TStrings); overload; (*Convert strings in aList to double (TCplx) starting at ListIndex. Store them in the Values array of the calling vector from Index to Index+Len-1. If strings represent complex numbers, then the complex property must be True or an exception is raised. The Length property of the calling vector is not changed. If array bounds are overrun and exception is raised. *) function StringsToValues(const srcList: TStrings; ListIndex: integer; Index: integer = 0; Len: integer = MtxVecEOA): TVec; overload; (*Copies only those values from Src, which are not NAN or INF.*) function StripNanAndInf(const Src: TMtxVec): TMtxVec; overload; (*Copies only those values from Src[SrcIndex.. SrcIndex+Len-1], which are not NAN or INF. The length of the Self is set to match the count of matching values. *) function StripNanAndInf(const Src: TMtxVec; SrcIndex, Len: integer): TMtxVec; overload; (*Copies only those values from Src[SrcIndex.. SrcIndex+Len-1], which are not NAN or INF. The length of the Self is not modified. The funtion returns "Index" increased by Number of elements found. The calling vector must have enough space to hold at least Index+Len elements, or an exception will be raised. *) function StripNanAndInf(const Src: TMtxVec; SrcIndex, Index, Len: integer): integer; overload; (*Tensor product between vector and matrix. Calculates the right tensor product between matrix and vector. The result is placed in the calling vector. Depending on the the following operations are available: * mtSymmetric: y = alfa*a*x + beta*y * mtSymmPosDef: y = alfa*a*x + beta*y * mtHermitian: y = alfa*a*x + beta*y * mtHermPosDef: y = alfa*a*x + beta*y * mtTriangular: y = op(a)*x * mtGeneral: y = alfa*op(a)*x + beta*y The and are TVec complex public variables. Their default values are: * Alfa = Cplx(1,0) * Beta = Cplx(0,0). Note Each time you call TensorProd the values of Alfa and Beta are reset to default. If the matrix is not complex, only the real part of Alfa and Beta is used. If matrix complex and symmetric the general type is used. var a,b,c,t: TMtx; d,e,f: TVec; begin CreateIt(a,b,c,t); CreateIt(d,e,f); try // Test non quadratic general matrix a.SetIt(2,3,False,[4,3,3, 3,4,2]); e.SetIt(false,[1,2]); d.TensorProd(e,a); f.SetIt(False,[10,11,7]); if not f.Equal(d) then raise Exception.Create('Not same'); // Test on triangular matrices, left a.TriangleForm := tfUpper; a.TriangleUnit := False; a.SetIt(2,2,False,[4,3, 0,4]); e.SetIt(false,[1,2]); d.TensorProd(e,a,mtTriangle); f.SetIt(False,[4,11]); if not f.Equal(d) then raise Exception.Create('Not same'); // Test on triangular matrices, right a.TriangleForm := tfUpper; // data to be referenced is in upper triangle a.TriangleUnit := False; // non unit diagonal a.SetIt(2,2,False,[4,3, 0,4]); e.SetIt(false,[1,2]); d.TensorProd(a,e,mtTriangle); f.SetIt(False,[10,8]); if not f.Equal(d) then raise Exception.Create('Not same'); // Test on symmetric matrices, right a.TriangleForm := tfUpper; a.SetIt(2,2,False,[4,3, 3,4]); e.SetIt(false,[1,2]); d.TensorProd(e,a,mtSymmetric); f.SetIt(False,[10,11]); if not f.Equal(d) then raise Exception.Create('Not same'); // Test on symmetric matrices, Left a.TriangleForm := tfUpper; a.SetIt(2,2,False,[4,3, 3,4]); e.SetIt(false,[1,2]); d.TensorProd(a,e,mtSymmetric); f.SetIt(False,[10,11]); if not f.Equal(d) then raise Exception.Create('Not same'); finally FreeIt(a,b,c,t); FreeIt(d,e,f); end; end; *) function TensorProd(const Mtx: TMtx; const Vec: TVec; MtxType: TMtxType = mtGeneral; Operation: TMtxOperation = opNone): TVec; overload; (*Calculates the left tensor product between vector and matrix.*) function TensorProd(const Vec: TVec; const Mtx: TMtx; MtxType: TMtxType = mtGeneral; Operation: TMtxOperation = opNone): TVec; overload; (*Calculates the right tensor product between vector and matrix and adds the result to the calling vector.*) function AddTensorProd(const Mtx: TMtx; const Vec: TVec; MtxType: TMtxType = mtGeneral; Operation: TMtxOperation = opNone): TVec; overload; (*Inserts zeroes between consecutive vector values. Inserts zeroes between consecutive vector values. The method copies the values from Src to the calling vector and places Factor-1 zeros between consecutive values. The and Complex properties of the calling vector are set implicitly. Phase parameter defines the initial sample offset and must be less than Factor. var a,b: TVec; begin CreateIt(a,b); try b.SetIt(False,[0,0,1,3,2]); a.UpSample(b,2); // a = [0,0,0,0,1,0,3,0,2,0] finally FreeIt(a,b); end; end; *) function UpSample(const Src: TMtxVec; Factor: integer; Phase: integer = 0): TVec; overload; (*Converts the content of the Values array of the calling vector to a list of strings. Converts all elements of the calling vector to strings with formating ReFormat for the real part and ImFormat for the imaginary part and stores them in dstList, by using the Add method of TStringsobject. If vector is not complex only the ReFormat is used. Note Complex numbers are formated by default as: a+bi. You can have any formating by specifying the ReFormat and ImFormat parameters, but in order for the to work, the basic a+bi formating must be preserved - (chars '+' (' - ') and 'i' ). Performance note: This routine will be exceedingly slow, if TRichEdit.Lines or TMemo.Lines are passed as a parameter for dstList. Use TStringList or StringList types and then call TMemo.Lines.AddStrings(yourList) for best results. procedure TForm1.Button1Click(Sender: TObject); var a,b: TVec; begin CreateIt(a,b); try a.SetIt(False,[1,2,3,4]); a.Cos; b.Size(a); b.SetVal(1); a.Add(b); Richedit1.Clear; Memo1.Clear; a.ValuesToStrings(Richedit1.Lines); b.ValuesToStrings(Richedit1.Lines); a.ValuesToStrings(Memo1.Lines); b.ValuesToStrings(Memo1.Lines); Memo1.Lines.SaveToFile('C:\Test.txt'); Memo1.Lines.LoadFromFile('C:\Test.txt'); a.StringsToValues(Memo1.Lines); finally FreeIt(a,b); end; end; *) function ValuesToStrings(const dstList: TStrings; const Align: TFixedTextAlign = ftaNone; const ReFormat: string = ' 0.#####;-0.#####'; const ImFormat: string = '+0.#####i;-0.#####i'; const Headers: boolean = false; const ColumnWidth: integer = -1): integer; overload; (*Convert elements from Index to Index+Len-1 of the calling vector to strings. Use ReFormat for the real part and ImFormat for the imaginary part and store them in dstList starting at ListIndex. If dstList is not large enough, the method will use the add method of dstList object. If vector is not complex, only the ReFormat is used. Performance note: This routine will be exceedingly slow, if TRichEdit.Lines or TMemo.Lines are passed as a parameter for dstList. Use TStringList or StringList types and then call TMemo.Lines.AddStrings(yourList) for best results. *) function ValuesToStrings(const dstList: TStrings; ListIndex, Index, Len: integer; const Align: TFixedTextAlign = ftaNone; const ReFormat: string = ' 0.#####;-0.#####'; const ImFormat: string = '+0.#####i;-0.#####i'; const Headers: boolean = false; const ColumnWidth: integer = -1): integer; overload; (*Convert all vector elements to text.*) procedure ValuesToText(out Text: String; const ReFormat: string = ' 0.#####;-0.#####'; const ImFormat: string = '+0.#####i;-0.#####i'); overload; (*Convert Index..Index+Len-1 vector elements to text.*) procedure ValuesToText(out Text: String; Index, Len: integer; const ReFormat: string = ' 0.#####;-0.#####'; const ImFormat: string = '+0.#####i;-0.#####i'); overload; (*Transforms vector into vector of standardized data.*) function ZScore: TVec; overload; (*Transforms Src vector into vector of standardized data. Store the results in calling vector. *) function ZScore(const Src: TVec): TVec; overload; (*Returns content as a string. Values will be separated by line breaks. *) function ToString: string; override; (*Parses string content as vector. Values need to be separated by line breaks. For other parsing options call StringToValues. The Parse method works in pair with the ToString method both meant to be a reverse of the other, but do not preserve any other property of the vector except only values. Use SaveToStream/LoadFromStream methods for binary storage option, which uses up to 10x less memory and is a lot faster to save and load. *) function Parse(const Src: string): TVec; end; (*Defines the norm, used in calculating the condition number parameter. Defines the norm, used in calculating the . *) TConditionNumber = ( (*the condition number will not be calculated*)cnNone, (*the norm-1 will be used to calculate the condition number*)cnNorm1, (*the infinite norm will be used to calculate the condition number*)cnNormInf ); (*Defines the matrix triangular type.*) TTriangleForm = ( (*lower triangular matrix*)tfLower, (*upper triangular matrix*)tfUpper ); (*Defines the method, used to balance the matrix.*) TBalanceType = ( (*matrix is neither scaled or permuted*)btNone, (*matrix is scaled, but not permuted*)btScale, (*matrix is permuted, but not scaled*)btPerm, (*matrix is permuted AND scaled*)btFull ); (*Defines the type of the symmetric-definite generalized eigenvalue problem.*) TEigGenType = ( (*The problem is A*x = lambda*B*x, and A is overwritten by inv(U**T)*A*inv(U) or inv(L)*A*inv(L**T)*) etAzBz, (*The problem is A*B*x = lambda*x and A is overwritten by U*A*U**T or L**T*A*L*) etABz, (*The problem is B*A*x = lambda*x and A is overwritten by U*A*U**T or L**T*A*L*) etBAz ); (*Defines the shape of the Sylvester equation.*) TSign = ( (*the + sign in the Sylvester equation*)siPlus, (*the - sign in the Sylvester equation*)siMinus ); (*Defines the vector form in eigenvector calculation.*) TVectorForm = ( (**)vfEig, (**)vfSchur); (*Defines the matrix function. Defines the matrix function. This function prototype is used to define a arbitrary "matrix" function. The parameters are passed as Params and the function is to be applied to the elements of the D vector. *) TMtxFunction = procedure(D: TVec; const Params: array of TCplx); (*Two dimensional array - matrix. Use the matrix class to perform matix operations like multiplication addition, subtraction, solve a system of linear equations, compute eigenvalues, singular value decomposition, least squares solution, 2D FFT's, parallel 1D FFT's and more. *) TMtx = class(TDenseMtxVec ) strict private FMtxError: string; FRefineSolution: boolean; FBackError: double; FForwError: double; FConditionNumber: TConditionNumber; FConditionNr: double; FTriangleForm: TTriangleForm; FTriangleUnit: boolean; FBalance: TBalanceType; FAutoMtxType: boolean; FSuperDiag: integer; FSubDiag: integer; SRows,SCols: integer; SLeadingCols: integer; procedure SetRows(const Value: integer); procedure SetRefineSolution(const Value: boolean); procedure SetConditionNumber(const Value: TConditionNumber); procedure SetTriangleForm(const Value: TTriangleForm); procedure SetTriangleUnit(const Value: boolean); procedure SetBalance(const Value: TBalanceType); procedure SetAutoMtxType(const Value: boolean); procedure SetCols(const Value: integer); procedure SVDSolveInt(var B: TDoubleArray; BIndex: integer; var BC: TCplxDoubleArray; BCIndex, nrhs: integer; const S: TVec; Threshold: Double; var Rank: integer); overload; procedure SVDSolveInt(var B: TSingleArray; BIndex: integer; var BC: TCplxSingleArray; BCIndex, nrhs: integer; const S: TVec; Threshold: single; var Rank: integer); overload; procedure SetSubDiag(const Value: integer); procedure SetSuperDiag(const Value: integer); procedure SetLeadingCols(const Value: integer); function GetLeadingCols: integer; procedure ValidateRange (Row, Col, ToRow, ToCol: integer); strict protected fQuadratic: boolean; finfo: integer; FRows: integer; FCols: integer; FLeadingCols: integer; jitter: TSmallMatrixMultiply; function GetComplexValues: string; override; function GetRealValues: string; override; procedure SubRangeSaveState; override; procedure SubRangeLoadState; override; procedure SetSubRangeDirect(Index: Integer; Len: Integer); override; procedure SetSubRangeDirect(const Src: TMtxVecBase; Index: Integer; Len: Integer); override; procedure SetSubRangeDirect2(const Src: TMtxVecBase; Index: Integer; aRows, aCols: Integer); procedure LQRSolveInt(var B: TDoubleArray; BIndex: integer; var BC: TCplxDoubleArray; BCIndex: integer; BCols: integer; const R: TMtx; Op: TMtxOperation = opNone); overload; procedure LQRSolveInt(var B: TDoubleArray; BIndex: integer; var BC: TCplxDoubleArray; BCIndex: integer; BCols: integer; rcond: double; var rank: integer; const R: TMtx; Op: TMtxOperation = opNone); overload; procedure LQRSolveInt(var B: TSingleArray; BIndex: integer; var BC: TCplxSingleArray; BCIndex: integer; BCols: integer; const R: TMtx; Op: TMtxOperation = opNone); overload; procedure LQRSolveInt(var B: TSingleArray; BIndex: integer; var BC: TCplxSingleArray; BCIndex: integer; BCols: integer; rcond: single; var rank: integer; const R: TMtx; Op: TMtxOperation = opNone); overload; procedure LUSolveInt(var B: TDoubleArray; BIndex: integer; var BC: TCplxDoubleArray; BCIndex: integer; var X: TDoubleArray; XIndex: integer; var XC: TCplxDoubleArray; XCIndex: integer; nrhs: integer; MtxType: TMtxType; Operation: TMtxOperation; const Mtx, OrigMtx: TMtx; const Pipiv: TVecInt); overload; procedure LUSolveInt(var B: TSingleArray; BIndex: integer; var BC: TCplxSingleArray; BCIndex: integer; var X: TSingleArray; XIndex: integer; var XC: TCplxSingleArray; XCIndex: integer; nrhs: integer; MtxType: TMtxType; Operation: TMtxOperation; const Mtx, OrigMtx: TMtx; const Pipiv: TVecInt); overload; function EigDoubleInt(const VL: TMtx; const D: TVec; const VR: TMTx = nil; MtxType: TMTxType = mtGeneral; VectorForm: TVectorForm = vfEig; aExpand: boolean = True): TMtx; overload; function EigSingleInt(const VL: TMtx; const D: TVec; const VR: TMTx = nil; MtxType: TMTxType = mtGeneral; VectorForm: TVectorForm = vfEig; aExpand: boolean = True): TMtx; overload; procedure DeterminantDoubleInt(out result: TCplx; MtxType: TMtxType = mtGeneral); overload; procedure DeterminantSingleInt(out result: TCplx; MtxType: TMtxType = mtGeneral); overload; function LowerTriangleInternal(const Mtx: TMtx; ZeroUpper, Diagonal: boolean): TMtx; overload; function UpperTriangleInternal(const Mtx: TMtx; ZeroLower, Diagonal: boolean): TMtx; overload; procedure DiagonalsCount(out Upper, Lower: integer); procedure DoSetComplex; override; function DoubleCachePointer: TDoubleArray; override; function DoubleCacheOffset: integer; override; function CplxDoubleCachePointer: TCplxDoubleArray; override; function CplxDoubleCacheOffset: integer; override; function SingleCachePointer: TSingleArray; override; function SingleCacheOffset: integer; override; function CplxSingleCachePointer: TCplxSingleArray; override; function CplxSingleCacheOffset: integer; override; function CacheLength: integer; override; function CacheLengthInBytes: Int64; override; procedure HookPointers; override; procedure SetLength(const Value: integer); override; function ValuesToStringsInternal(const dstList: TStrings; const aDelimiter: string; const Align: TFixedTextAlign; const Headers: boolean; const ColumnWidth: integer): integer; overload; override; function StringsToValuesInternal(const srcList: TStrings; const aDelimiter: string): TMtxVecBase; overload; override; strict protected function get_CValues(const RowIdx, ColIdx: integer): TCplx; function get_Values(const RowIdx, ColIdx: integer): double; procedure set_CValues(const RowIdx, ColIdx: integer; const Value: TCplx); procedure set_Values(const RowIdx, ColIdx: integer; const Value: double); function get_SCValues(const RowIdx, ColIdx: integer): TSCplx; function get_SValues(const RowIdx, ColIdx: integer): single; procedure set_SCValues(const RowIdx, ColIdx: integer; const Value: TSCplx); procedure set_SValues(const RowIdx, ColIdx: integer; const Value: single); function get_DefaultArray(const Indx1, Indx2: integer): double; procedure set_DefaultArray(const Indx1, Indx2: integer; const value: double); public function ToolTip: string; (*Returns the 1D index in to the matrix. Returns: Row*Mtx.Cols + Col *) function IndexOf(const Row, Col: integer): integer; overload; (*Returns content as a string. Values will be separated by line breaks. *) function ToString: string; override; (*Parses string content as vector. Values need to be separated by the tab charachter. Rows of values need to be separated by line breaks. For other parsing options call StringToValues. The Parse method works in pair with the ToString method both meant to be a reverse of the other, but do not preserve any other property of the matrix except only values. Use SaveToStream/LoadFromStream methods for binary storage option, which uses up to 10x less memory and is a lot faster to save and load. *) function Parse(const Src: string): TMtx; (*Stores the condition number reciprocial value after the call to LUSolve. The property is set by the method. It contains the calling matrix condition number reciprocial value after the call to method and if property was not cnNone. If the ConditionNr (inverse of condition number) is a very small number (thus the condition number is very large), then the calling matrix is ill-conditioned and the error in the solution will also be large. The condition number is used for analyzing the errors in the solution of a system of linear equations. In practice, most computations are performed with rounding errors. Besides, you often need to solve a system Ax = b where the data (the elements of A and b) are not known exactly. Therefore, it's important to understand how the data errors and rounding errors can affect the solution x. If x is the exact solution of Ax = b, and x + dx is the exact solution of a perturbed problem (A + dA)x = (b + db), then In other words, relative errors in A or b may be amplified in the solution vector x by a factor k(A) = ||A|| ||A -1 || called the condition number of A. The norm used to calculate the condition number is set by the property. Rounding errors have the same effect as relative perturbations c(n)e in the original data. Here e is the machine precision, and c(n) is a modest function of the matrix order n. The corresponding solution error is ||dx||/||x|| <= c(n)k(A)e. (The value of c(n) is seldom greater than 10n), Thus, if your matrix A is ill-conditioned (that is, its condition number k(A) is very large), then the error in the solution x is also large; you may even encounter a complete loss of precision. This loss can be greatly reduced by enabling the property. var X,B: TVec; A: TMtx; begin CreateIt(X,B); CreateIt(A); try B.SetIt(False,[0,2]); A.SetIt(2,2,false,[1,2, 3,4]); // 2x2, not complex matrix A.RefineSolution := True; A.ConditionNumber := cnNormInf; A.LUSolve(B,X); finally FreeIt(B,X); FreeIt(A); end; end; *) property ConditionNr: double read FConditionNr; (*The Info parameter as returned by the last called LAPACK function.*) property Info: integer read FInfo; (*The type of the error condition signaled by LAPACK. The string is set by the various methods, to indicate the type of the error condition signaled by LAPACK if property is not zero. *) property MtxError: string read FMtxError; (*True, if matrix is quadratic (rows=cols).*) property Quadratic: boolean read FQuadratic; (*The component-wise backward error. Set by the method, if the property was True. The BackError property returns the component-wise backward error b. The backward error is the smallest relative perturbation in elements of A (where A is the calling matrix) and b such that x is the exact solution of the perturbed system: The BackError property is calculated only if the property is set to true. *) property BackError: double read FBackError; (*The component-wise forward error. Set by the method, if the property was True. The ForwError property returns the component-wise forward error in the computed solution: *) property ForwError: double read FForwError; (*Access elements of the matrix without specifying the name of the property. This property allows you to access elements of the matrix without specifying the name of the property. For example: amtx[i,j] := 1; // where amtx is a TMtx object . Note Default array property is slower than array pointers. The default array property supports only real values. *) property DefaultArray2D[const Indx1, Indx2: integer]: double read get_DefaultArray write set_DefaultArray; default; {$WARNINGS OFF} (*Access elements of the matrix. The RowIdx indicates the row index and the ColIdx parameter indiciates the column index. *) property Values[const RowIdx, ColIdx: integer]: double read get_Values write set_Values; property SValues[const RowIdx, ColIdx: integer]: single read get_SValues write set_SValues; (*Access elements of the matrix. The RowIdx indicates the row index and the ColIdx parameter indiciates the column index. *) {$WARNINGS OFF} property CValues[const RowIdx, ColIdx: integer]: TCplx read get_CValues write set_CValues; property SCValues[const RowIdx, ColIdx: integer]: TSCplx read get_SCValues write set_SCValues; {$WARNINGS ON} (*Create a new TMtx object. Creates a new TMtx object. You should use the where possible and avoid using the Create constructor, but only in cases when the object is created and destroy within the same routine. var A: TMtx; begin A := TMtx.Create; try A.Size(20,20,false); finally A.Free; // takes about 500 CPU cycles end; CreateIt(A); try A.Size(20,20,false); finally FreeIt(A); // takes only about 40 CPU cycles end; end; *) constructor Create; overload; override; destructor Destroy; override; (*Obtain a pointer to a matrix from object cache. Returns a pointer to a matrix from object cache. Same as calling the CreateIt routine. *) class function CreateFromCache: TMtx; procedure FreeToCache; override; (*Returns a pointer to the double value stored at Row and Col.*) function PValues(const Row, Col: integer): PPDouble; overload; (*Returns a pointer to the single value stored at Row and Col.*) function PSValues(const Row, Col: integer): PPSingle; overload; function SDataIndex(const Row,Col: integer): integer; overload; (*Returns a pointer to the double precision complex value stored at Row and Col.*) function PCValues(const Row, Col: integer): PPCplx; overload; (*Returns a pointer to the single precision complex value stored at Row and Col.*) function PSCValues(const Row, Col: integer): PPSCplx; overload; function CDataIndex(const Row,Col: integer): integer; overload; (*Defines a sub vector/matrix. The method will define a subarray starting at Index and ending at Index + (aRows*aCols)-1. No copying will occur, only pointers will be shifted or indices adjusted. The subranged matrix will have the size aRows and aCols. Length will be equal to aRows*aCols. All values of the original will be preserved. An exception will be raised if an attempt is made to change the size of calling object. A sub-vector/matrix is vector/matrix, which does not have its own memory allocated. Instead it adopts the memory of the source object and all operations done on either of the objects affect the same elements. The use of subvectors/submatrices increases CPU cache reuse, lower's memory requirements, increases application performance and improves code readability. To again obtain a view of the full vector/matrix, see The routine only makes sense to be used where aCols matches Src.Cols. MtxVec has only limited support for matrices where the matrix rows are not stored strictly consecutively. This overload is to be used with great caution. The routine should not be mixed with other SetSubRange routines or subrange stack. *) procedure SetSubRange(const Src: TMtxVec; Index: integer; aRows, aCols: integer); overload; (*Adopts a pointer to one dimensional array. Addopts a pointer to AArray array. The method sets the calling matrix property to aFloatPrecision, to ARows, to ACols and Values1D and CValues1D to Pointer(AArray). Notes: * Required to call the method, before freeing the object * do not resize the vector * do not call any routines relying on Lapack when "Core edition" is used (not linking dlls), because Lapack will assume that adopted memory is a dynamic array and will modify array index -2. *) procedure Adopt(AArray: PAPointer; ARows, ACols: integer; aIsComplex: boolean; aIsDouble: boolean); overload; procedure Adopt(AArray: PAPointer; ARows, ACols: integer; aFloatPrecision: TMtxFloatPrecision); overload; (**) procedure Assign(Src: TPersistent); override; (*Calculates the tensor product of two vectors and adds the result to calling matrix. Calculates the tensor product of Vec1 and Vec2 vectors and adds the result to the calling matrix by using the following formula: Y=Vec1 x Vec2 + Y. If the ConjVec2 parameter is true, then the result will be tensor product of Vec1 and conjugated Vec2. The property is set to Vec1. and property is set to Vec2. and Complex property of the calling matrix is adjusted automatically. var a,b: TMtx; v1,v2: TVec; begin CreateIt(a,b); CreateIt(v1,v2); try // Test non quadratic general matrix a.SetIt(2,2,False,[0,2,2,0]); v1.SetIt(false,[1,0]); v2.setIt(false,[0,1]); a.AddTensorProd(v1,v2,False); b.SetIt(False,[1,2,2,1]); if not a.Equal(b) then raise Exception.Create('Not same'); finally FreeIt(a,b); FreeIt(v1,v2); end; end; *) function AddTensorProd(const Vec1, Vec2: TVec; ConjVec2: boolean = False): TMtx; overload; (*Adjungate matrix. Calculate the adjungate matrix in-place. Adjungation is equal to transpose and conjugate. *) function Adjung: TMtx; overload; (*Calculate the adjungate to X matrix and store the results in calling matrix. The , and Complex properties of the calling matrix are set implicitly to match those of X matrix. *) function Adjung(const X: TMtx): TMtx; overload; (*Convert banded matrix to dense. *) procedure BandedToDense(const Src: TMtx); overload; procedure Clear; override; (*Test if the matrix is semi positive definite. Returns True, if the matrix semi positive definite and at the same time performs the Cholesky decomposition of the calling matrix. If the TriangleForm is set to tfLower then the upper part of the matrix is overwritten with transpose of L, where L is the result of factorization. If the TriangleForm is set to ftUpper then the lower triangle of the matrix is overwritten with the transpose of U, where U the result of factorization. *) function Cholesky: boolean; overload; (*Exchange matrix columns. Exchange the i-tj and j-th columns of the calling matrix in-place. An exception is raised if matrix bounds are overrun. *) function ColExchange(i, j: integer): TMtx; overload; (*Permute the columns of the Src matrix. The parameter PermuteIdx contains indexes of columns P[i] to which column at index "i" is to be moved. The result of the permutation is stored in the calling matrix. Only entire matrix can be copied. *) function ColPermute(const Src: TMtx; const PermuteIdx: TVecInt): TMtx; overload; (*Permute the rows of the Src matrix. The parameter PermuteIdx contains indexes of columns P[i] to which column at index "i" is to be moved. The result of the permutation is stored in the calling matrix. Only entire matrix can be copied. *) function RowPermute(const Src: TMtx; const PermuteIdx: TVecInt): TMtx; overload; (*Concatenate an array of matrices to single matrix. Concatenate an array of matrices to form one big matrix and store the result in the calling matrix. The dimensions of the block matrices in the Src array must match, to form the new matrix. The block matrices must be all real or all complex, otherwise an exception will be raised. You must specify Arows*ACols block matrices in the Src array. The , and Complex properties of the calling matrix are adjusted automatically. var A,B,C,D,E: TMtx; begin CreateIt(A,B,C,D); CreateIt(E); try A.Size(2,2); B.Size(A); C.Size(A); D.Size(A); E.Concat(2,2,[A,B C,D]); // form one 4x4 matrix finally FreeIt(E); FreeIt(A,B,C,D); end; end; *) function Concat(ARows, ACols: integer;const Src: array of TMtx): TMtx; overload; (*Concenates an array of matrices horizontally. Concenate the Src matrices horizontally and store the results in the calling matrix. The , and Complex properties of the calling matrix are adjusted automatically. An exception is raised if any of the Src matrices Complex or Rows property does not match. var A,B,C,D,E: TMtx; begin CreateIt(A,B,C,D); CreateIt(E); try A.Size(2,2); B.Size(A); E.Size(4,4); // overwrite the lower part of the E matrix // with values from A and B E.ConcatHorz(2,2,[A,B]); //E becomes: //[E11 E12 E13 E14] //[E21 E22 E23 E24] //[A11 A12 B11 B12] //[A21 A22 B21 B22] finally FreeIt(E); FreeIt(A,B,C,D); end; end; *) function ConcatHorz(const Src: array of TMtx): TMtx; overload; (*Concenate the Src matrices horizontally and store the results in the calling matrix. The DestRow and DestCol parameters indicate the starting position (in the calling matrix) for concenating. An exception is raised, if the calling matrix array bounds are overrun. An exception is raised, if any of the Src matrices Complex or Rows properties do not match. *) function ConcatHorz(DestRow, DestCol: integer;const Src: array of TMtx): TMtx; overload; (*Concenates an array of matrices vertically. Concenate the Src matrices vertically and store the results in calling matrix. The , and Complex properties of the calling matrix are adjusted automatically. An exception is raised, if any of the Src matrices Complex or Cols properties do not match. var A,B,C,D,E: TMtx; begin CreateIt(A,B,C,D); CreateIt(E); try A.Size(1,2); B.Size(A); E.Size(4,4); // overwrite the lower part of the E matrix // with values from A and B E.ConcatVert(2,2,[A,B]); // E becomes: //[E11 E12 E13 E14] //[E21 E22 E23 E24] //[A11 A12 E33 E34] //[B11 B12 E43 E44] finally FreeIt(E); FreeIt(A,B,C,D); end; end; *) function ConcatVert(const Src: array of TMtx): TMtx; overload; (*Concenate the Src matrices vertically and store the results in calling matrix. The DestRow and DestCol parameters indicate the starting position (in the calling matrix) for concatenating. An exception is raised, if the calling matrix array bounds are overrun. An exception is raised, if any of the Src matrices Complex or Cols properties do not match. *) function ConcatVert(DestRow, DestCol: integer;const Src: array of TMtx): TMtx; overload; (*Performs finite, linear convolution of two two-dimensional signals. Performs finite, linear convolution of two two-dimensional signals. The argument names X and H are chosen to suggest FIR filtering. The result of the convolution is defined as follows: In the above expressions, X[n, m] is a shorthand for X[n+ m* X.Cols], H[n, m] is a shorthand for H[n+ m* H.Cols], and y[n, m] is a shorthand for: y[n+ m* (X.Cols+ H.Cols-1)]. If NoResize parameter is True, the size of the calling matrix is set to the size of the X matrix and filtering edge effect is equally distributed. If the NoResize parameter is False, the size of the calling matrix is set to: Rows = X.Rows + H.Rows - 1 Cols = X.Cols + H.Cols - 1 In image processing X is the mitxure and H is the convolution kernel. *) (*Copy the Mtx elements [MtxRow,MtxCol]..[MtxRow+NrRows-1,MtxCol+NrCols-1] to the calling matrix elements [Row,Col],,[Row+NrRows-1,Col+NrCols-1]. An exception is raised if is true and bounds are overrun. If Transpose is true, the matrix is transposed as well. An exception is raised if is true and Complex properties of the calling matrix and Mtx do not match. *) function Copy(const Mtx: TMtx; MtxRow, MtxCol, Row, Col, NrRows, NrCols: integer; Transpose: boolean = false): TMtx; overload; (*Copies matrix values to a 2D array. Copies all matrix values to a 2D array. The rows of the array will have two times as many columns, if the calling matrix object is Complex. *) procedure CopyToArray(var Dst: T2DDoubleArray); overload; procedure CopyToArray(var Dst: T2DSingleArray); overload; (*Copies all matrix values to a 2D array.*) procedure CopyToArray(var Dst: T2DCplxArray); overload; procedure CopyToArray(var Dst: T2DSCplxArray); overload; (*Copies the matrix from a 2D array. Sizes the matrix to match the size of the 2D array and copies all the values. *) procedure CopyFromArray(const Src: T2DDoubleArray); overload; procedure CopyFromArray(const Src: T2DSingleArray); overload; (*Sizes the matrix to match the size of the 2D array and copies all the values.*) procedure CopyFromArray(const Src: T2DCplxArray); overload; procedure CopyFromArray(const Src: T2DSCplxArray); overload; (*Sizes the Dst array to match the matrix. Sizes the Dst array to match the size of the matrix. *) procedure SizeToArray(var Dst: T2DCplxArray); overload; procedure SizeToArray(var Dst: T2DSCplxArray); overload; (*Sizes the Dst array to match the size of the matrix. The rows will have two times as many columns, if the calling matrix object is Complex. *) procedure SizeToArray(var Dst: T2DDoubleArray); overload; procedure SizeToArray(var Dst: T2DSingleArray); overload; (*Sizes the calling matrix to match the size of the array. Sizes the calling matrix to match the size of the array. Complex property is set to true. IsDouble property value is preserved. *) procedure SizeFromArray(const Src: T2DCplxArray); overload; procedure SizeFromArray(const Src: T2DSCplxArray); overload; (*Sizes the calling matrix to match the size of the array. Complex property is set to false. IsDouble property value is preserved. *) procedure SizeFromArray(const Src: T2DDoubleArray); overload; procedure SizeFromArray(const Src: T2DSingleArray); overload; (*Copies values from vector to a matrix. Copy all Vec elements to the calling matrix. Set the calling matrix property to NrRows. Set the calling matrix property to Vec.Length div NrRow (Length = Rows*Cols). The calling matrix Complex property is adjusted automatically. An exception is raised if Vec.Length mod NrRows <> 0. var A: TMtx; v: TVec; begin CreateIt(A); Create(v); try v.SetIt(true,[1, 0, 2, -1, 5, 1.2]) ; A.CopyVec(v); finally FreeIt(A); end; end; *) function CopyVec(const Vec: TVec; NrRows: Integer): TMtx; overload; function Copy(const Src: TMtxVecInt; const dstFloatPrecision: TMtxFloatPrecision): TMtxVec; override; (*Copy Vec elements [VecIndex]..[VecIndex+Len-1] to the calling matrix elements starting with [Row,Col]. An exception is raised if is true and bounds are overrun or if Complex properties of the calling matrix and Vec do not match. *) function CopyVec(const Vec: TVec; VecIndex, Len, Row, Col: Integer): TMtx; overload; (*Cumulative sum for each of the matrix columns. Calculate the cumulative sum for each of the calling matrix columns in-place. var Mtx: TMtx; begin Mtx := TMtx.Create; try Mtx.Size(3,2,false,[1,2, 2,5, 3,1]); Mtx.CumSum; // Mtx becomes: // 1, 2 // 3, 7 // 6, 8 finally Mtx.Free; end; end; *) function CumSum: TMtx; overload; (*Calculate the cumulative sum for each of the X matrix columns. Store the results in calling matrix. The , and Complex properties of the callig matrix are adjusted implicitly to match those of Mtx matrix. *) function CumSum(const Mtx: TMtx): TMtx; overload; (*Determines type of the matrix. Tests the calling matrix and returns the of the calling of matrix. The following types are supported: = symmetric positive definite matrix = symmetric matrix = Hermitian positve definite matrix = Hermitian matrix = triangular matrix, with unit or non unit main diagonal = general matrix (none of the above) Checking for positive definite matrix can be very expensive (O(n) = 1/3*n^3). Therefore the ChekPosDef parameter is False by default, unless the user specifies otherwise. The method will not detect banded matrix storage. var X,B: TVec; A: TMtx; at: TMtxType; begin CreateIt(X,B); CreateIt(A); try B.SetIt(false,[0,2]); A.SetIt(2,2,false,[1,2, 2,4]); // 2x2 real matrix at := A.DetectMtxType; A.LUSolve(B,X,at); // This is the same for this example (except slower) A.LUSolve(B,X,mtSymmetric); // You could also specify A.AutoMtxType := True A.LUSolve(B,X); // the type is autodetected finally FreeIt(B,X); FreeIt(A); end; end; *) function DetectMtxType(CheckPosDef: boolean = False): TMtxType; overload; (*Convert dense matrix to banded. Convert the calling matrix stored in dense format to banded format and store the result in Dst. MaxElemCount defines the maximum number of elements that the Banded matrix may have before an exception will be raised. *) procedure DenseToBanded(const Dst: TMtx; MaxElemCount: integer = 10000000); overload; (*Determinant of squared matrix. Calculate the determinant of squared real matrix. An exception is raised if the calling matrix Complex property is true. var A: TMtx; b: double; begin CreateIt(A); try A.SetIt(2,2,false,[1,2, 2,4]); // 2x2, not complex matrix b := A.Determinant; // 4 + 4 = 9 finally FreeIt(A); end; end; *) function Determinant(MtxType: TMtxType = mtGeneral): double; overload; (*Calculates the determinant of squared complex matrix. the result in result complex variable. An exception is raised if the calling matrix Complex property is false. *) procedure Determinant(out result: TCplx; MtxType: TMtxType = mtGeneral); overload; (*Disowns a pointer to an array from matrix Values1D. The method does the opposite of the method. It will set the AArrays to Pointer(Values), ARows and ACols to matrix's and and IsComplex to matrix Complex property. Use the Disown method to "disconnect" AArray from the TMtx.Values1D. Disown sets Values1D and CValues1D array pointers to nil and Rows, Cols properties to ACols, but without freeing the allocated memory. The allocated memory can be disowned only, if it was adopted with a call to the method. *) procedure Disown(out AArray: PAPointer; out ARows, ACols: integer; out aIsComplex: boolean; out aIsDouble: boolean); overload; procedure Disown(out AArray: PAPointer; out ARows, ACols: integer; out aFloatPrecision: TMtxFloatPrecision); overload; (*Disowns a pointer to an array from calling matrix Values1D. It dismisses the Values, Values1D, CValues1D array and sets the and to zero. *) procedure Disown; overload; (*Sets the matrix diagonal to values from the vector. Sets the k-th diagonal of the calling matrix to values from from the Vec object. If k = 0 then the main diagonal matrix is set, if k < 0 then the k-th subdiagonal matrix is set and if k > 0 the then the k-th super diagonal is set. The matrix must be large enough to hold diagonal or an exception is raised. var A: TMtx; D: TVec; begin CreateIt(A); CreateIt(D); try A.SetIt(2,2,True,[1,1, 2,1, 1,2, 2,2]); D.SetIt(2, True,[2,2, 1,1]); A.Diag(D,0); // A becomes: // [2,2, 2,1] // [1,2, 1,1] finally FreeIt(D); FreeIt(A); end; end; *) function Diag(const Vec: TVec; k: integer): TMtx; overload; (*Calculates matrix eigenvalues and eigenvectors. Calculates the eigenvalues (stored in vector D elements) and optionally the eigenvectors (stored in matrix the columns of matrices VL and VR) of the calling matrix. The MtxType parameter indicates the calling matrix . Depending the type of the calling matrix the Eig method will use specific optimized algorithm. If you don't know the type of the calling matrix, you can not omit the MtxType parameter. To determine the type of matrix use the method, or set property to True. Depending on the MtxType parameter, the following algorithms will be used : 1) for symmetric positive definite matrix (mtSymPosDef, mtHermPosDef): 1. reduce the calling matrix to tridiagonal form A=Q*T*Q'. 2. generate matrix Q. 3. find eigenvalues and eigenvectors of the tridiagonal matrix T. 2) for symmetric or hermitian matrix (mtSymetric, mtHermitian): 1. reduce the calling matrix to tridiagonal form A=Q*T*Q'. 2. generate matrix Q. 3. find eigenvalues and eigenvectors of the tridiagonal matrix T. 3) for general matrix (mtGeneral): * VectorForm = vfEig: 1. perform full balance of the calling matrix, 2. reduce the calling matrix to Hessenberg form A=Q*H*Q', 3. generate matrix Q, 4. find eigenvalues and left and/or right eigenvectors, 5. transform eigenvectors of the balanced matrix back to those of the original matrix. * VectorForm = vfSchur: 1. perform user defined balance of the calling matrix, 2. reduce the calling matrix to Hessenberg form A=Q*H*Q', 3. generate matrix Q, 4. Find the real Schur form and optionally the eigenvectors Z*T*Z'. Matrix T is the real Schur form and Z are the eigenvectors. 5. transform the eigenvectors of the balanced matrix to those of the original matrix. Matrix is in real Schur form, if it is upper quasi-triangular with 1-by-1 and 2-by-2 blocks. 2-by-2 blocks are standardized in the form [ a b ] [ c a ] where b*c < 0. The eigenvalues of such a block are: a +/- sqrt(bc). Note The calling matrix property must be true, otherwise an exception is raised. This overloaded version calculates the calling matrix eigenvalues and stores them in the vector D. The Complex and properties of the vector D are adjusted automatically. The MtxType parameter specifies the calling . If MtxType parameter is omitted, the default value mtGeneral (general matrix) will be used, but for symmetric matrices the matrix type has to be specified explicitly, because the algorithm for general matrices will fail on the symmetric matrix. The matrix Q is not explicitly generated. var D: TVec; A,V: TMtx; begin CreateIt(D); CreateIt(A,V); try A.SetIt(2,2,False,[1,2, 2,4]); // 2x2, real matrix A.Eig(D,mtSymmetric); // or if eigenvectors are also required A.Eig(V,D,nil,mtSymmetric); // get left eigenvectors finally FreeIt(A,V); FreeIt(D); end; end; *) function Eig(const D: TVec; MtxType: TMtxType = mtGeneral): TMtx; overload; (*Calculate the calling matrix eigenvalues and eigenvectors. Store the eigenvalues in the vector D. The Complex and Length properties of the vector D are adjusted automatically. If VectorForm is vfEig, store the left eigenvectors in matrix VL and the right eigenvectors in the matrix VR. Either of the eigenvector matrices VL and VR can be nil to indicate that they are not required. If the are both nil, an exception is raised. In case of symmetric matrices only VL is checked. The computed eigenvectors are normalized to have Euclidean norm equal to 1 and largest component real and are stored in the columns of the VL and VR matrices. If VectorForm is vfSchur, it will store the real T form in the matrix VL and the eigenvectors Z in the matrix VR. VR can be nil, to indicate that eigenvectors are not required. If VL is nil an exception is raised. The Rows, Cols and Complex properties of matrices VR and VL are adjusted automatically. The MtxType parameter specifies the calling . If MtxType parameter is omitted, the default value mtGeneral (general matrix) will be used, but for symmetric matrices the matrix type has to be specified explicitly, because the algorithm for general matrices will fail on the symmetric matrix. *) function Eig(const VL: TMtx; const D: TVec; const VR: TMTx = nil; MtxType: TMTxType = mtGeneral; VectorForm: TVectorForm = vfEig; aExpand: boolean = True): TMtx; overload; (* Computes the eigenvalues and left and right eigenvectors of A general matrix. If VL and VR are not nil, corresponding left and right eigenvectors are computed. Does not work for symmetric matrices. Use EigSym for symmetric matrices. *) procedure Eig(const D: TVec; const VL, VR: TMtx); overload; (* Computes the eigenvalues and left and right eigenvectors of A general matrix. If VL and VR are not nil, corresponding left and right eigenvectors are computed. Additionally balancing can be speicifed with Balance. The info about balancing performed is stored in TEigBalancing object. This object can be nil, if no balancing was requested or additional information about balancing is not needed. If assigned the rconde parameter contains reciprocal condition number of the j-th eigenvalue. These reciprocal condition numbers always lie between zero (very badly conditioned) and one (very well conditioned). If assigned the rcondv contains reciprocal condition number of the j-th right eigenvector. Does not work for symmetric matrices. Use EigSym for symmetric matrices. *) procedure Eig(const D: TVec; const Balance: TBalanceType; BInfo: TEigBalancing = nil; const rconde: TVec = nil; const rcondv: TVec = nil; const VL: TMtx = nil; const VR: TMTx = nil); overload; (*Computes eigenvalues and optionally Schure matrix Computes for an N-by-N nonsymmetric matrix A, the eigenvalues, the Schur form T, and, optionally, the matrix of Schur vectors VS. This gives the Schur factorization A = VS*T*(VS**H). Optionally the routine also orders the eigenvalues on the diagonal of the Schur form so that selected eigenvalues are at the top left. The Select function parameters accepts a function with two parameters. First is the real and the second is the imaginary part of the eigenvalue. The function is to return true, if the specified eigenvalue is to be included in to sorting at the top left of the Schur form. If sorting is not required pass nil (NULL) for this parameter. *) procedure EigSchure(const D: TVec; VS: TMTx = nil; const T: TMtx = nil; dSelect: TSelectTwoFunction = nil; zSelect: TSelectOneFunctionC = nil; sSelect: TSelectTwoFunctionSingle = nil; cSelect: TSelectOneFunctionSingleC = nil); overload; (*Computes eigenvalues and optionally Schure matrix Computes for an N-by-N nonsymmetric matrix A, the eigenvalues, the Schur form T, and, optionally, the matrix of Schur vectors VS. This gives the Schur factorization A = VS*T*(VS**H). Optionally, it also orders the eigenvalues on the diagonal of the Schur form so that selected eigenvalues are at the top left. If this is needed specify the Select function parameter and return true for each eigenvalue desired. Optionally computes a reciprocal condition number for the average of the selected eigenvalues (rconde[0]) and computes a reciprocal condition number for the right invariant subspace corresponding to the selected eigenvalues (rcondv[0]). The leading columns of VS form an orthonormal basis for this invariant subspace. *) procedure EigSchure(const D: TVec; VS: TMTx; const T: TMtx; const rconde, rcondv: TVec; dSelect: TSelectTwoFunction = nil; zSelect: TSelectOneFunctionC = nil; sSelect: TSelectTwoFunctionSingle = nil; cSelect: TSelectOneFunctionSingleC = nil); overload; (*Computes all the eigenvalues, and optionally, the eigenvectors of a generalized symmetric-definite eigenproblem. It can find solution to either of the following problems: A*x = lambda*B*x, A*B*x = lambda*x, or B*A*x = lambda*x Here A and B are assumed to be symmetric (Hermitian) and B is also positive definite. Eigenvector are stored within V in columns. var D: TVec; A,B,C: TMtx; begin CreateIt(D); CreateIt(A,B,C); try D.SetIt(2 ,False,[0,2]); // vector, length 2, real A.SetIt(2,2,False,[1,2, 2,4]); // 2x2, real matrix // A must be symmetric B.SetIt(2,2,False,[1,1, 1,2]); // 2x2, real matrix // B must be symmetric and positive definite A.EigSymGen(B,D); // Use A and B to find eigenvalues finally FreeIt(A,B,C); FreeIt(D); end; end; *) procedure EigSymGen(const B: TMtx; const D: TVec; const V: TMtx; const EigGenType: TEigGenType = etAzBz); overload; procedure EigSymGen(const B: TMtx; const D: TVec; const EigGenType: TEigGenType = etAzBz); overload; (*Computes generalized eigenvalues with reduction of the symmetric-definite generalized eigenvalues/eigenvectors problem to the normal eigenvalue case. The routine computes selected eigenvalues and optionally also eigenvectors. The problem is of type: A*x = lambda*B*x, A*B*x = lambda*x, or B*A*x = lambda*x A and B are symmetric (Hermitian) and B is also positive definite. Eigenvalues and eigenvectors can be selected by specifying a range of values. Eigenvectors are not computed, if V is passed as nil. (NULL). Tolerance parameter specifies the absolute error tolerance for the eigenvalues. An approximate eigenvalue is accepted as converged when it is determined to lie in an interval [a,b] of width less than or equal to Tolerance + EPS / max( |a|,|b| ) , where EPS is the machine precision. If Tolerance is less than or equal to zero, then EPS*|T| will be used in its place, where |T| is the 1-norm of the tridiagonal matrix obtained by reducing A to tridiagonal form. Eigenvalues will be computed most accurately when Tolerance is set to twice the underflow threshold, not zero. If this routine returns fails , indicating that some eigenvectors did not converge, try setting Tolerance to 2*UnderflowThreshold. If V is assinged, VInfo contains values equal to 0 at indices for which eigenvector calculation converged. Eigenvector are stored within V in columns. The returned column count may vary between calls depending on the number of eigenvectors that converged. The eigenvectors are normalized as follows: etAzBz, etBAz, Z**T*B*Z := I; etABz , Z**T*inv(B)*Z := I. . *) procedure EigSymGen(const B: TMtx; const D: TVec; Minimum, Maximum: double; V: TMtx; var VInfo: TIntegerArray; Tolerance: double = 0; const EigGenType: TEigGenType = etAzBz); overload; procedure EigSymGen(const B: TMtx; const D: TVec; const Minimum, Maximum: double; const Tolerance: double = 0; const EigGenType: TEigGenType = etAzBz); overload; (*Computes generalized eigenvalues with reduction of the symmetric-definite generalized eigenvalues/eigenvectors problem to the normal eigenvalue case. The routine computes selected eigenvalues and optionally also eigenvectors. The problem is of type: A*x = lambda*B*x, A*B*x = lambda*x, or B*A*x = lambda*x A and B are symmetric (Hermitian) and B is also positive definite. Eigenvalues and eigenvectors can be selected by specifying a range of indexes of values. Eigenvectors are not computed, if V is passed as nil (NULL). Tolerance parameter specifies the absolute error tolerance for the eigenvalues. An approximate eigenvalue is accepted as converged when it is determined to lie in an interval [a,b] of width less than or equal to Tolerance + EPS / max( |a|,|b| ) , where EPS is the machine precision. If Tolerance is less than or equal to zero, then EPS*|T| will be used in its place, where |T| is the 1-norm of the tridiagonal matrix obtained by reducing A to tridiagonal form. Eigenvalues will be computed most accurately when Tolerance is set to twice the underflow threshold, not zero. If this routine returns fails , indicating that some eigenvectors did not converge, try setting Tolerance to 2*UnderflowThreshold. The first eigenvalue index is 1 and the last index is equal to row/column count. LowerRange and UpperRange need to be specified within this interval: 1 <= LowerRange <= UpperRange <= Rows If V is assinged, VInfo contains values equal to 0 at indices for which eigenvector calculation converged. Eigenvector are stored within V in columns. The returned column count may vary between calls depending on the number of eigenvectors that converged. The eigenvectors are normalized as follows: etAzBz, etBAz, Z**T*B*Z := I; etABz , Z**T*inv(B)*Z := I. *) procedure EigSymGen(const B: TMtx; const D: TVec; LowerRange, UpperRange: integer; V: TMtx; var VInfo: TIntegerArray; Tolerance: double = 0; const EigGenType: TEigGenType = etAzBz); overload; procedure EigSymGen(const B: TMtx; const D: TVec; const LowerRange, UpperRange: integer; const Tolerance: double = 0; const EigGenType: TEigGenType = etAzBz); overload; (*Computes eigenvalues of a symmetric (Hermitian) matrix between minimum and maximum. The computation is based on Relatively Robust Representations. Tolerance parameter specifies the absolute error tolerance for the eigenvalues. An approximate eigenvalue is accepted as converged when it is determined to lie in an interval [a,b] of width less than or equal to Tolerance + EPS / max( |a|,|b| ) , where EPS is the machine precision. If Tolerance is less than or equal to zero, then EPS*|T| will be used in its place, where |T| is the 1-norm of the tridiagonal matrix obtained by reducing A to tridiagonal form. Eigenvalues will be computed most accurately when Tolerance is set to twice the underflow threshold, not zero. If this routine returns fails , indicating that some eigenvectors did not converge, try setting Tolerance to UnderflowThreshold. *) function EigSym(const D: TVec; const Minimum, Maximum: double; const Tolerance: double = 0): TMtx; overload; (*Computes eigenvalues and eigenvectors of a symmetric (Hermitian) matrix between minimum and maximum. The computation is based on Relatively Robust Representations. Tolerance parameter specifies the absolute error tolerance for the eigenvalues. An approximate eigenvalue is accepted as converged when it is determined to lie in an interval [a,b] of width less than or equal to Tolerance + EPS / max( |a|,|b| ) , where EPS is the machine precision. If Tolerance is less than or equal to zero, then EPS*|T| will be used in its place, where |T| is the 1-norm of the tridiagonal matrix obtained by reducing A to tridiagonal form. Eigenvalues will be computed most accurately when Tolerance is set to twice the underflow threshold, not zero. If this routine returns fails , indicating that some eigenvectors did not converge, try setting Tolerance to UnderflowThreshold. *) function EigSym(const D: TVec; V: TMtx; Minimum, Maximum: double; Tolerance: double = 0): TMtx; overload; (*Computes eigenvalues and eigenvectors of a symmetric (Hermitian) matrix between min and max index. The computation is based on Relatively Robust Representations. Tolerance parameter specifies the absolute error tolerance for the eigenvalues. An approximate eigenvalue is accepted as converged when it is determined to lie in an interval [a,b] of width less than or equal to Tolerance + EPS / max( |a|,|b| ) , where EPS is the machine precision. If Tolerance is less than or equal to zero, then EPS*|T| will be used in its place, where |T| is the 1-norm of the tridiagonal matrix obtained by reducing A to tridiagonal form. Eigenvalues will be computed most accurately when Tolerance is set to twice the underflow threshold, not zero. If this routine returns fails , indicating that some eigenvectors did not converge, try setting Tolerance to UnderflowThreshold. The first eigenvalue index is 1 and the last index is equal to row/column count. LowerRange and UpperRange need to be specified within this interval: 1 <= LowerRange <= UpperRange <= Rows *) function EigSymRange(const D: TVec; V: TMtx; LowRange, HighRange: integer; Tolerance: double = 0): TMtx; overload; (*Computes eigenvalues of a symmetric (Hermitian) matrix between min and max index. The computation is based on Relatively Robust Representations. Tolerance parameter specifies the absolute error tolerance for the eigenvalues. An approximate eigenvalue is accepted as converged when it is determined to lie in an interval [a,b] of width less than or equal to Tolerance + EPS / max( |a|,|b| ) , where EPS is the machine precision. If Tolerance is less than or equal to zero, then EPS*|T| will be used in its place, where |T| is the 1-norm of the tridiagonal matrix obtained by reducing A to tridiagonal form. Eigenvalues will be computed most accurately when Tolerance is set to twice the underflow threshold, not zero. If this routine returns fails , indicating that some eigenvectors did not converge, try setting Tolerance to UnderflowThreshold. The first eigenvalue index is 1 and the last index is equal to row/column count. LowerRange and UpperRange need to be specified within this interval: 1 <= LowerRange <= UpperRange <= Rows *) function EigSymRange(const D: TVec; const LowRange, HighRange: integer; const Tolerance: double = 0): TMtx; overload; (*Computes all eigenvalues of a symmetric (Hermitian) matrix between min and max index. The computation is based on Relatively Robust Representations. *) function EigSym(const D: TVec; const V: TMtx): TMtx; overload; (*Computes generalized eigenvalues and eigenvectors of a non-symmetric matrix. A generalized eigenvalue for a pair of matrices (A = Self,B) is a scalar lambda or a ratio alpha/beta := lambda, such that A - lambda*B is singular. It is usually represented as the pair (alpha,beta), as there is a reasonable interpretation for beta = 0, and even for both being zero. The right eigenvector v(j) corresponding to the eigenvalue lambda(j) of (A,B) satisfies: A * v(j) = lambda(j) * B * v(j). The left eigenvector u(j) corresponding to the eigenvalue lambda(j) of (A,B) satisfies: u(j)**H * A = lambda(j) * u(j)**H * B . where u(j)**H is the conjugate-transpose of u(j). The individual eigevalues can be computed as: lambda(j) = dAlpha(j)/dBeta(j); *) procedure EigGen(const B: TMtx; const DAlpha, DBeta: TVec; const VL, VR: TMtx); overload; procedure EigGen(const B: TMtx; const DAlpha, DBeta: TVec); overload; (*Computes generalized eigenvalues and eigenvectors of a non-symmetric matrix. Computes for a pair of N-by-N real nonsymmetric matrices (A = Self,B) the generalized eigenvalues, and optionally, the left and/or right generalized eigenvectors (VL and/or VR). A generalized eigenvalue for a pair of matrices (A,B) is a scalar lambda or a ratio alpha/beta := lambda, such that A - lambda*B is singular. It is usually represented as the pair (alpha,beta), as there is a reasonable interpretation for beta = 0, and even for both being zero. The right eigenvector v(j) corresponding to the eigenvalue lambda(j) of (A,B) satisfies: A * v(j) = lambda[j] * B * v(j) The left eigenvector u(j) corresponding to the eigenvalue lambda(j) of (A,B) satisfies: u(j)**H * A = lambda[j] * u(j)**H * B where u(j)**H is the conjugate-transpose of u(j). The individual eigevalues can be computed as: lambda[j] := dAlpha[j]/dBeta[j]; Optionally also computes a balancing transformation to improve the conditioning of the eigenvalues and eigenvectors , reciprocal condition numbers for the eigenvalues (rconde), and reciprocal condition numbers for the right eigenvectors (rcondv). *) procedure EigGen(const B: TMtx; const DAlpha, DBeta: TVec; const Balance: TBalanceType; BInfo: TEigBalancing; const rconde: TVec = nil; const rcondv: TVec = nil; const VL: TMtx = nil; const VR: TMTx = nil); overload; (*Computes generalized eigenvalues and Schur vectors of a non-symmetric matrix. It gives Schur factorization (A = Self) : (A,B) = ( VL*S*VR^T, VL*T*VR^T ) If only the generalized eigenvalues are needded then EigGen is faster. The individual eigevalues can be computed as: lambda(j) = dAlpha(j)/dBeta(j); If any of the VL, VR, S, T, rconde, rcondv are not required, pass nil value for the pointer. Optionally the routine also orders the eigenvalues on the diagonal of the Schur form so that selected eigenvalues are at the top left. The Select function parameters accepts a function with four parameters. In case of real data, the first is the real and the second is the imaginary part of the eigenvalue (alpha), the third is the real beta. In case of complex data, first two are complex dAlpha and the second two complex dBeta. The function is to return true, if the specified eigenvalue is to be included in to sorting at the top left of the Schur form. If sorting is not required pass nil (NULL) for this parameter. Optionally computes a reciprocal condition number for the average of the selected eigenvalues (rconde[0], rconde[1]) and computes a reciprocal condition number for the selected deflating subspaces (rcondv[0], rcondv[1]). If condition numbers are not required, pass nil (NULL) for this parameter. *) procedure EigSchureGen(const B: TMtx; const DAlpha, DBeta: TVec; const VL, VR, S, T: TMtx; rconde, rcondv: TVec; dSelect: TSelectThreeFunction = nil; zSelect: TSelectTwoFunctionC = nil; sSelect: TSelectThreeFunctionSingle = nil; cSelect: TSelectTwoFunctionSingleC = nil); overload; procedure EigSchureGen(const B: TMtx; const DAlpha, DBeta: TVec; dSelect: TSelectThreeFunction = nil; zSelect: TSelectTwoFunctionC = nil; sSelect: TSelectThreeFunctionSingle = nil; cSelect: TSelectTwoFunctionSingleC = nil); overload; (* Computes generalized singular value decomposition. Computes the generalized singular value decomposition (GSVD) of an M-by-N real matrix A and P-by-N real matrix B: U'*A*Q = D1*( 0 R ), V'*B*Q = D2*( 0 R ) where U, V and Q are orthogonal matrices, and Z' is the transpose of Z. The routine computes optionally the orthogonal transformation matrices U, V and Q. D1 and D2 are diagonal matrices, which on their diagonals contain C and S. K L D1 = K [ I 0 ] L [ 0 C ] M-K-L [ 0 0 ] K L D2 = L [ 0 S ] P-L [ 0 0 ] The generalized singular values, stored in C and S on exit, have the property: sqr(C) + sqr(S) = I The generalized singular value pairs of A and B in case of rank deficiency are stored like this: c(0:k-1) = 1, s(0:k-1) = 0, and if m-k-l = 0, c(k:k+l-1) = C, s(k:k+l-1) = S, or if m-k-l < 0, c(k:m-1)= C, c(m:k+l-1)=0 s(k:m-1) = S, s(m:k+l-1) = 1 and c(k+l:n-1) = 0 s(k+l:n-1) = 0 Effective rank is k + l. If B is an N-by-N nonsingular matrix, then the GSVD of A and B implicitly gives the SVD of A*inv(B): A*inv(B] := U*(D1*inv(D2))*V' If ( A',B')' has orthonormal columns, then the GSVD of A and B is also equal to the CS decomposition of A and B. Furthermore, the GSVD can be used to derive the solution of the eigenvalue problem: A'*A x := lambda* B'*B x In some literature, the GSVD of A and B is presented in the form U'*A*X := ( 0 D1 ), V'*B*X := ( 0 D2 ) where U and V are orthogonal and X is nonsingular, D1 and D2 are "diagonal". The former GSVD form can be converted to the latter form by taking the nonsingular matrix X as: X = Q*( I 0 ) ( 0 inv(R) ) The function returns the effective numerical rank of (A', B') = K + L. Reference: Lapack v3.4 source code *) function SVDGen(const B: TMtx; const C, S: TVec; U: TMtx; V: TMtx; Q: TMtx): integer; overload; function SVDGen(const B: TMtx; const C, S: TVec): integer; overload; (* Solves the linear equality-constrained least squares (LSE). Solves the linear equality-constrained least squares (LSE) problem: minimize || c - A*x ||_2 subject to B*x = d where A is an M-by-N matrix, B is a P-by-N matrix, c is a given vector of length M, and d is a given vector of length P. The sign "_2", denotes Norm L2. It is assumed that P <= N <= M+P, and rank(B) = P and rank( (A) ) = N ( (B) ) These conditions ensure that the LSE problem has a unique solution, which is obtained using a generalized RQ factorization of the matrices (B, A) given by B = (0 R)*Q, A = Z*T*Q The function returns the residual sum of squares for the solution References: 1.) Lapack v3.4 source code 2.) http://isites.harvard.edu/fs/docs/icb.topic774900.files/lec16.09.pdf 3.) http://www.cs.ucdavis.edu/~bai/publications/andersonbaidongarra92.pdf *) function LSESolve(const B: TMtx; const C, D, X: TVec): double; overload; (* Solves a general Gauss-Markov linear model (GLM) problem. The routine solves a general Gauss-Markov linear model (GLM) problem: minimize || y ||_2 subject to d = A*x + B*y x where A is an N-by-M matrix, B is an N-by-P matrix, and d is a given N-vector. It is assumed that M <= N <= M+P, and rank(A) = M and rank( A B ) = N. Under these assumptions, the constrained equation is always consistent, and there is a unique solution x and a minimal 2-norm solution y, which is obtained using a generalized QR factorization of the matrices (A, B) given by A = Q*(R), B = Q*T*Z (0) In particular, if matrix B is square nonsingular, then the problem GLM is equivalent to the following weighted linear least squares problem minimize || inv(B)*(d-A*x) ||_2 x where inv(B) denotes the inverse of B. The sign _2, denotes Norm L2. References: 1.) Lapack v3.4 source code *) procedure GLMSolve(const B: TMtx; const D, X, Y: TVec); overload; (*Compares two matrices. Compares Mtx with the calling matrix and returns true if the matrices are equal (if all elements match in position and value). Tolerance defines the comparison tolerance. The maximum difference between elements may not exceed: +/-Tolerance. If Tolerance is omitted, a direct comparison algorithm is used. var A,B: TMtx; c: boolean; begin CreateIt(A,B); try A.SetIt(2,2,false,[1,2, 2,4]); // 2x2, real matrix B.SetIt(2,2,false,[1,2, 2,4]); // 2x2, real matrix c := A.Equal(B,1e-8); // Check for differences bigger than 0.00000001 c := A.Equal(B); // Check for an exact match finally FreeIt(A,B); end; end; *) function Equal(const Mtx: TMtx; Tolerance: double = 0): boolean; overload; (*Allows to specify the comparison method via the Compare parameter.*) function Equal(const Mtx: TMtx; Tolerance: double; Compare: TCompare):boolean; overload; (*Constructs an eye matrix. Construct an eye matrix. The number of rows and columns of an eye matrix is set by ARows and ACols parameters. The Complex property of an eye matrix is set by AComplex parameter. var A,B: TMtx; begin CreateIt(A); try A.Eye(3,3); // ... finally FreeIt(A); end; end; *) function Eye(ARows,ACols: integer; AComplex: boolean; aIsDouble: boolean): TMtx; overload; function Eye(ARows,ACols: integer; aFloatPrecision: TMtxFloatPrecision): TMtx; overload; function Eye(ARows,ACols: integer; aFloatPrecisionRef: TMtxVec): TMtx; overload; (*Forward parallel in-place 1D FFT. Performs forward 1D FFT on each row of the matrix. See for more info on the forward FFT. *) function FFT1D: TMtx; overload; (*Forward parallel not in-place 1D FFT. The size of the destination is set automatically *) function FFT1D(const Mtx: TMtx): TMtx; overload; (*Forward parallel in-place 1D FFT from real to complex. Performs forward 1D FFT from real to complex on each row of the matrix. See for more info on the forward real FFT. *) function FFT1DFromReal: TMtx; overload; (*Forward parallel not in-place 1D real to complex FFT. The size of the destination is set automatically. *) function FFT1DFromReal(const Mtx: TMtx): TMtx; overload; (*Forward two-dimensional Fast Fourier Transformation from real/complex to complex. The transformation is applied in-place. The source matrix may be real or complex. The result will be always complex. The size of the calling matrix is not changed. (rows and cols will not chage). var a: TMtx; begin CreateIt(a); try a.SetIt(2,4,False, [1, 2, 3, 4, -5, 6,-7, 8]); a.FFT2D; // result will be [(12,0), ( 0,4), (-28,0), (0,-4), ( 8,0), (-4,0), ( 24,0), (-4,0)] finally FreeIt(a); end; end; *) function FFT2D: TMtx; overload; (*Forward two-dimentional Fast Fourier Transformation from real/complex to complex. The transformation is applied on data in Mtx matrix and results are saved in the calling matrix. The source matrix may be real or complex. The source matrix is not changed. The calling matrix will be complex and will be of the same size as the source matrix. (rows and cols will not chage). var a,b: TMtx; begin CreateIt(a,b); try a.SetIt(2,4,False, [1, 2, 3, 4, -5, 6,-7, 8]); b.FFT2D(a); // result will be [(12,0), ( 0,4), (-28,0), (0,-4), ( 8,0), (-4,0), ( 24,0), (-4,0)] finally FreeIt(a,b); end; end; *) function FFT2D(const Mtx: TMtx): TMtx; overload; (*Forward two-dimentional Fast Fourier Transformation for real numbers. The transformation is applied in-place. The source matrix must be real. An exception will be raised, if the source matrix is complex. The calling matrix stays real and does not change it's size, if was set to fsfPack or to fsfPerm. If the property was set to fsfCCS then the calling matrix becomes complex and is resized up to [Rows, Cols div 2], i.e. matrix changes Complex property, but does not reallocate storage for elements. The number of element which are involved in the transformation depends on the property . If that property is set to fsfPerm or to fsfPack, then all elements are involved into the trasformation. If that property is set to fsfCCS (which is default), then number of element which are involved into the transformation depends on the property and these rules will be followed: * Number of source columns must be even and more then two. Number of source rows must be more than two. Exception will be raised otherwise; * if is set to False, elements from range [0..Cols-2] x [0..Rows-2] will be involved into transformation; * if is set to True, elements from range [0..Cols-1] x [0..Rows-2] will be involved into transformation; Note Not all source elements are involved into transformation but all elements in the result matrix are needed for the inverse transformation. var a: TMtx; begin CreateIt(a); try a.SetIt (4,4,False, [1, 2, 3, 4, -5, 6, -7, 8, 9, 12,-11, 10, 16,-15,-14, 0]); a.FFTStorageFormat := fsfCCS; a.FFTOddLength := False; // the next elements are involved into transformation [1, 2, -5, 6] a.FFT2DFromReal; // result will be // [(4,0), (-12,0), // (0,0), (0,0), // (2,12), (10,10), // (0,-15), (0,0)] // after inverse transformation (a.IFFT2DToReal) only elements in range // [0..Col-2] x [0..Rows-2] will be reconstructed, other elements will be undefined // [1, 2, undef, undef, // -5, 6, undef, undef, // undef, undef, undef, undef, // undef, undef, undef, undef] // // if a.FFTOddLength is set to true, // then the range of reconstruction would be [0..Col-1] x [0..Rows-2]. finally FreeIt(a); end; end; *) function FFT2DFromReal: TMtx; overload; (*Forward two-dimentional Fast Fourier Transformation from real to complex. The transformation is applied on the Mtx matrix and results are saved in the calling matrix. The Mtx matrix must be real. And exception will be raised if the source matrix is complex. The source matrix will not be changed. The calling matrix will be real and will be resized up to [Mtx.Rows,Mtx.Cols], if is set to fsfPack or to fsfPack. If is set to fsfCCS, calling matrix will be complex and will be resized up to [Mtx.Rows, Mtx.Cols div 2]. The number of element which are involved in transformation depends on the property . If that property is set to fsfPerm or to fsfPack, then all the source elements are involved into the trasformation. If that property is set to fsfCCS (which is default), then the number of elements which are involved into the transformation depends on the property and these rules will be followed: * Number of source columns must be even and more then two. Number of source rows must be more than two. Exception will be raised otherwise; * if is set to False, elements from range [0..Mtx.Cols-2] x [0..Mtx.Rows-2] will be involved into transformation; * if is set to True, elements from range [0..Mtx.Cols-1] x [0..Mtx.Rows-2] will be involved into transformation; NOTE Not all source elements are involved into transformation but all elements in the result matrix are needed for the inverse transformation. *) function FFT2DFromReal(const Mtx: TMtx): TMtx; overload; (*Flips the matrix elements horizontally. Flip calling matrix elements horizontally - element [row, j] = element [row, Cols-j]. This operation is performed on all calling matrix rows. var A,B: TMtx; begin CreateIt(A,B); try A.SetIt(2,2,False,[1,2, 2,4]); // 2x2, not complex matrix B.FlipHor(A); // B becomes: // [2,1] // [4,2] finally FreeIt(A,B); end; end; *) function FlipHor: TMtx; overload; (*Flip all SrcMtx matrix elements horizontally. Store the results in the calling matrix. The flip operation is performed on all SrcMtx matrix rows. The , and Complex properties of callign matrix are adjusted automatically. *) function FlipHor(const SrcMtx: TMtx): TMtx; overload; (*Flips the matrix elements vertically Flip calling matrix elements vertically - element [j, col] = element [Rows-j, col]. This operation is performed on all calling matrix columns. var A,B: TMtx; begin CreateIt(A,B); try A.SetIt(2,2,False,[1,2, 2,4]); // 2x2, not complex matrix B.FlipVert(A); // B becomes: // [2,4] // [1,2] finally FreeIt(A,B); end; end; *) function FlipVer: TMtx; overload; (*Flip all SrcMtx matrix elements vertically. Store the results in the calling matrix. The flip operation is performed on all SrcMtx matrix columns. The , and Complex properties of callign matrix are adjusted automatically. *) function FlipVer(const SrcMtx: TMtx): TMtx; overload; (*Constructs a Hankel matrix. Constructs a Hankel matrix whose first column is FirstColumn and whose elements are zero below the first anti-diagonal. The , and Complex properties of the calling matrix are adjusted automatically. var v: TVec; H: TMtx; begin CreateIt(v); CreateIt(H); try v.SetIt(False,[1,2,3,4]); H.Hankel(v); // H becomes: //[1 2 3 4] //[2 3 4 0] //[3 4 0 0] //[4 0 0 0] finally FreeIt(H); FreeIt(v); end; end; *) function Hankel(const FirstColumn: TVec): TMtx; overload; (* Applies 2D filtering Computes the dot-product between the kernel matrix and underlaying source matrix elements for each possible position of the kernel and stores the result in to the calling object. Typically the kernel is much smaller than the source matrix. The operation is equivalent to the 2D Convolution and is used also for image resampling, image blurring etc.. SrcRect must meet the following condtitions: SrcRect.Width <= (Src.Cols - Kernel.Cols) SrcRect.Height <= (Src.Rows - Kernel.Rows) KernelAnchor defines the value to be written in the destination matrix relative to the corresponding position of the Kernel in the Src matrix. This can be for example center element (Kernel.Rows div 2, Kernel.Cols div 2), top left (0,0), bottom right (Kernel.Rows-1, Kernel.Cols-1) element etc... The X and Y coordinates may not exceed Kernel row or column count. The kernel can be square or not. Symmetric or not. The only requirement is that it is rectangular. It is the users responsability to select such combination of SrcRect, Kernel size and KernelAnchor to get desired border value processing. If the Kernel is 3x3 in size, then it would make sense that SrcRect leaves out 2 rows above and below and also 2 columns left and right in the Src matrix. These regions then need to be initialized to some value for example 0 for black color or use the value of the closest border element. The DstRect defines the area to be overwritten in the destination matrix. The width and height parameters of DstRect and SrcRect need to match. The Size of the destination matrix needs to be big enough to allow DstRect position and dimensions. var H, A, B: TMtx; i: integer; SrcRect, DstRect: TRect; KernelAnchor: TPoint; begin CreateIt(H,A,B); H.SetIt(3,3,false,[1, 1, 1, 1, 1, 1, 1, 1, 1]; // simple average kernel A.SetIt(9,9,false, [0, 0, 0, 0, 0, 0, 0, 0, 0, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 2, 2, 2, 2, 2, 0, 0, 0, 0, 3, 3, 3, 3, 3, 0, 0, 0, 0, 4, 4, 4, 4, 4, 0, 0, 0, 0, 5, 5, 5, 5, 5, 0, 0, 0, 0, 6, 6, 6, 6, 6, 0, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5]; SrcRect := TRect.Create(3,2, A.Cols-1, A.Rows-1 ); DstRect := TRect.Create(0,0, SrcRect.Width, SrcRect.Height); KernelAnchor := TPoint.Create(H.Rows div 2, H.Cols div 2); //center element B.Size(DstRect.Height, DstRect.Width); //could be bigger also B.Filter2D( A, H, SrcRect, DstRect, KernelAnchor); // B = [[ 7.5, 10.5, 10.5, 10.5, 7.5], //top left element at index A[2,3] // [ 12 , 18 , 18 , 18 , 12 ], // [ 18 , 27 , 27 , 27 , 18 ], // [ 24 , 36 , 36 , 36 , 24 ], // [ 30 , 45 , 45 , 45 , 30 ], // [ 23.5, 34.5, 34.5, 34.5, 23.5]] FreeIt(H,A,B); end; *) function Filter2D(const Src, Kernel: TMtx; const SrcRect, DstRect: TMtxRect; const KernelAnchor: TMtxPoint; const Buffer: TVecInt = nil): TMtx; overload; (*Applies 2D filtering. The result is stored in to the calling object. The size of the calling object is set to match SrcRect dimensions. Important: The allocated size of the destination will never be overwritten, but the value of samples on the edge of the Dst matrix could be computed from elements outside of the Src thus making them appear to be random, because uninitialized memory was being referenced, if the parameters are not set carefully. *) function Filter2D(const Src, Kernel: TMtx; const SrcRect: TMtxRect; const KernelAnchor: TMtxPoint; const Buffer: TVecInt = nil): TMtx; overload; (*Applies 2D filtering. The function will assume that Src has a border which is (Kernel.Cols div 2+1) wide on left and right and border which is (Kernel.Rows div 2 + 1) high on top and bottom. Kernel will be applied with its center element as the anchor. The filtered result will be stored in to the calling object without the extra borders. The size of the calling object is set automatically. It is the users responsability to initialize the border elements in the Src. *) function Filter2D(const Src, Kernel: TMtx; const Buffer: TVecInt = nil): TMtx; overload; (*Inverse parallel in-place 1D FFT. Performs inverse 1D FFT on each row of the matrix. See for more info on the inverse FFT. NoScale parameter allows the scaling to be turned off. The scaling scales the result by 1/(Length_Of_FFT). *) function IFFT1D(NoScale: boolean = False): TMtx; overload; (*Inverse parallel not in-place 1D FFT. The size of the destination is set automatically. *) function IFFT1D(const Mtx: TMtx; NoScale: boolean = False): TMtx; overload; (*Inverse parallel in-place 1D FFT from complex to real. Performs inverse 1D FFT from complex to real on each row of the matrix. See for more info on the inverse complex to real 1D FFT. NoScale parameter allows the scaling to be turned off. The scaling scales the result by 1/(Length_Of_FFT) *) function IFFT1DToReal(NoScale: boolean = False): TMtx; overload; (*Inverse parallel not in-place 1D complex to real FFT. The size of the destination is set automatically. *) function IFFT1DToReal(const Mtx: TMtx; NoScale: boolean = False): TMtx; overload; (*Inverse two-dimensional Fast Fourier Transformation from complex to complex. Transformation is applied in-place. Source matrix must be complex. If source matrix is real, an exception will be raised. result matrix will be complex. Size of the calling matrix is not changed. NoScale parameter allows the scaling to be turned off. var a: TMtx; begin CreateIt(a); try a.SetIt (2,4,False, [1, 2, 3, 4, -5, 6,-7, 8] ); a.ExtendToComplex; a.IFFT2D; // result will be [(1.5, 0), (0, -0.5), (-3.5, 0), (0, 0.5), (1, 0), (-0.5, 0), (3, 0), (-0.5, 0) ] finally FreeIt(a); end; end; *) function IFFT2D(NoScale: boolean = False): TMtx; overload; (*Inverse two-dimentional Fast Fourier Transformation from complex to complex. Transformation is applied on Mtx matrix and results are saved in the calling matrix. The source matrix must be complex. If source matrix is real, an exception will be raised. The source matrix is not changed. Calling matrix will be complex and will have the same size as the source matrix. NoScale parameter allows the scaling to be turned off. var a,b: TMtx; begin CreateIt(a,b); try a.SetIt (2,4,False, [1, 2, 3, 4, -5, 6,-7, 8] ); a.ExtendToComplex; b.IFFT2D(a); // result will be [(1.5, 0), (0, -0.5), (-3.5, 0), (0, 0.5), (1, 0), (-0.5, 0), (3, 0), (-0.5, 0) ] finally FreeIt(a,b); end; end; *) function IFFT2D(const Mtx: TMtx; NoScale: boolean = False): TMtx; overload; (*Inverse two-dimentional Fast Fourier Transformation from complex to real. Transformation is applied in-place. Source matrix Complex property must be false, if was set to fsfPack or to fsfPack. Source matrix Complex property must be True, if was set to fsfCCS. The calling matrix becomes real. Size of the calling matrix is not changed if was set to fsfPack or to fsfPack. Size of calling matrix will be set to [Rows, 2*Cols], if is set to fsfCCS, i.e. matrix changes Complex property, but does not reallocate storage for elements. All elements are involved into inverse transformation, but number of reconstructed elements depends on the property . If that property is set to fsfPerm or to fsfPack, then all elements will be reconstructed after inverse transformation. If that property is set to fsfCCS (which is default), then the number of element's which will be reconstructed depends on the property and these rules will be followed: * Number of source columns and rows must be more than one. Exception will be raised otherwise; * if is set to False, elements in range [0..Cols-2] x [0..Rows-2] will be reconstructed; * if is set to True, elements in range [0..Cols-1] x [0..Rows-2] will be reconstructed; * Here Cols and Rows are the number of columns and rows of the calling matrix after the inverse transformation. Note Both properties and must be set to the same values for forward and inverse transformation to get reversible results. NoScale parameter allows the scaling to be turned off. var a: TMtx; begin CreateIt(a); try a.SetIt (4,4,False, [1, 2, 3, 4, -5, 6, -7, 8, 9, 12,-11, 10, 16,-15,-14, 0]); a.FFTStorageFormat := fsfCCS; a.FFTOddLength := TRUE; // the next elements are involved into transformation [1, 2, 3, -5, 6, -7] a.FFT2DFromReal; // result will be // [(0,0), (-6, -10.39), // (0,0), (3, 12.12), // (12,12), (-11,10), // (0,-15), (-14,0)] a.IFFT2DToReal; // [ 1, 2, 3, 0 // -5, 6, -7, 0 // 12, 12,-11, 10 // 0,-15,-14, 0] // the next elements are reconstructed // [ 1, 2, 3, undef, // -5, 6, -7, undef, // undef, undef, undef, undef, // undef, undef, undef, undef] // // if a.FFTOddLength is set to False, // then range of reconstruction would be one column less, i.e. // [ 1, 2, undef, undef, // -5, 6, undef, undef, // undef, undef, undef, undef, // undef, undef, undef, undef] finally FreeIt(a); end; end; *) function IFFT2DToReal(NoScale: boolean = False): TMtx; overload; (*Inverse two-dimensional Fast Fourier Transformation from complex to real. Transformation is applied on source Mtx matrix and results are saved in the calling matrix. Source matrix must be real, if was set to fsfPack or to fsfPack. Check the storage format requirements to see how the complex numbers are to be stored in a real matrix. Source matrix must be complex, if was set to fsfCCS. The source matrix will not be changed. The calling matrix becomes real. Size of the calling matrix will be set to [Mtx.Rows,Mtx.Cols], if was set to fsfPack or to fsfPack. Size of calling matrix will be set to [Mtx.Rows, 2*Mtx.Cols], if is set to fsfCCS. All element are involved into the inverse transformation, but the number of reconstructed elements depends on the property . If that property is set to fsfPerm or to fsfPack, then all elements will be reconstructed after inverse transformation. If that property is set to fsfCCS (which is default), then the number of elements which will be reconstructed depends on the property and these rules will be followed: * Number of source columns and rows must be more than one. An exception will be raised otherwise; * if is set to False, elements in range [0..Cols-2] x [0..Rows-2] will be reconstructed; * if is set to True, elements in range [0..Cols-1] x [0..Rows-2] will be reconstructed; Here Cols and Rows are the number of columns and rows of the calling matrix after the inverse transformation. Note Both properties and must be set to the same values for forward and inverse transformation to get reversible results. NoScale parameter allows the scaling to be turned off. *) function IFFT2DToReal(const Mtx: TMtx; NoScale: boolean = False): TMtx; overload; (*Calculates matrix inverse (Mtx^-1). Calculate the inverse (Mtx^-1) of the calling matrix. If the calling matrix is not , an exception is raised. Parameter determines which optimized method will be used for calculating the inverse matrix. If MtxType is omitted, the default value mtGeneral (general quadratic matrix) is used. Note The MtxType parameter is not verified. To determine if the calling matrix type is actually MtxType, use the method. var A: TMtx; begin CreateIt(A); try A.SetIt(2,2,False,[1,2, 2,4]); // 2x2, real matrix A.Inv; finally FreeIt(A); end; end; *) function Inv(): TMtx; reintroduce; overload; (*Compute inverse of the matrix. Specify the matrix type to select the most performance efficient algorithm. *) function Inv(MtxType: TMtxType): TMtx; overload; (*The inverse of matrix elements. Calculates the inverse of all matrix elements in place. The computation occurs after first limiting the magnitude of each elements by the lower bound of Treshhold. The limiting operation is performed to avoid division by zero. Since Treshold represents a magnitude, it is always real and must always be positive. For complex versions, the magnitude of the input is limited, but the phase remains unchanged. Zero-valued input is assumed to have zero phase. To bypass the limiting operation set the Threshold to zero. var A: TMtx; begin CreateIt(A); try A.SetIt(2,2,False,[1,2, 2,4]); // 2x2, not complex matrix A.InvElem(1.0e-7); finally FreeIt(A); end; end; *) function InvElem(): TMtx; overload; (*Invert all Mtx elements and store them in the calling matrix.*) function InvElem(Threshold: double): TMtx; overload; (*Convert all Mtx elements Xtore them in the calling matrix. The , and Complex properties of the calling matrix are set implicitly to match Mtx matrix. If Treshold is omitted then the default value 1/MAXNUM is used. *) function InvElem(const SrcMtx: TMtx; const Threshold: double = 1/MAXNUM): TMtx; overload; (*Construct the Kac (Clement) matrix. Constructs the so called Kac (Clement) (n+1)x(n+1) tridiagonal matrix, defined by: | 0, n, 0, ... , 0 | | 1, 0, n-1, 0, ..., 0 | | 0, 2, 0, n-2, 0, ... | | ...........n-1, 0, 1 | | 0, ... ........, n, 0| The eigenvalues of so defined matrix are 2k-n for k=0,1,2,...,n. *) function Kac(n: Integer): TMtx; (*The Kronecker product between two vectors. Calculates the Kronecker product between Vec1 and Vec2 and stores the result in the calling matrix. The , and Complex properties of calling matrix are set automatically. var A: TMtx; V1,V2: TVec; begin CreateIt(A); CreateIt(V1,V2); try V1.SetIt(False,[1,2,3]); V2.SetIt(False,[4,5,6]); A.Kron(V1,V2); // A becomes: // [4 5 6] // [8 10 12] // [12 15 18] finally FreeIt(A); FreeIt(V1,V2); end; end; *) function Kron(const Vec1, Vec2: TVec): TMtx; overload; (*The Kronecker product between two matrices. Calculates the Kronecker product between SrcMtx1 and SrcMtx2 and stores the result in the calling matrix. The , and Complex properties of calling matrix are set automatically. *) function Kron(const SrcMtx1, SrcMtx2: TMtx): TMtx; overload; function LMinQR(const L: TMtx; Q: TMtx; const R: TMtx): TMtx; overload; (*Constructs lower triangular matrix. The method uses Mtx matrix to construct a lower triangular matrix. The results are stored in the calling matrix. If the ZeroLower parameter is true then the calling matrix superdiagonal elements will be set to zero - otherwise the superdiagonal elements will not be initialized. If the Diagonal boolean parameter is true then the Mtx matrix main diagonal elements will be copied to the calling matrix main diagonal elements. If the Diagonal parameter is false, the calling matrix main diagonal elements will be set to zero. var A,B: TMtx; begin CreateIt(A,B); try A.SetIt(2,1,True,[1,2, 2,4]); // 2x2, not complex matrix B.LowerTriangle(A,True,True); // B becomes: // [1,0, // [2,4] finally FreeIt(A,B); end; end; *) function LowerTriangle(const Mtx: TMtx; ZeroUpper, Diagonal: boolean): TMtx; overload; (*QR or LQ factorization. Performs QR or LQ factorization. If is bigger or equal than for the calling matrix, the linear system of equations is overdetermined and the method performs QR factorization. The matrix L is not used and can be nil. If Rows is smaller than Cols, the linear system equations is underdetermined and the method performs LQ factorization. The matrix R is not used and can be nil. If the Matrix Q is nil, then it's not explicitly formed. If the pointer is not nil, the full size Q is computed. If you do not want economy size L, Q and R, set MinSize to false. The calling matrix must have full rank. If the rank is not full, use the method. If the Minimized parameter is false, the following holds true: A = Q*R A = L*Q var L,Q,R,A: TMtx; begin CreateIt(Q,R,A); try A.SetIt(3,2,False,[1,2, 3,4, 3,3]); A.LQR(nil,Q,R,false); finally FreeIt(Q,R,A); end; end; *) function LQR(const L, Q, R: TMtx; Minimized: boolean = true): TMtx; overload; (*QR or LQ factorization. Performs QR factorization with optional pivoting or LQ factorization. The pivoting of columns in the calling matrix is performed only when P is not nil and Rows > Cols. The P[i] holds the permutation of columns in A, so that: P(A) = Q*R *) function LQR(const L: TMtx; Q: TMtx; const R: TMtx; const P: TVecInt; Minimized: boolean = true): TMtx; overload; (*Solve overdetermined or underdetermined system of real linear equations. Solve overdetermined or underdetermined real linear systems involving a Rows-by-Cols matrix or its transpose, using a QR or LQ factorization of the calling matrix. It is assumed that the calling matrix has full rank. The following options are provided: 1.If Op = opNone and m >= n: find the least squares solution of an overdetermined system, i.e., solve the least squares problem minimize || B - A*X ||. 2.If Op = opNone and m < n: find the minimum norm solution of an underdetermined system A * X = B. 3.If Op = opTrans and m >= n: find the minimum norm solution of an undetermined system A**T * X = B. 4.If Op = opTran and m < n: find the least squares solution of an overdetermined system, i.e., solve the least squares problem minimize || B - A**T * X || 5.If Op = opHerm and m >= n: find the minimum norm solution of an undetermined system A**H * X = B. 6.If Op = opHerm and m < n: find the least squares solution of an overdetermined system, i.e., solve the least squares problem minimize || B - A**H * X ||. Note If the parameters are of TVec type (vectors), the routine requires less pre and post processing. *) function LQRSolve(const B, X: TMtx; const R: TMtx = nil; Op: TMtxOperation = opNone): TMtx; overload; (*Matrix version of LQRSolve. Perfroms a LQRSolve for each B and X matrices columns in single pass.*) function LQRSolve(const B, X: TVec; const R: TMtx = nil;Op: TMtxOperation = opNone): TMtx; overload; (*Rank deficient version of LQRSolve. Perfroms LQRSolve for B vector. Computes the minimum-norm solution to a linear least squares problem: minimize || A * X - B || using a complete orthogonal factorization of A. A is an M-by-N matrix which may be rank-deficient. The function returns the effective rank of the matrix A. The effective rank is determined with the rcond parameter. A is factorized in such a way that condition number of leading submatrix of A will be less then 1/rcond. Set value of rcond to 1E-6 for less strict and to 1E-3 for more strict stability conditition. If R is assigned, the function returns the factorization of matrix A. Op parameter specified the operation to be applied to A before the computation. *) function LQRSolve(const B, X: TVec; rcond: double; const R: TMtx = nil; Op: TMtxOperation = opNone): integer; overload; (*Rank deficient version of LQRSolve. Perfroms LQRSolve for each B column in one pass. Computes the minimum-norm solution to a linear least squares problem: minimize || A * X - B || using a complete orthogonal factorization of A. A is an M-by-N matrix which may be rank-deficient. The function returns the effective rank of the matrix A. The effective rank is determined with the rcond parameter. A is factorized in such a way that condition number of leading submatrix of A will be less then 1/rcond. Set value of rcond to 1E-6 for less strict and to 1E-3 for more strict stability conditition. If R is assigned, the function returns the factorization of matrix A. Op parameter specified the operation to be applied to A before the computation. *) function LQRSolve(const B, X: TMtx; rcond: double; const R: TMtx = nil; Op: TMtxOperation = opNone): integer; overload; (*LU, Cholesky or Bunch-Kaufmann factorization. Performs a general LU, Cholesky or Bunch-Kaufmann factorization on the calling matrix and stores the results in lower triangular matrix L and upper triangular matrix U. The MtxType parameter defines which optimized method will be used to calculate the LU factorization. Depending on the type of the calling matrix the LU method will use specific optimized algorithm to perform the factorization. If you don't know the of the calling matrix, you can omit the MtxType parameter (the default value mtGeneral will be used) or determine the type of matrix with the method. The following methods can be used to calculate the LU factorization: * Matrix type is mtSymmPosDef, mtHermPosDef, mtBandSymmPosDef, mtBandHermPosDef : Cholesky factorization. * mtSymmetric : Bunch-Kaufmann factorization. * mtHermitian : Bunch-Kaufmann factorization (only for complex calling matrix). * mtTriangle : or method. * mtGeneral, mtBandGeneral : general m x n matrix LU factorization. Note An exception will be raised if the calling matrix property is not true and matrix storage format is not banded. var LU,A: TMtx; P: TVecInt; begin CreateIt(LU,A); CreateIt(P); try A.SetIt(3,2,False,[1,2, 3,4]); A.LU(LU,P); finally FreeIt(LU,A); FreeIt(P); end; end; *) function LU(const Dst: TMtx; const P: TVecInt; MtxType: TMtxType = mtGeneral): TMtx; (*Solves system of linear equations by using LU factorization. Uses the LU factorization to solve the system of linear equations. A X = B. The matrix must be full rank. If there are more rows than columns use the least square solver and if the matrix is also rank deficient use the method. MtxType allows the selection of an optimized algorithm and Op defines the operation to be performed on the calling matrix prior to solve. LUSolve also supports banded matrices. The banded matrix storage is defined with the help of two additional properties: and . SubDiag defines the number of non-zero subdiagonals and the SuperDiag the number of non-zero super diagonals. An example of the storage format for the first sub and super diagonal: A.SubDiag := 1; A.SuperDiag := 1; A.Size(3,6); // ... [0 , ud2, ud3, ud4 ,ud5 ,ud6] first upper diagonal [md1, md2, md3, md4, md5, md6] main diagonal [ld1, ld2, ld3, ld4, ld5, 0] first lower diagonal The columns must be aligned. All the diagonals between the SubDiag and SuperDiag diagonals including the main diagonal must always be included. Similarly you can define two sub/super diagonal storage format: aXY = (X Row index, Y Column index) [a11, a12, a13, 0, 0, 0] [a21, a22, a23, a24, 0, 0] [a31, a32, a33, a34, a35, 0] [0, a42, a43, a44, a45, a46] [0, 0, a53, a54, a55, a56] [0, 0, 0, a64, a65, a66] A.SubDiag := 2; A.SuperDiag := 2; A.Size(5,6); // 5 here is the number of rows for the banded, not for the dense matrix storage format [0 , 0, a13, a24 ,a35, a46] second upper diagonal [0 , a12, a23, a34, a45, a56] first upper diagonal [a11 , a22, a33, a44, a55, a66] main diagonal [a21 , a32, a43, a54, a65, 0] first lower diagonal [a31 , a42, a53, a64, 0, 0] second lower diagonal If you would like to solve X for several different B vectors (from the formula AX= B), you can pass TMtx objects to LUSolve method. With one call you solve the system for several different B vectors and save time. *) function LUSolve(const B, X: TVec; MtxType: TMtxType = mtGeneral; Operation: TMtxOperation = opNone): TMtx; overload; (*Matrix version of LUSolve. Perfroms a LUSolve for each B and X matrices columns in single pass.*) function LUSolve(const B,X: TMtx; MtxType: TMtxType = mtGeneral; Operation: TMtxOperation = opNone): TMtx; overload; (*Performs factorization for LUSolve. Mtx, origMtx and ipiv contain result of factorization on exit. This result is again to be passed to the LUSolve together with B to obtain solution for X. var LU,A, W1, W2: TMtx; P: TVecInt; B,X: TVec; begin CreateIt(LU, A, W1, W2); CreateIt(P); CreateIt(B,X); try A.RefineSolution := True; //it is False by default A.SetIt(2,2,False,[1,2, 3,4]); B.SetIt(2,false, [1, 0 ]); //Perform factorization: A.LUSolve(mtGeneral, W1, W2, P); //OrigMtx param can be nil, if A.RefineSolution = false //Perform solution with given factorization: A.LUSolve(B, X, mtGeneral, opNone, W1, W2, P); //X now holds solution finally FreeIt(LU,A, W1, W2); FreeIt(B,X); FreeIt(P); end; end; *) function LUSolve(MtxType: TMtxType; const Mtx, OrigMtx: TMtx; const pipiv: TVecInt): TMtx; overload; (*Finds solution with an already precomputed factorization. Mtx, origMtx and ipiv contain result of factorization on exit. The factorization was obtained with a previous call to LUSolve, which did not require B and X params. *) function LUSolve(const B, X: TVec; MtxType: TMtxType; Operation: TMtxOperation; const Mtx, OrigMtx: TMtx; const pipiv: TVecInt): TMtx; overload; (*Finds solution with an already precomputed factorzation. Mtx, origMtx and ipiv contain result of factorization on exit. The factorization was obtained with a previous call to LUSolve, which did not require B and X params. *) function LUSolve(const B,X: TMtx; MtxType: TMtxType; Operation: TMtxOperation; const Mtx, OrigMtx: TMtx; const pipiv: TVecInt): TMtx; overload; (*Calculates the mean value of each of the matrix columns. Calculate the mean vale of each of the calling matrix columns and store the results in result vector. The and Complex properties of the result vector are adjusted automatically. var A: TMtx; res: TVec; begin A := TMtx.Create; res := TVec.Create; try A.SetIt(2,2,false,[1,5, -3,6]); A.MeanCols(res); // res = (-1.0, 5.5) finally A.Free; res.Free; end; end; *) procedure MeanCols(const result: TVec); overload; (*Calculates the mean value of each of the matrix rows. Calculate the mean vale of each of the calling matrix rows and store the results in result vector. The and Complex properties of the result vector are adjusted automatically. var A: TMtx; res: TVec; begin A := TMtx.Create; res := TVec.Create; try A.SetIt(2,2,false,[1,5, -3,6]); A.MeanRows(res); // res = (3, 1.5) finally A.Free; res.Free; end; end; *) procedure MeanRows(const result: TVec); overload; (*Compute matrix function as a function of another matrix. The method allows you to compute any function as a function of the Src matrix. For example, a square of root of the matrix would not compute the square root of the elements of the matrix, but instead, the result would be such, that the product of two resulting matrices would return the original matrix. The Params parameters allow you to specify aditional parameter for the Func function. Because the method is based on the eigenvalue decomposition and the eigenvalue, the SourceType for symmetric and symmetric positive definite matrices has to be defined explicitly. The MtxPower function declaration: function TMtx.MtxPower(const Src: TMtx; Exponent: TCplx; SourceType: TMtxType = mtGeneral): TMtx; begin result := MtxFunction(Src,[Exponent],@DoToPower,SourceType); end; *) function MtxFunction(const Src: TMtx; const Params: array of TCplx; Func: TMtxFunction = nil; SourceType: TMtxType = mtGeneral): TMtx; overload; (*Calculates the matrix to integer power. Calculate the matrix to any integer power. Because the method is based on the eigenvalue decomposition and the eigenvalue, the SourceType for symmetric and symmetric positive definite matrices has to be defined explicitly. Note The algorithm for general matrices will fail on a symmetric matrix. *) function MtxIntPower(const Src: TMtx; Exponent: Integer): TMtx; overload; (*Calculates the matrix to any power, real or integer. Calculate the matrix to any power, real or integer. It can also be used to compute the square root of the matrix. Because the method is based on the eigenvalue decomposition and the eigenvalue, the SourceType for symmetric and symmetric positive definite matrices has to be defined explicitly. Note The algorithm for general matrices will fail on a symmetric matrix. *) function MtxPower(const Src: TMtx; Exponent: double; SourceType: TMtxType = mtGeneral): TMtx; overload; (*Calculate the matrix to complex power Exponent.*) function MtxPower(const Src: TMtx; Exponent: TCplx; SourceType: TMtxType = mtGeneral): TMtx; overload; (*Calculates the square root of the matrix. Calculates the square root of the Src matrix and stores the results to calling matrix. The product of the result with itself will give the original matrix. Because the method is based on the eigenvalue decomposition and the eigenvalue, the SourceType for symmetric and symmetric positive definite matrices has to be defined explicitly. Note The algorithm for general matrices will fail on a symmetric matrix. *) function MtxSqrt(const Src: TMtx; SourceType: TMtxType = mtGeneral): TMtx; overload; (*Matrix multiplication. Performs matrix multiplication. In most general case the matrix multiplication is defined by the following equation (result = calling matrix): where a and b are and variables. The default values for a and b are Cplx(1,0) and Cplx(0,0), so the above equation is reduced to: The Operation1 and Operation2 indicate additional , performed on Mtx1 and Mtx2 respectively. Default value for operation is opNone (no additional operation). The Mtx1Type and Mtx2Type parameters indicate the of Mtx1 and Mtx2 matrices. Depending what type of matrices you are multiplying, the Mul method will choose most optimized multiplication method. So, choosing the correct values for Mtx1Type and Mtx2Type can significantly speed up the multiplication. This overloaded function performs a left side multiply operation B with A matrix and stores the results in the calling matrix. If Operation1 and/or Operation2 parameters are specified, perform additional operation on A or B. If Operation1 and/or Operation2 parameters are omitted, the default values (no operation) will be used. The , and Complex properties of the calling matrix are adjusted automatically. An exception is raised is A Cols property does not match the B Rows property (matrix multiplication is not possible). An exception is raised, if Complex property of A and B does not match. Note * If you are not sure, which of matrix are you multiplying, you can use the mtGeneral type (general case). * You can also use the method to determine the type of matrix. * The routine is multithreaded, if specified by the environment variable. var A,B,C: TMtx; begin CreateIt(A,B,C); try A.SetIt(2,2,False,[1,2, 2,4]); B.SetIt(2,2,False,[1,2, 2,4]); C.Mul(A,B); finally FreeIt(A,B,C); end; end; *) function Mul(const A, B: TMtx): TMtx; overload; (*Multiplies multiple matrices. Multiplies all matrices in mtxArray from left to right using matrix multiplication. *) function MulArray(const mtxArray: array of TMtx): TMtx; overload; (*Multiplies multiple matrices. Multiplies all matrices in mtxArray from left to right using matrix multiplication. Specify "1" to request matrix transpose for the corresponding matrix in the second array. For complex matrices, specify "2" if conjugated transpose is needed. *) function MulArray(const mtxArray: array of TMtx; const transpArray: array of integer): TMtx; overload; (*Initializes small matrix multiply according to lapacks dgemm api standard. Initializes compute of: C = alpha*opA(A)*opB(B)+ beta*C The routine generates code by using JIT (just in time compilation) to create a kernel, which is optimized for the specified parameters. To release existing kernel and create a new one call this routine again. The process of creating a kernel is about 1000x slower than multiplying two matrices with size 2x2. The JIT targets small matrices and will fallback to standard dgemm for large matrices. The routine will set the size the calling matrix to match the size of the result of the multiplication. The actual matrix multiplication is performed by calling TMtx.MulSmall The function returns true, if custom code kernel was created. It returns false, if the code was routed to the default dgemm/zgemm routine, because the two matrices are too big to expect an improvement. It is safe to call this method with the same parameters more than once. The internal kernel will not be recreated, if the parameters other than A and B have not changed. *) function MulSmallInit(const A, B: TMtx; opA: TMtxOperation = opNone; opB: TMtxOperation = opNone; const alpha: double = 1; const beta: double = 0): boolean; overload; (*Initializes small matrix multiply according to lapacks dgemm api standard. Initializes compute of: C = alpha*opA(A)*opB(B)+ beta*C The routine generates code by using JIT (just in time compilation) to create a kernel, which is optimized for the specified parameters. To release existing kernel and create a new one call this routine again. The process of creating a kernel is about 1000x slower than multiplying two matrices with size 2x2. The JIT targets small matrices and will fallback to standard dgemm for large matrices. The routine will set the size the calling matrix to match the size of the result of the multiplication. The actual matrix multiplication is performed by calling TMtx.MulSmall method. The function returns true, if custom code kernel was created. It returns false, if the code was routed to the default dgemm/zgemm routine, because the two matrices are too big to expect an improvement. It is safe to call this method with the same parameters more than once. The internal kernel will not be recreated, if the parameters other than A and B have not changed. *) function MulSmallInit(const A, B: TMtx; opA: TMtxOperation; opB: TMtxOperation; const alpha: TCplx; const beta: TCplx): boolean; overload; (*Small matrix multiply. Performs arbitrary small matrix multiplication. The routine does no error checking and assumes that both A and B matrix sizes, FloatPrecision and layout do not change between calls. The size of the calling matrix is set automatically. The kernel for the particular precision is initialized with a call to MulSmallInit and released either when a new one is created or when the calling matrix is freed. *) function MulSmall(const A, B: TMtx): TMtx; overload; (*Small matrix multiply. Performs arbitrary small matrix multiplication. The routine does no error checking and assumes that both A and B matrix and for the calling matrix, the sizes, FloatPrecision, the layout and the memory location (!) do not change between calls. The matrices multiplied are those passed to the MulSmallInit routine. You can change the values in the memory allocated by those matrices, but may not resize them or resize the calling matrix. The kernel for the particular configuration is initialized with a call to MulSmallInit and released either when a new configuration is created or when the calling matrix is freed. *) function MulSmall: TMtx; overload; (*Left side multiply Mtx2 with Mtx1 matrix and store the results in the calling matrix. If Operation1 and/or Operation2 parameters are specified, perform additional operation on Mtx1 or Mtx2. If Operation1 and/or Operation2 parameters are omitted, the default values (no operation) will be used. The , and Complex properties of the calling matrix are adjusted automatically. An exception is raised is Mtx1 Cols property does not match the Mtx2 Rows property (matrix multiplication is not possible). An exception is raised, if Complex property of Mtx1 and Mtx2 does not match. When JITedMul is set to jtmEnabled, the JIT-ed matrix kernel will be created. This creation takes some time and should only be used, if the function will be called many times with the same parameters. The parameters that may not change include the size of the matrices, but matrix objects and memory locations can vary. As a rule of thumb, the change of the parameters can be 2-3x slower than using tmDisabled, but when the parameters do not change for a small matrix of 2x2 the speed-up can be 50x. *) function Mul(const Mtx1, Mtx2: TMtx; Operation1: TMtxOperation; Operation2: TMtxOperation = opNone; JITedMul: TJITedMul = jtmDisabled): TMtx; overload; (*Left side multiply Mtx2 with Mtx1 matrix and store the results in the calling matrix. If parameters Mtx1Type and/or Mtx2Type are specified, the optimized multiplication method will be used. If parameters Mtx1Type and/or Mtx2Type are omitted, default values (general matrix) will be used. If Operation1 and/or Operation2 parameters are specified, perform additional operation on Mtx1 or Mtx2. If Operation1 and/or Operation2 parameters are omitted, the default values (no operation) will be used. The , and Complex properties of the calling matrix are adjusted automatically. An exception is raised is Mtx1 Cols property does not match the Mtx2 Rows property (matrix multiplication is not possible). An exception is raised, if Complex property of Mtx1 and Mtx2 does not match. When JITedMul is set to jtmEnabled, the JIT-ed matrix kernel will be created. This creation takes some time and should only be used, if the function will be called many times with the same parameters. The parameters that may not change include the size of the matrices, but matrix objects and memory locations can vary. As a rule of thumb, the change of the parameters can be 2-3x slower than using tmDisabled, but when the parameters do not change for a small matrix of 2x2 the speed-up can be 50x. *) function Mul(const Mtx1, Mtx2: TMtx; Mtx1Type: TMtxType; Mtx2Type: TMtxType = mtGeneral; Operation1: TMtxOperation = opNone; Operation2: TMtxOperation = opNone; JITedMul: TJITedMul = jtmDisabled): TMtx; overload; (*Returns the matrix product of three matrices. Internally calls and does JIT-ed (faster) multiply only for small square sized matrices. *) function Mul(const Mtx1, Mtx2, Mtx3: TMtx): TMtx; overload; (*Returns the matrix product of four matrices. Internally calls and does JIT-ed (faster) multiply only for small square sized matrices. *) function Mul(const Mtx1, Mtx2, Mtx3, Mtx4: TMtx): TMtx; overload; (*Matrix element-wise multiplication. Multiplies elements in Mtx matrix with the elements in the calling matrix (array multiplication) and stores the results in calling matrix. The , and Complex properties of both matrices must match, otherwise an exception is raised. var A,B,C: TMtx; begin CreateIt(A,B,C); try A.SetIt(2,2,False,[1,2, 2,4]); B.SetIt(2,2,False,[1,2, 2,4]); C.MulElem(A,B); // C becomes: // [1, 4, // 4,16] finally FreeIt(A,B,C); end; end; *) function MulElem(const Mtx: TMtx): TMtx; overload; (*Multiplies elements in Mtx1 matrix with the elements in Mtx2 matrix (array multiplication) and stores the results in calling matrix. The , and Complex properties of calling matrix are set implicitly to match those of Mtx1 and Mtx2 matrices. Mtx1 and Mtx2 Rows, Cols, and Complex properties must be the same, otherwise an excetion is raised. raised. *) function MulElem(const Mtx1, Mtx2: TMtx): TMtx; overload; (* Compute X*Y*Z The following expression would also run at the same or higher speed, when passing X also for the Z parameter: X^2*Y *) function MulElem(const X, Y,Z: TMtxVec): TMtx; overload; (* Compute X*Y*zScalar The following expression would also run at the same or higher speed, when passing X also for the Z parameter: X^2*zScalar *) function MulElem(const X,Y: TMtxVec; const Z: Double): TMtx; overload; (* Compute X*Y*zScalar The following expression would also run at the same or higher speed, when passing X also for the Z parameter: X^2*zScalar *) function MulElem(const X,Y: TMtxVec; const Z: TCplx): TMtx; overload; (*Calculates the matrix norm-1. Calculates calling matrix norm-1. The "norm-1" is defined as the largest column sum. var A: TMtx; b: double; begin CreateIt(A); try A.SetIt(2,2,false,[1,2, 2,4]); // 2x2, not complex matrix b := A.Norm1; finally FreeIt(A); end; end; *) function Norm1: double; overload; (*Calculates the matrix Frobenius norm. Calculate the calling matrix Frobenius norm. The Frobenius norm is defined as the square root of the sum of sums of squared elements of rows. An exception is raised if calling matrix Complex property is true. var A: TMtx; b: double; begin CreateIt(A); try A.SetIt(2,2,false,[1,2, 2,4]); // 2x2, not complex matrix b := A.NormFro; finally FreeIt(A); end; end; *) function NormFro: double; overload; (*Calculates the matrix infinity norm. Calculate the calling matrix infinity norm. The "infinity norm" is defined as the largest row sum. var A: TMtx; b: double; begin CreateIt(A); try A.SetIt(2,2,false,[1,2, 2,4]); // 2x2, not complex matrix b := A.NormInf; // b= 6 finally FreeIt(A); end; end; *) function NormInf: double; overload; (*Constructs a Pascal matrix. Construct a Pascal matrix of order Order with integer elements, taken from the Pascal's triangle. The Pascal matrix is by definition symmetric positive definite. The Pascal matrix is written to the calling matrix. The , and Complex properties of the calling matrix are adjusted automatically. *) function Pascl(Order: integer): TMtx; overload; (*Raises matrix elements to any power. Raises Base matrix elements to the Exponent matrix elements power and stores the results in the calling matrix. The , and Complex properties of the calling matrix are adjusted automatically. The , and Complex properties of Base and Exponent matrices must match otherwise an exception is raised. Note Only positive exponents can be handled if Exponent matrix is not complex. var A,B,C: TMtx; begin CreateIt(A,B,C); try A.SetIt(2,2,False,[1,2, 2,4]); B.SetIt(2,2,False,[1,2, 2,4]); C.Power(A,B); finally FreeIt(A,B,C); end; end; *) function PowerMtx(const Base, Exponent: TMtx): TMtx; overload; (*Creates a reduced size dense matrix for screen display (bitmap) to show the matrix pattern. Creates a reduced size dense matrix for screen display (bitmap) to show the matrix pattern. Pixels parameter defines the target number of pixels to reduce and to. The size reduction method depends on what you want to see: * pdsPattern , Returns 1 for all areas with at least one nonzero value regardless of its amplitude. * pdsAverage, Average all values within an area (pixel). * pdsPeak, Return only the maximum absolute value within an area (region will become one pixel). Uses ..., MtxVecTee; var Mtx, ReducedMtx: TMtx; begin CreateIt(Mtx,ReducedMtx); try Mtx.Size(1000,1000,false); Mtx.RandGauss; // we're interested in averages, not pattern Mtx.PixelDownSample(ReducedMtx,200,pdsAverage); DrawIt(ReducedMtx); finally FreeIt(Mtx,ReducedMtx); end; end; 7*) procedure PixelDownSample(const Dst: TMtx; Pixels: integer = 500; Mode: TPixelDownSample = pdsPattern); overload; (*Allows to exactly specify the size of the destination matrix with PixelsHeight and PixelsWidth parameters. The source matrix can be bigger or smaller than the destination. *) procedure PixelResample(const Dst: TMtx; const ZoomRect: TMtxRect; Mode: TPixelDownSample = pdsPattern); overload; function ReadHeader(const SrcStream: TStream; Endian: TEndianness = boLittleEndian): TPrecision; override; procedure Reset; override; (*Resizes the matrix, while preserving the values in already allocated memory. Sets the property to NewRows, property to NewCols, while preserving the values in already allocated memory. var A,B: TMtx; begin CreateIt(A,B); try A.SetIt(2,2,False,[1,3, 2,4]); B.Resize(A,3,2,True); // B becomes: // [1,2,0, // 3,4,0]); finally FreeIt(A,B); end; end; *) function Resize(NewRows , NewCols: integer): TMtx; overload; (*Performs resize of the calling matrix to NewRows and NewCols. Copies the Src matrix values to the calling matrix. The elements outside the newly created matrix size are not referenced. *) function Resize(const Src: TMtx; NewRows, NewCols: integer): TMtx; overload; (*Resize and transpose. Resizes the calling matrix to NewRows and NewCols and then copies the Src matrix values to the calling matrix. The elements outside the newly created matrix size are not referenced. At the end the method also transposes the Src matrix. All this operations are performed in one single pass. *) function ResizeAndTranspose(const Src: TMtx; NewRows, NewCols: integer): TMtx; (*Rotates matrix rows 90 degrees clockwise. Rotates all calling matrix rows 90 degrees clockwise in-place (check the scheme bellow). Note This operation differs from the operation. var A,B: TMtx; begin CreateIt(A,B); A.SetIt(2,2,False,[1,3, 2,4]); B.Rotate90(A); FreeIt(A,B); end; *) function Rotate90: TMtx; overload; (*Rotate all Mtx matrix rows 90deg clockwise. Store the results in calling matrix. The , and Complex properties of the calling matrix are adjusted automatically. *) function Rotate90(const Mtx: TMtx): TMtx; overload; (*Exchanges two matrix rows. Exchange the i-th and j-th rows of the calling matrix in-place. An exception is raised if matrix bounds are overrun. The indexes i and j are zero based. (the first row has index 0). var A,B: TMtx; begin CreateIt(A,B); try A.SetIt(2,2,False,[1,3, 2,4]); B.RowExchange(0,1); // B becomes: // [2,4, // 1,3]); finally FreeIt(A,B); end; end; *) function RowExchange(i, j: integer): TMtx; overload; (*Scale all matrix columns with values from Src. Src.Length must be equal to Self.Cols. *) function ScaleCols(const Src: TVec): TMtx; overload; (*Scale all matrix rows with values from Src. Src.Length must be equal to Self.Rows. *) function ScaleRows(const Src: TVec): TMtx; overload; (*Scale all Mtx matrix columns with values from Src. Src.Length must be equal to Mtx.Cols. The result is stored in to the calling matrix. *) function ScaleCols(const Mtx: TMtx; const Src: TVec): TMtx; overload; (*Scale all Mtx matrix rows with values from Src. Src.Length must be equal to Mtx.Rows. The result is stored in to the calling matrix. *) function ScaleRows(const Mtx: TMtx; const Src: TVec): TMtx; overload; (*Multiply matrix with diagonal matrix from the left. DiagMtx contains the values of the main diagional of the diagonal matrix. Other values of the DiagMtx matrix are assumed to be zero. DiagMtx.Length must be equal to Self.Cols. This operation is the same as calling TMtx.ScaleRows. *) function MulDiagLeft(const DiagMtx: TVec): TMtx; overload; (*Multiply matrix with diagonal matrix from the right. DiagMtx contains the values of the main diagional of the diagonal matrix. Other values of the DiagMtx matrix are assumed to be zero. DiagMtx.Length must be equal to Self.Rows. This operation is the same as calling TMtx.ScaleCols. *) function MulDiagRight(const DiagMtx: TVec): TMtx; overload; (*Multiply matrix with diagonal matrix from the left. DiagMtx contains the values of the main diagional of the diagonal matrix. Other values of the DiagMtx matrix are assumed to be zero. DiagMtx.Length must be equal to Self.Cols. This operation is the same as calling TMtx.ScaleRows. *) function MulDiagLeft(const DiagMtx: TVec; const Mtx: TMtx): TMtx; overload; (*Multiply matrix with diagonal matrix from the right. DiagMtx contains the values of the main diagional of the diagonal matrix. Other values of the DiagMtx matrix are assumed to be zero. DiagMtx.Length must be equal to Self.Rows. This operation is the same as calling TMtx.ScaleCols. *) function MulDiagRight(const Mtx: TMtx; const DiagMtx: TVec): TMtx; overload; (*Compute maximum of each row. Compute maximum of each row and store the result in to Dst vector. The Dst is sized automatically. *) procedure MaxRows(const Dst: TVec); overload; (*Compute minimum of each row. Compute mniimum of each row and store the result in to Dst vector. The Dst is sized automatically. *) procedure MinRows(const Dst: TVec); overload; (*Compute maximum of each column. Compute maximum of each column and store the result in to Dst vector. The Dst is sized automatically. *) procedure MaxCols(const Dst: TVec); overload; (*Compute minimum of each column. Compute mniimum of each column and store the result in to Dst vector. The Dst is sized automatically. *) procedure MinCols(const Dst: TVec); overload; (*Compute maximum and minimum of each row. Compute maximum and minimum of each row and store the result in to Dst vectors. The Dst's are sized automatically. *) procedure MaxMinRows(const DstMaxRows, DstMinRows: TVec); overload; (*Compute maximum and minimum of each column. Compute maximum and minimum of each column and store the result in to Dst vectors. The Dst's are sized automatically. *) procedure MaxMinCols(const DstMaxCols, DstMinCols: TVec); (*Copies values from vector to matrix column. Copy all Vec elements to the calling matrix Col column. The Complex property of the calling matrix is adjusted automatically. An exception is raised, if array bounds are overrun. var A: TMtx; V: TVec; begin CreateIt(A); CreateIt(V); try A.Size(2,1,True); V.SetIt(True,[1,2, 2,4]); // complex vector A.SetCol(V,0); finally FreeIt(V); FreeIt(A); end; end; *) function SetCol(const Vec: TDenseMtxVec; Col: integer): TMtx; overload; (*Copy vector Vec elements [VecIndex]..[VecIndex+Len-1] to the calling matrix elements [Row,Col]..[Row+Len-1,Col]. An exception is raised if condition checking is enabled and array bounds are overrun. An exception is raised, if Vec and the calling matrix complex properties do not match. *) function SetCol(const Vec: TDenseMtxVec; VecIndex, Row, Col, Len: integer): TMtx; overload; (*Sets matrix values. Sets matrix values. This method gives you the possibility to pass large arrays of elements without having to declare constant arrays. Pass all elements in A array to the calling matrix. The and properties of the calling matrix are set to ARows and ACols and the Complex property is set to AComplex. An exception is raised if the matrix size (ARows*ACols) does not match the number of complex numbers in A. var A: TMtx; begin CreateIt(A); try A.SetIt(2,2,False,[1,2, 2,4]); finally FreeIt(A); end; end; *) function SetIt(ARows, ACols: integer; AComplex: Boolean;const A: array of double): TMtx; overload; (*Copies values from vector to matrix row. Copy all Vec elements to the calling matrix Row row. The Complex property of the calling matrix is adjusted automatically. An exception is raised, if array bounds are overrun. var A: TMtx; V: TVec; begin CreateIt(A); CreateIt(V); try A.Size(1,2,True); V.SetIt(True,[1,2, 2,4]); // complex vector A.SetCol(V,0); finally FreeIt(V); FreeIt(A); end; end; *) function SetRow(const Vec: TDenseMtxVec; Row: integer): TMtx; overload; (*Copy vector Vec elements [VecIndex]..[VecIndex+Len-1] to the calling matrix elements [Row,Col]..[Row,Col+Len-1]. An exception is raised if condition checking is enabled and array bounds are overrun. An exception is raised, if Vec and the calling matrix complex properties do not match. *) function SetRow(const Vec: TDenseMtxVec; VecIndex, Row, Col, Len: integer): TMtx; overload; (*Initializes matrix values to zero. Sets the calling matrix elements [Row,Col]..[ToRow,ToCol] to zero. An exception is raised if is true and array bounds are overrun. *) function SetZero(Row, Col, ToRow, ToCol: integer): TMtx; overload; (*Initializes matrix values to Value. Sets the calling matrix elements [Row,Col]..[ToRow,ToCol] to Value. An exception is raised if is true and array bounds are overrun. *) function SetVal(const Value: double; Row, Col, ToRow, ToCol: integer): TMtx; overload; (*Sets the calling matrix elements [Row,Col]..[ToRow,ToCol] to complex value Value. Complex properties of the calling object are set to true even before the call it was false. An exception is raised if array bounds are overrun. *) function SetVal(const Value: TCplx; Row, Col, ToRow, ToCol: integer): TMtx; overload; (*Sets the size of matrix. Set the calling matrix properties: * = ARows, * = ACols * and Complex = AComplex * = aIsDouble Calling the Size method does not preserve the contents of the matrix. Use the Resize method, if you want to preserve existing values. Note The Size method performs an out-of-memory safe resize, if the matrix already has memory allocated. This prevents out of memory message for example when redefining the size of the matrix from single column to single row: A.Rows := 10000; // matrix size = 0 A.Cols := 1; // matrix size = 10000 // ... A.Cols := 10000; // matrix size = 100 000 000 (problems here) A.Rows := 1; // matrix size = 10 000 var A: TMtx; begin CreateIt(A); try A.Size(2,1,True, mvDouble); // 2x1 complex matrix A.SetZero; // A becomes: // [0,0] // [0,0] finally FreeIt(A); end; end; *) function Size(const ARows, ACols: integer; const aComplex: boolean; const aIsDouble: boolean): TMtx ; overload; (*Sets the size of matrix. Set the calling matrix properties: * = ARows, * = ACols * and Complex = AComplex Calling the Size method does not preserve the contents of the matrix. Use the Resize method, if you want to preserve existing values. The existing floating point precision is preserved. *) function Size(const ARows, ACols: integer; const aComplex: boolean): TMtx ; overload; (*Sets the size of matrix. Set the calling matrix properties: * = ARows, * = ACols * and Complex = false Calling the Size method does not preserve the contents of the matrix. Use the Resize method, if you want to preserve existing values. The existing floating point precision is preserved. *) function Size(const ARows, ACols: integer): TMtx ; overload; (*Sets the size of matrix. Set the calling matrix properties: * = ARows, * = ACols * and = aFloatPrecision. If the aFloatPrecision parameter is omitted, the default value mvDouble is used. Calling the Size method does not preserve the contents of the matrix. Use the Resize method, if you want to preserve existing values. Note The Size method performs an out-of-memory safe resize, if the matrix already has memory allocated. This prevents out of memory message for example when redefining the size of the matrix from single column to single row. *) function Size(ARows, ACols: integer; aFloatPrecision: TMtxFloatPrecision): TMtx; overload; (*Sets the size of matrix. Set the calling matrix properties: * = ARows, * = ACols * and = FloatPrecisionRef.FloatPrecision *) function Size(ARows, ACols: integer; const FloatPrecisionRef: TMtxVec): TMtx; overload; function Size(const Src: TMtxVecBase; AComplex: boolean): TMtxVec ; override; function Size(const Src: TMtxVecBase; const aFloatPrecision: TMtxFloatPrecision): TMtxVec; override; (*Sorts the elements in a matrix row(s) in ascending order. Sorts the elements in calling matrix row(s) in ascending order in-place. If the calling matrix is complex, then complex values are first compared by the absolute value and then by the argument. Note Each row is sorted independently from the other. var A: TMtx; begin CreateIt(A); try A.SetIt(2,2,False,[1,2, 4,2]); A.SortAscend; // A becomes: // [1,2] // [2,4] finally FreeIt(A); end; end; *) function SortAscend: TMtx; overload; (*Performs row based sort in ascending order. The Col parameter defines the column based on which the rows are compared with each other.*) function SortAscend(Col: integer): TMtx; overload; (*Sorts the elements in a matrix row(s) in descending order. Sorts the elements in calling matrix row(s) in descending order in-place. If the calling matrix is complex, then complex values are first compared by the absolute value and then by the argument. Note Each row is sorted independently from the other. var A: TMtx; begin CreateIt(A); try A.SetIt(2,2,False,[1,2, 4,2]); A.SortDescend; // A becomes: // [2,1] // [4,2] finally FreeIt(A); end; end; *) function SortDescend: TMtx; overload; (*Performs row based sort in descending order. The Col parameter defines the column based on which the rows are compared with each other.*) function SortDescend(Col: integer): TMtx; overload; (* Depreciated. Use instead. *) function SqrElem(const Mtx: TMtx): TMtx; overload; deprecated; (* Depreciated. Use instead. *) function SqrElem: TMtx; overload; deprecated; (* Depreciated. Use instead. *) function SqrtElem(const Mtx: TMtx): TMtx; overload; deprecated; (* Depreciated. Use instead. *) function SqrtElem: TMtx; overload; deprecated; (*Standard deviation for matrix columns. Calculates the standard deviation for each of the calling matrix columns and stores the results in vector result. An exception is raised if calling matrix is complex. The Length and Complex properties of the result vector are adjusted automatically. *) procedure StdDevCols(result: TVec); (*Standard deviation for matrix rows. Calculates the standard deviation for each of the calling matrix rows and stores the results in vector result. An exception is raised if calling matrix is complex. The Length and Complex properties of the result vector are adjusted automatically. *) procedure StdDevRows(result: TVec); (*Convert strings to double (TCplx) and store them in the Values array. Convert strings in aList to double (real number) and store them in the Values array of the calling matrix. property is set to aList.Count. Complex and propertes are auto-detected. Complex numbers must follow the format: a+bi. All strings must have the same number of columns (numbers). Columns must be separated with a aDelimiter. var a,b: TMtx; begin CreateIt(a,b); try a.SetIt(2,2,False,[1,2,3,4]); a.Cos; b.Size(a); b.SetVal(1); a.Add(b); Richedit1.Clear; Memo1.Clear; a.ValuesToStrings(Richedit1.Lines); b.ValuesToStrings(Richedit1.Lines); a.ValuesToStrings(Memo1.Lines); b.ValuesToStrings(Memo1.Lines); Memo1.Lines.SaveToFile('C:\Test.txt'); Memo1.Lines.LoadFromFile('C:\Test.txt'); a.StringsToValues(Memo1.Lines); finally FreeIt(a,b); end; end; *) function StringsToValues(const srcList: TStrings; const aDelimiter: string): TMtx; overload; (*Convert strings to double (TCplx) and store them in the Values array. Uses Tab (#9) as the default column separator. *) function StringsToValues(const srcList: TStrings): TMtx; overload; virtual; (*Convert strings from [ListIndex]..[ListIndex+ListLen-1] in aList to double (TCplx). Store them in the Values array of the calling matrix, starting from element [Row,Cols]. The size of the calling matrix is not changed. If array bounds are overrun an exception is raised. Complex numbers must follow the format: a+bi. *) function StringsToValues(const srcList: TStrings; ListIndex,ListLen, Row,Col: Integer; Delimiter: string = kTab): TMtx; overload; (*Singular value decomposition. Performs a singular value decomposition on a calling matrix (A). U or V can be nil, if not desired. If you do not want economy size U and V set MinSize to False. The singular value decomposition (SVD) of the calling matrix (A, with m rows and n cols) is defined by the following equation: where U and V are unitary (for complex A) or orthogonal (for real A). S is a diagonal matrix with real diagonal elements is: The diagonal elements are singular values of A (calling matrix). The first min(m, n) columns of the matrices U and V are, respectively, left and right singular vectors of calling matrix (A). The singular values and singular vectors satisfy: where ui and vi are the ith columns of U and V, respectively. One interpretation of the singular values is as follows. If you take a unit sphere in n-dimensional space, and multiply each vector in it by an m x n matrix , you will get an ellipsoid in m-dimensional space. The singular values give the lengths of the principal axes of the ellipsoid. If the matrix is singular in some way, this will be reflected in the shape of the ellipsoid. In fact, the ratio of the largest singular value of a matrix to the smallest one gives a of the matrix, which determines, for example, the accuracy of numerical matrix inverses. Very small singular values are usually numerically meaningless. var A,U,V: TMtx; S: TVec; begin CreateIt(U,V,A); CreateIt(S); try A.SetIt(3,3,True, [2, 5, 12, 1, 5, 2.5, -4, 2, 8, 0, 0, 3, 2, 0, 4, 8, 12, 8]); A.SVD(U,S,V); // S = [21.3406,10.9726,3.7989] finally FreeIt(U,V,A); FreeIt(S); end; end; *) function SVD(const S: TVec): TMtx; overload; (*Matrix version of SVD. Performs a SVD for each U and V matrices columns in single pass. U and V will be calculated only, if both are assigned. The following holds true: A = U*S*Transp(V) V is returned already transposed. *) function SVD(U: TMtx; const S: TVec; V: TMtx; MinSize: boolean = True): TMtx; overload; (*Calculates the minimum norm solution to a real linear least squares problem. Calculates the minimum norm solution to a real linear least squares problem. Minimize 2-norm(| b - A*x |). using the singular value decomposition (SVD) of the calling matrix A. A is an Rows-by-Cols matrix which may be rank-deficient. Several right hand side vectors b and solution vectors x can be handled in a single call. The effective rank of A is determined by treating as zero those singular values which are less than Threshold times the largest singular value and is returned by the function. The S vector holds the singular values on the output. var X,B,D: TVec; V: TMtx; begin CreateIt(X,B,D); CreateIt(V); try B.SetIt(false,[0,2,3]); V.SetIt(3,3,false,[1,2,3, 3,4,5, 6,7,7]); V.SVDSolve(B,X,D); // matrix V can be non-quadratic finally FreeIt(X,B,D); FreeIt(V); end; end; *) function SVDSolve(const B, X, S: TVec; Threshold: double = 1E-9): integer; overload; (*Matrix version of SVDSolve. Performs a SVDSolve for each U and V matrices columns in single pass.*) function SVDSolve(const B, X: TMtx; const S: TVec; Threshold: double = 1E-9): integer; overload; (*Solves the Sylvester equation. Solves the Sylvester's equation: for real quasi-triangular or complex triangular matrices A and B. The solution (X) overwrites the C matrix. The AOp and BOp parameters indicate the performed on A and B respectively. The of the Sylvester equation is determined with the ASign parameter (siPlus for +, siMinus for -). The result of a Sylvester function is a scale factor a. The A and B matrices property must be true, otherwise an exception is raised. *) function Sylvester(const A, B, C: TMtx; ASign: TSign = siPlus; AOp: TMtxOperation = opNone; BOp: TMtxOperation = opNone): double; overload; (*Saves matrix data to MatrixMarket ASCII file format. Saves matrix data to MatrixMarket ASCII file format. *) procedure SaveToMatrixMarketFile(FileName: string); (*Splits matrix in blocks. Splits he calling matrix in blocks. Example: [ A B ] [ C D ] where A,B,C,D are matrices of size 2x2 and the calling matrix is of size 4x4. ARows and ACols define the number of rows and columns of the block based matrix. The matrices passed in the dst array to be filled with values from the calling matrix, must already have matching size and complex properties to cover the calling matrix or an exception will be raised. var A,B,C,D,E: TMtx; begin CreateIt(A,B,C,D); CreateIt(E); try A.Size(2,2); B.Size(A); C.Size(A); D.Size(A); E.SetIt(4,4,False,[1,2,3,4 5,6,7,8 9,1,2,3 4,5,6,7]); E.Split(2,2,[A,B, C,D]); // A becomes: // [1,2, // 5,6] // B becomes: // [3,4, // 7,8] // C becomes: // [9,1, // 4,5] // D becomes: // [2,3, // 6,7] finally FreeIt(A,B,C,D); FreeIt(E); end; end; *) procedure Split(ARows, ACols: integer;const Dst: array of TMtx); (*Calculates the sum of each of the calling matrix columns. Calculates the sum of each of the calling matrix columns and stores the results in Dst vector. The and Complex properties of the Dst vector are adjusted automatically. var A: TMtx; V: TVec; begin CreateIt(A); CreateIt(V); A.Size(2,2,False,[[1,5, 2,3]); A.SumCols(V); // V = [3,8] FreeIt(V); FreeIt(A); end; *) procedure SumCols(const Dst: TVec); overload; (*Calculates the sum of each of the calling matrix rows. Calculates the sum of each of the calling matrix rows and stores the results in Dst vector. The and Complex properties of the Dst vector are adjusted automatically. var A: TMtx; V: TVec; begin CreateIt(A); CreateIt(V); A.Size(2,2,False,[[1,2, 2,4]); A.SumRows(V); // V = [3,6] FreeIt(V); FreeIt(A); end; *) procedure SumRows(const Dst: TVec); overload; (*Calculates the tensor product of two vectors. Calculates the tensor product of Vec1 and Vec2 vectors and stores the results in the calling matrix. The property is set to Vec1. and property is set to Vec2.. The Complex property of the calling matrix is adjusted automatically. var Vec1,Vec2: TVec; V: TMtx; begin CreateIt(Vec1,Vec2); CreateIt(V); try Vec1.Size(3); Vec1.SetIt(false,[0,2,3] Vec2.Copy(Vec1); V.TensorProd(Vec1,Vec2); // V becomes: // [0,0,0] // [0,4,6] // [0,6,9] finally FreeIt(Vec1,Vec2); FreeIt(V); end; end; *) function TensorProd(const Vec1, Vec2: TVec): TMtx; overload; (*Constructs a Toeplitz matrix. Constructs a Toeplitz matrix with first row equal to FirstRow vector and first column equal to FirstCol vector, but without the first element. The , and Complex properties of the calling matrix are adjusted automatically. An exception is raised if FirstRow and FirstCol Complex properties do not match. var V1,V2: TVec; T: TMtx; begin CreateIt(V1,V2); CreateIt(T); try V1.SetIt(False,[1,2,3,4]); V2.SetIt(False,[2,3,4]); T.Toeplitz(V1,V2); // T becomes: //[1 2 3 4] //[2 1 2 3] //[3 2 1 2] //[4 3 2 1] finally FreeIt(T); FreeIt(V1,V2); end; end; *) function Toeplitz(const FirstRow,FirstCol: TVec): TMtx; overload; (*Constructs a Toeplitz matrix. Constructs a Toeplitz matrix with first row equal to FirstRow vector and first column equal to FirstRow vector, but without the first element. *) function Toeplitz(const FirstRow: TVec): TMtx; overload; (*Matrix trace. the trace of the calling matrix. If the calling matrix Complex property is false, the imaginary part is set to zero. *) function Trace: TCplx; overload; (*Transposes matrix. Transposes calling matrix in-place. Instead of using transpose directly, try using the parameter of many TMtx methods. If this operation can not be avoided try using the not-in-place version (see bellow) or see the method. var A: TMtx; begin CreateIt(A); A.Size(2,1,True); // 2x1 complex matrix A.SetVal(Cplx(3,4)); A.Transp; FreeIt(A); end; *) function Transp: TMtx; overload; (*Transpose the Mtx matrix. Write the results to the calling matrix. The , and Complex properties of the calling matrix are adjusted automatically. *) function Transp(const Mtx: TMtx): TMtx; overload; (*Constructs upper triangular matrix. The method uses Mtx matrix to construct an upper triangular matrix. The results are stored in the calling matrix. If the ZeroLower parameter is true then the calling matrix subdiagonal elements will be set to zero - otherwise the subdiagonal elements will not be initialized. If the Diagonal boolean parameter is true then the Mtx matrix main diagonal elements will be copied to the calling matrix main diagonal elements. If the Diagonal parameter is false, the calling matrix main diagonal elements will be set to zero. var A,B: TMtx; begin CreateIt(A,B); A.SetIt(2,1,True,[1,2, 2,4]); // 2x2, not complex matrix B.UpperTriangle(A,True,True); // B becomes: // [1,2, // [0,4] FreeIt(A,B); end; *) function UpperTriangle(const Mtx: TMtx; ZeroLower, Diagonal: boolean): TMtx; overload; (*Construct VanderMonde matrix. Constructs a VanderMonde matrix with Vec. rows and ACols columns. The second to last column of the VanderMonde matrix is Vec: *) function VanderMonde(ACols: Integer; const Vec: TVec): TMtx; overload; (*Converts the content of the matrix Values array to a list of strings. Convert all elements of the calling matrix to strings with formating real parts with ReFormat, imaginary parts with ImFormat, using the text delimiter Delimiter and store them in dstList, by using the Add method of TStrings object. Performance note: This routine will be exceedingly slow, if TRichEdit.Lines or TMemo.Lines are passed as a parameter for dstList. Use TStringList or StringList types and then call TMemo.Lines.AddStrings(yourList) for best results. procedure TForm1.Button1Click(Sender: TObject); var a,b: TMtx; begin CreateIt(a,b); try a.SetIt(2,2,False,[1,2,3,4]); a.Cos; b.Size(a); b.SetVal(1); a.Add(b); Richedit1.Clear; Memo1.Clear; a.ValuesToStrings(Richedit1.Lines); b.ValuesToStrings(Richedit1.Lines); a.ValuesToStrings(Memo1.Lines); b.ValuesToStrings(Memo1.Lines); Memo1.Lines.SaveToFile('C:\Test.txt'); Memo1.Lines.LoadFromFile('C:\Test.txt'); a.StringsToValues(Memo1.Lines); finally FreeIt(a,b); end; end; *) function ValuesToStrings(const dstList: TStrings; const Delimiter: string = kTab; const Align: TFixedTextAlign = ftaNone; const ReFormat: string = ' 0.######;-0.#######'; const ImFormat: string = '+0.######i;-0.######i'; const Headers: boolean = false; const ColumnWidth: integer = -1): integer; overload; (*Convert calling matrix elements, starting with [Row,Col] until [row + RowCount, col + ColCount] converting Len elements to strings. Formatting real parts with ReFormat, imaginary parts with ImFormat, using the text delimiter Delimiter and store them in dstList starting at ListIndex. If dstList is not large enough, the method will use the Add method of dstList object. Returns column width, when alignment is other than none. Performance note: This routine will be exceedingly slow, if TRichEdit.Lines or TMemo.Lines are passed as a parameter for dstList. Use TStringList or StringList types and then call TMemo.Lines.AddStrings(yourList) for best results. *) function ValuesToStrings(const dstList: TStrings; ListIndex,Row,Col,RowCount,ColCount: integer; const Delimiter: string = kTab; const Align: TFixedTextAlign = ftaNone; const ReFormat: string = ' 0.######;-0.######'; const ImFormat: string = '+0.######i;-0.######i'; const Headers: boolean = false; const ColumnWidth: integer = -1): integer; overload; (*Converts all calling matrix elements to string.*) procedure ValuesToText(out Text: String; Delimiter: string = kTab; const ReFormat: string = ' 0.######;-0.#######'; const ImFormat: string = '+0.######i;-0.######i');overload; (*Converts [Row, Col] to [Row+RowCount, Col+ColCount] matrix elements to string.*) procedure ValuesToText(out Text: String; Row,Col,RowCount,ColCount: integer; Delimiter: string = kTab; const ReFormat: string = ' 0.######;-0.######'; const ImFormat: string = '+0.######i;-0.######i'); overload; function TextToValues(Text: String; Delimiter: String = kTab): TMtx; (*Transforms matrix into matrix of standardized data. The routine uses Data matrix and transforms it into ZScore matrix of standardized data (the so called Z Scores). The standardization of each column (variable) is made by subtracting its mean and dividing by its standard deviation: Column - Mean(Column) Z(Column) = ----------------------- StdDev(Column) var Data: TMtx; Res TMtx; begin Data := TMtx.Create; Res := TMtx.Create; try Data.SetIt(3,3,false,[1,2,3, 4,5,6, 7,100,12]); Res.ZScore(Data); // result = (-1 -0,604 -0,873, // 0 -0,55 -0,218 // 1 1,154 1,091) finally Data.Free; Res.Free; end; end; *) function ZScore(const Src: TMtx): TMtx; overload; procedure WriteHeader(const Dst: TStream; Precision: TPrecision; Rounding: TRounding = rnTrunc; Endian: TEndianness = boLittleEndian); override; procedure WriteHeader(const Dst: TStream); override; published (*Defines if matrix type will be checked automatically. If True, some routines requesting information will check for the matrix type first by calling the method, in order to select the most efficient algorithm. The following types will be detected: mtSymmetric = symmetric matrix mtHermitian = Hermitian matrix mtTriangle = triangular matrix, with unit or non unit main diagonal mtGeneral = general matrix (none of the above) In worst case the matrix type detection will require O(n^2) compare operations. In case of a general matrix, it only takes a few cycles for the algorithm to detect that the matrix is not Symmetric, triangular or Hermitian. And in case of a symmetric or hermitian or triangular matrix, the cost of O(n^2) compare operations is still much lower than the loss of performance, when using the general purpose algorithm. For some computations, like eigenvalues, the type of the matrix has to specified explicitly, especially when it comes to symmetric matrices, because the algorithm for the general matrix will fail on a symmetric matrix. If you specify the type of matrix explicitly to the procedures and AutoMtxType is set to True, then AutoMtxType will override the user specified type. *) property AutoMtxType: boolean read FAutoMtxType write SetAutoMtxType default false; (*Defines matrix balancing method. Defines which will be used to balance the calling matrix. Balancing the calling matrix can be very useful when calculating the eigenvalues and eigenvector. Balancing operation can perform one or both of the following similarity transformations: 1.Permute the calling matrix (A) to block of upper triangular form: where P is a permutation matrix, and A'11 and A' 33 are upper triangular. The diagonal elements of A'11 and A' 33 are eigenvalues of the calling matrix (A). 2.Apply a diagonal similarity transformation to A', to make the rows and columns of A'22 as close in norm as possible: This scaling can reduce the norm of the matrix (that is, ||A''22|| < ||A'22||), and hence reduce the effect of rounding errors on the accuracy of computed eigenvalues and eigenvectors. var A: TMtx; d: TVec; begin CreateIt(A); // ... A.Balance := btFull; // applies both methods A.Eig(d); // ... FreeIt(A); end; *) property Balance: TBalanceType read FBalance write SetBalance default btFull; (*Defines the number of matrix columns. Use this property to set or get the number of the calling matrix columns. Setting the Cols does not affect the actual amount of memory allocated unless Rows*Cols is bigger than . Note Always set the Complex property before setting Cols. Complex is initially false and Cols is initially 0. You can also set the Cols property by calling the method. *) property Cols: integer read FCols write SetCols default 0; (*Defines the norm used to compute the condition number. Defines the norm used to compute the . The default value is cnNone meaning that no condition number will be estimated. *) property ConditionNumber: TConditionNumber read FConditionNumber write SetConditionNumber default cnNone; (*Enables/disables the refining of the solution of the system of linear equations. The method enables/disables the refining of the solution of the system of linear equations, computed by method. When RefineSolution is enabled, an iterative refinement of the solution to a system of linear equations is executed. For each computed solution the component-wise and the the component-wise in the computed solution are calculated as well. var X,B: TVec; A: TMtx; begin CreateIt(X,B); CreateIt(A); try B.SetIt(False,[0,2]); A.SetIt(2,2,false,[1,2, 3,4]); // 2x2, not complex matrix A.RefineSolution := True; A.ConditionNumber := cnNormInf; A.LUSolve(B,X); finally FreeIt(B,X); FreeIt(A); end; end; *) property RefineSolution: boolean read FRefineSolution write SetRefineSolution default false; (*Defines the number of matrix rows. Use this property to set or get the number of the calling matrix rows. Setting the Rows does not affect the actual amount of memory allocated unless Rows*Cols is bigger than . Note Always set the Complex property before setting Rows. Complex is initially false and Rows is initially 0. You can also set the Rows property by calling the method. *) property Rows: integer read FRows write SetRows default 0; (*Defines the number of leading columns. This value defines the spacing in number of samples between rows. It is fixed to be the same to the value of (for now). *) property LeadingCols: integer read GetLeadingCols write SetLeadingCols; (*Sets/reads the number of superdiagonals in banded matrices. *) property SuperDiag: integer read FSuperDiag write SetSuperDiag default 0; (*Sets/reads the number of subdiagonals in banded matrices. *) property SubDiag: integer read FSubDiag write SetSubDiag default 0; (*Determine which part (upper or lower) of the symmetric, hermitian or triangular matrix is set. Determine which part (upper or lower) of the symmetric, hermitian or triangular matrix is set. *) property TriangleForm: TTriangleForm read FTriangleForm write SetTriangleForm default tfUpper; (*Determine, if the matrix is unit triangular. Determine, if the matrix is unit triangular. *) property TriangleUnit: boolean read FTriangleUnit write SetTriangleUnit default false; end; TMtxArray = array of TMtx; TVecArray = array of TVec; (*List of TMtx objects. List of objects. The list manages the object list. The TMtx objects are created and destroyed by the list. List size can be controled with the Count property. *) TMtxList = class(TObjectsList) private function GetItems(i: integer): TMtx; procedure SetItems(i: integer; const Value: TMtx); procedure SetCount(const Value: integer); reintroduce; function GetCount: integer; reintroduce; public (*Creates and adds a new TMtx object to the list. The function returns the Index at which the newly created object resides in the list. *) function Add: integer; virtual; (*Assigns the source to the calling object. All the data is copied. *) procedure Assign(Source: TMtxList); virtual; destructor Destroy; override; procedure SaveToStream(Stream: TStream); overload; virtual; procedure LoadFromStream(Stream: TStream); overload; virtual; property Item[i: integer]: TMtx read GetItems write SetItems; default; property Count: integer read GetCount write SetCount; end; (*List of TVec objects. List of objects. The list manages the object list. The TVec objects are created and destroyed by the list. List size can be controled with the Count property. Items can be added which already exist with Add(src), by calling Add() method or by setting Count property. *) TVecList = class(TObjectsList) strict private function GetItems(i: integer): TVec; procedure SetItems(i: integer; const Value: TVec); procedure SetCount(const Value: integer); reintroduce; function GetCount: integer; reintroduce; public (*Uses all list elements to form columns of the Dst Matrix. All TVec list elements must have the same number of elements. The number of columns will match the number of vectors. *) procedure ComposeColumnMatrix(const Dst: TMtx); (*Uses all list elements to form rows of the Dst Matrix. All TVec list elements must have the same number of elements. The number of rows will match the number of vectors. *) procedure ComposeRowMatrix(const Dst: TMtx); (*Copies all columns to the list of vectors. The number of columns will match the number of vectors. *) procedure DecomposeColumnMatrix(const Src: TMtx); (*Copies all rows to the list of vectors. The number of rows will match the number of vectors. *) procedure DecomposeRowMatrix(const Src: TMtx); (*Subranges all rows from the Src Matrix with vectors from the list.*) procedure SetSubRange(const Src: TMtx); (*Calls SetFullRange on each of the list elements.*) procedure SetFullRange; (*Creates and adds a new TVec object to the list. The function returns the Index at which the newly created object resides in the list. *) function Add: integer; overload; virtual; (*Creates and adds a new TVec object to the list. The function returns the Index at which the object resides in the list. *) function Add(const Src: TVec): integer; overload; virtual; (*Assigns the source to the calling object. All the data is copied. *) procedure Assign(Source: TVecList); virtual; destructor Destroy; override; (*Save the list to a stream.*) procedure SaveToStream(const Stream: TStream); overload; virtual; (*Load the list from a stream.*) procedure LoadFromStream(const Stream: TStream); overload; virtual; property Item[i: integer]: TVec read GetItems write SetItems; default; property Count: integer read GetCount write SetCount; end; (*The report printer. The most common way to debug an algorithm in the old days was to print the values of the variables to the screen or to the file. Today it is more common to use watches and tooltips to examine the values of variables. In some cases this two approaches do not work because of multithreading. Sometimes it is also desirable to have an algorithm return report on its convergence, like it is the case with optimization algorithms. For cases like this there is a global variable called Report declared in MtxVec.pas unit. Report is of a TMtxVecReport type and is derived from TStringStream. It has been extended with several new methods to support: * Saving the stream to TStream or a file. * Write the contents of TVec and TMtx objects to the stream (as text). * Specify the text formatting of the floating point values. *) TMtxVecReport = class( TStringStream ) strict private FImFormat: string; FReFormat: string; StrList: TStringList; FDelimiter: string; procedure SetImFormat(const Value: string); procedure SetReFormat(const Value: string); procedure SetDelimiter(const Value: string); procedure StrListClear; public (*Save the strings to a stream.*) procedure SaveToStream(Dst: TStream); overload; virtual; procedure WriteString(const aStrings: TStringList); overload; (*Save the strings to a text file.*) procedure SaveToFile(const FileName: string; Append: boolean = false); (*Convert the values of TVec and TMtx objects to text. Adds them to stream. Names parameter is an open array that can hold the names of variables in the MtxVecs list. *) procedure Print(const MtxVecs: array of TMtxVec; const Names: array of string); overload; (*Convert the values of TVec objects to text. Adds them to stream. Names parameter is an open array that can hold the names of variables in the vecs list. *) procedure PrintVec(const vecs: array of TVec; const Names: array of string); virtual; (*Convert the values of TMtx objects to text. Adds them to stream. Names parameter is an open array that can hold the names of variables in the mtxs list. *) procedure PrintMtx(const mtxs: array of TMtx; const Names: array of string); virtual; (*Convert TCplx values to text. Adds them to stream. Names parameter is an open array that can hold the names of variables in the mtxs list. *) procedure PrintCplx(const cplxs: array of TCplx; const Names: array of string); virtual; procedure PrintSCplx(const cplxs: array of TSCplx; const Names: array of string); virtual; (*Convert double values to text. Adds them to stream. Names parameter is an open array that can hold the names of variables in the mtxs list. *) procedure PrintSample(const val: array of double; const Names: array of string); virtual; procedure PrintDouble(const val: array of double; const Names: array of string); virtual; procedure PrintSingle(const val: array of single; const Names: array of string); virtual; (*Convert an array of double values to text. Adds them to stream. Names parameter can hold the name of the array variable. *) procedure PrintSampleArray(const val: array of double; const aName: string); virtual; (*Convert an array of TCplx values to text. Adds them to stream. Names parameter can hold the name of the array variable. *) procedure PrintCplxArray(const val: array of TCplx; const aName: string); virtual; (*Inserts a new line.*) procedure NewLine; (*Inserts a new line.*) procedure WriteLine; (*Clears the stream.*) procedure Clear; constructor Create(Astring: string); virtual; destructor Destroy; override; (*The format specifier for the real part of the complex number.*) property ReFormat: string read FReFormat write SetReFormat; (*The format specifier for the imaginary part of the complex number.*) property ImFormat: string read FImFormat write SetImFormat; (*Delimiter used when converting matrices to text.*) property Delimiter: string read FDelimiter write SetDelimiter; end; TVecRecord = record Vec: TVec; Used: boolean; end; TMtxRecord = record Mtx: TMtx; Used: boolean; end; TCacheVec = array of TVecRecord; TCacheMtx = array of TMtxRecord; (*Sets threading mode used by MtxVec.*) TMklThreadingMode = ( (*Threading is disabled.*) ttSerial, (*Threading is agressive. To reduce thread switching time, threads never enter sleep state and continue running empty until new job is given. This consumes all CPU resources and gives best performance. This is not suitable, if there are any other applications to be run on the same computer, because CPU will be completely consumed by one application.*) ttTurnAround, (*Threading is balanced. To reduce thread switching time, but also reduce CPU load, threads enter sleep state after specified time if no new job is given. This can consume a lot CPU resources, if the wait time before entering the sleep is larger than 0. While threads wait they consume all available CPU resources. By default, the time before sleeping is 0.*) ttThroughput); TVecCache = class(TAbstractMtxVecCache) public DoubleCacheOffset: TIntegerArray; DoubleCachePointers: T2DDoubleArray; CplxDoubleCacheOffset: TIntegerArray; CplxDoubleCachePointers: T2DCplxDoubleArray; SingleCacheOffset: TIntegerArray; SingleCachePointers: T2DSingleArray; CplxSingleCacheOffset: TIntegerArray; CplxSingleCachePointers: T2DCplxSingleArray; strict protected SingleCache: TSingleArray; DoubleCache: TDoubleArray; function NewItem: TMtxVecBase; override; procedure CacheMemFree; override; function GetCacheInBytes: Int64; override; procedure CacheMemAllocate(ItemCount, Elements: integer); override; end; TMtxCache = class(TAbstractMtxVecCache) public DoubleCacheOffset: TIntegerArray; DoubleCachePointers: T2DDoubleArray; CplxDoubleCacheOffset: TIntegerArray; CplxDoubleCachePointers: T2DCplxDoubleArray; SingleCacheOffset: TIntegerArray; SingleCachePointers: T2DSingleArray; CplxSingleCacheOffset: TIntegerArray; CplxSingleCachePointers: T2DCplxSingleArray; strict protected SingleCache: TSingleArray; DoubleCache: TDoubleArray; function NewItem: TMtxVecBase; override; procedure CacheMemFree; override; function GetCacheInBytes: Int64; override; procedure CacheMemAllocate(ItemCount, Elements: integer); override; end; TMtxVecPoolItem = class(TPersistent) strict protected fIsUsed: integer; fThreadID: TThreadID; fPoolIndex: integer; cs: TCriticalSection; procedure SetThreadID(Value: TThreadID); procedure SetPoolIndex(Value: integer); procedure SetIsUsed(Value: boolean); function GetIsUsed: boolean; public Vec: TVecCache; VecInt: TVecIntCache; Mtx: TMtxCache; MtxInt: TMtxIntCache; procedure Enter; overload; procedure Leave; overload; function TryEnter: boolean; function CacheUsed: boolean; property ThreadID: TThreadID read fThreadID write SetThreadID; property PoolIndex: integer read fPoolIndex write SetPoolIndex; property IsUsed: boolean read GetIsUsed write SetIsUsed; constructor Create; destructor Destroy; override; end; TMtxVecPoolItemArray = array of TMtxVecPoolItem; TSmallMatrixMultiplyArray = array of TSmallMatrixMultiply; TMtxMulJitCache = class(TPersistent) private cs: TCriticalSection; sKernel: TSmallMatrixMultiplyArray; dKernel: TSmallMatrixMultiplyArray; cKernel: TSmallMatrixMultiplyArray; zKernel: TSmallMatrixMultiplyArray; sKernelTransp: TSmallMatrixMultiplyArray; dKernelTransp: TSmallMatrixMultiplyArray; cKernelTransp: TSmallMatrixMultiplyArray; zKernelTransp: TSmallMatrixMultiplyArray; fSize: integer; procedure SetSize(const Value: integer); public function GetSKernel(mSize: integer): TSmallMatrixMultiply; function GetDKernel(mSize: integer): TSmallMatrixMultiply; function GetCKernel(mSize: integer): TSmallMatrixMultiply; function GetZKernel(mSize: integer): TSmallMatrixMultiply; function GetSKernelTransp(mSize: integer): TSmallMatrixMultiply; function GetDKernelTransp(mSize: integer): TSmallMatrixMultiply; function GetCKernelTransp(mSize: integer): TSmallMatrixMultiply; function GetZKernelTransp(mSize: integer): TSmallMatrixMultiply; property Size: integer read fSize write SetSize; procedure Enter; procedure Leave; constructor Create; destructor Destroy; override; end; (*Controlls the object cache and threading logic. Provides multi-threading functions for MtxVec.*) TMtxVecController = class(TPersistent) strict private fThreadDimension: integer; FDenormalsAreZero: boolean; FThreadingMode: TMklThreadingMode; FThreadWaitBeforeSleep: integer; MainThreadID: TThreadID; fSuperConductive: boolean; fCacheLevel1: integer; fCacheLevel2: integer; fCacheLevel3: integer; fCPUCoresPhysical: integer; fCPUCoresLogical: integer; fCPUCoresPhysicalPerNuma: integer; fCPUCacheSizeInBytes: integer; fNumaNodes: integer; fCPUVendor: string; csLock: Byte; function GetFFTDescriptorCacheSize: integer; procedure SetFFTDescriptorCacheSize(const value: integer); function GetThreadCount: integer; procedure SetThreadCount(const Value: integer); function GetLapackThreadCount: integer; procedure SetLapackThreadCount(const Value: integer); function GetBlasThreadCount: integer; procedure SetBlasThreadCount(const Value: integer); function GetIppThreadCount: integer; procedure SetIppThreadCount(const Value: integer); function GetVmlThreadCount: integer; procedure SetVmlThreadCount(const Value: integer); function GetFFTThreadCount: integer; procedure SetFFTThreadCount(const Value: integer); function GetCpuFrequencyInMhz: integer; function GetCpuType: integer; procedure SetDenormalsAreZero(const Value: boolean); procedure SetThreadingMode(const Value: TMklThreadingMode); procedure SetThreadWaitBeforeSleep(const Value: integer); procedure SetThreadDimension(const Value: integer); procedure SetSuperConductive(const Value: boolean); strict protected procedure UnMarkThreads; procedure Enter; procedure MarkMainThread; procedure Leave; procedure FreeMKLMemory; public procedure FreeItx(var a: TMtx); overload; procedure FreeItx(var a: TVec); overload; procedure FreeItx(var a: TVecInt); overload; procedure FreeItx(var a: TMtxInt); overload; procedure CreateItx(var a: TMtx); overload; procedure CreateItx(var a: TVec); overload; procedure CreateItx(var a: TVecInt); overload; procedure CreateItx(var a: TMtxInt); overload; function GetPoolIndex: integer; procedure DoMarkThread(Sender: TObject); procedure DoUnMarkThread(Sender: TObject); public Pool: TMtxVecPoolItemArray; JitCache: TMtxMulJitCache; (* Specifies the maximum number of threads that object cache can serve. Specifies maximum number of threads that object cache can serve concurrently. Each thread has its own memory pool. UnMarkThread must be called before a thread ends. Creating more threads than ThreadDimension will route additoinal threads in to the main threads pool. Before changing ThreadDimension the object cache may not be used: There may not be any TVec/TVecInt/TMtx/TMtxInt objects for which FreeIt was not called. *) property ThreadDimension: integer read FThreadDimension write SetThreadDimension; (* If true, the denormals will be rounded to 0. Denomormals are values close the maximum floating point range. *) property DenormalsAreZero: boolean read FDenormalsAreZero write SetDenormalsAreZero; (* Specifies the threading for MtxVec. *) property ThreadingMode: TMklThreadingMode read FThreadingMode write SetThreadingMode; (* Specifies the thread waiting time before entering sleep in ms. Used only when ThreadingMode is equal to ttThroughput. A value larger than zero can lead to excessive CPU usage, with only minor improvements in processing speed. *) property ThreadWaitBeforeSleep: integer read FThreadWaitBeforeSleep write SetThreadWaitBeforeSleep; (* Returns the CPU type. *) property CpuType: integer read GetCpuType; (* Specifies the number of CPU cores to be used by the threaded algorithms internally. Returns and allows setting thread count only for the Intel IPP algorithms related code. If you want to do multi-threading in your own code, set this parameter to 1. The default value is 1 and user side multi-threading is assumed *) property IppThreadCount: integer read GetIppThreadCount write SetIppThreadCount; (* Specifies the number of CPU cores to be used by the threaded algorithms internally. Returns and allows setting thread count only for the FFT algorithm related code. If you want to do multi-threading in your own code, set this parameter to 1. The default value is 1 and user side multi-threading is assumed. *) property FftThreadCount: integer read GetFftThreadCount write SetFftThreadCount; (* Specifies the number of CPU cores to be used by the threaded algorithms internally. Returns and allows setting thread count only for the Intel MKL Lapack algorithms related code. If you want to do multi-threading in your own code, set this parameter to 1. The default value is 1 and user side multi-threading is assumed. *) property BlasThreadCount: integer read GetBlasThreadCount write SetBlasThreadCount; (* Specifies the number of CPU cores to be used by the threaded algorithms internally. Returns and allows setting thread count only for the Intel MKL Lapack algorithms related code. If you want to do multi-threading in your own code, set this parameter to 1. The default value is 1 and user side multi-threading is assumed. *) property LapackThreadCount: integer read GetLapackThreadCount write SetLapackThreadCount; (* Specifies the number of CPU cores to be used by the threaded algorithms internally. Returns and allows setting thread count only for the Intel VML algorithms related code. If you want to do multi-threading in your own code, set this parameter to 1. The default value is 1 and user side multi-threading is assumed. *) property VmlThreadCount: integer read GetVmlThreadCount write SetVmlThreadCount; (* Specifies the number of CPU cores to be used by the threaded algorithms internally. Setting this property will modify IppThreadCount, FftThreadCount, LapackThreadCount and VmlThreadCount. If you want to do multi-threading in your own code, set this parameter to 1. The default value is 1 and user side multi-threading is assumed. *) property ThreadCount: integer read GetThreadCount write SetThreadCount; (* Returns CPU frequency in Mhz, but takes about 2s to execute. *) property CpuFrequencyInMhz: integer read GetCpuFrequencyInMhz; (* Returns the size of the CPU L3 cache in bytes. *) property CpuCacheSizeInBytes: integer read fCPUCacheSizeInBytes; (* Returns the size of the CPU L1 cache in bytes per CPU Core. *) property CpuCacheL1SizeInBytes: integer read fCacheLevel1; (* Returns the size of the CPU L2 cache in bytes per CPU Core. *) property CpuCacheL2SizeInBytes: integer read fCacheLevel2; (* Returns the size of the CPU L3 cache in bytes across all CPU cores. *) property CpuCacheL3SizeInBytes: integer read fCacheLevel3; (* Returns the number of physical CPU cores per one Numa Node. This value defines the default MtxVec pool thread size and the ThreadDimension property. The OS scheduler will schedule threads on the same socket on which the memory is allocated. Embarcadero RAD Studio currently does not support memory allocation on a different NUMA node (December 2024). While it is possible to specify ThreadCount and ThreadDimension properties to be more than CPUCores on multi-socket systems, the performance benefits could be modest. Each time a thread enters sleep, it could wake up on a different CPU core (invalidating CPU cache) and also a different NUMA node (invalidating main memory), if thread affinity is not specified explicitely. *) property CpuCores: integer read fCPUCoresPhysicalPerNuma; (* Returns the number of physical CPU cores across all NUMA nodes. *) property CpuCoresPhysical: integer read fCPUCoresPhysical; (* Returns the number of (hyper-threaded) CPU cores across all NUMA nodes. *) property CpuCoresLogical: integer read fCPUCoresLogical; (* Returns the number of NUMA nodes (CPU sockets) in the system. *) property CpuNumaNodes: integer read fNumaNodes; (* Specifies the numbe of FFT algorithm setups (descriptors) to keep stored in memory. When a descriptor or algorithm setup for a particular FFT size and type already exists, the computation of the FFT can be much (3-5x) faster. However, if the number of different FFT sizes and consequently descriptors is too big, the system can run out of memory. Notice also that FFT's of lengths other than power of two, can be 3-5x slower. As a guideline, allocating 100 descriptors for different (1D) FFT sizes in range from 39600 to 40000 will require around 300MBytes of memory. The bigger the FFT's that you compute, the smaller must be the descriptor cache size and fewer different FFT sizes should be computed to keep the performance level high. Note: This property should not be changed while there are FFT's being executed! *) property FFTDescriptorCacheSize: integer read GetFFTDescriptorCacheSize write SetFFTDescriptorCacheSize; (* Enables thread congestion free CreateIt/FreeIt. Enabled by default. *) property SuperConductive: boolean read FSuperCOnductive write SetSuperConductive; (*CPU Vendor name. Intel or AMD. *) property CPUVendor: string read FCPUVendor; (*Setting condition check to false, will disable all range checks.*) procedure SetMtxConditionCheck(Value: boolean); overload; (*Setting condition check to false, will disable all range checks.*) procedure SetVecConditionCheck(Value: boolean); overload; (*Defines the object cache size for vectors. Elements defines the number of elements per vector to preallocate. *) procedure SetVecCacheSize(Vectors, Elements: integer); (*Defines the object cache size for vectors. Elements defines the number of elements per matrix to preallocate. *) procedure SetMtxCacheSize(Matrices, Elements: integer); (*Defines the object cache size for integervectors. Elements defines the number of elements per matrix to preallocate. *) procedure SetMtxIntCacheSize(Matrices, Elements: integer); (*Defines the object cache size for integervectors. Elements defines the number of elements per matrix to preallocate. *) procedure SetVecIntCacheSize(Vectors, Elements: integer); (* When thread has finished using object cache, release it. When threads are using object cache each thread must call UnMarkThread after all objects have been released back to object cache and before the thread finished executing. *) procedure UnMarkThread; overload; procedure UnMarkThread(const PoolIdx: integer); overload; (* Associates calling thread with object cache super conducting logic. Call this before using object cache within the thread. Once all objects have been released back to object cache and before the thread finished executing call UnMarkThread. *) function MarkThread: boolean; (* Returns the number of unused thread dimensions. Thread dimensions are slots used one per thread. The function returns the number of threads that can still be associated with the object cache to make use of super conducting memory allocation logic. *) function UnusedThreadDimension: integer; constructor Create; destructor Destroy; override; end; (* Provides interface for multiplying small matrices by using the lapack's dgemm api standard.) The matrix multiplication code is generated on the fly to achieve maximum possible performance. Additionally all the error checking on each consecutive call is also absent. This is most usefull, when the matrices to be multiplied are very small: 2x2 or 3x3, (100x) but there are still considerable benefits up to size 50x50 (1.3x) and more. Typically this object would be created, then Init method is to be called and finally, one of the six Mul methods can be called multiple times.The class provides four variants of Multiply methods: Mul(a,b,c: TMtx); Mul; MulKernel MulKernelFloat, MulKernelDouble, MulKernelComplexFloat, MulKernelComplexDouble It is most safe to use the first variant. Performance will increase with the parameterless Mul method (2x) and best performance can be obtained with the third variant (3x). Only switch to using the third variant when you are confident, that your algorithm works correctly. Please note that TMtx.Mul(A,B); will use object cache to store JIT-ed kernels up to user specified matrix size for square matrices. The default limit is set at size 32x32. The kernel will be created on first call. Three different options to setup matrix multiplication of small matrices uses MtxVec, MtxExpr, Math387; procedure TForm84.Button2Click(Sender: TObject); var am, bm, cm, cmRef: Matrix; jit: TSmallMatrixMultiply; a,b,c: TDoubleArray; begin jit := TSmallMatrixMultiply.Create; try am := [ [1 , 2], [2 , 3] ]; bm := [ [0.5, 1.5], [2.5, 3.5] ]; // Compute with TMtx cmRef.Mul(am, bm); //standard method optimized for large matrices jit.Init(am, bm, cm, opNone, opNone, 1, 0); // Option 1: jit.Mul; //reuse memory allocation by am, cm and bm if not cmRef.Equal(cm) then ERaise('Problem'); // Option 2: jit.Mul(am, bm, cm); // am, cm, bm can use different memory on each call, but a bit slower if not cmRef.Equal(cm) then ERaise('Problem'); // Option 3: a := [1 , 2, 2 , 3]; b := [ 0.5, 1.5, 2.5, 3.5 ]; jit.Init(2, 2, 2, 2, mvDouble, opNone, opNone, 1, 0); SetLength(c, 4); //allocate storage to hold the result jit.MulKernelDouble(jit.Jitter, a, b, c); if not cmRef.Equal(cm) then ERaise('Problem'); //alternative finally jit.Free; end; end; *) TSmallMatrixMultiply = class private FloatPrecision: TMtxFloatPrecision; ap, bp, cp: PAPointer; IsInit: boolean; JitKernel: PAPointer; calpha, cbeta: TSCplx; zalpha, zbeta: TCplx; fcRows: integer; fcCols: integer; faRows: integer; faCols: integer; fbRows: integer; fbCols: integer; faOp: TMtxOperation; fbOp: TMtxOperation; public (* Jitted code pointer. Do not overwrite. To be passed to MulFloat, MulDouble, MulFloatComplex, MulDoubleComplex *) Jitter: PAPointer; (* Function pointer to the jitted multiplication kernel. The first parameter must be the Jitter field of this object. The A, B and C parameters are pointers to the first element of the dense matrix storage (not jagged or other) and can vary between calls. It is at least 3x faster as the Delphi unrolled loop matrix multiply even for 2x2 matrices. *) MulKernel: Tgemm_jit_kernel_tp; (* Function pointer to the single precision jitted multiplication kernel. This pointer is not nil, if the Init routine was called with matrix A,B and C.FloatPrecision set to mvSingle. The first parameter must be the Jitter field of this object. The A, B and C parameters are pointers to the first element of the dense matrix storage (not jagged or other) and can vary between calls. It is at least 3x faster as the Delphi unrolled loop matrix multiply. *) MulKernelFloat: Tsgemm_jit_kernel_t; (* Function pointer to the complex single precision jitted multiplication kernel. This pointer is not nil, if the Init routine was called with matrix A, B and C.FloatPrecision set to mvSingleComplex. The first parameter must be the Jitter field of this object. The A, B and C parameters are pointers to the first element of the dense matrix storage (not jagged or other) and can vary between calls. It is at least 3x faster as the Delphi unrolled loop matrix multiply even for 2x2 matrices. *) MulKernelComplexFloat: Tcgemm_jit_kernel_t; (* Function pointer to the double precision jitted multiplication kernel. This pointer is not nil, if the Init routine was called with matrix A, B and C.FloatPrecision set to mvDouble. The first parameter must be the Jitter field of this object. The A, B and C parameters are pointers to the first element of the dense matrix storage (not jagged or other) and can vary between calls. It is at least 3x faster as the Delphi unrolled loop matrix multiply even for 2x2 matrices. *) MulKernelDouble: Tdgemm_jit_kernel_t; (* Function pointer to the complex double precision jitted multiplication kernel. This pointer is not nil, if the Init routine was called with matrix A, B and C.FloatPrecision set to mvDoubleComplex. The first parameter must be the Jitter field of this object. The A, B and C parameters are pointers to the first element of the dense matrix storage (not jagged or other) and can vary between calls. It is at least 4x faster as the Delphi unrolled loop matrix multiply even for 2x2 matrices. *) MulKernelComplexDouble: Tzgemm_jit_kernel_t; (* Frees the internally jitted kernel *) procedure FreeKernel; (* Initialize matrix multiplication Initializes computation of: C = alpha*opA(A)*opB(B) + beta*C The procedure will initialize matrix multiplication and create in-memory code specifically designed to multiply exactly these matrices with the specified operators. (just-in-time compilation). This design makes the performance efficient multiplication of "small" matrices possible. To perform actual multiplication call one of the Mul methods of this object. The matrices passed must unconditionally match the parameters (size and layout) as they had when they were passed to this (Init) routine. The parameterless Mul routine assumes also the same memory locations at which matrices A, B and C store their data and is slightly faster than the alternative Mul method. This means, that A,B and C may not be resized after calling Init. Init can be called multiple times. Each call will overwrite the previous settings. The alpha and beta parameters are specified as complex type, but only the real part will be used when A, B and C are not complex. Returns true if JIT will be used and false otherwise. If the JIT will not be used standard dgemm routine will be called instead. The procedure of JIT compilation is about 1000x slower, than the actual multiply operation. The kernel(s) therefore must be prepared upfront. The Init routine is protected against initializing with same parameters again and will simply exit and reuse the existing kernel. Matrix A. Matrix B. Matrix C. Request matrix A transpose. Request matrix B transpose. Scaling factor. Scaling factor.*) function Init(const A, B, C: TMtx; opA: TMtxOperation; opB: TMtxOperation; const Alpha, Beta: TCplx): boolean; overload; (* Initialize matrix multiplication Initializes computation of: C = alpha*opA(A)*opB(B) + beta*C Returns true if JIT will be used and false otherwise. If the JIT will not be used standard dgemm routine will be called instead. The procedure of JIT compilation is about 1000x slower, than the actual multiply operation. The kernel(s) therefore must be prepared upfront. The Init routine is protected against initializing with same parameters again and will simply exit and reuse the existing kernel. Matrix A row count. Matrix A column count. Matrix B row count. Matrix B column count. Request matrix A transpose. Request matrix B transpose. Scaling factor. Scaling factor. The storage precision of all three matrices, A, B and C.*) function Init(const ARows, ACols, BRows, BCols: integer; aFloatPrecision: TMtxFloatPrecision; opA, opB: TMtxOperation; const Alpha, Beta: double): boolean; overload; (* Initialize matrix multiplication Initializes computation of: C = alpha*opA(A)*opB(B) + beta*C Returns true if JIT will be used and false otherwise. If the JIT will not be used, the standard dgemm routine will be called instead. The procedure of JIT compilation is about 1000x slower, than the actual multiply operation. The kernel(s) therefore must be prepared upfront. The Init routine is protected against initializing with same parameters again and will simply exit and reuse the existing kernel. Matrix A row count. Matrix A column count. Matrix B row count. Matrix B column count. Request matrix A transpose. Request matrix B transpose. Scaling factor. Scaling factor. The storage precision of all three matrices, A, B and C.*) function Init(const ARows, ACols, BRows, BCols: integer; aFloatPrecision: TMtxFloatPrecision; opA, opB: TMtxOperation; const Alpha, Beta: TCplx): boolean; overload; (* Initialize matrix multiplication Initializes computation of: C = alpha*opA(A)*opB(B) + beta*C The procedure will initialize matrix multiplication and create in-memory code specifically designed to multiply exactly these matrices with the specified operators. (just-in-time compilation). This design makes the performance efficient multiplication of "small" matrices possible. To perform actual multiplication call one of the Mul methods of this object. The matrices passed must unconditionally match the parameters (size and layout) as they had when they were passed to this (Init) routine. The parameterless Mul routine assumes also the same memory locations at which matrices A, B and C store their data and is slightly faster than the alternative Mul method. This means, that A,B and C may not be resized after calling Init. Init can be called multiple times. Each call will overwrite the previous settings. The alpha and beta parameters are specified as complex type, but only the real part will be used when A, B and C are not complex. The Init routine is protected against initializing with same parameters again and will simply exit and reuse the existing kernel. Returns true if JIT will be used and false otherwise. If the JIT will not be used standard dgemm routine will be called instead. The procedure of JIT compilation is about 1000x slower, than the actual multiply operation. Matrix A. Matrix B. Matrix C. Request matrix A transpose. Request matrix B transpose. Scaling factor. Scaling factor.*) function Init(const A, B, C: TMtx; opA: TMtxOperation; opB: TMtxOperation; const Alpha, Beta: double): boolean; overload; (* Performs matrix multiplication optimized for small matrices Computes: C = alpha*opA(A)*opB(B) + beta*C The operation must first be initialized with a call to the Init method. This means, that A,B and C may not be have a different size than when calling Init. Their size however can change in between the calls. This routine performs no error checking! Any error checking is performed during the call to the Init routine. The method is about 3x slower than the jit.Mul; overload; It is about 4x slower than calling jit.MulKernelDouble(jit.jitter, a,b,c); function It is equally fast as the Delphi unrolled loop matrix multiply. *) procedure Mul(const A,B,C: TMtx); overload; (* Performs matrix multiplication optimized for small matrices Computes: C = alpha*opA(A)*opB(B) + beta*C The operation must first be initialized with a call to the Init method. The method will use the memory locations of parameters A,B and C passed to the Init routine. This means, that A,B and C may not be resized after calling Init even if they restore the size and layout before calling this routine. There is no other dependence and all objects can be free independently. Calling TMtx.Size multiple times will not trigger a resize or memory allocation unless the size has changed. This routine performs no error checking! Any error checking is performed during the call to the Init routine. The method is about 2x faster than the jit.Mul(a,b,c) overload; It is about 1.3% slower than calling jit.MulKernelDouble(jit.jitter, a,b,c); function It is 3x faster than the Delphi's unrolled-loop matrix multiply. *) procedure Mul; overload; inline; (* The object is required to be freed manually. *) destructor Destroy; override; (* Field computed by Init method. Holds the row count of the matrix to hold the result. *) property cRows: integer read fcRows; (* Field computed by Init method. Holds the row count of the matrix to hold the result. *) property cCols: integer read fcCols; end; (* Generic thread object which can work with object cache. Use this thread type when objects obtained from object cache via Createit/FreeIt are used by the thread. Using this thread type will result in super conductive memory manager avoiding all thread contention allowing perfect parallelism, but only if default memory manager is not used at all or very sparingly within the thread. This thread object simply calls TMtxVecController.UnMarkThread before the thread terminates. *) TMtxThreadInternal = class(TThread) strict private fOnExecute: TNotifyEvent; protected procedure Execute; override; procedure SuperExecute; virtual; procedure SetOnExecute(const Value: TNotifyEvent); public property OnExecute: TNotifyEvent read FOnExecute write SetOnExecute; end; TMtxThread = class(TMtxThreadInternal) protected procedure Execute; reintroduce; end; TVecDouble = TVec; TMtxDouble = TMtx; (*Releases objects back to the object cache. Releases objects back to the object cache and sets the parameters to nil. If the parameters were not from the object cache, they are destroyed. *) procedure FreeIt(var a,b,c,d: TMtx); overload; (*Release three matrices.*) procedure FreeIt(var a,b,c: TMtx); overload; (*Release two matrices.*) procedure FreeIt(var a,b: TMtx); overload; (*Release one matrix.*) procedure FreeIt(var a: TMtx); overload; (*Releases objects back to the object cache. Releases objects back to the object cache and sets the parameters to nil. If the parameters were not from the object cache, they are destroyed. *) procedure FreeIt(var a,b,c,d: TVec); overload; (*Release three vectors.*) procedure FreeIt(var a,b,c: TVec); overload; (*Release two vectors.*) procedure FreeIt(var a,b: TVec); overload; (*Release one vector.*) procedure FreeIt(var a: TVec); overload; (*Obtains an object from the object cache. Obtains an object from the object cache. *) function CreateIt: TVec; overload; (*Obtains a TVec object from the object cache. Obtains a TVec object from the object cache. If the cache is used, it creates a new object. To release an object from the cache, use *) procedure CreateIt(out a: TVec); overload; (*Obtains two TVec objects from the object cache.*) procedure CreateIt(out a,b: TVec); overload; (*Obtains three TVec objects from the object cache.*) procedure CreateIt(out a,b,c: TVec); overload; (*Obtains four TVec objects from the object cache.*) procedure CreateIt(out a,b,c,d: TVec); overload; (*Obtains a TMtx object from the object cache. Obtains a TMtx object from the object cache. If the cache is used, it creates a new object. To release an object from the cache, use *) procedure CreateIt(out a: TMtx); overload; (*Obtains two TMtx objects from the object cache.*) procedure CreateIt(out a,b: TMtx); overload; (*Obtains three TMtx objects from the object cache.*) procedure CreateIt(out a,b,c: TMtx); overload; (*Obtains four TMtx objects from the object cache.*) procedure CreateIt(out a,b,c,d: TMtx); overload; (*Raises exception if PAPointer is nil. Raises exception any of the PAPointer variables is nil. var a,b: TVec; begin a := TVec.Create; b := TVec.Create; try // ... finally a.Free; end; TestNil(a,b); *) procedure TestNil(a,b,c,d: PAPointer); overload; (*Test three pointers, if they are nil.*) procedure TestNil(a,b,c: PAPointer); overload; (*Test two pointers, if they are nil.*) procedure TestNil(a,b: PAPointer); overload; (*Test one pointer, if it equals nil.*) procedure TestNil(a: PAPointer); overload; (*Dereferences a pointer to TMtxVec memory. Dereferences pointer's to memory of four TMtx objects. It constructs a 2D jagged floating point array. The range checks must be off, when working on this array. The array's must be "cleaned up" by passing them to DismissIt before the routine ends. Special care must be given not to destroy the objects that were dereferenced, before the arrays are freed. Note Under .NET this command simply copies data from objects to the arrays. *) procedure Enlist(a,b,c,d: TMtx; var ap,bp,cp,dp: T2DDoubleArray); overload; (*Dereferences (.NET copies) pointer's to memory of three TMtx objects.*) procedure Enlist(a,b,c: TMtx; var ap,bp,cp: T2DDoubleArray); overload; (*Dereferences (.NET copies) pointer's to memory of two TMtx objects.*) procedure Enlist(a,b: TMtx; var ap,bp: T2DDoubleArray); overload; (*Dereferences (.NET copies) a pointer to memory of a TMtx object.*) procedure Enlist(a: TMtx; var ap: T2DDoubleArray); overload; procedure Enlist(a,b,c,d: TMtx; var ap,bp,cp,dp: T2DSingleArray); overload; (*Dereferences (.NET copies) pointer's to memory of three TMtx objects.*) procedure Enlist(a,b,c: TMtx; var ap,bp,cp: T2DSingleArray); overload; (*Dereferences (.NET copies) pointer's to memory of two TMtx objects.*) procedure Enlist(a,b: TMtx; var ap,bp: T2DSingleArray); overload; (*Dereferences (.NET copies) a pointer to memory of a TMtx object.*) procedure Enlist(a: TMtx; var ap: T2DSingleArray); overload; (*Dereferences a pointer to TMtxVec memory. Dereferences pointer's to memory of four TMtxVec objects. The range checking will work fine. The array's must be "cleaned up" by passing them to DismissIt before the routine ends.Special care must be given not to destroy the objects that were dereferenced, before the arrays are freed. Note Under .NET this command simply copies data from objects to the arrays. *) procedure Enlist(a,b,c,d: TMtxVec; var ap,bp,cp,dp: TDoubleArray); overload; (*Dereferences (.NET copies) pointer's to memory of three TMtxVec objects.*) procedure Enlist(a,b,c: TMtxVec; var ap,bp,cp: TDoubleArray); overload; (*Dereferences (.NET copies) pointer's to memory of two TMtxVec objects.*) procedure Enlist(a,b: TMtxVec; var ap,bp: TDoubleArray); overload; (*Dereferences (.NET copies) pointer to memory of one TMtxVec object.*) procedure Enlist(a: TMtxVec; var ap: TDoubleArray); overload; procedure Enlist(a,b,c,d: TMtxVec; var ap,bp,cp,dp: TSingleArray); overload; (*Dereferences (.NET copies) pointer's to memory of three TMtxVec objects.*) procedure Enlist(a,b,c: TMtxVec; var ap,bp,cp: TSingleArray); overload; (*Dereferences (.NET copies) pointer's to memory of two TMtxVec objects.*) procedure Enlist(a,b: TMtxVec; var ap,bp: TSingleArray); overload; (*Dereferences (.NET copies) pointer to memory of one TMtxVec object.*) procedure Enlist(a: TMtxVec; var ap: TSingleArray); overload; (*Dereferences (.NET copies) pointer's to memory of four TMtxVec objects as a jagged 2D array of complex numbers.*) procedure Enlist(a,b,c,d: TMtx; var ap,bp,cp,dp: T2DCplxArray); overload; (*Dereferences (.NET copies) pointer's to memory of three TMtxVec objects.*) procedure Enlist(a,b,c: TMtx; var ap,bp,cp: T2DCplxArray); overload; (*Dereferences (.NET copies) pointer's to memory of Two TMtxVec objects.*) procedure Enlist(a,b: TMtx; var ap,bp: T2DCplxArray); overload; (*Dereferences (.NET copies) pointer's to memory of TMtxVec object.*) procedure Enlist(a: TMtx; Var ap: T2DCplxArray); overload; (*Dereferences (.NET copies) pointer's to memory of three TMtxVec objects as an array of complex numbers. *) procedure Enlist(a,b,c,d: TMtxVec; var ap,bp,cp,dp: TCplxArray); overload; (*Dereferences (.NET copies) pointer's to memory of three TMtxVec objects.*) procedure Enlist(a,b,c: TMtxVec; var ap,bp,cp: TCplxArray); overload; (*Dereferences (.NET copies) pointer's to memory of two TMtxVec objects.*) procedure Enlist(a,b: TMtxVec; var ap,bp: TCplxArray); overload; (*Dereferences (.NET copies) pointer's to memory of TMtxVec object.*) procedure Enlist(a: TMtxVec; var ap: TCplxArray); overload; (*Dereferences (.NET copies) pointer's to memory of three TMtxVec objects as an array of complex numbers. *) procedure Enlist(a,b,c,d: TMtxVec; var ap,bp,cp,dp: TSCplxArray); overload; (*Dereferences (.NET copies) pointer's to memory of three TMtxVec objects.*) procedure Enlist(a,b,c: TMtxVec; var ap,bp,cp: TSCplxArray); overload; (*Dereferences (.NET copies) pointer's to memory of two TMtxVec objects.*) procedure Enlist(a,b: TMtxVec; var ap,bp: TSCplxArray); overload; (*Dereferences (.NET copies) pointer's to memory of TMtxVec object.*) procedure Enlist(a: TMtxVec; var ap: TSCplxArray); overload; (*Free arrays allocated with a call to Enlist. Free arrays allocated with a call to Enlist. The version taking TMtxVec as a parameter under .NET also copies the values from the array back to the object before freeing the array. This is usefull for writing code that can execute both under W32 and .NET. *) procedure DismissIt(var ap,bp,cp,dp: T2DDoubleArray); overload; (*Free three arrays allocated with a call to Enlist.*) procedure DismissIt(var ap,bp,cp: T2DDoubleArray); overload; (*Free two arrays allocated with a call to Enlist.*) procedure DismissIt(var ap,bp: T2DDoubleArray); overload; (*Free one array allocated with a call to Enlist.*) procedure DismissIt(var ap: T2DDoubleArray); overload; procedure DismissIt(var ap,bp,cp,dp: T2DSingleArray); overload; (*Free three arrays allocated with a call to Enlist.*) procedure DismissIt(var ap,bp,cp: T2DSingleArray); overload; (*Free two arrays allocated with a call to Enlist.*) procedure DismissIt(var ap,bp: T2DSingleArray); overload; (*Free one array allocated with a call to Enlist.*) procedure DismissIt(var ap: T2DSingleArray); overload; (*Free four arrays allocated with a call to Enlist.*) procedure DismissIt(var ap,bp,cp,dp: TDoubleArray); overload; (*Free three arrays allocated with a call to Enlist.*) procedure DismissIt(var ap,bp,cp: TDoubleArray); overload; (*Free two arrays allocated with a call to Enlist.*) procedure DismissIt(var ap,bp: TDoubleArray); overload; (*Free one array allocated with a call to Enlist.*) procedure DismissIt(var ap: TDoubleArray); overload; (*Free four arrays allocated with a call to Enlist.*) procedure DismissIt(var ap,bp,cp,dp: TSingleArray); overload; (*Free three arrays allocated with a call to Enlist.*) procedure DismissIt(var ap,bp,cp: TSingleArray); overload; (*Free two arrays allocated with a call to Enlist.*) procedure DismissIt(var ap,bp: TSingleArray); overload; (*Free one array allocated with a call to Enlist.*) procedure DismissIt(var ap: TSingleArray); overload; (*Free four arrays allocated with a call to Enlist.*) procedure DismissIt(var ap,bp,cp,dp: T2DCplxArray); overload; (*Free three arrays allocated with a call to Enlist.*) procedure DismissIt(var ap,bp,cp: T2DCplxArray); overload; (*Free two arrays allocated with a call to Enlist.*) procedure DismissIt(var ap,bp: T2DCplxArray); overload; (*Free one array allocated with a call to Enlist.*) procedure DismissIt(var ap: T2DCplxArray); overload; (*Free four arrays allocated with a call to Enlist.*) procedure DismissIt(var ap,bp,cp,dp: TCplxArray); overload; (*Free three arrays allocated with a call to Enlist.*) procedure DismissIt(var ap,bp,cp: TCplxArray); overload; (*Free two arrays allocated with a call to Enlist.*) procedure DismissIt(var ap,bp: TCplxArray); overload; (*Free one array allocated with a call to Enlist.*) procedure DismissIt(var ap: TCplxArray); overload; (*Free four arrays allocated with a call to Enlist.*) procedure DismissIt(var ap,bp,cp,dp: TSCplxArray); overload; (*Free three arrays allocated with a call to Enlist.*) procedure DismissIt(var ap,bp,cp: TSCplxArray); overload; (*Free two arrays allocated with a call to Enlist.*) procedure DismissIt(var ap,bp: TSCplxArray); overload; (*Free one array allocated with a call to Enlist.*) procedure DismissIt(var ap: TSCplxArray); overload; (*Free arrays allocated with a call to Enlist and under .NET also copy the contents of arrays back to the coresponding objects.*) procedure DismissIt(a,b,c,d: TMtx; var ap,bp,cp,dp: T2DDoubleArray); overload; (*Free three arrays allocated with a call to Enlist.*) procedure DismissIt(a,b,c: TMtx; var ap,bp,cp: T2DDoubleArray); overload; (*Free two arrays allocated with a call to Enlist.*) procedure DismissIt(a,b: TMtx; var ap,bp: T2DDoubleArray); overload; (*Free one array allocated with a call to Enlist.*) procedure DismissIt(a: TMtx; var ap: T2DDoubleArray); overload; (*Free arrays allocated with a call to Enlist and under .NET also copy the contents of arrays back to the coresponding objects.*) procedure DismissIt(a,b,c,d: TMtx; var ap,bp,cp,dp: T2DSingleArray); overload; (*Free three arrays allocated with a call to Enlist.*) procedure DismissIt(a,b,c: TMtx; var ap,bp,cp: T2DSingleArray); overload; (*Free two arrays allocated with a call to Enlist.*) procedure DismissIt(a,b: TMtx; var ap,bp: T2DSingleArray); overload; (*Free one array allocated with a call to Enlist.*) procedure DismissIt(a: TMtx; var ap: T2DSingleArray); overload; (*Free arrays allocated with a call to Enlist and under .NET also copy the contents of arrays back to the coresponding objects.*) procedure DismissIt(a,b,c,d: TMtxVec; var ap,bp,cp,dp: TDoubleArray); overload; (*Free three arrays allocated with a call to Enlist.*) procedure DismissIt(a,b,c: TMtxVec; var ap,bp,cp: TDoubleArray); overload; (*Free two arrays allocated with a call to Enlist.*) procedure DismissIt(a,b: TMtxVec; var ap,bp: TDoubleArray); overload; (*Free one array allocated with a call to Enlist.*) procedure DismissIt(a: TMtxVec; var ap: TDoubleArray); overload; (*Free arrays allocated with a call to Enlist and under .NET also copy the contents of arrays back to the coresponding objects.*) procedure DismissIt(a,b,c,d: TMtxVec; var ap,bp,cp,dp: TSingleArray); overload; (*Free three arrays allocated with a call to Enlist.*) procedure DismissIt(a,b,c: TMtxVec; var ap,bp,cp: TSingleArray); overload; (*Free two arrays allocated with a call to Enlist.*) procedure DismissIt(a,b: TMtxVec; var ap,bp: TSingleArray); overload; (*Free one array allocated with a call to Enlist.*) procedure DismissIt(a: TMtxVec; var ap: TSingleArray); overload; (*Free arrays allocated with a call to Enlist and under .NET also copy the contents of arrays back to the coresponding objects.*) procedure DismissIt(a,b,c,d: TMtx; var ap,bp,cp,dp: T2DCplxArray); overload; (*Free three arrays allocated with a call to Enlist.*) procedure DismissIt(a,b,c: TMtx; var ap,bp,cp: T2DCplxArray); overload; (*Free two arrays allocated with a call to Enlist.*) procedure DismissIt(a,b: TMtx; var ap,bp: T2DCplxArray); overload; (*Free one array allocated with a call to Enlist.*) procedure DismissIt(a: TMtx; var ap: T2DCplxArray); overload; (*Free arrays allocated with a call to Enlist and under .NET also copy the contents of arrays back to the coresponding objects.*) procedure DismissIt(a,b,c,d: TMtxVec; var ap,bp,cp,dp: TCplxArray); overload; (*Free two arrays allocated with a call to Enlist.*) procedure DismissIt(a,b,c: TMtxVec; var ap,bp,cp: TCplxArray); overload; (*Free two arrays allocated with a call to Enlist.*) procedure DismissIt(a,b: TMtxVec; var ap,bp: TCplxArray); overload; (*Free one array allocated with a call to Enlist.*) procedure DismissIt(a: TMtxVec; var ap: TCplxArray); overload; (*Free arrays allocated with a call to Enlist and under .NET also copy the contents of arrays back to the coresponding objects.*) procedure DismissIt(a,b,c,d: TMtxVec; var ap,bp,cp,dp: TSCplxArray); overload; (*Free two arrays allocated with a call to Enlist.*) procedure DismissIt(a,b,c: TMtxVec; var ap,bp,cp: TSCplxArray); overload; (*Free two arrays allocated with a call to Enlist.*) procedure DismissIt(a,b: TMtxVec; var ap,bp: TSCplxArray); overload; (*Free one array allocated with a call to Enlist.*) procedure DismissIt(a: TMtxVec; var ap: TSCplxArray); overload; (*Dereferences a pointer to TMtxVec memory. Dereferences pointer's to memory of four TMtx objects. It constructs a 2D jagged floating point array. The range checks must be off, when working on this array. The array's must be "cleaned up" by passing them to DismissIt before the routine ends. Special care must be given not to destroy the objects that were dereferenced, before the arrays are freed. Note Under .NET this command only resizes the array to match the size of the objects. *) procedure EnlistIt(a,b,c,d: TMtx; out ap,bp,cp,dp: T2DCplxArray); overload; (*Dereferences (.NET sizes arrays only) pointer's to memory of three TMtxVec objects.*) procedure EnlistIt(a,b,c: TMtx; out ap,bp,cp: T2DCplxArray); overload; (*Dereferences (.NET sizes arrays only) pointer's to memory of two TMtxVec objects.*) procedure EnlistIt(a,b: TMtx; out ap,bp: T2DCplxArray); overload; (*Dereferences (.NET sizes the array only) pointer's to memory of TMtxVec object.*) procedure EnlistIt(a: TMtx; out ap: T2DCplxArray); overload; (*Dereferences (.NET sizes arrays only) pointer's to memory of four TMtxVec objects.*) procedure EnlistIt(a,b,c,d: TMtx; out ap,bp,cp,dp: T2DDoubleArray); overload; (*Dereferences (.NET sizes arrays only) pointer's to memory of three TMtxVec objects.*) procedure EnlistIt(a,b,c: TMtx; out ap,bp,cp: T2DDoubleArray); overload; (*Dereferences (.NET sizes arrays only) pointer's to memory of two TMtxVec objects.*) procedure EnlistIt(a,b: TMtx; out ap,bp: T2DDoubleArray); overload; (*Dereferences (.NET sizes the array only) pointer's to memory of TMtxVec object.*) procedure EnlistIt(a: TMtx; out ap: T2DDoubleArray); overload; (*Dereferences a pointer to TMtxVec memory. Dereferences pointer's to memory of four TMtxVec objects. The range checking will work fine. The array's must be "cleaned up" by passing them to DismissIt before the routine ends.Special care must be given not to destroy the objects that were dereferenced, before the arrays are freed. Note Under .NET this command only resizes the array to match the size of the objects. *) procedure EnlistIt(a,b,c,d: TMtxVec; out ap,bp,cp,dp: TCplxArray); overload; (*Dereferences (.NET sizes arrays only) pointer's to memory of three TMtxVec objects.*) procedure EnlistIt(a,b,c: TMtxVec; out ap,bp,cp: TCplxArray); overload; (*Dereferences (.NET sizes arrays only) pointer's to memory of two TMtxVec objects.*) procedure EnlistIt(a,b: TMtxVec; out ap,bp: TCplxArray); overload; (*Dereferences (.NET sizes arrays only) pointer's to memory of TMtxVec object.*) procedure EnlistIt(a: TMtxVec; out ap: TCplxArray); overload; procedure EnlistIt(a,b,c,d: TMtxVec; out ap,bp,cp,dp: TSCplxArray); overload; (*Dereferences (.NET sizes arrays only) pointer's to memory of three TMtxVec objects.*) procedure EnlistIt(a,b,c: TMtxVec; out ap,bp,cp: TSCplxArray); overload; (*Dereferences (.NET sizes arrays only) pointer's to memory of two TMtxVec objects.*) procedure EnlistIt(a,b: TMtxVec; out ap,bp: TSCplxArray); overload; (*Dereferences (.NET sizes arrays only) pointer's to memory of TMtxVec object.*) procedure EnlistIt(a: TMtxVec; out ap: TSCplxArray); overload; (*Dereferences (.NET sizes arrays only) pointer's to memory of four TMtxVec objects.*) procedure EnlistIt(a,b,c,d: TMtxVec; out ap,bp,cp,dp: TDoubleArray); overload; (*Dereferences (.NET sizes arrays only) pointer's to memory of three TMtxVec objects.*) procedure EnlistIt(a,b,c: TMtxVec; out ap,bp,cp: TDoubleArray); overload; (*Dereferences (.NET sizes arrays only) pointer's to memory of two TMtxVec objects.*) procedure EnlistIt(a,b: TMtxVec; out ap,bp: TDoubleArray); overload; (*Dereferences (.NET sizes the array only) pointer's to memory of TMtxVec object.*) procedure EnlistIt(a: TMtxVec; out ap: TDoubleArray); overload; (*Dereferences (.NET sizes arrays only) pointer's to memory of four TMtxVec objects.*) procedure EnlistIt(a,b,c,d: TMtxVec; out ap,bp,cp,dp: TSingleArray); overload; (*Dereferences (.NET sizes arrays only) pointer's to memory of three TMtxVec objects.*) procedure EnlistIt(a,b,c: TMtxVec; out ap,bp,cp: TSingleArray); overload; (*Dereferences (.NET sizes arrays only) pointer's to memory of two TMtxVec objects.*) procedure EnlistIt(a,b: TMtxVec; out ap,bp: TSingleArray); overload; (*Dereferences (.NET sizes the array only) pointer's to memory of TMtxVec object.*) procedure EnlistIt(a: TMtxVec; out ap: TSingleArray); overload; (*Computes the Median from the source data. *) function Median(const X: TDenseMtxVec): double; overload; (*Returns the maximum of the source data. *) function Maxc(const X: TDenseMtxVec): TCplx; overload; (*Returns the minimum of the source data. *) function Minc(const X: TDenseMtxVec): TCplx; overload; (*Returns the average value of the source data. *) function Meanc(const X: TDenseMtxVec): TCplx; overload; (*Returns the product of all elements in the source data. *) function Product(const X: TMtxVec): double; overload; (*Returns the product of all elements in the source data. *) function Productc(const X: TMtxVec): TCplx; overload; (*Compute the standard deviation from the source data. *) function StdDev(const X: TMtxVec): double; overload; (*Returns the sum of elements in the source data. *) function Sum(const X: TMtxVec): double; overload; (*Returns the sum of elements in the source data. *) function Sumc(const X: TMtxVec): TCplx; overload; (*Returns the sum of squares of the source data. *) function SumOfSquares(const X: TDenseMtxVec): double; overload; (*Vector Root Mean square. Vector RMS. Calling vector or matrix object for which function will be evaluated.*) function RMS(const Vec: TDenseMtxVec): double; overload; (*RMS for Vector values [Index,Index+Len], starting at Index.*) function RMS(const Vec: TDenseMtxVec; Index,Len: integer): double; overload; (*Vector standard deviation. Vector standard deviation. Calling vector or matrix object for which function will be evaluated. The average value computed from the Vec parameter.*) function StdDev(const Vec: TDenseMtxVec; AMean: double): double; overload; (*Standard deviation for Vector values [Index,Index+Len], starting at Index.*) function StdDev(const Vec: TDenseMtxVec; AMean: TCplx): TCplx; overload; (*Vector Norm-L1. Vector Norm-L1. Calling vector or matrix object for which function will be evaluated.*) function NormL1(const Vec: TDenseMtxVec): double; overload; (*|L1| norm for Vector values [Index,Index+Len], starting at Index.*) function NormL1(const Vec1,Vec2: TDenseMtxVec; RelativeError: boolean = False): double; overload; (*Vector L2-Norm. Vector L2-Norm Calling vector or matrix object for which function will be evaluated.*) function NormL2(const Vec: TDenseMtxVec): double; overload; (*|L2| norm for Vector values [Index,Index+Len], starting at Index.*) function NormL2(const Vec1,Vec2: TDenseMtxVec; RelativeError: boolean = False): double; overload; (*Vector C-Norm. Vector C-Norm Calling vector or matrix object for which function will be evaluated."/>*) function NormC(const Vec: TDenseMtxVec): double; overload; (*|C| norm for Vector values [Index,Index+Len], starting at Index.*) function NormC(const Vec1,Vec2: TDenseMtxVec; RelativeError: boolean = False): double; overload; (*Is number a prime number? True, if X is prime number. Evaluated nunmber.*) function Prime(const X: integer): boolean; (*Vector kurtosis. Vector kurtosis value. Calling vector or matrix object for which function will be evaluated. The average value computed from the Vec parameter. The standard deviation computed from the Vec parameter.*) function Kurtosis(const Vec: TDenseMtxVec; AMean, AStdDev: double): double; overload; (*Vector skewness Vector skewness. Calling vector or matrix object for which function will be evaluated. The average value computed from the Vec parameter. The standard deviation computed from the Vec parameter.*) function Skewness(const Vec: TDenseMtxVec; AMean, AStdDev: double): double; overload; function Equal(const Vec1,Vec2: TVec; Tolerance: double = 0): boolean; overload; (*Vector median. Vector median value. Calling vector or matrix object for which function will be evaluated.*) function Median(const Vec: TVec): double; overload; (*Vector mean. Vector mean value. Calling vector or matrix object for which function will be evaluated.*) function Mean(const Vec: TDenseMtxVec):double; overload; (*Mean valur for Vector values [Index,Index+Len], starting at Index.*) function Mean(const Vec: TDenseMtxVec; Index, Len: integer): double; overload; (*Vector sum. Sum of Vector values. Calling vector or matrix object for which function will be evaluated.*) function Min(const Vec: TDenseMtxVec): double; overload; function Max(const Vec: TDenseMtxVec): double; overload; (*Matrix trace. Matrix trace. Calling matrix object for which function will be evaluated.*) function Trace(const Mtx: TMtx): TCplx; overload; function Equal(Mtx1,Mtx2: TMtx; Tolerance: double = 0): boolean; overload; function Find(const Vec: TDenseMtxVec; const X: TCplx): integer; overload; function Find(const Vec: TDenseMtxVec; const X: double): integer; overload; (*Matrix Norm-1. Matrix Norm-1. Calling matrix object for which function will be evaluated.*) function Norm1(const Mtx: TMtx): double; overload; (*Matrix infinite norm. Matrix infinite norm. Calling matrix object for which function will be evaluated.*) function NormInf(const Mtx: TMtx): double; overload; function ColumnCount(aList: TStrings; Row: integer; const Delimiter: string = kTab): integer; overload; function SizeOfPrecision(Precision: TPrecision; aIsComplex: Boolean): integer; procedure SetVecSize(Length: integer; FloatPrecision: TMtxFloatPrecision; const Vec: array of TVec); overload; procedure SetMtxSize(Rows,Cols: integer; FloatPrecision: TMtxFloatPrecision; const Mtx: array of TMtx); overload; function PrecisionToStr(Precision: TPrecision): string; procedure MtxVecPrint(const vecs: array of TVec; const Names: array of string); overload; procedure MtxVecPrint(const mtxs: array of TMtx; const Names: array of string); overload; procedure MtxVecPrint(const cplxs: array of TCplx; const Names: array of string); overload; procedure MtxVecPrint(const vals: array of double; const Names: array of string); overload; procedure MtxVecPrint(const cplxs: array of TSCplx; const Names: array of string); overload; procedure MtxVecPrint(const vals: array of single; const Names: array of string); overload; function MtxTypeToString(matrixType: TMtxType): string; overload; procedure ShowMessageBox(const Msg: string); overload; procedure EigVecExpand(VR, Work: TMtx; WI: TVec); overload; procedure FindIndexes(const Dst: TVecInt; const a: TMtxVec; const op: string; const b: TMtxVec); overload; procedure FindIndexes(const Dst: TVecInt; const a: TMtxVec;const op: string; const b: double); overload; procedure FindIndexes(const Dst: TVecInt; const a: TMtxVec; const op: string; const b: TCplx); overload; function aGetLength(const src: array of TMtx): integer; overload; (* Exact brute-force K-NN without multi-threading. A matrix where each row is one vector of the original data. A matrix where each row is one vector. We want to find K vectors from srcData for each srcCompareData vector. The number of nearest neighbours/rows from SrcData to find for each row in SrcCompareData. Contains K indexes of rows from srcData for each row in SrcCompareData on output. The actual distances are stored in dstNearDistance parameter. Contains K distance of rows from srcData for each row in SrcCompareData on output. The distances are not sorted. K-nearest-neighbours will be computing the square of L2-Norm (distance) between rows in srcData and rows in srcCompareData to find K nearest rows from srcData for each row in the srcCompareData matrix. The SrcData.Cols and SrcCompareData.Cols need to match in size or an exception will be raised. The sizes of dstNearIdx, dstNearDistance and dstNearLargestIdx are set automatically. Performance notes: * This variant does not use threads and is suitable for user-side multi-threading. * The algorithm assumes existence of 32KB L1 cache. This is true for all Intel CPUs since Sandy Bridge and AMD Zen. The performance will drop by roughly 10x, if not present. * The algorithms efficiency grows with the size of srcData and especially of the srcCompareData matrices. uses MtxExpr, MtxVec, MtxExprInt; var Data, cmpData, nearDistance: Matrix; nearIdx: MatrixInt; begin data := [[1,2,3], [2,3,1], [3,2,1]]; cmpData := [[2,2,3], [2,3,4]]; ClusteredKNN(computeThreads, Data, cmpData, 2, nearIdx, nearDistance); // Results: // nearIdx = [[0, 1], // data rows 0 and 1 are closest vectors to cmpData row 0. // [0, 1]] // data rows 0 and 1 are closest vectors to cmpData row 1. // nearDistance = [[1 5], // [0,0] = sqr(2-1) + sqr(2-2) + sqr(3-3), distance from cmpData row 0 to Data row 0 is 1 // [3, 9]] // [1,0] = sqr(2-1) + sqr(3-2) + sqr(4-3), distance from cmpData row 1 to Data row 0 is 3 *) procedure ClusteredKNN(const srcData, srcCompareData: TMtx; const K: integer; const dstNearIdx: TMtxInt; const dstNearDistance: TMtx); overload; (* Exact brute-force K-NN with support for symmetric and asymetric multi-threading. A TMtxFoorLoop object, which is a threading library. ComputeThreads.BlockGranularity is required to be set to 4 for this algorithm. Additionally this object allows the user to specify thread-count and thread-affinity etc.. A matrix where each row is one vector of the original data. A matrix where each row is one vector. We want to find K vectors from srcData for each srcCompareData vector. The number of nearest neighbours/rows from SrcData to find for each row in SrcCompareData. Contains K indexes of rows from srcData for each row in SrcCompareData on output. The actual distances are stored in dstNearDistance parameter. Contains K distance of rows from srcData for each row in SrcCompareData on output. The distances are not sorted. K-nearest-neighbours will be computing the square of L2-Norm (euclidian norm or the distance) between rows in srcData and rows in srcCompareData to find K nearest rows from srcData for each row in the srcCompareData matrix. The SrcData.Cols and SrcCompareData.Cols need to match in size or an exception will be raised. The sizes of dstNearIdx and dstNearDistance are set automatically. Performance notes: * The ideal ComputeThreads.ThreadCount passed to the routine will equal the number of hyper-threaded cores. * The algorithm assumes existence of 32KB L1 cache. This is true for all Intel CPUs since Sandy Bridge and AMD Zen. The performance will drop by roughly 10x, if not present. * MtxVec.Controller.ThreadDimension is to be set to value larger than ComputeThreads.ThreadCount or an error will be raised. * computeThreads.BlockGranularity needs to be 4 or an error will be raised. * Multi-threading is performed only across the srcCompareData rows. If that matrix has less than 10-20 rows, the user can still perform multi-threading in his own code. The maximum performance gain in this case however will scale with thread count only up to the systems memory channel count (2-8). * The algorithm is set to scale linearly with core count (32, 64, 128 etc...), provided that srcCompareData.Rows is large enough. * For a 950 000 x 950 000 problem with, K = 50, Vector length = 30, 32bit float, on 8 SkyLake cores, the expected time to finish is 90s. * The speed-up over naive and not threaded KNN implementation starts at around 10x for small problems in grows to 1000x and more for very large problems. * Double precision is about 1.5x slower than single precision. uses MtxExpr, MtxVec, MtxExprInt, MtxForLoop; var Data, cmpData, nearDistance: Matrix; nearIdx: MatrixInt; threads: TMtxForLoop; begin // 1.) Create once ahead of time. This is the thread pool and is slow to create. threads := TMtxForLoop.Create; threads.ThreadCount := Controller.CpuCores*2; //hyperthreaded core count threads.BlockGranularity := 4; //required // 2.) This sets the "minimum" required. Also slow and needs to be set upfront and // it can only be done before any allocations are made by MtxVec. Controller.ThreadDimension := Max(threads.ThreadCount + 1, Controller.ThreadDimension); // 3.) Compiler assertions switch needs to be "off", when compling the source code data := [[1,2,3], [2,3,1], [3,2,1]]; cmpData := [[2,2,3], [2,3,4]]; ClusteredKNN(threads, Data, cmpData, 2, nearIdx, nearDistance); // Results: // nearIdx = [[0, 1], // data rows 0 and 1 are closest vectors to cmpData row 0. // [0, 1]] // data rows 0 and 1 are closest vectors to cmpData row 1. // nearDistance = [[1, 5], // [0,0] = sqr(2-1) + sqr(2-2) + sqr(3-3), distance from cmpData row 0 to Data row 0 is 1 // [3, 9]] // [1,0] = sqr(2-1) + sqr(3-2) + sqr(4-3), distance from cmpData row 1 to Data row 0 is 3 threads.Free; *) procedure ClusteredKNN(computeThreads: TMtxForLoop; const srcData, srcCompareData: TMtx; const K: integer; const dstNearIdx: TMtxInt; const dstNearDistance: TMtx); overload; (* Call this function to initiate threaded for-loop. The MyLoop method pointer must be a method. This is the function that will be called once by each thread. Threads parameter requires a TMtxForLoop object and the Context parameter can be used to pass any parameters to the threaded function. The threading engine will attempt to equaly partition the job between available threads assuming constant computational load for each Iteration in the range from IterMin to IterMax. However, further vectorization is possible within each threaded function call. This overload will take advantage of the super-conductive MtxVec object cache, if MtxVec.Controller.ThreadDimension is more than Threads.ThreadCount+1. Calling DoForLoop in parallel from multiple threads will not work. The call is to be protected with a critical section or otherwise. *) function DoForLoop(IterMin, IterMax: integer; MyLoop: TForLoopRangeEvent; Threads: TMtxForLoop; const Context: array of TObject): boolean; overload; (* Call this function to initiate threaded for-loop. The MyLoop method pointer must be a method. This is the function that will be called (IterMax - IterMin + 1) times. Threads parameter requires a TMtxForLoop object and Context can be used to pass any parameters to the threaded function. Computational load for each Iteration in the range from IterMin to IterMax is allowed to vary (possibly by a lot). Further vectorization within each threaded function call is not possible across the working Iteration range. This overload will take advantage of the super-conductive MtxVec object cache, if MtxVec.Controller.ThreadDimension is more than Threads.ThreadCount+1. Calling DoForLoop in parallel from multiple threads will not work. The call is to be protected with a critical section or otherwise. *) function DoForLoop(IterMin, IterMax: integer; MyLoop: TForLoopEvent; Threads: TMtxForLoop; const Context: array of TObject): boolean; overload; (* Call this function to initiate threaded while-loop. The MyLoop method pointer must be a function (not object method). This is the function that will be called until Stop parameter of MyLoop will be returned as True. Threads parameter requires a TMtxForLoop object and Context can be used to pass any parameters to the threaded function. This overload will take advantage of the super-conductive MtxVec object cache, if MtxVec.Controller.ThreadDimension is more than Threads.ThreadCount+1. Calling DoForLoop in parallel from multiple threads will not work. The call is to be protected with a critical section or otherwise. *) function DoWhileLoop(MyLoop: TWhileLoopEvent; Threads: TMtxForLoop; const Context: array of TObject): boolean; overload; (* Call this function to initiate threaded for-loop. The MyLoop method pointer must be a function (not object method). This is the function that will be called (IterMax - IterMin + 1) times. Threads parameter requires a TMtxForLoop object and Context can be used to pass any parameters to the threaded function. The computational load of MyLoop function is allowed to vary from one iteration to the next. This overload will take advantage of the super-conductive MtxVec object cache, if MtxVec.Controller.ThreadDimension is more than Threads.ThreadCount+1. Calling DoForLoop in parallel from multiple threads will not work. The call is to be protected with a critical section or otherwise. *) function DoForLoop(IterMin, IterMax: integer; MyLoop: TForLoopFunEvent; Threads: TMtxForLoop; const Context: array of TObject): boolean; overload; (* Call this function to initiate threaded for-loop. The MyLoop method pointer must be a function (not object method). This is the function that will be called once and will allow further code vectorization inside the thread. Threads parameter requires a TMtxForLoop object and Context can be used to pass any parameters to the threaded function. This overload will take advantage of the super-conductive MtxVec object cache, if MtxVec.Controller.ThreadDimension is more than Threads.ThreadCount+1. Calling DoForLoop in parallel from multiple threads will not work. The call is to be protected with a critical section or otherwise. *) function DoForLoop(IterMin, IterMax: integer; MyLoop: TForLoopRangeFunEvent; Threads: TMtxForLoop; const Context: array of TObject): boolean; overload; (* Call this function to initiate threaded while loop. The MyLoop method pointer must be a method (of object). This is the function that will be called until Stop parameter of MyLoop will be True. Threads parameter requires a TMtxForLoop object and Context can be used to pass any parameters to the threaded function. This overload will take advantage of the super-conductive MtxVec object cache, if MtxVec.Controller.ThreadDimension is more than Threads.ThreadCount+1. Calling DoWhileLoop in parallel from multiple threads will not work. The call is to be protected with a critical section or otherwise. *) function DoWhileLoop(MyLoop: TWhileLoopFunEvent; Threads: TMtxForLoop; const Context: array of TObject): boolean; overload; var (*Controls how the TVec/TMtx assign operation works. If True, the assign operation, will also copy the data and not only object's published properties. *) MtxVecAssignCopyData: boolean = True; (*MtxVec reporting object.*) Report: TMtxVecReport; (*MtxVec object cache controller.*) Controller: TMtxVecController; (*Implements abstract classes and shared code for TVec/TMtx/TVecInt.*) unit MtxVecBase; {$I BdsppDefs.inc} {$Z4} interface uses Math387 ,Windows ,SyncObjs ,Contnrs ,Classes ,SysUtils ,Forms ,Dialogs ; type TObjectsList = TObjectList; TMtxVecType = (mvTVec, mvTMtx, mvTVecInt, mvTMtxInt, mvTSparseMtx); TMtxVecBase = class; TSubRangeItem = record Index: integer; Len: integer; Src: TMtxVecBase; end; TSubRangeStack = array of TSubRangeItem; TSubRangeOp = (srPush, srNone); (*Base class for all one/two/../n dimensional arrays. This is the basic vector/matrix object. It handles memory allocation and basic vector arithmetics. It works with memory obtained directly from the operating system. The object bypasses the default Delphi memory manager and frees it from the load for which it is not very well suited. Memory allocation is cached via an "object cache" mechanism. Error checking All methods and properties of TMtxVec descendants are explicitly "range checked". Range checking ensures that the user can not read or write values past the size of the allocated memory. Once the code is compiled without assertations, range checking is disabled and higher performance can be achieved in some cases. Every effort has been made to prevent the user of the library to make an error that would result in memory overwrite. (Writing or reading to parts of the memory which were not allocated before and thus overwriting data of another part of the application.) *) TMtxVecBase = class(TPersistent ) strict private fCondEnabled: boolean; FOnSetSize: TMtxNotifyEvent; FBlockEnd: boolean; procedure set_Caption(const value: string); procedure setOnSetSize(const value: TMtxNotifyEvent); procedure set_Tag(const value: integer); procedure set_ConditionCheck(const value: boolean); procedure set_CacheIndex(const value: integer); function get_BlockEnd: boolean; function get_MtxVecType: TMtxVecType; protected procedure FreeCached; virtual; procedure CreateCached(aPoolIndex: integer; aCacheSizeInBytes: Int64; aMemIndex, aCacheIndex: integer); virtual; procedure DebugReport(ItemIndex: integer); strict protected fMemIndex: integer; fSubRangeStack: TSubRangeStack; FCacheOwned: boolean; fCacheIndex: integer; fSubRangeLevel: integer; fIsDouble: boolean; fPoolIndex: integer; (* Pointer to the automatic reference counting block. *) ipoint: PIArray; (* Pointer to the allocated memory block. *) aPoint: PointerInteger; (* Pointer to the first element of the array. *) ValuesPointer: PointerInteger; (* Amount of allocated memory. *) AllocSize: Int64; FCaption: string; FTag: integer; SComplex: boolean; fComplex: boolean; fLength: integer; BlockSize,BlockI: integer; BlockLevel: integer; BlockSrc: TMtxVecBase; fIsSubRange: boolean; fActualSizeInBytes: Int64; fConditionCheck: boolean; subrange_refs_count: integer; usage_refs_count: integer; fAllowSubrange: boolean; FFTDescriptorIndex: integer; fCapacityInBytes: Int64; fCapacityStep: double; SActualSize: Int64; SFloatPrecision: TMtxFloatPrecision; SLength: integer; SOffset: integer; SIsDouble: boolean; SValuesPointer: PointerInteger; fMtxVecType: TMtxVecType; fFloatPrecision: TMtxFloatPrecision; fBlockSubRangeLevel: integer; fDebuggerMarker: integer; procedure SubRangeSaveState; virtual; abstract; procedure SubRangeLoadState; virtual; abstract; procedure SetSubRangeDirect(Index, Len: integer); overload; virtual; abstract; procedure SetSubRangeDirect(const Src: TMtxVecBase; Index, Len: integer); overload; virtual; abstract; procedure SetFullRangeInternal(PopStack: boolean); procedure SetSubRangeInternal(Index: integer; Len: integer; stackOp: TSubRangeOp); overload; procedure SetSubRangeInternal(const Src: TMtxVecBase; Index: integer; Len: integer; stackOp: TSubRangeOp); overload; procedure InternalSubRangeStackOp(var Index: integer; var Len: integer; stackOp: TSubRangeOp); overload; procedure InternalSubRangeStackOp(const Src: TMtxVecBase; Index: integer; Len: integer; stackOp: TSubRangeOp); overload; procedure CopyFromArray(const Src: TIntegerArray; const Dst: TMtxVecBase; const SrcIdx, DstIdx, Len: integer); overload; virtual; abstract; procedure CopyFromArray(const Src: TSmallIntArray; const Dst: TMtxVecBase; const SrcIdx, DstIdx, Len: integer); overload; virtual; abstract; procedure CopyFromArray(const Src: Math387.TByteArray; const Dst: TMtxVecBase; const SrcIdx, DstIdx, Len: integer); overload; virtual; abstract; procedure CopyToArrayInternal(const Src: TMtxVecBase; const Dst: TDoubleArray; const Index,DstIdx,Len: integer); overload; virtual; abstract; procedure CopyToArrayInternal(const Src: TMtxVecBase; const Dst: TSingleArray; const Index,DstIdx,Len: integer); overload; virtual; abstract; procedure AddRefSubrange; procedure AddRefUsage; procedure ReleaseSubrange; procedure ReleaseUsage; procedure LoadBinaryStream(Stream: TStream); overload; procedure SaveBinaryStream(Stream: TStream); overload; procedure InternalReadHeader(const SrcStream: TStream); overload; virtual; procedure InternalWriteHeader(const DstStream: TStream); overload; virtual; procedure MapIndexes(const Src: TIntegerArray; var Idxs,Lens: TIntegerArray; IdxOffset: integer); function InsertRowHeaders(const aList: TStrings; const aListIndex: integer; const Align: TFixedTextAlign; const Rows: integer): integer; procedure InsertColumnHeaders(const aList: TStrings; const aListIndex: integer; const Align: TFixedTextAlign; const Cols: integer; rowLabelColumnWidth, valueColumnWidth: integer); function InternalStringPadding(const strList: array of string; const aList: TStrings; const aListIndex: integer; const Align: TFixedTextAlign; const Headers: boolean; const ColumnWidth: integer): integer; procedure AllocMemory; virtual; procedure AllocCacheMemory; virtual; procedure HookPointers; virtual; function AllocateMemory(Bytes: Int64): PointerInteger; procedure ReleaseMemory; virtual; procedure DefineProperties(Filer: TFiler); override; function CacheLength: integer; virtual; function CacheLengthInBytes: Int64; virtual; function ElemSize: Integer; virtual; procedure setActualSize(const byteCount: Int64); virtual; function ValuesToStringsInternal(const dstList: TStrings; const aDelimiter: string; const Align: TFixedTextAlign; const Headers: boolean; const ColumnWidth: integer): integer; overload; virtual; function StringsToValuesInternal(const srcList: TStrings; const aDelimiter: string): TMtxVecBase; overload; virtual; (*For internal use only. Read to get the amount of memory allocated in number of doubles (8byte packs).*) property ActualSize: Int64 read FActualSizeInBytes write setActualSize; strict protected procedure SetCapacityInBytes(const value: Int64); virtual; procedure SetCapacityInElements(const value: Int64); virtual; function GetCapacityInElements: Int64; virtual; procedure setCapacityStep(const value: double); virtual; procedure setIsDouble(const value: boolean); virtual; procedure SetLength(const value: integer); virtual; public ThreadID: TThreadID; property MtxVecType: TMtxVecType read get_MtxVecType; constructor Create; virtual; destructor Destroy; override; (*Returns the current subrange stack level. When the stack has zero size, the subrange level is -1. Maximum level is determined with MaxSubRangeLevel global variable with default value of 4. This routine can be usefull for debugging purposes. *) function SubRangeLevel: integer; (*Returns the current subrange stack level used by block processing functions. When the stack has zero size, the subrange level is -1. This routine can be usefull for debugging purposes. When block processing is initiated with a call to BlockInit, the value of BlockSubRangeLevel is set to be equal to the current value of SubRangeLevel. When the block processing finishes, the BlockSubRangeLevel will be set to -1. *) function BlockSubRangeLevel: integer; (*Defines a sub vector/matrix. The method will define a subarray starting at Index and ending at Index+Len-1. No copying will occur, only pointers will be shifted or indices adjusted. All values of the original will be preserved. An exception will be raised, if an attempt is made to change the size of calling object. A sub-vector/matrix is vector/matrix which does not neccessarily have its own memory allocated. Instead it adopts the memory of the source object and all operations done on the either of the objects affect the same elements. The use of subvectors/submatrices increases CPU cache reuse, lower's memory requirements, increases application performance and improves code readability. To again obtain a view of the full vector/matrix, see *) procedure SetSubRange(Index: integer; Len: integer = MtxVecEOA); overload; (*Defines a sub vector/matrix and pushes any previous subranges on to a stack. The method will define a subarray starting at Index and ending at Index+Len-1. No copying will occur, only pointers will be shifted or indices adjusted. The routine allows for stack based pushing and poping of sub-ranges with the additional constraint that each deepening of the sub-range is strictly within the bounds of the previous one. The pairs of SetSubRangeLevel/SetFullRangeLevel need to match. All values of the original will be preserved. An exception will be raised, if an attempt is made to change the size of calling object. It is possible to call SetSubRange/SetFullRange on the object, which has been subranged with SetSubRangeLevel. To again obtain a view of the previous subrange level on the vector/matrix, call The Index parameter of the SetSubRange is absolute for the original memory or current stack level. The Index parameter for the SetSubRangeLevel is relative to the previous SetSubRangeLevel call. *) procedure SetSubRangeLevel(Index: integer; Len: integer = MtxVecEOA); overload; (*Define a subvector of the Src vector. The method will define a subarray starting at Index and ending at Index+Len-1 of Src. No copying will occur, only pointers will be shifted or indices adjusted. A sub-vector/matrix is vector/matrix which does not neccessarily have its own memory allocated. Instead it adopts the memory of the source object and all operations done on the either of the objects affect the same elements. The use of subvectors/submatrices increases CPU cache reuse, lower's memory requirements, increases application performance and improves code readability. All values of the original will be preserved. An exception will be raised, if an attempt is made to change the size of calling object. No exception will be raised, if Src is resized while subranged. (possibly leading to memory overwrites) To again obtain a view of the original vector/matrix, call *) procedure SetSubRange(const Src: TMtxVecBase; Index: integer; Len: integer = MtxVecEOA); overload; (*Defines a sub vector/matrix of Src and pushes any previous subranges on to a stack. The method will define a subarray starting at Index and ending at Index+Len-1 of Src. No copying will occur, only pointers will be shifted or indices adjusted. The routine allows for stack based pushing and poping of sub-ranges with the additional constraint that each deepening of the sub-range is strictly within the bounds of the previous one. The pairs of SetSubRangeLevel/SetFullRangeLevel need to match. All values of the original will be preserved. An exception will be raised, if an attempt is made to change the size of calling object. No exception will be raised, if Src is resized while subranged. (possibly leading to memory overwrites) It is possible to call SetSubRange/SetFullRange on the object, which has been subranged with SetSubRangeLevel. To again obtain a view of the previous subrange level on the vector/matrix, call The Index parameter of the SetSubRange is always relative to the previous, if any, stack level. The Index parameter for the SetSubRangeLevel is relative to the current stack level. *) procedure SetSubRangeLevel(const Src: TMtxVecBase; Index: integer; Len: integer = MtxVecEOA); overload; (*Initializes block processing. Initializes block processing. Because the size of the CPU cache is limited, significant performance gains can be obtained by splitting long vectors in to a series of short ones, which can all fit in the CPU cache entirely. The BlockInit method is to be used together with and methods to initialize a block processing while loop. BlockInit will call to obtain subrange of the data in TVec. The of the subranged vector is determined by the global variable declared in Math387 unit. Default value of MtxVecBlockSize is preset to 800 vector elements for double precision and 1600 elements for single precision. BlockInit supports nested calls and from witihin a blocked while loop you can call procedures and functions which are also blocked. If you use block processing, typical performance gains will range from 2 to a maximum of 6. Block processing can not be used, or it is difficult to apply, in cases where vector elements are not independent of each other. The block processing while loop must be written like this: a.BlockInit; while not A.BlockEnd do begin // .... user defined function a.BlockNext; end; Normal vectorized procedure: procedure ParetoPDF(X: TVec; a, b: double; Res: TVec); overload; begin Res.Size(X); Res.Power(x,-(a+1)); Res.Mul(Power(b,a)*a);; end; Vectorized and blocked version of the Pareto probability distribution procedure: procedure ParetoPDF(X: TVec; a, b: double; Res: TVec); overload; begin Res.Size(X); Res.BlockInit; X.BlockInit; while not X.BlockEnd do begin Res.Power(x,-(a+1)); Res.Mul(Power(b,a)*a); Res.BlockNext; X.BlockNext; end; end; Alternative: procedure ParetoPDF(X: TVec; a, b: double; Res: TVec); overload; var x1: Vector; begin Res.Size(X); Res.BlockInit; X1.BlockInit(X); while not X1.BlockEnd do begin Res.Power(x,-(a+1)); Res.Mul(Power(b,a)*a); Res.BlockNext; X1.BlockNext; end; end; The block version of the ParetoPDF will execute faster then the non-blocked version in cases where X contains 5000-10000 elements or more (double precision). Below that value the two versions will perform about the same, except for very short vector sizes (below 50 elements), where the non-blocked version will have a slight advantage, because of the absence of block processing methods overhead. The time is saved between the calls to Res.Power(x,-(a+1)) and Res.Mul(Power(b,a)*a), where the same memory (stored in Res vector) is accesed in two consecutive calls. That memory is loaded in the CPU cache on the first call, if the Length of the Res vector is short enough to fit in. As an excercise you can also try to compare the performance of the vectorized and blocked version of the function with the single value version (ParetoPDF(X: double; a, b: double; Res: double) and measure the execution time of both versions for long vectors (100 000 elements) and short vectors (10 elements). The differences with block processing strongly depend upon the fatness of individual functions. When the relative number of memory accesses is high in compare to amount of computation, block processing with thrive. *) procedure BlockInit; overload; inline; procedure BlockInit(const Src: TMtxVecBase); overload; inline; (*Initializes block processing.*) procedure BlockInit(ABlockSize: integer); overload; (*Initializes block processing. Block processing can be applied on possibly already subranged Src object. Src may not be freed or go out of scope until block processing loop has finished. There would be no error raised other than AV. *) procedure BlockInit(const Src: TMtxVecBase; ABlockSize: integer); overload; (*Deinitializes block processing before the final block is processed. Call this routine before breaking out of a while-loop prematurely. Vec.BlockInit While not Vec.BlockEnd do Begin If Vec.Min < 0 then //check some condition, if you need to exit begin Vec.BlockFinish; //finish the loop Break; //and break out end; Vec.BlockNext; end *) procedure BlockFinish; (*Obtains the next subrange of the data. Obtains the next subrange of the data in TVec. The routine must be used together with and methods. *) procedure BlockNext; (*Resets subrange defined with SetSubRange. *) procedure SetFullRange; virtual; (*Pops the current subrange stack one level up. *) procedure SetFullRangeLevel; virtual; (*Prevents calls to . Prevents calls to method. This can be usefull guard when an object is already working on a subrange and the user would like to further subrange an already subranged object. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TVec a,b; MtxVec.CreateIt(out a, out b); try { a.SetIt(false, new double[] {1,2,3,4,5,6,7,8,9}); a.SetSubRange(0,2); //a = [1,2] a.DisableSubrange(); a.SetSubRange(2,2); //exception raised here b.SetSubRange(a,2,2); //but this will work a.SetFullRange(); //b is not changed, it still points to [4,5] } finally { MtxVec.FreeIt(ref a, ref b); } } } *) procedure DisableSubrange; (*Enables calls to . Enables calls to by removing the block set by . *) procedure EnableSubrange; (*Copy values to Dst array. The size of the array is set automatically. If the calling object is complex, the size of the Dst array will be equal to 2*. If the calling object is not complex an exception will be raised. *) function CopyToArray(var Dst: TDoubleArray): TMtxVecBase; overload; (*Copy real or complex values from the calling object [Index]..[Index+len-1] to the Dst array at positions [DstIndex]...[DstIndex+Len-1]. The size of the Dst array is not changed. If the calling object is complex, the Index and Len parameters define the number of complex elements. *) function CopyToArray(var Dst: TDoubleArray; DstIndex, Index,Len: integer): TMtxVecBase; overload; (*Copies the calling object data to an array of single precision floating point data. Any values exceeding the range are clipped. *) function CopyToArray(var Dst: TSingleArray): TMtxVecBase; overload; (*Copy real or complex values from the calling object [Index]..[Index+len-1] to the Dst single precision floating point array at positions [DstIndex]...[DstIndex+Len-1]. The size of the Dst array is not changed. If the calling object is complex, the Index and Len parameters define the number of complex elements. *) function CopyToArray(var Dst: TSingleArray; DstIndex, Index,Len: integer): TMtxVecBase; overload; (*Prevents calls to . Prevents calls to method. This can be usefull guard when an object is already working on a subrange and the user would like to further subrange an already subranged object. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TVec a,b; MtxVec.CreateIt(out a, out b); try { a.SetIt(false, new double[] {1,2,3,4,5,6,7,8,9}); a.Select(0,2); //a = [1,2] a.DisableSelect(); a.Select(2,2); //exception raised here b.Select(a,2,2); //but this will work a.SelectAll(); //b is not changed, it still points to [4,5] } finally { MtxVec.FreeIt(ref a, ref b); } } } *) procedure DisableSelect; (*Enables calls to . Enables calls to by removing the block set by . *) procedure EnableSelect; (*Resets any defined selection. *) procedure SelectAll; overload; (*Reads the header information and the values array content from a stream. Reads the header information and the values array content from the SrcStream. The return value indicates the number of elements read. var b: TVec; AStream: TFileStream; begin CreateIt(b); try b.SetIt(False,[0,0,1,3,2]); AStream := TFileStream.Create('C:\test.Vec',fmCreate); try b.LoadFromStream(AStream); // Read info and header for b finally AStream.Free; end; finally FreeIt(b); end; end; *) function LoadFromStream(const Src: TStream): Int64; overload; virtual; (*Writes the header information and the Values content to a stream. Writes the header information and the Values content to a DstStream stream. Number type is defined by the Precision parameter. Rounding defines the rounding for integer types. When saving double precision as single precision, all overflows are saved as INF (-INF). When saving to integer types all overflows are clipped. Attempt to save single precision as double precision will raise an exception. var b: TVec; AStream: TFileStream; begin CreateIt(b); b.SetIt(False,[0,0,1,3,2]); AStream := TFileStream.Create('C:\test.Vec',fmCreate); try b.SaveToStream(AStream); // Write info and header for b finally AStream.Free; end FreeIt(b); end; *) procedure SaveToStream(const Dst: TStream); overload; virtual; (*Sizes double precision array. If the property is true the Length of the Dst array will be 2*. *) procedure SizeToArray(var Dst: TDoubleArray); overload; (*Size single precision array. If the property is true the Length of the Dst array will be 2*. *) procedure SizeToArray(var Dst: TSingleArray); overload; (*Sizes integer array. If the property is true the Length of the Dst array will be 2*. *) procedure SizeToArray(var Dst: TIntegerArray); overload; (*Sizes integer array. If the property is true the Length of the Dst array will be 2*. *) procedure SizeToArray(var Dst: Math387.TWordArray); overload; (*Sizes integer array. If the property is true the Length of the Dst array will be 2*. *) procedure SizeToArray(var Dst: TSmallIntArray); overload; (*Sizes integer array. If the property is true the Length of the Dst array will be 2*. *) procedure SizeToArray(var Dst: Math387.TByteArray); overload; (* For internal use only. Used to return object to cache. *) procedure Reset; virtual; procedure Assign(Src: TPersistent); override; procedure ValidateParams (const Index: integer; var Len: integer); overload; procedure ValidateCplxArrayIndexes (const SrcIndex,SrcLen,Index: integer; var Len: integer); procedure ValidateRealArrayIndexes (const SrcIndex,SrcLen,Index: integer; var Len: integer); (*Sets vector size to zero. Calling Clear sets property to 0 and property to False. *) procedure Clear; virtual; (*Frees the object. If the object was created with a call to CreateIt, this routine will call FreeIt. If the object was created with a call to constructor (Create), this routine will call the destructor (Free). *) procedure FreeToCache; virtual; (*Selects a set of elements from the vector. The method will define a subarray starting at Index and ending at Index+Len-1. No copying will occur, only pointers will be shifted. All values of the original will be preserved. An exception will be raised if an attempt is made to change the size of the calling object after a selection has been made. A selection will behave exactly as if the object always contained only the selected values. When a selection is made from another object the source object and all operations done on either of the two objects will affect the same elements. The use of selections increases CPU cache reuse, lower's memory requirements, increases application performance and improves code readability. To again obtain a view of the full vector/matrix use the method. When selecting elements from other objects, care must be given not to use the selections after the source object has been freed: var a,b: TVec; begin CreateIt(a,b); try a.SetIt(False,[1,2,3,4]); b.Select(a,2,2); FreeIt(a); //free the source object b.Values[0] := b.Valuess[1]; //b does not point to valid memory anymore finally FreeIt(a); end; end; *) procedure Select(Index: integer; Len: integer); overload; (*Resets the selection. This method is the same as the method. *) procedure Select; overload; (*Sets the subarray size to full size. This method is the same as the method. *) procedure SetSubRange; overload; (*Defines a subarray. The method will define a sub array starting at BeginIndex and ending at EndIndex (inclusive). All values of the original vector/matrix will be preserved. An exception will be raised if an attempt is made to change the size of calling vector/matrix. A subarray is array which does not have its own memory allocated. Instead it adopts the memory of the source object and all operations done on the either of the objects affect the same elements. The use of subarrays increases CPU cache reuse, lower's memory requirements, increases application performance and improves code readability. To again obtain a view of the full vector see *) procedure SetSubIndex(BeginIndex, EndIndex: integer); (*Saves the current value of ConditionCheck property and sets it to false. Saves the current value of property and sets it to false. You can restore back to the original setting by calling method. *) procedure CondDisable; (*Sets the ConditionCheck property to whatever it was before the CondDisable was used. Sets the property to whatever it was before the was used. *) procedure CondEnable; (*Write object header and values to a file. Write the header describing the calling object and the values array of the calling object to the file, specified by the FileName. If the file already exist, the data is overwritten by default. If Append is True, the data is appended to the end of the file. The data is always saved with the default precision precision (single or double). * In case of '.csv' extension a comma is used as a column delimiter for matrices. * In case of '.txt' extension a tab is used as a column delimiter for matrices. * For all other extensions, the expected format is binary. Note It is recommended you use a *.mtx extension when you're saving/loading matrix to/from file. Similarly, use *.vec extension when you're saving/loading vector to/from file. var Mtx: TMtx; begin CreateIt(Mtx); try Mtx.SetIt(2,2,False,[3,1,-1,5]); Mtx.SaveToFile('c:\test.mtx'); // Write info and header for Mtx to file finally FreeIt(Mtx); end; end; *) procedure SaveToFile(FileName: string; Append: boolean = False); (*Reads the header information and the values array content from the file. Reads the header information and the values array content from the file specified by FileName parameter. * In case of '.csv' extension a comma is used as a column delimiter for matrices. * In case of '.txt' extension a tab is used as a column delimiter for matrices. * For all other extensions, the expected format is binary. var b: TVec; begin CreateIt(b); try b.LoadFromFile('c:\test.Vec'); // Read header and values for b finally FreeIt(b); end; end; *) procedure LoadFromFile(FileName: string); (*Called when object size changes. Called when the object size changes. *) property OnSetSize: TMtxNotifyEvent read FOnSetSize write setOnSetSize; (*Set to true after the SetSubIndex or SetSubRange call. This property is set to true after the or call. If IsSubRange is true then the TVec method/function will be performed on subrange of values. Use to set IsSubRange back to False and thus reset sub range to full vector length. *) property IsSubRange: boolean read fIsSubRange; (*Returns true, if the currrent subrange of the vector was also the last subrange in the vector. Returns true, if the currrent subrange of the vector was also the last subrange in the vector. This property be used together with and . *) property BlockEnd: boolean read get_BlockEnd; (*For internal use only. Read to get the index of this object in object cache. If the object is not from object cache, teh property will return -1. *) property CacheIndex: integer read FCacheIndex write set_CacheIndex; (*Sizing the object will not allocate less than Capacity. Capacity equals CapacityInElements. Rounded up to multiple of 16bytes. After changing Capacity, do not assume that any existing values will be preserved. Any memory re-allocation needed happens at the next call to Size. Capacity cannot be an odd number. When setting an odd number, the Capacity will be increased to the next even number. If Capacity specified is less than object cache size, then the value of Capacity is not considered. *) property Capacity: Int64 read GetCapacityInElements write setCapacityInElements; (*Sizing the object will not allocate less than CapacityInBytes. Rounded up to multiple of 16bytes. *) property CapacityInBytes: Int64 read fCapacityInBytes write SetCapacityInBytes; (*Sizing the object will not allocate less than CapacityInElements. Rounded up to multiple of 16bytes. When the storage precision is changed, the CapacityInElements will be adjusted accordingly with CapacityInBytes retaining the value. *) property CapacityInElements: Int64 read GetCapacityInElements write SetCapacityInElements; (*Specifies increment step for the Capacity property. If this property is 0, the Capacity will never be modified on its own. When the value 1, the capacity will continue increasing to match largest value requested. When the value is more than 1, the capacity will be increasing with the factor specified. *) property CapacityStep: double read fCapacityStep write setCapacityStep; (*Defines the precision (single or double) of the floating point operations. *) property IsDouble: boolean read fIsDouble write setIsDouble; (*Internal. Used by object-cache to determine the thread pool. *) property PoolIndex: integer read fPoolIndex; published (*Defines the length in number of samples. Defines the number of samples that the object can store. The length property does not map directly to memory reallocation when it is changed. Until the amount of preallocated memory is not exceed, there is no reallocation going on. Changing the Length property will preserve the existing values, but only if the new property value is smaller than the amount of preallocated memory. To properly resize the memory allocated use the method. It is recommended that vector sizes do not exceed the size of preallocated memory to increase overall performance. The size of preallocated memory can be controlled with the Controller global variable and with the Capacity property. *) property Length: integer read fLength write SetLength stored false; (*Enables/disable inline condition checking. Enables/disables inline condition checking. When true, TVec methods perform additional (range) checking before operations are executed. The drawback is slight loss of speed. If ConditionCheck is set to false then no additional checking is performed. This speeds up the execution but disables some safeguards. For short vectors the loss of speed can be significant. The more parameters the method requires the more error checking is performed. Some methods (parameterless) don't use the ConditionCheck property at all. ConditionCheck property is initially True. This property is an additional safeguard against array overrun or underrun errors. It allows you to work with explicit range checking while writing and debugging the application and once your code is running you can turn it off. By functionality it is similar to assertions. (See Assert Delphi procedure). You can also use compiler directives to check, if assertions are on and then set ConditionCheck to True. *) property ConditionCheck: boolean read fConditionCheck write set_ConditionCheck stored false; (*Caption. Use this property to set/get the object string caption. This can be usefull for associating description with data when making a user interface. *) property Caption: string read FCaption write set_Caption stored false; (*Stores an integer value as part of a TMtxVec object. Stores an integer value as part of a object. Tag has no predefined meaning. The Tag property is provided for the convenience of developers. It can be used for storing an additional integer value or it can be typecast to any 32-bit value such as a component reference or even a pointer. *) property Tag: integer read FTag write set_Tag stored false; end; TMtxVecSample = class(TMtxVecBase) strict protected FDataOffset: integer; FCDataOffset: integer; fFloatPrecisionLock: boolean; public SData: TDoubleArray; CData: TCplxDoubleArray; SSData: TSingleArray; SCData: TCplxSingleArray; procedure ValidateParams (const X: TMtxVecBase; const XIndex: integer;const Index: integer; var Len: integer); overload; procedure ValidateParams (const X1, X2: TMtxVecBase; const xIndex1,xIndex2,Index: integer; var Len: integer); overload; procedure ValidateParams (const X1, X2, X3: TMtxVecBase; const xIndex1, xIndex2, xIndex3, Index: integer; var Len: integer); overload; procedure RangeCheck(const Indx: integer); overload; procedure RangeCheckComplex(const Indx: integer); overload; constructor Create; override; destructor Destroy; override; (*Obtains a pointer to the real value of the vector at Index. The function returns @Values[i]. Under .NET this is a pointer to managed memory, which needs to be pinned before the address is taken. *) function PValues1D(const Index: integer): PPDouble; overload; (*Obtains a pointer to the real value of the vector at Index. The function returns @Values[i]. Under .NET this is a pointer to managed memory, which needs to be pinned before the address is taken. *) function PSValues1D(const Index: integer): PPSingle; overload; (*Returns an index pointing to element at Index for double data. The data for the current object may or may not start at index offset 0 within the internal storage array. *) function SDataIndex(const Index: integer): integer; overload; (*Obtaines a pointer to the complex value of the vector at Index. The function returns @CValues[i]. Under .NET this is a pointer to managed memory, which needs to be pinned before the address is taken. *) function PCValues1D(const Index: integer): PPCplx; overload; (*Obtaines a pointer to the complex value of the vector at Index. The function returns @CValues[i]. Under .NET this is a pointer to managed memory, which needs to be pinned before the address is taken. *) function PSCValues1D(const Index: integer): PPSCplx; overload; (*Returns an index pointing to element at Index for TCplx data. The data for the current object may or may not start at index offset 0 within the internal storage array. *) function CDataIndex(const Index: integer): integer; overload; (* Returns machine constant depending on value of FloatPrecision property. *) function PrecisionEPS: double; (*Sqrt(EPS) machine constant depending on value of FloatPrecision property. Square root of EPS. *) function PrecisionSqrtEPS: double; (*Returns maximum floating point number depending on the value of FloatPrecision property. Maximum floating point number. *) function PrecisionMaxValue: double; (*Minimum floating point number. Minimum floating point number: 2^(-1022). *) function PrecisionMinValue: double; public property FloatPrecisionLock: boolean read fFloatPrecisionLock write fFloatPrecisionLock; end; TPoolItemRecord = record Item: TMtxVecBase; Used: boolean; end; TCacheItem = array of TPoolItemRecord; (* Abstract class for object cache. *) TAbstractMtxVecCache = class(TPersistent) strict protected Cache: TCacheItem; Cache1: TCacheItem; FCacheWasFull: boolean; Count: integer; fCacheUsedCount: integer; LowCount: integer; fConditionCheck: boolean; FCacheSize: integer; fCacheElements: integer; procedure SetConditionCheck(const value: boolean); procedure Recollect; procedure DestroyCache; procedure CacheMemFree; virtual; function NewItem: TMtxVecBase; virtual; procedure CacheMemAllocate(ItemCount, Elements: integer); virtual; procedure InternalSetCacheSize; function GetCacheFull: boolean; function GetCacheInBytes: Int64; virtual; protected FMaxCount: integer; public csLock: Byte; function CreateItx: TMtxVecBase; function LockedCreateItx: TMtxVecBase; procedure FreeIty(const a: TMtxVecBase); overload; procedure LockedFreeIty(const a: TMtxVecBase); overload; public PoolIndex: integer; ThreadId: TThreadID; (* Returns the number of objects in the object cache. To change the size of the object cache call SetCacheSize. *) property CacheSize: integer read fCacheSize; (* Returns true, if object cache was too small. Only a limited count of items is available in the object cache. If object cache runs out of objects, the code performance could be seriously affected (also by 20x in some cases). Do not allocate objects from cache in large numbers. *) property CacheWasFull: boolean read fCacheWasfull; (* Returns true, if currently there are no free objects in cache. *) property CacheFull: boolean read GetCacheFull; (*Returns the number of precreated objects inside object cache.*) property CacheElements: integer read FCacheElements; property CacheInBytes: Int64 read GetCacheInBytes; (* Returns the number of currently used objects in the object cache. *) property CacheUsedCount: integer read fCacheUsedCount; (*Read only property. Maximum number of objects used inside object cache. Use this value to trim the size of the object cache for your application. Too large cache eats away too much system memory and too small cache can result in performance penalties. *) property MaxCount: integer read FMaxCount; (* Sets ConditionCheck for all items in the list. *) property ConditionCheck: boolean read fConditionCheck write SetConditionCheck; (* Sets the cache object count to ItemCount and allocates Elements count of data elements per object. *) procedure SetCacheSize(ItemCount, Elements: integer); (* Call Enter to enable thread exclusive access. Internally this has no effect other than it saves the user from allocating his own critical section. *) procedure Enter; (* Call Leave to end thread exclusive access. Internally this has no effect other than it saves the user from allocation its own critical section. *) procedure Leave; (* Call Enter to enable thread exclusive access. Internally this has no effect other than it saves the user from allocating his own critical section. The function returns false, if thread exclusive access could not be granted immediately. *) function TryEnter: boolean; procedure DebugReport; constructor Create; virtual; destructor Destroy; override; end; TIntegersList = class strict private data: TIntegerArray; fCount: integer; function GetItems(i: integer): integer; inline; procedure SetItems(i: integer; const Value: integer); inline; public property Count: integer read fCount; function Add(const aItem: integer): integer; procedure Delete(const i: integer); procedure Insert(const i: integer); procedure Clear; property Items[i: integer]: integer read GetItems write SetItems; default; end; function LockCmpxchg(CompareVal, NewVal: Byte; AAddress: PByte): Byte; procedure EValidateParams(const Index, Len, Length: integer); overload; procedure EValidateParamsX(const XIndex, Len, xLength: integer); overload; procedure EValidateParamsSelf; overload; procedure EValidateParamsSelf2; overload; procedure EValidateParamsSelf3; overload; procedure EValidateParamsX1(const xIndex1, Len, x1Length: integer); overload; procedure EValidateParamsX2(const xIndex2, Len, x2Length: integer); overload; procedure EValidateParamsX3(const xIndex3, Len, x3Length: integer); overload; procedure EValidatePrecisionCheck1(); overload; procedure EValidatePrecisionCheck2(); overload; procedure EValidatePrecisionCheck3(); overload; procedure aSetLength(var A: TSubRangeStack; const Len: integer); overload; procedure aSetLength(var A: TCacheItem; const Len: integer); overload; function aGetLength(const a: TSubRangeStack): integer; overload; function aGetLength(const a: TCacheItem): integer; overload; procedure GetCpuInfo(var CpuPhysicalCores, CpuLogicalCores, NumaNodes, L1Cache, L2Cache, L3Cache: integer); overload; function GetCPUVendorInfo: string; overload; procedure CheckSubrange(f, a, p: TMtxVecBase); overload; procedure dgemm3(const A, B, C: TDoubleArray; const alpha, beta: Double); overload; inline; procedure dgemm3(const A, B, C: TDoubleArray); overload; inline; procedure zgemm3(const A, B, C: TCplxArray; const alpha, beta: TCplx); overload; inline; procedure zgemm3(const A, B, C: TCplxArray); overload; inline; procedure dgemm2(const A, B, C: TDoubleArray; const alpha, beta: Double); overload; inline; procedure dgemm2(const A, B, C: TDoubleArray); overload; inline; procedure zgemm2(const A, B, C: TCplxArray; const alpha, beta: TCplx); overload; inline; procedure zgemm2(const A, B, C: TCplxArray); overload; inline; procedure sgemm3(const A, B, C: TSingleArray; const alpha, beta: Single); overload; inline; procedure sgemm3(const A, B, C: TSingleArray); overload; inline; procedure cgemm3(const A, B, C: TSCplxArray; const alpha, beta: TSCplx); overload; inline; procedure cgemm3(const A, B, C: TSCplxArray); overload; inline; procedure sgemm2(const A, B, C: TSingleArray; const alpha, beta: Single); overload; inline; procedure sgemm2(const A, B, C: TSingleArray); overload; inline; procedure cgemm2(const A, B, C: TSCplxArray; const alpha, beta: TSCplx); overload; inline; procedure cgemm2(const A, B, C: TSCplxArray); overload; inline; procedure zgemm2x(const A, B, C: TDoubleArray); overload; inline; procedure zgemm2x(const A, B, C: TDoubleArray; const alphaR, alphaI, betaR, betaI: Double); overload; inline; procedure cgemm2x(const A, B, C: TSingleArray); overload; inline; procedure cgemm2x(const A, B, C: TSingleArray; const alphaR, alphaI, betaR, betaI: single); overload; inline; procedure zgemm3x(const A, B, C: TDoubleArray); overload; procedure zgemm3x(const A, B, C: TDoubleArray; const alphaR, alphaI, betaR, betaI: Double); overload; procedure cgemm3x(const A, B, C: TSingleArray); overload; procedure cgemm3x(const A, B, C: TSingleArray; const alphaR, alphaI, betaR, betaI: single); overload; function CountSetBits(ABitMask: UInt64): integer; var MtxVecFileCode: word = $FA13; MtxVecTVecVer: integer = -1; MaxSubrangeLevel: integer = 4; (*Implements TVecInt object. Implements integer math object TVecInt and supporting routines *) unit MtxVecInt; {$I BdsppDefs.inc} interface uses Math387, MtxVecBase, AbstractMtxVecInt ,Classes ,SysUtils ; type TMtxInt = class; (*Intermediate class to allow insertion of helper classes for TMtxVecInt. *) TAbstractMtxVecInt = class(TMtxVecInt); (*Class for one dimensional integer arrays. Class for accessing and manipulating 8bit unsigned and 16 or 32 bit signed one dimensional arrays of integers and bits. Purpose of usage: * leverage the SSEX/AVX instruction sets for integers * take advantage of reduce storage size and fast bit (and, or, xor, not) operations * provide basic (saturation) math support. Saturation math means that adding two integers whose result would be greater than the integer range will result in clipping of the result to the maximum value representable by the integer type. * support for super-conductive object cache allows efficient multi-core threading of algorithms using this type. * Pack and unpack bit arrays for much faster boolean processing. The same object type can be used to work with three different integer types and integer precision is never changed implicitely. Mixing of different integer types or mixing with real types is not supported to avoid hidden cost of repeated conversions. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples() { void Example() { TVecInt a = new TVecInt(); a.SetIt(new int[] {1,2,4,3}); a.SortAscending(); // a = 1,2,3,4 } } *) TVecInt = class(TAbstractMtxVecInt ) strict private function InternalResize(Len: integer; ZeroIt: boolean): TVecInt; function GetIntegerValues: string; strict protected function Int32CachePointer: TIntegerArray; override; function Int16CachePointer: TSmallIntArray; override; function Int8CachePointer: Math387.TByteArray; override; function Int32CacheOffset: integer; override; function Int16CacheOffset: integer; override; function Int8CacheOffset: integer; override; procedure SetSubRangeDirect(Index: integer; Len: integer); override; procedure SetSubRangeDirect(const Src: TMtxVecBase; Index: integer; Len: integer); override; procedure SubRangeSaveState; override; procedure HookPointers; override; function CacheLength: integer; override; function CacheLengthInBytes: Int64; override; procedure setActualSize(const byteCount: Int64); override; procedure SetIntPrecision(const value: TIntPrecision); override; function get_Bits(const Indx: Int64): boolean; procedure set_Bits(const Indx: Int64; const value: boolean); function StringsToValuesInternal(const srcList: TStrings; const aDelimiter: string): TMtxVecBase; overload; override; function ValuesToStringsInternal(const dstList: TStrings; const aDelimiter: string; const Align: TFixedTextAlign; const Headers: boolean; const ColumnWidth: integer): integer; overload; override; protected function get_DefaultArray(const Indx: integer): integer; procedure set_DefaultArray(const Indx, value: integer); procedure set_BitCount(const value: Int64); function get_BitCount: Int64; strict protected procedure SetLength(const Value: integer); override; public function ToolTip: string; constructor Create; overload; override; procedure Adopt(AArray: PAPointer; ALength: integer; Precision: TIntPrecision); overload; procedure Disown(out AArray: PAPointer; out ALength: integer); overload; procedure Assign(Src: TPersistent); override; procedure Disown(); overload; (*Releases this object back to cache. This method does the same as the routine. *) procedure FreeToCache; override; (*Sets size to 0 and releases associated memory.*) procedure Clear; override; (*Cumulative sum. Calculate the cumulative sum for all calling object elements in-place. var a: TVecIn; begin CreateIt(a); try a.SetIt([1,2,3,4]); a.CumSum; // a = [1,3,6,10] finally FreeIt(a); end; end; *) function CumSum: TVecInt; overload; (*Calculate the cumulative sum for all Vec elements. Store the results in calling object. Size and properties of the calling object are set implicitly. *) function CumSum(const Vec: TVecInt): TVecInt; overload; (*Concatenates an array of TVecInt objects. Concatenates an array of TVecInt objects. The method copies the contents of all TVecInt objects from the Src array to the calling object. The and Complex properties of the calling vector are set implicitly. An exception is raised, if Complex properties of TVecInt objects do not match. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples { void Example() { TVecInt a,b,c,d; MtxVec.CreateIt(out a, out b, out c, out d); try { a.SetIt(new int[] {1,2,3}); b.Copy(a); c.Concat([a,b]); // c = [1,2,3,1,2,3] d.Size(10); d.SetZero(0,4); d.Concat(4,[c]); // d = [0,0,0,0,1,2,3,1,2,3] } finally { MtxVec.FreeIt(ref a, ref b, ref c, ref d); } } } *) function Concat(const Src: array of TVecInt): TVecInt; overload; (*Copies the contents of all TVecInt objects from the Src array to the calling vector elements, starting with at Index. The and properties of the calling vector must be set explicitly. An exception is raised, if Complex properties of TVecInt objects do not match or if the sum of Length's exceeds the Length property of the calling object. *) function Concat(Index: integer; const Src: array of TVecInt): TVecInt; overload; (*Copies the k-th diagonal from the TMtxInt object. Copies the k-th diagonal from the TMtxInt object. If k = 0 then the main diagonal is copied, if k < 0 then the subdiagonal is copied and if k > 0 then the k-th super diagonal is copied to the calling vector. In the following example we setup a matrix, populate it with values and then extract it's main diagonal to a vector. var a: TVecInt; d: TMtxInt; begin CreateIt(a); CreateIt(d); try // setup matrix d.SetIt(2,2,[1,-2, 3, 4]); // get main diagonal from matrix a.Diag(d,0); // a now containes [1,4]; finally FreeIt(a); FreeIt(d); end; end; *) function Diag(const Mtx: TMtxInt; k: integer): TVecInt; (* Stores distinct values from Src in to Dst. *) function Distinct(const Src: TMtxVecInt): TVecInt; (*The difference between two succesive vector elements. Calculate the difference for all calling vector elements. The following formula is used to calculate the difference: The Length of calling vector is automatically decremented by one. *) function Difference(Lag: Integer = 1): TVecInt; overload; (*Calculate the difference for all Vec elements. Store the results in the calling vector. The of the calling vector is set to one less the length of Vec. *) function Difference(const Vec: TMtxVecInt; Lag: Integer = 1): TVecInt; overload; (*Finds and gathers vector elements. Fills the Indexes vector with indexes, of those elements where the Op comparison between a and b is True. Op string parameter can be '<', '>', '>=','<=','=' or '<>'. The method also copies or "gathers" the matched elements to the calling vector. Both the calling vector and Indexes will be sized to match a.Length. On return, both will be subranged to reflect actual number of matching elements. The method will not raise an exception, if the calling vector (Self) or Indexes parameter are already subranged. *) (*The b parameter is of integer type.*) function FindAndGather(const a: TMtxVecInt; const op: string; const b: integer; const Indexes: TVecInt = nil): TVecInt; overload; (*The b parameter is of type.*) function FindAndGather(const a: TMtxVecInt; const op: string; const b: TMtxVecInt; const Indexes: TVecInt = nil): TVecInt; overload; (*Copies a column from matrix. Copies the Col-th column from Mtx matrix to calling vector. The and properties of calling vector are adjusted automatically. An exception is raised if condition checking is enabled and Col is greater than Mtx.Cols-1. var a: TVecInt; b: TMtxInt; begin CreateIt(a); CreateIt(b); try b.SetIt(2,2,[1,2, 3,4]); a.GetCol(b,0); // a now contains [1,3] finally FreeIt(a); FreeIt(b); end; end; *) function GetCol(const Mtx: TMtxInt; Col: integer): TVecInt; overload; (*Copy the Col-th column elements [Row]..[Row+Len-1] to calling vector elements [Index]..[Index+Len-1]. The property of calling vector must be set explicitly. An exception is raised if condition checking is enabled and column array borders are overrun. *) function GetCol(const Mtx: TMtxInt; Row, Col, Index, Len: integer): TVecInt; overload; (*Copy the Col-th column elements [Row]..[Row+Len-1] to calling vector. The and properties of calling vector are adjusted automatically. An exception is raised if condition checking is enabled and column array borders are overrun. *) function GetCol(const Mtx: TMtxInt; Row, Col, Len: integer): TVecInt; overload; (*Copies a row from matrix. Copies the Row-th row from Mtx matrix to calling vector. The and properties of calling vector are adjusted automatically. An exception is raised if condition checking is enabled and Row is greater than Mtx.Rows-1. var a: TVecInt; b: TMtxInt; begin CreateIt(a); CreateIt(b); try b.SetIt(2,2,[1,2, 3,4]); a.GetRow(b,0); // a now contains [1,2] finally FreeIt(a); FreeIt(b); end; end; *) function GetRow(const Mtx: TMtxInt; Row: integer): TVecInt; overload; (*Copy the Row-th column elements [Col]..[Col+Len-1] to calling vector elements [Index]..[Index+Len-1]. The property of calling vector must be set explicitly. An exception is raised if condition checking is enabled and column array borders are overrun. *) function GetRow(const Mtx: TMtxInt; Row, Col, Index, Len: integer): TVecInt; overload; (*Copy the Row-th column elements [Col]..[Col+Len-1] to calling vector. The and properties of calling vector are adjusted automatically. An exception is raised if condition checking is enabled and column array borders are overrun. *) function GetRow(const Mtx: TMtxInt; Row, Col, Len: integer): TVecInt; overload; (*Gather vector elements. Gather the elements of vector X and store them to the calling vector according to the IndexType, Increment and Offset parameters. The Indexes vector is used only if IndexType is either indVector or indMask. If IndexType is indVector, the values from the Indexes vector denote the index positions in the X vector from which the values should be copied to the calling vector. The Indexes vector must have the indexes stored in the IValues array. The IValues integer arrays points the same memory as Values array. The Increment and Offset parameters are used only if TIndexType is indIncrement. They define the initial offset and a fixed step (increment) between elements to be gathered. If IndexType is indMaks the Indexes vector must have the same size as the X vector. The routine will copy only those elements from the X vector to the calling vector, for which there is a 1 at the coresponding index in the Indexes vector. The elements copied from the X vector will be stored consecutively in the calling vector. See the method to see how to undo the gathering. The performance of the CPU heavily depends on the assumption that elements are stored at consecutive memory locations. If it is neccessary to apply a set of operations only to elements at specific indexes, performance-wise it can proof to be very helpfull, if the elements are gathered first. *) function Gather(const X: TMtxVecInt; const Indexes: TVecInt = nil; IndexType: TIndexType = indVector; Increment: integer = 1; Offset: integer = 0): TVecInt; overload; (* Gathers elements from X starting at Offset and with Increment to the calling object. *) function GatherByIncr (const X: TMtxVecInt; Increment: integer = 1; Offset: integer = 0): TVecInt; overload; (* Gathers elements from X specified by indices stored in Indexes the calling object. *) function GatherByIndex(const X: TMtxVecInt; const Indexes: TVecInt): TVecInt; overload; (* Gathers elements from X specified by non-zero values stored in the Mask to the calling object. *) function GatherByMask (const X: TMtxVecInt; const Mask: TMtxVecInt; const MaskNonZeroCount: integer = -1): TVecInt; overload; (* Counts groups of equal numbers within Bins. The maximum integer value within SrcBins parameter defines the Size of the calling vector. Within each IValues[Idx] of the result will be number of Bin items, which have value equal to "Idx". The size of self is set to SrcBins.Max+1. SrcBinsMax with default value of -1 indicates that Bins.Max is computed internally. The routine does not perform additional range checking, if BinsMax is provided explicitely (memory overwrite is possible, if indexes are less than zero or more than calling vector length). *) function GroupCount(const SrcBins: TMtxVecInt; const SrcBinsMax: integer = -1): TVecInt; overload; (* Counts groups of equal numbers within Bins. The routine checks the size of the calling object, if it is equal to SrcBinsMax+1, and raises an exception, if not. The rouine does not size the calling object and also does not perform initialization to zero. It can be used for iterative calls to fill the same histogram. *) function GroupCountIteration(const SrcBins: TMtxVecInt; const SrcBinsMax: integer): TVecInt; overload; (* Scatters Src elements defined with the Mask to the calling object. *) function ScatterByMask(const Src: TMtxVecInt; const Mask: TMtxVecInt; allow_resizing: boolean = False): TMtxVecInt; overload; override; (*Packs integer storage vector to bit storage. All elements are checked only, if they are zero or not. *) function BitPack(const Src: TVecInt): TVecInt; overload; (*Unpacks bit storage to specified integer storage.*) function BitUnpack(const Src: TVecInt; const dstPrecision: TIntPrecision = prInt32): TVecInt; overload; (*Applies median filter with size Mask to the calling vector. Median filter is a nonlinear filter which replaces each element of the calling vector with the median value, calculated over the fixed range (mask) centered around that element. *) function Median(MaskSize: integer): TVecInt; overload; (*Applies median filter with size Mask to data in Src and stores the result in the calling vector. Median filter is a nonlinear filter which replaces each element of the calling vector with the median value, calculated over the fixed range (mask) centered around that element and stores the result in the calling vector. *) function Median(const Src: TMtxVecInt; MaskSize: integer): TVecInt; overload; (*Fills the calling vector with a series following linear rule. Fills the calling vector with a series following the rule: Values[k] := k (Offset is zero and Step is one). var a: TVecInt; begin CreateIt(a); try a.Size(5,prInt32); a.Ramp(0,2); // [0, 2, 4, 6, 8] finally FreeIt(a); end; end; which is identical to: CreateIt(a); try a.Size(5,prInt32); for i:= 0 to a.Length-1 do a[i] := i*2; finally FreeIt(a); end; *) function Ramp: TVecInt; overload; (*Fills the calling vector. Method uses the following rule: Values[k] := Offset + k*Step. *) function Ramp(Offset, Step: double): TVecInt; overload; (*Fills the calling vector elements with linear rule and randomly shuffles the indexes. Fills the calling vector with a series following the rule: Values[k] := k and then scrambles the contents of the vector randomly by using the Fisher–Yates shuffle. *) function RandomRamp: TVecInt; overload; (*Randomly shuffles the content of the vector. Scrambles the contents of the vector randomly by using the Fisher–Yates shuffle. *) function RandomShuffle: TVecInt; overload; (*Resizes vector size while preserving values. Resizes calling vector to Len and fills it with Src vector first Len values. If Src length is less than Len and ZeroIt parameter is true, the remaining calling vector values are set to zero. var a, b: TVecInt; begin CreateIt(a,b); try a.SetIt([1,2,3]); b.SetIt([9]); b.Resize(a,7,True); // b=(9,1,2,3,4,0,0,0) finally FreeIt(a,b); end; end; *) function Resize(const Src: TVecInt; Len: integer; ZeroIt: boolean = False): TVecInt; overload; (*Resizes calling vector Length to Len. If is less than Len and ZeroIt parameter is true, the remaining calling vector values are set to zero. var a: TVecInt; begin CreateIt(a); try a.SetIt([1,2,3]); a.Resize(7,True); // a= [1,2,3,0,0,0,0] finally FreeIt(a); end; end; *) function Resize(Len: integer; ZeroIt: boolean = False): TVecInt; overload; function ReadHeader(const SrcStream: TStream; Endian: TEndianness = MtxSystemEndianness): TPrecision; overload; override; procedure WriteHeader(const DstStream: TStream; aPrecision: TPrecision = prInteger; Endian: TEndianness = MtxSystemEndianness); overload; override; procedure Reset; override; (*A cyclic shift on all calling vector elements. Performs cyclic shift on all calling vector elements. Offset can be any integer number, positive or negative. *) function Rotate(Offset: integer): TVecInt; overload; (*A cyclic shift on vector elements in range. Performs cyclic shift on all source vector elements and stores them to calling vector elements [Index .. Index+Len-1]. The number of elements to shift is specified in the Offset parameter. Offset can be any integer number, positive or negative. An exception is raised if array borders are overrun/underrun. *) function Rotate(const Src: TMtxVecInt; Offset: integer): TVecInt; overload; (*Reverse vector elements. The method reverses vector elements by using the following equation: This overload reverses all calling vector elements in-place. var a: TVecInt; begin CreateIt(a); try a.SetIt([1,2,3,4]); a.Reverse; // a = [4,3,2,1] finally FreeIt(a); end; end; *) function Reverse: TVecInt; overload; (*Reverse all Vec elements. Xtore the result in the calling vector elements. The property of the calling vector are set implicitly to match Vec vector. *) function Reverse(Vec: TMtxVecInt): TVecInt; overload; (*Sets object values. Set object values. Method call does not change object's size, but it does check for array overrun. The elements of A array are copied to the calling object elements, starting at Index. The IntPrecision property of the calling object is not changed. *) function SetIt(Index: integer; const A: array of integer): TVecInt; overload; (*Sets object values. Set object values. The size of the calling object is adjusted to match the length of the array. The elements of A array are copied to the calling object elements. The IntPrecision property of the calling object is not changed. *) function SetIt(const A: array of integer): TVecInt; overload; function SetInteger(const A: array of integer): TVecInt; overload; (*Defines a sub-vector. Define a subvector of the Src vector starting at BeginIndex and ending at EndIndex (inclusive). *) procedure SetSubIndex(const Src: TMtxVecInt; BeginIndex, EndIndex: integer); overload; (*Defines the calling vector to have the view of the same memory as Src. Src vector's Length property may not change while any other object has it's own view of it. a.SetSubRange(b,..); This SetSubRange method must be handled with great care. Namely: * b can be freed before "a" and accessing "a" gives AV. * a can be further subranged with c and same problem occurs when b is freed before c. * If you resize b, all objects which have subranged b are no longer pointing to valid memory. * b can Subrange other objects. Similar problem as when changing the size of b. Again all objects which have subranged b are not longer pointing to valid memory. All this can lead to hard to find bugs. *) procedure SetSubRange(const Src: TMtxVecInt); overload; (*Sets the size of the vector to match an array. Sets the Length of the calling vector to match the length of the array. IntPrecision property value is preserved. *) procedure SizeFromArray(const Src: TCplxArray); overload; (*Sets the size of the vector to match an array. Sets the Length of the calling vector to match the length of the array. IntPrecision property value is preserved. *) procedure SizeFromArray(const Src: TDoubleArray); overload; (*Sets the size of the vector to match an array. Sets the Length of the calling vector to match the length of the array. IntPrecision property value is preserved. *) procedure SizeFromArray(const Src: TSingleArray); overload; (*Sets the size of the vector to match an array. Sets the Length of the calling vector to match the length of the array. IntPrecision property value is preserved. *) procedure SizeFromArray(const Src: TIntegerArray); overload; (*Sets the size of the vector to match an array. Sets the Length of the calling vector to match the length of the array. IntPrecision property value is preserved. *) procedure SizeFromArray(const Src: TSmallIntArray); overload; (*Sets the size of the vector to match an array. Sets the size (Length) of the caling vector to match the length of the array. IntPrecision property value is preserved. *) procedure SizeFromArray(const Src: Math387.TByteArray); overload; (*Do a shift on all calling vector elements. Performs shift on all calling vector elements. Offset can be any integer number, positive or negative. *) function Shift(Offset: integer): TVecInt; overload; (*Do a shift on vector elements in range. Performs shift on all source vector elements and stores them to calling vector elements [Index .. Index+Len-1]. The number of elements to shift is specified in the Offset parameter. Offset can be any integer number, positive or negative. An exception is raised if array borders are overrun/underrun. *) function Shift(const Src: TVecInt; Offset: integer): TVecInt; overload; (*Sets the size and storage precision of the calling object.*) function Size(aLength: integer; aPrecision: TIntPrecision = prInt32): TVecInt ; overload; function Size(const Src: TMtxVecBase; aPrecision: TIntPrecision): TMtxVecInt ; override; function Size(const Src: TMtxVecBase): TMtxVecInt ; override; (*Sort all calling vector elements in ascending order in-place. *) function SortAscend: TVecInt; overload; (*Sort all calling vector elements in ascending order in-place. calling vector, storing sorted values. After execution stores sorted values indices. Size of DstSortIdx and calling vector are adjusted automatically. *) function SortAscend(DstSortIdx: TVecInt): TVecInt; overload; (*Sort all calling vector elements in descending order in-place. *) function SortDescend: TVecInt; overload; (*Sort all calling vector elements in descending order in-place. calling vector, storing sorted values. After execution stores sorted values indices. Size of DstSortIdx and calling vector are adjusted automatically. *) function SortDescend(DstSortIdx: TVecInt): TVecInt; overload; (*Convert strings in srcList to integers. Convert strings in srcList to integers according to the IntPrecision property and store them in the Values array of the calling vector. The of the calling vector is set to srcList.Count. var a,b: TVecInt; begin CreateIt(a,b); try a.SetIt([1,2,3,4]); a.Add(1) b.Size(a); b.SetVal(1); a.Add(b); Richedit1.Clear; Memo1.Clear; a.ValuesToStrings(Richedit1.Lines); b.ValuesToStrings(Richedit1.Lines); a.ValuesToStrings(Memo1.Lines); b.ValuesToStrings(Memo1.Lines); Memo1.Lines.SaveToFile('C:\Test.txt'); Memo1.Lines.LoadFromFile('C:\Test.txt'); a.StringsToValues(Memo1.Lines); finally FreeIt(a,b); end; end; *) procedure StringsToValues(const srcList: TStrings); overload; (*Convert strings in srcList to integers starting at ListIndex. Store them in the Values array of the calling vector from Index to Index+Len-1. The Length property of the calling vector is not changed. If array bounds are overrun and exception is raised. *) function StringsToValues(const srcList: TStrings; ListIndex: integer; Index: integer = 0; Len: integer = MtxVecEOA): TVecInt; overload; (*Converts the content of the Values array of the calling vector to a list of strings. Converts all elements of the calling vector to strings with specified formating and stores them in dstList, by using the Add method of TStrings object. Values are appended to existing content of dstList. Set Equidistant to True, if you are using fixed width font and need to have the text right aligned. Performance note: This routine will be exceedingly slow, if TRichEdit.Lines or TMemo.Lines are passed as a parameter for dstList. Use TStringList or StringList types and then call TMemo.Lines.AddStrings(yourList) for best results. procedure TForm1.Button1Click(Sender: TObject); var a,b: TVecInt; begin CreateIt(a,b); try a.SetIt([1,2,3,4]); a.Cos; b.Size(a); b.SetVal(1); a.Add(b); Richedit1.Clear; Memo1.Clear; a.ValuesToStrings(Richedit1.Lines); b.ValuesToStrings(Richedit1.Lines); a.ValuesToStrings(Memo1.Lines); b.ValuesToStrings(Memo1.Lines); Memo1.Lines.SaveToFile('C:\Test.txt'); Memo1.Lines.LoadFromFile('C:\Test.txt'); a.StringsToValues(Memo1.Lines); finally FreeIt(a,b); end; end; *) function ValuesToStrings(const dstList: TStrings; const Align: TFixedTextAlign = ftaNone; const Headers: boolean = false; const ColumnWidth: integer = -1): integer; overload; (*Convert elements from Index to Index+Len-1 of the calling vector to strings. Store values in dstList starting at ListIndex. If dstList is not large enough, the method will use the add method of dstList object. Set Equidistant to True, if you are using fixed width font and need to have the text right aligned. Performance note: This routine will be exceedingly slow, if TRichEdit.Lines or TMemo.Lines are passed as a parameter for dstList. Use TStringList or StringList types and then call TMemo.Lines.AddStrings(yourList) for best results. *) function ValuesToStrings(const dstList: TStrings; ListIndex, Index, Len: integer; const Align: TFixedTextAlign = ftaNone; const Headers: boolean = false; const ColumnWidth: integer = -1): integer; overload; (*Convert all vector elements to text.*) procedure ValuesToText(out Text: String); overload; (*Convert Index..Index+Len-1 vector elements to text.*) procedure ValuesToText(out Text: String; Index, Len: integer); overload; (*Returns content as a string. Values will be separated by line breaks. *) function ToString: string; override; (*Parses string content as vector. Values need to be separated by line breaks. For other parsing options call StringToValues. The Parse method works in pair with the ToString method both meant to be a reverse of the other, but do not preserve any other property of the vector except only values. Use SaveToStream/LoadFromStream methods for binary storage option, which uses up to 10x less memory and is a lot faster to save and load. *) function Parse(const Src: string): TVecInt; (*Returns content as a string suitable for display as a tooltip.*) property IntegerValues: string read GetIntegerValues; public (*Allows reading/writing individual bits of the array. Use BitPack and BitUnpack for much faster access to bit data. *) property Bits[const Indx: Int64]: boolean read get_Bits write set_Bits; (*Allows sizing the internal storage to accomodate desired number of bits. Use BitPack and BitUnpack for much faster access to bit data or Bits[i] property for individual bit access. Setting BitCount will also call the Size method. The Length of the internal arrays will be adjusted so that all bits can be stored with padding of the last 32bit integer element. The value of BitCount, which is not an integer multiple of the IntPrecision is preserved only by certain methods where applicable and where it is not ambiguous. The value of the property affects only the results of BitPack and BitUnpack routines. *) property BitCount: Int64 read get_BitCount write set_BitCount; (*Allows setting/getting the integer value at position Indx. Allows setting/getting the 32bit integer value at position Indx. In Delphi, this property reads/writes to the same memory as , and properties. *) property DefaultArray[const Indx: integer]: integer read get_DefaultArray write set_DefaultArray; default; end; (*List of TVecInt objects. List of objects. The list manages the object list. The TVec objects are created and destroyed by the list. List size can be controled with the Count property. *) TVecIntList = class(TObjectsList) strict private function GetItems(i: integer): TVecInt; procedure SetItems(i: integer; const Value: TVecInt); procedure SetCount(const Value: integer); reintroduce; function GetCount: integer; reintroduce; public (*Creates and adds a new TVecInt object to the list. The function returns the Index at which the newly created object resides in the list. *) function Add: integer; overload; virtual; (*Creates and adds a new TVecInt object to the list. The function returns the Index at which the object resides in the list. The object will not be owned (freed by the List), when the list is destroyed if Owned parameter remains false. *) function Add(const Src: TVecInt): integer; overload; virtual; (*Assigns the source to the calling object. All the data is copied. *) procedure Assign(Source: TVecIntList); virtual; procedure SetFullRange; destructor Destroy; override; (*Save the list to a stream.*) procedure SaveToStream(const DstStream: TStream); overload; virtual; (*Load the list from a stream.*) procedure LoadFromStream(const SrcStream: TStream); overload; virtual; property Item[i: integer]: TVecInt read GetItems write SetItems; default; property Count: integer read GetCount write SetCount; end; (*Class for 16bit one dimensional integer arrays. Class for accessing and manipulating 16bit one dimensional arrays. It handles memory allocation and basic vector arithmetics. *) TVecSmallInt = class(TVecInt) strict protected procedure HookPointers; override; private function get_DefaultArray(const Indx: integer): SmallInt; procedure set_DefaultArray(const Indx: integer; const value: SmallInt); public (*Allows setting/getting the 16bit integer value at position Indx. Allows setting/getting the 16bit integer value at position Indx. *) Values: TSmallIntArray; (*Allows setting/getting the integer value at position Indx. Allows setting/getting the 16bit integer value at position Indx. This property reads/writes to the same memory as property. *) property DefaultArray[const Indx: integer]: SmallInt read get_DefaultArray write set_DefaultArray; default; function PValues(Index: integer): PAPointer; override; constructor Create; override; end; (*Class for 8bit one dimensional integer arrays. Class for accessing and manipulating 8bit one dimensional arrays. It handles memory allocation and basic vector arithmetics. *) TVecByte = class(TVecInt) strict protected procedure HookPointers; override; private function get_DefaultArray(const Indx: integer): Byte; procedure set_DefaultArray(const Indx: integer; const value: Byte); public (*Allows setting/getting the 8bit integer value at position Indx. Allows setting/getting the 8bit integer value at position Indx. *) Values: Math387.TByteArray; (*Allows setting/getting the integer value at position Indx. Allows setting/getting the 8bit value at position Indx. This property reads/writes to the same memory as property. *) property DefaultArray[const Indx: integer]: Byte read get_DefaultArray write set_DefaultArray; default; (*Obtains a pointer to the integer value of the vector at Index. The function returns address of element at Values[i]. Under .NET, internal memory must be Pinned first. See and *) function PValues(Index: integer): PAPointer; override; constructor Create; override; end; (*Two dimensional array - matrix. Use the matrix class to perform matix operations like multiplication addition, subtraction, solve a system of linear equations, compute eigenvalues, singular value decomposition, least squares solution, 2D FFT's, parallel 1D FFT's and more. *) TMtxInt = class(TAbstractMtxVecInt ) strict private FRows: integer; FCols: integer; fColsBitCount: integer; procedure SetRows(const value: integer); procedure SetCols(const value: integer); function GetIntegerValues: string; procedure SetColsBitCount(const value: integer); procedure ValidateRange (Row, Col, ToRow, ToCol: integer); strict protected FLeadingCols: integer; SRows, SCols: integer; SLeadingCols: integer; function CacheLength: integer; override; function CacheLengthInBytes: Int64; override; procedure HookPointers; override; function Int32CachePointer: TIntegerArray; override; function Int16CachePointer: TSmallIntArray; override; function Int8CachePointer: Math387.TByteArray; override; function Int32CacheOffset: integer; override; function Int16CacheOffset: integer; override; function Int8CacheOffset: integer; override; procedure SetIntPrecision(const value: TIntPrecision); override; function LowerTriangleInternal(const Mtx: TMtxInt; ZeroUpper, Diagonal: boolean): TMtxInt; overload; function UpperTriangleInternal(const Mtx: TMtxInt; ZeroLower, Diagonal: boolean): TMtxInt; overload; procedure SetLeadingCols(const value: integer); function GetLeadingCols: integer; procedure SubRangeSaveState; override; procedure SubRangeLoadState; override; procedure SetSubRangeDirect(Index, Len: integer); override; procedure SetSubRangeDirect(const Src: TMtxVecBase; Index, Len: integer); override; procedure SetSubRangeDirect2(const Src: TMtxVecBase; Index: Integer; aRows, aCols: Integer); procedure SetLength(const value: integer); override; function StringsToValuesInternal(const srcList: TStrings; const aDelimiter: string): TMtxVecbase; overload; override; function ValuesToStringsInternal(const dstList: TStrings; const Delimiter: string; const Align: TFixedTextAlign; const Headers: boolean; const ColumnWidth: integer): integer; overload; override; public function get_IValues(const RowIdx, ColIdx: integer): integer; function get_SValues(const RowIdx, ColIdx: integer): SmallInt; function get_BValues(const RowIdx, ColIdx: integer): Byte; procedure set_IValues(const RowIdx, ColIdx: integer; const value: integer); procedure set_SValues(const RowIdx, ColIdx: integer; const value: SmallInt); procedure set_BValues(const RowIdx, ColIdx: integer; const value: Byte); function GetBits(const row, col: integer): boolean; procedure SetBits(const row, col: integer; const value: boolean); strict protected function get_DefaultArray(const Indx1, Indx2: integer): integer; procedure set_DefaultArray(const Indx1, Indx2: integer; const value: integer); public {$WARN HIDING_MEMBER OFF} (*Access elements of the matrix. The RowIdx indicates the row index and the ColIdx parameter indiciates the column index. *) property IValues[const RowIdx, ColIdx: integer]: integer read get_IValues write set_IValues; (*Access elements of the matrix. The RowIdx indicates the row index and the ColIdx parameter indiciates the column index. *) property SValues[const RowIdx, ColIdx: integer]: SmallInt read get_SValues write set_SValues; (*Access elements of the matrix. The RowIdx indicates the row index and the ColIdx parameter indiciates the column index. *) property BValues[const RowIdx, ColIdx: integer]: Byte read get_BValues write set_BValues; (*Allows reading/writing individual bits of the array. Use BitPack and BitUnpack for much faster access to bit data. *) property Bits[const row, col: integer]: boolean read GetBits write SetBits; (*Access elements of the matrix without specifying the name of the property. This property allows you to access elements of the matrix without specifying the name of the property. For example: amtx[i,j] := 1; // where amtx is a TMtxInt object . Note Default array property is slower than array pointers. The default array property supports only 32bit integer values (IValues). *) property DefArray[const Indx1, Indx2: integer]: integer read get_DefaultArray write set_DefaultArray; default; (*Returns content as a string suitable for display as a tooltip.*) property IntegerValues: string read GetIntegerValues; (*Returns content as a string. Values will be separated by line breaks. *) function ToString: string; override; (*Parses string content as vector. Values need to be separated by line breaks. For other parsing options call StringToValues. The Parse method works in pair with the ToString method both meant to be a reverse of the other, but do not preserve any other property of the vector except only values. Use SaveToStream/LoadFromStream methods for binary storage option, which uses up to 10x less memory and is a lot faster to save and load. *) function Parse(const Src: string): TMtxInt; function DataIndex(aRow, aCol: integer; aPrecision: TIntPrecision): integer; overload; function DataIndex(aRow, aCol: integer): integer; overload; (*Sizes the matrix according to bit storage required.*) function BitSize(const bitRows, bitCols: integer): TMtxInt; (*Unpacks bit storage to specified integer storage.*) function BitUnpack(const Src: TMtxInt; const dstPrecision: TIntPrecision = prInt32): TMtxInt; overload; (*Packs integer storage matrix to bit storage. All elements are checked only, if they are zero or not. *) function BitPack(const Src: TMtxInt): TMtxInt; overload; (*Create a new TMtxInt object. Creates a new TMtxInt object. You should use the where possible and avoid using the Create constructor, but only in cases when the object is created and destroy within the same routine. var A: TMtxInt; begin A := TMtxInt.Create; try A.Size(20,20); finally A.Free; // takes about 500 CPU cycles end; CreateIt(A); try A.Size(20,20,false); finally FreeIt(A); // takes only about 40 CPU cycles end; end; *) constructor Create; overload; override; procedure FreeToCache; override; procedure Clear; override; function ToolTip: string; procedure Assign(Src: TPersistent); override; (*Copies matrix values to a 2D array. Copies all matrix values to a 2D array. *) procedure CopyToArray(var Dst: T2DIntegerArray); overload; (*Copies all matrix values to a 2D array.*) procedure CopyToArray(var Dst: T2DSmallIntArray); overload; (*Copies all matrix values to a 2D array.*) procedure CopyToArray(var Dst: T2DByteArray); overload; (*Copies the matrix from a 2D array. Sizes the matrix to match the size of the 2D array and copies all the values. *) procedure CopyFromArray(const Src: T2DIntegerArray); overload; (*Sizes the matrix to match the size of the 2D array and copies all the values.*) procedure CopyFromArray(const Src: T2DSmallIntArray); overload; (*Sizes the matrix to match the size of the 2D array and copies all the values.*) procedure CopyFromArray(const Src: T2DByteArray); overload; (*Sizes the Dst array to match the matrix. Sizes the Dst array to match the size of the matrix. *) procedure SizeToArray(var Dst: T2DIntegerArray); overload; (*Sizes the Dst array to match the size of the matrix.*) procedure SizeToArray(var Dst: T2DSmallIntArray); overload; (*Sizes the Dst array to match the size of the matrix.*) procedure SizeToArray(var Dst: T2DByteArray); overload; (*Sizes the calling matrix to match the size of the array. Sizes the calling matrix to match the size of the array. IntPrecision property value is preserved. *) procedure SizeFromArray(const Src: T2DIntegerArray); overload; (*Sizes the calling matrix to match the size of the array. IntPrecision property value is preserved. *) procedure SizeFromArray(const Src: T2DSmallIntArray); overload; (*Sizes the calling matrix to match the size of the array. IntPrecision property value is preserved. *) procedure SizeFromArray(const Src: T2DByteArray); overload; (*Sets the size of matrix. Set the calling matrix properties: * = ARows, * = ACols Calling the Size method does not preserve the contents of the matrix. Use the Resize method, if you want to preserve existing values. Note The Size method performs an out-of-memory safe resize, if the matrix already has memory allocated. This prevents out of memory message for example when redefining the size of the matrix from single column to single row: A.Rows := 10000; // matrix size = 0 A.Cols := 1; // matrix size = 10000 // ... A.Cols := 10000; // matrix size = 100 000 000 (problems here) A.Rows := 1; // matrix size = 10 000 var A: TMtxInt; begin CreateIt(A); try A.Size(2,1); // 2x1 integer matrix A.SetZero; // A becomes: // [0] // [0] finally FreeIt(A); end; end; *) function Size(ARows, ACols: integer; aPrecision: TIntPrecision): TMtxInt ; overload; (*Specifies size of an integer matrix. The Value of IntPrecision property is preserved. *) function Size(ARows, ACols: integer): TMtxInt ; overload; function Size(const Src: TMtxVecBase; aPrecision: TIntPrecision): TMtxVecInt ; override; function Size(const Src: TMtxVecBase): TMtxVecInt ; override; (*Returns the 1D index in to the matrix. Returns: Row*Mtx.Cols + Col *) function IndexOf(const Row, Col: integer): integer; (*Obtain a pointer to a matrix from object cache. Returns a pointer to a matrix from object cache. Same as calling the CreateIt routine. *) class function CreateFromCache: TMtxInt; (*Returns a pointer to the real value stored at Row and Col.*) function PIValues(const Row, Col: integer): PPInteger; overload; (*Returns a pointer to the real value stored at Row and Col.*) function PSValues(const Row, Col: integer): PPSmallInt; overload; (*Returns a pointer to the real value stored at Row and Col.*) function PBValues(const Row, Col: integer): PPByte; overload; (*Adopts a pointer to one dimensional array. Adopts a pointer to AArray array. The method sets the calling matrix property to prInt32, to ARows, to ACols and Values1D and CValues1D to Pointer(AArray). Note You must call the method, before you destroy the matrix. Use this method to save a copy operation. You should be very careful never to resize the calling matrix while it contains the adopted memory or call any routines that would require the matrix to reallocate the memory. *) procedure Adopt(const AArray: PAPointer; const ARows, ACols: integer; const aIntPrecision: TIntPrecision); (*Exchange matrix columns. Exchange the i-tj and j-th columns of the calling matrix in-place. An exception is raised if matrix bounds are overrun. *) function ColExchange(i, j: integer): TMtxInt; overload; (*Permute the columns of the Src matrix. The parameter PermuteIdx contains indexes of columns P[i] to which column at index "i" is to be moved. The result of the permutation is stored in the calling matrix. Only entire matrix can be copied. *) function ColPermute(const Src: TMtxInt; const PermuteIdx: TVecInt): TMtxInt; overload; (*Permute the rows of the Src matrix. The parameter PermuteIdx contains indexes of columns P[i] to which row at index "i" is to be moved. The result of the permutation is stored in the calling matrix. Only entire matrix can be copied. *) function RowPermute(const Src: TMtxInt; const PermuteIdx: TVecInt): TMtxInt; overload; (*Concatenate an array of matrices to single matrix. Concatenate an array of matrices to form one big matrix and store the result in the calling matrix. The dimensions of the block matrices in the Src array must match, to form the new matrix. The block matrices must have matching integer precision or an exception will be raised. You must specify Arows*ACols block matrices in the Src array. The , and properties of the calling matrix are adjusted automatically. var A,B,C,D,E: TMtxInt; begin CreateIt(A,B,C,D); CreateIt(E); try A.Size(2,2); B.Size(A); C.Size(A); D.Size(A); E.Concat(2,2[A,B C,D]); // form one 4x4 matrix finally FreeIt(E); FreeIt(A,B,C,D); end; end; *) function Concat(ARows, ACols: integer;const Src: array of TMtxInt): TMtxInt; overload; (*Concenates an array of matrices horizontally. Concenate the Src matrices horizontally and store the results in the calling matrix. The , and properties of the calling matrix are adjusted automatically. An exception is raised if any of the Src matrices IntPrecision or Rows property does not match. var A,B,C,D,E: TMtxInt; begin CreateIt(A,B,C,D); CreateIt(E); try A.Size(2,2); B.Size(A); E.Size(4,4); // overwrite the lower part of the E matrix // with values from A and B E.ConcatHorz(2,2,[A,B]); //E becomes: //[E11 E12 E13 E14] //[E21 E22 E23 E24] //[A11 A12 B11 B12] //[A21 A22 B21 B22] finally FreeIt(E); FreeIt(A,B,C,D); end; end; *) function ConcatHorz(const Src: array of TMtxInt): TMtxInt; overload; (*Concenate the Src matrices horizontally and store the results in the calling matrix. The DestRow and DestCol parameters indicate the starting position (in the calling matrix) for concenating. An exception is raised, if the calling matrix array bounds are overrun. An exception is raised, if any of the Src matrices IntPrecision or Rows properties do not match. *) function ConcatHorz(DestRow, DestCol: integer;const Src: array of TMtxInt): TMtxInt; overload; (*Concenates an array of matrices vertically. Concenate the Src matrices vertically and store the results in calling matrix. The , and properties of the calling matrix are adjusted automatically. An exception is raised, if any of the Src matrices IntPrecision or Cols properties do not match. var A,B,C,D,E: TMtxInt; begin CreateIt(A,B,C,D); CreateIt(E); try A.Size(1,2); B.Size(A); E.Size(4,4); // overwrite the lower part of the E matrix // with values from A and B E.ConcatVert(2,2,[A,B]); // E becomes: //[E11 E12 E13 E14] //[E21 E22 E23 E24] //[A11 A12 E33 E34] //[B11 B12 E43 E44] finally FreeIt(E); FreeIt(A,B,C,D); end; end; *) function ConcatVert(const Src: array of TMtxInt): TMtxInt; overload; (*Concenate the Src matrices vertically and store the results in calling matrix. The DestRow and DestCol parameters indicate the starting position (in the calling matrix) for concatenating. An exception is raised, if the calling matrix array bounds are overrun. An exception is raised, if any of the Src matrices IntPrecision or Cols properties do not match. *) function ConcatVert(DestRow, DestCol: integer;const Src: array of TMtxInt): TMtxInt; overload; (*Copy the Mtx elements [MtxRow,MtxCol]..[MtxRow+NrRows-1,MtxCol+NrCols-1] to the calling matrix elements [Row,Col],,[Row+NrRows-1,Col+NrCols-1]. An exception is raised if is true and bounds are overrun. If Transpose is true, the matrix is transposed as well. *) function Copy(const Mtx: TMtxInt; MtxRow, MtxCol, Row, Col, NrRows, NrCols: integer; Transpose: boolean = false): TMtxInt; overload; (*Copies values from vector to a matrix. Copy all Vec elements to the calling matrix. Set the calling matrix property to NrRows. Set the calling matrix property to Vec.Length div NrRow (Length = Rows*Cols). The calling matrix property is adjusted automatically. An exception is raised if Vec.Length mod NrRows <> 0. var A: TMtxInt; v: TVecInt; begin CreateIt(A); Create(v); try v.SetIt([1, 0, 2, -1, 5, 1.2]) ; A.CopyVec(v); finally FreeIt(A); FreeIt(v); end; end; *) function CopyVec(const Vec: TVecInt; NrRows: Integer): TMtxInt; overload; (*Copy Vec elements [VecIndex]..[VecIndex+Len-1] to the calling matrix elements starting with [Row,Col]. An exception is raised if is true and bounds are overrun or if properties of the calling matrix and Vec do not match. *) function CopyVec(const Vec: TVecInt; VecIndex, Len, Row, Col: Integer): TMtxInt; overload; (*Cumulative sum for each of the matrix columns. Calculate the cumulative sum for each of the calling matrix columns in-place. Function performs no overflow checking. It is users responsibility to ensure that the sum does not overflow the range of the used integer storage type. var Mtx: TMtxInt; begin Mtx := TMtxInt.Create; try Mtx.Size(3,2,[1,2, 2,5, 3,1]); Mtx.CumSum; // Mtx becomes: // 1, 2 // 3, 7 // 6, 8 finally Mtx.Free; end; end; *) function CumSum: TMtxInt; overload; (*Calculate the cumulative sum for each of the X matrix columns. Store the results in calling matrix. The , and properties of the callig matrix are adjusted implicitly to match those of Mtx matrix. *) function CumSum(const Mtx: TMtxInt): TMtxInt; overload; (*Disowns a pointer to an array from matrix Values1D. The method does the opposite of the method. It will set the AArrays to Pointer(Values), ARows and ACols to matrix's and and aIntPrecision to matrix property. Use the Disown method to "disconnect" AArray from the TMtxInt.IValues1D. Disown sets IValues1D, SValues1D and BValues1D array pointers to nil and Rows, Cols properties to ACols, but without freeing the allocated memory. The allocated memory can be disowned only, if it was adopted with a call to the method. *) procedure Disown(out AArray: PAPointer; out ARows, ACols: integer; out aIntPrecision: TIntPrecision); overload; (*Disowns a pointer to an array from calling matrix Values1D. It dismisses the Values, Values1D, CValues1D array and sets the and to zero. *) procedure Disown; overload; (*Sets the matrix diagonal to values from the vector. Sets the k-th diagonal of the calling matrix to values from from the Vec object. If k = 0 then the main diagonal matrix is set, if k < 0 then the k-th subdiagonal matrix is set and if k > 0 the then the k-th super diagonal is set. The matrix must be large enough to hold diagonal or an exception is raised. var A: TMtxInt; D: TVecInt; begin CreateIt(A); CreateIt(D); try A.SetIt(2,2,[1,1, 1,2]); D.SetIt([3,4]); A.Diag(D,0); // A becomes: // [3,1] // [1,4] finally FreeIt(D); FreeIt(A); end; end; *) function Diag(const Vec: TVecInt; k: integer): TMtxInt; overload; (*Compares two matrices. Compares Mtx with the calling matrix and returns true if the matrices are equal (if all elements match in position and value). Tolerance defines the comparison tolerance. The maximum difference between elements may not exceed: +/-Tolerance. If Tolerance is omitted, a direct comparison algorithm is used. var A,B: TMtxInt; c: boolean; begin CreateIt(A,B); try A.SetIt(2,2,[1,2, 2,4]); // 2x2, int matrix B.SetIt(2,2,[1,2, 2,4]); // 2x2, int matrix c := A.Equal(B); // Check for an exact match finally FreeIt(A,B); end; end; *) function Equal(const Mtx: TMtxInt): boolean; overload; (*Constructs an eye matrix. Construct an eye matrix with ones only on main diagonal and zeros elsewhere. The number of rows and columns of an eye matrix are set by ARows and ACols parameters. The property of an eye matrix is set by aIntPrecision parameter. var A,B: TMtxInt; begin CreateIt(A); try A.Eye(3,3); // ... finally FreeIt(A); end; end; *) function Eye(ARows,ACols: integer; aIntPrecision: TIntPrecision = prInt32): TMtxInt; overload; (*Flips the matrix elements horizontally. Flip calling matrix elements horizontally - element [row, j] = element [row, Cols-j]. This operation is performed on all calling matrix rows. var A,B: TMtxInt; begin CreateIt(A,B); try A.SetIt(2,2,[1,2, 2,4]); // 2x2, integer matrix B.FlipHor(A); // B becomes: // [2,1] // [4,2] finally FreeIt(A,B); end; end; *) function FlipHor: TMtxInt; overload; (*Flip all SrcMtx matrix elements horizontally. Store the results in the calling matrix. The flip operation is performed on all SrcMtx matrix rows. The , and properties of callign matrix are adjusted automatically. *) function FlipHor(const SrcMtx: TMtxInt): TMtxInt; overload; (*Flips the matrix elements vertically Flip calling matrix elements vertically - element [j, col] = element [Rows-j, col]. This operation is performed on all calling matrix columns. var A,B: TMtxInt; begin CreateIt(A,B); try A.SetIt(2,2,[1,2, 2,4]); // 2x2, integer matrix B.FlipVert(A); // B becomes: // [2,4] // [1,2] finally FreeIt(A,B); end; end; *) function FlipVer: TMtxInt; overload; (*Flip all SrcMtx matrix elements vertically. Store the results in the calling matrix. The flip operation is performed on all SrcMtx matrix columns. The , and properties of callign matrix are adjusted automatically. *) function FlipVer(const SrcMtx: TMtxInt): TMtxInt; overload; (*The Kronecker product between two vectors. Calculates the Kronecker product between Vec1 and Vec2 and stores the result in the calling matrix. The , and properties of calling matrix are set automatically. var A: TMtxInt; V1,V2: TVecInt; begin CreateIt(A); CreateIt(V1,V2); try V1.SetIt([1,2,3]); V2.SetIt([4,5,6]); A.Kron(V1,V2); // A becomes: // [4 5 6] // [8 10 12] // [12 15 18] finally FreeIt(A); FreeIt(V1,V2); end; end; *) function Kron(const Vec1, Vec2: TVecInt): TMtxInt; overload; (*Constructs lower triangular matrix. The method uses Mtx matrix to construct a lower triangular matrix. The results are stored in the calling matrix. If the ZeroLower parameter is true then the calling matrix superdiagonal elements will be set to zero - otherwise the superdiagonal elements will not be initialized. If the Diagonal boolean parameter is true then the Mtx matrix main diagonal elements will be copied to the calling matrix main diagonal elements. If the Diagonal parameter is false, the calling matrix main diagonal elements will be set to zero. var A,B: TMtxInt; begin CreateIt(A,B); try A.SetIt(2,1,[1,2, 2,4]); // 2x2, integer matrix B.LowerTriangle(A,True,True); // B becomes: // [1,0, // [2,4] finally FreeIt(A,B); end; end; *) function LowerTriangle(const Mtx: TMtxInt; ZeroUpper, Diagonal: boolean): TMtxInt; overload; (*Compute maximum of each row. Compute maximum of each row and store the result in to Dst vector. The Dst is sized automatically. *) procedure MaxRows(const Dst: TVecInt); overload; (*Compute minimum of each row. Compute mniimum of each row and store the result in to Dst vector. The Dst is sized automatically. *) procedure MinRows(const Dst: TVecInt); overload; (*Compute maximum of each column. Compute maximum of each column and store the result in to Dst vector. The Dst is sized automatically. *) procedure MaxCols(const Dst: TVecInt); overload; (*Compute minimum of each column. Compute minimum of each column and store the result in to Dst vector. The Dst is sized automatically. *) procedure MinCols(const Dst: TVecInt); overload; (*Compute maximum and minimum of each row. Compute maximum and minimum of each row and store the result in to Dst vectors. The Dst's are sized automatically. *) procedure MaxMinRows(const DstMaxRows, DstMinRows: TVecInt); overload; (*Compute maximum and minimum of each column. Compute maximum and minimum of each column and store the result in to Dst vectors. The Dst's are sized automatically. *) procedure MaxMinCols(const DstMaxCols, DstMinCols: TVecInt); overload; (*Matrix array multiplication. Multiplies elements in Mtx matrix with the elements in the calling matrix (array multiplication) and stores the results in calling matrix. The , and properties of both matrices must match, otherwise an exception is raised. var A,B,C: TMtxInt; begin CreateIt(A,B,C); try A.SetIt(2,2,[1,2, 2,4]); B.SetIt(2,2,[1,2, 2,4]); C.MulElem(A,B); // C becomes: // [1, 4, // 4,16] finally FreeIt(A,B,C); end; end; *) function MulElem(const Mtx: TMtxInt): TMtxInt; overload; (*Multiplies elements in Mtx1 matrix with the elements in Mtx2 matrix (array multiplication) and stores the results in calling matrix. The , and properties of calling matrix are set implicitly to match those of Mtx1 and Mtx2 matrices. Mtx1 and Mtx2 Rows, Cols, and IntPrecision properties must be the same, otherwise an excetion is raised. raised. *) function MulElem(const Mtx1, Mtx2: TMtxInt): TMtxInt; overload; procedure Reset; override; (*Resizes the matrix, while preserving the values in already allocated memory. Sets the property to NewRows, property to NewCols, while preserving the values in already allocated memory. var A,B: TMtxInt; begin CreateIt(A,B); try A.SetIt(2,2,[1,3, 2,4]); B.Resize(A,3,2,True); // B becomes: // [1,2,0, // 3,4,0]); finally FreeIt(A,B); end; end; *) function Resize(NewRows , NewCols: integer): TMtxInt; overload; (*Performs resize of the calling matrix to NewRows and NewCols. Sopies the Src matrix values to the calling matrix. The elements outside the newly created matrix size are not referenced. *) function Resize(const Src: TMtxInt; NewRows, NewCols: integer): TMtxInt; overload; (*Resize and transpose. Resizes the calling matrix to NewRows and NewCols and then copies the Src matrix values to the calling matrix. The elements outside the newly created matrix size are not referenced. At the end the method also transposes the calling matrix. All this operations are performed in one single pass. *) function ResizeAndTranspose(const Src: TMtxInt; NewRows, NewCols: integer): TMtxInt; (*Rotates matrix rows 90 degrees clockwise. Rotates all calling matrix rows 90 degrees clockwise in-place (check the scheme bellow). Note This operation differs from the operation. var A,B: TMtxInt; begin CreateIt(A,B); A.SetIt(2,2,[1,3, 2,4]); B.Rotate90(A); FreeIt(A,B); end; *) function Rotate90: TMtxInt; overload; (*Rotate all Mtx matrix rows 90deg clockwise. Store the results in calling matrix. The , and properties of the calling matrix are adjusted automatically. *) function Rotate90(const Mtx: TMtxInt): TMtxInt; overload; (* Scatters Src elements defined with the Mask to the calling object. *) function ScatterByMask(const Src: TMtxVecInt; const Mask: TMtxVecInt; allow_resizing: boolean = False): TMtxVecInt; overload; override; (*Exchanges two matrix rows. Exchange the i-th and j-th rows of the calling matrix in-place. An exception is raised if matrix bounds are overrun. The indexes i and j are zero based. (the first row has index 0). var A,B: TMtxInt; begin CreateIt(A,B); try A.SetIt(2,2,[1,3, 2,4]); B.RowExchange(0,1); // B becomes: // [2,4, // 1,3]); finally FreeIt(A,B); end; end; *) function RowExchange(i, j: integer): TMtxInt; overload; (*Defines a sub vector/matrix. The method will define a subarray starting at Index and ending at Index + (aRows*aCols)-1. No copying will occur, only pointers will be shifted or indices adjusted. The subranged matrix will have the size aRows and aCols. Length will be equal to aRows*aCols. All values of the original will be preserved. An exception will be raised if an attempt is made to change the size of calling object. A sub-vector/matrix is vector/matrix, which does not have its own memory allocated. Instead it adopts the memory of the source object and all operations done on either of the objects affect the same elements. The use of subvectors/submatrices increases CPU cache reuse, lower's memory requirements, increases application performance and improves code readability. To again obtain a view of the full vector/matrix, see The routine only makes sense to be used where aCols matches Src.Cols. MtxVec has only limited support for matrices where the matrix rows are not stored strictly consecutively. This overload is to be used with great caution. The routine should not be mixed with other SetSubRange routines or subrange stack. *) procedure SetSubRange(const Src: TMtxVecInt; Index: integer; aRows, aCols: integer); overload; (*Copies values from vector to matrix column. Copy all Vec elements to the calling matrix Col column. An exception is raised, if array bounds are overrun. var A: TMtxInt; V: TVecInt; begin CreateIt(A); CreateIt(V); try A.Size(2,1); V.SetIt([1,2, 2,4]); A.SetCol(V,0); finally FreeIt(V); FreeIt(A); end; end; *) function SetCol(const Vec: TMtxVecInt; Col: integer): TMtxInt; overload; (*Copy vector Vec elements [VecIndex]..[VecIndex+Len-1] to the calling matrix elements [Row,Col]..[Row+Len-1,Col]. An exception is raised if condition checking is enabled and array bounds are overrun. *) function SetCol(const Vec: TMtxVecInt; VecIndex, Row, Col, Len: integer): TMtxInt; overload; (*Sets matrix values. Sets matrix values. This method gives you the possibility to pass large arrays of elements without having to declare constant arrays. Pass all elements in A array to the calling matrix. The and properties of the calling matrix are set to ARows and ACols and the property is set to aPrecision. An exception is raised if the matrix size (ARows*ACols) does not match the number of integer numbers in A. var A: TMtxInt; begin CreateIt(A); try A.SetIt(2,2,[1,2, 2,4]); finally FreeIt(A); end; end; *) function SetIt(ARows, ACols: integer; aPrecision: TIntPrecision; const A: array of Integer): TMtxInt; overload; function SetIt(ARows, ACols: integer; const A: array of integer): TMtxInt; overload; (*Copies values from vector to matrix row. Copy all Vec elements to the calling matrix Row row. The property of the calling matrix is adjusted automatically. An exception is raised, if array bounds are overrun. var A: TMtxInt; V: TVecInt; begin CreateIt(A); CreateIt(V); try A.Size(1,2); V.SetIt([1,2, 2,4]); A.SetCol(V,0); finally FreeIt(V); FreeIt(A); end; end; *) function SetRow(const Vec: TMtxVecInt; Row: integer): TMtxInt; overload; (*Copy vector Vec elements [VecIndex]..[VecIndex+Len-1] to the calling matrix elements [Row,Col]..[Row,Col+Len-1]. An exception is raised if condition checking is enabled and array bounds are overrun. *) function SetRow(const Vec: TMtxVecInt; VecIndex, Row, Col, Len: integer): TMtxInt; overload; (*Initializes matrix values to zero. Sets the calling matrix elements [Row,Col]..[ToRow,ToCol] to zero. An exception is raised if is true and array bounds are overrun. *) function SetZero(Row, Col, ToRow, ToCol: integer): TMtxInt; overload; (*Initializes matrix values to Value. Sets the calling matrix elements [Row,Col]..[ToRow,ToCol] to Value. An exception is raised if is true and array bounds are overrun. *) function SetVal(const Value: integer; Row, Col, ToRow, ToCol: integer): TMtxInt; overload; (*Sorts the elements in a matrix row(s) in ascending order. Sorts the elements in calling matrix row(s) in ascending order in-place. Note Each row is sorted independently from the other. var A: TMtxInt; begin CreateIt(A); try A.SetIt(2,2,[1,2, 4,2]); A.SortAscend; // A becomes: // [1,2] // [2,4] finally FreeIt(A); end; end; *) function SortAscend: TMtxInt; overload; (*Performs row based sort in ascending order. The Col parameter defines the column based on which the rows are compared with each other.*) function SortAscend(Col: integer): TMtxInt; overload; (*Sorts the elements in a matrix row(s) in descending order. Sorts the elements in calling matrix row(s) in descending order in-place. Note Each row is sorted independently from the other. var A: TMtxInt; begin CreateIt(A); try A.SetIt(2,2,[1,2, 4,2]); A.SortDescend; // A becomes: // [2,1] // [4,2] finally FreeIt(A); end; end; *) function SortDescend: TMtxInt; overload; (*Performs row based sort in descending order. The Col parameter defines the column based on which the rows are compared with each other.*) function SortDescend(Col: integer): TMtxInt; overload; (*Convert strings to integers and store them in the Values array. Convert strings in aList to integers and store them in to the IValues/SValues/BValues array of the calling matrix. property is set to aList.Count. and propertes are auto-detected. Columns must be separated with a Delimiter. By default the delimiter is the tab charachter. var a,b: TMtxInt; begin CreateIt(a,b); try a.SetIt(2,2,[1,2,3,4]); a.Cos; b.Size(a); b.SetVal(1); a.Add(b); Richedit1.Clear; Memo1.Clear; a.ValuesToStrings(Richedit1.Lines); b.ValuesToStrings(Richedit1.Lines); a.ValuesToStrings(Memo1.Lines); b.ValuesToStrings(Memo1.Lines); Memo1.Lines.SaveToFile('C:\Test.txt'); Memo1.Lines.LoadFromFile('C:\Test.txt'); a.StringsToValues(Memo1.Lines); finally FreeIt(a,b); end; end; *) function StringsToValues(const srcList: TStrings; const aDelimiter: string): TMtxInt; overload; (*Convert strings to integers and store them in the Values array. The assumed delimiter between columns will be a tab charachter. *) function StringsToValues(const srcList: TStrings): TMtxInt; overload; (*Convert strings from [ListIndex]..[ListIndex+ListLen-1] in srcList to integers. Store them in the Values array of the calling matrix, starting from element [Row,Cols]. The size of the calling matrix is not changed. If array bounds are overrun an exception is raised. *) function StringsToValues(const srcList: TStrings; ListIndex,ListLen, Row,Col: Integer; Delimiter: string = kTab): TMtxInt; overload; (*Saves matrix data to MatrixMarket ASCII file format. Saves matrix data to MatrixMarket ASCII file format. *) procedure SaveToMatrixMarketFile(FileName: string); (*Splits matrix in blocks. Splits he calling matrix in blocks. Example: [ A B ] [ C D ] where A,B,C,D are matrices of size 2x2 and the calling matrix is of size 4x4. ARows and ACols define the number of rows and columns of the block based matrix. The matrices passed in the dst array to be filled with values from the calling matrix, must already have matching size and IntPrecision properties to cover the calling matrix or an exception will be raised. var A,B,C,D,E: TMtxInt; begin CreateIt(A,B,C,D); CreateIt(E); try A.Size(2,2); B.Size(A); C.Size(A); D.Size(A); E.SetIt(4,4,[1,2,3,4 5,6,7,8 9,1,2,3 4,5,6,7]); E.Split(2,2,[A,B, C,D]); // A becomes: // [1,2, // 5,6] // B becomes: // [3,4, // 7,8] // C becomes: // [9,1, // 4,5] // D becomes: // [2,3, // 6,7] finally FreeIt(A,B,C,D); FreeIt(E); end; end; *) procedure Split(ARows, ACols: integer;const Dst: array of TMtxInt); (*Calculates the sum of each of the calling matrix columns. Calculates the sum of each of the calling matrix columns and stores the results in Dst vector. The and properties of the Dst vector are adjusted automatically. var A: TMtxInt; V: TVecInt; begin CreateIt(A); CreateIt(V); A.Size(2,2,[1,5, 2,3]); A.SumCols(V); // V = [3,8] FreeIt(V); FreeIt(A); end; *) procedure SumCols(const Dst: TVecInt); overload; (*Calculates the sum of each of the calling matrix rows. Calculates the sum of each of the calling matrix rows and stores the results in Dst vector. The and properties of the Dst vector are adjusted automatically. var A: TMtxInt; V: TVecInt; begin CreateIt(A); CreateIt(V); A.Size(2,2, [1,2, 2,4]); A.SumRows(V); // V = [3,6] FreeIt(V); FreeIt(A); end; *) procedure SumRows(const Dst: TVecInt); overload; (*Calculates the tensor product of two vectors. Calculates the tensor product of Vec1 and Vec2 vectors and stores the results in the calling matrix. The property is set to Vec1. and property is set to Vec2.. The property of the calling matrix is adjusted automatically. var Vec1,Vec2: TVecInt; V: TMtxInt; begin CreateIt(Vec1,Vec2); CreateIt(V); try Vec1.Size(3); Vec1.SetIt([0,2,3] Vec2.Copy(Vec1); V.TensorProd(Vec1,Vec2); // V becomes: // [0,0,0] // [0,4,6] // [0,6,9] finally FreeIt(Vec1,Vec2); FreeIt(V); end; end; *) function TensorProd(const Vec1, Vec2: TVecInt): TMtxInt; overload; (*Transposes matrix. Transposes calling matrix in-place. Instead of using transpose directly, try using the parameter of many TMtxInt methods. If this operation can not be avoided try using the not-in-place version (see bellow) or see the method. var A: TMtxInt; begin CreateIt(A); A.Size(2,1); // 2x1 integer matrix A.SetVal(3); A.Transp; FreeIt(A); end; *) function Transp: TMtxInt; overload; (*Transpose the Mtx matrix. Write the results to the calling matrix. The , and properties of the calling matrix are adjusted automatically. *) function Transp(const Mtx: TMtxInt): TMtxInt; overload; (*Constructs upper triangular matrix. The method uses Mtx matrix to construct an upper triangular matrix. The results are stored in the calling matrix. If the ZeroLower parameter is true then the calling matrix subdiagonal elements will be set to zero - otherwise the subdiagonal elements will not be initialized. If the Diagonal boolean parameter is true then the Mtx matrix main diagonal elements will be copied to the calling matrix main diagonal elements. If the Diagonal parameter is false, the calling matrix main diagonal elements will be set to zero. var A,B: TMtxInt; begin CreateIt(A,B); A.SetIt(2,1,[1,2, 2,4]); // 2x2, integer matrix B.UpperTriangle(A,True,True); // B becomes: // [1,2, // [0,4] FreeIt(A,B); end; *) function UpperTriangle(const Mtx: TMtxInt; ZeroLower, Diagonal: boolean): TMtxInt; overload; (*Converts the content of the matrix Values array to a list of strings. Convert all elements of the calling matrix to strings with text delimiter Delimiter and store them in dstList, by using the Add method of TStrings object. Set Align to have columns aligned left or right when using fixed width font (like Courier New). Specifiy Headers to be "true", if row and column labels are to be printed. Performance note: This routine will be exceedingly slow, if TRichEdit.Lines or TMemo.Lines are passed as a parameter. Use TStringList or StringList types and then call Memo.Lines.AddStrings(yourList) for best results. procedure TForm1.Button1Click(Sender: TObject); var a,b: TMtxInt; begin CreateIt(a,b); try a.SetIt(2,2,[1,2,3,4]); a.Cos; b.Size(a); b.SetVal(1); a.Add(b); Richedit1.Clear; Memo1.Clear; a.ValuesToStrings(Richedit1.Lines); b.ValuesToStrings(Richedit1.Lines); a.ValuesToStrings(Memo1.Lines); b.ValuesToStrings(Memo1.Lines); Memo1.Lines.SaveToFile('C:\Test.txt'); Memo1.Lines.LoadFromFile('C:\Test.txt'); a.StringsToValues(Memo1.Lines); finally FreeIt(a,b); end; end; *) function ValuesToStrings(const dstList: TStrings; const Delimiter: string; const Align: TFixedTextAlign; const Headers: boolean; const ColumnWidth: integer = -1): integer; overload; (*Converts the content of the matrix Values array to a list of strings. Performance note: This routine will be exceedingly slow, if TRichEdit.Lines or TMemo.Lines are passed as a parameter. Use TStringList or StringList types and then call Memo.Lines.AddStrings(yourList) for best results. *) function ValuesToStrings(const dstList: TStrings; const Delimiter: string = kTab; const Align: TFixedTextAlign = ftaNone): integer; overload; (*Convert calling matrix elements, starting with [Row,Col] and up to [Row+RowCount-1,Col+ColCount-1] elements to strings. Use text Delimiter for columns and store the resulting strings in dstList starting at ListIndex. If dstList is not large enough, the method will use the Add method of dstList object. Existing items will be overwritten. Set Align to have columns aligned left or right when using fixed width font (like Courier New). Specifiy Headers to be "true", if row and column labels are to be printed. Performance note: This routine will be exceedingly slow, if TRichEdit.Lines or TMemo.Lines are passed as a parameter. Use TStringList or StringList types and then call Memo.Lines.AddStrings(yourList) for best results. *) function ValuesToStrings(const dstList: TStrings; ListIndex,Row,Col,RowCount,ColCount: integer; const Delimiter: string = kTab; const Align: TFixedTextAlign = ftaNone; const Headers: boolean = false; const ColumnWidth: integer = -1): integer; overload; (*Converts all calling matrix elements to string.*) procedure ValuesToText(out Text: String; const Delimiter: string = kTab);overload; (*Converts Row..Col to Row+RowCount..Col+ColCount matrix elements to string.*) procedure ValuesToText(out Text: String; Row,Col,RowCount,ColCount: integer; const Delimiter: string = kTab); overload; function TextToValues(const Text: String; const Delimiter: String = kTab): TMtxInt; function ReadHeader(const SrcStream: TStream; Endian: TEndianness = MtxSystemEndianness): TPrecision; override; procedure WriteHeader(const DstStream: TStream; Precision: TPrecision = prInteger; Endian: TEndianness = MtxSystemEndianness); override; published (*Defines number of bits stored in one row.*) property ColsBitCount: integer read fColsBitCount write SetColsBitCount; (*Defines the number of leading columns. This value defines the spacing in number of samples between rows. It is fixed to be the same to the value of (for now). *) property LeadingCols: integer read GetLeadingCols write SetLeadingCols; (*Defines the number of matrix columns. Use this property to set or get the number of the calling matrix columns. Setting the Cols does not affect the actual amount of memory allocated unless Rows*Cols is bigger than . *) property Cols: integer read FCols write SetCols default 0; (*Defines the number of matrix rows. Use this property to set or get the number of the calling matrix rows. Setting the Rows does not affect the actual amount of memory allocated unless Rows*Cols is bigger than . *) property Rows: integer read FRows write SetRows default 0; end; (*Class for 16bit two dimensional integer arrays. Class for accessing and manipulating 16bit two dimensional arrays. It handles memory allocation and basic vector arithmetics. *) TMtxSmallInt = class(TMtxInt) strict protected procedure HookPointers; override; public (*Allows setting/getting the 16bit integer value at position row,col. Allows setting/getting the 16bit integer value at position row,col. *) Values: TSmallIntArray; function get_DefaultArray(const row,col: integer): SmallInt; procedure set_DefaultArray(const row,col: integer; const value: SmallInt); (*Allows setting/getting the integer value at position row,col. Allows setting/getting the 16bit integer value at position row,col. This property reads/writes to the same memory as property. *) property DefaultArray[const row,col: integer]: SmallInt read get_DefaultArray write set_DefaultArray; default; function PValues(const row, col: integer): PAPointer; overload; constructor Create; override; end; (*Class for 8bit two dimensional integer arrays. Class for accessing and manipulating 8bit two dimensional arrays. It handles memory allocation and basic vector arithmetics. *) TMtxByte = class(TMtxInt) strict protected procedure HookPointers; override; public (*Allows setting/getting the 8bit integer value at position row,col. Allows setting/getting the 8bit integer value at position row,col. *) Values: Math387.TByteArray; function get_DefaultArray(const row,col: integer): Byte; procedure set_DefaultArray(const row,col: integer; const value: Byte); (*Allows setting/getting the integer value at position row,col. Allows setting/getting the 8bit value at position row,col. This property reads/writes to the same memory as property. *) property DefaultArray[const row,col: integer]: Byte read get_DefaultArray write set_DefaultArray; default; (*Obtains a pointer to the integer value of the vector at Index. The function returns address of element at Values[i]. Under .NET, internal memory must be Pinned first. See and *) function PValues(const row, col: integer): PAPointer; overload; constructor Create; override; end; (* Implementation of object cache for TVecInt objects. *) TVecIntCache = class(TAbstractMtxVecCache) public Int32CacheOffset: TIntegerArray; Int32CachePointers: T2DIntegerArray; Int16CacheOffset: TIntegerArray; Int16CachePointers: T2DSmallIntArray; Int8CacheOffset: TIntegerArray; Int8CachePointers: Math387.T2DByteArray; strict protected Int16Cache: TSmallIntArray; Int8Cache: Math387.TByteArray; function NewItem: TMtxVecBase; override; procedure CacheMemFree; override; function GetCacheInBytes: Int64; override; procedure CacheMemAllocate(ItemCount, Elements: integer); override; public Int32Cache: TIntegerArray; constructor Create; override; end; (* Implementation of object cache for TVecInt objects. *) TMtxIntCache = class(TAbstractMtxVecCache) public Int32CacheOffset: TIntegerArray; Int32CachePointers: T2DIntegerArray; Int16CacheOffset: TIntegerArray; Int16CachePointers: T2DSmallIntArray; Int8CacheOffset: TIntegerArray; Int8CachePointers: Math387.T2DByteArray; strict protected Int8Cache: Math387.TByteArray; Int16Cache: TSmallIntArray; Int32Cache: TIntegerArray; function NewItem: TMtxVecBase; override; procedure CacheMemFree; override; function GetCacheInBytes: Int64; override; procedure CacheMemAllocate(ItemCount, Elements: integer); override; public constructor Create; override; end; procedure CreateIt(out a: TVecInt); overload; procedure CreateIt(out a, b: TVecInt); overload; procedure CreateIt(out a, b, c: TVecInt); overload; procedure CreateIt(out a, b, c, d: TVecInt); overload; procedure FreeIt(var a: TVecInt); overload; procedure FreeIt(var a, b: TVecInt); overload; procedure FreeIt(var a, b, c: TVecInt); overload; procedure FreeIt(var a, b, c, d: TVecInt); overload; procedure CreateIt(out a: TMtxInt); overload; procedure CreateIt(out a, b: TMtxInt); overload; procedure CreateIt(out a, b, c: TMtxInt); overload; procedure CreateIt(out a, b, c, d: TMtxInt); overload; procedure FreeIt(var a: TMtxInt); overload; procedure FreeIt(var a, b: TMtxInt); overload; procedure FreeIt(var a, b, c: TMtxInt); overload; procedure FreeIt(var a, b, c, d: TMtxInt); overload; (*Interfaces several MtxVec routines and intruduces new components.*) unit MtxVecTools; interface {$I BdsppDefs.inc} Uses MtxVec, Optimization, Math387, MtxBaseComp, MtxIntDiff, MtxVecInt ,Classes ; Type TMtxOptimization = class; (*Interfaces the optimization routines. The component can be used to find the minimum of function of several variables. How to use TMtxOptimization component? * Drop a TMtxOptimization component on the form. * Define the number of variables and their initial values by accessing the vector. * Define any additional constant parameters by accessing vector. * Define any additional constant pointer parameter by using the method. * Define real function (must be of type). * Define optimization method by accessing the property. * Depending on optimization method you'll have to (optionally) define the gradient calculation procedure ( method) or gradient/Hessian matrix calculation procedure ( method). If you don't specify the GradProcedure or GradHessProcedure then the numeric approximation will be used to calculate the gradient vector and Hessian matrix. In this case you must also specify which gradient aproximation method you will use - access the property. * Call the method to find the minimum of function of several variables. Results: * : RealFunction, evaluated at minimum. * : minimum position. * : Number of iterations needed to reach specified ( property) minimum precision. * : Inverse Hessian matrix (returned only by BFGS, ConjGrad and Marquardt methods) * : Why did the optimization algorithm stopped ? How to solve the optimization problem using TMtxOptimization component? using Dew.Math; using Dew.Math.Units; namespace Dew.Examples { // define the real function to be minimized private double Banana(TVec pars, TVec consts, params object[] objConsts) { return 100*Math.Pow(pars[1]-Math.Pow(pars[0],2),2)+Math.Pow(1-pars[0],2); } private void Example(TMtxOptimization MtxOptim); { if (MtxOptim != null) { // define two variables and their initial values MtxOptim.VariableParameters.SetIt(false, new double[] {2,-1}); // use BFGS optimization method MtxOptim.OptimizationMethod = TOptMethod.optBFGS; // tolerance for MinValue and gradient calculation // additional note : since we did not define the GradProc, // the internal numerical gradient approximation will be used MtxOptim.Tolerance = 2.0e-6; MtxOptim.GradTolerance = 2.0e-6; // function to be minimized MtxOptim.RealFunction = Banana; // finally, calculate minimum MtxOptim.Recalculate(); } } } *) TMtxOptimization = class(TMtxComponent) strict private FOptimizationMethod: TOptMethod; FDirty: boolean; FMaxIterations: Integer; FVerbose: TStrings; IObjArray: TObjectArray; FConstantParameters: TVec; FVariableParameters: TVec; FTolerance: double; FLambda0: double; FGradTolerance: double; FGradProcedure: TGrad; FGradHessProcedure: TGradHess; FRealFunction: TRealFunction; FSoftSearch: boolean; FStopReason: TOptStopReason; FNumericGradMethod: TNumericGradMethod; FAutoUpdate: boolean; procedure SetOptimizationMethod(const Value: TOptMethod); procedure SetDirty(const Value: boolean); procedure SetMaxIterations(const Value: Integer); procedure SetVerbose(const Value: TStrings); procedure SetConstantParameters(const Value: TVec); procedure SetVariableParameters(const Value: TVec); procedure SetTolerance(const Value: double); procedure SetLambda0(const Value: double); procedure SetGradTolerance(const Value: double); procedure SetGradHessProcedure(const Value: TGradHess); procedure SetGradProcedure(const Value: TGrad); procedure SetRealFunction(const Value: TRealFunction); procedure SetSoftSearch(const Value: boolean); procedure SetNumericGradMethod(const Value: TNumericGradMethod); procedure SetAutoUpdate(const Value: boolean); public (*Returns the inverse of Hessian matrix.*) InverseHess: TMtx; (*Returns number of optimization algorithm iterations.*) Iterations : Integer; (*Stores value of the objective function, evaluated at minimum.*) MinValue: double; (*Becomes true after any of the properties have changed. When any of the TMtxOptimization properties changes, this property is automatically set to true. If and Dirty are both true then the method will be called automatically. *) property Dirty: boolean read FDirty write SetDirty; (*Stop reason for optimization algorithm. Returns the stop reason for optimization algorithm. See type to learn more about different stop reasons. *) property StopReason: TOptStopReason read FStopReason; (*Define any additional Object constant parameters in the RealFunction. Use SetObjects method to define any additional Object constant parameters in the RealFunction. By default, the PConsts has 0 elements. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples { // define the real function to be minimized private double vecfun(TVec pars, TVec consts, params object[] objConsts) { TVec tmpVec = object0] as TVec; return pars[0]*tmpVec.Sum() -tmpVec.SumOfSquares()*pars[1]; } private void Example(TMtxOptimization opt1); { // ... opt1.RealFunction = VecFun; opt1.VariableParameters.SetIt(false,new double[] {-1,0)}); Vector xVec = new Vector(0); opt1.SetObjects(new object[] {xVec}); } } *) procedure SetObjects(Const ObjConst: Array of TObject); (*Triggers TMtxOptimization recalculation. Triggers TMtxOptimization recalculation. After the Recalculate call the property is set to false. The results are stored to: * : RealFunction, evaluated at minimum. * : minimum position. * : Number of iterations needed to reach specified ( property) minimum precision. * : Inverse Hessian matrix (returned only by BFGS, ConjGrad and Marquardt methods). * : Why did the optimization algorithm stop? *) procedure Recalculate; (*If not nil then the optimization method uses it for logging each optimization step. If not nil then the optimization method uses it for logging each optimization step. By default the Verbose property is nil meaning no logging is done. Log directly to TStringList: TStringList log = new TStringList(); MtxOptimizaton.Verbose = log; MtxOptimization.Recalculate(); *) property Verbose: TStrings read FVerbose write SetVerbose; (*Defines the gradient vector calculation routine. Defines the gradient vector calculation routine. Set to nil if you want to use internal numeric gradient vector calculation. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples { // Objective function double Banana(TVec pars, TVec consts, params object[] obj) { return 100.0*Math387.IntPower(pars[1]- Math387.IntPower(pars[0],2),2) + Math387.IntPower(1.0-pars[0],2); } // Analytical gradient of the objective function void GradBanana(TRealFunction Fun, TVec pars, TVec consts, object[] obj, TVec grad) { grad.Values[0] = -400*(pars[1]-Math387.IntPower(pars[0],2))*pars[0] - 2*(1-pars[0]); grad.Values[1] = 200*(pars[1]-Math387.IntPower(pars[0],2)); } private void Example(TMtxOptimization opt) { opt.VariableParameters.SetIt(new double[] {2,-1}); opt.RealFunction = Banana; opt.OptimizationMethod = TOptimizationMethod.optBFGS; // use exact gradient vector calculation // NOTE : set opt.GradProcedure to null if you // want to use internal numeric gradient calculation opt.GradProcedure = GradBanana; opt.Recalculate(); } } *) property GradProcedure: TGrad read FGradProcedure write SetGradProcedure; (*Defines the gradient vector and Hessian matrix calculation routine. Defines the gradient vector and Hessian matrix calculation routine. Set to nil if you want to use internal numeric gradient and Hessian matrix calculation. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples { // Objective function double Banana(TVec pars, TVec consts, params object[] obj) { return 100.0*Math387.IntPower(pars[1]- Math387.IntPower(pars[0],2),2) + Math387.IntPower(1.0-pars[0],2); } // Analytical gradient of the objective function void GradHessBanana(TRealFunction Fun, TVec pars, TVec consts, object[] obj, TVec grad, TMtx Hess) { grad.Values[0] = -400*(pars[1]-Math387.IntPower(pars[0],2))*pars[0] - 2*(1-pars[0]); grad.Values[1] = 200*(pars[1]-Math387.IntPower(pars[0],2)); Hess.Values1D[0] = -400*Pars[1]+1200*Math387.IntPower(Pars[0],2)+2; Hess.Values1D[1] = -400*Pars[0]; Hess.Values1D[2] = -400*Pars[0]; Hess.Values1D[3] = 200; } private void Example(TMtxOptimization opt) { opt.VariableParameters.SetIt(new double[] {2,-1}); opt.RealFunction = Banana; opt.OptimizationMethod = TOptimizationMethod.optBFGS; // use exact gradient and Hessian calculation // NOTE : set opt.GradHessProcedure to null if you // want to use internal numeric gradient calculation opt.GradHessProcedure = GradHessBanana; opt.Recalculate(); } } *) property GradHessProcedure: TGradHess read FGradHessProcedure write SetGradHessProcedure; (*Defines the function to be minimized. Defines the function to be minimized. The must be of the type. Before you write actual function, set the Parameters, Constants and PConstants array size by using the: vector Length, Size or SetIt method, vector Length, Size or SetIt method, method Define a function of two variables and one additional constant parameter. 1) Set the VariableParameters, ConstantParameters size and (optionally) initial value: MtxOptimization.VariableParameters.SetIt(false,[1,1]); MtxOptimization.ConstantParameters.SetIt(false,[2.5]); MtxOptimization->VariableParameters->SetIt(false,OPENARRAY(double,(1,1))); MtxOptimization->ConstantParameters->SetIt(false,OPENARRAY(double,(2.5))); Note that all values are real. 2) Define the actual function: function TestFunction(const Pars: TVec; const Consts: TVec;const ObjConsts: Array of TObject): double; begin TestFunction := 2*Pars[0]+Sqrt(Pars[1]-Consts[0]); end; double __fastcall BTestFunction(TVec* const Parameters, TVec* const Constants, System::TObject* const * ObjConst, const int ObjConst_Size) { double* Pars = Parameters->PValues1D(0); return 2*Pars[0] + Sqrt(Pars[1]-Consts[0]); } Here Pars = VariableParameters.Values and Consts = ConstantParameters.Values. 3) "Connect" the function with TMtxOptimization component: MtxOptimization.RealFunction := TestFunction; MtxOptimization->RealFunction = TestFunction; Please note that the internal algorithm does not check if Parameters, Constants, PConstants array size is the same as VariableParameters.Values, ConstantParameters.Values and SetPointers array size. *) property RealFunction: TRealFunction read FRealFunction write SetRealFunction; constructor Create(aOwner: TComponent); override; destructor Destroy; override; classfunction EditorClass: string; override; published (*Automatic recalculation. If true then changing any of the TMtxOptimization properties will trigger the method. *) property AutoUpdate: boolean read FAutoUpdate write SetAutoUpdate default false; (*Optimization algorithm used for minimum search. Defines which optimization method will be used to find the minimum of function of several variables. *) property OptimizationMethod: TOptMethod read FOptimizationMethod write SetOptimizationMethod default optSimplex; (*maximum number of iterations allowed for minimum search. Defines the maximum number of iterations allowed for minimum search. *) property MaxIterations: Integer read FMaxIterations write SetMaxIterations default 500; (*Precision. Defines VariableParameters precision. *) property Tolerance: double read FTolerance write SetTolerance; (*Set/read the variables in minimized function. Access the VariableParameters vector to set/read the variables in minimized function. To define number of variables and their initial values, set the VariableParameters vector Length and Values properties. Read the VariableParameters Values property to get the function minimum position. using Dew.Math; using Dew.Math.Units; using Dew.Math.Editors; double Banana(TVec Pars, TVec Consts, object[] objs) { return 100*Math387.IntPower(Pars[1]-Math387.IntPower(Pars[0],2),2) + Math387.IntPower(1-Pars[0],1); } void Example(TMtxOptim opt1) { // function with two variables // initial values for variables => Pars[0] := 2, Pars[1] := -1; opt1.VariableParameters.SetIt(false,new double[] {2,-1}); opt1.RealFunction = Banana; opt1.OptimizationMethod = optMarquardt; // numeric approximation opt1.GradProcedure = null; opt1.GradHessProcedure = null; opt1.Recalculate(); // now VariableParameters holds minimum position MtxVecEdit.ViewValues(opt1.VariableParameters,"Minimum position"); end; *) property VariableParameters: TVec read FVariableParameters write SetVariableParameters stored AllowStreaming; (*set/read the additional constants used in minimized function. Access the ConstantParameters vector to set/read the additional constants used in minimized function. By default the ConstantParameters vector has 0 elements. *) property ConstantParameters: TVec read FConstantParameters write SetConstantParameters stored AllowStreaming; (*Initial lambda step used in Marquardt optimization algorithm.*) property Lambda0: double read FLambda0 write SetLambda0; (*The precision for numeric gradient and/or Hessian matrix calculation. Sets the precision for numeric gradient and/or Hessian matrix calculation. This value is used only if or is nil (i.e. if numerical approximation is being used). *) property GradTolerance: double read FGradTolerance write SetGradTolerance; (*Internal line search algorithm. Defines the internal line search algorithm. If true then Quasi-Newton and Conjugate gradient method internal line search algoritm will use soft line search method. Set SoftSearch to true if you're using numerical approximation for gradient. If SoftSearch if false, then the internal line search algorithm will use exact line search method. Set SoftSearch to false if you're using *exact* gradient. *) property SoftSearch: boolean read FSoftSearch write SetSoftSearch default true; (*Defines which gradient numerical approximation method will be used to to evaluate gradient. Defines which gradient numerical approximation method will be used to evaluate gradient. The NumericGradMethod is used only if is nil. *) property NumericGradMethod: TNumericGradMethod read FNumericGradMethod write SetNumericGradMethod default numRichardson; end; TMtxLP = class; (*Interfaces Linear Programming algorithms. The component can be used to solve several linear programming problems. How to use TMtxLP component? * Drop a TMtxLP component on the form. * Set the property to minimize or maximize objective function f(x). * By setting select which algorithm will be used to solve LP problem. * Define , , and optionaly , keeping in mind correct size of matrix, vectors and string. * Call the method to solve LP problem. The results of solving LP are returned as: * Final tableaux , * Legitimate variables, stored in vector , * Indexes of legitimate variables, stored in vector IValues, * Solution type, stored in , * Objective function , evaluated at minimum or maximum. *) TMtxLP = class(TMtxComponent) strict private fDirty: boolean; fAutoUpdate : boolean; fA,fAFinal: TMtx; fc,fx,fb: TVec; fIndexes: TVecInt; FMinimize: boolean; fAlgorithm: TLPAlgorithm; FSolutionType: TLPSolution; fVerbose: TStrings; fRelations: String; fz: double; procedure Setfc(const Value: TVec); procedure SetfA(const Value: TMtx); procedure Setfb(const Value: TVec); procedure SetDirty(const Value: boolean); procedure SetAutoUpdate(const Value: boolean); procedure SetMinimize(const Value: boolean); procedure SetAlgorithm(const Value: TLPAlgorithm); procedure SetVerbose(const Value: TStrings); procedure SetRelations(const Value: String); public (*Checks A,b,c and relations dimensions. True, if system has correct dimensions. Checks if A.Cols equals to b.Length and A.Rows equals to c.Length. Additionally, if Two-Phase Simplex algorithm is used, checks if Relations string length is equal to b.Length. *) function CheckDimensions: Boolean; (*Triggers TMtxLP recalculation. Triggers TMtxLP recalculation. After the Recalculate call property is set to false. The results are stored to: * : Objective function, evaluated at minimum or maximum. * : Values of the legitimate variables at minimum or maximum. * : Indices of legitimate variables in final tableaux. * : Type of solution. * : Final tableaux. *) procedure Recalculate; (*Becomes true, after any property has changed. When any of the TMtxLP properties changes, this property is automatically set to true. If and Dirty are both true then the method will be called automatically. *) property Dirty: boolean read fDirty write SetDirty; (*LP solution type. Returns LP solution type. Check type to learn more about different solution types. *) property SolutionType: TLPSolution read fSolutionType; (*Values of the legitimate variables. Returns values of the legitimate variables (optimal solution). *) property x: TVec read fx; (*Final tableaux. Returns the final tableaux. *) property AFinal: TMtx read fAFinal; (*Returns indices (stored in IValues) of basic variables in final tableaux. *) property Indexes: TVecInt read fIndexes; (*Log optimization algorithm calculation. If not nil then the optimization method uses it for logging each optimization step. By default the Verbose property is nil meaning no logging is done. Log to TStringList log and copy contence to richTextBox. TStringList log = new TStringList(); MtxLP.Verbose = log; MtxLP.Recalculate(); richTextBox1.Text = log.Text; // copy text to RichTextBox *) property Verbose: TStrings read fVerbose write SetVerbose; (*Value of the objective function. Returns objective function, evaluated at minimum or maximum. *) property z: double read fz; constructor Create(aOwner: TComponent); override; destructor Destroy; override; classfunction EditorClass: string; override; published property AutoUpdate: boolean read fAutoUpdate write SetAutoUpdate default false; (*Defines c in f=c(T)*x equation. Defines c in the f=c(T)*x equation. *) property c: TVec read fc write Setfc; (*Defines A in A*x <= b equation. Defines A in the A*x <= b equation. *) property A: TMtx read fA write SetfA; (*Defines b in A*x <= b equation. Defines constraints b in the A*x <= b equation. *) property b: TVec read fb write Setfb; (*Defines relations for two phase algorithm. Defines relations for two-phase Simplex algorith. Length of relation string must be equal to length of vector b (number of constraints). *) property Relations: String read fRelations write SetRelations; (*Find minimum or maximum of objective function. Find minimum or maximum of objective function: min(max) f=c(T)*x *) property Minimize: boolean read FMinimize write SetMinimize default true; (*Defines LP solving algorithm. Defines which algorithm will be used to solve LP problem. *) property Algorithm: TLPAlgorithm read fAlgorithm write SetAlgorithm; end; (*Implements base methods for vector, matrix and sparse matrix. Implements base methods for vector, matrix and sparse matrix. *) unit MtxVecUtils; interface {$I BdsppDefs.inc} uses Math387, IppsplTypes ,Ippspl ,ippsplSingle ,Classes ,SysUtils ,Registry ; type TRegistryFile = TRegIniFile; (*Reads values from stream and converts to double type. Reads values from stream and converts to double type. The values will be read from Stream, intepreted as of Precision type, converted to double and stored in the Values array. The routine will read Length samples. The length of the Values array must be set to Length*(byte(Complex)+1). *) function ReadBinaryValues(Stream: TStream; Values: TDoubleArray; ValuesIndex: integer; Precision: TPrecision; Endian: TEndianness; Length: integer): Int64; overload; function ReadBinaryValuesc(Stream: TStream; Values: TCplxDoubleArray; ValuesIndex: integer; Precision: TPrecision; Endian: TEndianness; Length: integer): Int64; overload; (*The source is a pointer to memory, which holds Length elements stored with Precision.*) function ReadBinaryValues(Stream: Math387.TByteArray; StreamIndex: integer; Values: TDoubleArray; ValuesIndex: integer; Precision: TPrecision; Endian: TEndianness; Length: integer): Int64; overload; function ReadBinaryValuesc(Stream: Math387.TByteArray; StreamIndex: integer; Values: TCplxDoubleArray; ValuesIndex: integer; Precision: TPrecision; Endian: TEndianness; Length: integer): Int64; overload; function ReadBinaryValues(Stream: PAPointer; Values: TDoubleArray; ValuesIndex: integer; Precision: TPrecision; Endian: TEndianness; Length: integer): Int64; overload; function ReadBinaryValuesc(Stream: PAPointer; Values: TCplxDoubleArray; ValuesIndex: integer; Precision: TPrecision; Endian: TEndianness; Length: integer): Int64; overload; (*Writes double values to stream and converts to specified type. Writes TSample values to stream and converts to specified type. The values from Values array will be converted to Precision type, using the Rounding specified and written to the Stream. The length of the Values arrays is defined with the Length and Complex parameters. If Complex is True, the length of the Values array must be two times bigger then the Value of the Length parameter. *) procedure WriteBinaryValues(Stream: TStream; Values: TDoubleArray; ValuesIndex: integer; Precision: TPrecision; Rounding: TRounding; Endian: TEndianness; Length: integer); overload; procedure WriteBinaryValuesc(Stream: TStream; Values: TCplxDoubleArray; ValuesIndex: integer; Precision: TPrecision; Rounding: TRounding; Endian: TEndianness; Length: integer); overload; (*The destination is a pointer to memory, which will hold Length elements stored with Precision.*) procedure WriteBinaryValues(Stream: Math387.TByteArray; StreamIndex: integer; Values: TDoubleArray; ValuesIndex: integer; Precision: TPrecision; Rounding: TRounding; Endian: TEndianness; Length: integer); overload; procedure WriteBinaryValuesc(Stream: Math387.TByteArray; StreamIndex: integer; Values: TCplxDoubleArray; ValuesIndex: integer; Precision: TPrecision; Rounding: TRounding; Endian: TEndianness; Length: integer); overload; procedure WriteBinaryValues(Stream: PAPointer; Values: TDoubleArray; ValuesIndex: integer; Precision: TPrecision; Rounding: TRounding; Endian: TEndianness; Length: integer); overload; procedure WriteBinaryValuesc(Stream: PAPOinter; Values: TCplxDoubleArray; ValuesIndex: integer; Precision: TPrecision; Rounding: TRounding; Endian: TEndianness; Length: integer); overload; (*Reads values from stream and converts to single precision type. Reads values from stream and converts to single precision type. The values will be read from Stream, intepreted as of Precision type, converted to double precision and stored in the Values array. The routine will read Length samples. The length of the Values array must be set to Length*(byte(Complex)+1). *) function ReadBinaryValues(Stream: TStream; Values: TSingleArray; ValuesIndex: integer; Precision: TPrecision; Endian: TEndianness; Length: integer): Int64; overload; function ReadBinaryValuesc(Stream: TStream; Values: TCplxSingleArray; ValuesIndex: integer; Precision: TPrecision; Endian: TEndianness; Length: integer): Int64; overload; (*The source is a pointer to memory, which holds Length elements stored with Precision.*) function ReadBinaryValues(Stream: Math387.TByteArray; StreamIndex: integer; Values: TSingleArray; ValuesIndex: integer; Precision: TPrecision; Endian: TEndianness; Length: integer): Int64; overload; function ReadBinaryValuesc(Stream: Math387.TByteArray; StreamIndex: integer; Values: TCplxSingleArray; ValuesIndex: integer; Precision: TPrecision; Endian: TEndianness; Length: integer): Int64; overload; function ReadBinaryValues(Stream: PAPointer; Values: TSingleArray; ValuesIndex: integer; Precision: TPrecision; Endian: TEndianness; Length: integer): Int64; overload; function ReadBinaryValuesc(Stream: PAPointer; Values: TCplxSingleArray; ValuesIndex: integer; Precision: TPrecision; Endian: TEndianness; Length: integer): Int64; overload; (*Writes single precision values to stream and converts to specified type. Writes Tsingle precision values to stream and converts to specified type. The values from Values array will be converted to Precision type, using the Rounding specified and written to the Stream. The length of the Values arrays is defined with the Length and Complex parameters. If Complex is True, the length of the Values array must be two times bigger then the Value of the Length parameter. *) procedure WriteBinaryValues(Stream: TStream; Values: TSingleArray; ValuesIndex: integer; Precision: TPrecision; Rounding: TRounding; Endian: TEndianness; Length: integer); overload; procedure WriteBinaryValuesc(Stream: TStream; Values: TCplxSingleArray; ValuesIndex: integer; Precision: TPrecision; Rounding: TRounding; Endian: TEndianness; Length: integer); overload; (*The destination is a pointer to memory, which will hold Length elements stored with Precision.*) procedure WriteBinaryValues(Stream: Math387.TByteArray; StreamIndex: integer; Values: TSingleArray; ValuesIndex: integer; Precision: TPrecision; Rounding: TRounding; Endian: TEndianness; Length: integer); overload; procedure WriteBinaryValuesc(Stream: Math387.TByteArray; StreamIndex: integer; Values: TCplxSingleArray; ValuesIndex: integer; Precision: TPrecision; Rounding: TRounding; Endian: TEndianness; Length: integer); overload; procedure WriteBinaryValues(Stream: PAPointer; Values: TSingleArray; ValuesIndex: integer; Precision: TPrecision; Rounding: TRounding; Endian: TEndianness; Length: integer); overload; procedure WriteBinaryValuesc(Stream: PAPOinter; Values: TCplxSingleArray; ValuesIndex: integer; Precision: TPrecision; Rounding: TRounding; Endian: TEndianness; Length: integer); overload; (*Convert 24 bit signed integer to single precision value. Convert 24 bit signed integer to single precision value. The n parameter defines the number of elements to convert. Src points to a byte array and Dst is an array of single precision elements. DstIndex defines where in the Dst array will the elements be placed. *) procedure Bit24ToFloat(n: integer; Src: PPBArray; var Dst: array of single; DstIndex: integer = 0); overload; (*Convert 24 bit signed integer to double precision value. Convert 24 bit signed integer to double precision value. The n parameter defines the number of elements to convert. Src points to a byte array and Dst is an array of double precision elements. DstIndex defines where in the Dst array will the elements be placed. *) procedure Bit24ToFloat(n: integer; Src: PPBArray; var Dst: array of double; DstIndex: integer = 0); overload; (*Convert single precision to 24 bit signed integer. Convert single precision to 24 bit signed integer. The n parameter defines the number of elements to convert. Src is an array of single precision elements and Dst is a pointer to a byte array. Rounding parameter defines the rounding type used. *) procedure FloatTo24Bit(n: integer; var Src: array of single; Dst: PPBArray; Rounding: TRounding = rnRound); overload; (*Convert double precision to 24 bit signed integer. Convert double precision to 24 bit signed integer. The n parameter defines the number of elements to convert. Src is an array of double precision elements and Dst is a pointer to a byte array. Rounding parameter defines the rounding type used. *) procedure FloatTo24Bit(n: integer; var Src: array of double; Dst: PPBArray; Rounding: TRounding = rnRound); overload; function ReadBinaryFromStream(SrcStream: TStream; Count: integer; out Dst: TSingleArray; Endian: TEndianness): boolean; overload; function ReadBinaryFromStream(SrcStream: TStream; Count: integer; out Dst: TIntegerArray; Endian: TEndianness): boolean; overload; function WriteBinaryToStream(DstStream: TStream; Count: integer; const Src: TSingleArray; Endian: TEndianness): boolean; overload; function WriteBinaryToStream(DstStream: TStream; Count: integer; const Src: TIntegerArray; Endian: TEndianness): boolean; overload; procedure WriteToStream(const Stream: TStream; var Values: TDoubleArray; ValuesIndex: integer; NumBytes: Int64; Endian: TEndianness); overload; procedure WriteToStreamc(const Stream: TStream; var Values: TCplxSingleArray; ValuesIndex: integer; NumBytes: Int64; Endian: TEndianness); overload; procedure WriteToStreamc(const Stream: TStream; var Values: TCplxDoubleArray; ValuesIndex: integer; NumBytes: Int64; Endian: TEndianness); overload; procedure WriteToStream(const Stream: TStream; const Values: Math387.TByteArray; ValuesIndex: integer; NumBytes: Int64); overload; procedure WriteToStream(const Stream: TStream; const Values: Math387.TShortIntArray; ValuesIndex: integer; NumBytes: Int64); overload; procedure WriteToStream(const Stream: TStream; var Values: Math387.TWordArray; ValuesIndex: integer; NumBytes: Int64; Endian: TEndianness); overload; procedure WriteToStream(const Stream: TStream; var Values: TCardinalArray; ValuesIndex: integer; NumBytes: Int64; Endian: TEndianness); overload; procedure WriteToStream(const Stream: TStream; var Values: TSingleArray; ValuesIndex: integer; NumBytes: Int64; Endian: TEndianness); overload; procedure WriteToStream(const Stream: TStream; var Values: TIntegerArray; ValuesIndex: integer; NumBytes: Int64; Endian: TEndianness); overload; procedure WriteToStream(const Stream: TStream; var Values: TSmallIntArray; ValuesIndex: integer; NumBytes: Int64; Endian: TEndianness); overload; procedure WriteToStream(Stream: Math387.TByteArray; StreamIndex: integer; Values: Math387.TSingleArray; ValuesIndex: integer; NumBytes: Int64; Endian: TEndianness); overload; procedure WriteToStream(Stream: Math387.TByteArray; StreamIndex: integer; Values: Math387.TSmallIntArray; ValuesIndex: integer; NumBytes: Int64; Endian: TEndianness); overload; procedure WriteToStream(Stream: Math387.TByteArray; StreamIndex: integer; Values: Math387.TIntegerArray; ValuesIndex: integer; NumBytes: Int64; Endian: TEndianness); overload; procedure WriteToStream(Stream: Math387.TByteArray; StreamIndex: integer; Values: Math387.TCardinalArray; ValuesIndex: integer; NumBytes: Int64; Endian: TEndianness); overload; procedure WriteToStream(Stream: Math387.TByteArray; StreamIndex: integer; Values: Math387.TShortIntArray; ValuesIndex: integer; NumBytes: Int64); overload; procedure WriteToStream(Stream: Math387.TByteArray; StreamIndex: integer; Values: Math387.TByteArray; ValuesIndex: integer; NumBytes: Int64); overload; procedure WriteToStream(Stream: Math387.TByteArray; StreamIndex: integer; Values: Math387.TDoubleArray; ValuesIndex: integer; NumBytes: Int64; Endian: TEndianness); overload; procedure WriteToStreamc(Stream: Math387.TByteArray; StreamIndex: integer; Values: Math387.TCplxSingleArray; ValuesIndex: integer; NumBytes: Int64; Endian: TEndianness); overload; procedure WriteToStreamc(Stream: Math387.TByteArray; StreamIndex: integer; Values: Math387.TCplxDoubleArray; ValuesIndex: integer; NumBytes: Int64; Endian: TEndianness); overload; procedure WriteToStream(Stream: Math387.TByteArray; StreamIndex: integer; Values: Math387.TWordArray; ValuesIndex: integer; NumBytes: Int64; Endian: TEndianness); overload; procedure WriteToStream(Stream: PAPointer; Values: Math387.TSingleArray; ValuesIndex: integer; NumBytes: Int64; Endian: TEndianness); overload; procedure WriteToStream(Stream: PAPointer; Values: Math387.TByteArray; ValuesIndex: integer; NumBytes: Int64); overload; procedure WriteToStream(Stream: PAPointer; Values: Math387.TSmallIntArray; ValuesIndex: integer; NumBytes: Int64; Endian: TEndianness); overload; procedure WriteToStream(Stream: PAPointer; Values: Math387.TIntegerArray; ValuesIndex: integer; NumBytes: Int64; Endian: TEndianness); overload; procedure WriteToStream(Stream: PAPointer; Values: Math387.TCardinalArray; ValuesIndex: integer; NumBytes: Int64; Endian: TEndianness); overload; procedure WriteToStream(Stream: PAPointer; Values: Math387.TShortIntArray; ValuesIndex: integer; NumBytes: Int64); overload; procedure WriteToStream(Stream: PAPointer; Values: Math387.TDoubleArray; ValuesIndex: integer; NumBytes: Int64; Endian: TEndianness); overload; procedure WriteToStreamc(Stream: PAPointer; Values: Math387.TCplxSingleArray; ValuesIndex: integer; NumBytes: Int64; Endian: TEndianness); overload; procedure WriteToStreamc(Stream: PAPointer; Values: Math387.TCplxDoubleArray; ValuesIndex: integer; NumBytes: Int64; Endian: TEndianness); overload; procedure WriteToStream(Stream: PAPointer; Values: Math387.TWordArray; ValuesIndex: integer; NumBytes: Int64; Endian: TEndianness); overload; function ReadFromStream(const Stream: TStream; const Values: Math387.TByteArray; ValuesIndex: integer; NumBytes: Int64): integer; overload; function ReadFromStream(const Stream: TStream; const Values: Math387.TShortIntArray; ValuesIndex: integer; NumBytes: Int64): integer; overload; function ReadFromStream(const Stream: TStream; var Values: Math387.TWordArray; ValuesIndex: integer; NumBytes: Int64; Endian: TEndianness): integer; overload; function ReadFromStream(const Stream: TStream; var Values: TCardinalArray; ValuesIndex: integer; NumBytes: Int64; Endian: TEndianness): integer; overload; function ReadFromStream(const Stream: TStream; var Values: TDoubleArray; ValuesIndex: integer; NumBytes: Int64; Endian: TEndianness): integer; overload; function ReadFromStreamc(const Stream: TStream; var Values: TCplxSingleArray; ValuesIndex: integer; NumBytes: Int64; Endian: TEndianness): integer; overload; function ReadFromStreamc(const Stream: TStream; var Values: TCplxDoubleArray; ValuesIndex: integer; NumBytes: Int64; Endian: TEndianness): integer; overload; function ReadFromStream(const Stream: TStream; var Values: TSingleArray; ValuesIndex: integer; NumBytes: Int64; Endian: TEndianness): integer; overload; function ReadFromStream(const Stream: TStream; var Values: TIntegerArray; ValuesIndex: integer; NumBytes: Int64; Endian: TEndianness): integer; overload; function ReadFromStream(const Stream: TStream; var Values: TSmallIntArray; ValuesIndex: integer; NumBytes: Int64; Endian: TEndianness): integer; overload; procedure ReadFromStream(Stream: Math387.TByteArray; StreamIndex: Integer; Values: Math387.TSingleArray; ValuesIndex: integer; NumBytes: Int64; Endian: TEndianness); overload; procedure ReadFromStream(Stream: Math387.TByteArray; StreamIndex: Integer; Values: Math387.TSmallIntArray; ValuesIndex: integer; NumBytes: Int64; Endian: TEndianness); overload; procedure ReadFromStream(Stream: Math387.TByteArray; StreamIndex: Integer; Values: Math387.TIntegerArray; ValuesIndex: integer; NumBytes: Int64; Endian: TEndianness); overload; procedure ReadFromStream(Stream: Math387.TByteArray; StreamIndex: Integer; Values: Math387.TCardinalArray; ValuesIndex: integer; NumBytes: Int64; Endian: TEndianness); overload; procedure ReadFromStream(Stream: Math387.TByteArray; StreamIndex: Integer; Values: Math387.TShortIntArray; ValuesIndex: integer; NumBytes: Int64); overload; procedure ReadFromStream(Stream: Math387.TByteArray; StreamIndex: Integer; Values: Math387.TByteArray; ValuesIndex: integer; NumBytes: Int64); overload; procedure ReadFromStream(Stream: Math387.TByteArray; StreamIndex: Integer; Values: Math387.TDoubleArray; ValuesIndex: integer; NumBytes: Int64; Endian: TEndianness); overload; procedure ReadFromStreamc(Stream: Math387.TByteArray; StreamIndex: Integer; Values: Math387.TCplxSingleArray; ValuesIndex: integer; NumBytes: Int64; Endian: TEndianness); overload; procedure ReadFromStreamc(Stream: Math387.TByteArray; StreamIndex: Integer; Values: Math387.TCplxDoubleArray; ValuesIndex: integer; NumBytes: Int64; Endian: TEndianness); overload; procedure ReadFromStream(Stream: Math387.TByteArray; StreamIndex: Integer; Values: Math387.TWordArray; ValuesIndex: integer; NumBytes: Int64; Endian: TEndianness); overload; procedure ReadFromStream(Stream: PAPointer; Values: Math387.TSmallIntArray; ValuesIndex: integer; NumBytes: Int64; Endian: TEndianness); overload; procedure ReadFromStream(Stream: PAPointer; Values: Math387.TIntegerArray; ValuesIndex: integer; NumBytes: Int64; Endian: TEndianness); overload; procedure ReadFromStream(Stream: PAPointer; Values: Math387.TCardinalArray; ValuesIndex: integer; NumBytes: Int64; Endian: TEndianness); overload; procedure ReadFromStream(Stream: PAPointer; Values: Math387.TShortIntArray; ValuesIndex: integer; NumBytes: Int64); overload; procedure ReadFromStreamp(Stream: PAPointer; Values: PAPointer; ValuesIndex: integer; NumBytes: Int64); overload; procedure ReadFromStream(Stream: PAPointer; Values: Math387.TDoubleArray; ValuesIndex: integer; NumBytes: Int64; Endian: TEndianness); overload; procedure ReadFromStream(Stream: PAPointer; Values: Math387.TSingleArray; ValuesIndex: integer; NumBytes: Int64; Endian: TEndianness); overload; procedure ReadFromStreamc(Stream: PAPointer; Values: Math387.TCplxSingleArray; ValuesIndex: integer; NumBytes: Int64; Endian: TEndianness); overload; procedure ReadFromStreamc(Stream: PAPointer; Values: Math387.TCplxDoubleArray; ValuesIndex: integer; NumBytes: Int64; Endian: TEndianness); overload; procedure ReadFromStream(Stream: PAPointer; Values: Math387.TWordArray; ValuesIndex: integer; NumBytes: Int64; Endian: TEndianness); overload; procedure ReadFromStream(Stream: PAPointer; Values: Math387.TByteArray; ValuesIndex: integer; NumBytes: Int64); overload; procedure QuickSortDescMtx(const A: TDoubleArray;const B: TIntegerArray; iLo, iHi: Integer; Index: integer); overload; procedure CQuickSortDescMtx(const A: TCplxArray; const B: TIntegerArray; const C: TDoubleArray; iLo, iHi: Integer; Index: integer); overload; procedure CQuickSortDescMtx(const A: TDoubleArray; const B: TIntegerArray; const C: TDoubleArray; iLo, iHi: Integer; Index: integer); overload; procedure QuickSortDescMtx(const A: TDoubleArray; AIndex: integer; const B: TIntegerArray; BIndex, iLo, iHi: Integer; Index: integer); overload; procedure CQuickSortDescMtx(const A: TCplxArray; AIndex: integer; const B: TIntegerArray; BIndex: integer; const C: TDoubleArray; CIndex, iLo, iHi: Integer; Index: integer); overload; procedure CQuickSortDescMtx(const A: TDoubleArray; AIndex: integer; const B: TIntegerArray; BIndex: integer; const C: TDoubleArray; CIndex, iLo, iHi: Integer; Index: integer); overload; procedure QuickSortAscMtx(const A: TDoubleArray; const B: TIntegerArray; iLo, iHi: Integer; Index: integer); overload; procedure CQuickSortAscMtx(const A: TCplxArray; const B: TIntegerArray; const C: TDoubleArray; iLo, iHi: Integer; Index: integer); overload; procedure CQuickSortAscMtx(const A: TDoubleArray; const B: TIntegerArray; const C: TDoubleArray; iLo, iHi: Integer; Index: integer); overload; procedure QuickSortAscMtx(const A: TDoubleArray; AIndex: integer; const B: TIntegerArray; BIndex, iLo, iHi: Integer; Index: integer); overload; procedure CQuickSortAscMtx(const A: TCplxArray; AIndex: integer; const B: TIntegerArray; BIndex: integer; const C: TDoubleArray; CIndex: integer; iLo, iHi: Integer; Index: integer); overload; procedure CQuickSortAscMtx(const A: TDoubleArray; AIndex: integer; const B: TIntegerArray; BIndex: integer; const C: TDoubleArray; CIndex: integer; iLo, iHi: Integer; Index: integer); overload; procedure QuickSortDescMtx(const A: TSingleArray;const B: TIntegerArray; iLo, iHi: Integer; Index: integer); overload; procedure CQuickSortDescMtx(const A: TSCplxArray; const B: TIntegerArray;const C: TSingleArray; iLo, iHi: Integer; Index: integer); overload; procedure CQuickSortDescMtx(const A: TSingleArray; const B: TIntegerArray;const C: TSingleArray; iLo, iHi: Integer; Index: integer); overload; procedure QuickSortDescMtx(const A: TSingleArray; AIndex: integer; const B: TIntegerArray; BIndex, iLo, iHi: Integer; Index: integer); overload; procedure CQuickSortDescMtx(const A: TSCplxArray; AIndex: integer; const B: TIntegerArray; BIndex: integer; const C: TSingleArray; CIndex, iLo, iHi: Integer; Index: integer); overload; procedure CQuickSortDescMtx(const A: TSingleArray; AIndex: integer; const B: TIntegerArray; BIndex: integer; const C: TSingleArray; CIndex, iLo, iHi: Integer; Index: integer); overload; procedure CQuickSortAscMtx(const A: TSCplxArray; const B: TIntegerArray; const C: TSingleArray; iLo, iHi: Integer; Index: integer); overload; procedure CQuickSortAscMtx(const A: TSingleArray; const B: TIntegerArray; const C: TSingleArray; iLo, iHi: Integer; Index: integer); overload; procedure QuickSortAscMtx(const A: TSingleArray; const B: TIntegerArray; iLo, iHi: Integer; Index: integer); overload; procedure QuickSortAscMtx(const A: TSingleArray; AIndex: integer; const B: TIntegerArray; BIndex, iLo, iHi: Integer; Index: integer); overload; procedure CQuickSortAscMtx(const A: TSCplxArray; AIndex: integer; const B: TIntegerArray; BIndex: integer; const C: TSingleArray; CIndex: integer; iLo, iHi: Integer; Index: integer); overload; procedure CQuickSortAscMtx(const A: TSingleArray; AIndex: integer; const B: TIntegerArray; BIndex: integer; const C: TSingleArray; CIndex: integer; iLo, iHi: Integer; Index: integer); overload; procedure CQuickSortAsc(const A: TCplxArray; AIndex: integer; const C: TDoubleArray; CIndex, iLo, iHi: Integer); overload; procedure CQuickSortAsc(const A: TSCplxArray; AIndex: integer; const C: TSingleArray; CIndex, iLo, iHi: Integer); overload; procedure QuickSortAsc(const A: TDoubleArray; iLo, iHi: Integer); overload; procedure CQuickSortAsc(const A: TCplxArray; const C: TDoubleArray; iLo, iHi: Integer); overload; procedure QuickSortAsc(const A: TSingleArray; iLo, iHi: Integer); overload; procedure CQuickSortAsc(const A: TSCplxArray; const C: TSingleArray; iLo, iHi: Integer); overload; procedure CQuickSortDesc(const A: TCplxArray; const C: TDoubleArray; iLo, iHi: Integer); overload; procedure CQuickSortDesc(const A: TDoubleArray; const C: TDoubleArray; iLo, iHi: Integer); overload; procedure CQuickSortDesc(const A: TCplxArray; AIndex: integer; const C: TDoubleArray; CIndex, iLo, iHi: Integer); overload; procedure CQuickSortDesc(const A: TDoubleArray; AIndex: integer; const C: TDoubleArray; CIndex, iLo, iHi: Integer); overload; procedure QuickSortDesc(const A: TDoubleArray; iLo, iHi: Integer); overload; procedure CQuickSortDesc(const A: TSCplxArray; const C: TSingleArray; iLo, iHi: Integer); overload; procedure CQuickSortDesc(const A: TSingleArray; const C: TSingleArray; iLo, iHi: Integer); overload; procedure CQuickSortDesc(const A: TSCplxArray; AIndex: integer; const C: TSingleArray; CIndex, iLo, iHi: Integer); overload; procedure CQuickSortDesc(const A: TSingleArray; AIndex: integer; const C: TSingleArray; CIndex, iLo, iHi: Integer); overload; procedure QuickSortDesc(const A: TSingleArray; iLo, iHi: Integer); overload; procedure WriteShortString(const Stream: TStream;const Str: string); overload; function ReadShortString(const Stream: TStream): string; overload; function ReadString(const Stream: TStream): string; overload; function aRound(const X: double): integer; overload; function aTrunc(const X: double): integer; overload; (*Function minimization routines. Introduces the following algorithms for finding the minimum of scalar function of several variables: Nelder-Mead (); unconstrained and bounded minimization. Quasi-Newton ( or DFP update scheme); unconstrained minimization. Levenberg-Marquardt (); unconstrained minimization. Conjugate Gradient (Fletcher - Reeves or Polak - Ribiere uate scheme); unconstrained minimization. Introduces the following algorithms for finding the minimum of vector function of several variables: Trust Region (TR); unconstrained and bounded minimization. Introduces the following algorithms for finding the minimum of function of single variable: Brent method; unconstrained minimization. In addition, several routines for linear programming (LP) are also provided. The following algorithms are supported: Two phase Simplex method. Dual Simplex method. Simplex method. Gomory's cutting plane algorithm for solving integral problems. *) unit Optimization; interface {$I BdsppDefs.inc} uses Math387, MtxVec, MtxVecInt, MtxIntDiff, AbstractMtxVec, MtxVecBase, AbstractMtxVecInt ,Nmkl ,NmklSingle ,SysUtils, Classes ,Types ; type (*Optimization methods.*) TOptMethod = ( (*Nelder-Mead optimization method.*)optSimplex, (*Marquardt optimization method.*)optMarquardt, (*Quasi-Newton optimization method (Broyden-Fletcher-Goldfarb-Shanno Hessian update).*) optBFGS, (*Quasi-Newton optimization method (Davidson-Fletcher-Power Hessian update).*) optDFP, (*Conjugate Gradient optimization method (Fletcher-Reeves).*)optConjGradFR, (*Conjugate Gradient optimization method (Polak-Ribiere).*)optConjGradPR, (*Trust Region (TR) optimization method.*)optTR ); (*Stop reason for the main loop in optimization.*) TOptStopReason = ( (*The algorithm did not find minimum (within given tolerance).*)OptResNotFound, (*The gradient C-Norm is bellow given gradient tolerance.*)OptResSmallGrad, (*The inverse Hessian matrix is near singular.*)OptResSingular, (*Iteration x step is less than EPS.*)OptResSmallStep, (*Iteration x step is zero.*)OptResZeroStep, (*(Marquardt) Lambda is more than 1000.*)OptResBigLambda, (*(Marquardt) Lambda is less than 1E-300 (singularity).*) OptResSmallLambda, (*Number of iterations has reached the MaxIter.*) OptResMaxIter, (*Number of iterations is less than MaxIter and parameters are within given tolerance.*)OptResConverged, (*Jacobian matrix elements are bekiw given tolerance.*) optResSmallJacobian, (*Target function returned NAN value.*) optNANValue, (*Stop signal detected.*) optStopped ); (*LP system solution.*) TLPSolution = ( (*System has empty feasable region.*)LPEmptyFeasableRegion, (*System has a finite (bounded) solution.*)LPFiniteSolution, (*System has unbounded (plus or minus infinity) objective function f(x). Otherwise function objectiva value is bounded. In this case there are three possibilities for a linear programming problem. It may be bounded feasible, it may be unbounded feasible, and it may be infeasible.*) LPUnboundedObjectiveFunction ); (*Linear programming algorithm.*) TLPAlgorithm = ( (*Dual Simplex algorithm.*)LPAlgoDualSimplex, (*Two Phase Simplex algorithm.*)LPAlgoTwoPhaseSimplex, (*Simplex algorithm.*)LPAlgoSimplex, (*Gomory's cutting plane algorithm.*)LPAlgoCPA ); (*Defines vector function of several variables. Defines vector function of several variables. Function variables. Function results. Array of additional constants which can be used in math formula. Array of additional constants (pointers) which can be used in math formula. Define the vector function f(x,y) with three components: private void VecFun(TVec x, TVec f, double[] c, object[] o) { f[0] = x[0]*Math.Sqrt(x[0]*x[0]+x[1]*x[1]); f[1] = x[1]*Math.Sqrt(x[0]*x[0]+x[1]*x[1]); f[2] = x[0]*(x[1]-x[0])*(x[1]-x[0]); } *) TVectorFunction = procedure(const X,Y: TVec; const Consts: array of double; const PConsts: array of TObject); (*Optional object class type to be passed to optimization routines. Create and pass this object as the "Verbose" parameter to the optimization routines. This object allows different type of optimization control, if the optimization is executed inside of a thread. *) TOptControl = class(TStringList) public (* Returns True, if functiona evaluation is in progress (not for the purpose of gradient or jacoby, used only by TR for now) *) FunEval: boolean; (* If True, log messages will be appended to the inherited TStringList. *) Verbose: Boolean; (* Initialized to false by the algorithm. The user can set this property to True (from another thread), to stop the optimization process. *) Stop: Boolean; (* Set to True by the optimization algorithm just before the function will exit. *) Stopped: Boolean; (* Contains the current iteration count, which can be read from another thread, while the optimization algorithm is running. *) Iter: integer; (* Returns True, if before ms amount of miliseconds has elapsed, the Stopped field was set to True *) function WaitFor(ms: integer): boolean; virtual; constructor Create; end; (*Defines procedure for calculating the Jacobian matrix. Jacobian matrix element (i,j) is defined as partial(Y(j))/partial(C(i)). Define the Jacobian for the banana function. // Split banana function in two parts private void BananaFun(TVec x, TVec f, double[] c, object[] o); { f[0] = 100*Math387.IntPower(x[1]-Math387.IntPower(x[0],2),2); f[1] = Math387.IntPower(1-x[0],2); } // Jacobian is 2x2 matrix private void BananaJac(TVec x, TVec f, TMtx Jac); { Jac[0,0] = -400*(x[1]-Math387.IntPower(x[0],2))*x[0]; // partial(f0)/ partial(x0) Jac[0,1] = -2*(1-x[0]); // partial(f1)/ partial(x0) Jac[1,0] = 200*(x[1]-Math387.IntPower(x[0],2)); // partial(f0)/ partial(x1) Jac[1,1] = 0.0; // partial(f1)/ partial(x1) } *) TJacobianFunction = procedure(const X,Y: TVec; const Jac: TMtx); (*Defines the procedure for calculating the gradient of a real function. Real function of several variables. Function variables. Array of additional constants which can be used in math formula. Array of additional constants (objects) which can be used in math formula. Returns calculated gradient. Defines the procedure for calculating the gradient of a real function. *) TGrad = procedure (Fun : TRealFunction; const Pars: TVec; Const Consts: TVec; Const PConsts: Array of TObject; const Grad: TVec); (*Defines the procedure for calculating the gradient and Hessian matrix of a real function. Real function of several variables. variables. Array of additional constants which can be used in math formula. Array of additional constants (objects) which can be used in math formula. Returns calculated gradient. Returns calculated Hessian matrix. Defines the procedure for calculating the gradient and Hessian matrix of a real function. *) TGradHess = procedure (Fun: TRealFunction; const Pars: TVec; Const Consts: TVec; Const ObjConst: Array of TObject; const Grad: TVec; const Hess: TMtx); (*Stores the stopping tests for TR optimization. The eps array contains the stopping tests: eps[0]: Grad < eps[0] eps[1]: ||F(x)|| < eps[1] eps[2]: ||A(x)ij|| < eps[2] eps[3]: ||s|| < eps[3] eps[4]: ||F(x)||- ||F(x) - A(x)s|| < eps[4] eps[5]: trial step precision. If eps[5] = 0, then eps[5] = 1E-10, where A(x) = the jacobi matrix F(x) = ||y - f(x)|| *) TEPSArray = array[0..5] of double; TRCustomData = class Consts: TDoubleArray; OConsts: TObjectArray; Fun: TVectorFunction; Fun1: TMKLTRFunction; FloatPrecision: TMtxFloatPrecision; constructor Create; destructor Destroy; override; end; (*Minimizes single variable function. Defines initial lower limit for minimum search. Defines initial upper limit for minimum search. Real function of single variable (must be of type) to be minimized. Additional Fun constant parameters (can be/is usually nil). Additional Fun constant parameters (can be/is usually nil). Returns the position of function minimum. Maximum allowed numer of minimum search iterations. Desired minimum position tolerance. If assigned, stores Func, evaluated at each iteration step. Optionally, you can also pass object to the Verbose parameter. This allows the optimization procedure to be interrupted from another thread and optionally also allows logging and iteration count monitoring. Specifies the floating point precision to be used by the routine. the number of iterations required to reach the solution(minimum) within given tolerance. Minimizes the function of one variable. This routine uses slightly modified version of the algol 60 procedure localmin, introduced by Richard Brent. Problem: Find the minimum of the function of single variable by using the Brent method. Solution:The function is defined by the following equation: private double Fun(TVec pars, TVec c, params object[] o) { return Math.Sin(Pars[0])+Math387.IntPower(Pars[0]+2,2); // note that Pars holds only one variable ! } private void Example() { // initial estimates for x1 and x2 double x; double res = Optimization.MinBrent(-10,10,Fun,TMtxFloatPrecsion.mvDouble,null,null,out x, 500,1e-8,null); // stop if Iters >500 or Tolerance < 1e-8 // Returns res = -1.8582461797 } *) function MinBrent(ax,bx: double; Func: TRealFunction; const FloatPrecision: TMtxFloatPrecision; Const Consts: array of double; Const ObjConst: Array of TObject; out MinX: double; MaxIter: integer; Accuracy: double = 1.0E-8; const Verbose: TStrings = nil): Integer; overload; (*Minimizes single variable function by using default settings and no log. Use this version if algorithm step logs are not needed. *) function MinBrent(ax,bx: double; Func: TRealFunction; const FloatPrecision: TMtxFloatPrecision; Const Consts: array of double; Const ObjConst: Array of TObject; out MinX: double): Integer; overload; (*Minimizes the function of several variables by using the Nelder-Mead (Simplex) optimization method. Real function (must be of type) to be minimized. Stores the initial estimates for parameters (minimum estimate). After the call to routine returns adjusted calculated values (minimum position). Additional Fun constant parameteres (can be/is usually nil). Additional Fun constant parameteres (can be/is usually nil). Returns function value at minimum. Returns reason why minimum search stopped (see ). Maximum allowed numer of minimum search iterations. Desired Pars - minimum position tolerance. Specifies the floating point precision to be used by the routine. If assigned, stores Fun, evaluated at each iteration step. Optionally, you can also pass object to the Verbose parameter. This allows the optimization procedure to be interrupted from another thread and optionally also allows logging and iteration count monitoring. the number of iterations required to reach the solution(minimum) within given tolerance. Minimizes the function of several variables by using the Nelder-Mead (Simplex) optimization method. The advantage of Simplex method is it does not require gradient or Hessian. Problem: Find the minimum of the "Banana" function by using the Nelder-Mead (Simplex) method. Solution:The Banana function is defined by the following equation: private double Banana(TVec x, TVec c, params object[] o) { return 100*Math387.IntPower(x[1] - Math387.IntPower(x[0],2),2) + Math387.IntPower(1 - x[0],2); } private void Example() { double[2] x; double fmin; TOptStopReason StopReason; // initial estimates for x1 and x2 x[0] = 0; x[1] = 0; int iters = Simplex(Banana,x,null,null,out fmin,out StopReason, TMtxFloatPrecision.mvDouble, 1000,1.0E-8,null); // stop if Iters >1000 or Tolerance < 1e-8 // Returns x = [1,1] and FMin = 0, meaning x1=1, x2=1 and minimum value is 0 } *) function Simplex(Func: TRealFunction; var Pars: Array of double; Const Consts: array of double; Const ObjConst: Array of TObject; out FMin: double; out StopReason: TOptStopReason; const FloatPrecision: TMtxFloatPrecision = mvDouble; MaxIter: Integer = 500; Tolerance : double = 1.0E-8; const Verbose: TStrings = nil): Integer; overload; (*Minimizes function of several variables by using Simplex optimization method with no algorithm step log.*) function Simplex(Func: TRealFunction; var Pars: double; Const Consts: array of double; Const ObjConst: Array of TObject; out FMin: double; out StopReason: TOptStopReason; const FloatPrecision: TMtxFloatPrecision; MaxIter: Integer; Tolerance: double): Integer; overload; (*Minimize function of several variables by using Simplex method with lower and/or upper bounds for parameters. This version supports lower and upper bound(s) for function parameters Pars. Lower and upper bounds are defined in LB and UP arrays respectively. Depending on lower and/or upper bound for parameter, there are several possibilities for LB and UB: Lower and upper bound: For each parameter both LB and UB should be set to specific value. Upper bound only: In this case, LB is set to -INF, UB to specific value. Lower bound only: In this case, LB should be set to specific value, UB to +INF. No bounds: In this case, use non-bounded Simplex version or set LB and UB to -INF and +INF respecively. Minimize the "Banana" function, but use lower and upper limit for first parameter and only upper limit for second parameter. private double Banana(TVec x, TVec c, object[] o) { return 100*Math387.IntPower(x[1] - Math387.IntPower(x[0],2),2) + Math387.IntPower(1 - x[0],2); } private void Example() { double[2] x; double fmin; TOptStopReason StopReason; // initial estimates for x1 and x2 x[0] = 0; x[1] = 0; int iters = Simplex(Banana,x,null,null, new double[] {0,-INF}, new double[] {0.5, 0.7}, out fmin,out StopReason, TMtxFloatPrecision.mvDouble,1000,1.0E-8,null); // stop if Iters >1000 or Tolerance < 1e-8 } *) function Simplex(Func: TRealFunction; var Pars: Array of double; Const Consts: array of double; Const ObjConst: Array of TObject; Const LB, UB: Array of double; out FMin: double; out StopReason: TOptStopReason; const FloatPrecision: TMtxFloatPrecision; MaxIter: Integer = 500; Tolerance : double = 1.0E-8; const Verbose: TStrings = nil): Integer; overload; (*Minimizes the function of several variables by using the Quasi-Newton optimization algorithm. Real function (must be of type) to be minimized. The gradient and Hessian procedure (must be of type), used for calculating the gradient. Stores the initial estimates for parameters (minimum estimate). After the call to routine returns adjusted calculated values (minimum position). Additional Fun constant parameteres (can be/is usually nil). Additional Fun constant parameteres (can be/is usually nil). Returns function value at minimum. Returns inverse Hessian matrix. Returns reason why minimum search stopped (see ). If True, BFGS procedure will use Davidon-Fletcher-Powell Hessian update scheme. If False, BFGS procedure will use Broyden-Fletcher-Goldberg-Shamo Hessian update scheme. If True, BFGS internal line search algoritm will use soft line search method. Set SoftLineSearch to true if you're using numerical approximation for gradient. If SoftLineSearch if false, BFGS internal line search. algorithm will use exact line search method. Set SoftLineSearch to false if you're using *exact* gradient. Maximum allowed numer of minimum search iterations. Desired Pars - minimum position tolerance. Minimum allowed gradient C-Norm. If assigned, stores Fun, evaluated at each iteration step. Optionally, you can also pass object to the Verbose parameter. This allows the optimization procedure to be interrupted from another thread and optionally also allows logging and iteration count monitoring. Specifies the floating point precision to be used by the routine. the number of iterations required to reach the solution(minimum) within given tolerance. Problem: Find the minimum of the "Banana" function by using the BFGS-DFP method. Solution:The Banana function is defined by the following equation: Also, BFGS method requires the gradient of the function. The gradient of the Banana function is: // Objective function private double Banana(TVec x, TVec c, params object[] o) { return 100*Math387.IntPower(x[1] - Math387.IntPower(x[0],2),2) + Math387.IntPower(1-x[0],2); } // Analytical gradient of the objective function private void BananaGrad(TRealFunction Fun, TVec Pars, TVec Consts, object[] PConsts, TVec Grad) { Grad[0] = -400*(Pars[1]-Pars[0]*Pars[0])*Pars[0]-2*(1-Pars[0]); Grad[1] = 200*(Pars[1]-Pars[0]*Pars[0]); } private void Example() { double[2] Pars; double fmin; TOptStopReason StopReason; // initial estimates for x1 and x2 Pars[0] = 0; Pars[1] = 0; int iters = Optimization.BFGS(Banana,GradBanana,Pars,null,null,out fmin, iHess, out StopReason, TMtxFloatPrecision.mvDouble, false,true,1000,1.0e-8,1.0e-8,null); // stop if Iters >1000 or Tolerance < 1e-8 } *) function BFGS(Fun: TRealFunction; Grad: TGrad; var Pars: Array of double; Const Consts: array of double; Const ObjConst: Array of TObject; out FMin: double; const IHess: TMtx; out StopReason: TOptStopReason; const FloatPrecision: TMtxFloatPrecision; DFPAlgo: Boolean = false; SoftLineSearch: boolean = true; MaxIter: Integer = 500; Tol: double = 1.0E-8; GradTol: double =1.0E-8; const Verbose: TStrings = nil): Integer;overload; (*Minimizes the function of several variables by using the Quasi-Newton optimization method with no log.*) function BFGS(Fun: TRealFunction; Grad: TGrad; var Pars: Array of double; Const Consts: array of double; Const ObjConst: Array of TObject; out FMin: double; const FloatPrecision: TMtxFloatPrecision; DFPAlgo: Boolean): Integer; overload; (*Minimizes the function of several variables by using the Quasi-Newton optimization method with no log.*) function BFGS(Fun: TRealFunction; Grad: TGrad; var Pars: Array of double; Const Consts: array of double; Const ObjConst: Array of TObject; out FMin: double; const IHess: TMtx; out StopReason: TOptStopReason; const FloatPrecision: TMtxFloatPrecision; DFPAlgo: Boolean; SoftLineSearch: boolean): Integer; overload; (*Minimizes the function of several variables by using the Quasi-Newton optimization method with no log.*) function BFGS(Fun: TRealFunction; Grad: TGrad; var Pars: Array of double; Const Consts: array of double; Const ObjConst: Array of TObject; out FMin: double; const IHess: TMtx; out StopReason: TOptStopReason; const FloatPrecision: TMtxFloatPrecision; DFPAlgo: Boolean; MaxIter: Integer; Tol: double; GradTol: double): Integer; overload; (*Minimizes the function of several variables by using the Conjugate gradient optimization algorithm. the number of iterations required to reach the solution(minimum) within given tolerance. Real function (must be of type) to be minimized. The gradient and Hessian procedure (must be of type), used for calculating the gradient. Stores the initial estimates for parameters (minimum estimate). After the call to routine returns adjusted calculated values (minimum position). Additional Fun constant parameteres (can be/is usually nil). Specifies the floating point precision to be used by the routine. Additional Fun constant parameteres (can be/is usually nil). Returns function value at minimum. Returns reason why minimum search stopped (see ). If True, ConjGrad procedure will use Fletcher-Reeves method. If false, ConjGrad procedure will use Polak-Ribiere method. If True, ConjGrad internal line search algoritm will use soft line search method. Set SoftLineSearch to true if you're using numerical approximation for gradient. If SoftLineSearch if false, ConjGrad internal line search algorithm will use exact line search method. Set SoftLineSearch to false if you're using *exact* gradient. Maximum allowed numer of minimum search iterations. Desired Pars - minimum position tolerance. Minimum allowed gradient C-Norm. If assigned, stores Fun, evaluated at each iteration step. Optionally, you can also pass object to the Verbose parameter. This allows the optimization procedure to be interrupted from another thread and optionally also allows logging and iteration count monitoring. Problem: Find the minimum of the "Banana" function by using the Conjugate gradient method. Solution:The Banana function is defined by the following equation: Normally ConjGrad method would also require gradient procedure. But in this example we'll use the numerical approximation, more precisely the routine. This is done by specifying NumericGradRichardson routine as Grad parameter in ConjGrad routine call (see below) // Objective function private double Banana(TVec x, TVec c, params object[] o) { return 100*Math387.IntPower(x[1] - Math387.IntPower(x[0],2),2) + Math387.IntPower(1-x[0],2); } private void Example() { double[2] Pars; double fmin; TOptStopReason StopReason; // initial estimates for x1 and x2 Pars[0] = 0; Pars[1] = 0; int iters = Optimization.ConjGrad(Banana, MtxIntDiff.NumericGradRichardson, Pars, null, null, out fmin, out StopReason, mvDouble, true, false, 1000, 1.0e-8, 1.0e-8, null); // stop if Iters >1000 or Tolerance < 1e-8 } *) function ConjGrad(Fun: TRealFunction; Grad: TGrad; var Pars: Array of double; Const Consts: array of double; Const ObjConst: Array of TObject; out FMin: double; out StopReason: TOptStopReason; const FloatPrecision: TMtxFloatPrecision; FletcherAlgo: Boolean = true; SoftLineSearch: boolean = true; MaxIter: Integer = 500; Tol: double = 1.0E-8; GradTol: double =1.0E-8; const Verbose: TStrings = nil): Integer; overload; (*Minimizes the function of several variables by using the Conjugate gradient optimization method with no log.*) function ConjGrad(Fun: TRealFunction; Grad: TGrad; var Pars: Array of double; Const Consts: array of double; Const ObjConst: Array of TObject; out FMin: double; const FloatPrecision: TMtxFloatPrecision; FletcherAlgo: Boolean): Integer; overload; (*Minimizes the function of several variables by using the Conjugate gradient optimization method with no log.*) function ConjGrad(Fun: TRealFunction; Grad: TGrad; var Pars: Array of double; Const Consts: array of double; Const ObjConst: Array of TObject; out FMin: double; out StopReason: TOptStopReason; const FloatPrecision: TMtxFloatPrecision; FletcherAlgo: Boolean; SoftLineSearch: boolean ): Integer; overload; (*Minimizes the function of several variables by using the Conjugate gradient optimization method with no log.*) function ConjGrad(Fun: TRealFunction; Grad: TGrad; var Pars: Array of double; Const Consts: array of double; Const ObjConst: Array of TObject; out FMin: double; out StopReason: TOptStopReason; const FloatPrecision: TMtxFloatPrecision; FletcherAlgo: Boolean; SoftLineSearch: boolean; MaxIter: Integer; Tol: double; GradTol: double): Integer; overload; (*Minimizes the function of several variables by using the Marquardt optimization algorithm. Real function (must be of type) to be minimized. The gradient and Hessian procedure (must be of type), used for calculating the gradient and Hessian matrix. Stores the initial estimates for parameters (minimum estimate). After the call to routine returns adjusted calculated values (minimum position). Additional Fun constant parameteres (can be/is usually nil). Additional Fun constant parameteres (can be/is usually nil). Specifies the floating point precision to be used by the routine. Returns function value at minimum. Returns inverse Hessian matrix. Returns reason why minimum search stopped (see ). Maximum allowed numer of minimum search iterations. Desired Pars - minimum position tolerance. Minimum allowed gradient C-Norm. Initial lambda step, used in Marquardt algorithm. If assigned, stores Fun, evaluated at each iteration step. Optionally, you can also pass object to the Verbose parameter. This allows the optimization procedure to be interrupted from another thread and optionally also allows logging and iteration count monitoring. the number of iterations required to reach the solution(minimum) within given tolerance. Problem: Find the minimum of the "Banana" function by using the Marquardt method. Solution:The Banana function is defined by the following equation: Also, Marquardt method requires the gradient and Hessian matrix of the function. The gradient of the Banana function is: and the Hessian matrix is : // Objective function private double Banana(TVec x, TVec c, params object[] o) { return 100*Math387.IntPower(x[1] - Math387.IntPower(x[0],2),2) + Math387.IntPower(1-x[0],2); } // Analytical gradient and Hessian matrix of the objective function private void BananaGradHess(TRealFunction Fun, TVec Pars, TVec Consts, object[] obj, TVec Grad, TMtx Hess) { double[] Pars = Parameters.PValues1D(0); Grad[0] = -400.0*(Pars[1]-Math387.IntPower(Pars[0],2))*Pars[0] - 2*(1-Pars[0]); Grad[1] = 200.0*(Pars[1]-Math387.IntPower(Pars[0],2)); Hess.Values1D[0] = -400.0*Pars[1]+1200*Math387.IntPower(Pars[0],2)+2; Hess.Values1D[1] = -400.0*Pars[0]; Hess.Values1D[2] = -400.0*Pars[0]; Hess.Values1D[3] = 200.0; } private void Example() { double[2] Pars; double fmin; Matrix iHess = new Matrix(0,0); TOptStopReason StopReason; // initial estimates for x1 and x2 Pars[0] = 0; Pars[1] = 0; int iters = Optimization.Marquardt(Banana,BananaGradHess,Pars, null, null, out fmin, iHess, out StopReason, TMtxFloatPrecision.mvDouble, 1000, 1.0e-8, 1.0e-8, null); // stop if Iters >1000 or Tolerance < 1e-8 } *) function Marquardt(Fun: TRealFunction; GradHess: TGradHess; var Pars: Array of double; Const Consts: array of double; Const ObjConst: Array of TObject; out FMin: double; IHess: TMtx; out StopReason: TOptStopReason; const FloatPrecision: TMtxFloatPrecision; MaxIter: Integer = 500; Tol: double = 1.0E-8; GradTol: double =1.0E-8; Lambda0: double = 1e-2; Verbose: TStrings = nil): Integer; overload; (*Minimizes the function of several variables by using the Marquardt optimization method with no log.*) function Marquardt(Fun: TRealFunction; GradHess: TGradHess; var Pars: Array of double; Const Consts: array of double; Const ObjConst: Array of TObject; out FMin: double; const FloatPrecision: TMtxFloatPrecision): Integer; overload; (*Minimizes the function of several variables by using the Marquardt optimization method with no log.*) function Marquardt(Fun: TRealFunction; GradHess: TGradHess; var Pars: Array of double; Const Consts: array of double; Const ObjConst: Array of TObject; out FMin: double; out StopReason: TOptStopReason; const FloatPrecision: TMtxFloatPrecision): Integer; overload; (*Minimizes the function of several variables by using the Marquardt optimization method with no log.*) function Marquardt(Fun: TRealFunction; GradHess: TGradHess; var Pars: Array of double; Const Consts: array of double; Const ObjConst: Array of TObject; out FMin: double; IHess: TMtx; out StopReason: TOptStopReason; const FloatPrecision: TMtxFloatPrecision; MaxIter: Integer; Tol: double; GradTol: double; Lambda0: double): Integer; overload; (*Trust region algorithm for finding minimum of vector function. The objective function to be minimized. The Jacobian matrix calculation procedure. If it is nil, then the numerical approximation will be used to evaluate Jacobi matrix elements. Stores the initial estimates for X. On completion returns estimates, evaluated at function minimum. Returns objective function value, evaluated at minimum. Additional Fun constant parameteres (can be/is usually nil). Additional Fun constant parameteres (can be/is usually nil). Defines the maximum number of main TR algorithm loops. Defines the maximum number of iterations of trial-step calculation. Optional object, which allows the interruption of the search. Array of size 6. Contains stopping tests. eps[0]: Grad < eps[0] eps[1]: ||F(x)|| < eps[1] eps[2]: ||A(x)ij|| < eps[2] eps[3]: ||s|| < eps[3] eps[4]: ||F(x)||- ||F(x) - A(x)s|| < eps[4] eps[5]: trial step precision. If eps[5] = 0, then eps[5] = 1E-10, where A(x) = the jacobi matrix F(x) = ||y - f(x)|| Positive input variable used in determining the initial step bound, the initial size of the trust region. In most cases the factor should lie within the interval (0.1, 100.0). The generally recommended value is 100, which is used by default, if this param is set to 0. Returns the TR algorithm stop reason. the number of iterations needed for results. The Trust Region (TR) algorithms are relatively new iterative algorithms for solving nonlinear optimization problems. They are widely used in power engineering, finance, applied mathematics, physics, computer science, economics, sociology, biology, medicine, mechanical engineering, chemistry, and other areas. TR methods have global convergence and local super convergence, which differenciates them from line search methods and Newton methods. TR methods have better convergence when compared with widely-used Newton-type methods. The main idea behind TR algorithm is calculating a trial step and checking if the next values of x belong to the trust region. Calculation of the trial step is strongly associated with the approximation model. For more on TR algorithm, check the following links: * http://iridia.ulb.ac.be/~fvandenb/optimization/optimizationIntro.html * http://en.wikipedia.org/wiki/Trust_region Note: This function is currently not supported under .NET. The objective function calls are threaded. The objective function should not be allocating any memory on the heap because calling threads are created outside of Delphi/BCB code. Uses MtxExpr, Optimization, MtxVec, Math387; // Objective function, 4 variables, 4 f components procedure TestVFun(const x,f: TVec; const c: Array of double; const o: Array of TObject); begin f[0] := x[0] + 10.0*x[1]; f[1] := 2.2360679774997896964091736687313*(x[2] - x[3]); f[2] := (x[1] - 2.0*x[2])*(x[1] - 2.0*x[2]); f[3] := 3.1622776601683793319988935444327*(x[0] - x[3])*(x[0] - x[3]); end; procedure Example; var x,f: Vector; epsa: TEPSArray; sr: TOptStopReason; begin // Initial estimates for variabless x.SetIt(false,[3,-1,0,1]); // 4 components, size must match the TestVFun implementation above f.Size(4); // setup stopping criteria, use default values epsa[0] := 1.0E-5; epsa[1] := 1.0E-5; epsa[2] := 1.0E-5; epsa[3] := 1.0E-5; epsa[4] := 1.0E-5; epsa[5] := 1.0E-10; // Minimize TrustRegion(TestVFun,x,f,[],[],1000,100,epsa,0.0,sr); // x stores minimum position (variables) // f stores function value at minimum // sr stores stop reason end; #include "MtxExpr.hpp" #include "Math387.hpp" #include "Optimization.hpp" void __fastcall TestVFun(TVec* const x, TVec* const f, const double * c, const int c_Size, System::TObject* const * o, const int o_Size) { double* X = x->PValues1D(0); f->Values[0] = X[0] + 10.0*X[1]; f->Values[1] = 2.2360679774997896964091736687313*(X[2] - X[3]); f->Values[2] = (X[1] - 2.0*X[2])*(X[1] - 2.0*X[2]); f->Values[3] = 3.1622776601683793319988935444327*(X[0] - X[3])*(X[0] - X[3]); } void __fastcall Example(); { Vector x,f; TEPSArray epsarr; TOptStopReason sr; // Initial estimates for variabless x->SetIt(false,OPENARRAY(double,(3,-1,0,1))); // 4 components, size must match the TestVFun implementation above f->Size(4,false); // setup stopping criteria, use default values epsarr[0] = 1.0E-5; epsarr[1] = 1.0E-5; epsarr[2] = 1.0E-5; epsarr[3] = 1.0E-5; epsarr[4] = 1.0E-5; epsarr[5] = 1.0E-10; // Minimize TrustRegion(TestVFun,NULL,x,f,NULL,-1,NULL,-1,1000,100,epsarr,0.0,sr); // x stores minimum position (variables) // f stores function value at minimum // sr stores stop reason } *) function TrustRegion(Fun: TVectorFunction; JacProc: TJacobianFunction; const X,Y: TVec; Const Consts: Array of double; Const OConsts: Array of TObject; MaxIter, MaxTrialIter: Integer; Const EPSArray: TEPSArray; Rs: double; out StopReason: TOptStopReason; const Control: TOptControl = nil): Integer; overload; (**) function TrustRegion(Fun: TMKLTRFunction; JacProc: TJacobianFunction; const X,Y: TVec; const CustomData: TObject; MaxIter, MaxTrialIter: Integer; Const EPSArray: TEPSArray; Rs: double; out StopReason: TOptStopReason; const Control: TOptControl = nil): Integer; overload; (*Trust region algorithm to find bounded minimum of vector function. Additional parameters LB and UB define x lower and/or upper bounds. *) function TrustRegion(Fun: TVectorFunction; JacProc: TJacobianFunction; const X,Y: TVec; const LB,UB: TVec; Const Consts: Array of double; Const OConsts: Array of TObject; MaxIter, MaxTrialIter: Integer; Const EPSArray: TEPSArray; Rs: double; out StopReason: TOptStopReason; const Control: TOptControl = nil): Integer; overload; (**) function TrustRegion(Fun: TMKLTRFunction; JacProc: TJacobianFunction; const X,Y: TVec; const CustomData: TObject; const LB,UB: TVec; MaxIter, MaxTrialIter: Integer; Const EPSArray: TEPSArray; Rs: double; out StopReason: TOptStopReason; const Control: TOptControl = nil): Integer; overload; (*Linear optimization by Dual Simplex algorithm. Value of the objective function, evaluated at minimum or maximum. Defines initial values for A*x >= b relation. Defines values in f=c(T)*x equation. Defines initial values for A*x >= b relation. Returns the final tableaux. Returns values of the legitimate variables (optimal solution). Returns indices (in IValues) of the basic variables in AFinal tableu. If false, find minimum of the objective function f. If false, find maximum of the objective function f. Returns type of LP solution. If assigned, each tableu and row/column pivoting is logged to Verbose. Optionally, you can also assign object to the Verbose parameter. This allows the optimization procedure to be interrupted from another thread and optionally also allows logging and iteration count monitoring. Solves the following optimization problem: Components of the vector b are not required to satisfy the nonnegativity constraints. The Dual Simplex Algorithm has numerous applications to other problems of linear programming. It is used, for instance, in some implementations of the Gomory's cutting plane algorithm for solving the integer programming problems. Solve linear programming problem with 3 equations and 4 positive constraints. using Dew.Math.Units; using Dew.Math; namespace Dew.Examples { private void Example() { Matrix A=new Matrix(0,0); Matrix Af=new Matrix(0,0); Vector b = new Vector(0); Vector c = new Vector(0); Vector x = new Vector(0); Vector iondexes = new Vector(0); TLPSolution sol; A.SetIt(3,4,false, new double[] {2,1,5,0,1,2,3,0,1,1,1,1}); b.SetIt(new double[] {20,25,10}); c.SetIt(new double[] {1,2,3,-1}); // Find maximum using above system double f = Optimization.SimplexDual(A,b,c,Af,x,indexes, out sol, false, null); } } *) function SimplexDual(const A: TMtx; const b,c: TVec; const AFinal: TMtx; const X: TVec; const Indexes: TVecInt; out SolutionType: TLPSolution; Minimize: boolean = true; const Verbose: TStrings = nil): double; (*Linear optimization by Two-Phase Simplex algorithm. Solves the following optimization problem: where rel holds the relation signs. For example, relation string ' < = > ' means the constraints system consists of one inequality ' <= ', one equality ' = ' and one more inequality ' >= '. Optionally, you can also assign object to the Verbose parameter. This allows the optimization procedure to be interrupted from another thread and optionally also allows logging and iteration count monitoring. Solve the following LP problem: f(x) = x1+x2+2*x3-2*x4 subject to: f(x) = x1+x2+2*x3-2*x4 subject to: x1+2x <= 700 2x2-8x4 <= 0 x2-2x3+x4 > 1 x1+x2+x3+x4 = 1 which translates to using two-phase simplex method: using Dew.Math; using Dew.Math.Units; namespace Dew.Examples { private void Example() { Matrix A = new Matrix(0,0); Matrix AFinal = new Matrix(0,0); Vector b = new Vector(0); Vector c = new Vector(0); Vector x = new Vector(0); Vector indexes = new Vector(0); TLPSolution sol; A.SetIt(4,3,false,new double[] {1,1,0,0 0,2,0,-8, 0,1,-2,1, 1,1,1,1}); b.SetIt(new double[] {700,0,1,1}); c.SetIt(new double[] {1,1,2,-2}); string relations = " < < > = "; //remove spaces from the string: relations = relations.Replace(" ", ""); //for XMLDoc only double f = Optimization.SimplexTwoPhase(A,b,c,relations,AFinal,x,indexes, out sol, true,null); } } *) function SimplexTwoPhase(const A: TMtx; const b,c: TVec; const relations: String; const AFinal: TMtx; const X: TVec; const Indexes: TVecInt; out SolutionType: TLPSolution; Minimize: boolean = true; const Verbose: TStrings = nil): double; (*Linear optimization by using Simplex method. Solves the following optimization problem: where vector b must be a positive vector. Optionally, you can also assign object to the Verbose parameter. This allows the optimization procedure to be interrupted from another thread and optionally also allows logging and iteration count monitoring. *) function SimplexLP(const A: TMtx; const b,c: TVec; const AFinal: TMtx; const X: TVec; const Indexes: TVecInt; out SolutionType: TLPSolution; Minimize: boolean = true; const Verbose: TStrings = nil): double; (*Gomory's cutting plane algorithm for solving the integer programming problem. Implements the Gomory's Cutting Plane Algorithm (CPA) for solwing the following linear programming problem with decision variables being restricted to integer values. Optionally, you can also assign object to the Verbose parameter. This allows the optimization procedure to be interrupted from another thread and optionally also allows logging and iteration count monitoring. Minimize the following linear programming problem: f(x)=x1-3x2 (x1,x2 integers) x1-x2=2 2x1+4x2=15 which translates to: using Dew.Math; using Dew.Math.Units; namespace Dew.Examples { private void Example() { Matrix A = new Matrix(0,0); Matrix AFinal = new Matrix(0,0); Vector b = new Vector(0); Vector c = new Vector(0); Vector x = new Vector(0); Vector indexes = new Vector(0); TLPSolution sol; A.SetIt(2,2,false,new double[] {1,-1,2,4}); b.SetIt(new double[] {2,15}); c.SetIt(new double[] {1,-3}); double f = Optimization.CPA(A,b,c,AFinal,x,indexes, out sol, true,null); // f = -9.0 // x1=0, x2=3 } } *) function CPA(const A: TMtx; const b,c: TVec; const AFinal: TMtx; const X: TVec; const Indexes: TVecInt; out SolutionType: TLPSolution; Minimize: boolean = true; const Verbose: TStrings = nil): double; function StopReasonToStr(const stopReason: TOptStopReason): string; (*Introduces several polynomial handling routines. Unit introduces routines for: * poly roots,coefficients, * evaluation, fitting, * splines, * piecewise polynomials, * polynomial division and multiplication. *) unit Polynoms; interface {$I BdsppDefs.inc} uses MtxVec, Math387, IppsplTypes, AbstractMtxVec ,SysUtils ,Classes ,Types ; (*Defines the type of 1D interpolation.*) type TInterpolationType = ( (*Perform linear interpolation.*)IntLinear, (*Perform cubic interpolation.*)IntCubic ); (*Manages piece-wise polynomials. Use this object to construct and evaluate piece-wise polynomials. Key properties of the object can initialized by interpolation routines: and Additional properties like ,, and must be set manually. Setting these properties can significantly improve the performance. Note All vector and matrices, used in this class must be real. *) type TPiecePoly=class(TObject) strict private FCoefficients: TMtx; FBreaks: TVec; StartPos : Integer; FDummyInt : Integer; FBreaksEquidistant: boolean; FBreaksStep: double; FValuesSorted: boolean; FBreaksOffset: double; function GetPieces: Integer; function GetOrder: Integer; procedure SefCoefficients(const Value: TMtx); procedure SetBreaks(const Value: TVec); procedure IOnSetSize(Sender: TObject); procedure SetBreaksStep(const Value: double); procedure SetBreaksEquidistant(const Value: boolean); procedure SetValuesSorted(const Value: boolean); procedure SetBreaksOffset(const Value: double); public (*Evaluate piece-wise polynomial. Evaluate piece-wise polynomial at all X values and store the results in Y. The Length and Complex properies of vector Y are adjusted automatically. Note There are four additional parameters that affect how fast will the evaluation occur: , , and . *) procedure Evaluate(X: TDenseMtxVec; Y: TDenseMtxVec); overload; (*Evaluate piece-wise polynomial. Evaluates pice-wise polynomial for single x,y point. *) procedure Evaluate(X: double;var Y: double); overload; (*Evaluate piece-wise polynomial. Evaluates pice-wise polynomial for single x,y point. *) procedure Evaluate(X: single;var Y: single); overload; constructor Create; destructor Destroy; override; public (*If True all breaks will be assumed to be spaced at equal intervals. If True all breaks will be assumed to be spaced at equal intervals. This allows the routine to compute the interval within which the interpolation point falls. If the breaks are not equidistant the interval defined by two breaks Low_Break < X_Value < High_Break, must be searched for. *) property BreaksEquidistant: boolean read FBreaksEquidistant write SetBreaksEquidistant; (*Defines the step between the Breaks. Defines the step between the . This step must be specified, if is True. *) property BreaksStep: double read FBreaksStep write SetBreaksStep; (*Defines the offset from zero of the first break. Defines the offset from zero of the first break. This offest must be specified, if is True. *) property BreaksOffset: double read FBreaksOffset write SetBreaksOffset; (*Defines if X Values are sorted. If X Values defining the interpolation points are sorted, but the Breaks are not equidistant (BreaksEquidistant is false), the Evaluate routine will use a consecutive linear search algorithm to find the right breaks interval. The linear search for each X-Value will continue from the point where it left off for the previous one. If X Values are not sorted, the ValuesSorted must be set to false. A bisection search algorithm will be employed in that case. *) property ValuesSorted: boolean read FValuesSorted write SetValuesSorted; (*Returns the number of piece-wise polynomial pieces. The number of pieces is one less than the number of breaks (Breaks.Length). *) property Pieces: Integer read GetPieces write FDummyInt; (*Returns the order of the piece-wise interpolation. The order of the polynomial is equal to the number of Coefficients columns -1 and is smaller by one then the value of this property. For linear interpolation the order is 2. For cubic interpolation, the order is 4. *) property Order: Integer read GetOrder write FDummyInt; (*Stores the piece-wise polynomial breaks. Stores the piece-wise polynomial breaks. Property determines the intervals for piece-wise polynomial. It can not be complex. *) property Breaks: TVec read FBreaks write SetBreaks; (*Stores the coefficients of the piece-wise polynomial. Stores the coefficients of the piece-wise polynomial. Each section is stored in its own row. When setting the Coefficients Rows and Cols properties, the number of rows must be equal to the number of sections - pieces. The number of columns must be equal to the property. *) property Coefficients: TMtx read FCoefficients write SefCoefficients; end; (*Fits a polynomial to data. Defines x values in p=p(x). Defines polynomial, evaluated at x i.e p(x). Defines polynomial degree. If not nil, defines fitting weights. Returns the coeficients of fitted polynomial. Returns the Cholesky factor of the Vandermonde matrix. Returns the degree of freedom. Returns the L2 norm of the residuals. The PolyFit procedure uses the least-squares method to find the fitted polynomial coefficients. using Dew.Math; using Dew.Math.Units; using Dew.Math.Tee; namespace Dew.Examples { private void Example() { Vector X = new Vector(0); Vector Y = new Vector(0); Vector YCalc = new Vector(0); Vector Delta = new Vector(0); Vector Coeff = new Vector(0); Matrix R = new Matrix(0,0); int degF; double L2R; X.Ramp(100); y.Size(X); Y.RandomGauss(2.0,3.0); Polynoms.PolyFit(X,Y,3,Coeff,R, out degF, out L2R, null); //Fit Polynoms.PolyEval(X,Coeff,degF,L2R,YCalc,Delta); // Evaluate MtxVecTee.DrawIt(new Vector[] {Y,YCalc}, new string[] {"Original","Fit"},"Fit results",false); } } *) procedure PolyFit(XValues,YValues: TVec; Degree: Integer; Coeff: TVec; R: TMtx; out DegFreedom: Integer; out L2R: double; Weights: TVec = nil); overload; (*Fits a polynomial to data. This overload does not return additional statistical parameters like Cholesky matrix or degrees of freedom. *) procedure PolyFit(XValues,YValues: TVec; Degree: Integer; Coeff: TVec; Weights: TVec = nil); overload; (*Converts polynomial roots to coefficients. The PolyCoeff procedure converts polynomial roots to coefficients. The following scheme is used to construct a coefficients from the roots: P(x) = coeff[0]*x^n + coeff[1]*x^(n-1) + .. + coeff[n] = (x - roots[0])* .. *(x - roots[n-1]) n .. order of the polynomial The length and complex property of the Coeff object are set automatically. The inverse to this routine is *) procedure PolyCoeff(Roots, Coeff: TVec); overload; (*Returns coefficients of the characteristic polynomial. Returns coefficients of the characteristic polynomial: det( Mtx - Lambda * I ). Find coefficients of a characteristic polynomial: using Dew.Math; using Dew.Math.Units; using Dew.Math.Editors; namespace Dew.Examples { private void Example() { Vector Coeff = new Vector(0); Matrix A = new Matrix(0,0); A.SetIt(3,3,false, new double[] {1, 4, -1, 2, 1, 5, 3, -2, 0}); Polynoms.PolyCoeff(A,Coeff); MtxVecEdit.ViewValues(Coeff,"Coefficients"); } } *) procedure PolyCoeff(Mtx: TMtx; Coeff: TVec); overload; (*Finds the roots of the polynomial from the coefficents. Finds the roots of the polynomial from the coefficents. The Coeff holds the coefficients and the result is placed in the Roots. P(x) = coeff[0]*x^n + coeff[1]*x^(n-1) + .. + coeff[n+1] = (x - roots[0])* .. *(x - roots[n-1]) n ... order of the polynomial P(x).. value of the polynomial evaluated at x. The Length and Complex property of the Roots parameter are set automatically. The inverse to this routine is Roots are computed by finding the eigenvalues of the companion matrix. using Dew.Math; using Dew.Math.Units; using Dew.Math.Editors; namespace Dew.Examples { private void Example() { Vector Coeff = new Vector(0); Vector Roots = new Vector(0); // coefficients of the polynomial 1*x^2 - 2*x + 1: Coeff.SetIt(false, new double[] {1, -2, 1}); Polynoms.PolyRoots(Roots,Coeff); // Roots now hold the roots of the polynomial = [ 1, 1 ] // x^2 - 2x + 1 = (x - 1) * (x - 1) MtxVecEdit.ViewValues(Roots,"Roots"); } } *) procedure PolyRoots(Roots, Coeff:TVec); (*Evaluate a polynomial. Stores values doe which the polynomial will be evaluated (x values). Stores polynomial coefficients for which the polynomial will be evaaluted. Returns the Cholesky factor of the Vandermonde matrix. Returns the residuals degree of freedom. Returns the L2 norm of the residuals. Returns the results P(x), evaluated at Val. Returns the error estimates for Results. Evaluate a polynomial with coefficients Coeff at value Val. The order of polynomial (N) is determined as: N := Coeff.Length - 1. The algorithm employed uses Horners rule. The following formula is used to evaluate the polynomial: P(x) = coeff[0]*x^n + coeff[1]*x^(n-1) + .. + coeff[n] To estimate the error of polynomial interpolation after a call to additional parameters have to be passed to the routine. *) procedure PolyEval(Val, Coeff: TVec; R: TMtx; DegFreedom: Integer; L2R: double; EvalResult, Delta: TVec); overload; (*Evaluates a polynomial with coefficients Coeff at value Val and returns the results in EvalResult. Evaluates a polynomial with coefficients Coeff at value Val and returns the results in EvalResult. *) procedure PolyEval(Val, Coeff, EvalResult: TVec); overload; (*Evaluates a polynomial with coefficients Coeff at real value Val and returns real result. Evaluates a polynomial with coefficients Coeff at real value Val and returns real result. *) function PolyEval(Val: double; Coeff: TVec): double; overload; (*Evaluates a polynomial with coefficients Coeff at complex value Val and returns complex results. Evaluates a polynomial with coefficients Coeff at complex value Val and returns complex results. using Dew.Math; using Dew.Math.Units; using Dew.Math.Tee; namespace Dew.Examples { private void Example() { Vector X = new Vector(0); Vector Y = new Vector(0); Vector Coeff = new Vector(0); X.Size(10); X.Ramp(-5,1); // X = [-5,-4,-3,-2,-1, 0, 1, 2, 3, 4] // construct a parabola Coeff.SetIt(false,new double[] {2, -1, 3}); Polynoms.PolyEval(X,Coeff,Y); // Y now holds the values of polynomial, evaluated at all X.Values MtxVecTee.DrawIt(X,Y,"Parabola",false); } } *) function PolyEval(Val:TCplx; Coeff:TVec): TCplx; overload; procedure StripZeros(Src,Dst:TVec; var Lead, Trail: integer); overload; (*Removes leading zeros. Removes leading zeros. In case of polynomials the most left coefficents in the array are for the highest powers. If those coefficients are zero they can be removed. The routine will copy the Src to Dst and remove any leading zeros from Dst. *) procedure StripLeadZeros(Src,Dst: TVec); overload; (*Cubic spline interpolation. The procedure interpolates cubic splines between consequtive (X,Y) pairs. The rotine does not return interpolated points. It constructs piece-wise polynomial, which in term can be used for evaluating (by using the TPiecePoly.Evaluate method) cubic splines. To directly obtain interpolated values, use the routine. Note If X.Length=Y.Length, then the "not-a-knot" end conditions are used. If Y.Length = X.Length +2 then the "knot" end conditions are used. X values must be monotonic or the result will not be valid. *) procedure Spline1D(X, Y: TVec; PiecePoly: TPiecePoly);overload; (*Interpolates cubic splines between consecutive Y points. Interpolates cubic splines between consecutive Y points. The assumption is that Y is evaluated at [0,1,2,...] -> X values are [0,1,2,...]. If the Knot parameter is true then the first and the last Y value will be used for the end conditions. In this case Y.Length = X.Length + 2. using Dew.Math; using Dew.Math.Units; using Dew.Math.Tee; namespace Dew.Examples { private void Example() { Vector X = new Vector(0); Vector Y = new Vector(0); Vector Y2 = new Vector(0); TPiecePoly PP = new TPiecePoly(); int i; double YVal; // generate function - note that X values are monotonical X.Size(100); Y.Size(100); Y2.Size(100); X.Ramp(0,1); Y.RandUniform(0,50); Y2.Ramp(100,0.25); Y += Y2; // construct cubic splines, but do not evaluate them Polynoms.Spline1D(X,Y,PP); X.Size(800); X.Ramp(0,0.125); //get interpolation points PP.Evaluate(X,Y2); // evaluate MtxVecTee.DrawIt(Y,"Original",false); MtxVecTee.DrawIt(Y2,"Interpolated",false); } } *) procedure Spline1D(Y: TVec; PiecePoly: TPiecePoly; Knots: boolean = false);overload; (*Linear interpolation. The Linear1D procedure interpolates lines between consecutive (X,Y) pairs. Linear1D does not return interpolated points. It constructs piece-wise polynomial, which can be used to evaluate ( by using the PiecePoly.Evaluate method) the linear functions. To directly obtain interpolated values, use the routine. Note: X values must be monotonic or the result will not be valid. *) procedure Linear1D(X, Y: TVec; PiecePoly: TPiecePoly);overload; (*Perform interpolation assuming that Y is evaluated at [0,1,2,...]. using Dew.Math; using Dew.Math.Units; using Dew.Math.Tee; namespace Dew.Examples { private void Example() { Vector X = new Vector(0); Vector Y = new Vector(0); Vector Y2 = new Vector(0); TPiecePoly PP = new TPiecePoly(); int i; double YVal; // generate function - note that X values are monotonical X.Size(100); Y.Size(100); Y2.Size(100); X.Ramp(0,1); Y.RandUniform(0,50); Y2-Ramp(100,0.25); Y += Y2; // construct cubic splines, but do not evaluate them Polynoms.Linear1D(X,Y,PP); X.Size(800); X.Ramp(0,0.125); //get interpolation points PP.Evaluate(X,Y2); // evaluate MtxVecTee.DrawIt(Y,"Original",false); MtxVecTee.DrawIt(Y2,"Interpolated",false); } } *) procedure Linear1D(Y: TVec; PiecePoly: TPiecePoly);overload; procedure InterpolateEqd(X,Y: TVec; intX, IntY: TVec; IntType: TInterpolationType = IntCubic); (*Perform linear or cubic interpolation. The routine interpolates IntY at IntX to the underlying function values, stored in Y. X.Length and Y.length properties must match or an exception will be raised. The IntType parameter defines the type of interpolation (linear, cubic). The intXSorted parameter defines whether intX values are sorted. If intX values are sorted the interpolation is much faster. Vector X stores the positions, where the function is evaluated. X values must be monotonic. The Length and Complex properties of the IntY vector are adjusted automatically. *) procedure Interpolate(X,Y: TVec; intX, IntY: TVec; IntType: TInterpolationType = IntCubic; IntXSorted: boolean = true);overload; (*Performs interpolation assuming X=[0,1,..]. Performs interpolation assuming X=[0,1,..] and assumes that Y is evaluated at [0,1,2,...] -> X values are [0,1,2,...]. using Dew.Math; using Dew.Math.Units; using Dew.Math.Tee; namespace Dew.Examples { private void Example() { Vector X = new Vector(0); Vector Y = new Vector(0); Vector PX = new Vector(0); Vector PY = new Vector(0); // generate function - note that X values are monotonical Random r = new Random(); X.Ramp(); Y.Values[0] = 100.0; for (int i=1; i < X.Length; i++) Y.Values[i] = Y.Values[i-1] + 250 - r.Next(500); // now setup the points at which you want to interpolate PX.Size(1000); PX.Ramp(); PX.Scale(0.1); // calculate piecewise poly for the range of points - // note that PX values are sorted Polynoms.Interpolate(X,Y,PX,PY,TInterpolationType.IntCubic,true); // PY returns the interpolated points, calculated at PX MtxVecTee.DrawIt(Y,"Original",false); MtxVecTee.DrawIt(PY,"Interpolated",false); } } *) procedure Interpolate(Y: TVec; intX, IntY: TVec; IntType: TInterpolationType = IntCubic; intXSorted: boolean = true); overload; (*Performs infinite impulse response (IIR) filtering. Performs infinite impulse response (IIR) filtering. The IIRFilter procedure filters X through an IIR filter ([1]) and stores the results in vector Y. The filter is described with vectors A and B. The X values are filtered by using the following equation: y[i] = b[0]*x[i] + b[1]*x[i-1] + ... + b[N]*x[i-N] + a[1]*y[i-1] + ... + a[M]*y[i-M] x[i] ... input sample y[i] ... output (filtered) sample where M = A.Length-1 and N = B.Length-1. The filter coefficients are normalized by A.Values[0]. The routine is not capable of continuous filtering (streaming). *) procedure IIRFilter(const B, A, X, Y: TVec; const DelayLine: TVec = nil); overload; (*Divide polynomials, deconvolution. The procedure deconvolves vector A out of vector B. If vectors A and B are treated as polynomial coefficients, the the deconvolution is equal to polynomial division. In this case the DeConv divides polynomial B with polynomial A and returns the quotient in Quot and remainder in Remain. An exception is raised if A and B complex properties do not match. An exception is raised if |A.Values[0]| = 0. NOTE To perform polynomial multiplication, use the TVec.Convolve method. Below are two cases. In the first case the following division is performed. (x - 1) * (x - 2) * (x - 2) -------------------------------- = (x - 1) * (x - 2) 1*x^3 - 5*x^2 + 8x - 4 -------------------------- = x - 2 x^2 - 3x + 2 For the first example the ratio is x-2, and the reminder is zero. The second case demonstrates that division can be done also for complex polynomials giving complex result and reminder. using Dew.Math; using Dew.Math.Units; using Dew.Math.Editors; namespace Dew.Examples { private void Example() { Vector A = new Vector(0); Vector B = new Vector(0); Vector Ar = new Vector(0); Vector Br = new Vector(0); Vector Q = new Vector(0); Vector R = new Vector(0); // Case 1 Ar.SetIt(false,new double[] {1,2}); // Define roots of the polynomial A: Polynoms.PolyCoeff(Ar,A); // get coefficients = (X - 1)* (X - 2) Br.SetIt(false,new double[] {1,2,2}); // Define roots of the polynomial B: Polynoms.PolyCoeff(Br,B); //get coefficents = (X - 1)* (X - 2) * (X - 2) Polynoms.DeConv(B,A,Q,R); // Q = [ 1, -2 ] // R = [ 0 ] MtxVecEdit.ViewValues(Q,"Q",true); MtxVecEdit.ViewValues(R,"R",true); // Case 2 B.SetIt(true,new double[] {2,-1, 2,3, 0,5}); A.SetIt(true,new double[] {0,2, 1,-3, 2,2}); Polynoms.DeConv(B,A,Q,R); // Q = [ -0.5 - i ] // R = [ 0 , 5.5 + 2.5i, -1 + 8i] MtxVecEdit.ViewValues(Q,"Q",true); MtxVecEdit.ViewValues(R,"R",true); } } *) procedure DeConv(B,A:TVec; Quot,Remain: TVec); (* Probabilities distribution functions. This unit introduces over 40 commonly used probability distributions. Discrete and Continuous distributions A random variable is discrete if it can assume at most a finite or countably infinite number of possible values. A random variable is continuous if it can assume any value in some interval or intervals of real numbers and the probability that it assumes any specific value is zero. PDF, CDF and inverse CDF When dealing with the random variable, it is not enough just to determine what values are possible. There is also a need to determine what is probable. We must be able to predict in some sense the values that the variable is likely to assume at any time. Since the behavior of a random variable is governed by chance, these predictions must be made in the face of a great deal of uncertainty. The best that can be done is to describe the behavior of the random variable in terms of probabilities. Two functions are used to accomplish this, probability density functions and cumulative distribution functions. Probability density function (PDF) Discrete distributions: There are several facts to \note concerning the PDF in the discrete case. First, the PDF is defined on the entire real line, and for any given real number x, f(x) is the probability that the random variable X assumes the value x. The necessary and sufficient conditions for a function f to be a PDF are: Even though a discrete density is defined on the entire real line, it is only necessary to specify the density for those values x for which f(x) is not zero. Continuous distributions: The PDF is defined on an entire real line and is nonnegative. In the continuous case the probability that the random variable X assumes the value x is 0. Therefore, we are interested in finding the probability that random variable X assumes values in some interval [a,b]. The necessary conditions for a function f to be a PDF are: In Probabilities.pas all probability density functions have a PDF at the end of their name. Cumulative distribution function (CDF) Discrete distributions: The word "cumulative" suggests the role of the CDF function. It sums or accumulates the probabilities found by means of PDF. The cumulative distribution function F(x) is defined as follows: We must sum the PDF over all values of X that occur with nonzero probability that are less than or equal to x. Continuous distributions: In continuous case is the cumulative distribution function - CDF defined exactly as in the discrete case although found by using integration rather than summation. The cumulative distribution function F(X) is defined as follows: In this case, to find a specific F(x), we must integrate the density over all real numbers that are less than or equal to x. In Probabilities.pas all cumulative distribution functions have a CDF at the end of their name. Getting the "original values" from given probability (inverse CDF) Generally, the "inverse" cumulative distributions are used to "get" the original values that were used for calculating the CDF. If the distribution is continuous, the result of the inverse CDF is the original value. If the distribution is discrete, the result is generally not the exact original value. Discrete distributions: As stated above, the relationship between a discrete CDF and its inverse function is more complicated. It is likely that there is no such value x that the CDF of x gives the desired probability. In these cases the inverse function returns the first value x such that the CDF of that value equals or exceeds the desired probability. Continuous distributions: Calculating the CDF of values gives the probabilities in the interval [0,1]. If we want the original values that were used for the CDF (x), we must apply the inverse cumulative distribution. The result is the original value used to calculate CDF. In Probabilities.pas all inverse cumulative distribution functions have a CDFInv at the end of their name. *) unit Probabilities; {$I BdsppDefs.inc} interface uses Math387 , MtxVec, AbstractMtxVec, AbstractMtxVecInt, MtxVecInt, MtxVecBase ,SysUtils ; type (*All supported probability distributions.*) TDistribution = ( (*Beta distribution*)distBETA, (*Bernoulli distribution*)distBERNOULLI, (*Binomial distribution*)distBINOM, (*Bose-Einstein distribution*)distBOSEEINSTEIN, (*Cauchy distribution*)distCAUCHY, (*Chi-Squared distribution*)distCHISQUARE, (*Erlang distribution*)distERLANG, (*Exponential distribution*)distEXP, (*Fisher(F) distribution*)distF, (*Fatigue-Life distribution*)distFATIGUE, (*Fermi-Dirac distribution*)distFERMIDIRAC, (*Gamma distribution*)distGAMMA, (*Generalized Extreme value distribution*)distGenExtValue, (*Generalized Pareto distribution*)distGenPareto, (*Geometric distribution*)distGEOMETRIC, (*Gumbel maximum distribution*)distGUMBELMAX, (*Gumbel minimum distribution*)distGUMBELMIN, (*Hypergeometric distribution*)distHYPGEOMETRIC, (*Inverse Chi-Squared distribution*)distINVChi2, (*Inverse Gaussian distribution*)distINVGAUSS, (*Johnson bounded distribution*)distJOHNSONSB, (*Johnson unbounded distribution*)distJOHNSONUB, (*Laplace distribution*)distLAPLACE, (*Logarithmic distribution*)distLOGARITHMIC, (*Logistic distribution*)distLOGISTIC, (*Log-Normal distribution*)distLOGNORMAL, (*Log-Weibull distribution*)distLOGWEIBULL, (*Maxwell distribution*)distMAXWELL, (*Negative binomial distribution*)distNEGBINOM, (*Normal distribution*)distNORMAL, (*Pareto distribution*)distPARETO, (*Poisson distribution*)distPOISSON, (*Power distribution*)distPOWER, (*Rayleigh distribution*)distRAYLEIGH, (*Student(T) distribution*)distSTUDENT, (*Triangular distribution*)distTRIANGULAR, (*Uniform distribution*)distUNIFORM, (*Discrete uniform distribution*)distUNIFORMD, (*Weibull distribution*)distWEIBULL, (*Zipf distribution*)distZIPF); (*Binomial coefficient C(n,k). the binomial coefficient nCk. n in nCk. k in nCk. Binomial coefficient nCk is the number of ways of picking k unordered outcomes from n possibilities, also known as a combination or combinatorial number. The binomial coefficient is defined by the following equation: *) function Binomial(N, K: integer): double; overload; (*Beta function B. beta function B for given parameters x and y. x in Beta function definition. y in Beta function definition. The beta function is defined by the following equation: *) function Beta(x, y: double): double; overload; (*Incomplete beta function. incomplete beta function for given parameters x, a and b. The incomplete beta function is defined by the following equation: , where B(a,b) is function. *) function BetaIncomplete(x,a,b: double): double; overload; (*Dirichlet Beta function. the Dirichlet Beta function. The Dirichlet beta function, defined for real values can be written as: , It can be extended over a whole complex plane by the following relation: , where Gamma denotes the function. *) function DirichletBeta(const Z: TCplx): TCplx; overload; (*Dirichlet Lambda function. the Dirichlet Lambda function. Defines complex value for which the Lambda function is to be calculated. Defines used number of terms used in complex series approximation of Lambda function. Dirichlet Lambda function is defined by the following equation: , *) function DirichletLambda(const Z: TCplx; n: Integer= 64): TCplx; overload; (*Dirichlet Eta function. the Dirichlet Eta function. Defines complex value for which the Eta function is to be calculated. Defines used number of terms used in complex series approximation of Eta function. Dirichlet eta function is defined by the following equation: , *) function DirichletEta(const Z: TCplx; n: Integer = 64 ): TCplx; overload; (*Riemann Zeta function. the Riemman zeta function. Defines complex value for which the Riemann zetao function is to be calculated. Defines used number of terms used in complex series approximation of Riemann zeta function. The Riemann zeta-function is the function of a complex variable z initially defined by the following infinite series: , for values of z with real part greater than one, and then analytically continued to all complex z <> 1. The zeta-function satisfies the following functional equation: , valid for all complex numbers z. Zeta function is related to Dirichlet Lambda and Eta functions by: *) function RiemannZeta(const Z: TCplx; n: Integer = 64 ): TCplx; overload; (*Lerch transcendent function. the an approximation to Lerch transcendent function. Estimates Lerch transcendent function. The Lerch transcendent function is defined as: *) function Lerch(const z: double; s: double; a: double): double; overload; (*Generalized harmonic number H(n,m). the Generalized harmonic number (n). The Generalized harmonic number is defined by the following equation: *) function GenHarmonic(n: Integer; m: double): double; overload; (*Harmonic number H(n). the Harmonic number H(n). *) function Harmonic(n: Integer): double; overload; (*Beta probability density function (PDF). the beta distribution probability density function (PDF). Function domain, real positive value on closed interval [0,1]. Shape parameter, real positive value. Shape parameter, real positive value. Calculates the beta probability density function. The beta probability density function is defined by the following equation: where B(a,b) is function and it defines the interval on which the beta PDF is not zero. The beta distribution describes a family of curves that are nonzero only on the interval [0,1]. The parameters a and b must both be greater than zero and x must lie on the interval (0,1) otherwise the result is NAN. Calculate Beta distribution (a=3 and b= 2.1) PDF and CDF for x =0.55 using Dew.Probability; using Dew.Probability.Units; namespace Dew.Examples { void Example() { double pdf = BetaPDF(0.55, 3.0, 2.1); double cdf = BetaCDF(0.55, 3.0, 2.1); } } *) function BetaPDF(x, a, b: double): double; overload; (*Beta cumulative distribution function (CDF). the beta cumulative distribution function (CDF), which the probability that a single observation from a beta distribution with parameters a and b will fall in the interval [0,x]. Function domain, real positive value on closed interval [0,1]. Shape parameter, real positive value. Shape parameter, real positive value. The beta cumulative distribution function is defined by the following equation: where B(a,b) is function. *) function BetaCDF(x, a, b: double): double; overload; (*Beta distribution point percent function (PPF). the Beta distribution point percent function (PPF) for given parameters a and b. Probability, real positive value on closed interval [0,1]. Shape parameter, real positive value. Shape parameter, real positive value. The inverse beta cumulative distribution function is defined by the following equation: where B(a,b) is function. *) function BetaCDFInv(p, a, b: double): double; overload; (*Bernoulli probability density function (PDF). the Bernoulli distribution probability density function (PDF). Function domain, integer, valid values 0 or 1. parameter, real positive value on closed intervali [0,1]. Calculates the Bernoulli probability distribution function. The Bernoulli probability density function is defined by the following equation: *) function BernoulliPDF(x: integer; p: double): double; overload; (*Bernoulli cumulative distribution function (CDF). Bernoulli cumulative distribution function (CDF). Function domain, integer, valid values 0 or 1. parameter, real positive value on closed intervali [0,1]. Calculates the Bernoulli czumulative density function. The Bernoulli probability density function is defined by the following equation: *) function BernoulliCDF(x: integer; p: double): double; overload; (*Bernoulli distribution point percent function (PPF). the Bernoulli distribution point percent function (PPF) Probability, real positive value on closed interval [0,1]. parameter, real positive value on closed intervali [0,1]. *) function BernoulliCDFInv(y: double; p: double): double; overload; (*Binomial probability density function (PDF). the binomial probability density function (PDF). Function domain, integer, valid on closed interval [0,n]. Defines number of trials. n must be a positive integer. Defines success probability. p must lie on the [0,1] closed interval. Calculates the binomial probability density function. The binomial probability density function is defined by the following equation: where q=1-p and I is the discrete interval [0,1,...n] on which the binomial CDF is not zero. The result of BinomPDF is the probability of observing x successes in n independent trials and where the probability of success in any given trial is p. To recognize a situation that involves a binomial random variable, following assumptions must be met: * The experiment consists of a fixed number, n, of Bernoulli trials that result in either success or failure. * The trials are identical and independent and therefore the probability of success p, remains the same from trial to trial. * The random variable x denotes the number of successes obtained in the n trials. *) function BinomPDF(x: Integer; N: integer; p: double): double; overload; (*Binomial cumulative distribution function (CDF). the binomial cumulative distribution function (CDF). Function domain, integer, valid on closed interval [0,n]. Defines number of trials. n must be a positive integer. Defines success probability. p must lie on the [0,1] closed interval. The binomial cumulative distribution function is defined by the following equation: where q=1-p and I is the discrete interval [0,1,...n] on which the binomial CDF is not zero. The result of BinomCDF is the probability of observing up to x successes in n independent trials and where the probability of success in any given trial is p. *) function BinomCDF(x: Integer; N: integer; p: double): double; overload; (*Binomial distribution point percent function (PPF). the binomial distribution point percent function (PPF). Probability, real positive value on closed interval [0,1]. Defines number of trials. n must be a positive integer. Defines success probability. p must lie on the [0,1] closed interval. The result of BinomCDFInv is the smallest integer such that the binomial cdf evaluated at the result is equal to or exceeds y. The y is the probability of observing result successes in n independent trials where p is the probability of success in each trial. *) function BinomCDFInv(y: double; N: integer; p: double): double; overload; (*Bose-Einstein probability density function (PDF). Bose-Einstein probability density function (PDF). Function domain, real value. Location parameter, real value. Shape parameter, real positive value. Calculates the Bose-Einstein PDF for x using the parameters a and s. The distribution arises in the study of integer spin particles in physics. Integer spin particles are described by Bose-Einstein statistics and are called BOSONS. Bose-Einstein PDF is defined by the following equation: *) function BoseEinsteinPDF(x: double; Mu, s: double): double; overload; (*Bose-Einstein cumulative distribution function (CDF). Bose-Einstein cumulative distribution function (CDF). Function domain, real value. Location parameter, real value. Shape parameter, real positive value. The distribution arises in the study of integer spin particles in physics.*) function BoseEinsteinCDF(x: double; Mu,s: double): double; overload; (*Cauchy probability density function (PDF). the Cauchy probability density function (PDF) for given parameters b and m. Parameter b must be greater than zero, otherwise the result is NAN. Function domain, real value. Location parameter, real value. Shape parameter, real positive value. Calculates the Cauchy probability density function. The Cauchy probability density function is defined by the following equation: where m is the location parameter, specifying the location of the peak of the distribution, and b is the scale parameter which specifies the half-width at half-maximum (HWHM). As a probability distribution, it is known as the Cauchy distribution while among physicists it is known as the Lorentz distribution or the Breit-Wigner distribution. *) function CauchyPDF(x, m, b: double): double; overload; (*Cauchy cumulative distribution function (CDF). the Cauchy cumulative distribution function (CDF) Function domain, real value. Location parameter, real value. Shape parameter, real positive value. The Cauchy cumulative distribution function is defined by the following equation: *) function CauchyCDF(x,m,b: double): double; overload; (*Cauchy distribution point percent function (PPF). the Cauchy distribution point percent function (PPF) for given parameters b and m. Probability, real positive value on closed interval [0,1]. Location parameter, real value. Shape parameter, real positive value. The inverse Cauchy cumulative distribution function is defined by the following equation: The result of CauchyCDFInv is the solution of the integral equation of the Cauchy CDF with parameters b and m and with the desired probability p. *) function CauchyCDFInv(p,m,b: double): double; overload; (*Chi-squared probability density Function (PDF). the Chi-squared probability density Function (PDF). Function domain, real positive value. Defines distribution degrees of freedom. Nu must be a positive integer value. Calculates the Chi-Squared probability density function, defined by the following equation: where n (Nu) is the degrees of freedom and G is function. One of the most important classes of quadratic functions in sampling theory is the class of functions reducible to sums of squares of Nu independent standard normals. This function is called a chi-squared function with Nu degrees of freedom. A chi-squared random variable is completely specified by stating its degrees of freedom Nu. The chi-squared distribution is just a special case of distribution (for gamma distribution parameter b=2). *) function ChiSquarePDF(x: double; Nu: Integer): double; overload; (*Chi-squared cumulative distribution Function (CDF). the chi-squared cumulative distribution Function (CDF). The parameter Nu (degrees of freedom) must be a positive integer, otherwise the result is NAN. Function domain, real positive value. Defines distribution degrees of freedom. Nu must be a positive integer value. The chi-squared cumulative distribution function is defined by the following equation: where n (Nu) is the degrees of freedom and G is gamma function. The result of ChiSquareCDF is the probability that a single observation from the chi-squared distribution with Nu degrees of freedom will fall in the interval [0,x]. *) function ChiSquareCDF(x: double; Nu: Integer): double; overload; (*Chi-squared distribution point percent function (PPF). the Chi-squared distribution point percent function (PPF). The parameter Nu (degrees of freedom) must be a positive integer and the probability y must lie on the interval [0,1], otherwise the result is NAN. The Chi-squared PPF is defined by the following equation: *) function ChiSquareCDFInv(p: double; Nu: Integer): double; overload; (*Erlang probability density function (PDF). the Erlang probability density function (PDF) for integer parameter k and double parameter Lambda at the value x. Parameters k and Lambda must both be greater than zero. Function domain, real positive value or zero. Defines distribution shape parameter. k must be a positive integer. Defines distribution rate parameter. Lambda must be a positive value. The Erlang probability distribution function (PDF) is defined by the following relation: The Erlang distribution is a continuous distribution, which has a positive value for all real numbers greater than zero, and is given by two parameters: the shape k, which is an integer, and the rate Lambda, which is a real. The distribution is sometimes defined using the inverse of the rate parameter, the scale phi. When the shape parameter k equals 1, the distribution simplifies to the exponential distribution. The Erlang distribution is a special case of the Gamma distribution where the shape parameter k is an integer. In the Gamma distribution, this parameter is a real. *) function ErlangPDF(x:double; k: Integer; Lambda: double): double; overload; (*Erlang distribution cumulative distribution function (CDF). the Erlang cumulative distribution function (CDF) for parameters k and Lambda, evaluated at x. Function domain, real positive value or zero. Defines distribution shape parameter. k must be a positive integer. Defines distribution rate parameter. Lambda must be a positive value. Calculates the Erlang cumulative distribution function, defined by the following relation: *) function ErlangCDF(x:double; k: Integer; Lambda: double): double; overload; (*Erlang distribution point percent function (PPF). the Erlang distribution point percent function (PPF). Both parameters k and Lambda must be positive, otherwise the result is NAN. Probability, real positive value on closed interval [0,1]. Defines distribution shape parameter. k must be a positive integer. Defines distribution rate parameter. Lambda must be a positive value. The inverse of the Erlang cumulative distribution function is defined by the following equation: *) function ErlangCDFInv(p:double; k: Integer; Lambda: double): double; overload; (*Exponential probability density function (PDF). the exponent probability density function (PDF) for parameter Mu at the value x. Parameter Mu must be greater than zero, otherwise the result is NAN. Function domain, real positive value or zero. Defines distribution rate parameter. Mu must be a positive scalar. Calculates the exponential probability density function, defined by the equation: The exponential distribution arises often in practice with conjunction with the study of Poisson processes. In a Poisson process discrete events are being observed over a continuous time interval. If we let W denote the time of the occurrence of the first event, then W has and exponential distribution. *) function ExpPDF(x, Mu: double): double; overload; (*Exponential cumulative distribution function (CDF). the exponential cumulative distribution function (CDF) for parameter Mu at the value X. Parameter Mu must be greater than zero, otherwise the result is NAN. Function domain, real positive value or zero. Defines distribution rate parameter. Mu must be a positive scalar. The exponential cumulative distribution function s defined by the following equation: The result of ExpCDF is the probability that a single observation from an exponential distribution will fall in the interval [0,x]. *) function ExpCDF(x, Mu: double): double; overload; (*Exponential distribution point percent function (PPF). the exponential distribution point percent function (PPF). The parameter Mu must be a positive real value and the probability y must lie on the interval [0,1], otherwise the result is NAN. Probability, real positive value on closed interval [0,1]. Defines distribution rate parameter. Mu must be a positive real value. The inverse exponential cumulative distribution function is defined by the following equation: The result of ExpCDFInv is the value such that there is a probability p that an observation from an exponential distribution with parameter Mu will fall in the range [0,result]. *) function ExpCDFInv(p, Mu: double): double; overload; (*Fatigue life probability density function (PDF). the Fatigue life probability density function (PDF)evaluated at x using the parameters gamma, Mu and beta. Gamma and beta must be positive real numners and x>Mu, otherwise an exception is raised. Distribution domain, real value on open interval (Mu,INF). Defines distribution location parameter. Defines distribution shape parameter. gamma must be a positive scalar. Defines distribution scale parameter. beta must be a positive scalar. Calculates the "Fatigue life" probability density function, defined by the equation: The fatigue life distribution is also commonly known as the Birnbaum-Saunders distribution. Please note that there are several alternative formulations of the fatigue life distribution in the literature. *) function FatigueLifePDF(x: double; Mu, gamma, beta: double): double; overload; (*Fatigue life cumulative distribution function (CDF). the Fatigue life CDF, evaluated at x using positive scalar parameters Mu, gamma and beta. Distribution domain, real value on open interval (Mu,INF). Defines distribution location parameter. Defines distribution shape parameter. gamma must be a positive scalar. Defines distribution scale parameter. beta must be a positive scalar. The Fatigue CDF is defined by the following equation: where gamma>0, beta>0. *) function FatigueLifeCDF(x: double; Mu, gamma, beta: double): double; overload; (*Fatigue life distribution point percent function (PPF). the "fatigue life" distribution point percent function (PPF). Parameters gamma and beta must be positive and the probability p must lie on the interval [0,1], otherwise the result is NAN. Probability, real positive value on closed interval [0,1]. Defines distribution location parameter. Defines distribution shape parameter. gamma must be a positive scalar. Defines distribution scale parameter. beta must be a positive scalar. The inverse Fatigue life cumulative distribution function is defined by the following equation: The result is the value such that there is a probability p that an observation from an Fatigue life distribution with parameters Mu, gamma and beta will fall in the range [0 result]. *) function FatigueLifeCDFInv(p: double; Mu, gamma, beta: double): double; overload; (*F probability density function (PDF). the F probability density function (PDF) for integer parameters Nu1 and Nu2 (degrees of freedom) at the value x. Both Nu1 and Nu2 must be positive integer numbers, otherwise the result is NAN. Distribution domain, real positive value or zero. Defines distribution degrees of freedom. Nu1 must be a positive integer. Defines distribution degrees of freedom. Nu2 must be a positive integer. Calculates the Fisher (F) probability density function, defined by the equation: where n1=Nu1 and n2=Nu2 are degrees of freedom, and G is the gamma function. The most widely applied of all statistical techniques, the analysis of variance, depends heavily on the comparison of mutually independent "sum of squares" which are proportional to the chi-squared variables. The F distribution can defined in terms of a chi-squared distribution. In particular, any F random variable can be written as the ration of two independent chi-squared random variables, each divided by their respective degrees of freedom. *) function FPDF(x: double; Nu1, Nu2: Integer): double; overload; (*F cumulative distribution function (CDF). the F cumulative distribution function (CDF) for integer parameters Nu1 and Nu2 at the value X. Both Nu1 and Nu2 must be positive integer numbers, otherwise the result is NAN. Distribution domain, real positive value or zero. Defines distribution degrees of freedom. Nu1 must be a positive integer. Defines distribution degrees of freedom. Nu2 must be a positive integer. The F cumulative distribution function is defined by the following equation: where n1=Nu1 and n2=Nu2 are degrees of freedom, and Gamma is the function. The result of FCDF is the probability that a single observation from an F distribution with parameters Nu1 and Nu2 will fall in the interval [0,x]. *) function FCDF(x: double; Nu1, Nu2: Integer): double; overload; (*F distribution point percent function (PPF). the Fisher(F) distribution point percent function (PPF) for integer parameters Nu1 and Nu2 (degrees of freedom) at the probability y. Both Nu1 and Nu2 must be positive integer numbers and the probability p must lie on the interval [0,1], otherwise the result is NAN. Probability, real positive value on closed interval [0,1]. Defines distribution degrees of freedom. Nu1 must be a positive integer. Defines distribution degrees of freedom. Nu2 must be a positive integer. The inverse F cumulative distribution function is defined by the following equation: *) function FCDFInv(p: double; Nu1, Nu2 : Integer): double; overload; (*Fermi-Dirac probability density function (PDF). Fermi-Dirac probability density function (PDF). Function domain, real value. Location parameter, real value. Shape parameter, real positive value. Calculates the Fermi-Dirac PDF for x using the parameters Mu and s. The distribution arises in the study of half-integer spin particles in physics. Half-integer spin particles are described by Fermi-Dirac statistics and are called FERMIONS. Fermi-Dirac PDF is defined by the following equation: *) function FermiDiracPDF(x: double; Mu, s: double): double; overload; (*Fermi-Dirac cumulative distribution function (CDF). Fermi-Dirac cumulative distribution function (CDF). Function domain, real value. Location parameter, real value. Shape parameter, real positive value. The distribution arises in the study of integer spin particles in physics.*) function FermiDiracCDF(x: double; Mu, s: double): double; overload; (*Gamma probability density function (PDF). the Gamma probability density function (PDF) for value x using the parameters a and b. Distribution domain, real positive value. Defines distribution scale parameter. a must be a positive scalar. Defines distribution shape parameter. b must be a positive scalar. Calculates the Gamma distribution probability density function, defined by the equation: where Gamma denotes the function. The Gamma distribution is especially important in that it allows us to define two families of random variables, the exponential and chi-squared, that are used extensively in applied statistics. Gamma probability density function can be useful in reliability models of lifetimes.The gamma distribution is more flexible than the exponential in that the probability of surviving an additional period may depend on age. *) function GammaPDF(x, a, b: double): double; overload; (*Gamma cumulative distribution function (CDF). the Gamma cumulative distribution function (CDF) for value x using the parameters a and b. Both parameters a and b must be positive, otherwise the result is NAN. Distribution domain, real positive value. Defines distribution scale parameter. a must be a positive scalar. Defines distribution shape parameter. b must be a positive scalar. The gamma cumulative distribution is defined by the following equation: where Gamma denotes the gamma function. The result is the probability that a single observation from a gamma distribution with parameters a and b will fall in the interval [0,x]. *) function GammaCDF(x, a, b: double): double; overload; (*Gamma distribution point percent function (PPF). the Gamma distribution point percent function (PPF) for probability y using the parameters a and b. Both parameters a and b must be positive, otherwise the result is NAN. Probability, real positive value on closed interval [0,1]. Defines distribution scale parameter. a must be a positive scalar. Defines distribution shape parameter. b must be a positive scalar. The inverse gamma cumulative distribution function is defined by the following equation: where Gamma denotes the function. *) function GammaCDFInv(p, a, b: double): double; overload; (*Generalized extreme value probability density function (PDF). the Generalized extreme value probability density function (PDF) for value x using the parameters k, Mu and sigma. Distribution domain, real value, valid if the relation k*(x-Mu)/sigma >-1 Defines distribution shape parameter, real value. Defines distribution location parameter, real value. Defines distribution scale parameter, positive real value. Calculates the Generalized extreme value distribution probability density function, defined by the equation: *) function GenExtValuePDF(x, k, Mu, sigma: double): double; overload; (*Generalized extreme value cumulative distribution function (CDF). the Generalized extreme value cumulative distribution function (CDF) for value x using the parameters k, Mu and sigma. Distribution domain, real value, valid if the relation k*(x-Mu)/sigma >-1 Defines distribution shape parameter, real value. Defines distribution location parameter, real value. Defines distribution scale parameter, positive real value. The Generalized Extreme Value distribution CDF is defined by the following equation: *) function GenExtValueCDF(x, k, Mu, sigma: double): double; overload; (*Generalized extreme value distribution point percent function (PPF). the Generalized extreme value distribution point percent function (PPF) for probability y using the parameters k, Mu and sigma. Probability, real positive value on closed interval [0,1]. Defines distribution shape parameter, real value. Defines distribution location parameter, real value. Defines distribution scale parameter, positive real value. *) function GenExtValueCDFInv(p, k, Mu, sigma: double): double; overload; (*Generalized Pareto probability density function (PDF). the Generalized Pareto probability density function (PDF) for value x using the parameters a and b. Both parameters k, Mu and sigma. Distribution domain, real value, if k >= 0 valid on open interval (Mu,Inf), if k < 0, valid if 0 <= (x-Mu)/sigma <= -1/k. Defines distribution shape parameter, real value. Defines distribution location parameter, real value. Defines distribution scale parameter, positive real value. Calculates the Generalized Pareto distribution probability density function, defined by the equation: *) function GenParetoPDF(x, k, Mu, sigma: double): double; overload; (*Generalized Pareto cumulative distribution function (CDF). the Generalized Pareto cumulative distribution function (CDF) for value x using the parameters k, Mu and sigma. Distribution domain, real value, if k >= 0 valid on open interval (Mu,Inf), if k < 0, valid if 0 <= (x-Mu)/sigma <= -1/k. Defines distribution shape parameter, real value. Defines distribution location parameter, real value. Defines distribution scale parameter, positive real value. Calculates the Generalized Pareto distribution CDF, defined by the equation: *) function GenParetoCDF(x, k, Mu, sigma: double): double; overload; (*Generalized Pareto distribution point percent function (PPF). the Generalized extreme value distribution point percent function (PPF) for probability y using the parameters k, Mu and sigma. Probability, real positive value on closed interval [0,1]. Defines distribution shape parameter, real value. Defines distribution location parameter, real value. Defines distribution scale parameter, positive real value. *) function GenParetoCDFInv(p, k, Mu, sigma: double): double; overload; (*Geometric probability density function (PDF). the geometric probability density function (PDF) for value x by using parameter p (probability). Function domain, positive integer. Defines success probability. p must lie on the [0,1] closed interval. Calculates the geometric distribution probability density function, defined by the following equation: where I is the discrete interval on which the geometric PDF is not zero. To recognize a situation that involves a geometrical random variable, following assumptions must be met: * The experiment consist of series of trials. The outcome of each trial can be classed either as success or a failure. A trial with this property is called a Bernoulli trial. * The trials are identical and independent in the sense that the outcome of one trial has no effect on the outcome of any other. The probability of success, p, remains the same from trial to trial. * The random variable x denotes the number of trials needed to obtain the first success. *) function GeometricPDF(x: Integer; p: double): double; overload; (*Geometric cumulative distribution function (CDF). The geometric cumulative distribution function (CDF) for value x by using parameter p (probability). Probability p must lie on the interval [0,1] and x must be greater or equal than zero, otherwise the result is NAN. Function domain, positive integer. Defines success probability. p must lie on the [0,1] closed interval. The geometric cumulative distribution function is defined by the following equation: The result of GeometricCDF is the probability of observing up to x trials before a success, when the probability of success in any given trial is p. *) function GeometricCDF(x: Integer; p: double): double; overload; (*Geometric distribution point percent function (PPF). the geometric distribution point percent function (PPF) for probability y by using parameter p (probability). Probability y and parameter p must lie on the interval [0,1], otherwise the result is NAN. Probability, real positive value on closed interval [0,1]. Defines success probability. p must lie on the [0,1] closed interval. The result of GeometricCDFInv is observing result successes in a row, each with independent success probability p, with probability y. *) function GeometricCDFInv(y: double; p: double): double; overload; (*Gumbel probability density function (PDF). the Gumbel probability density function (PDF) for value x by using parameters Mu and beta. Function domain, real value. Defines the location parameter. Defines the scale parameter, positive real value. Defines maximum or minimum Gumbel distrubution. If true, th routine calculates minimum Gumbel PDF If false, the routine calculates maximum Gumbel PDF. Calculates Gumbel (minimum or maximum) distribution probabilty density function, defined by the following equation: The Gumbel distribution is a special case of the Generalized Extreme Value distribution. It used in industry in QA/QC applications and in the environmental sciences to model extreme values associated with flooding and rainfall. The Gumbel distribution takes its name from Emil J. Gumbel. *) function GumbelPDF(x: double; Mu, beta: double; minimum: boolean): double; overload; (*Gumbel cumulative distribution function (CDF). the Gumbel cumulative distribution function (CDF) for value x by using parameters Mu and beta. Function domain, real value. Defines the location parameter. Defines the scale parameter, positive real value. Defines maximum or minimum Gumbel distrubution. If true, th routine calculates minimum Gumbel PDF If false, the routine calculates maximum Gumbel PDF. Gumbel cumulative distribution function is defined by the following equation: *) function GumbelCDF(x: double; Mu, beta: double; minimum: boolean): double; overload; (*Gumbel distribution point percent function (PPF). the Gumbel distribution point percent function (PPF) for probability p using the parameters Mu and beta. Parameter beta must be positive, otherwise the result is NAN. Probability, real positive value on closed interval [0,1]. Defines the location parameter. Defines the scale parameter, positive real value. Defines maximum or minimum Gumbel distrubution. If true, th routine calculates minimum Gumbel PDF If false, the routine calculates maximum Gumbel PDF. The inverse Gumbel cumulative distribution function is defined by the following equation: *) function GumbelCDFInv(p: double; Mu, beta: double; minimum: boolean): double; overload; (*Hypergeometric probability density function (PDF). the hypergeometric probability density function (PDF) for value x using the integer parameters M (total number of elements), K (number of elements with a certain trait) and N (number of samples). Distribution domain, integer on closed interval [0,N]. Defines total number of elements, valid values ae integers on closed interval [0,X]. Defines number of elements with certain traits, valid values are integers on closed interval [X,M]. Defines number of samples, valid values are integers on closed interval [X,M]. Calculates the hypergeometric distribution probability density function. The hypergeometric probability density function is defined by the following equation: where M is the total size of elements, K is the number of elements with desired trait and N is the number of samples drawn.The function returns the probability of drawing exactly x elements of a possible K in N drawings without replacement from group of M elements. Sampling from a finite population can be done in one of two ways. An item can be selected, examined, and returned to the population for possible reselection; or it can be selected, examined, and kept, thus preventing its reselection in subsequent draws. The former is called sampling with replacement, whereas the later is called sampling without replacement. Sampling with replacement guarantees that the draws are independent. In sampling without the replacement the draws are not independent. Thus if we sample without replacement, the random variable x, the number of successes in N draws, is no longer binomial. Rather, it follows a hypergeometric distribution. If the number of items sampled (N) is small relative to the number of objects from which the sample is drawn (M), then the distribution can be used to approximate hypergeometric probability. *) function HypGeometricPDF(x: Integer; M, K, N: Integer): double; overload; (*Hypergeometric cumulative distribution function (CDF). the hypergeometric cumulative distribution function (CDF) for value x using the integer parameters M (total number of elements), K (number of elements with a certain trait) and N (number of samples drawn). Value x must be greater of equal than zero, all the parameters M, K N must be greater or equal than zero, M >= N, M >= K, N >= X, K >= x. If not all of these conditions are met, the result is NAN. Distribution domain, integer on closed interval [0,N]. Defines total number of elements, valid values ae integers on closed interval [0,X]. Defines number of elements with certain traits, valid values are integers on closed interval [X,M]. Defines number of samples, valid values are integers on closed interval [X,M]. The hypergeometric cumulative distribution function is defined by the following equation: The result of HypGeometricCDF is the probability of drawing up to x elements of a possible K in N drawings without replacement from a group of M elements. *) function HypGeometricCDF(x: Integer; M, K, N: Integer): double; overload; (*Hypergeometric distribution point percent function (PPF). the hypergeometric distribution point percent function (PPF) for probability p using the integer parameters M (total number of elements), K (number of elements with a certain trait) and N (number of samples drawn). Probability, real positive value on closed interval [0,1]. Defines total number of elements, valid values ae integers on closed interval [0,X]. Defines number of elements with certain traits, valid values are integers on closed interval [X,M]. Defines number of samples, valid values are integers on closed interval [X,M]. The result is the least integer such that the hypergeometric CDF evaluated at result equals or exceeds p. *) function HypGeometricCDFInv(p: double; M, K, N: Integer): double; overload; (*Inverse Chi-Square probability distribution function (PDF). the inverse Chi-Squared distribution probability density function (PDF), evaluated at x for integer parameter Nu. Function domain, real value. Defines distribution degrees of freedom, positive integer. The inverse-chi-square distribution is the probability distribution of a random variable whose multiplicative inverse (reciprocal) has a chi-square distribution. It is also often defined as the distribution of a random variable whose reciprocal divided by its degrees of freedom is a chi-square distribution. That is, if x has the chi-square distribution with Nu degrees of freedom, then according to the first definition, 1/x has the inverse-chi-square distribution with Nzu degrees of freedom; while according to the second definition, Nu/x has the inverse-chi-square distribution with Nu degrees of freedom. This package uses first definition which yields the following relation: *) function InverseChiSquarePDF(x: double; Nu: Integer): double; overload; (*Inverse Chi-Square cumulative density function (CDF). the inverse Chi-Squared distribution cumulative distribution function (CDF), evaluated at x for integer parameter Nu. Function domain, real value. Defines distribution degrees of freedom, positive integer. *) function InverseChiSquareCDF(x: double; Nu: Integer): double; overload; (*Inverse Chi-Square Percent Point Function (PPF). the inverse Chi-Squared percent point function (PPF), evaluated for integer parameter Nu. Probability, real positive value on closed interval [0,1]. Defines distribution degrees of freedom, positive integer. *) function InverseChiSquareCDFInv(p: double; Nu: Integer): double; overload; (*Inverse Gaussian probability density function (PDF). the inverse Gaussian PDF for value x using parameters Mu and Lambda, where both Mu and Lambda are positive scalars. Function domain, positive real value. Defines distribution Mu parameter. Mu must be a positive scalar. Defines distribution Lambda parameter. Lambda must be a positive scalar. Calculates the inverse Gaussian distribution probability density function, defined by the following equation: where Mu>0 and Lambda>0. *) function InverseGaussianPDF(x: double; Mu, Lambda: double): double; overload; (*Inverse Gaussian cumulative distribution function (CDF). the inverse Gaussian CDF for value x using parameters Mu and Lambda, where both Mu and Lambda are positive scalars. Function domain, positive real value. Defines distribution Mu parameter. Mu must be a positive scalar. Defines distribution Lambda parameter. Lambda must be a positive scalar. Inverse Gaussian CDFis defined by the following equation: where Mu and Lambda are both positive real numbers. *) function InverseGaussianCDF(x: double; Mu, Lambda: double): double; overload; (*Inverse Gaussian distribution point percent function (PPF). the inverse Gaussian distribution point percent function (PPF) for probability p using the parameters Mu and Lambda. Probability p must lie on the interval [0,1] and Mu, Lambda must both be positive, otherwise the result is NAN. Probability, real positive value on closed interval [0,1]. Defines distribution Mu parameter. Mu must be a positive scalar. Defines distribution Lambda parameter. Lambda must be a positive scalar. The inverse CDF is defined by the following equation: *) function InverseGaussianCDFInv(p: double; Mu, Lambda: double): double; overload; (*Johnson bounded probability density function (PDF). Johnson bounded (SB) probability density function (PDF) for parameters gamma, delta, Lambda and xi. Function domain, real value on closed interval [xi,xi+Lambda]. Distribution shape parameter, real value. Distribution shape parameter, real positive value. Distribution scale parameter, real positive value. Distribution location parameter, real value. Calculates the Johnson bounded (SB) probability density function, defined by the following equation: *) function JohnsonSBPDF(x: double; gamma,delta,Lambda,xi: double): double; overload; (*Johnson bounded cumulative distribution function (CDF). Johnson bounded (SB) cumulative distribution function (CDF) for parameters gamma, delta, Lambda and xi. Function domain, real value on closed interval [xi,xi+Lambda]. Distribution shape parameter, real value. Distribution shape parameter, real positive value. Distribution scale parameter, real positive value. Distribution location parameter, real value. Calculates the Johnson bounded (SB) cumulative distribution function, defined by the following equation: *) function JohnsonSBCDF(x: double; gamma,delta,Lambda,xi: double): double; overload; (*Johnson bounded point percent function (PPF). Johnson distribution bounded (SB) point percent function (PPF). Probability, real positive value on closed interval [0,1]. Distribution shape parameter, real value. Distribution shape parameter, real positive value. Distribution scale parameter, real positive value. Distribution location parameter, real value. Calculates the Johnson bounded (SB) point percent function, defined by the following equation: *) function JohnsonSBCDFInv(p: double; gamma,delta,Lambda,xi: double): double; overload; (*Johnson unbounded probability density function (PDF). Johnson unbounded (SU) probability density function (PDF) for parameters gamma, delta, Lambda and xi. Function domain, real value. Distribution shape parameter, real value. Distribution shape parameter, real positive value. Distribution scale parameter, real positive value. Distribution location parameter, real value. Calculates the Johnson unbounded (SU) probability density function, defined by the following equation: *) function JohnsonUBPDF(x: double; gamma,delta,Lambda,xi: double): double; overload; (*Johnson unbounded cumulative distribution function (CDF). Johnson unbounded (SU) cumulative distribution function (CDF). Function domain, real value. Distribution shape parameter, real value. Distribution shape parameter, real positive value. Distribution scale parameter, real positive value. Distribution location parameter, real value. Johnson unbounded (SU) cumulative distribution function, defined by the following equation: *) function JohnsonUBCDF(x: double; gamma,delta,Lambda,xi: double): double; overload; (*Johnson unbounded point percent function (PPF). Johnson distribution unbounded (SU) point percent function (PPF). Probability, real positive value on closed interval [0,1]. Distribution shape parameter, real value. Distribution shape parameter, real positive value. Distribution scale parameter, real positive value. Distribution location parameter, real value. Calculates the Johnson unbounded (SU) point percent function, defined by the following equation: *) function JohnsonUBCDFInv(p: double; gamma,delta,Lambda,xi: double): double; overload; (*Laplace probability densify function (PDF). the Laplace probability density function (PDF) for value x using the parameters m and b. Function domain, real value. Distribution location parameter, real value. Distribution scale parameter, real positive value. Laplace PDF is defined by the following equation: *) function LaplacePDF(x : double; m, b: double) : double; overload; (*Laplace cumulative distribution function (CDF). the Laplace cumulative distribution function (CDF) for value x using the parameters m and b. Function domain, real value. Distribution location parameter, real value. Distribution scale parameter, real positive value. The result of LaplaceCDF is the probability that a single observation from a Laplace distribution with parameters m and b will fall in the interval [-infinity,x]. Laplace CDF is defined by the following equation: *) function LaplaceCDF(x : double; m, b: double) : double; overload; (*Laplace distribution point percent function (PPF). the Laplace distribution point percent function (PPF) for probability p using the parameters m, and b. Probability, real positive value on closed interval [0,1]. Distribution location parameter, real value. Distribution scale parameter, real positive value. Inverse CDF is defined by the following equation: *) function LaplaceCDFInv(p : double; m, b: double) : double; overload; (*Logarithmic probability densify function (PDF). the logarithmic probability density function (PDF) for value x using the parameter p. Function domain, positive integer. Distribution parameter, real value on open interval (0,1). Calculates the logarithmic distribution probability density function (PDF), defined by the following equation: *) function LogarithmicPDF(x: Integer; p: double): double; overload; (*Logarithmic cumulative distribution function (CDF). the logarithmic probability density function (PDF) for value x using the parameter p. Function domain, positive integer. Distribution parameter, real value on open interval (0,1). Calculates the logarithmic distribution cumulative distribution function (CDF), defined by the following equation: *) function LogarithmicCDF(x: Integer; p: double): double; overload; (*Logarithmic point percent function (PPF). the logarithmic point percent function (PPF) for probability y using the parameter p. Probability, real positive value on closed interval [0,1]. Distribution parameter, real value on open interval (0,1). *) function LogarithmicCDFInv(y: double; p: double): double; overload; (*Logistic probability densify function (PDF). the logistic probability density function(PDF) for value x using the parameters m and b. Function domain, real value. Distribution location parameter. Distribution scale parameter, real positive value. The logistic probability density function is defined by the following equation: m and b must both be positive, otherwise the result is NAN. *) function LogisticPDF(x : double; m, b: double) : double; overload; (*Logistic cumulative distribution function (CDF). the logistic cumulative distribution function (CDF) for value x using the parameters m and b. Both parameters must be positive, otherwise the result is NAN. Function domain, real value. Distribution location parameter, real value. Distribution scale parameter, real positive value. The logistic cumulative distribution function is defined by the following equation: The result of LogisticCDF is the probability that a single observation from a logistic distribution with parameters m and b will fall in the interval [-infinity,x]. *) function LogisticCDF(x, m, b: double): double; overload; (*Logistic distribution point percent function (PPF). the Logistic distribution point percent function (PPF) for probability p using the parameters m, and b. Probability p must lie on the interval [0,1] and m, b must both be positive, otherwise the result is NAN. Probability, real positive value on closed interval [0,1]. Distribution location parameter, real value. Distribution scale parameter, real positive value. The inverse logistic cumulative distribution is defined by the following equation: *) function LogisticCDFInv(p, m, b: double): double; overload; (*Log-normal probability densify function (PDF). the log-normal probability density function (PDF) for value x using the parameters Mu (mean value) and sigma (standard deviation). Sigma must be positive value, otherwise the result is NAN. Function domain, positive real value or zero. Distribution location parameter, real value. Distribution scale parameter, real positive value. Log-normal probability density function is defined by the following equation: *) function LogNormalPDF(x : double; Mu, sigma: double) : double; overload; (*Log-normal cumulative distribution function (CDF). the log-normal cumulative distribution function (CDF) for value x using the parameters Mu (mean value) and sigma (standard deviation). Sigma must be positive value, otherwise the result is NAN. Function domain, positive real value or zero. Distribution location parameter, real value. Distribution scale parameter, real positive value. Log-normal cumulative distribution function is defined by the following equation: *) function LogNormalCDF(x, Mu, sigma: double): double; overload; (*Log-normal distribution point percent function (PPF). the Log-normal distribution point percent function (PPF) for probability p using the parameters Mu (mean value) and sigma (standard deviation). Probability p must lie on the interval [0,1] and sigma must be positive value, otherwise the result is NAN. Probability, real positive value on closed interval [0,1]. Distribution location parameter, real value. Distribution scale parameter, real positive value. Inverse Log-normal CDF is defined by the following equation: *) function LogNormalCDFInv(p, Mu, sigma: double): double; overload; (*Log-Weibull probability densify function (PDF). the log-Weibull (aka Extreme value or Fisher-Tippett) probability density function (PDF) for value x using the parameters a and b. Function domain, real value. Distribution location parameter, real positive value. Distribution scale parameter, real positive value. Log-Weibull PDF is defined by the following equation: *) function LogWeibullPDF(x : double; a, b: double) : double; overload; (*Log-Weibull cumulative distribution function (CDF). the log-Weibull cumulative distribution function (CDF) for value x using the parameters a and and b. Function domain, real value. Distribution location parameter, real positive value. Distribution scale parameter, real positive value. Log-Weibull cumulative distribution function (CDF) is defined by the following equation: *) function LogWeibullCDF(x : double; a, b: double) : double; overload; (*Log-Weibull distribution point percent function (PPF). the Log-Weibull distribution point percent function (PPF) for probability p using the parameters a and b. Probability p must lie on the interval [0,1], otherwise the result is NAN. Probability, real positive value on closed interval [0,1]. Distribution location parameter, real positive value. Distribution scale parameter, real positive value. Inverse Log-Weibull CDF is defined by the following equation: *) function LogWeibullCDFInv(p : double; a, b: double) : double; overload; (*Maxwell probability density function (PDF). the Maxwell probability density function (PDF) for value x using the parameter a. Parameter a must be positive and value x >= 0 , otherwise the result is NAN. Function domain, zero or positive real value. Distribution parameter, positive real value. The Maxwell probability density function is defined by the following equation: *) function MaxwellPDF(x, a: double): double; overload; (*Maxwell cumulative distribution function (CDF). the Maxwell cumulative distribution function (CDF) for value x using the parameter a. Parameter a must be positive, value x >= 0 , otherwise the result is NAN. Function domain, zero or positive real value. Distribution parameter, positive real value. Maxwell cumulative distribution is defined by the following equation: where is incomplete Gamma function. The result of MaxwellCDF is the probability that a single observation from a Maxwell distribution with parameter a will fall in the interval [0,x]. *) function MaxwellCDF(x, a: double): double; overload; (*Maxwell point percent function (PPF). the Maxwell distribution point percent function (PPF) for probabilty p using the parameter a. Parameter a must be positive and probabilty p must lie on the interval [0,1], otherwise the result is NAN. Probability, real positive value on closed interval [0,1]. Distribution parameter, positive real value. Inverse Maxwell cumulative distribution is defined by the following equation: The result of MaxwellCDFInv is the solution of the integral equation of the with parameter a and with the desired probability p. *) function MaxwellCDFInv(p, a: double): double; overload; (*Negative binomial probability density function (PDF). the negative binomial probability density function (PDF) for value x using the parameters R (number of success) and p (probability of success). Probability p must lie on the interval [0,1] and R must be greater or equal than one, otherwise the result is NAN. Function domain, integer, number of trials needed to obtain R successes. Defines number of successes, positive integer. Defines probability of each trial, real value on closed interval [0,1]. The negative binomial probability density function is defined by the following equation: where I is the discrete interval on which the negative binomial PDF is not zero. The negative binomial distribution can be thought of as a "reversal" of the binomial distribution. In the binomial setting the random variable represents the number of successes obtained in a series on n independent and identical Bernoulli trials: the number of trials is fixed and the number of successes will vary from experiment to experiment. The negative binomial random variable represents the number of trials needed to obtain exactly R successes; here, the number of successes is fixed and the number of trials will vary from experiment to experiment. In particular, the negative binomial random variable arises in situations characterized by these properties: * The experiment consists of a series of independent and identical Bernoulli trials, each with probability p of success. * The trials are observed until exactly R successes are obtained, where R is fixed by the experimentator. * The random variable x is the number of trials needed to obtain the R successes. *) function NegBinomPDF(x: Integer; R: double; p: double): double; overload ; (*Negative binomial cumulative distribution function (CDF). the negative binomial cumulative distribution function (CDF) for value x using the parameters R (number of success) and p (probability of success). Probability p must lie on the interval [0,1], x must be greater or equal than zero and R must be greater or equal than one, otherwise the result is NAN. Function domain, integer, nzmber of trials needed to obtain R successes. Defines number of successes, positive integer. Defines probability of each trial, real value on closed interval [0,1]. The negative binomial cumulative distribution function is defined by the following equation: where I is the interval on which the negative binomial cumulative distribution function is not zero. *) function NegBinomCDF(x: Integer; R: double; p: double): double; overload; (*Negative binomial distribution point percent function (PPF). the Negative binomial distribution point percent function (PPF) for probability y using the parameters R (number of success) and p (probability of success). Probabilities p and y must lie on the interval [0,1], and R must be greater or equal than one, otherwise the result is NAN. Probability, real positive value on closed interval [0,1]. Defines number of successes, positive integer. Defines probability of each trial, real value on closed interval [0,1]. The result of NegBinomCDFinv is the smallest integer such that the negative binomial CDF evaluated at result equals or exceeds y. If the function returns NAN, either one of the inputs was NAN, or total loss of precision was detected. *) function NegBinomCDFInv(y: double; R: double; p: double): double; overload; (*Normal probability density function (PDF). the normal probability density function (PDF) for value x using the parameters Mu (mean value) and sigma (standard deviation). Sigma must be positive value, otherwise the result is NAN. Function domain, real value. Distribution location parameter, real value. Distribution scale parameter, real positive value. The normal probability density function is defined by the following equation: where Mu is mean value and sigma is standard deviation. Special case of normal distribution (mean = 0, sigma =1) is called standard normal distribution. The normal distribution is a distribution that underlies many of the statistical methods used in data analysis. This distribution is often referred to as "Gaussian" distribution. Normal distribution can be used for modeling when the sample size is large. The theoretical justification can be found in Central Limit Theorem which states (roughly) that the sum of independent samples from any distribution with finite mean and variance converges to the normal distribution as the sample size goes to infinity. *) function NormalPDF(x: double; Mu, sigma: double): double; overload; (*Normal cumulative distribution function (CDF). the normal cumulative distribution function (CDF) for value x using the parameters Mu (mean value) and sigma (standard deviation). Sigma must be positive value, otherwise the result is NAN. Function domain, real value. Distribution location parameter, real value. Distribution scale parameter, real positive value. The normal cumulative distribution function is defined by the following equation: where Mu is mean value and sigma is standard deviation. The result of NormalCDF is the probability that a single observation from a normal distribution with parameters Mu and sigma will fall in the interval (-infinity,x]. *) function NormalCDF(x, Mu, sigma: double): double; overload; (*Normal distribution point percent function (PPF). the normal distribution point percent function (PPF) for probability p using the parameters Mu (mean value) and sigma (standard deviation). Probability p must lie on the interval [0,1] and sigma must be positive value, otherwise the result is NAN. Probability, real positive value on closed interval [0,1]. Distribution location parameter, real value. Distribution scale parameter, real positive value. The normal distribution point percent function is defined by the following equation: where Mu is mean value and sigmsa is standard deviation. The result of NormalCDFInv is the solution of the integral equation above with the parameters Mu and sigma where you supply the probability p. *) function NormalCDFInv(p, Mu, sigma: double): double; overload; (*Pareto probability density function (PDF). the Pareto probability density function (PDF) for value x using the parameters a and b. Parameter b must be smaller than value x , otherwise the result is NAN. Function domain. Distribution scale parameter, real positive value. Distribution shape parameter, real positive value, smaller than x. The Pareto probability density function is defined by the following equation: *) function ParetoPDF(x, a, b: double): double; overload; (*Pareto cumulative distribution function (CDF). the Pareto cumulative distribution function (CDF) for value x using the parameters a and b. Parameter b must be smaller than value x , otherwise the result is NAN. Function domain Distribution scale parameter, real positive value. Distribution shape parameter, real positive value, smaller than x. The Pareto cumulative distribution function is defined by the following equation: *) function ParetoCDF(x, a, b: double): double; overload; (*Pareto distribution point percent function (PPF). the Pareto distribution point percent function (PPF) for probability p using the parameters a and b. Probability p must lie on the interval [0,1], otherwise the result is NAN. Probability, real positive value on closed interval [0,1]. Distribution scale parameter, real positive value. Distribution shape parameter, real positive value, smaller than x. The inverse Pareto cumulative distribution function is defined by the following equation: *) function ParetoCDFInv(p, a, b: double): double; overload; (*Poisson probability density function (PDF). the Poisson probability density function (PDF) for value x using the parameter Lambda. Lambda must be positive, otherwise the result is NAN. Function domain, positive integer or zero. Distribution parameter, real positive value. The Poisson probability density function is defined by the following equation: Poisson random variable usually arise in connection with what are called Poisson processes. Poisson process involve observing discrete events in a continuous interval of time, length or space. The variable of interest in a Poisson process is the number of occurrences of the event in an interval of length. Basically, the result is physically, the parameter Lambda of a Poisson process represents the average number of occurrences of the event in question per measurement unit. One other important application of the Poisson distribution is approximating the distribution with the Poisson distribution. This approximation is usually good if n >= 20 and p <= 0.05 (binomial distribution parameters) and very good if n >= 100 and np <= 10. Since the approximation is used when number of events (n) is large and p (probability of success) is small, the Poisson distribution is often called the distribution of "rare" events. *) function PoissonPDF(x: Integer; Lambda: double): double; overload; (*Poisson cumulative distribution function (CDF). the Poisson cumulative distribution function (CDF) for value x using the parameter Lambda. Lambda must be positive, otherwise the result is NAN. Function domain, positive integer or zero. Distribution parameter, real positive value. The Poisson cumulative distribution function is defined by the following equation: *) function PoissonCDF(x: integer; Lambda: double): double; overload; (*Poisson distribution point percent function (PPF). the Poisson distribution point percent function (PPF) for probability p using the parameter Lambda. Lambda must be positive and probability y must lie on the interval [0,1], otherwise the result is NAN. Probability, real value on closed interval [0,1]. Distribution parameter, real positive value. *) function PoissonCDFInv(p: double; Lambda: double): double; overload; (*Power probability distribution function (PDF). Power distribution PDF, evaluated at x using parameters alpha and beta. Alpha, beta parameters must be positive and 0 <= x <= 1/beta, otherwise the result is NAN. Function domain, real on closed interval [0,1/beta] Distribution shape parameter, real positive value.. Distribution scale parameter, positive real number. Power probability distribution function is defined by the following equation: where alpha, beta are both positive scalars and 0 <= x <= 1/beta. *) function PowerPDF(x: double; alpha, beta: double): double; overload; (*ower cumulative density function (CDF). Power distribution CDF, evaluated at x using parameters alpha and beta. Alpha, beta parameters must be positive and 0 <= x <= 1/beta, otherwise the result is NAN. Function domain, real on closed interval [0,1/beta] Distribution shape parameter, real positive value.. Distribution scale parameter, positive real number. Power probability distribution function is defined by the following equation: where alpha, beta are both positive scalars and 0 <= x <= 1/beta. *) function PowerCDF(x: double; alpha, beta: double): double; overload; (*Power distribution point percent function (PPF). the Power distribution point percent function (PPF) for probability p using the parameters alpha and beta. Probability p must lie on the interval [0,1], and alpha, beta must be positive scalars, otherwise the result is NAN. Probability, real positive value on closed interval [0,1]. Distribution shape parameter, real positive value.. Distribution scale parameter, positive real number. The inverse Pareto cumulative distribution function is defined by the following equation: *) function PowerCDFInv(p: double; alpha, beta: double): double; overload; (*Rayleigh probability density function (PDF). the Rayleigh probability density function (PDF) for value x using the parameter b. Parameter b must be positive and value x must be >= 0, otherwise the result is NAN. Function domain, positive real value or zero. Distribution parameter, positive real value. The Rayleigh probabilty density function is defined by the following equation: *) function RayleighPDF(x, b: double): double; overload; (*Rayleigh cumulative distribution function (CDF). the Rayleigh cumulative distribution function (CDF) for value x using the parameter b. x and b must both be positive real numbers, otherwise the result is NAN. Function domain, positive real value or zero. Distribution parameter, positive real value. The Rayleigh cumulative distribution function is defined by the following equation: *) function RayleighCDF(x, b: double): double; overload; (*Rayleigh distribution point percent function (PPF). the Rayleigh distribution point percent function (PPF) for probabilty p using the parameter b. Parameter b must be positive and probabilty p must lie on the interval [0,1], otherwise the result is NAN. Probability, real positive value on closed interval [0,1]. Distribution parameter, positive real value. The inverse Rayleigh cumulative distribution function is defined by the following equation: The result of RayleighCDFInv is the solution of the integral equation of the with parameter b and with the desired probability p. *) function RayleighCDFInv(p, b: double): double; overload; (*Student probability density function (PDF). the Student probability density function for value x using the integer parameter Nu (degrees of freedom). Parameter Nu must be positive integer number, otherwise the result is NAN. Function domain, real value. Defines distribution degrees of freedom, positive integer. The Student probability density function is defined by the following equation: The Student (or T) distribution describes family of curves that depend on a single parameter Nu (degrees of freedom). If a random variable follows a Student distribution, then it must be written as a ratio of a standard normal random variable to the square root of an independent chi-squared random variable, divided by its degrees of freedom. As Nu goes towards infinity, the Student distribution approaches the standard normal distribution. *) function StudentPDF(x :double; Nu: Integer): double; overload; (*Student cumulative distribution function (CDF). the Student cumulative distribution function for value x using the integer parameter Nu (degrees of freedom). Parameter Nu must be positive integer number, otherwise the result is NAN. Function domain, real value. Defines distribution degrees of freedom, positive integer. The Student cumulative distribution function is defined by the following equation: The result of StudentCDF is the probability that a single observation from the Student distribution with Nu degrees of freedom will fall in the interval (-infinity,x]. *) function StudentCDF(x :double; Nu: Integer): double; overload; (*Student distribution point percent function (PPF). the Student distribution point percent function (PPF) for probability p using the integer parameter Nu (degrees of freedom). Parameter Nu must be positive integer number and probability p must lie on the interval [0,1], otherwise the result is NAN. Probability, real positive value on closed interval [0,1]. Defines distribution degrees of freedom, positive integer. The inverse Student cumulative distribution function is defined by the following equation: The result of StudentCDFInv is the solution of the integral equation of the StudentCDF with parameter Nu where you must specify the probability p. *) function StudentCDFInv(p :double; Nu: Integer): double;overload; (*Triangular probability density function (PDF). the Triangular probability density function for parameters a, b and c. Distribution domain, real value on closed interval [a,b]. Distribution locagtion parameter, real value, smaller than parameter b. Distribution scale parameter, real value, greater than parameter a. Distribution shape parameter, real value on closed interval [a,b]. The triangular probability density function is defined by the following equation: where a is location, b scale and c shape parameter. The triangular distribution is a simple distribution that has no real source in nature. It is most, if not exclusively, useful for stochastic modeling rather than statistical analysis because of its artificial nature. In stochastic modeling, the triangular distribution is best used to model variables with both upper and lower bounds near the range of interest. The distribution does not need to be, and frequently is not, symmetric. *) function TriangularPDF(x: double; a,b,c: double): double; overload; (*Triangular cumulative distribution function (CDF). the triangular cumulative distribution function for value x using the parameters a,b,c. Distribution domain, real value on closed interval [a,b]. Distribution locagtion parameter, real value, smaller than parameter b. Distribution scale parameter, real value, greater than parameter a. Distribution shape parameter, real value on closed interval [a,b]. The triangular cumulative distribution function is defined by the following equation: The result of TriangularCDF is the probability that a single observation from the triangular distribution with location parameter a, scale parameter b and shape parameter c fall in the interval (a,x]. *) function TriangularCDF(x: double; a,b,c: double): double; overload; (*Triangular distribution point percent function (PPF). the Triangular distribution point percent function (PPF) for probability y using distribution parameters a,b,c. Probability, real positive value on closed interval [0,1]. Distribution locagtion parameter, real value, smaller than parameter b. Distribution scale parameter, real value, greater than parameter a. Distribution shape parameter, real value on closed interval [a,b]. The inverse triangular cumulative distribution function is defined by the following equation: The result of TriangularCDFInv is the solution of the integral equation of the TriangularCDF with parameters a,b,c where you must specify the probability p. *) function TriangularCDFInv(p: double; a,b,c: double): double; overload; (*Uniform probability density function (PDF). the uniform probability density function (PDF) for value x using the parameters a and b. The parameter a must be smaller than parameter b, otherwise the result is NAN. Distribution domain, real value on closed interval [a,b]. Distribution parameter, real value, defining distribution lower bound. Distribution parameter, real value, defining distribution upper bound. The uniform probability density function is defined by the following equation: where a and b define the interval on which uniform CDF is defined. Uniform distribution is perhaps the simplest distribution with which to work. It can be used do describe processes in which the events occur with equal or uniform probability. *) function UniformPDF(x: double; a, b: double): double; overload; (*Uniform cumulative distribution function (CDF). the uniform cumulative distribution function (CDF) for value x using the parameters a and b. The parameter a must be smaller than parameter b, otherwise the result is NAN. Distribution domain, real value on closed interval [a,b]. Distribution parameter, real value, defining distribution lower bound. Distribution parameter, real value, defining distribution upper bound. The uniform cumulative distribution function is defined by the following equation: where a and b define the interval on which uniform CDF is defined. *) function UniformCDF(x: double; a, b: double): double; overload; (*Uniform distribution point percent function (PPF). the Uniform distribution point percent function (PPF) for probability p using the parameters a and b. The parameter a must be smaller than parameter b and p must lie on the interval [0,1], otherwise the result is NAN. Probability, real positive value on closed interval [0,1]. Distribution parameter, real value, defining distribution lower bound. Distribution parameter, real value, defining distribution upper bound. The inverse uniform cumulative distribution function is defined by the following equation: where a and b define the interval on which uniform CDF is defined. *) function UniformCDFInv(p: double; a, b: double): double; overload; (*Discrete uniform probability density function (PDF). the discrete uniform probability density function (PDF) for value x using the parameter N. The parameter N must be greater than 0, otherwise the result is NAN. The discrete uniform distribution is a simple distribution that puts equal weights 1/N on the integers from 1 to N. *) function UniformDPDF(x: Integer; N: Integer): double; overload; (*Discrete uniform cumulative distribution function (CDF). the discrete uniform cumulative distribution function (CDF) for value x using the parameter N. The parameter N must be greater or equal to 1, otherwise the result is NAN. *) function UniformDCDF(x: Integer; N: Integer): double; overload; (*Discrete uniform distribution point percent function (PPF). the Discrete uniform distribution point percent function (PPF) for probability p using the parameter N. The probability p must lie on the interval (0,1] and parameter N must be greater than 1, otherwise the result is NAN. Probability, real positive value on closed interval [0,1]. Distribution parameter, real positive integer. *) function UniformDCDFInv(p: double; N: Integer): double; overload; (*Weibull probability density function (PDF). the Weibull probability density function for value x using the parameters a and b. Parameters a and b must be positive numbers, otherwise the result is NAN. Function domain, zero or real positive value. Distribution scale parameter, real positive value. Distribution shape parameter, real positive value. Calculates the Weibull probability density function, defined by the following equation: where I is the interval on which the inverse Weibull CDF is not zero. The Weibull distribution has been found to be useful in a variety of physical applications. It arises in the study of reliability. Reliability studies are concentrated with accessing whether or not a system functions adequately under the conditions for which it was designed. *) function WeibullPDF(x: double; a,b :double): double; overload; (*Weibull cumulative distribution function (CDF). the Weibull cumulative distribution function for value x using the parameters a and b. Value x must be greater or equal than zero and parameters a and b must be positive numbers, otherwise the result is NAN. Function domain, zero or real positive value. Distribution scale parameter, real positive value. Distribution shape parameter, real positive value. The Weibull cumulative distribution function is defined by the following equation: where I is the interval on which the Weibull CDF is not zero. *) function WeibullCDF(x: double; a,b :double): double; overload; (*Weibull distribution point percent function (PPF). the Weibull distribution point percent function (PPF) for probability p using the parameters a and b. Probability p must lie on the interval [0,1] and parameters a and b must be positive numbers, otherwise the result is NAN. Probability, real positive value on closed interval [0,1]. Distribution scale parameter, real positive value. Distribution shape parameter, real positive value. The inverse Weibull cumulative distribution function is defined by the following equation: where I is the interval on which the inverse Weibull CDF is not zero. *) function WeibullCDFInv(p: double; a,b :double): double; overload; (*Zipf distribution probability density function (PDF). the Zipf distribution probability density function (PDF). Function domain, positive integer or zero [0,N]. Distribution parameter, real positive value. Distribution parameter, positive integer. Calculates the Zipf probability distribution function. The Zipf probability density function is defined by the following equation: where H(N,s) is a generalized Harmonic function, evaluated at parameters N,s and x,s respectively. *) function ZipfPDF(x: Integer; s: double; N: Integer): double; overload; (*Zipf distribution cumulative distribution function (CDF). the Zipf distribution cumulative distribution function (CDF). Function domain, positive integer or zero [0,N]. Distribution parameter, real positive value. Distribution parameter, positive integer. Calculates the Zipf cumulative density function. The Zipf probability density function is defined by the following equation: where H(N,s) is a generalized Harmonic function, evaluated at parameters N,s and N,s-1 respectively. *) function ZipfCDF(x: Integer; s: double; N: Integer): double; overload; (*Zipf distribution point percent function (PPF). Zipf distribution point percent function (PPF). Probability, real positive value on closed interval [0,1]. Distribution parameter, real positive value. Distribution parameter, positive integer. *) function ZipfCDFInv(p: double; s: double; N: Integer): double; overload; (*Inverse cumulative probability distribution for the Studentized Range distribution The cumulative probability or percentile range. Number of samples. Degrees of freedom. To obtain quantiles from the maximum normal range distribution (v = Inf), specify this param value bigger than 25000. If ci = 1, then the inverse cumulative probability function of the studentized range is returned. If ci > 1 (2), then the inverse distribution of the studentized maximum modulus is obtained. Note: The maximum allowed p value when v = 1, is 0.98. In general, the accuracy of the algorithm decreases as r increases, as v decreases and as p approaches 1. It is recommended to verify the result with the StudentRangeCDF function to ensure, that the value of the p parameter can again be recovered. References: [1] Based on Fortran program from statlib, http://lib.stat.cmu.edu, Algorithm AS 190 Appl. Statist. (1983) Vol.32, No. 2 Incorporates corrections from Appl. Statist. (1985) Vol.34 (1) [2] Ferreira, D., et al. "Quantiles from the Maximum Studentized Range Distribution." Biometric Brazilian Journal 25.1 (2007): 117-135. http://jaguar.fcav.unesp.br/RME/fasciculos/v25/v25_n1/A8_Daniel.pdf (See prange function) *) function StudentRangeCDFInv(const p: double; const r, v: integer; const ci: integer = 1): double; (*Cumulative probability distribution for the Studentized Range statistics. The probability at which to evaluate the function. Number of samples. Degrees of freedom. To obtain quantiles from the maximum normal range distribution (v = Inf), specify this param value bigger than 25000. If ci = 1, then the cumulative probability function of the studentized range is returned. If ci > 1 (2), then the distribution of the studentized maximum modulus is obtained. Note: The maximum allowed q value when v = 1, is 200. In general, the accuracy of the algorithm decreases as r increases, as v decreases and as p approaches 1. References: [1] Based on Fortran program from statlib, http://lib.stat.cmu.edu, Algorithm AS 190 Appl. Statist. (1983) Vol.32, No. 2 Incorporates corrections from Appl. Statist. (1985) Vol.34 (1) [2] Ferreira, D., et al. "Quantiles from the Maximum Studentized Range Distribution." Biometric Brazilian Journal 25.1 (2007): 117-135. http://jaguar.fcav.unesp.br/RME/fasciculos/v25/v25_n1/A8_Daniel.pdf (See qrange function) *) Function StudentRangeCDF(const q: double; const r, v: integer; const ci: integer = 1): double; (*Beta distribution statistic parameters. Returns distribution mean estimate. Returns distribution variance estimate. Returns distribution skewness estimate. Returns distribution kurtosis estimate. Shape parameter, real positive value. Shape parameter, real positive value. Calculates beta distribution mean, variance, skewness and kurtosis values using parameters a and b. *) procedure BetaStat(a, b: double; out AMean, AVariance, ASkewness, AKurtosis : double); overload; (*Bernoulli distribution statistic parameters. Returns distribution mean estimate. Returns distribution variance estimate. Returns distribution skewness estimate. Returns distribution kurtosis estimate. parameter, real positive value on closed intervali [0,1]. Calculates Bernoulli distribution mean, variance, skewness and kurtosis values using parameter p. *) procedure BernoulliStat(p: double; out AMean, AVariance, ASkewness, AKurtosis : double); overload; (*Binomial distribution statistic parameters. Returns distribution mean estimate. Returns distribution variance estimate. Returns distribution skewness estimate. Returns distribution kurtosis estimate. Defines number of trials. n must be a positive integer. Defines success probability. p must lie on the [0,1] closed interval. Calculates binomial distribution mean, variance, skewness and kurtosis values using parameters n and p. *) procedure BinomStat(n: Integer; p: double; out AMean, AVariance, ASkewness, AKurtosis : double); overload; (*Cauchy distribution statistic parameters. Returns distribution mean estimate. Returns distribution variance estimate. Returns distribution skewness estimate. Returns distribution kurtosis estimate. Shape parameter, real positive value. Location parameter, real value. Calculates Cauchy distribution mean, variance, skewness and kurtosis values using parameters b and m. *) procedure CauchyStat(b, m: double; out AMean, AVariance, ASkewness, AKurtosis: double); overload; (*Chi-squared distribution statistic parameters. Returns distribution mean estimate. Returns distribution variance estimate. Returns distribution skewness estimate. Returns distribution kurtosis estimate. Defines distribution degrees of freedom. Nu must be a positive integer value. Calculates Chi-Squared distribution mean, variance, skewness and kurtosis values using parameter Nu. *) procedure ChiSquareStat(Nu: Integer; out AMean, AVariance, ASkewness, AKurtosis : double); overload; (*Erlang distribution statistic parameters. Returns distribution mean estimate. Returns distribution variance estimate. Returns distribution skewness estimate. Returns distribution kurtosis estimate. Defines distribution shape parameter. k must be a positive integer. Defines distribution rate parameter. Lambda must be a positive value. Calculates Erlang distribution mean, variance, skewness and kurtosis values using parameters k and Lambda. *) procedure ErlangStat(k: Integer; Lambda: double; out AMean, AVariance, ASkewness, AKurtosis : double); overload; (*Exponential distribution statistic parameters. Returns distribution mean estimate. Returns distribution variance estimate. Returns distribution skewness estimate. Returns distribution kurtosis estimate. Defines distribution rate parameter. Mu must be a positive scalar. Calculates exponential distribution mean, variance, skewness and kurtosis values using parameter Mu. *) procedure ExponentStat(Mu: double; out AMean, AVariance, ASkewness, AKurtosis : double); overload; (*Fatigue life distribution statistic parameters. Returns distribution mean estimate. Returns distribution variance estimate. Returns distribution skewness estimate. Returns distribution kurtosis estimate. Defines distribution location parameter. Defines distribution shape parameter. gamma must be a positive scalar. Defines distribution scale parameter. beta must be a positive scalar. Calculates Fatigue life distribution mean, variance, skewness nd kurtosis values using parameters Mu, gamma and beta. *) procedure FatigueLifeStat(Mu, gamma, beta: double; out AMean, AVariance, ASkewness, AKurtosis : double); overload; (*F(Fisher) distribution statistic parameters. Returns distribution mean estimate. Returns distribution variance estimate. Returns distribution skewness estimate. Returns distribution kurtosis estimate. Defines distribution degrees of freedom. Nu1 must be a positive integer. Defines distribution degrees of freedom. Nu2 must be a positive integer. Calculates Fisher-F distribution mean, variance, skewness and kurtosis values using parameters Nu1 and Nu2. *) procedure FStat(Nu1, Nu2: Integer; out AMean, AVariance, ASkewness, AKurtosis : double); overload; (*Gamma distribution statistic parameters. Returns distribution mean estimate. Returns distribution variance estimate. Returns distribution skewness estimate. Returns distribution kurtosis estimate. Defines distribution scale parameter. A must be a positive scalar. Defines distribution shape parameter. B must be a positive scalar. Calculates Gamma distribution mean, variance, skewness and kurtosis values using parameters a and b. *) procedure GammaStat(A, B: double; out AMean, AVariance, ASkewness, AKurtosis : double); overload; (*Generalized Extreme value distribution statistic parameters. Returns distribution mean estimate. Returns distribution variance estimate. Returns distribution skewness estimate. Returns distribution kurtosis estimate. Defines distribution shape parameter, real value. Defines distribution location parameter, real value. Defines distribution scale parameter, positive real value. Calculates Generalized Extreme value distribution mean, variance, skewness and kurtosis values using parameters k, Mu and sigma. *) procedure GenExtValueStat(k, Mu, sigma: double; out AMean, AVariance, ASkewness, AKurtosis : double); overload; (*Generalized Pareto value distribution statistic parameters. Returns distribution mean estimate. Returns distribution variance estimate. Returns distribution skewness estimate. Returns distribution kurtosis estimate. Defines distribution shape parameter, real value. Defines distribution location parameter, real value. Defines distribution scale parameter, positive real value. Calculates Generalized Pareto distribution mean, variance, skewness and kurtosis values using parameters k, Mu and sigma. *) procedure GenParetoStat(k, Mu, sigma: double; out AMean, AVariance, ASkewness, AKurtosis : double); overload; (*Geometric distribution statistic parameters. Returns distribution mean estimate. Returns distribution variance estimate. Returns distribution skewness estimate. Returns distribution kurtosis estimate. Defines success probability. p must lie on the [0,1] closed interval. Calculates geometric distribution mean, variance, skewness and kurtosis values using parameter p. *) procedure GeometricStat(p: double; out AMean, AVariance, ASkewness, AKurtosis : double); overload; (*Gumbel distribution statistic parameters. Returns distribution mean estimate. Returns distribution variance estimate. Returns distribution skewness estimate. Returns distribution kurtosis estimate. Defines the location parameter. Defines the scale parameter, positive real value. Calculates Gumbel distribution mean, variance, skewness and kurtosis values using parameters Mu and beta. *) procedure GumbelStat(Mu, beta: double; out AMean, AVariance, ASkewness, AKurtosis : double); overload; (*Hypergeometric distribution statistic parameters. Returns distribution mean estimate. Returns distribution variance estimate. Returns distribution skewness estimate. Returns distribution kurtosis estimate. Defines total number of elements, valid values ae integers on closed interval [0,X]. Defines number of elements with certain traits, valid values are integers on closed interval [X,M]. Defines number of samples, valid values are integers on closed interval [X,M]. Calculates hypergeometric distribution mean, variance, skewness and kurtosis values using parameters M,K and N. *) procedure HypGeometricStat(M,K,N: Integer; out AMean, AVariance, ASkewness, AKurtosis: double); overload; (*Inverse Chi-squared distribution statistic parameters. Returns distribution mean estimate. Returns distribution variance estimate. Returns distribution skewness estimate. Returns distribution kurtosis estimate. Defines distribution degrees of freedom, positive integer. Calculates Inverse Chi-squared distribution mean, variance, skewness and kurtosis values using parameters Mu and Lambda. *) procedure InverseChiSquareStat(Nu: Integer; out AMean, AVariance, ASkewness, AKurtosis: double); overload; (*Inverse Gaussian distribution statistic parameters. Returns distribution mean estimate. Returns distribution variance estimate. Returns distribution skewness estimate. Returns distribution kurtosis estimate. Defines distribution Mu parameter. Mu must be a positive scalar. Defines distribution Lambda parameter. Lambda must be a positive scalar. Calculates Inverse Gaussian distribution mean, variance, skewness and kurtosis values using parameters Mu and Lambda. *) procedure InverseGaussianStat(Mu, Lambda: double; out AMean, AVariance, ASkewness, AKurtosis: double); overload; (*Johnson bounded (SB) distribution statistic parameters. Returns distribution mean estimate. Returns distribution variance estimate. Returns distribution skewness estimate. Returns distribution kurtosis estimate. Distribution shape parameter, real value. Distribution shape parameter, real positive value. Distribution scale parameter, real positive value. Distribution location parameter, real value. Calculates Johnson SB distribution mean, variance, skewness and kurtosis values using parameters gamma, delta, Lambda and xi. *) procedure JohnsonSBStat(gamma,delta,Lambda,xi: double; out AMean, AVariance, ASkewness, AKurtosis: double); overload; (*Johnson unbounded (SU) distribution statistic parameters. Returns distribution mean estimate. Returns distribution variance estimate. Returns distribution skewness estimate. Returns distribution kurtosis estimate. Distribution shape parameter, real value. Distribution shape parameter, real positive value. Distribution scale parameter, real positive value. Distribution location parameter, real value. Calculates Johnson SU distribution mean, variance, skewness and kurtosis values using parameters gamma, delta, Lambda and xi. *) procedure JohnsonUBStat(gamma,delta,Lambda,xi: double; out AMean, AVariance, ASkewness, AKurtosis: double); overload; (*Laplace distribution statistic parameters. Returns distribution mean estimate. Returns distribution variance estimate. Returns distribution skewness estimate. Returns distribution kurtosis estimate. Distribution location parameter, real value. Distribution scale parameter, real positive value. Calculates Laplace distribution mean, variance, skewness and kurtosis values using parameters m and b. *) procedure LaplaceStat(m,b: double; out AMean, AVariance, ASkewness, AKurtosis: double); overload; (*Logarithmic distribution statistic parameters. Returns distribution mean estimate. Returns distribution variance estimate. Returns distribution skewness estimate. Returns distribution kurtosis estimate. Distribution parameter, real value on open interval (0,1). Calculates logarithmic distribution mean, variance, skewness and kurtosis values using parameter p. *) procedure LogarithmicStat(p: double; out AMean, AVariance, ASkewness, AKurtosis: double); overload; (*Logistic distribution statistic parameters. Returns distribution mean estimate. Returns distribution variance estimate. Returns distribution skewness estimate. Returns distribution kurtosis estimate. Distribution location parameter, real value. Distribution scale parameter, real positive value. Calculates Logistic distribution mean, variance, skewness and kurtosis values using parameters m and b. *) procedure LogisticStat(m,b: double; out AMean, AVariance, ASkewness, AKurtosis: double); overload; (*Log-Normal distribution statistic parameters. Returns distribution mean estimate. Returns distribution variance estimate. Returns distribution skewness estimate. Returns distribution kurtosis estimate. Distribution location parameter, real value. Distribution scale parameter, real positive value. Calculates log-normal distribution mean, variance, skewness and kurtosis values using parameters Mu and sigma. *) procedure LogNormalStat(Mu,sigma: double; out AMean, AVariance, ASkewness, AKurtosis: double); overload; (*Log-Weibull distribution statistic parameters. Returns distribution mean estimate. Returns distribution variance estimate. Returns distribution skewness estimate. Returns distribution kurtosis estimate. Distribution location parameter, real positive value. Distribution scale parameter, real positive value. Calculates log-Weibull distribution mean, variance, skewness and kurtosis values using parameters a and b. *) procedure LogWeibullStat(a,b: double; out AMean, AVariance, ASkewness, AKurtosis: double); overload; (*Maxwell distribution statistic parameters. Returns distribution mean estimate. Returns distribution variance estimate. Returns distribution skewness estimate. Returns distribution kurtosis estimate. Distribution parameter, positive real value. Calculates negative binomial distribution mean, variance, skewness and kurtosis values using parameter a. *) procedure MaxwellStat(a: double; out AMean, AVariance, ASkewness, AKurtosis : double); overload; (*Negaive binomial distribution statistic parameters. Returns distribution mean estimate. Returns distribution variance estimate. Returns distribution skewness estimate. Returns distribution kurtosis estimate. Defines number of successes, positive integer. Defines probability of each trial, real value on closed interval [0,1]. Calculates negative binomial distribution mean, variance, skewness and kurtosis values using parameters R and p. *) procedure NegBinomStat(R: double; p: double; out AMean, AVariance, ASkewness, AKurtosis: double); overload; (*Normal distribution statistic parameters. Returns distribution mean estimate. Returns distribution variance estimate. Returns distribution skewness estimate. Returns distribution kurtosis estimate. Distribution location parameter, real value. Distribution scale parameter, real positive value. Calculates normal distribution mean, variance, skewness and kurtosis values using parameters Mu and sigma. *) procedure NormalStat(Mu, sigma: double; out AMean, AVariance, ASkewness, AKurtosis : double); overload; (*Pareto distribution statistic parameters. Returns distribution mean estimate. Returns distribution variance estimate. Returns distribution skewness estimate. Returns distribution kurtosis estimate. Distribution scale parameter, real positive value. Distribution shape parameter, real positive value, smaller than x. Calculates Pareto distribution mean, variance, skewness and kurtosis values using parameters a and b. *) procedure ParetoStat(a, b: double; out AMean, AVariance, ASkewness, AKurtosis: double); overload; (*Poisson distribution statistic parameters. Returns distribution mean estimate. Returns distribution variance estimate. Returns distribution skewness estimate. Returns distribution kurtosis estimate. Distribution parameter, real positive value. Calculates Poisson distribution mean, variance, skewness and kurtosis values using parameter Lambda. *) procedure PoissonStat(Lambda: double; out AMean, AVariance, ASkewness, AKurtosis: double); overload; (*Power distribution statistic parameters. Returns distribution mean estimate. Returns distribution variance estimate. Returns distribution skewness estimate. Returns distribution kurtosis estimate. Distribution shape parameter, real positive value. Distribution scale parameter, positive real number. Calculates Power distribution mean, variance, skewness and kurtosis values using parameters alpha and beta. *) procedure PowerStat(alpha, beta: double; out AMean, AVariance, ASkewness, AKurtosis: double); overload; (*Rayleigh distribution statistic parameters. Returns distribution mean estimate. Returns distribution variance estimate. Returns distribution skewness estimate. Returns distribution kurtosis estimate. Distribution parameter, positive real value. Calculates Rayleigh distribution mean, variance, skewness and kurtosis values using parameter b. *) procedure RayleighStat(b: double; out AMean, AVariance, ASkewness, AKurtosis: double); overload; (*Student(T) distribution statistic parameters. Returns distribution mean estimate. Returns distribution variance estimate. Returns distribution skewness estimate. Returns distribution kurtosis estimate. Defines distribution degrees of freedom, positive integer. Calculates Student-t distribution mean, variance, skewness and kurtosis values using parameter Nu. *) procedure StudentStat(Nu: Integer; out AMean, AVariance, ASkewness, AKurtosis: double); overload; (*Triangular distribution statistic parameters. Returns distribution mean estimate. Returns distribution variance estimate. Returns distribution skewness estimate. Returns distribution kurtosis estimate. Distribution locagtion parameter, real value, smaller than parameter b. Distribution scale parameter, real value, greater than parameter a. Distribution shape parameter, real value on closed interval [a,b]. Calculates triangular distribution mean, variance, skewness and kurtosis values using parameters a,b and c. *) procedure TriangularStat(a,b,c: double; out AMean, AVariance, ASkewness, AKurtosis: double); overload; (*Unniform distribution statistic parameters. Returns distribution mean estimate. Returns distribution variance estimate. Returns distribution skewness estimate. Returns distribution kurtosis estimate. Distribution parameter, real value, defining distribution lower bound. Distribution parameter, real value, defining distribution upper bound. Calculates uniform distribution mean, variance, skewness and kurtosis values using parameters a and b. *) procedure UniformStat(a, b: double; out AMean, AVariance, ASkewness, AKurtosis: double); overload; (*Discrete uniform distribution statistic parameters. Returns distribution mean estimate. Returns distribution variance estimate. Returns distribution skewness estimate. Returns distribution kurtosis estimate. Distribution parameter, positive integer. Calculates discrete uniform distribution mean, variance, skewness and kurtosis values using parameter N. *) procedure UniformDStat(N: Integer; out AMean, AVariance, ASkewness, AKurtosis: double); overload; (*Weibull distribution moment estimates. Returns distribution mean estimate. Returns distribution variance estimate. Returns distribution skewness estimate. Returns distribution kurtosis estimate. Distribution scale parameter, real positive value. Distribution shape parameter, real positive value.*) procedure WeibullStat(a, b: double; out AMean, AVariance, ASkewness, AKurtosis: double); overload; (*Zipf distribution moment estimates. Distribution parameter, real positive value. Distribution parameter, positive integer. Returns distribution mean estimate. Returns distribution variance estimate. Returns distribution skewness estimate. Returns distribution kurtosis estimate.*) procedure ZipfStat(s: double; N: Integer; out AMean, AVariance, ASkewness, AKurtosis: double); overload; (*Beta PDF (vectorized). Defines distribution domain, real vector or matrix with integer values on open interval (0,1). Distribution scale parameter, real positive value. Distribution shape parameter, real positive value. After calculation stores the PDF calculated from X, A and B. Length and Complex properties of Res are adjusted automatically to match Length and Complex properties of X.*) procedure BetaPDF(const X: TDenseMtxVec; A,B: double; const Res: TDenseMtxVec); overload; (*Beta CDF (vectorized). Defines distribution domain, real vector or matrix with integer values on open interval (0,1). Distribution scale parameter, real positive value. Distribution shape parameter, real positive value. After calculation stores the CDF calculated from X, A and B. Length and Complex properties of Res are adjusted automatically to match Length and Complex properties of X.*) procedure BetaCDF(const X: TDenseMtxVec; A, B: double; const Res: TDenseMtxVec); overload; (*Beta PPF (vectorized). Defines distribution probabilities, real vector or matrix with values within closed interval [0,1]. Distribution scale parameter, real positive value. Distribution shape parameter, real positive value. After calculation stores the PPF calculated from P, A and B. Length and Complex properties of Res are adjusted automatically to match Length and Complex properties of X.*) procedure BetaCDFInv(const P: TDenseMtxVec; A, B: double; const Res: TDenseMtxVec); overload; (*Binomial PDF (vectorized). Defines distribution domain, real vector or matrix with integer values on closec interval [0,n]. Defines number of trials. n must be a positive integer. Defines success probability. p must lie on the [0,1] closed interval. After calculation stores the PDF calculated using X, n and p. Length and Complex properties of Res are adjusted automatically to match Length and Complex properties of X.*) procedure BinomPDF(const X: TMtxVecInt; n: Integer; P: double; const Res: TDenseMtxVec ); overload; (*Binomial CDF (vectorized). Defines distribution domain, real vector or matrix with integer values on closec interval [0,n]. Defines number of trials. n must be a positive integer. Defines success probability. p must lie on the [0,1] closed interval. After calculation stores the CDF calculated using X, n and p. Length and Complex properties of Res are adjusted automatically to match Length and Complex properties of X.*) procedure BinomCDF(const X: TMtxVecInt; n: Integer; P: double; const Res: TDenseMtxVec ); overload; (*Binomial PPF (vectorized). Defines distribution probabilities, real vector or matrix with values within closed interval [0,1]. Defines number of trials. n must be a positive integer. Defines success probability. p must lie on the [0,1] closed interval. After calculation stores the PPF calculated from Y, n and p. Length and Complex properties of Res are adjusted automatically to match Length and Complex properties of X.*) procedure BinomCDFInv(const Y: TDenseMtxVec; n: integer; P: double; const Res: TDenseMtxVec); overload; (*Bose-Einstein PDF (vectorized).*) procedure BoseEinsteinPDF(const X: TDenseMtxVec; Mu, S: double; const Res: TDenseMtxVec); overload; (*Cauchy PDF (vectorized). Defines distribution domain, real vector or matrix. Location parameter, real value. Shape parameter, real positive value. After calculation stores the PDF calculated from X, m and b. Length and Complex properties of Res are adjusted automatically to match Length and Complex properties of X.*) procedure CauchyPDF(const X: TDenseMtxVec; m, b: double; const Res: TDenseMtxVec); overload; (*Cauchy CDF (vectorized). Defines distribution domain, real vector or matrix. Location parameter, real value. Shape parameter, real positive value. After calculation stores the CDF calculated from X, m and b. Length and Complex properties of Res are adjusted automatically to match Length and Complex properties of X.*) procedure CauchyCDF(const X: TDenseMtxVec; m, b: double; const Res: TDenseMtxVec); overload; (*Cauchy PPF (vectorized). Defines distribution probabilities, real vector or matrix with values within closed interval [0,1]. Location parameter, real value. Shape parameter, real positive value. After calculation stores the PPF calculated from P, m and b. Length and Complex properties of Res are adjusted automatically to match Length and Complex properties of X.*) procedure CauchyCDFInv(const P: TDenseMtxVec; m, b: double; const Res: TDenseMtxVec); overload; (*Chi-Squared PDF (vectorized). Defines distribution domain, real vector or matrix with positive values. Defines distribution degrees of freedom. Nu must be a positive integer value. After calculation stores the PDF calculated from X, m and b. Length and Complex properties of Res are adjusted automatically to match Length and Complex properties of X.*) procedure ChiSquarePDF(const X: TDenseMtxVec; Nu: Integer; const Res: TDenseMtxVec); overload; (*Chi-Squared CDF (vectorized). Defines distribution domain, real vector or matrix with positive values. Defines distribution degrees of freedom. Nu must be a positive integer value. After calculation stores the CDF calculated from X, m and b. Length and Complex properties of Res are adjusted automatically to match Length and Complex properties of X.*) procedure ChiSquareCDF(const X: TDenseMtxVec; Nu: Integer; const Res: TDenseMtxVec); overload; (*Chi-Squared PPF (vectorized). Defines distribution probabilities, real vector or matrix with values within closed interval [0,1]. Defines distribution degrees of freedom. Nu must be a positive integer value. After calculation stores the PPF calculated from P and Nu. Length and Complex properties of Res are adjusted automatically to match Length and Complex properties of X.*) procedure ChiSquareCDFInv(const P: TDenseMtxVec; Nu: Integer; const Res: TDenseMtxVec); overload; (*Erlang PDF (vectorized). Defines distribution domain, real vector or matrix with positive values or zero. Defines distribution shape parameter. k must be a positive integer. Defines distribution rate parameter. Lambda must be a positive value. After calculation stores the PDF calculated from X, k and Lambda. Length and Complex properties of Res are adjusted automatically to match Length and Complex properties of X.*) procedure ErlangPDF(const X: TDenseMtxVec; k: Integer; Lambda: double; const Res: TDenseMtxVec); overload; (*Erlang CDF (vectorized). Defines distribution domain, real vector or matrix with positive values or zero. Defines distribution shape parameter. k must be a positive integer. Defines distribution rate parameter. Lambda must be a positive value. After calculation stores the CDF calculated from X, k and Lambda. Length and Complex properties of Res are adjusted automatically to match Length and Complex properties of X.*) procedure ErlangCDF(const X: TDenseMtxVec; k: Integer; Lambda: double; const Res: TDenseMtxVec); overload; (*Erlang PPF (vectorized). Defines distribution probabilities, real vector or matrix with values within closed interval [0,1]. Defines distribution shape parameter. k must be a positive integer. Defines distribution rate parameter. Lambda must be a positive value. After calculation stores the PPF calculated from P, k and Lambda. Length and Complex properties of Res are adjusted automatically to match Length and Complex properties of P.*) procedure ErlangCDFInv(const P: TDenseMtxVec; k: Integer; Lambda: double; const Res: TDenseMtxVec); overload; (*Exponential PDF (vectorized). Defines distribution domain, real vector or matrix with positive values or zero. Defines distribution rate parameter. Mu must be a positive scalar. After calculation stores the PDF calculated from X and Mu. Length and Complex properties of Res are adjusted automatically to match Length and Complex properties of X.*) procedure ExpPDF(const X: TDenseMtxVec; Mu: double; const Res: TDenseMtxVec); overload; (*Exponential CDF (vectorized). Defines distribution domain, real vector or matrix with positive values or zero. Defines distribution rate parameter. Mu must be a positive scalar. After calculation stores the CDF calculated from X and Mu. Length and Complex properties of Res are adjusted automatically to match Length and Complex properties of X.*) procedure ExpCDF(const X: TDenseMtxVec; Mu: double; const Res: TDenseMtxVec); overload; (*Exponential PPF (vectorized). Defines distribution probabilities, real vector or matrix with values within closed interval [0,1]. Defines distribution rate parameter. Mu must be a positive scalar. After calculation stores the PPF calculated from P and Mu. Length and Complex properties of Res are adjusted automatically to match Length and Complex properties of P.*) procedure ExpCDFInv(const P: TDenseMtxVec; Mu: double; const Res: TDenseMtxVec); overload; (*Fatigue Life PDF (vectorized). Defines distribution domain, real vector or matrix with real values on open interval (Mu,INF). Defines distribution location parameter. Defines distribution shape parameter. gamma must be a positive scalar. Defines distribution scale parameter. beta must be a positive scalar. After calculation stores the PDF calculated from X, Mu, gamma and beta. Length and Complex properties of Res are adjusted automatically to match Length and Complex properties of X.*) procedure FatigueLifePDF(const X: TDenseMtxVec; Mu, gamma, beta: double; const Res: TDenseMtxVec); overload; (*Fatigue Life CDF (vectorized). Defines distribution domain, real vector or matrix with real values on open interval (Mu,INF). Defines distribution location parameter. Defines distribution shape parameter. gamma must be a positive scalar. Defines distribution scale parameter. beta must be a positive scalar. After calculation stores the CDF calculated from X, Mu, gamma and beta. Length and Complex properties of Res are adjusted automatically to match Length and Complex properties of X.*) procedure FatigueLifeCDF(const X: TDenseMtxVec; Mu, gamma, beta: double; const Res: TDenseMtxVec); overload; (*Fatigue Life PPF (vectorized). Defines distribution probabilities, real vector or matrix with values within closed interval [0,1]. Defines distribution location parameter. Defines distribution shape parameter. gamma must be a positive scalar. Defines distribution scale parameter. beta must be a positive scalar. After calculation stores the PPF calculated from P, m, gamma and beta. Length and Complex properties of Res are adjusted automatically to match Length and Complex properties of P.*) procedure FatigueLifeCDFInv(const P: TDenseMtxVec; Mu, gamma, beta: double; const Res: TDenseMtxVec); overload; (*Fisher(F) PDF (vectorized). Defines distribution domain, real vector or matrix with positive real values or zeros. Defines distribution degrees of freedom. Nu1 must be a positive integer. Defines distribution degrees of freedom. Nu2 must be a positive integer. After calculation stores the PDF calculated from X, Nu1 and Nu2. Length and Complex properties of Res are adjusted automatically to match Length and Complex properties of X.*) procedure FPDF(const X: TDenseMtxVec; Nu1, Nu2: Integer; const Res: TDenseMtxVec); overload; (*Fisher(F) CDF (vectorized). Defines distribution domain, real vector or matrix with positive real values or zeros. Defines distribution degrees of freedom. Nu1 must be a positive integer. Defines distribution degrees of freedom. Nu2 must be a positive integer. After calculation stores the CDF calculated from X, Nu1 and Nu2. Length and Complex properties of Res are adjusted automatically to match Length and Complex properties of X.*) procedure FCDF(const X: TDenseMtxVec; Nu1, Nu2: Integer; const Res: TDenseMtxVec); overload; (*Fisher(F) PPF (vectorized). Defines distribution probabilities, real vector or matrix with values within closed interval [0,1]. Defines distribution degrees of freedom. Nu1 must be a positive integer. Defines distribution degrees of freedom. Nu2 must be a positive integer. After calculation stores the PPF calculated from P, Nu1 and Nu2. Length and Complex properties of Res are adjusted automatically to match Length and Complex properties of P.*) procedure FCDFInv(p: double; const Nu1, Nu2 : TMtxVecInt; const Res: TDenseMtxVec); overload; procedure FCDFInv(const p: TDenseMtxVec; Nu1, Nu2: Integer; const Res: TDenseMtxVec); overload; (*Fermi-Dirac probability density function (PDF). Fermi-Dirac probability density function (PDF). Function domain, real value. Location parameter, real value. Shape parameter, real positive value. Contains result. Calculates the Fermi-Dirac PDF for x using the parameters Mu and s. The distribution arises in the study of half-integer spin particles in physics. Half-integer spin particles are described by Fermi-Dirac statistics and are called FERMIONS. Fermi-Dirac PDF is defined by the following equation: *) procedure FermiDiracPDF(const x: TDenseMtxVec; Mu, s: double; const y: TDenseMtxVec); overload; (*Fermi-Dirac cumulative distribution function (CDF). Fermi-Dirac cumulative distribution function (CDF). Function domain, real value. Location parameter, real value. Shape parameter, real positive value. Contains result. The distribution arises in the study of integer spin particles in physics.*) procedure FermiDiracCDF(const x: TDenseMtxVec; Mu, s: double; const y: TDenseMtxVec); overload; (*Gamma distribution PDF (vectorized). Defines distribution domain, real vector or matrix with real positive real values. Defines distribution scale parameter. A must be a positive scalar. Defines distribution shape parameter. B must be a positive scalar. After calculation stores the PDF calculated from X, a and b. Length and Complex properties of Res are adjusted automatically to match Length and Complex properties of X.*) procedure GammaPDF(const X: TDenseMtxVec; A, B : double; const Res: TDenseMtxVec); overload; (*Gamma distribution CDF (vectorized). Defines distribution domain, real vector or matrix with real positive real values. Defines distribution scale parameter. A must be a positive scalar. Defines distribution shape parameter. B must be a positive scalar. After calculation stores the CDF calculated from X, a and b. Length and Complex properties of Res are adjusted automatically to match Length and Complex properties of X.*) procedure GammaCDF(const X: TDenseMtxVec; A, B: double; const Res: TDenseMtxVec); overload; (*Gamma distribution PPF (vectorized). Defines distribution probabilities, real vector or matrix with values within closed interval [0,1]. Defines distribution scale parameter. A must be a positive scalar. Defines distribution shape parameter. B must be a positive scalar. After calculation stores the PPF calculated from P, A and B. Length and Complex properties of Res are adjusted automatically to match Length and Complex properties of P.*) procedure GammaCDFInv(const P: TDenseMtxVec; A, B : double; const Res: TDenseMtxVec); overload; (*Geometric distribution PDF (vectorized). Defines distribution domain, real vector or matrix with positive integers. Defines success probability. p must lie on the [0,1] closed interval. After calculation stores the PDF calculated from X and p. Length and Complex properties of Res are adjusted automatically to match Length and Complex properties of X.*) procedure GeometricPDF(const X: TMtxVecInt; p: double; const Res: TDenseMtxVec); overload; (*Geometric distribution CDF (vectorized). Defines distribution domain, real vector or matrix with positive integers. Defines success probability. p must lie on the [0,1] closed interval. After calculation stores the CDF calculated from X and p. Length and Complex properties of Res are adjusted automatically to match Length and Complex properties of X.*) procedure GeometricCDF(const X: TMtxVecInt; p: double; const Res: TDenseMtxVec); overload; (*Geometric distribution PPF (vectorized). Defines distribution probabilities, real vector or matrix with values within closed interval [0,1]. Defines success probability. p must lie on the [0,1] closed interval. After calculation stores the PPF calculated from Y and p. Length and Complex properties of Res are adjusted automatically to match Length and Complex properties of Y.*) procedure GeometricCDFInv(const Y: TDenseMtxVec; p: double; const Res: TDenseMtxVec); overload; (*Gumbel distribution PDF (vectorized). Defines distribution domain, real vector or matrix. Defines the location parameter. Defines the scale parameter, positive real value. Defines maximum or minimum Gumbel distrubution. If true, th routine calculates minimum Gumbel PDF If false, the routine calculates maximum Gumbel PDF. After calculation stores the PDF calculated from X, Mu, and beta. Length and Complex properties of Res are adjusted automatically to match Length and Complex properties of X.*) procedure GumbelPDF(const X: TDenseMtxVec; Mu, beta : double; minimum: boolean; const Res: TDenseMtxVec); overload; (*Gumbel distribution CDF (vectorized). Defines distribution domain, real vector or matrix. Defines the location parameter. Defines the scale parameter, positive real value. Defines maximum or minimum Gumbel distrubution. If true, the routine calculates minimum Gumbel PDF. After calculation stores the CDF calculated from X, Mu, and beta. Length and Complex properties of Res are adjusted automatically to match Length and Complex properties of X.*) procedure GumbelCDF(const X: TDenseMtxVec; Mu, beta: double; minimum: boolean; const Res: TDenseMtxVec); overload; (*Gumbel distribution PPF (vectorized). Defines distribution probabilities, real vector or matrix with values within closed interval [0,1]. Defines the location parameter. Defines the scale parameter, positive real value. Defines maximum or minimum Gumbel distrubution. If true, the routine calculates minimum Gumbel PDF. After calculation stores the PPF calculated from P, Mu and beta. Length and Complex properties of Res are adjusted automatically to match Length and Complex properties of P.*) procedure GumbelCDFInv(const P: TDenseMtxVec; Mu, beta : double; minimum: boolean; const Res: TDenseMtxVec); overload; (*Hypergeometric distribution PDF (vectorized). Distribution domain, with integer values on closed interval [0,N]. Defines total number of elements, valid values ae integers on closed interval [0,X]. Defines number of elements with certain traits, valid values are integers on closed interval [X,M]. Defines number of samples, valid values are integers on closed interval [X,M]. After calculation stores the PDF calculated from X, K, M and N. Length and Complex properties of Res are adjusted automatically to match Length and Complex properties of X.*) procedure HypGeometricPDF(const X: TMtxVecInt; M, K, N: Integer; const Res: TDenseMtxVec); overload; (*Hypergeometric distribution CDF (vectorized). Distribution domain, with integer values on closed interval [0,N]. Defines total number of elements, valid values ae integers on closed interval [0,X]. Defines number of elements with certain traits, valid values are integers on closed interval [X,M]. Defines number of samples, valid values are integers on closed interval [X,M]. After calculation stores the CDF calculated from X, K, M and N. Length and Complex properties of Res are adjusted automatically to match Length and Complex properties of X.*) procedure HypGeometricCDF(const X: TMtxVecInt; M, K, N: Integer; const Res: TDenseMtxVec); overload; (*HyperGeometric distribution PPF (vectorized). Defines distribution probabilities, real vector or matrix with values within closed interval [0,1]. Defines total number of elements, valid values ae integers on closed interval [0,X]. Defines number of elements with certain traits, valid values are integers on closed interval [X,M]. Defines number of samples, valid values are integers on closed interval [X,M]. After calculation stores the PPF calculated from P, K, M and N. Length and Complex properties of Res are adjusted automatically to match Length and Complex properties of P.*) procedure HypGeometricCDFInv(const P: TDenseMtxVec; M, K, N: Integer; const Res: TDenseMtxVec); overload; (*Inverse Gaussian distribution PDF (vectorized). Defines distribution domain, vector or matrix with positive real values. Defines distribution Mu parameter. Mu must be a positive scalar. Defines distribution Lambda parameter. Lambda must be a positive scalar. After calculation stores the PDF calculated from X, Mu, and Lambda. Length and Complex properties of Res are adjusted automatically to match Length and Complex properties of X.*) procedure InverseGaussianPDF(const X: TDenseMtxVec; Mu, Lambda: double; const Res: TDenseMtxVec); overload; (*Inverse Gaussian distribution CDF (vectorized). Defines distribution domain, vector or matrix with positive real values. Defines distribution Mu parameter. Mu must be a positive scalar. Defines distribution Lambda parameter. Lambda must be a positive scalar. After calculation stores the CDF calculated from X, Mu, and Lambda. Length and Complex properties of Res are adjusted automatically to match Length and Complex properties of X.*) procedure InverseGaussianCDF(const X: TDenseMtxVec; Mu, Lambda: double; const Res: TDenseMtxVec); overload; (*Inverse Gaussian distribution PPF (vectorized). Defines distribution probabilities, real vector or matrix with values within closed interval [0,1]. Defines distribution Mu parameter. Mu must be a positive scalar. Defines distribution Lambda parameter. Lambda must be a positive scalar. After calculation stores the PPF calculated from P, Mu and Lambda. Length and Complex properties of Res are adjusted automatically to match Length and Complex properties of P.*) procedure InverseGaussianCDFInv(const P: TDenseMtxVec; Mu, Lambda: double; const Res: TDenseMtxVec); overload; (*Johnson bounded (SB) distribution PDF (vectorized). Defines distribution domain, vector or matrix with real values on closed interval [xi,xi+Lambda]. Distribution shape parameter, real value. Distribution shape parameter, real positive value. Distribution scale parameter, real positive value. Distribution location parameter, real value. After calculation stores the PDF calculated from X, agmma, delta, Lambda and xi. Length and Complex properties of Res are adjusted automatically to match Length and Complex properties of X.*) procedure JohnsonSBPDF(const X: TDenseMtxVec; gamma,delta,Lambda,xi: double; const Res: TDenseMtxVec); overload; (*Johnson bounded (SB) distribution CDF (vectorized). Defines distribution domain, vector or matrix with real values on closed interval [xi,xi+Lambda]. Distribution shape parameter, real value. Distribution shape parameter, real positive value. Distribution scale parameter, real positive value. Distribution location parameter, real value. After calculation stores the CDF calculated from X, agmma, delta, Lambda and xi. Length and Complex properties of Res are adjusted automatically to match Length and Complex properties of X.*) procedure JohnsonSBCDF(const X: TDenseMtxVec; gamma,delta,Lambda,xi: double; const Res: TDenseMtxVec); overload; (*Johnson bounded (SB) distribution PPF (vectorized). Defines distribution probabilities, real vector or matrix with values within closed interval [0,1]. Distribution shape parameter, real value. Distribution shape parameter, real positive value. Distribution scale parameter, real positive value. Distribution location parameter, real value. After calculation stores the PPF calculated from P, gamma, delta, Lambda and xi. Length and Complex properties of Res are adjusted automatically to match Length and Complex properties of P.*) procedure JohnsonSBCDFInv(const P: TDenseMtxVec; gamma,delta,Lambda,xi: double; const Res: TDenseMtxVec); overload; (*Johnson unbounded (SU) distribution PDF (vectorized). Defines distribution domain, vector or matrix with real values. Distribution shape parameter, real value. Distribution shape parameter, real positive value. Distribution scale parameter, real positive value. Distribution location parameter, real value. After calculation stores the PDF calculated from X, agmma, delta, Lambda and xi. Length and Complex properties of Res are adjusted automatically to match Length and Complex properties of X.*) procedure JohnsonUBPDF(const X: TDenseMtxVec; gamma,delta,Lambda,xi: double; const Res: TDenseMtxVec); overload; (*Johnson unbounded (SU) distribution CDF (vectorized). Defines distribution domain, vector or matrix with real values. Distribution shape parameter, real value. Distribution shape parameter, real positive value. Distribution scale parameter, real positive value. Distribution location parameter, real value. After calculation stores the CDF calculated from X, agmma, delta, Lambda and xi. Length and Complex properties of Res are adjusted automatically to match Length and Complex properties of X.*) procedure JohnsonUBCDF(const X: TDenseMtxVec; gamma,delta,Lambda,xi: double; const Res: TDenseMtxVec); overload; (*Johnson unbounded (SU) distribution PPF (vectorized). Defines distribution probabilities, real vector or matrix with values within closed interval [0,1]. Distribution shape parameter, real value. Distribution shape parameter, real positive value. Distribution scale parameter, real positive value. Distribution location parameter, real value. After calculation stores the PPF calculated from P, gamma, delta, Lambda and xi. Length and Complex properties of Res are adjusted automatically to match Length and Complex properties of P.*) procedure JohnsonUBCDFInv(const P: TDenseMtxVec; gamma,delta,Lambda,xi: double; const Res: TDenseMtxVec); overload; (*Laplace distribution PDF (vectorized). Defines distribution domain, vector or matrix with real values. Distribution location parameter, real value. Distribution scale parameter, real positive value. After calculation stores the PDF calculated from X, m and b. Length and Complex properties of Res are adjusted automatically to match Length and Complex properties of X.*) procedure LaplacePDF(const X: TDenseMtxVec; m, b: double; const Res: TDenseMtxVec); overload; (*Laplace distribution CDF (vectorized). Defines distribution domain, vector or matrix with real values. Distribution location parameter, real value. Distribution scale parameter, real positive value. After calculation stores the CDF calculated from X, m and b. Length and Complex properties of Res are adjusted automatically to match Length and Complex properties of X.*) procedure LaplaceCDF(const X: TDenseMtxVec; m, b: double; const Res: TDenseMtxVec); overload; (*Laplace distribution PPF (vectorized). Defines distribution probabilities, real vector or matrix with values within closed interval [0,1]. Distribution location parameter, real value. Distribution scale parameter, real positive value. After calculation stores the PPF calculated from P, m and b. Length and Complex properties of Res are adjusted automatically to match Length and Complex properties of P.*) procedure LaplaceCDFInv(const P: TDenseMtxVec; m, b : double; const Res: TDenseMtxVec); overload; (*Logistic PDF (vectorized). Defines distribution domain, real vector or matrix. Distribution location parameter, real value. Distribution scale parameter, real positive value. After calculation stores the PDF calculated from X, m and b. Length and Complex properties of Res are adjusted automatically to match Length and Complex properties of X.*) procedure LogisticPDF(const X: TDenseMtxVec; m, b: double; const Res: TDenseMtxVec); overload; (*Logistic CDF (vectorized). Defines distribution domain, real vector or matrix. Distribution location parameter, real value. Distribution scale parameter, real positive value. After calculation stores the CDF calculated from X, m and b. Length and Complex properties of Res are adjusted automatically to match Length and Complex properties of X.*) procedure LogisticCDF(const X: TDenseMtxVec; m, b: double; const Res: TDenseMtxVec); overload; (*Logistic distribution PPF (vectorized). Defines distribution probabilities, real vector or matrix with values within closed interval [0,1]. Distribution location parameter, real value. Distribution scale parameter, real positive value. After calculation stores the PPF calculated from P, m and b. Length and Complex properties of Res are adjusted automatically to match Length and Complex properties of P.*) procedure LogisticCDFInv(const P: TDenseMtxVec; m, b: double; const Res: TDenseMtxVec); overload; (*Log-Normal PDF (vectorized). Defines distribution domain, real vector or matrix with positive real values or zeros. Distribution location parameter, real value. Distribution scale parameter, real positive value. After calculation stores the PDF calculated from X, Mu and sigma. Length and Complex properties of Res are adjusted automatically to match Length and Complex properties of X.*) procedure LogNormalPDF(const X: TDenseMtxVec; Mu, sigma: double; const Res: TDenseMtxVec); overload; (*Log-Normal CDF (vectorized). Defines distribution domain, real vector or matrix with positive real values or zeros. Distribution location parameter, real value. Distribution scale parameter, real positive value. After calculation stores the CDF calculated from X, Mu and sigma. Length and Complex properties of Res are adjusted automatically to match Length and Complex properties of X.*) procedure LogNormalCDF(const X: TDenseMtxVec; Mu,sigma: double; const Res: TDenseMtxVec); overload; (*Log-Normql distribution PPF (vectorized). Defines distribution probabilities, real vector or matrix with values within closed interval [0,1]. Distribution location parameter, real value. Distribution scale parameter, real positive value. After calculation stores the PPF calculated from P, Mu and sigma. Length and Complex properties of Res are adjusted automatically to match Length and Complex properties of P.*) procedure LogNormalCDFInv(const P: TDenseMtxVec; Mu, sigma: double; const Res: TDenseMtxVec); overload; (*Log-Weibull PDF (vectorized). Defines distribution domain, real vector or matrix with real values. Distribution location parameter, real positive value. Distribution scale parameter, real positive value. After calculation stores the PDF calculated from X, a and b. Length and Complex properties of Res are adjusted automatically to match Length and Complex properties of X.*) procedure LogWeibullPDF(const X: TDenseMtxVec; a,b: double; const Res: TDenseMtxVec); overload; (*Log-Weibull CDF (vectorized). Defines distribution domain, real vector or matrix with real values. Distribution location parameter, real positive value. Distribution scale parameter, real positive value. After calculation stores the CDF calculated from X, a and b. Length and Complex properties of Res are adjusted automatically to match Length and Complex properties of X.*) procedure LogWeibullCDF(const X: TDenseMtxVec; a,b: double; const Res: TDenseMtxVec); overload; (*Log-Weibull distribution PPF (vectorized). Defines distribution probabilities, real vector or matrix with values within closed interval [0,1]. Distribution location parameter, real positive value. Distribution scale parameter, real positive value. After calculation stores the PPF calculated from P, a and b. Length and Complex properties of Res are adjusted automatically to match Length and Complex properties of P.*) procedure LogWeibullCDFInv(const P: TDenseMtxVec; a,b: double; const Res: TDenseMtxVec); overload; (*Maxwell PDF (vectorized). Defines distribution domain, real vector or matrix with positive real values or zeros. Distribution parameter, positive real value. After calculation stores the PDF calculated from X and a. Length and Complex properties of Res are adjusted automatically to match Length and Complex properties of X.*) procedure MaxwellPDF(const X: TDenseMtxVec; a: double; const Res: TDenseMtxVec); overload; (*Maxwell CDF (vectorized). Defines distribution domain, real vector or matrix with positive real values or zeros. Distribution parameter, positive real value. After calculation stores the CDF calculated from X and a. Length and Complex properties of Res are adjusted automatically to match Length and Complex properties of X.*) procedure MaxwellCDF(const X: TDenseMtxVec; a: double; const Res: TDenseMtxVec); overload; (*Negative binomial distribution PPF (vectorized). Defines distribution probabilities, real vector or matrix with values within closed interval [0,1]. Distribution parameter, positive real value. After calculation stores the PPF calculated from P and a. Length and Complex properties of Res are adjusted automatically to match Length and Complex properties of P.*) procedure MaxwellCDFInv(const P: TDenseMtxVec; a: double; const Res: TDenseMtxVec); overload; (*Negative binomial distribution PDF (vectorized). Defines distribution domain, vector or matrix with integer values. Defines number of successes, positive integer. Defines probability of each trial, real value on closed interval [0,1]. After calculation stores the PDF calculated from X, R and P Length and Complex properties of Res are adjusted automatically to match Length and Complex properties of X.*) procedure NegBinomPDF(const X: TMtxVecInt; R: double; P: double; const Res: TDenseMtxVec); overload; (*Negative binomial distribution CDF (vectorized). Defines distribution domain, vector or matrix with integer values. Defines number of successes, positive integer. Defines probability of each trial, real value on closed interval [0,1]. After calculation stores the CDF calculated from X, R and P Length and Complex properties of Res are adjusted automatically to match Length and Complex properties of X.*) procedure NegBinomCDF(const X: TMtxVecInt; R: double; P: double; const Res: TDenseMtxVec); overload; (*Negative binomial distribution PPF (vectorized). Defines distribution probabilities, real vector or matrix with values within closed interval [0,1]. Defines number of successes, positive integer. Defines probability of each trial, real value on closed interval [0,1]. After calculation stores the PPF calculated from Y, R and p. Length and Complex properties of Res are adjusted automatically to match Length and Complex properties of P.*) procedure NegBinomCDFInv(const Y: TDenseMtxVec; R: double; P: double; const Res: TDenseMtxVec); overload; (*Normal distribution PDF (vectorized). Defines distribution domain, real vector or matrix. Distribution location parameter, real value. Distribution scale parameter, real positive value. After calculation stores the PDF calculated from X, Mu and sigma. Length and Complex properties of Res are adjusted automatically to match Length and Complex properties of X.*) procedure NormalPDF(const X: TDenseMtxVec; Mu, sigma: double; const Res: TDenseMtxVec); overload; (*Normal distribution PDF (vectorized). Defines distribution domain, real vector or matrix. Distribution location parameter, real vector or matrix. Distribution scale parameter, real positive vector or matrix. After calculation stores the PDF calculated from X, Mu and sigma. Length and Complex properties of Res are adjusted automatically to match Length and Complex properties of X.*) procedure NormalPDF(const X, Mu, sigma: TDenseMtxVec; const Res: TDenseMtxVec); overload; (*Normal distribution CDF (vectorized). Defines distribution domain, real vector or matrix. Distribution location parameter, real value. Distribution scale parameter, real positive value. After calculation stores the CDF calculated from X, mi and sigma. Length and Complex properties of Res are adjusted automatically to match Length and Complex properties of X.*) procedure NormalCDF(const X: TDenseMtxVec; Mu,sigma: double; const Res: TDenseMtxVec); overload; (*Normal distribution CDF (vectorized). Defines distribution domain, real vector or matrix. Distribution location parameter, real vector or matrix. Distribution scale parameter, real positive vector or matrix. After calculation stores the CDF calculated from X, mi and sigma. Length and Complex properties of Res are adjusted automatically to match Length and Complex properties of X.*) procedure NormalCDF(const X, Mu, sigma, Res: TDenseMtxVec); overload; (*Normal distribution CDF (vectorized) two-tailed. Defines distribution domain, real vector or matrix. Distribution location parameter, real vector or matrix. Distribution scale parameter, real positive vector or matrix. After calculation stores the CDF calculated from X, mi and sigma. Length and Complex properties of Res are adjusted automatically to match Length and Complex properties of X.*) procedure NormalCDFTwoTail(const X, Mu, sigma: TDenseMtxVec; const Res: TDenseMtxVec); overload; (*Normal distribution CDF (vectorized) two-tailed. Defines distribution domain, real vector or matrix. Distribution location parameter, real value. Distribution scale parameter, real positive value. After calculation stores the CDF calculated from X, mi and sigma. Length and Complex properties of Res are adjusted automatically to match Length and Complex properties of X.*) procedure NormalCDFTwoTail(const X: TDenseMtxVec; const Mu, sigma: double; const Res: TDenseMtxVec); overload; (*Normal distribution PPF (vectorized). Defines distribution probabilities, real vector or matrix with values within closed interval [0,1]. Distribution location parameter, real value. Distribution scale parameter, real positive value. After calculation stores the PPF calculated from P, Mu and sigma. Length and Complex properties of Res are adjusted automatically to match Length and Complex properties of P.*) procedure NormalCDFInv(const P: TDenseMtxVec; Mu, sigma: double; const Res: TDenseMtxVec); overload; (*Pareto distribution PDF (vectorized). Defines distribution domain, real vector or matrix. Distribution scale parameter, real positive value. Distribution shape parameter, real positive value, smaller than x. After calculation stores the PDF calculated from X, a and b. Length and Complex properties of Res are adjusted automatically to match Length and Complex properties of X.*) procedure ParetoPDF(const X: TDenseMtxVec; a, b: double; const Res: TDenseMtxVec); overload; (*Pareto distribution CDF (vectorized). Defines distribution domain, real vector or matrix. Distribution scale parameter, real positive value. Distribution shape parameter, real positive value, smaller than x. After calculation stores the CDF calculated from X, a and b. Length and Complex properties of Res are adjusted automatically to match Length and Complex properties of X.*) procedure ParetoCDF(const X: TDenseMtxVec; a, b: double; const Res: TDenseMtxVec); overload; (*Pareto distribution PPF (vectorized). Defines distribution probabilities, real vector or matrix with values within closed interval [0,1]. Distribution scale parameter, real positive value. Distribution shape parameter, real positive value, smaller than x. After calculation stores the PPF calculated from P, a and b. Length and Complex properties of Res are adjusted automatically to match Length and Complex properties of P.*) procedure ParetoCDFInv(const P: TDenseMtxVec; a, b: double; const Res: TDenseMtxVec); overload; (*Poisson distribution PDF (vectorized). Distribution domain, positive integer values or zeros. Distribution parameter, real positive value. After calculation stores the PDF calculated from X, alpha and beta. Length and Complex properties of Res are adjusted automatically to match Length and Complex properties of X.*) procedure PoissonPDF(const X: TMtxVecInt; Lambda: double; const Res: TDenseMtxVec); overload; (*Poisson distribution CDF (vectorized). Distribution domain, positive integer values or zeros. Distribution parameter, real positive value. After calculation stores the CDF calculated from X, alpha and beta. Length and Complex properties of Res are adjusted automatically to match Length and Complex properties of X.*) procedure PoissonCDF(const X: TMtxVecInt; Lambda: double; const Res: TDenseMtxVec); overload; (*Poisson distribution PPF (vectorized). Defines distribution probabilities, real vector or matrix with values within closed interval [0,1]. Distribution parameter, real positive value. After calculation stores the PPF calculated from P and Lambda. Length and Complex properties of Res are adjusted automatically to match Length and Complex properties of P.*) procedure PoissonCDFInv(const P: TDenseMtxVec; Lambda: double; const Res: TDenseMtxVec); overload; (*Power distribution PDF (vectorized). Distribution domain, positive real values on closed interval [0,1/beta]. Distribution shape parameter, real positive value.. Distribution scale parameter, positive real number. After calculation stores the PDF calculated from X, alpha and beta. Length and Complex properties of Res are adjusted automatically to match Length and Complex properties of X.*) procedure PowerPDF(const X: TDenseMtxVec; alpha, beta: double; const Res: TDenseMtxVec); overload; (*Power distribution CDF (vectorized). Distribution domain, positive real values on closed interval [0,1/beta]. Distribution shape parameter, real positive value.. Distribution scale parameter, positive real number. After calculation stores the CDF calculated from X, alpha and beta. Length and Complex properties of Res are adjusted automatically to match Length and Complex properties of X.*) procedure PowerCDF(const X: TDenseMtxVec; alpha, beta: double; const Res: TDenseMtxVec); overload; (*Power distribution PPF (vectorized). Defines distribution probabilities, real vector or matrix with values within closed interval [0,1]. Distribution shape parameter, real positive value.. Distribution scale parameter, positive real number. After calculation stores the PPF calculated from P, alpha and beta. Length and Complex properties of Res are adjusted automatically to match Length and Complex properties of P.*) procedure PowerCDFInv(const P: TDenseMtxVec; alpha, beta: double; const Res: TDenseMtxVec); overload; (*Rayleigh distribution PDF (vectorized). Distribution domain, positive real values or zeros. Distribution parameter, positive real value. After calculation stores the PDF calculated from X and b. Length and Complex properties of Res are adjusted automatically to match Length and Complex properties of X.*) procedure RayleighPDF(const X: TDenseMtxVec; b: double; const Res: TDenseMtxVec); overload; (*Rayleigh distribution CDF (vectorized). Distribution domain, positive real values or zeros. Distribution parameter, positive real value. After calculation stores the CDF calculated from X and b. Length and Complex properties of Res are adjusted automatically to match Length and Complex properties of X.*) procedure RayleighCDF(const X: TDenseMtxVec; b: double; const Res: TDenseMtxVec); overload; (*Rayleigh distribution PPF (vectorized). Defines distribution probabilities, real vector or matrix with values within closed interval [0,1]. Distribution parameter, positive real value. After calculation stores the PPF calculated from P and b. Length and Complex properties of Res are adjusted automatically to match Length and Complex properties of P.*) procedure RayleighCDFInv(const P: TDenseMtxVec; b: double; const Res: TDenseMtxVec); overload; (*Student(T) distribution PDF (vectorized). Distribution domain, real values. Defines distribution degrees of freedom, positive integer. After calculation stores the PDF calculated from X and Nu. Length and Complex properties of Res are adjusted automatically to match Length and Complex properties of X.*) procedure StudentPDF(const X: TDenseMtxVec; Nu: Integer; const Res: TDenseMtxVec); overload; (*Student(T) distribution CDF (vectorized). Distribution domain, real values. Defines distribution degrees of freedom, positive integer. After calculation stores the CDF calculated from X and Nu. Length and Complex properties of Res are adjusted automatically to match Length and Complex properties of X.*) procedure StudentCDF(const X: TDenseMtxVec; Nu: Integer; const Res: TDenseMtxVec); overload; (*Student(T) distribution PPF (vectorized). Defines distribution probabilities, real vector or matrix with values within closed interval [0,1]. Defines distribution degrees of freedom, positive integer. After calculation stores the PPF calculated from P and Nz. Length and Complex properties of Res are adjusted automatically to match Length and Complex properties of P.*) procedure StudentCDFInv(const P: TDenseMtxVec; Nu: Integer; const Res: TDenseMtxVec); overload; (*Triangular distribution PDF (vectorized). Distribution domain, real value on closed interval [a,b]. Distribution locagtion parameter, real value, smaller than parameter b. Distribution scale parameter, real value, greater than parameter a. Distribution shape parameter, real value on closed interval [a,b]. After calculation stores the PDF calculated from X, a, b and c. Length and Complex properties of Res are adjusted automatically to match Length and Complex properties of X.*) procedure TriangularPDF(const X: TDenseMtxVec; a,b,c: double; const Res: TDenseMtxVec); overload; (*Triangular distribution CDF (vectorized). Distribution domain, real value on closed interval [a,b]. Distribution location parameter, real value, smaller than parameter b. Distribution scale parameter, real value, greater than parameter a. Distribution shape parameter, real value on closed interval [a,b]. After calculation stores the CDF calculated from X, a, b and c. Length and Complex properties of Res are adjusted automatically to match Length and Complex properties of X.*) procedure TriangularCDF(const X: TDenseMtxVec; a,b,c: double; const Res: TDenseMtxVec); overload; (*Triangular distribution PPF (vectorized). Defines distribution probabilities, real vector or matrix with values within closed interval [0,1]. Distribution locagtion parameter, real value, smaller than parameter b. Distribution scale parameter, real value, greater than parameter a. Distribution shape parameter, real value on closed interval [a,b]. After calculation stores the PPF calculated from P, a,b and c. Length and Complex properties of Res are adjusted automatically to match Length and Complex properties of P.*) procedure TriangularCDFInv(const P: TDenseMtxVec; a,b,c: double; const Res: TDenseMtxVec); overload; (*Uniform distribution PDF (vectorized). Defines distribution domain, real vector or matrix with values on closed interval [A,B]. Distribution parameter, real value, defining distribution lower bound. Distribution parameter, real value, defining distribution upper bound. After calculation stores the PDF calculated from X, A and B. Length and Complex properties of Res are adjusted automatically to match Length and Complex properties of X.*) procedure UniformPDF(const X: TDenseMtxVec; A, B: double; const Res: TDenseMtxVec); overload; (*Discrete uniform distribution CDF (vectorized). Defines distribution domain, real vector or matrix with values on closed interval [A,B]. Distribution parameter, real value, defining distribution lower bound. Distribution parameter, real value, defining distribution upper bound. After calculation stores the CDF calculated from X, A and B. Length and Complex properties of Res are adjusted automatically to match Length and Complex properties of X.*) procedure UniformCDF(const X: TDenseMtxVec; A, B: double; const Res: TDenseMtxVec); overload; (*Uniform distribution PPF (vectorized). Defines distribution probabilities, real vector or matrix with values within closed interval [0,1]. Distribution parameter, real value, defining distribution lower bound. Distribution parameter, real value, defining distribution upper bound. After calculation stores the PPF calculated from P, A and B. Length and Complex properties of Res are adjusted automatically to match Length and Complex properties of P.*) procedure UniformCDFInv(const P: TDenseMtxVec; A, B: double; const Res: TDenseMtxVec); overload; (*Discrete uniform distribution PDF (vectorized). Defines distribution domain, vector or matrix with integer values on closed interval [1,N]. Distribution parameter, positive integer. After calculation stores the PDF calculated from X and N. Length and Complex properties of Res are adjusted automatically to match Length and Complex properties of X.*) procedure UniformDPDF(const X: TMtxVecInt; N: Integer; const Res: TDenseMtxVec); overload; (*Discrete uniform distribution CDF (vectorized). Defines distribution domain, vector or matrix with integer values on closed interval [1,N]. Distribution parameter, positive integer. After calculation stores the CDF calculated from X and N. Length and Complex properties of Res are adjusted automatically to match Length and Complex properties of X.*) procedure UniformDCDF(const X: TMtxVecInt; N: Integer; const Res: TDenseMtxVec); overload; (*Discrete uniform distribution PPF (vectorized). Defines distribution probabilities, real vector or matrix with values within closed interval [0,1]. Distribution parameter, positive integer. After calculation stores the PPF calculated from P and N. Length and Complex properties of Res are adjusted automatically to match Length and Complex properties of P.*) procedure UniformDCDFInv(const P: TDenseMtxVec; N: Integer; const Res: TDenseMtxVec); overload; (*Weibull distribution PDF (vectorized). Defines distribution domain, real vector or matrix with positive real values. Distribution scale parameter, real positive value. Distribution shape parameter, real positive value. After calculation stores the PDF calculated from X, a and b. Length and Complex properties of Res are adjusted automatically to match Length and Complex properties of X.*) procedure WeibullPDF(const X: TDenseMtxVec; A,B: double; const Res: TDenseMtxVec); overload; (*Weibull distribution CDF (vectorized). Defines distribution domain, real vector or matrix with positive real values. Distribution scale parameter, real positive value. Distribution shape parameter, real positive value. After calculation stores the CDF calculated from X, a and b. Length and Complex properties of Res are adjusted automatically to match Length and Complex properties of X.*) procedure WeibullCDF(const X: TDenseMtxVec; A,B: double; const Res: TDenseMtxVec); overload; (*Weibull distribution PPF (vectorized). Defines distribution probabilities, real vector or matrix with values within closed interval [0,1]. Distribution scale parameter, real positive value. Distribution shape parameter, real positive value. After calculation stores the PPF calculated from P, a and b. Length and Complex properties of Res are adjusted automatically to match Length and Complex properties of P.*) procedure WeibullCDFInv(const P: TDenseMtxVec; A,B: double; const Res: TDenseMtxVec); overload; (*Zipf distribution PDF (vectorized). Defines distribution domain, real vector or matrix with integer values on interval [1,Inf). Distribution parameter, real positive value. Distribution parameter, positive integer. After calculation stores the PDF calculated from X,s and N. Length and Complex properties of Res are adjusted automatically to match Length and Complex properties of X.*) procedure ZipfPDF(const X: TMtxVecInt; s: double; N: Integer; const Res: TDenseMtxVec); overload; (*Zipf distribution CDF (vectorized). Defines distribution domain, real vector or matrix with integer values on interval [1,Inf). Distribution parameter, real positive value. Distribution parameter, positive integer. After calculation stores the CDF calculated from X,s and N. Length and Complex properties of Res are adjusted automatically to match Length and Complex properties of X.*) procedure ZipfCDF(const X: TMtxVecInt; s: double; N: Integer; const Res: TDenseMtxVec); overload; (*Zipf distribution PPF (vectorized). Defines distribution probabilities, real vector or matrix with values within closed interval [0,1]. Distribution parameter, real positive value. Distribution parameter, positive integer. After calculation stores the PPF calculated from P,s and N. Length and Complex properties of Res are adjusted automatically to match Length and Complex properties of P.*) procedure ZipfCDFInv(const p: TDenseMtxVec; s: double; N: Integer; const Res: TDenseMtxVec); overload; (* Returns digamma function or psi(0,x) Computes the first derivate of the logarithm of the gamma function. The function returns NAN, if the x is less than zero. The algorithm was adapted from: The algorithm "AS 103" from "Applied Statistics" (1976) VOL.25, NO.3 Available in Fortran at: http://lib.stat.cmu.edu/apstat/103 *) function digamma(x: double): double; (* Returns trigamma function or psi(1,x) Computes the second derivate of the logarithm of the gamma function. The function returns NAN, if the x is less than or equal to zero. The algorithm was adapted from: The algorithm "AS 121" from "Applied Statistics" (1978) vol 27, no. 1 Available in Fortran at: http://lib.stat.cmu.edu/apstat/121 *) function trigamma(x: double): double; (* Returns psi function of x. Computes the second or third derivate of the logarithm of the gamma function. The function returns NAN, if the x is less than or equal to zero. If derivate parameter is 0, the function returns digamma(x). If the derivate parameter is 1 then the function returns trigamma(x). Other values for derivate parameter are not supported. *) function psi(derivate: integer; x: double): double; (*Nmkl random generators interface.*) unit RndGenerators; interface {$I BdsppDefs.inc } {$Z4} uses Math387, AbstractMtxVec, MtxVec, MtxVecInt, AbstractMtxVecInt ,RndImport ,Classes ; type (*Defines available random generator algorithms.*) TBasicRandomGenerator = ( (*MCG31m1 32-bit linear congruential generators, which also include MCG31m1 [14], are still used as default RNGs in various systems mostly due to simplicity of implementation, speed of operation, and compatibility with earlier versions of the systems. However, their period lengths do not meet the requirements for modern basic random number generators. Nevertheless, MCG31m1 possesses good statistical properties and may be used to advantage in generating random numbers of various distribution types for relatively small samplings. *) rgMCG31, (*R250 R250 is a generalized feedback shift register generator. Feedback shift register generators possess extensive theoretical footing and were first considered as RNGs for cryptographic and communications applications. Generator R250 proposed in [10] is fast and simple in implementation. It is common in the field of physics. However, the generator fails a number of tests, a 2D self-avoiding random walk [21] being an example. *) rgR250, (*MRG32K3A A combined generator MRG32k3a [13] meets the requirements for modern RNGs: good multidimensional uniformity, fairly large period, etc. Besides, being optimized for various Intel® architectures, this generator rivals the other VSL BRNGs in speed. *) rgMRG32K3A, (*MCG59 A multiplicative congruential generator MCG59 is one of the two basic generators implemented in NAG Numerical Libraries [18] (see www.nag.co.uk). Since the module of this generator is not prime, its period length is not 259, but just 257, if the seed is an odd number. A drawback of such generators is well-known (for example, see [11], [12]): the lower bits of the output sequence are not random, therefore breaking numbers down into their bit patterns and using individual bits may cause trouble. Besides, block-splitting of the sequence over the entire period into 2d similar blocks results in full coincidence of such blocks in d lower bits (see, for instance, [11], [12]). *) rgMCG59, (*WH WH is a set of 273 different basic generators. It is the second basic generator in NAG libraries. The constants ai,j are in the range 112 to 127 and the constants mi,j are prime numbers in the range 16718909 to 16776971, which are close to 224. These constants have been chosen so that they give good results with the spectral test, see [11] and [15]. The period of each Wichmann–Hill generator would be at least 292, if it were not for common factors between (m1,j–1), (m2,j–1), (m3,j–1), and (m4,j–1). However, each generator should still have a period of at least 280. Further discussion of the properties of these generators is given in [15], which shows that the generated pseudo-random sequences are essentially independent of one another according to the spectral test. *) rgWH, (*SOBOL Bratley and Fox [4] provide an implementation of the Sobol quasi-random number generator. VSL implementation allows generating Sobol’s low-discrepancy sequences of length up to 232. The dimension of quasi-random vectors can vary from 1 to 40 inclusive. *) rgSOBOL, (*NIEDERR According to the results of Bratley, Fox, and Niederreiter [5] Niederreiter’s sequences have the best known theoretical asymptotic properties. VSL implementation allows generating Niederreiter’s low-discrepancy sequences of length up to 232. The dimension of quasi-random vectors can vary from 1 to 318 inclusive. VSL provides an option of registering one or more new basic generators that you see as preferable or more reliable. Use them in the same way as the BRNGs available with VSL. The registration procedure makes it easy to include a variety of user-designed generators. *) rgNIEDERR, (*MT19937 Mersenne Twister pseudorandom number generator. Properties of the algorithm (the period length equal to 219937-1 and 623-dimensional equidistribution up to 32-bit accuracy) make this generator applicable for simulations in various fields of science and engineering. *) rgMT19937, (*MT2203 The set of 1024 MT2203 pseudorandom number generators is an addition to MT19937 generator intended for application in large scale Monte Carlo simulations performed on distributed multi-processor systems. Every MT2203 generator has a period length equal to 22203-1 and possesses 68-dimensional equidistribution up to 32-bit accuracy. *) rgMT2203, rgIAbstract, rgDAbstract, rgSAbstract, rgSFMT19937, rgNONDETERM, rgARS5, rgPHILOX4X32X10 ); (*Gaussian (normal) distribution random generator options.*) TGaussRandMethod = ( (*Box Muller Generates a normal distributed random number x via a pair of uniforms u1, u2 according to the formula x=sqrt(-ln(u1))*sin(2*Pi*u2) *) grmBoxMuller = 0 , (*Box Muller 2 Generates a pair of normal distributed random numbers x1, x2 via a pair of uniforms u1, u2 according to the formulas x1=sqrt(-ln(u1))*sin(2*Pi*u2) x2=sqrt(-ln(u1))*cos(2*Pi*u2). Method implemented so that it correctly processes odd vector length, i.e. if a call ends with generating x1, the next call starts from generating x2. *) grmBoxMuller2 = 1, (*ICDF*) grmICDF = 2 ); (*Possion distribution random generator options.*) TPoissonRandMethod = ( (*PTPE If lambda >= 27, acceptance/rejection method is used with decomposition onto 4 regions: * 2 combined parallelograms, triangle, * left exponential tail and * right exponential tail. Othewise table lookup method is used. *) prmPTPE = 0, (*Normal For lambda >= 1 method is based on Poisson inverse CDF approximation via Gaussian (normal) inverse CDF; for lambda < 1 table lookup method is used. *) prmNormal = 1); (*Defines the method used to get random number series independence. Defines the method used to obtain several independent random streams using the same random generator with the same seed. If the method is not supported by the specified random basic random generator, an error will be raised. *) TRngStreamIndependence = ( (*None All random streams will return the series of numbers. *) rsiNone, (*Leap-frog Random streams will be sample interleaved. If there are three random streams defined, they will be filled from one continues random number stream like this: Original : 0 1 2 3 4 5 6 7 8 9 10 11 Leapfrog 1: 0 3 6 9 Leapfrog 2: 1 4 7 10 Leapfrog 3: 2 5 8 11 Leapfroging is not very suitable, if there is a need for a large number of independent streams. *) rsiLeapfrog, (*Block-interleaved Random streams will be block interleaved. The following example is for block size 2 and random stream count 3. The block size is independent from the number of samples that are generated on each call from each of the streams. Original : 0 1 2 3 4 5 6 7 8 9 10 11 Leapfrog 1: 0 1 6 7 Leapfrog 2: 2 3 8 9 Leapfrog 3: 4 5 10 11 *) rsiBlockSplitting); (*Random stream class.*) TRngStream = class(TPersistent) strict private fRngStream: PAPointer; strict protected procedure StatusCheck(const aStatus: integer); procedure CheckNewStream(const rStatus: integer); public property RngStream: PAPointer read fRngstream; procedure Delete; procedure NewStream(rngType: integer; Seed: cardinal); (*Saves random generator stream state to Stream.*) procedure SaveToStream(const Dst: TStream); virtual; (*Loads random generator stream state from Stream.*) procedure LoadFromStream(const Src: TStream); virtual; (*Copies the state from another stream.*) procedure CopyState(const Src: TRngStream); (*Copies entire descriptor from another random stream.*) procedure Copy(const Src: TRngStream); (*Generates an array of samples distributed by Cauchy distribution. Returns random numbers distributed according to to the Cauchy probability density function (PDF) as defined here . The number of samples generated is defined with the Dst.Length parameter. The result is an array which can be accessed via Dst.Values property. *) procedure RandomCauchy(const Dst: TMtxVec; const mu,b: double); (*Generates an array of samples distributed by Uniform distribution. Returns random numbers distributed according to the Uniform probability density function (PDF) as defined here . The number of samples generated is defined with the Dst.Length parameter. The result is an array which can be accessed via Dst.Values property. *) procedure RandomUniform(const Dst: TMtxVec; const a,b: double); (*Generates an array of samples distributed by Gaussian distribution. Returns random numbers distributed according to the Gaussian probability density function (PDF) as defined here . The number of samples generated is defined with the Dst.Length parameter. The result is an array which can be accessed via Dst.Values property. *) procedure RandomGaussian(const Dst: TMtxVec; const mu ,sigma: double; const Method: TGaussRandMethod = grmBoxMuller); (*Generates random numbers from multivariate normal distribution. The function generates random numbers with d-variate normal (Gaussian) distribution with Mean value and variance-covariance matrix Sigma, where Sigma is a dxd symmetric positive-definite matrix in full storage. The number of d-dimensional vectors to be generated is defined with Dst.Rows, the dimension d with Dst.Cols. Mean must be equal to Dst.Cols and Sigma.Rows and Sigma.Cols also equal to Dst.Cols. *) procedure RandomGaussianMV(const Dst: TMtx; const Mean: TVec; const Sigma: TMtx; const Method: TGaussRandMethod = grmBoxMuller); (*Generates an array of samples distributed by Exponential distribution. Returns random numbers distributed according to the Exponential probability density function (PDF) similar to as defined here . The number of samples generated is defined with the Dst.Length parameter. The result is an array which can be accessed via Dst.Values property. The probability density function is defined as: 1 (x-a) f(x) = ------ exp( - ---- ) , x >= a mu mu f(x) = 0, x < a *) procedure RandomExponential(const Dst: TMtxVec; const a,mu: double); (*Generates an array of samples distributed by Laplace distribution. Returns random numbers distributed according to the Laplace probability density function (PDF). The number of samples generated is defined with the Dst.Length parameter. The result is an array which can be accessed via Dst.Values property. The probability density function is defined as: 1 |x-a| f(x) = --------------- exp( - ------ ) sqrt(2*beta) beta *) procedure RandomLaplace(const Dst: TMtxVec; const a, beta: double); (*Generates an array of samples distributed by Weibull distribution. Returns random numbers distributed according to the Weibull probability density function (PDF) similar to as defined here . The number of samples generated is defined with the Dst.Length parameter. The result is an array which can be accessed via Dst.Values property. The probability density function is defined as: alfa*(x-a)^(alfa-1) x-a f(x) = ------------------- exp( - (----)^alfa ) , x >= a (beta)^alfa beta f(x) = 0, x < a *) procedure RandomWeibull(const Dst: TMtxVec; const alpha, a, beta: double); (*Generates an array of samples distributed by Rayleigh distribution. Returns random numbers distributed according to the Rayleigh probability density function (PDF) similar to as defined here . The number of samples generated is defined with the Dst.Length parameter. The result is an array which can be accessed via Dst.Values property. The Rayleigh distribution is a special case of the Weibull distribution where the alfa parameter is equal to 2. The probability density function is defined as: 2*(x-a) sqr(x-a) f(x) = -------- exp( ------------ ) , x >= a sqr(b) sqr(beta) f(x) = 0, x < a *) procedure RandomRayleigh(const Dst: TMtxVec; const a, beta: double); (*Generates an array of samples distributed Lognormally. Returns random numbers distributed according to the Lognormal probability density function (PDF) similar to as defined here . Additional parameters are "b" is displacement and beta is scale factor: 1 sqr( ln((x - b)/beta) - mu) f(x) = ---------------------*exp( - ----------------------------) , x > b sigma*(x-b)*sqrt(2Pi) 2*sqr(sigma) f(x) = 0, x <= b The number of samples generated is defined with the Dst.Length parameter. The result can be accessed via Dst.Values property. *) procedure RandomLogNormal(const Dst: TMtxVec; const mu, sigma, b, beta: double); (*Generates an array of samples distributed by Beta distribution. Returns random numbers distributed according to the Beta probability density function (PDF). The number of samples generated is defined with the Dst.Length parameter. The result is an array which can be accessed via Dst.Values property. *) procedure RandomBeta(const Dst: TMtxVec; const p, q, a, beta: double); (*Generates an array of samples distributed by Gamma distribution. Returns random numbers distributed according to the Gamma probability density function (PDF). The number of samples generated is defined with the Dst.Length parameter. The result is an array which can be accessed via Dst.Values property. *) procedure RandomGamma(const Dst: TMtxVec; const alpha, a, beta: double); (*Generates an array of samples distributed by Gumbel distribution. Returns random numbers distributed according to the Gumbel probability density function (PDF). The number of samples generated is defined with the Dst.Length parameter. The result is an array which can be accessed via Dst.Values property. *) procedure RandomGumbel(const Dst: TMtxVec; const a, beta: double); (*Generates an array of integer samples distributed by Bernoulli distribution. Returns random numbers distributed according to the Bernoulli distribution. The number of samples generated is defined with the Dst.Length parameter. Dst is automatically resized to store 32bit integers, if needed. *) procedure RandomBernoulli(const Dst: TMtxVecInt; const p: double); (*Generates an array of integer samples distributed by Uniform distribution. Returns random numbers distributed according to the Uniform probability density function (PDF) as defined here . The number of samples generated is defined with the Dst.Length parameter. Dst is automatically resized to store 32bit integers, if needed. *) procedure RandomUniformI(const Dst: TMtxVecInt; const a,b: integer); (*Generates integer random values with Uniform bit distribution. Lower bits can be less random than higher bits depending on the random generator used. The number of samples generated is defined with the Dst.Length parameter. Dst is automatically resized to store 32bit integers, if needed. The result is an array of integers. *) procedure RandomUniformBitsI(const Dst: TMtxVecInt); (*Generates an array of integer samples distributed Geometrically. Returns random numbers distributed according to the Geometric probability density function (PDF) as defined here . The number of samples generated is defined with the Dst.Length parameter. Dst is automatically resized to store 32bit integers, if needed. The result is an array of integers. *) procedure RandomGeometric(const Dst: TMtxVecInt; const p: double); (*Generates an array of integer samples distributed Binomially. Returns random numbers distributed according to the Binomial probability density function (PDF) as defined here . The number of samples generated is defined with the Dst.Length parameter. The result is an array of integers which can be accessed via Dst.IValues property. Dst is automatically resized to store 32bit integers, if needed. *) procedure RandomBinomial(const Dst: TMtxVecInt; const n: integer; const p: double); (*Generates an array of integer samples distributed Hypergeometrically. Hypergeometric probability density function (PDF). Returns random numbers distributed according to the Hypergeometric probability density function (PDF) as defined here . The number of samples generated is defined with the Dst.Length parameter. The result is an array of integers which can be accessed via Dst.IValues property. Dst is automatically resized to store 32bit integers, if needed. *) procedure RandomHypergeometric(const Dst: TMtxVecInt; const m, k, n: integer); (*Generates an array of integer amples distributed according to the Negative binomial probability distribution. Returns random numbers distributed according to the Negative binomial probability density function (PDF) as defined here . The number of samples generated is defined with the Dst.Length parameter. The result is an array of integers which can be accessed via Dst.IValues property. Dst is automatically resized to store 32bit integers, if needed. *) procedure RandomNegbinomial(const Dst: TMtxVecInt; const r, p: double); (*Generates an array of integer samples distributed according to the Poisson probability distribution. The lambda parameter is the same for all random numbers generated. Dst is automatically resized to store 32bit integers, if needed. *) procedure RandomPoisson(const Dst: TMtxVecInt; const lambda: double; const Method: TPoissonRandMethod = prmPTPE); overload; (*Generates an array of integer samples distributed according to the Poisson probability distribution. Returns random numbers distributed according to the Poisson probability density function (PDF) as defined here . The lambda parameter can be different for each random number generated, The number of samples generated is defined with the Lambda.Length parameter. The result is an array of integers which can be accessed via Dst.IValues property. Dst is automatically resized to store 32bit integers, if needed. *) procedure RandomPoisson(const Dst: TMtxVecInt; const lambda: TDoubleArray; const Method: TPoissonRandMethod = prmPTPE); overload; (* Generates uniformly distributed bits in 32-bit chunks Unlike RandomUniformBits, which provides the output of underlying integer recurrence and does not guarantee uniform distribution across bits, RandomUniformBits32 is designed to ensure each bit in the 32-bit chunk is uniformly distributed. *) procedure RandomUniformBits32(const Dst: TCardinalArray); overload; (* Generates uniformly distributed bits in 64-bit chunks Unlike RandomUniformBits, which provides the output of underlying integer recurrence and does not guarantee uniform distribution across bits, RandomUniformBits64 is designed to ensure each bit in the 64-bit chunk is uniformly distributed. *) procedure RandomUniformBits64(const Dst: TUInt64Array); overload; (*Generates multinomially distributed random numbers. The function generates multinomially distributed random numbers with m independent trials and k possible mutually exclusive outcomes, with corresponding probabilities in p. *) procedure RandomMultinomial(const Dst: TVecInt; const nTrials, k: integer; const p: TDoubleArray); overload; destructor Destroy; override; end; TRngStreamArray = array of TRngStream; (*Random generator. Use this class to generate streams of random numbers. To achieve independence between two series of random numbers there are three options: 1. create several instances of this class and initialize each with a different seed. (and maybe a different random generator). 2. create a single instance of this class and use leapfroging. 3. create a single instance of this class and use block splitting. var rnd : TRandomGenerator; IntVec : TVecInt; begin if Seed = -1 then Seed := aRound(Random*High(Cardinal)); rnd := TRandomGenerator.Create; IntVec := TVecInt.Create; try IntVec.Size(Results.Length, prInt32); rnd.StreamCount := 1; rnd.Init(rgMRG32k3a,Seed); rnd.Stream[0].RandomBinomial(IntVec,an,p); Results.Copy(IntVec); finally rnd.Free; IntVec.Free; end end; *) TRandomGenerator = class(TPersistent) strict private StreamList: TRngStreamArray; FStreamCount: integer; FStreamIndependence: TRngStreamIndependence; FSeed: integer; FBasicRngType: TBasicRandomGenerator; FBlockStep: integer; function GetStream(Index1: integer): TRngStream; procedure SetStream(Index1: integer; const Value: TRngStream); procedure SetStreamCount(const Value: integer); procedure SetStreamIndependence(const Value: TRngStreamIndependence); procedure SetBlockStep(const Value: integer); public (*The basic random generator used. Returns the basic random generator used that was passed to the Init routine. *) property BasicRngType: TBasicRandomGenerator read FBasicRngType; (*The random generator seed. Returns the random generator seed that was passed to the Init routine. *) property Seed: integer read FSeed; (*A list of independent random streams. The number of independent random streams is defined with the property. The method used to achieve random stream independence is defined with . *) property Stream[Index1: integer]: TRngStream read GetStream write SetStream; default; (*Initializes random generator. Initializes random generator by specifying the basic random generator and a seed for the generator. Typical value for aSeed is 1. *) procedure Init(const aBasicRngType: TBasicRandomGenerator; const aSeed: integer); (*Saves random generator state to Dst.*) procedure SaveToStream(const Dst: TStream); virtual; (*Loads random generator state from Src.*) procedure LoadFromStream(const Src: TStream); virtual; (*Saves random generator state to File. var rnd: TRandomGenerator; iVec: VectorInt; begin rnd := TRandomGenerator.Create; rnd.StreamIndependence := TRngStreamIndependence.rsiLeapfrog; try iVec.Size(1000); rnd.StreamCount := 2; rnd.Stream[0].RandomUniformbitsI(iVec); rnd.Stream[1].RandomUniformbitsI(iVec); rnd.SaveToFile('D:\Test.rnd'); finally rnd.Free; end; rnd := TRandomGenerator.Create; //load stream count, and individual stream state at the time when they were saved rnd.LoadFromFile('D:\Test.rnd'); try rnd.Stream[0].RandomUniformBitsI(iVec); rnd.Stream[1].RandomUniformBitsI(iVec); finally rnd.Free; end; end; *) procedure SaveToFile(const FileName: string); virtual; (*Loads random generator state from File. var rnd: TRandomGenerator; iVec: VectorInt; begin rnd := TRandomGenerator.Create; rnd.StreamIndependence := TRngStreamIndependence.rsiLeapfrog; try iVec.Size(1000); rnd.StreamCount := 2; rnd.Stream[0].RandomUniformbitsI(iVec); rnd.Stream[1].RandomUniformbitsI(iVec); rnd.SaveToFile('D:\Test.rnd'); finally rnd.Free; end; rnd := TRandomGenerator.Create; //load stream count, and individual stream state at the time when they were saved rnd.LoadFromFile('D:\Test.rnd'); try //continue where we left of:... rnd.Stream[0].RandomUniformbitsI(iVec); rnd.Stream[1].RandomUniformbitsI(iVec); finally rnd.Free; end; end; *) procedure LoadFromFile(const FileName: string); virtual; constructor Create; virtual; destructor Destroy; override; published (*Number of independent random streams. Defines the number of independent random streams to be obtained from the same stream of random numbers. *) property StreamCount: integer read FStreamCount write SetStreamCount; (*Specifies the method to achieve random stream independence.*) property StreamIndependence: TRngStreamIndependence read FStreamIndependence write SetStreamIndependence; (*A parameter to the block splitting method to achieve stream independence.*) property BlockStep: integer read FBlockStep write SetBlockStep; end; (*Implements the sparse matrix class. This unit implements the class. *) unit Sparse; {$I BdsppDefs.inc} interface uses AbstractMtxVec, MtxVec, Math387, MtxVecBase ,Ippspl ,IppsplSingle ,lapack_umfpack ,SysUtils, Classes ; {$HPPEMIT END '#include "Sparse.h"'} {$HPPEMIT '#include '} {$HPPEMIT '#include '} (*Defines the system to be solved by the method. Defines the system to be solved by the method. In the declaration bellow L is lower triangular matrix, U is uper triangular matrix, P and Q are the permutation matrices and T denotes tranpose operation. PAQ = LU. Applies to Umfpack only. *) type TSparseSystem = ( (*Ax=b*)spsA = UMFPACK_A, (*A'x=b*)spsAT = UMFPACK_At, (*A.'x=b*)spsAat = UMFPACK_Aat, (*P'Lx=b*)spsPtL = UMFPACK_Pt_L, (*Lx=b*)spsL = UMFPACK_L, (*L'Px=b*)spsLTP = UMFPACK_Lt_P, (*L.'Px=b*)spsLaTP = UMFPACK_Lat_P, (*L'x=b*)spsLT = UMFPACK_Lt, (*L.'x=b*)spsLaT = UMFPACK_Lat, (*UQ'x=b*)spsUQT = UMFPACK_U_Qt, (*Ux=b*)spsU = UMFPACK_U, (*QU'x=b*)spsQUT = UMFPACK_Q_Ut, (*QU.'x=b*)spsQUaT = UMFPACK_Q_Uat, (*U'x=b*)spsUT = UMFPACK_Ut, (*U.'x=b*)spsUaT = UMFPACK_Uat ); (*Defines sparse matrix file format. Note: Currently only Matrix Market file format is supported. *) TSparseFormat = ( (*Matrix Market file format.*)spfMatrixMarket); (*Defines how to solve the matrix using the Solve method.*) TSparsePattern = ( (*The matrix pattern will be analyzed, the upper triangle matrix will be formed and the system will be solved. In this case the pattern of matrix changes with each iteration.*) sppNone, (*The matrix pattern will be analyzed only with the first call to the method. In this case the pattern of the matrix is fixed, but the values can change between consecutive calls to the Solve method. To reset the stored pattern of the matrix and prepare for a new pattern, call the FreeSymbolic method.*) sppSymbolic, (**) sppNumericIterative, (*The matrix pattern and the values of the matrix will remain fixed. The method will only call the routine to solve the upper triangular matrix. The pattern analysis and matrix factorization will be performed only on the first call to the Solve method. To reset the matrix factorization call the method. To also reset the matrix pattern, call the method after . Both Symbolic and Numeric states are freed automatically when the property is changed to sppNone.*) sppNumeric ); (*Defines which method will be used to solve system of equations.*) TSparseSolver = ( (*Use one of the iterative methods.*)ssIterative, (*Use UMF Pack library.*)ssUmfPack, (*Use the Pardiso library.*)ssPardiso, (*Use the TAUCS library.*)ssTaucs); (*The method for iterative solver.*) TIterativeMethod = ( (*Gauss-Seidel method iterative sparse Ax=b solver.*)itmSGS, (*Solve a symmetric positive definite linear system Ax=b using the incomplete Cholesky preconditioned conjugate gradient method.*) itmICCG, (*Solve a general linear system Ax=b using the incomplete LU decomposition with iterative refinement.*) itmILUR, (*Solve a general linear system Ax=b using Jacobi iteration.*) itmJAC, (*Solve a linear system Ax=b using the BiConjugate gradient method with incomplete LU decomposition preconditioning.*) itmLUBC, (*Solve a general linear system Ax=b using the incomplete LU decomposition with the Conjugate Gradient method applied to the normal equations, viz., AA'y=b, x=A'y.*) itmSLUCN, (*Solve a linear system Ax=b using the BiConjugate Gradient method with incomplete LU decomposition pre conditioning.*) itmLUCS, (*This routine uses the generalized minimum residual (GMRES) method with pre conditioning to solve non-symmetric linear systems of the form: A*x=b.*) itmLUGMRES, (*Solve a general linear system A*x=b using the preconditioned orthomin method.*) itmLUOM ); (*The detail of the report generated by method. Note: Used only by UMFPack solver. *) TReportLevel = ( (*Leave everything out of report.*)prlNone, (*Include only errors in the report.*)prlErrorsOnly, (**)prlBasic, (**)prlExtensive, (**)prlComplete, (*Include full report.*)prlAll ); (*The criteria for convergence check.*) TConvergenceCheck = ( (*Iteration stops when the 2-norm of the residual divided by the 2-norm of the right-hand side is less than the value of the Tolerance property.*) cvcNorm2, (*Iteration stops when the 2-norm of M-inv times the residual divided by the 2-norm of M-inv times the right hand side is less than then value of Tolerance property, where M-inv is the inverse of the diagonal of A.*) cvcNorm2InvA ); (*The reordering method for Pardiso solver.*) TPardisoReordering = ( (**)prMinimumDegree, (*Use METIS nested dissection method.*)prMETIS, (*Parallel nested dissection.*) prParallel ); (*Iterative solution refinment for Pardiso solver.*) TPardisoIterative = ( (*The factorization is always computed as required by "phase".*)piNone, (*CGS iteration replaces the computation of LU.*)piCG, (*CGS iteration for symmetric positive definite matrices replaces the computation of LU*)piCGS ); (*Parallel factorization control.*) TParallelFactorization = ( (*Classic algorithm.*)pfClassic, (*Two-level factorization algorithm. Usefull when using more than 8 threads.*)pfTwoLevel ); (*Parallel solve control.*) TParallelForwardBackward = ( (*Sequential forward and backward solve.*) pfbSequential, (*Parallel solve step for in-core variant.*) pfbParallelIncore, (*Parallel forward and backward substition.*) pfbParallel ); (*Out-of core sparse matrix solver. The OOC PARDISO can solve very large problems by holding the matrix factors in files on the disk. Because of that the amount of main memory required by OOC PARDISO is significantly reduced. By default, the OOC PARDISO uses the current directory for storing data. All temporary data files can be deleted or stored when the calculations are completed in accordance with the value of the environmental variable MKL_PARDISO_OOC_KEEP_FILE. If it is set to 1 (default value) - all files are deleted, if it is set to 0 - all files are stored. OOC parameters can be set in the configuration file. You can set the path to this file and its name via environmental variable MKL_PARDISO_OOC_CFG_PATH and MKL_PARDISO_OOC_CFG_FILE_NAME. By default, the OOC PARDISO uses the current directory for storing data, and all work arrays associated with the matrix factors are stored in files named ooc_temp with different extensions. These default values can be changed by using the environmental variable MKL_PARDISO_OOC_PATH. To set the environmental variables: * MKL_PARDISO_OOC_MAX_CORE_SIZE, * MKL_PARDISO_OOC_KEEP_FILE, and * MKL_PARDISO_OOC_PATH, the configuration file should be created with the following lines: * MKL_PARDISO_OOC_PATH = path\ooc_file * MKL_PARDISO_OOC_MAX_CORE_SIZE = N * MKL_PARDISO_OOC_KEEP_FILE = 0 (or 1), where * "path" - is the directory for storing data, * ooc_file - file name without extension, * N - memory size in MBytes, It is not recommended to set this value greater than the size of the available RAM (default value - 2000 MBytes). Alternatively the environment variables can be set via command line: * set MKL_PARDISO_OOC_PATH = path\ooc_file * set MKL_PARDISO_OOC_MAX_CORE_SIZE = N * set MKL_PARDISO_OOC_KEEP_FILE = 0 (or 1) *) TOutofCoreMode = ( (*Out of core solver is not used.*)pooNone, (*Out of core solver is used, if more than the amount of prespecified memory is required. The in-core PARDISO is used if the total memory (in MBytes) needed for storing the matrix factors is less than the value of the environment variable MKL_PARDISO_OOC_MAX_CORE_SIZE (it's default value is 2000), and OOC PARDISO is used otherwise.*) pooAutomatic, (*Out of core is used always.*) pooAlways ); TSparseMtx = class; TPardisoWork = class public nrhs, FCols: integer; IsAllocated: boolean; IParam: TIntegerArray; WorkMtx: TSparseMtx; Symbolic: boolean; Numeric: boolean; (*Pointer to pardiso object.*) Pt: TIntegerArray; function CheckError(Err: integer): string; constructor Create; destructor Destroy; override; end; (*Class encapsulates Pardiso sparse solver specific settings. *) TPardisoSettings = class(TPersistent) strict private FIterativeStep: TPardisoIterative; FMatrixNumber: integer; FMaxFactorizedMatrices: integer; FCpuCount: integer; FReordering: TPardisoReordering; FPivotingPerturbation: integer; FSymmetricScalingAndMatching: boolean; FSymmetricBunchKaufmanPivot: boolean; FOutOfCoreMode: TOutofCoreMode; FTranspose: TMtxOperation; FParallelFactorization: TParallelFactorization; FParallelForwardBackward: TParallelForwardBackward; procedure SetMatrixNumber(const Value: integer); procedure SetMaxFactorizedMatrices(const Value: integer); procedure SetCpuCount(const Value: integer); procedure SetReordering(const Value: TPardisoReordering); procedure SetIterativeStep(const Value: TPardisoIterative); procedure SetPivotingPerturbation(const Value: integer); procedure SetSymmetricScalingAndMatching(const Value: boolean); procedure SetSymmetricBunchKaufmanPivot(const Value: boolean); procedure SetOutOfCoreMode(const Value: TOutofCoreMode); procedure SetTranspose(const Value: TMtxOperation); procedure SetParallelFactorization(const Value: TParallelFactorization); procedure SetParallelForwardBackward(const Value: TParallelForwardBackward); public (*Class constructor.*) constructor Create; destructor Destroy; override; published (*Maximum number of factors with identical nonzero sparsity structure. It is possible to store several different factorizations with the same nonzero structure at the same time in the internal data management of the solver. In most of the applications this value is equal to 1. *) property MaxFactorizedMatrices: integer read FMaxFactorizedMatrices write SetMaxFactorizedMatrices; (*Actual matrix for the solution phase. With this scalar you can define the matrix that you would like to factorize. *) property MatrixNumber: integer read FMatrixNumber write SetMatrixNumber; (*The number of CPU's in the system. Must match the OpenMP system environment variable and the number must be equal to the MKL environment variable MKL_NUM_THREADS *) property CpuCount: integer read FCpuCount write SetCpuCount; (*Defines the fill-in reducing reordering algorithms to use.*) property Reordering: TPardisoReordering read FReordering write SetReordering; (*Defines if iterative CG/CGS factorization should be attempted. Defines if previous numeric factorization should be used as the initial solution for first CG step for iterative factorization. *) property IterativeStep: TPardisoIterative read FIterativeStep write SetIterativeStep; (*Specifies how to handle small pivots. Defines an Eps as 10^(-PivotingPerturbation). This eps is then used to determine the magnitude of a potential pivot. A setting of -1 defines a default value of 13 for general and 8 for symmetric matrices. *) property PivotingPerturbation: integer read FPivotingPerturbation write SetPivotingPerturbation; (*If true, iproves accuracy for symmetric indefinite matrices.*) property SymmetricScalingAndMatching: boolean read FSymmetricScalingAndMatching write SetSymmetricScalingAndMatching; (*Potentially improves accuracy for symmetric matrices by using Bunch-Kaufman pivoting.*) property SymmetricBunchKaufmanPivot: boolean read FSymmetricBunchKaufmanPivot write SetSymmetricBunchKaufmanPivot; (*Controls Out of core solver behaviour.*) property OutOfCoreMode: TOutofCoreMode read FOutOfCoreMode write SetOutOfCoreMode; (*Defines any additional transposition while computing the solution. *) property Transpose: TMtxOperation read FTranspose write SetTranspose; (*Parallel factorization control. Considered only when SymmetricScalingAndMatching is false. *) property ParallelFactorization: TParallelFactorization read FParallelFactorization write SetParallelFactorization; (*Parallel solve control.*) property ParallelForwardBackward: TParallelForwardBackward read FParallelForwardBackward write SetParallelForwardBackward; end; (*The event type called when user defined stop criteria for iterative sparse solver is requested. The "Stop" parameter should be false to continue iteration and true to stop the iteration. The second dpar parameter is an array with the following contents: * dpar[0] specifies the relative tolerance. The default value is 1.0D-6. * dpar[1] specifies the absolute tolerance. The default value is 0.0D-0. * dpar[2] specifies the Euclidean norm of the initial residual (if it is computed in the dfgmres routine). The initial value is 0.0. * dpar[3] service variable equal to dpar(1)*dpar(3)+dpar(2). The initial value is 0.0. * dpar[4] specifies the Euclidean norm of the current residual. The initial value is 0.0. * dpar[5] specifies the Euclidean norm of residual from the previous iteration step (if available). The initial value is 0.0. * dpar[6] contains the norm of the generated vector for FGMRES. The initial value is 0.0. * dpar[7] contains the tolerance for the zero norm of the currently generated vector for GMRES (Default value is 1.0D-12) and and Alpha parameter for CG with default value of 0. * dpar[8] beta parameter for CG (dpar(5)/dpar(6) with default value of 0. Not used by GMRES. *) TIterativeStopTest = procedure(var Stop: boolean; var dpar: array of double) of object; (*Iterative preconditioner options. Preconditioners can be used to accelerate the iteration process. They are not to be used with Conjugate Gradient (CG) solver. *) TIterativePreconditioner = ( (*Do not use a preconditioner*) itpNone, (*Use ILU0 preconditioner.*) itpILU0, (*Use ILUT preconditioner.*) itpILUT); TIterativeSolverMethod = ( (*Conjugate gradient solver.*) ismCG, (*GMRES solver.*) ismGMRES ); TIterativeSettings = class private FMaxIters: integer; FPreconditioner: TIterativePreconditioner; FOnStopTest: TIterativeStopTest; FSolverMethod: TIterativeSolverMethod; procedure SetMaxIters(const Value: integer); procedure SetOnStopTest(const Value: TIterativeStopTest); procedure SetPreconditioner(const Value: TIterativePreconditioner); procedure SetSolverMethod(const Value: TIterativeSolverMethod); public property SolverMethod: TIterativeSolverMethod read FSolverMethod write SetSolverMethod; property Preconditioner: TIterativePreconditioner read FPreconditioner write SetPreconditioner; property MaxIters: integer read FMaxIters write SetMaxIters; property OnStopTest: TIterativeStopTest read FOnStopTest write SetOnStopTest; end; TPAPCharArray = array of PAPChar; (*Iterative solution refinment for Taucs. Defines the factorization method used by the Taucs sparse solver. *) TTaucsFactorization = ( (*Cholesky factorization.*)tfCholesky, (*LU factorization with partial pivoting.*)tfLU, (*LDL(T) factorization without pivoting.*)tfLDL, (*Multifrontal factorization.*)tfMultiFrontal, (*Left-looking factorization.*)tfLeftLooking ); (*Defines the reordering method used by Taucs.*) TTaucsReordering = ( (**)tpMMD, (**)tpAMD, (**)tpMD, (**)tpMETIS, (**)tpGENMMD, (**)tpCOLAMD, (**)tpRANDOM, (**)tpTREE, (**)tpIdentity ); (*Iterative solution refinment for Taucs.*) TTaucsIterative = ( (*No iterative algorithm is used.*)tiNone, (*Use the Conjugate gradient iterative algoritm to solve sparse equation. The Conjugate gradient is only guaranteed to work on symmetric and positive definite matrices.*) tiCG, (*Use the MinRes algorithm to solve sparse equation. Unlike the Conjugate gradient method this one requires only a symmetric matrix.*) tiMinRes ); TTaucsWork = class public POptions: TPAPCharArray; POptionCount: integer; StoredFactorization: integer; procedure AppendOption(const Param: string); procedure ClearOption; function CheckError(Err: integer): string; constructor Create; destructor Destroy; override; end; (*Class encapsulates Taucs sparse solver specific settings.*) TTaucsSettings = class(TPersistent) strict private FIterativeStep: TTaucsIterative; FOutOfCore: boolean; FOutOfCoreFileName: string; FFactor: TTaucsFactorization; FReordering: TTaucsReordering; FAmwb: boolean; FAmwbSubGraphs: integer; FAmwbRandomSeed: integer; FInCoreMemoryAuto: boolean; FInCoreMemorySize: integer; FCustomOptions: TStringList; procedure SetCustomOptions(const Value: TStringList); procedure SetFactor(const Value: TTaucsFactorization); procedure SetReordering(const Value: TTaucsReordering); procedure SetOutOfCore(const Value: boolean); procedure SetOutOfCoreFileName(const Value: string); procedure SetIterativeStep(const Value: TTaucsIterative); procedure SetAmwb(const Value: boolean); procedure SetAmwbRandomSeed(const Value: integer); procedure SetAmwbSubGraphs(const Value: integer); procedure SetInCoreMemoryAuto(const Value: boolean); procedure SetInCoreMemorySize(const Value: integer); public (*Virtual constructor*) constructor Create; virtual; destructor Destroy; override; published property CustomOptions: TStringList read FCustomOptions write SetCustomOptions; (*Specifies the factorization method to use. Note: Not all methods support all matrix types! *) property Factor: TTaucsFactorization read FFactor write SetFactor; (*Use Out Of Core factorization. If True, the factorization process will use the disk as data storage. This can improve the speed of the solver in compare to using the Windows virtual memory, when memory requirements are really big (10s of GB), or when trying to address more then 2GB of memory. *) property OutOfCore: boolean read FOutOfCore write SetOutOfCore; (*Factorization data filename. Specifies the Filename (and path) of where to store the factorization data files sliced in to pieces of 1GB each. This file name is used only when OutOfCore is set to True. *) property OutOfCoreFileName: string read FOutOfCoreFileName write SetOutOfCoreFileName; (*Defines the in-core memory size to use in bytes. *) property InCoreMemorySize: integer read FInCoreMemorySize write SetInCoreMemorySize; (* If True in-core memory size used is determined automatically. If False in-core memory size used by the out-of-core solver is NOT determined automatically. *) property InCoreMemoryAuto: boolean read FInCoreMemoryAuto write SetInCoreMemoryAuto; (*Defines the fill-in reducing reordering algorithms to use.*) property Reordering: TTaucsReordering read FReordering write SetReordering; (*Defines if and which iterative CG/MinRes factorization should be attempted. The defines the maximum number of iterations and the requested accuracy. *) property IterativeStep: TTaucsIterative read FIterativeStep write SetIterativeStep; (*Set it to true to enable maximum-weight-basis Vaidha preconditioners.*) property Amwb: boolean read FAmwb write SetAmwb; (*Desired number of graphs in the tree partitioning. Used only if is True. *) property AmwbSubGraphs: integer read FAmwbSubGraphs write SetAmwbSubGraphs; (*Random seed between 0 and High(Integer)-1. Used only if is True. *) property AmwbRandomSeed: integer read FAmwbRandomSeed write SetAmwbRandomSeed; end; (*Encapsulates sparse matrix properties and methods/operations. The class encapsulates sparse matrix properties and methods/operations like sparse matrix addition, subtraction, multiplication, mixed operations with dense vectors and matrices, three types of sparse linear system solvers: * Umfpack, * Pardiso * Iterative The class also includes different matrix storage format conversion methods and more... *) TSparseMtx = class(TMtxVec ) strict private fTaucs: TTaucsSettings; fTaucsWork: TTaucsWork; fPardiso: TPardisoSettings; fPardisoWork: TPardisoWork; FSparseSolver: TSparseSolver; TripletsRow, TripletsColumn: TIntegerArray; TripletsValues: TDoubleArray; TripletsCValues: TCplxArray; TripletsSValues: TSingleArray; TripletsSCValues: TSCplxArray; TripletRowCount, TripletColCount,TripletsCount: integer; FRefinmentIters: integer; FIterativeMethod: TIterativeMethod; FSparseSystem: TSparseSystem; FMtxError: string; FAutoPattern: boolean; FReportLevel: TReportLevel; FConvergenceCheck: TConvergenceCheck; FTolerance: double; FMaxIters: integer; FActualIters: integer; FVectorCount: integer; FAutoClearReport: boolean; FRows: integer; FCols: integer; FBackError: double; FSparseBlockSize: integer; FDontStripZeros: boolean; FSparsePattern: TSparsePattern; procedure SetIterativeMethod(const Value: TIterativeMethod); procedure SetRefinmentIters(const Value: integer); procedure SetSparseSystem(const Value: TSparseSystem); procedure SetMtxError(const Value: string); procedure SetAutoPattern(const Value: boolean); procedure SetReportLevel(const Value: TReportLevel); procedure UmfErrorCheck(Status: integer; aName: string; Control, Info: TDoubleArray; Report: boolean = False; NoInfo: boolean = false); overload; procedure UmfErrorCheck(Status: integer; aName: string; sControl, sInfo: TSingleArray; Report: boolean = False; NoInfo: boolean = false); overload; procedure SetConvergenceCheck(const Value: TConvergenceCheck); procedure SetTolerance(const Value: double); procedure SetActualIters(const Value: integer); procedure SetMaxIters(const Value: integer); procedure SetVectorCount(const Value: integer); procedure SetAutoClearReport(const Value: boolean); procedure SetCols(const Value: integer); procedure SetRows(const Value: integer); procedure SetBackError(const Value: double); procedure SetSparseBlockSize(const Value: integer); procedure InternalTripletsToSparse(RowCount, ColCount: integer; const Row, Column: TIntegerArray; const aCValues: TCplxArray; const aValues: TDoubleArray; Threshold: double = 0; PreserveZeroDiagElem: boolean = true); procedure InternalTripletsToSparseS(RowCount, ColCount: integer; const Row, Column: TIntegerArray; const aCValues: TSCplxArray; const aValues: TSingleArray; Threshold: double = 0; PreserveZeroDiagElem: boolean = true); procedure SetDontStripZeros(const Value: boolean); procedure SetSparsePattern(const Value: TSparsePattern); procedure SetSparseSolver(const Value: TSparseSolver); strict protected function GetValue(ARow, ACol: integer): double; procedure SetValue(ARow, ACol: integer; const Value: double); procedure SetMtxCValue(ARow, ACol: integer; const CValue: TCplx); function GetMtxCValue(ARow, ACol: integer): TCplx; function GetSValue(ARow, ACol: integer): single; procedure SetSValue(ARow, ACol: integer; const Value: single); procedure SetMtxSCValue(ARow, ACol: integer; const CValue: TSCplx); function GetMtxSCValue(ARow, ACol: integer): TSCplx; strict protected Symbolic: PAPointer; Numeric: PAPointer; property AutoPattern: boolean read FAutoPattern write SetAutoPattern; procedure DoSetCols(Sender: TObject); procedure LoadFromHarwellBoeingFile(const FileName: string); procedure SaveToHarwellBoeingFile(const FileName: string); procedure DoSetComplex; override; procedure setActualSize(const byteCount: Int64); override; procedure SolveUmfPack(const B, X: TVec); overload; procedure SolveTaucs(const B, X: TVec; MtxType: TMtxType); overload; procedure SolveTaucs(const B, X: TMtx; MtxType: TMtxType); overload; procedure SolveTaucsInternal(const B, X: TDenseMtxVec; MtxType: TMtxType; nrhs: integer); overload; procedure SolveUmfPack(const B, X: TMtx); overload; procedure SolvePardiso(const B, X: TVec; MtxType: TMtxType); overload; procedure SolvePardiso(const B, X: TMtx; MtxType: TMtxType); overload; procedure SolveIterative2(const B, X: TVec; MtxType: TMtxType); overload; procedure SolveIterative2(const B, X: TMtx; MtxType: TMtxType); overload; procedure SolvePardisoInternal(const B, X: TDenseMtxVec; MtxType: TMtxType; nrhs: integer); overload; function MtxTypePardiso(MtxType: TMtxType): integer; function MtxTypeTaucs(MtxType: TMtxType): integer; procedure SetPardiso(Value: TPardisoSettings); procedure SetTaucs(Value: TTaucsSettings); function InternalRMS: double; function InternalEig(const D, R: TVec; const V: TMtx; EigCount: integer; Smallest, IsSymmetric: boolean; const fpm: TIntegerArray): integer; function InternalEigGen(const bB: TSparseMtx; const D, R: TVec; const V: TMtx; EigCount: integer; Smallest, IsSymmetric: boolean; const fpm: TIntegerArray): integer; function InternalSvd(const S, R: TVec; const VL, VR: TMtx; SvdCount: integer; Smallest, IsSymmetric: boolean; const fpm: TIntegerArray): integer; procedure SubRangeSaveState; override; procedure SetSubRangeDirect(Index, Len: integer); override; procedure SetSubRangeDirect(const Src: TMtxVecBase; Index, Len: integer); override; procedure UmfpackFreeSymbolic; procedure UmfpackFreeNumeric; procedure PardisoFreeSymbolic; procedure PardisoFreeNumeric; procedure SetLength(const Value: integer); override; public (**) Ap: TIntegerArray; (**) Ai: TIntegerArray; (**) Control: TDoubleArray; SControl: TSingleArray; (**) Info: TDoubleArray; SInfo: TSingleArray; (*Defines the pattern used when solving a system of linear equations. Use this property to instruct the linear system solver which of the results from the previous sparse system solution can be reused. This can be symbolic factorization and/or numeric factorization. *) property SparsePattern: TSparsePattern read FSparsePattern write SetSparsePattern; (*Holds the error string, if an error has occurred. Holds the error string, if an error has occurred. If there was no error, the string is empty. *) property MtxError: string read FMtxError write SetMtxError; (*Returns the number of actual iterations performed by . Returns the number of actual iterations performed by . After running direct solver ( method) with active iterative refinement ( bigger than 0) or iterative solvers ( method), the ActualInters property contains the actual number of iterations performed. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples { private void Example() { Vector x = new Vector(0); Vector b = new Vector(0); TSparseMtx sparseM = new TSparseMtx(); x.size(b); sparseM.SolveIterative(b,x); int iters = sparseM.ActualIters; } } *) property ActualIters: integer read FActualIters write SetActualIters; (*Holds the backward or iterative stopping criteria. After running direct solver ( method) with active iterative refinement ( > 0) the property holds the backward error. In case of iterative solvers ( method), the property holds the error according to the stoping criteria (see property). *) property BackError: double read FBackError write SetBackError; (*Allows setting and getting value at position Row and Col. Allows setting and getting value at position Row and Col. This property is to be used to form a new sparse matrix only. See the method, on how to use this property. This property should not be used to access individual values of a sparse matrix. To access individual values, the following pattern can be used: for i := 0 to SparseMtx.Cols-1 do for j := SparseMtx.ap[i] to SparseMtx.ap[i+1]-1 do begin aRow := SparseMtx.ai[j]; aValue := SparseMtx.Values[j]; //... The aValue is stored at i'th column and aRow //i'th column values are stored in the Values array from index ap[i] to ap[i+1] //the row indices for the i'th column are stored in the Ai array end; *) property Value[Row, Col: integer]: double read GetValue write SetValue; default; (*Allows setting and getting double precision complex values.*) property CValue[Row, Col: integer]: TCplx read GetMtxCValue write SetMtxCValue; (*Allows setting and single precision values.*) property SValue[Row, Col: integer]: single read GetSValue write SetSValue; (*Allows setting and getting single precision complex values.*) property SCValue[Row, Col: integer]: TSCplx read GetMtxSCValue write SetMtxSCValue; public (*Copies sparse matrix from Src to the calling object.*) procedure Copy(const Src: TSparseMtx; StripZeros: boolean = false); overload; (*Copies sparse matrix from Src to the calling object.*) procedure CopyTo(const Dst: TSparseMtx; const aFloatPrecision: TMtxFloatPrecision); overload; procedure Assign(Source: TPersistent); override; (*Sums two sparse matrices (A+B). Sum sparse matrices A and B and place the result in the calling sparse matrix. Because the resulting matrix can be much less sparse, the memory requirements can increase beyond the available system memory. An exception will be raised if if the requested memory size will exceed the value of . *) procedure Add(const A, B: TSparseMtx; MaxNonZeroCount: integer = 10000000); overload; (*Add the content of the calling sparse matrix to the dense matrix Y.*) procedure Add(const Y: TMtx); overload; (*Construct sparse matrxix by summing lower, upper triangluar part and the diagonal. Sums up the sparse matrix from its three parts: The lower triangle (LowerTriang), main diagonal (Diag) and upper triangle (UpperTriang). using Dew.Math; using Dew.Math.Units; namespace Dew.Examples { private void Example() { Vector d = new Vector(0); TSparseMtx asp = new TSparseMtx(); TSparseMtx bsp = new TSparseMtx(); TSparseMtx csp = new TSparseMtx(); TSparseMtx dsp = new TSparseMtx(); // ... // #1 : split asp into lower(bsp), upper(csp) and diagonal(d) sections bsp.LowerTriangle(asp); csp.UpperTriangle(asp); asp.Diag(d); // now combine lower(bsp), upper, and diagonal(d) back dsp.AddSplit(bsp,d,csp); } } *) procedure AddSplit(const LowerTriang: TSparseMtx; const Diag: TVec; const UpperTriang: TSparseMtx); overload; (*Sums up the sparse matrix from its lower (LoweTriang) and upper triangle (UpperTriang).*) procedure AddSplit(const LowerTriang, UpperTriang: TSparseMtx); overload; (*Adjungate operation. Adjungate X and store the results in calling sparse matrix. *) function Adjung(const X: TSparseMtx): TSparseMtx; overload; (*Converts banded matrix to modified compressed column sparse matrix format. Converts banded matrix Src to modified compressed column sparse matrix format. *) procedure BandedToSparse(const Src: TMtx; ZeroThreshold: double = 0); (*Conjugate Sparse2 and matrix multiply it with Sparse1. Conjugate Sparse2, multiply it with Sparse1 and store the results in calling sparse matrix. *) function ConjMul(const Sparse1, Sparse2: TSparseMtx; MaxNonZeroCount: integer = 10000000): TSparseMtx; overload; procedure Clear; override; (*Copies the kk-th diagonal of TSparseMtx to the Vec object. Copies the kk-th diagonal of TSparseMtx to the Vec object. If k = 0 then the main diagonal matrix is obtained, if k < 0 then the k-th subdiagonal matrix is obtained and if k > 0 the then the k-th super diagonal is copied to Vec. The Vec parameters size is set automatically. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples { private void Example() { Vector d = new Vector(0); TSparseMtx asp = new TSparseMtx(); TSparseMtx bsp = new TSparseMtx(); TSparseMtx csp = new TSparseMtx(); TSparseMtx dsp = new TSparseMtx(); // ... // #1 : split asp into lower(bsp), upper(csp) and diagonal(d) sections bsp.LowerTriangle(asp); csp.UpperTriangle(asp); asp.Diag(d); // now combine lower(bsp), upper, and diagonal(d) back dsp.AddSplit(bsp,d,csp); } } *) procedure Diag(const Vec: TVec; kk: integer = 0); overload; (*Calculates the number of diagonals above and below main diagonal. Calculates the number of diagonals above (Upper) and below (Lower) the main diagonal. This information is used by the method. *) procedure DiagonalsCount(out Upper, Lower: integer); (*Convert dense matrix to sparse matrix format. Convert dense matrix A to modified compressed column sparse matrix format. Step 1: Construct dense matrix, var A,B: Matrix; SparseA: TSparseMtx; /// ... A.SetIt(3,3,false,[1,0,0,0,2,0,0,1,3]); Step 2: Convert dense matrix to sparse matrix /// ... SparseA.DenseToSparse(A); Step 3: Convert sparse matrix back to dense and compare /// ... SparseA.SparseToDense(B); if not A.Equal(B,1.0e-5) then ERaise('Not Equal!'); *) procedure DenseToSparse(const A: TMtx; ZeroThreshold: double = 0; PreserveZeroDiagElem: boolean = true); (*Divide individual elements of sparse matrices. Divide individual elements of the calling object with the Sparse matrix. The sparsitiy pattern of both matrices is assumed to be equal. *) function DivideElem(const Sparse: TSparseMtx): TSparseMtx; overload; (*Compares two sparse matrices. Compare B with calling sparse matrix. Defines the comparison tolerance. The maximum difference between elements may not exceed: +/-Tolerance. If Tolerance is omitted, a direct comparison algorithm is used. true, if the calling matrix is equal to sparse B matrix (if all elements match in position and value).*) function Equal(const B: TSparseMtx; Tolerance: double = 0): boolean; overload; (*Compares two sparse matrices. true, if the calling matrix is equal to dense B matrix (if all elements match in position and value). Tolerance defines the comparison tolerance. The maximum difference between elements may not exceed: +/-Tolerance. If Tolerance is omitted, a direct comparison algorithm is used. If NonZerosOnly is True then only the non-zero values of the calling sparse matrix are compared with corresponding values in the dense matrix. *) function Equal(const B: TMtx; Tolerance: double = 0; NonZerosOnly: boolean = False): boolean; overload; (*Frees the numeric object used by the Umfpack. Frees the numeric object used by the Umfpack and thus releases the associated memory. *) procedure FreeNumeric; (*Frees the symbolic object used by the Umfpack. Frees the symbolic object used by the Umfpack and thus releases the associated memory. *) procedure FreeSymbolic; procedure FreeToCache; override; (*Resizes the sparse matrix to a new number of non-zeros. Resizes the sparse matrix to a new number of non-zeros. The existing values are preserved up to the new size. This includes the sparsity pattern arrays Ai and Ap. This resize does not change the number of Columns of the sparse matrix, but only the number of non-zeros that can be stored in the matrix. *) function Resize(Len: integer; ZeroIt: boolean = False): TMtxVec; overload; (*The inverse matrix. Calculates the inverse (Mtx^-1) of the calling matrix and stores the result in Y dense matrix. If the calling matrix is not quadratic, an exception is raised. *) procedure Inv(const Y: TMtx); (*Compares matrix size. true if Sparse sparse matrix , , and properties match those of calling sparse matrix. SparseA.Size(3,4,3,false); SparseB.Size(3,4,1,false); if SparseA.IxEqualSize(SparseB) then Console.WriteLine("Equal size"); else Console.WriteLine("Not equal size"); *) function IsEqualSize(const Sparse: TSparseMtx): boolean; virtual; (*Extract lower part of the Mtx. Copies only the lower triangular part of the Src sparse matrix. The result is stored in the calling sparse matrix. If the Diagonal boolean parameter is true then the Src matrix main diagonal elements will be copied to the calling matrix main diagonal elements. If the Diagonal parameter is false, the calling matrix main diagonal elements will be set to zero. using Dew.Math; using Dew.Math._Units; void Example() { Vector d = new Vector(0); TSparseMtx asp = new TSparseMtx(); TSparseMtx bsp = new TSparseMtx(); TSparseMtx csp = new TSparseMtx(); TSparseMtx dsp = new TSparseMtx(); // ... // #1 : split asp into lower(bsp), upper(csp) and diagonal(d) sections bsp.LowerTriangle(asp); csp.UpperTriangle(asp); asp.Diag(d); // now combine lower(bsp), upper, and diagonal(d) back dsp.AddSplit(bsp,d,csp); // should be equal if (!asp.Equal(dsp)()) Console.WriteLine("Not equal!"); } *) function LowerTriangle(const Src: TSparseMtx; Diagonal: boolean = false): TSparseMtx; overload; (*Multiply two sparse matrices (matrix multiplication). Multiply sparse matrices A and B and place the result in the calling matrix. Because the resulting matrix can be much less sparse, the memory requirements can increase beyond the available system memory. This method will raise an exception, if the requested memory size will exceed the value of . Multiply SparseA and SparseB where maximum number of non-zero elements is estimated at 100. SparseC.Mul(SparseA,SparseB, 100); *) procedure Mul(const C, B: TSparseMtx; MaxNonZeroCount: integer = 10000000); overload; (*Multiply the sparse matrix from left. Multiply calling sparse matrix from left with dense matrix X and place the result in dense matrix Y. Matrix a= new Matrix(3,2); Matrix b = new Matrix(2,3); TMtxSparse aSparse = new TMtxSparse(); aSparse.MulLeft(a,b); // result is stored in b *) procedure MulLeft(const X, Y: TMtx); overload; (*Multiply sparse matrix from left with vector X and place the result in vector Y.*) procedure MulLeft(const X, Y: TVec); overload; (*Multiply the sparse matrix from right. Multiply calling sparse matrix from right with dense matrix X and place the result in dense matrix Y. Matrix a= new Matrix(3,2); Matrix b = new Matrix(2,3); TMtxSparse aSparse = new TMtxSparse(); aSparse.MulRight(a,b); // result is stored in b *) procedure MulRight(const X, Y: TMtx); overload; (*Multiply sparse matrix from right with vector X and place the result in vector Y.*) procedure MulRight(const X, Y: TVec); overload; (*Root mean squared of all non-zero elements.*) function RMS: double; reintroduce; overload; (*Minimum of all non-zero elements. *) function Min: double; overload; (*Maximum of all non-zero elements. *) function Max: double; overload; (*Average of all non-zero elements.*) function Mean: double; overload; (*Minimum of all non-zero complex elements. *) function Minc: TCplx; overload; (*Maximum of all non-zero complex elements. *) function Maxc: TCplx; overload; (*Average of all non-zero complex elements. *) function Meanc: TCplx; overload; (*The size of sparse matrix. Defines the calling matrix size to match those of the AMtxVec objects. If AComplex is true, calling sparse matrix property is set to true. SparseA.Size(3,4,5,false); // is the same as calling this sequence SparseA.Complex = false; SparseA.Rows = 3; SparseA.Cols = 4; SparseA.NonZeros = 5; *) function Size(const Src: TMtxVecBase; AComplex: boolean): TMtxVec; override; (*Sets sparse matrix size to match Src with new aFloatPrecision.*) function Size(const Src: TMtxVecBase; const aFloatPrecision: TMtxFloatPrecision): TMtxVec; override; (*Define sparse matrix size in single pass. Define the sparse matrix size to RowCount , ColCount , NonZeroCount non-zero elements (the property) and define the matrix to be complex if IsComplex is true. *) procedure Size(const RowCount, ColCount, NonZeroCount: integer; const aFloatPrecision: TMtxFloatPrecision); overload; procedure Size(const RowCount, ColCount, NonZeroCount: integer; const aComplex: boolean; const aIsDouble: boolean); overload; procedure Size(const RowCount, ColCount, NonZeroCount: integer; const IsComplex: boolean); overload; (*Direct solve. Solve the system A*X = B, where A is the calling matrix. The actual system being solved is defined by property. A is sparse and unsymmetric. It is based on the Unsymmetric MultiFrontal method, which factorizes PAQ into the product LU, where L and U are lower and upper triangular, respectively, and P are Q are permutation matrices. Both P and Q are chosen to reduce fill-in (new nonzeros in L and U that are not present in A). The permutation P has the dual role of reducing fill-in and maintaining numerical accuracy (via relaxed partial pivoting and row interchanges). The Solve method uses BLAS level 3 dgeem matrix multiply routine and takes full advantage of CPU specific optimized code and symmetric multiprocessing. uses MtxExpr, MtxVecTee, Sparse; procedure Example; var x,b: Vector; SparseA: TSparseMtx; begin // load data SparseA.LoadFromMatrixFile('system.mtx'); b.LoadFromFile('coefficients.Vec'); // set solution size x.Size(b); // solve SparseA.SparseSolver := ssUmfPack; SparseA.Solve(b,x); //view solution ViewValues(x); end; #include "MtxExpr.hpp" #include "Sparse.hpp" #include "MtxVecTee.hpp" void __fastcall Example() { sVector x,b; TSparseMtx *SparseA = new TSparseMtx(); try { // load data SparseA->LoadFromMatrixFile("system.mtx"); b->LoadFromFile("coefficients.Vec"); // set solution size x->Size(b); // solve SparseA->SparseSolver = ssUmfPack; SparseA->Solve(b,x); //view solution ViewValues(x); } __finally { delete SparseA; } } *) procedure Solve(const B,X: TMtx; MtxType: TMtxType = mtGeneral); overload; (*Vector version of Solve.*) procedure Solve(const B,X: TVec; MtxType: TMtxType = mtGeneral); overload; (*Solve the system A*X = B by using one of the iterative methods. The term "iterative method" refers to a wide range of techniques that use successive approximations to obtain more accurate solutions to a linear system at each step. There are two major groups of iterative methods: stationary and nonstationary methods. Stationary methods are older, simpler to understand and implement, but usually not as effective. Nonstationary methods are a relatively recent development; their analysis is usually harder to understand, but they can be highly effective. The nonstationary methods are based on the idea of sequences of orthogonal vectors. The rate at which an iterative method converges depends greatly on the spectrum of the coefficient matrix. Hence, iterative methods usually involve a second matrix that transforms the coefficient matrix into one with a more favorable spectrum. The transformation matrix is called a pre conditioner. A good precondition improves the convergence of the iterative method, sufficiently to overcome the extra cost of constructing and applying the pre conditioner. Indeed, without a pre conditioner the iterative method may even fail to converge. Non stationary methods: Conjugate Gradient (CG) The conjugate gradient method derives its name from the fact that it generates a sequence of conjugate (or orthogonal) vectors. These vectors are the residuals of the iterates. They are also the gradients of a quadratic functional, the minimization of which is equivalent to solving the linear system. CG is an extremely effective method when the coefficient matrix is symmetric positive definite, since storage for only a limited number of vectors is required. Conjugate Gradient on the Normal Equations These methods are based on the application of the CG method to one of two forms of the normal equations for Ax = b. CGNE solves the system (AA T )y = b for y and then computes the solution x = A'y. When the coefficient matrix A is nonsymmetric and nonsingular, the normal equations matrices AA' and A'A will be symmetric and positive definite, and hence CG can be applied. The convergence may be slow, since the spectrum of the normal equations matrices will be less favorable than the spectrum of A. Generalized Minimal Residual (GMRES) The Generalized Minimal Residual method computes a sequence of orthogonal vectors (like minimum residual), and combines these through a least-squares solve and update. However, unlike MINRES (and CG) it requires storing the whole sequence, so that a large amount of storage is needed. For this reason, restarted versions of this method are used. In restarted versions, computation and storage costs are limited by specifying a fixed number of vectors to be generated. This method is useful for general nonsymmetric matrices. BiConjugate Gradient (BiCG) The Biconjugate Gradient method generates two CG-like sequences of vectors, one based on a system with the original coefficient matrix A, and one on A T . Instead of orthogonalizing each sequence, they are made mutually orthogonal, or "bi-orthogonal". This method, like CG, uses limited storage. It is useful when the matrix is nonsymmetric and nonsingular; however, convergence may be irregular, and there is a possibility that the method will break down. BiCG requires a multiplication with the coefficient matrix and with its transpose at each iteration. Stationary methods: (converge very slow and are provided only as a reference) Jacobi The Jacobi method is based on solving for every variable locally with respect to the other variables; one iteration of the method corresponds to solving for every variable once. The resulting method is easy to understand and implement, but convergence is slow. Gauss-Seidel The Gauss-Seidel method is like the Jacobi method, except that it uses updated values as soon as they are available. In general, if the Jacobi method converges, the Gauss-Seidel method will converge faster than the Jacobi method, though still relatively slowly. Reference: Templates for the Solution of Linear Systems: Building Blocks for Iterative Methods 1, R. Barrett, M. Berry, T. F. Chan, J. Demmel, J. Donato, J. Dongarra, V. Eijkhout, R. Pozo, C. Romine, and H. Van der Vorstg , SIAM, 1994, Philadelphia, PA. { TMtxSparse SparseA = new TMtxSparse(); Vector x = new Vector(0); Vector b = new Vector(0); // load data SparseA.LoadFromMatrixFile("system.mtx"); b.LoadFromFile("coefficients.Vec"); // set solution size x.Size(b); // define iterative method - in this case Jacobi iterative method SparseA.RefinementIters = 4; SparseA.IterativeMethod = itmJAC; // solve SparseA.SolveIterative(b,x); // view solution MtxVecEdit.ViewValues(x); } *) procedure SolveIterative(const B,X: TMtx; Symmetric: boolean = false); overload; (*Vector version of SolveIterative.*) procedure SolveIterative(const B,X: TVec; Symmetric: boolean = false); overload; (* Computes eigenvalues and eigenvectors for symmetric (hermitian) sparse matrix. Returns the eigenvalues. Returns the relative residual vector Contains the relative error on the trace: |trac[i] - trace[i-1]|/Max(|Maximum|, |sMinimum|) Returns the eigenvectors in rows. On Input, the matrix can contain estimate of eigenvectors, otherwise V.Length must be zero. Start of the search interval. Stop of the search interval. Contains estimated eigenvalue on input and actual count on return. Processing parameter list. Leave nil, to use default values. The function will return: 0 on success. 1 no eigenvalues found in search interval. Try to scale up/down the matrix: (A/t) x=(Lambda/t) x 2 in case of no convergence (maximum iteration loops specified in fpm(4) exceeded) 3 There are more eigenvalues present than have been estimated with EigCount To compute all eigenvalues and eigenvectors would require storage equal to the size of the dense matrix. For this reason, the routine allows computation of eigenvectors and eigenvalues only within a specified range. The expected number of eigenvalues within the Interval [Minimum, Maximum] is specified with EigCount. If the function returns with a different EigCount, the initial estimate needs to be adjusted, because there was not enough storage to store the result. The quadratic sparse matrix is expected to store only lower triangular part including the main diagonal. *) function EigSym(const D, R: TVec; const V: TMtx; var EigCount: integer; var EpsOut: double; Minimum, Maximum: double; var fpm: TIntegerArray): integer; overload; (* Computes largest eigenvalues and eigenvectors for symmetric sparse matrix. The sparse matrix must be symmetric and it must use full storage. Important: * The routine does not check, if the matrix is symmetric. * Inclusion of explicit zero valued elements could cause access violation. Returns the eigenvalues. Returns the relative residual vector Returns the eigenvectors in rows. Pass nil for this paramter, if you don't require eigen-vectors, The function will return up to DesiredEigCount largest eigen values. Processing parameter list. Leave nil, to use default values. Alternatively, it is possible to specify an array of parameters "fpm" as the last parameter to the routine (Reference: Intel MKL manual). Optional: processing parameter list. Leave nil, to use default values. If you do pass this parameter, its length must be minimum 129 items. (Reference: Intel MKL manual). "fpm[0]" 0 Reserved for future use. "fpm[1]" 6 Defines the tolerance for the stopping criteria: tol = 10-pm 1 + 1 "fpm[2]" 0 Specifies the algorithm to use: • 0 - Decided at runtime • 1 - The Krylov-Schur method • 2 - Subspace Iteration technique based on FEAST algorithm "fpm[3]" This parameter is referenced only for Krylov-Schur Method. It indicates the number of Lanczos/Arnoldi vectors (NCV) generated at each iteration. This parameter must be less than or equal to size of matrix and greater than number of eigenvalues (k0) to be computed. If unspecified, NCV is set to be at least 1.5 times larger than k0. "fpm[4]" Maximum number of iterations. If unspecified, this parameter is set to 10000 for the Krylov-Schur method and 60 for the subspace iteration method. "fpm[5]" 0 Power of Chebychev expansion for approximate spectral projector. Only referenced when pm[2]=1 "fpm[6]" 1 Used only for Krylov-Schur Method. If 0, then the method only computes eigenvalues. If 1, then the method computes eigenvalues and eigenvectors. The subspace iteration method always computes eigenvectors/singular vectors. You must allocate the required memory space. "fpm[7]" Convergence stopping criteria. "fpm[8]" Specifies if for detecting convergence the solver must compute the true residuals for eigenpairs for the Krylov-Schur method or it can only use the residual norm estimates. If 0, only residual norm estimates are used. If 1, the solver computes not just residual norm estimates but also the true residuals as defined in the description of pm[7]. "fpm[9]" Used only for the Krylov-Schur method and only as an output parameter. Reports the reason for exiting the iteration loop of the method: • If 0, the iterations stopped since convergence has been detected. • If -1, maximum number of iterations has been reached and even the residual norm estimates have not converged. • If -2, maximum number of iterations has been reached despite the residual norm estimates have converged (but the true residuals for eigenpairs have not). • If -3, the iterations stagnated and even the residual norm estimates have not converged. • If -4, the iterations stagnated while the eigenvalues have converged (but the true residuals for eigenpairs do not). "fpm[10..128]">reserved The function will return the number of actually found eigen-values. If there was an error during evaluation, an exception will be raised with an error message. *) function EigSymLargest(const D, Residuals: TVec; const EigVectors: TMtx; DesiredEigCount: integer; const fpm: TIntegerArray = nil): integer; overload; (* Computes smallest eigenvalues and eigenvectors for a symmetric sparse matrix. The sparse matrix must be symmetric and it must use full storage. Important: * The routine does not check, if the matrix is symmetric. * Inclusion of explicit zero valued elements could cause access violation. Returns the eigenvalues. Returns the relative residual vector Returns the eigenvectors in rows. Pass nil for this paramter, if you dont require eigen-vectors, The function will return up to DesiredEigCount smallest eigen values. Optiona: processing parameter list. Leave nil, to use default values. If you do pass this parameter, its length must be minimum 129 items. (Reference: Intel MKL manual). "fpm[0]"> 0 Reserved for future use. "fpm[1]"> 6 Defines the tolerance for the stopping criteria: tol = 10-pm 1 + 1 "fpm[2]"> 0 Specifies the algorithm to use: • 0 - Decided at runtime • 1 - The Krylov-Schur method • 2 - Subspace Iteration technique based on FEAST algorithm "fpm[3]"> This parameter is referenced only for Krylov-Schur Method. It indicates the number of Lanczos/Arnoldi vectors (NCV) generated at each iteration. This parameter must be less than or equal to size of matrix and greater than number of eigenvalues (k0) to be computed. If unspecified, NCV is set to be at least 1.5 times larger than k0. "fpm[4]"> Maximum number of iterations. If unspecified, this parameter is set to 10000 for the Krylov-Schur method and 60 for the subspace iteration method. "fpm[5]"> 0 Power of Chebychev expansion for approximate spectral projector. Only referenced when pm[2]=1 "fpm[6]"> 1 Used only for Krylov-Schur Method. If 0, then the method only computes eigenvalues. If 1, then the method computes eigenvalues and eigenvectors. The subspace iteration method always computes eigenvectors/singular vectors. You must allocate the required memory space. "fpm[7]"> Convergence stopping criteria. "fpm[8]"> Specifies if for detecting convergence the solver must compute the true residuals for eigenpairs for the Krylov-Schur method or it can only use the residual norm estimates. If 0, only residual norm estimates are used. If 1, the solver computes not just residual norm estimates but also the true residuals as defined in the description of pm[7]. "fpm[9]"> Used only for the Krylov-Schur method and only as an output parameter. Reports the reason for exiting the iteration loop of the method: • If 0, the iterations stopped since convergence has been detected. • If -1, maximum number of iterations has been reached and even the residual norm estimates have not converged. • If -2, maximum number of iterations has been reached despite the residual norm estimates have converged (but the true residuals for eigenpairs have not). • If -3, the iterations stagnated and even the residual norm estimates have not converged. • If -4, the iterations stagnated while the eigenvalues have converged (but the true residuals for eigenpairs do not). "fpm[10..128]">reserved The function will return the number of actually found eigen-values. If there was an error during evaluation, an exception will be raised with an error message. *) function EigSymSmallest(const D, Residuals: TVec; const EigVectors: TMtx; DesiredEigCount: integer; const fpm: TIntegerArray = nil): integer; overload; (* Computes generalized largest eigenvalues and eigenvectors for symmetric sparse matrix. Solves: Ax = lambda Bx The sparse matrix must be symmetric and it must use full storage. Important: * The routine does not check, if the matrix is symmetric. * Inclusion of explicit zero valued elements could cause access violation. The sparse matrix B, which must be symmetric, positive definite and have full storage. Returns the eigenvalues. Returns the relative residual vector Returns the eigenvectors in rows. Pass nil for this paramter, if you don't require eigen-vectors, The function will return up to DesiredEigCount largest eigen values. Processing parameter list. Leave nil, to use default values. Alternatively, it is possible to specify an array of parameters "fpm" as the last parameter to the routine (Reference: Intel MKL manual). "fpm Optional: processing parameter list. Leave nil, to use default values. If you do pass this parameter, its length must be minimum 129 items. (Reference: Intel MKL manual). "fpm[0]" 0 Reserved for future use. "fpm[1]" 6 Defines the tolerance for the stopping criteria: tol = 10-pm 1 + 1 "fpm[2]" 0 Specifies the algorithm to use: • 0 - Decided at runtime • 1 - The Krylov-Schur method • 2 - Subspace Iteration technique based on FEAST algorithm "fpm[3]" This parameter is referenced only for Krylov-Schur Method. It indicates the number of Lanczos/Arnoldi vectors (NCV) generated at each iteration. This parameter must be less than or equal to size of matrix and greater than number of eigenvalues (k0) to be computed. If unspecified, NCV is set to be at least 1.5 times larger than k0. "fpm[4]" Maximum number of iterations. If unspecified, this parameter is set to 10000 for the Krylov-Schur method and 60 for the subspace iteration method. "fpm[5]" 0 Power of Chebychev expansion for approximate spectral projector. Only referenced when pm[2]=1 "fpm[6]" 1 Used only for Krylov-Schur Method. If 0, then the method only computes eigenvalues. If 1, then the method computes eigenvalues and eigenvectors. The subspace iteration method always computes eigenvectors/singular vectors. You must allocate the required memory space. "fpm[7]" Convergence stopping criteria. "fpm[8]" Specifies if for detecting convergence the solver must compute the true residuals for eigenpairs for the Krylov-Schur method or it can only use the residual norm estimates. If 0, only residual norm estimates are used. If 1, the solver computes not just residual norm estimates but also the true residuals as defined in the description of pm[7]. "fpm[9]" Used only for the Krylov-Schur method and only as an output parameter. Reports the reason for exiting the iteration loop of the method: • If 0, the iterations stopped since convergence has been detected. • If -1, maximum number of iterations has been reached and even the residual norm estimates have not converged. • If -2, maximum number of iterations has been reached despite the residual norm estimates have converged (but the true residuals for eigenpairs have not). • If -3, the iterations stagnated and even the residual norm estimates have not converged. • If -4, the iterations stagnated while the eigenvalues have converged (but the true residuals for eigenpairs do not). "fpm[10..128]" reserved The function will return the number of actually found eigen-values. If there was an error during evaluation, an exception will be raised with an error message. *) function EigSymGenLargest(const B: TSparseMtx; const D, Residuals: TVec; const EigVectors: TMtx; DesiredEigCount: integer; const fpm: TIntegerArray = nil): integer; (* Computes smallest generalized eigenvalues and eigenvectors for a symmetric sparse matrix. Solves: Ax = lambda Bx The sparse matrix must be symmetric and it must use full storage. The function will return up to EigCount smallest eigen values. Important: * The routine does not check, if the matrix is symmetric. * Inclusion of explicit zero valued elements could cause access violation. The sparse matrix B, which must be symmetric, positive definite and have full storage. Returns the eigenvalues. Returns the relative residual vector Returns the eigenvectors in rows. Pass nil for this paramter, if you dont require eigen-vectors, The function will return up to DesiredEigCount smallest eigen values. Optiona: processing parameter list. Leave nil, to use default values. If you do pass this parameter, its length must be minimum 129 items. (Reference: Intel MKL manual). "fpm[0]" Reserved for future use. "fpm[1]" Default 6. Defines the tolerance for the stopping criteria: tol = 10-pm 1 + 1 "fpm[2]" Default 0. Specifies the algorithm to use: • 0 - Decided at runtime • 1 - The Krylov-Schur method • 2 - Subspace Iteration technique based on FEAST algorithm "fpm[3]" This parameter is referenced only for Krylov-Schur Method. It indicates the number of Lanczos/Arnoldi vectors (NCV) generated at each iteration. This parameter must be less than or equal to size of matrix and greater than number of eigenvalues (k0) to be computed. If unspecified, NCV is set to be at least 1.5 times larger than k0. "fpm[4]" Default 0. Maximum number of iterations. If unspecified, this parameter is set to 10000 for the Krylov-Schur method and 60 for the subspace iteration method. "fpm[5]" Default 0. Power of Chebychev expansion for approximate spectral projector. Only referenced when pm[2]=1 "fpm[6]" Default 1. Used only for Krylov-Schur Method. If 0, then the method only computes eigenvalues. If 1, then the method computes eigenvalues and eigenvectors. The subspace iteration method always computes eigenvectors/singular vectors. You must allocate the required memory space. "fpm[7]" Convergence stopping criteria. "fpm[8]" Specifies if for detecting convergence the solver must compute the true residuals for eigenpairs for the Krylov-Schur method or it can only use the residual norm estimates. If 0, only residual norm estimates are used. If 1, the solver computes not just residual norm estimates but also the true residuals as defined in the description of pm[7]. "fpm[9]" Used only for the Krylov-Schur method and only as an output parameter. Reports the reason for exiting the iteration loop of the method: • If 0, the iterations stopped since convergence has been detected. • If -1, maximum number of iterations has been reached and even the residual norm estimates have not converged. • If -2, maximum number of iterations has been reached despite the residual norm estimates have converged (but the true residuals for eigenpairs have not). • If -3, the iterations stagnated and even the residual norm estimates have not converged. • If -4, the iterations stagnated while the eigenvalues have converged (but the true residuals for eigenpairs do not). "fpm[10..128]"reserved The function will return the number of actually found eigen-values. If there was an error during evaluation, an exception will be raised with an error message. *) function EigSymGenSmallest(const B: TSparseMtx; const D, Residuals: TVec; const EigVectors: TMtx; DesiredEigCount: integer; const fpm: TIntegerArray = nil): integer; (* Computes largest singular values and signular vectors for symmetric sparse matrix. The sparse matrix must be symmetric and it must use full storage. Important: * The routine does not check, if the matrix is symmetric. * Inclusion of explicit zero valued elements could cause access violation. Returns the singular values. Returns the relative residual vector Returns left singular vectors in rows. Pass nil for this paramter, if you dont require singular vectors, The function will return up to DesiredSCount largest singular values. When V is not nil, left singular vectors are returned by default. Set this parameter to True, to obtain right singular vectors. Processing parameter list. Leave nil, to use default values. Alternatively, it is possible to specify an array of parameters "fpm" as the last parameter to the routine (Reference: Intel MKL manual). "fpm" Optional: processing parameter list. Leave nil, to use default values. If you do pass this parameter, its length must be minimum 129 items. (Reference: Intel MKL manual). "fpm[0]" 0. Reserved for future use. "fpm[1]" 6. Defines the tolerance for the stopping criteria: tol = 10-pm 1 + 1 "fpm[2]" 0. Specifies the algorithm to use: • 0 - Decided at runtime • 1 - The Krylov-Schur method • 2 - Subspace Iteration technique based on FEAST algorithm "fpm[3]" This parameter is referenced only for Krylov-Schur Method. It indicates the number of Lanczos/Arnoldi vectors (NCV) generated at each iteration. This parameter must be less than or equal to size of matrix and greater than number of eigenvalues (k0) to be computed. If unspecified, NCV is set to be at least 1.5 times larger than k0. "fpm[4]" Maximum number of iterations. If unspecified, this parameter is set to 10000 for the Krylov-Schur method and 60 for the subspace iteration method. "fpm[5]" 0. Power of Chebychev expansion for approximate spectral projector. Only referenced when pm[2]=1 "fpm[6]" 1. Used only for Krylov-Schur Method. If 0, then the method only computes eigenvalues. If 1, then the method computes eigenvalues and eigenvectors. The subspace iteration method always computes eigenvectors/singular vectors. You must allocate the required memory space. "fpm[7]" Convergence stopping criteria. "fpm[8]" Specifies if for detecting convergence the solver must compute the true residuals for eigenpairs for the Krylov-Schur method or it can only use the residual norm estimates. If 0, only residual norm estimates are used. If 1, the solver computes not just residual norm estimates but also the true residuals as defined in the description of pm[7]. "fpm[9]" Used only for the Krylov-Schur method and only as an output parameter. Reports the reason for exiting the iteration loop of the method: • If 0, the iterations stopped since convergence has been detected. • If -1, maximum number of iterations has been reached and even the residual norm estimates have not converged. • If -2, maximum number of iterations has been reached despite the residual norm estimates have converged (but the true residuals for eigenpairs have not). • If -3, the iterations stagnated and even the residual norm estimates have not converged. • If -4, the iterations stagnated while the eigenvalues have converged (but the true residuals for eigenpairs do not). "fpm[10..128]" reserved The function will return the number of actually found eigen-values. If there was an error during evaluation, an exception will be raised with an error message. It is possible, that the function does not return an error, but the result is not correct, if the requsted tolerance is to high (fpm[1] is too big, asking for too small value). *) function SvdSymLargest(const S, Residuals: TVec; const V: TMtx; DesiredSCount: integer; RightVectors: boolean = false; const fpm: TIntegerArray = nil): integer; overload; (* Computes smallest singular values and signular ectors for a symmetric sparse matrix. The sparse matrix must be symmetric and it must use full storage. Important: * The routine does not check, if the matrix is symmetric. * Inclusion of explicit zero valued elements could cause access violation. Returns the singular values. Returns the relative residual vector Returns left singular vectors in rows. Pass nil for this paramter, if you dont require singular vectors, The function will return up to DesiredSCount smallest singular values. When V is not nil, left singular vectors are returned by default. Set this parameter to True, to obtain right singular vectors. Optional: processing parameter list. Leave nil, to use default values. If you do pass this parameter, its length must be minimum 129 items. (Reference: Intel MKL manual). "fpm[0]" 0. Reserved for future use. "fpm[1]" 6. Defines the tolerance for the stopping criteria: tol = 10-pm 1 + 1 "fpm[2]" 0. Specifies the algorithm to use: • 0 - Decided at runtime • 1 - The Krylov-Schur method • 2 - Subspace Iteration technique based on FEAST algorithm "fpm[3]" This parameter is referenced only for Krylov-Schur Method. It indicates the number of Lanczos/Arnoldi vectors (NCV) generated at each iteration. This parameter must be less than or equal to size of matrix and greater than number of eigenvalues (k0) to be computed. If unspecified, NCV is set to be at least 1.5 times larger than k0. "fpm[4]" Maximum number of iterations. If unspecified, this parameter is set to 10000 for the Krylov-Schur method and 60 for the subspace iteration method. "fpm[5]" 0. Power of Chebychev expansion for approximate spectral projector. Only referenced when pm[2]=1 "fpm[6]" 1. Used only for Krylov-Schur Method. If 0, then the method only computes eigenvalues. If 1, then the method computes eigenvalues and eigenvectors. The subspace iteration method always computes eigenvectors/singular vectors. You must allocate the required memory space. "fpm[7]" Convergence stopping criteria. "fpm[8]" Specifies if for detecting convergence the solver must compute the true residuals for eigenpairs for the Krylov-Schur method or it can only use the residual norm estimates. If 0, only residual norm estimates are used. If 1, the solver computes not just residual norm estimates but also the true residuals as defined in the description of pm[7]. "fpm[9]" Used only for the Krylov-Schur method and only as an output parameter. Reports the reason for exiting the iteration loop of the method: • If 0, the iterations stopped since convergence has been detected. • If -1, maximum number of iterations has been reached and even the residual norm estimates have not converged. • If -2, maximum number of iterations has been reached despite the residual norm estimates have converged (but the true residuals for eigenpairs have not). • If -3, the iterations stagnated and even the residual norm estimates have not converged. • If -4, the iterations stagnated while the eigenvalues have converged (but the true residuals for eigenpairs do not). "fpm[10..128]"reserved The function will return the number of actually found eigen-values. If there was an error during evaluation, an exception will be raised with an error message. *) function SvdSymSmallest(const S, Residuals: TVec; const V: TMtx; DesiredSCount: integer; RightVectors: boolean = false; const fpm: TIntegerArray = nil): integer; overload; (* Computes eigenvalues and eigenvectors for generalized symmetric (hermitian) sparse problem. The symmetric positive definite matrix. Returns the eigenvalues. Returns the relative residual vector Returns the contains the relative error on the trace: |trac[i] - trace[i-1]|/Max(|Maximum|, |sMinimum|) Returns the eigenvectors in rows. Pass nil for this paramter, if you dont require eigen-vectors, Start of the search interval. Stop of the search interval. Contains estimated eigenvalue on input and actual count on return. Processing parameter list. Leave nil, to use default values. The function will return: 0 on success. 1 no eigenvalues found in search interval. Try to scale up/down the matrix: (A/t) x=(Lambda/t) x 2 in case of no convergence (maximum iteration loops specified in fpm(4) exceeded) 3 There are more eigenvalues present than have been estimated with EigCount To compute all eigenvalues and eigenvectors would require storage equal to the size of the dense matrix. For this reason, the routine allows computation of eigenvectors and eigenvalues only within a specified range. The expected number of eigenvalues within the Interval [Minimum, Maximum] is specified with EigCount. If the function returns with a different EigCount, the initial estimate needs to be adjusted, because there was not enough storage to store the result. Matrix A is expected to be symmetric and B must be symmetric and positive definite (Hermitian). Both matrices are expected to store only lower triangular part. Size of A and B is expected to be equal and both matrices are to be quadratic. *) function EigSymGen(const B: TSparseMtx; const D, R: TVec; const V: TMtx; var EigCount: integer; var EpsOut: double; Minimum, Maximum: double; var fpm: TIntegerArray): integer; overload; (*Convert sparse matrix to banded matrix. Convert calling matrix, stored in HB sparse matrix format, to banded matrix format. The result (banded matrix format) is stored in Dst matrix. The size and complex properties of Dst matrix are adjusted automatically. Step 1: construct banded matrix var subDiag, SupDiag,MainDiag: Vector; A: Matrix; begin SubDiag.Size(4); SuperDiag.Size(4); MainDiag.Size(4); A.Size(3,4); A.SubDiag := 1; // one subdiagonal A.SuperDiag := 1; // one superdiagonal SubDiag.SetIt([0,1,3,2]); SupDiag.SetIt([-1,2,7,0]); MainDiag.SetIt([2,3,5,1]); A.SetRow(SupDiag,0); A.SetRow(MainDiag,1); A.SetRow(SubDiag,2); end; Step 2: convert banded matrix to sparse matrix: SparseA.BandedToSparse(A); end; *) procedure SparseToBanded(const Dst: TMtx; MaxElemCount: integer = 10000000); (*Convert sparse matrix to banded matrix. Convert sparse matrix modified compressed column format to dense matrix. Step 1: Construct dense matrix var A,B: TMtx; SparseA: TSparseMtx; // ... A.SetIt(3,3,false,[1,0,0,0,2,0,0,1,3]); Step 2: Convert dense matrix to sparse matrix // ... SparseA.DenseToSparse(A); Step 3: Convert sparse matrix back to dense and compare // ... SparseA.SparseToDense(B); if not A.Equal(B,1.0e-5) then ERaise('Not Equal!'); *) procedure SparseToDense(const Dst: TMtx; MaxElemCount: integer = 10000000); (*Convert sparse matrix to triplets. A sparse matrix can also be presented as pairs of the three elements called triplets. For each non zero value in the matrix we specify it's position: Row, Column, and it's Value. SparseToTriplets will convert the calling sparse matrix data to the triplets format. The data will be sorted first by columns and then by rows. Triplets can be represented by three arrays: Row, Column and Values or they can all be stored in one TMtx matrix. TSparseMtx sparseA = new TSparseMtx(); TSparseMtx sparseB = new TSparseMtx(); int[] R1 = new int[sparseA.NonZeros]; int[] C1 = new int[sparseA.NonZeros]; double[] V1 = new double[sparseA.NonZeros]; Matrix A = new Matrix(0,0); sarseA.SparseToTriplets(ref R1,ref C1,ref V1); sparseB.TripletsToSparse(sparseA.Cols,sparseA.Cols,R1,C1,V1,0.0); sparseA.SparseToDense(A,10000000); if (!sparseB.Equal(sparseA,1.0E-5)) throw("Not equal"); if (!sparseA.Equal(A,0,true)) throw("Not equal"); sparseA.SparseToTriplets(A,false); sparseB.TripletsToSparse(sparseA.Cols,sparseA.Cols,A); if (!sparseA.Equal(sparseB)) throw("Not equal"); *) procedure SparseToTriplets(var DstRow, DstColumn: TIntegerArray; var DstValues: TDoubleArray); overload; procedure SparseToTriplets(var DstRow, DstColumn: TIntegerArray; var DstValues: TSingleArray); overload; (*Convert sparse matrix to triplets (complex version).*) procedure SparseToTriplets(var DstRow, DstColumn: TIntegerArray; var DstCValues: TCplxArray); overload; procedure SparseToTriplets(var DstRow, DstColumn: TIntegerArray; var DstCValues: TSCplxArray); overload; (*Convert sparse matrix to triplets. Triplets are stored in the first three rows of the matrix. First row stores the row indices, the second stores the column indices and the third row stores the matrix values. In case of a complex matrix and if ImInRow is True, the imaginary part's of the complex numbers are stored in the fourth row. *) procedure SparseToTriplets(const DstTriplets: TMtx; ImInRow: boolean = False); overload; (*Split sparse matrix into lower triangle, main diagonal and upper triangle. Splits the calling sparse matrix in to lower triangle, main diagonal and upper triangle. LowerTriang sparse matrix will then contain the lower triangle of the sparse matrix with or without the diagonal depending on the DiagWithLower parameter. UpperTriang sparse matrix will contain the upper diagonal of the calling sparse matrix. *) procedure Split(const LowerTriang: TSparseMtx; const Diag: TVec; const UpperTriang: TSparseMtx; DiagWithLower: boolean = False); (*Form a full symmetric matrix from upper half with diagonal included. Forms full storage sparse symmetric matrix from the upper half of the matrix. *) procedure ExpandSymmetric; (*Convert strings to specific matrix format. Convert strings to specific matrix format. Currently only Matrix market format is supported. *) procedure StringsToValues(const Strings: TStrings; Format: TSparseFormat = spfMatrixMarket); (*Subract two sparse matrices. Subtract each of Sparse2 elements from the corresponding elements in matrix Sparse1 (matrix subtraction). The results are stored in the calling sparse matrix. Size and properties of the calling matrix are set implicitly to match Sparse1 and Sparse2 matrices. *) function Sub(const sLeft, sRight: TSparseMtx): TSparseMtx; overload; (*The residual norm of the solution of the system of linear equations A*X=B. Defines B vector in the A*X=B equation. Defines X vector in the A*X=B equation. If true, treat A (calling matrix) as transposed matrix. the residual norm of the solution of the system of linear equations A*X=B, where A is calling sparse matrix.*) function ResidualNorm(const B, X: TVec; Transp: boolean = False): double; (*Creates quadratic non-complex non-singular sparse matrix. Creates general/symmetric quadratic non-complex non-singular sparse matrix. It returns the right hand side in vector Y and the solution in vector X. If Symmetric is true the method will generate a matrix with symmetric pattern. The parameter defines the percentage of non-zero in the sparse matrix. The MaxNonZeroCount parameter defines an upper limit to prevent against excessive memory usage (consequence of invalid user parameters) and consecutive system lock up. Note: You have to set property to definethe size of the matrix before calling this routine. using Dew.Math; using Dew.Math.Units; using Dew.Math.Tee; namespace Dew.Examples { private void Example(MtxGridSeries GridSeries) { // ... SparseA.Size(7500,4000,4000,false); SparseA.RandomSparse(v1,v2); SparseA.PixelDownSample(A); MtxVecTee.DrawValues(A,GridSeries); // showing A } } *) procedure RandomSparse(const X,Y: TVec; Symmetric: boolean = false; FillInPercent: double = 33; MaxNonZeroCount: integer = 10000000); overload; (*Convert triplets to sparse format. A sparse matrix can also be presented as pairs of the three elements called triplets. For each non zero value in the matrix we specify it's position: Row, Column, and it's Value. MatrixSize defines the size of the matrix and sets the Size and Cols properties. The maximum row and column index may not exceed rowCount and colCount. This is usually the most efficient way to convert a given dense matrix to sparse format. The values do not need to be ordered, the same coordinates can appear more than once. All values having the same coordinates will be summed together. This routine can therefore also be used as a way to sum multiple sparse matrices. Triplets can be represented by three arrays: Row, Column and Values or they can all be stored in one TMtx matrix. By default any zeros on the main diagonal will be preserved. Set the last parameter to false to drop them on conversion. Test sparseToTriplets, TripletsToSparse methods. using Dew.Math; using Dew.Math.Units; namespace Dew.Examples { private void Example() { Matrix A = new Matrix(0,0); TSparseMtx SparseA = new TSparseMtx(); TSparseMtx SparseB = new TSparseMtx(); int[] R1 = new int[SparseA.NonZeros]; int[] C1 = new int[SparseA.NonZeros]; double[] V1 = new double[SparseA.NonZeros]; SparseA.SparseToTriplets(ref R1,ref C1,ref V1); SparseB.TripletsToSparse(SparseA.Cols,SparseA.Cols,R1,C1,V1,0.0); SparseA.SparseToDense(A); if (!SparseB.Equal(SparseA,1E-5)) throw("Not equal"); if (!SparseA.Equal(A,0,true)) throw("Not equal"); SparseA.SparseToTriplets(A); SparseB.>TripletsToSparse(SparseA.Cols,SparseA.Cols,A,0.0); if (!SparseA.Equal(SparseB)) throw("Not equal"); } } *) procedure TripletsToSparse(RowCount,ColCount: integer; const SrcRow, SrcColumn: TIntegerArray; const SrcValues: TDoubleArray; Threshold: double = 0; PreserveZeroDiagElem: boolean = true); overload; procedure TripletsToSparse(RowCount,ColCount: integer; const SrcRow, SrcColumn: TIntegerArray; const SrcValues: TSingleArray; Threshold: double = 0; PreserveZeroDiagElem: boolean = true); overload; (*Convert triplets to sparse format (complex version).*) procedure TripletsToSparse(RowCount,ColCount: integer; const SrcRow, SrcColumn: TIntegerArray; const SrcCValues: TCplxArray; Threshold: double = 0; PreserveZeroDiagElem: boolean = true); overload; procedure TripletsToSparse(RowCount,ColCount: integer; const SrcRow, SrcColumn: TIntegerArray; const SrcCValues: TSCplxArray; Threshold: double = 0; PreserveZeroDiagElem: boolean = true); overload; (*Convert triplets to sparse format. The triplets are stored in the Triplets matrix. First row are row indices, second row are column indices and the third row stores the values. If the matrix is complex, the row and column indicies are stored in the real part of the complex values. *) procedure TripletsToSparse(RowCount,ColCount: integer; const SrcTriplets: TMtx); overload; (*Construct a sparse matrix by specifying the position of each element in dense matrix. This method can be used to construct a sparse matrix by specifying the position of each element in dense matrix. A[1,0] := 1; A[2,3] := 5; A[4,0] := 2; A.TripletsToSparseAndFlush; If you later call :A.SparseToDense, you'll construct a dense matrix of form: 0 0 0 0 1 0 0 0 <= 1,0 0 0 0 5 <= 2,3 0 0 0 0 2 0 0 0 <= 4,0 *) procedure TripletsToSparseAndFlush; (*Transpose sparse matrix in-place.*) procedure Transp; overload; (**) procedure Transp(const Src: TSparseMtx; const P: TIntegerArray; const Q: TIntegerArray); overload; (*Transpose Src sparse matrix. Store the results in calling sparse matrix. Size and Complex properties of calling sparse matrix are adjusted automatically. *) procedure Transp(const Src: TSparseMtx); overload; (*Extract upper part of the Mtx. Copies only the upper triangular part of the Mtx sparse matrix. The result is stored in the calling sparse matrix. If the Diagonal boolean parameter is true then the Mtx matrix main diagonal elements will be copied to the calling matrix main diagonal elements. If the Diagonal parameter is false, the calling matrix main diagonal elements will be set to zero. var asp, bsp: TSparseMtx; csp, dsp: TSparseMtx; d: Vector; begin // ... // #1 : split asp into lower(bsp), upper(csp) and diagonal(d) sections bsp.LowerTriangle(asp); csp.UpperTriangle(asp); asp.Diag(d); // now combine lower(bsp), upper, and diagonal(d) back dsp.AddSplit(bsp,d,csp); // should be equal if not asp.Equal(dsp) then Eraise('Not Equal!'); end; *) function UpperTriangle(const Src: TSparseMtx; Diagonal: boolean = false): TSparseMtx; overload; (*Reduces dense matrix for screen display (bitmap) to show the non-zero pattern. Creates a reduced size Dst dense matrix for screen display (bitmap) to show the non-zero pattern. Pixels parameter defines the target number of pixels to reduce and to. The Mode parameter defines how reduced matrix will be constructed. Vector v1 = new Vector(0); Vector v2 = new Vector(0); Matrix A = new Matrix(0,0); TSparseMtx SparseA = new TSparseMtx(); // ... SparseA.Size(7500,4000,4000,false); SparseA.RandomSparse(v1,v2); SparseA.PixelDownSample(A); MtxVecTee.DrawValues(A,GridSeries); // showing A *) procedure PixelDownSample(const Dst: TMtx; Pixels: integer = 500; Mode: TPixelDownSample = pdsPattern); (*Convert matrix values to strings. Converts calling sparse matrix, stored in HB sparse format to Strings. Performance note: This routine will be exceedingly slow, if TRichEdit.Lines or TMemo.Lines are passed as a parameter for Verbose parameter. Use TStringList or StringList types and then call TMemo.Lines.AddStrings(yourList) for best results. *) procedure ValuesToStrings(const Dst: TStrings; Format: TSparseFormat = spfMatrixMarket; ColumnVector: boolean = True); overload; procedure WriteHeader(const Dst: TStream; Precision: TPrecision; Rounding: TRounding = rnTrunc; Endian: TEndianness = MtxSystemEndianness); override; function ReadHeader(const Src: TStream; Endian: TEndianness = MtxSystemEndianness): TPrecision; override; (*Saves the matrix in matrix market file format. *) procedure SaveToMatrixMarketFile(const FileName: string); (*Loads the matrix stored in a matrix market file format. Loads the matrix stored in a Matrix Market file format. *) procedure LoadFromMatrixMarketFile(const FileName: string); (*Reduces the number of non-zeros. Reduces the number of non-zeros by rounding all values smaller than Threshold to zero. All zeros on the main diagonal are retained. *) procedure ZeroThresh(Threshold: double = 0); (*Required by Pardiso solver to solve for general matrices. Pardiso solver can solve for general real/complex non-symmetric matrices only if they are first made structurally symmetric. StructurizeSymmetric method makes the matrix structurually symmetric, by inserting additional zeros in the matrix. *) procedure StructurizeSymmetric; constructor Create; overload; override; destructor Destroy; override; (*Frees the memory of the Pardiso solver. If the parameter is -1, it frees all the allocated memory. If the parameter is bigger then 0 it frees the memory associated with the factorized matrix at that index. *) procedure FreePardiso(AMatrixNumber: integer = -1); (*Releases factorization stored by taucs.*) procedure FreeTaucs; public published (*Number of rows in the sparse matrix. Defines number of rows in the sparse matrix. This value is needed only by the routines for matrix addition and multiplication to check the matrix sizes (which can be non-rectangular). SparseA.Complex = false; SparseA.Rows = 3; SparseA.Cols = 4; SparseA.NonZeros = 5; *) property Rows: integer read FRows write SetRows; (*Number of columns in the sparse matrix. Defines number of columns in the sparse matrix. This value is needed only by the routines for matrix addition and multiplication to check the matrix sizes (which can be non-rectangular). *) property Cols: integer read FCols write SetCols; (*Defines the number of non-zero elements in the sparse matrix.*) property NonZeros: integer read fLength write setLength; (*Prevents zeros to be stripped. Prevents zeros to be stripped when forming a sparse matrix from triplets. *) property DontStripZeros: boolean read FDontStripZeros write SetDontStripZeros; (*Specifies the sparse matrix solver to use. Specifies the sparse matrix solver to be used by the method. *) property SparseSolver: TSparseSolver read FSparseSolver write SetSparseSolver; (*Defines if call to Solve will clear the report. If True, each consecutive call to Solve method will clear MtxVec.Report object. Report is a global class located in unit. Be sure to reduce the level off reporting when solving large matrices, or the system will be busy just by printing reports. *) property AutoClearReport: boolean read FAutoClearReport write SetAutoClearReport; (*Defines how detailed report will be printed. Defines how detailed report will be printed. Be careful not to set it to prlAll for larger sparse matrices, because then all non-zero elements of the sparse matrix will be printed to Report cllass, a global TStringList object located in unit. The report is generated by Umfpack and can be very extensive, including everything from time needed to solve the system and number of flops to details about the path to the solution and many other useful parameters. Reports are generated only by method. // load report from Report and display it in Memo1 Memo1.Lines.Clear(); MtxVec.Report.Position := 0; Memo1.Lines.LoadFromStream(MtxVec.Report.Stream); // load report from Report and display it in Memo1 Memo1->Lines.Clear(); MtxVec->Report->Position = 0; Memo1->Lines->LoadFromStream(MtxVec->Report->Stream()); *) property ReportLevel: TReportLevel read FReportLevel write SetReportLevel; (*Defines number of refinement steps the method should try. Defines number of refinement steps the method should try. Default value is 2. The number of actual refinement steps is returned in property. Vector x = new Vector(0); Vector b = new Veector(0); TSparseMtx SparseMtx = new TSparseMtx(); // ... x.size(b); SparseMtx.RefinementIters = 4; // set to four iterations SparseMtx.SolveIterative(b,x); int maxiter = SparseMtx.ActualIters; // return the actual number of iterations used *) property RefinmentIters: integer read FRefinmentIters write SetRefinmentIters; (*Defines the system to be solved by the Solve method. Defines the system to be solved by the method. *) property SparseSystem: TSparseSystem read FSparseSystem write SetSparseSystem; (*The size of the block as used by UmfPack. This parameter gets/sets the UMFPACK_BLOCK_SIZE control parameter of the Umfpack sparse solver. *) property SparseBlockSize: integer read FSparseBlockSize write SetSparseBlockSize; (*Defines the iterative method for solving system of equations. The term "iterative method" refers to a wide range of techniques that use successive approximations to obtain more accurate solutions to a linear system at each step. There are two major groups of iterative methods: stationary and nonstationary methods. Stationary methods are older, simpler to understand and implement, but usually not as effective. Nonstationary methods are a relatively recent development; their analysis is usually harder to understand, but they can be highly effective. The nonstationary methods are based on the idea of sequences of orthogonal vectors. The rate at which an iterative method converges depends greatly on the spectrum of the coefficient matrix. Hence, iterative methods usually involve a second matrix that transforms the coefficient matrix into one with a more favorable spectrum. The transformation matrix is called a pre conditioner. A good precondition improves the convergence of the iterative method, sufficiently to overcome the extra cost of constructing and applying the pre conditioner. Indeed, without a pre conditioner the iterative method may even fail to converge. *) property IterativeMethod: TIterativeMethod read FIterativeMethod write SetIterativeMethod; (*Convergence criteria for iterative method. Defines the convergence criteria used by the method. *) property ConvergenceCheck: TConvergenceCheck read FConvergenceCheck write SetConvergenceCheck; (*Defines the tolerance for iterative method. This property defines the tlerance of the solution used as a parameter for the method. *) property Tolerance: double read FTolerance write SetTolerance; (*Upper limit for number of iterations. Defines the maximum number of iterations performed by the method. *) property MaxIters: integer read FMaxIters write SetMaxIters; (*Defines maximum number of vectors used in some iterative methods. Defines the maximum number of vectors used in case of the Generalized Minimal Residual (GMRES) and Orthmin method by the method. *) property VectorCount: integer read FVectorCount write SetVectorCount; (*The pardiso sparse solver settings.*) property Pardiso: TPardisoSettings read FPardiso write SetPardiso; (*The Taucs sparse solver settings.*) property Taucs: TTaucsSettings read FTaucs write SetTaucs; end; (*Special math functions Introduces several special functions: * Airy, Bessel functions, * Elliptic integrals, * Jacoby elliptic functions, * Associated Legendre polynomials. *) unit SpecialFuncs; interface {$I BdsppDefs.inc} uses Math387, AbstractMtxVec, MtxVec ,Nmkl ,NmklSingle ,SysUtils ,Types ; (*Complete elliptic integral. the complete elliptic integrals of the first kind, evaluated at m. Parameter m must lie on the (0,1) interval, otherwise an exception is raised. Defines integral evaluation point, real value on closed interval [0,1].*) function EllipComplete(m: double):double; overload; function EllipComplete(m: single):single; overload; (*Complete elliptic integral, additional options. the complete elliptic integrals of the first kind, evaluated at m. Parameter m must lie on the (0,1) interval, otherwise an exception is raised. Defines integral evaluation point, real value on closed interval [0,1]. Defines the accuracy for evaluating elliptic integral of the second kind. Returns the value of the complete elliptic integral of the second kind, evaluated at m, to the accuracy Epsilon. *) function EllipComplete(m, Epsilon: double; var e: double): double; overload; function EllipComplete(m, Epsilon: single; var e: single): single; overload; (*Jacoby elliptic functions. The routine calculates the values of Jacoby elliptic functions sn, cn and dn, evaluated at u and using the parameter m. Defines value at which functions will be evaluated. Defines integral evaluation point, real value on closed interval [0,1]. Defines the accuracy for evaluating complete elliptic integral. Returns Jacoby elliptic function sn. Returns Jacoby elliptic function cn. Returns Jacoby elliptic function dn. *) procedure EllipJacoby(u,m, Epsilon: double; var sn,cn,dn: double); overload; procedure EllipJacoby(u,m, Epsilon: single; var sn,cn,dn: single); overload; (*Airy function of the first kind (Real argument). the Airy function from the K Bessel functions. Defines real value where AI should be evaluated.*) function Airy(A: double): double; overload; function Airy(A: single): single; overload; (*Airy function of the first kind (Complex argument). the Airy function from the K Bessel functions. Defines complex value where AI should be evaluated.*) function Airy(Z: TCplx): TCplx; overload; function Airy(Z: TSCplx): TSCplx; overload; (*Airy function or it's derivative of the first kind (Real argument, allows derivative and scale). the Airy function or it's derivative from the K Bessel functions. Defines complex value where AI or it's derivative should be evaluated. is true, it will return derivative of Airy function of the first kind. is true, result is additionaly multiplied by factor (see below) Returns error code after the calculation. Return values are: 0, Normal return - Computation completed. 1, input error - no computation. 2, overflow - no computation; dreal(zta)- too large with Scaling=false. 3, zabs(z) large - computation completed. Losses of signifcance by argument reduction produce less than half of machine accuracy. 4, zabs(z) too large - no computation; complete loss of accuracy by argument reduction. 5, error - no computation; algorithm termination condition not met. *) function Airy(A: double; Derive, Scale: boolean; var Error: integer): double; overload; function Airy(A: single; Derive, Scale: boolean; var Error: integer): single; overload; (*Airy function of the first kind or it's derivative (Complex argument, allows derivative or scale. If Derive is false, it will return Airy function of the first kind. If is true, it will return derivative of Airy function of the first kind. If is true, result is additionaly multiplied by factor (see below) Function independant variable, complex value. Returns error code after the calculation. Return values are: 0, Normal return - Computation completed. 1, input error - no computation. 2, overflow - no computation; dreal(zta)- too large with Scaling=false. 3, zabs(z) large - computation completed. Losses of signifcance by argument reduction produce less than half of machine accuracy. 4, zabs(z) too large - no computation; complete loss of accuracy by argument reduction. 5, error - no computation; algorithm termination condition not met. If true, function will return Airy derivative instead of the actual Airy (AI) function. If true, result function or it's derivative is scaled by Exp(z), where z = (2/3)*(Z)^(3/2) *) function Airy(Z: TCplx; Derive, Scale: boolean; var Error: integer): TCplx; overload; function Airy(Z: TSCplx; Derive, Scale: boolean; var Error: integer): TSCplx; overload; (*Airy function of the second kind (Real argument). the Airy function Airy of the second kind (BI) for real argument X. Defines real value where BI should be evaluated.*) function Biry(A: double): double; overload; function Biry(A: single): single; overload; (*Airy function of the second kind (Complex argument). the Airy function Airy of the second kind (BI) for complex argument X. Defines complex value where BI should be evaluated.*) function Biry(Z: TCplx): TCplx; overload; function Biry(Z: TSCplx): TSCplx; overload; (*Airy function or it's derivative of the second kind (Real argument, allows derivative and scale). the Airy function or it's derivative of the second kind (BI). Defines complex value where BI or it's derivative should be evaluated. If true, function will return Airy (BI) derivative instead of the actual Airy (BI) function. If true, result function (BI) or it's derivative is scaled by Exp(-|z|*|z|), where z = z = (2/3)*(Z)^(3/2) Returns error code after the calculation. Return values are: 0, Normal return - Computation completed. 1, input error - no computation. 2, overflow - no computation; dreal(zta)- too large with Scaling=false. 3, zabs(z) large - computation completed. Losses of signifcance by argument reduction produce less than half of machine accuracy. 4, zabs(z) too large - no computation; complete loss of accuracy by argument reduction. 5, error - no computation; algorithm termination condition not met. *) function Biry(A: double; Derive, Scale: boolean; var Error: integer): double; overload; function Biry(A: single; Derive, Scale: boolean; var Error: integer): single; overload; (*Airy function of the second kind or it's derivative (Complex argument, allows derivative or scale. If is true, it will return derivative of Airy function of the second kind (BI). Additionaly, if is true, result is additionaly multiplied by factor (see above). If is false, it will return Airy function of the second kind (BI). Function independant variable, complex value. Returns error code after the calculation. Return values are: 0, Normal return - Computation completed. 1, input error - no computation. 2, overflow - no computation; dreal(zta)- too large with Scaling=false. 3, zabs(z) large - computation completed. Losses of signifcance by argument reduction produce less than half of machine accuracy. 4, zabs(z) too large - no computation; complete loss of accuracy by argument reduction. 5, error - no computation; algorithm termination condition not met. If true, function will return Airy (BI) derivative instead of the actual Airy (BI) function. If true, result function (BI) or it's derivative is scaled by Exp(-|z|*|z|), where z = z = (2/3)*(Z)^(3/2) *) function Biry(Z: TCplx; Derive, Scale: boolean; var Error: integer): TCplx; overload; function Biry(Z: TSCplx; Derive, Scale: boolean; var Error: integer): TSCplx; overload; (*Bessel function of the first kind Jn(Z) (Complex argument). the Bessel function of the first kind Jn(Z) with NU parameter describing order of Bessel function. Defines complex value for which Jn(Z) should be evaluated. Defines the order of the Bessel function of the first kind Jn.*) function Besj(NU: double; Z: TCplx): TCplx; overload; function Besj(NU: single; Z: TSCplx): TSCplx; overload; (*Bessel function of the first kind Jn(Z) (Real argument). the Bessel function of the first kind Jn(Z) with NU parameter describing order of Bessel function. Defines the order of the Bessel function of the first kind Jn. Defines real value for which Jn(A) should be evaluated.*) function Besj(NU: double; A: double): TCplx; overload; function Besj(NU: single; A: single): TSCplx; overload; (*Bessel function of the first kind Jn(Z) (Complex argument, can be scaled). the Bessel function of the first kind Jn(Z) with NU parameter describing order of Bessel function. If Scale parameter is true, Jn(Z) is multiplied by exp(-|Im(Z)|) Defines the order of the Bessel function of the first kind Jn. Defines complex value for which Jn(Z) should be evaluated. If Scale parameter is true, Jn(Z) is multiplied by exp(-|Im(Z)|). *) function Besj(NU: double; Z: TCplx; Scale: boolean): TCplx; overload; function Besj(NU: single; Z: TSCplx; Scale: boolean): TSCplx; overload; (*Bessel function of the first kind Jn(Z) (Complex argument, can be scaled). the Bessel function of the first kind Jn(Z) with NU parameter describing order of Bessel function. If Scale parameter is true, Jn(Z) is multiplied by exp(-|Im(Z)|) Defines the order of the Bessel function of the first kind Jn. Defines complex value for which Jn(Z) should be evaluated. Contains the result, which is an array: resCY[I]=Exp(-Abs(Y))*J(FNU+I,Z) , I = 0...,N-1 , Y=Imag(Z). The part Exp(-Abs(Y)) is applied only if Scaling is True. The length of the array N is specified with resCY.Length on input. If Scale parameter is true, Jn(Z) is multiplied by exp(-|Im(Z)|).*) procedure Besj(NU: double; Z: TCplx; resCY: TVec; Scale: boolean); overload; (*Bessel function of the first kind Jn(A) (Real argument, can be scaled). the Bessel function of the first kind Jn(Z) with NU parameter describing order of Bessel function. If parameter is true, Jn(Z) is multiplied by factor (see above). Defines the order of the Bessel function of the first kind Jn. Defines real value for which Jn(A) should be evaluated. If Scale parameter is true, Jn(A) is multiplied by exp(-|Im(A)|).*) function Besj(NU: double; A: double; Scale: boolean): TCplx; overload; function Besj(NU: single; A: single; Scale: boolean): TSCplx; overload; (*Bessel function of the second kind Yn(Z) (Complex argument). the Bessel function of the second kind Yn(Z), with NU parameter describing order of Bessel function. Defines complex value for which JYn(Z) should be evaluated. Defines the order of the Bessel function of the second kind Jn.*) function Besy(NU: double; Z: TCplx): TCplx; overload; function Besy(NU: single; Z: TSCplx): TSCplx; overload; (*Bessel function of the second kind Yn(Z) (Real argument). the Bessel function of the second kind Yn(A), with NU parameter describing order of Bessel function. Defines real value for which JYn(Z) should be evaluated. Defines the order of the Bessel function of the second kind Jn.*) function Besy(NU, A: double): TCplx; overload; function Besy(NU, A: single): TSCplx; overload; (*Bessel function of the second kind Yn(Z) (Complex argument, can be scaled). the Bessel function of the second kind Yn(Z), with NU parameter describing order of Bessel function.If parameter is true, Yn(Z) is multiplied by appropriate factor (see below). Defines complex value for which Yn(Z) should be evaluated. Defines the order of the Bessel function of the second kind Yn. If Scale parameter is true, Yn(Z) is multiplied by -exp(-|Im(Z)|). *) function Besy(NU: double; Z: TCplx; Scale: boolean): TCplx; overload; function Besy(NU: single; Z: TSCplx; Scale: boolean): TSCplx; overload; (*Bessel function of the second kind Yn(A) (Real argument, can be scaled). the Bessel function of the second kind Yn(A), with NU parameter describing order of Bessel function. If Scale parameter is true, Yn(A) is multiplied by appropriate factor (see below). Defines real value for which Yn(A) should be evaluated. Defines the order of the Bessel function of the second kind >n. If Scale parameter is true, Yn(A) is multiplied by -exp(-|Im(A)|).*) function Besy(NU,A: double; Scale: boolean): TCplx; overload; function Besy(NU,A: single; Scale: boolean): TSCplx; overload; procedure Besy(NU: double; Z: TCplx; resCY: TVec; Scale: boolean); overload; (*Modified Bessel function of the first kind In(Z) (complex argument). modified Bessel function of the first kind In(Z), with NU parameter describing order of modified Bessel function In(Z). Defines the order of In(Z). Defines complex value for which In(Z) should be evaluated.*) function Besi(NU: double; Z: TCplx): TCplx; overload; function Besi(NU: single; Z: TSCplx): TSCplx; overload; (*Modified Bessel function of the first kind In(A) (real argument). modified Bessel function of the first kind In(A), with NU parameter describing order of modified Bessel function In(A). Defines the order of In(A). Defines real value for which In(A) should be evaluated.*) function Besi(NU, A: double): TCplx; overload; function Besi(NU, A: single): TSCplx; overload; (*Modified Bessel function of the first kind In(Z) (Complex argument, can be scaled). the modified Bessel function of the first kind In(Z), with NU parameter describing order of Bessel function.If parameter is true, Kn(Z) is multiplied by appropriate factor (see below). Defines complex value for which In(Z) should be evaluated. Defines the order of the Bessel function of the first kind In. If Scale parameter is true, In(Z) is multiplied by exp(-|Re(Z)|). *) function Besi(NU: double; Z: TCplx; Scale: boolean): TCplx; overload; function Besi(NU: single; Z: TSCplx; Scale: boolean): TSCplx; overload; (*Modified Bessel function of the first kind In(Z) (Complex argument, can be scaled). the modified Bessel function of the first kind In(Z), with NU parameter describing order of Bessel function.If parameter is true, Kn(Z) is multiplied by appropriate factor (see below). Defines complex value for which In(Z) should be evaluated. Defines the order of the Bessel function of the first kind In. If Scale parameter is true, In(Z) is multiplied by exp(-|Re(Z)|). Contains result on output and needs to be sized to desired N on input. The result holds: cyRes[j] = I(NU + j, Z)*Exp(-|Re(A)|) when scaled and cyRes[j] = I(NU + j, Z) otherwise.*) procedure Besi(NU: double; const Z: TCplx; const resCY: TVec; Scale: boolean); overload; (*Modified Bessel function of the first kind In(A) (Real argument, can be scaled). the modified Bessel function of the first kind In(A), with NU parameter describing order of Bessel function.If Scale parameter is true, Kn(A) is multiplied by appropriate factor (see below). Defines real value for which In(A) should be evaluated. Defines the order of the Bessel function of the first kind In. If Scale parameter is true, In(A) is multiplied by Exp(-|Re(A)|).*) function Besi(NU, A: double; Scale: boolean): TCplx; overload; function Besi(NU, A: single; Scale: boolean): TSCplx; overload; (*Modified Bessel function of the third kind - Hankel function H(Z) (Real argument). modified Bessel function of the third kind - Hankel function H(A). Defines the order of Hankel function. Defines real value for which H(A) should be evaluated.*) (*Modified Bessel function of the second kind Kn(Z) (complex argument). modified Bessel function of the second kind Kn(Z), with NU parameter describing order of modified Bessel function. Defines the order of Hankel function. Defines complex value for which Kn(Z) should be evaluated.*) function Besk(NU: double; Z: TCplx): TCplx; overload; function Besk(NU: single; Z: TSCplx): TSCplx; overload; (*Modified Bessel function of the second kind Kn(A) (real argument). modified Bessel function of the second kind Kn(A), with NU parameter describing order of modified Bessel function. Defines the order of Hankel function. Defines real value for which Kn(A) should be evaluated.*) function Besk(NU, A: double): TCplx; overload; function Besk(NU, A: single): TSCplx; overload; (*Bessel function of the second kind Kn(Z) (Complex argument, can be scaled). the Bessel function of the second kind Kn(Z), with NU parameter describing order of Bessel function.If parameter is true, Kn(Z) is multiplied by appropriate factor (see below). Defines complex value for which Kn(Z) should be evaluated. Defines the order of the Bessel function of the second kind Kn. If Scale parameter is true, Kn(Z) is multiplied by exp(Z). *) function Besk(NU: double; Z: TCplx; Scale: boolean): TCplx; overload; function Besk(NU: single; Z: TSCplx; Scale: boolean): TSCplx; overload; (*Bessel function of the second kind Kn(A) (Real argument, can be scaled). the Bessel function of the second kind Kn(A), with NU parameter describing order of Bessel function.If Scale parameter is true, Kn(A) is multiplied by appropriate factor (see below). Defines real value for which Kn(A) should be evaluated. Defines the order of the Bessel function of the second kind Kn. If Scale parameter is true, Kn(A) is multiplied by exp(Z).*) function Besk(NU,A: double; Scale: boolean): TCplx; overload; function Besk(NU,A: single; Scale: boolean): TSCplx; overload; (*Modified Bessel function of the second kind Kn(Z) (complex argument). modified Bessel function of the second kind Kn(Z), with NU parameter describing order of modified Bessel function. Defines the order of Hankel function. Defines complex value for which Kn((Z) should be evaluated. Contains result on output and needs to be sized to desired N on input. The result holds: cyRes[i] = K(NU + i, Z)*Exp(Z) when scaled and cyRes[i] = K(NU + i, Z) when not scaled. If Scale parameter is true, Kn(A) is multiplied by exp(Z).*) procedure Besk(NU: double; Z: TCplx; resCY: TVec; Scale: boolean); overload; (*Modified Bessel function of the third kind - Hankel function H(Z) (Complex argument). modified Bessel function of the third kind - Hankel function H(z). Defines the order of Hankel function. Defines complex value for which H(Z) should be evaluated.*) function Besh(NU: double; Z: TCplx): TCplx; overload; function Besh(NU: single; Z: TSCplx): TSCplx; overload; (*Modified Bessel function of the third kind - Hankel function H(Z) (Real argument). modified Bessel function of the third kind - Hankel function H(A). Defines the order of Hankel function. Defines real value for which H(A) should be evaluated.*) function Besh(NU,A: double): TCplx; overload; function Besh(NU,A: single): TSCplx; overload; (*Hankel function H(z) of the first or second kind (Complex argument, first or second kind, can be scaled. modified Bessel function of the third kind - Hankel function H(z). If parameter FirstKind is true, the return function will be Hankel function of the first kind. If false, the return function will be Hankel function of second kind. If Scale parameter is true, the result will be multiplied by scale factor Exp(+i*z) or Exp(-i*z), depending on FirstKind parameter value. Defines complex value for which H(Z) should be evaluated. describes the order of Hankel function. If true, calculate Hankel function of first kind, if false, calculate Hankel function of second kind. If true, the result will be multiplied by scale factor Exp(+i*z) or Exp(-i*z), depending on FirstKind parameter value. *) function Besh(NU: double; Z: TCplx; Scale, FirstKind: boolean): TCplx; overload; function Besh(NU: single; Z: TSCplx; Scale, FirstKind: boolean): TSCplx; overload; (*Hankel function H(z) of the first or second kind (Complex argument, first or second kind, can be scaled. modified Bessel function of the third kind - Hankel function H(z). If parameter FirstKind is true, the return function will be Hankel function of the first kind. If false, the return function will be Hankel function of second kind. If Scale parameter is true, the result will be multiplied by scale factor Exp(+i*z) or Exp(-i*z), depending on FirstKind parameter value. Defines complex value for which H(Z) should be evaluated. describes the order of Hankel function. Contains result on output and resCY.Length specifies the length "N" on input. Will hold on output (FirstKind): resCY[j] = H(M, NU + j, Z) * Expj(-Z) Second kind: resCY[j] = H(M, NU + j, Z) * Expj(Z) if Scaling is enabled. Otherwise just: resCY[j] = H(M, NU + j, Z) If true, calculate Hankel function of first kind, if false, calculate Hankel function of second kind. If true, the result will be multiplied by scale factor Expj(z) or Expj(-z), depending on FirstKind parameter value.*) procedure Besh(NU: double; Z: TCplx; resCY: TVec; Scale, FirstKind: boolean); overload; (*Hankel function H(z) of the first or second kind (Real argument, first or second kind, can be scaled. modified Bessel function of the third kind - Hankel function H(A). If parameter is true, the return function will be Hankel function of the first kind. If false, the return function will be Hankel function of second kind. If Scale parameter is true, the result will be multiplied by scale factor Exp(+i*A) or Exp(-i*A), depending on FirstKind parameter value. Defines real value for which H(Z) should be evaluated. describes the order of Hankel function. If true, calculate Hankel function of first kind, if false, calculate Hankel function of second kind. If true, the result will be multiplied by scale factor Exp(+i*A) or Exp(-i*A), depending on FirstKind parameter value.*) function Besh(NU,A: double; Scale, FirstKind: boolean): TCplx; overload; function Besh(NU,A: single; Scale, FirstKind: boolean): TSCplx; overload; (*Associated Legendre polynomial P(l,m,x). Defines value at which the Legendre polynomial will be evaluated. Valid x values are real values on closed interval [-1,1]. Defines Legenre polynomial parameter l. Defines Legenre polynomial parameter m, defined for closed interval [0,l]. The associated Legendre polynomial P(l,m,x).*) function LegendreP(l, m: Integer; X: double): double; overload; function LegendreP(l, m: Integer; X: single): single; overload; (*The associated Legendre polynomial P(l,0,x), (m = 0). Defines value at which the Legendre polynomial will be evaluated. Valid x values are real values on closed interval [-1,1]. Defines Legenre polynomial parameter l. The associated Legendre polynomial P(l,0,x), (m = 0).*) function LegendreP(l: Integer; X: double): double; overload; function LegendreP(l: Integer; X: single): single; overload; (*The associated Legendre polynomials for l= 0.. n, P(l,0,x). Defines value at which the Legendre polynomials will be evaluated. Valid x values are real values on closed interval [-1,1]. Defines upper limit for Legentre polynomials. n must be less or equal to l. Returns Legendre polynomials P(0,0,x), P(1,x),...P(n,0,x).*) procedure LegendreP(n: Integer; X: double; result: TDenseMtxVec); overload; procedure LegendreP(n: Integer; X: single; result: TDenseMtxVec); overload; (* Computes exponentional integral Ei(X) . X may not be equal 0. *) function EI(X: Double): Double; overload; (* Computes exponentional integral exp(-X)*Ei(X) .*) function ExpEI(X: Double): Double; overload; (* Computes exponentional integral -Ei(-X) . X must be greater than zero. *) function E1(X: Double): Double; overload; (*Solvers for toeplitz matrices. Solvers for real and complex toeplitz matrices. *) unit Toeplitz; interface {$I BdsppDefs.inc} uses AbstractMtxVec, MtxVec, Math387 ,Nmkl ,NmklSingle ,SysUtils ; (*Solve a toepltiz system of linear equations. Defines the first row R(0)..R(N-1) in the equation below. Vector can be real or complex. Defines the first column C(0)..C(N-2) in the equation below. FirstCol.Length must be equal to FirstRow.Length-1. Vector can be real or complex. Defines B vector in equation below. Returns X vector as solution in the equation below. The procedures solves Toeplitz system of linear equations defined as: [ R(0) R(1) ... R(N-1) ] [ X(0) ] = [ -B(0) ] [ C(0) R(0) ... R(N-2) ] [ X(1) ] = [ -B(1) ] [ .... . . ] x [ . ] = [ . ] [ C(N-1) C(N-2) ... R(1) ] [ X(N-2)] = [ -B(N-2) ] [ C(N-2) C(N-1) ... R(0) ] [ X(N-1)] = [ -B(N-1) ] The computational complexity of the algorithm is O(n2) as oposed to at least O(n3) for solving a general matrix. using Dew.Math; using Dew.Math.Units; using Dew.Math.Editors; namespace Dew.Examples { private void Example() { Vector FirstRow = new Vector(0); Vector FirstCol = new Vector(0); Vector X1 = new Vector(0); Vector X2 = new Vector(0); Vector B = new Vector(0); Vector R = new Vector(0; Matrix A = new Matrix(0,0); FirstRow.SetIt(false,new double[] {1,2,3,4}); FirstCol.SetIt(false,new double[] {2,3,4}); A.Toeplitz(FirstRow,FirstCol); B.SetIt(false, new double[] {-2,-3,-4,-5}); R.Copy(FirstRow); R.Resize(5); R.Values[4] = 5; Toeplitz.ToeplitzSolve(FirstRow, FirstCol,B, X1); A.LUSolve(B,X2,MtxVec.mtGeneral); MtxVecEdit.ViewValues(X1,"Real X1",true); Toeplitz.Levinson(R,X2); MtxVecEdit.ViewValues(X2,"Real X2",true); } } *) procedure ToeplitzSolve(FirstRow,FirstCol,B,X: TVec); overload; (*Solves toeplitz system. Defines the first row R(0)..R(N-1) in the equation below. Defines B vector in equation below. Returns X vector in the equation below. Solves toeplitz system, defined as: [ R(0) R(1)* ... R(N-1)* ] [ X[1] ] = [ -B[1] ] [ R(1) R(0) ... R(N-2)* ] [ X[2] ] = [ -B[2] ] [ .... . . ] x [ . ] = [ . ] [ R(N-2) R(N-3) ... R(1)* ] [ X[N-1] ] = [ -B[N-1] ] [ R(N-1) R(N-2) ... R(0) ] [ X[N] ] = [ -B[N] ] *) procedure ToeplitzSolve(FirstRow,B,X: TVec); overload; (*Solves a toeplitz system. The solution is stored in vector A. The first element of A at Index 0 is set to 1. The sign '*' stands for conjugation. can be real or complex. N is equal to R.Length-1. The procedures solves Toeplitz system of linear equations defined as: [ R(0) R(1)* ... R(N-1)* ] [ A[1] ] = [ -R[1] ] [ R(1) R(0) ... R(N-2)* ] [ A[2] ] = [ -R[2] ] [ .... . . ] x [ . ] = [ . ] [ R(N-2) R(N-3) ... R(1)* ] [ A[N-1] ] = [ -R[N-1] ] [ R(N-1) R(N-2) ... R(0) ] [ A[N] ] = [ -R[N] ] The computational complexity of the algorithm is O(n2) as oposed to at least O(n3) for LUSolve. *) procedure Levinson(R,A: TVec);