Up \ObjAlg
{@abstract( interfaces and implementation of
1D and 2D boolean, 1D and 2D integer and 1D, 2D and 3D float arrays)
author: Nikolai Shokhirev )
created: February 02, 2001)
last modified: June 06, 2003)
ŠNikolai V. Shokhirev, 2001-2003
<pre> 2D Matrix notation <br>
Lo2 Lo2+1 Hi2 <br>
+-----------------------------------------------+<br>
Lo1 | a[Lo1 ,Lo2] a[Lo1 ,Lo2+1] .. a[Lo1, Hi2 ] | Row Lo1 <br>
Lo1+1| a[Lo1+1,Lo2] a[Lo1+1,Lo2+1] .. a[Lo1+1,Hi2] | Row Lo1+1 <br>
.| ................... .. ..................... | .........<br>
Hi1 | a[Hi1 ,Lo2] a[Hi1 ,Lo2+1] .. a[Hi1, Hi2 ] | Row Hi1 <br>
+-----------------------------------------------+ <br>
Col Lo2 Col Lo2+1 .. Col Hi2 <pre>}
unit uArrays;
interface
uses
uMatTypes, uTensors;
type
{ Interfaces - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - }
{ Interface for Dynamic 1D Array: Array [Lo1..Hi1] of Boolean }
IBVector = interface(IBTensor1D)
['{05495060-1C53-11D7-82A2-00C04F2859BF}']
// no new functionality so far ...
end;
{ Interface for Dynamic 2D Array: Array [Lo1..Hi1, Lo2..Hi2] of Boolean }
IBMatrix = interface(IBTensor2D)
['{05495061-1C53-11D7-82A2-00C04F2859BF}']
// no new functionality so far ...
end;
{ Interface for Dynamic 1D Array: Array [Lo1..Hi1] of TInt }
IIntVector = interface(IIntTensor1D)
['{05495062-1C53-11D7-82A2-00C04F2859BF}']
function GetMaxAbs: TInt;
property MaxAbs: TInt read GetMaxAbs;
end;
{ Interface for Dynamic 2D Array: Array [Lo1..Hi1, Lo2..Hi2] of TInt }
IIntMatrix = interface(IIntTensor2D)
['{05495063-1C53-11D7-82A2-00C04F2859BF}']
procedure AssignScalar(v: TInt);
procedure AssignDiag(D: IIntVector);
function IsSquare: boolean;
procedure Transpose;
end;
{ Interface for Dynamic 1D Array: Array [Lo1..Hi1] of TFloat }
IVector = interface(ITensor1D)
['{05495064-1C53-11D7-82A2-00C04F2859BF}']
function MaxAbsIndex(var val: TFloat; imin: TInt = LowInt; imax: TInt = HighInt):TInt;
function GetMaxAbs: TFloat;
procedure CxSelf(C: TFloat; imin: TInt = LowInt; imax: TInt = HighInt);
property MaxAbs: TFloat read GetMaxAbs;
procedure Shift(h: TFloat; imin: TInt = LowInt; imax: TInt = HighInt);
function GetNorm: TFloat;
function GetNorm2: TFloat;
procedure Normalize;
function Dot(const V: IVector; imin: TInt = LowInt; imax: TInt = HighInt): TFloat;
procedure Add(h: TFloat; const V: IVector; imin: TInt = LowInt; imax: TInt = HighInt);
property Norm: TFloat read GetNorm;
end;
{ Interface for Dynamic 2D Array: Array [Lo1..Hi1, Lo2..Hi2] of TInt }
IMatrix = interface(ITensor2D)
['{05495065-1C53-11D7-82A2-00C04F2859BF}']
function GetMaxAbs: TFloat;
procedure CxSelf(C: TFloat);
property MaxAbs: TFloat read GetMaxAbs;
procedure Transpose;
function GetCol(i2: TInt): IVector;
function GetRow(i1: TInt): IVector;
procedure AssignScalar(v: TFloat);
procedure AssignDiag(D: IVector);
function IsSquare: boolean;
property Col[i2: TInt]: IVector read GetCol;
property Row[i1: TInt]: IVector read GetRow;
end;
{ Interface for Dynamic 3D Array: Array [Lo1..Hi1, Lo2..Hi2, Lo3..Hi3] of TFloat }
IMatrix3D = interface(ITensor3D)
['{05495066-1C53-11D7-82A2-00C04F2859BF}']
function GetMaxAbs: TFloat;
procedure CxSelf(C: TFloat);
property MaxAbs: TFloat read GetMaxAbs;
// function GetMatrix(i3: TInt): IMatrix;
// property Matrix[i3: TInt]: IMatrix read GetMatrix;
end;
{ Dynamic 1D Array: Array [Lo1..Hi1] of Boolean <br>
- no new functionality so far }
TBVector = class(TBTensor1D, IBVector);
{ Dynamic 2D Array: Array [Lo1..Hi1] of Boolean <br>
- no new functionality so far }
TBMatrix = Class(TBTensor2D, IBMatrix); //
{ Dynamic 1D Array: Array [Lo1..Hi1] of TInt }
TIntVector = class(TIntTensor1D, IIntVector)
protected
function GetMaxAbs: TInt;
public
property MaxAbs: TInt read GetMaxAbs;
end;
{ Dynamic 2D Array: Array [Lo1..Hi1, Lo2..Hi2] of TInt }
TIntMatrix = class(TIntTensor2D, IIntMatrix)
public
procedure AssignScalar(v: TInt);
procedure AssignDiag(D: IIntVector);
function IsSquare: boolean;
procedure Transpose;
end;
{ Dynamic 1D Array: Array [Lo1..Hi1] of TFloat }
TVector = class(TTensor1D, IVector)
protected
function GetNorm2: TFloat;
public
constructor Create(aPVc: VcPtr; aDim: TInt); overload; virtual;
destructor Destroy; override;
function MaxAbsIndex(var val: TFloat; imin: TInt = LowInt; imax: TInt = HighInt):TInt;
function GetMaxAbs: TFloat;
procedure Normalize;
function Dot(const V: IVector; imin: TInt = LowInt; imax: TInt = HighInt): TFloat; // DotProduct <Self|V>
procedure CxSelf(C: TFloat; imin: TInt = LowInt; imax: TInt = HighInt);
procedure Shift(h: TFloat; imin: TInt = LowInt; imax: TInt = HighInt);
procedure Add(h: TFloat; const V: IVector; imin: TInt = LowInt; imax: TInt = HighInt);
property MaxAbs: TFloat read GetMaxAbs;
property Norm: TFloat read GetNorm;
end;
{ Dynamic 2D Array: Array [Lo1..Hi1,Lo2..Hi2] of TFloat }
TMatrix = class(TTensor2D, IMatrix)
public
constructor Create; overload; override; //virtual;
constructor Create(aPMt: MtPtr; aDim1, aDim2: TInt); overload; //virtual;
constructor Create(aDim1, aDim2: TInt); overload; override; // virtual;
constructor Create(M: ITensor2D); overload; override; // virtual;
destructor Destroy; override;
procedure SetSize(aDim1, aDim2: TInt);
procedure CxSELF(C: TFloat);
function GetMaxAbs: TFloat;
procedure AssignScalar(v: TFloat);
procedure AssignDiag(D: IVector);
function IsSquare: boolean;
procedure Transpose;
property MaxAbs: TFloat read GetMaxAbs;
property Col[i2: TInt]: IVector read GetCol; // = M[ ,i2]
property Row[i1: TInt]: IVector read GetRow; // = M[i1, ]
end;
{ Dynamic 3D Array: Array [Lo1..Hi1, Lo2..Hi2, 1Lo3..Hi3] of TFloat }
TMatrix3D = class(TTensor3D, IMatrix3D)
public
constructor Create(aDim1,aDim2,aDim3: TInt); override; //virtual;
procedure SetSize(aDim1, aDim2, aDim3: TInt); override;
procedure CxSelf(C: TFloat);
function GetMaxAbs: TFloat;
property MaxAbs: TFloat read GetMaxAbs;
// property Matrix[i3: TInt]: IMatrix read GetMatrix;
end;
{ IVector implementation for internal use in IMatrix }
TRow = class(TInterfacedObject, IVector)
public
constructor Create(PMt: MtPtr; i1, aDim, aBase: TInt); //virtual;
destructor Destroy; override;
procedure SetSize(aDim: TInt);
function MaxAbsIndex(var val: TFloat; imin: TInt = LowInt; imax: TInt = HighInt):TInt;
function GetMaxAbs: TFloat;
function GetNorm2: TFloat;
procedure Swap(i, j: TInt);
procedure Fill(v: TFloat);
procedure AssignData(const A: ITensor1D; imin: TInt = LowInt; imax: TInt = HighInt);
procedure AssignValues(const A: ITensor1D);
procedure CxSelf(C: TFloat; imin: TInt = LowInt; imax: TInt = HighInt);
procedure Shift(h: TFloat; imin: TInt = LowInt; imax: TInt = HighInt);
procedure Normalize;
function Dot(const V: IVector; imin: TInt = LowInt; imax: TInt = HighInt): TFloat;
procedure Add(h: TFloat; const V: IVector; imin: TInt = LowInt; imax: TInt = HighInt);
property MaxAbs: TFloat read GetMaxAbs;
property Norm: TFloat read GetNorm;
property Lo: TInt read GetLo;
property Hi: TInt read GetHi;
property Dim: TInt read GetDim;
property Base: TInt read GetBase write SetBase;
property Value[i: TInt]: TFloat read GetValue write SetValue; default;
end;
{ IVector implementation for internal use in IMatrix }
TCol = class(TInterfacedObject, IVector)
public
constructor Create(PMt: MtPtr; i2, aDim, aBase, aDim2: TInt); //virtual;
destructor Destroy; override;
procedure SetSize(aDim: TInt);
function MaxAbsIndex(var val: TFloat; imin: TInt = LowInt; imax: TInt = HighInt):TInt;
function GetMaxAbs: TFloat;
function GetNorm2: TFloat;
function GetNorm: TFloat;
procedure Swap(i, j: TInt);
procedure Fill(v: TFloat);
procedure AssignData(const A: ITensor1D; imin: TInt = LowInt; imax: TInt = HighInt);
procedure AssignValues(const A: ITensor1D);
procedure CxSelf(C: TFloat; imin: TInt = LowInt; imax: TInt = HighInt);
procedure Shift(h: TFloat; imin: TInt = LowInt; imax: TInt = HighInt);
procedure Normalize;
function Dot(const V: IVector; imin: TInt = LowInt; imax: TInt = HighInt): TFloat;
procedure Add(h: TFloat; const V: IVector; imin: TInt = LowInt; imax: TInt = HighInt);
property MaxAbs: TFloat read GetMaxAbs;
property Norm: TFloat read GetNorm;
property Lo: TInt read GetLo;
property Hi: TInt read GetHi;
property Dim: TInt read GetDim;
property Base: TInt read GetBase write SetBase;
property Value[i: TInt]: TFloat read GetValue write SetValue; default;
end;
implementation
end.
Up \ObjAlg