Up \ObjAlg
{@abstract( implementation of basic
1D and 2D boolean arrays,
1D and 2D integer arrays and
1D, 2D and 3D float arrays)
created: 2001.02.02)
last modified: 2004.02.02)
author: Nikolai Shokhirev )
ŠNikolai V. Shokhirev, 2001-2004
<pre> 1D Tensor notation
+---------+
Lo | a[Lo ] |
Lo+1 | a[Lo+1] |
| ....... |
Hi | a[Hi ] |
+---------+
2D Tensor notation
Lo2 Lo2+1 Hi2
+-----------------------------------------------+
Lo1 | a[Lo1 ,Lo2] a[Lo1 ,Lo2+1] .. a[Lo1, Hi2 ] | Row Lo1
Lo1+1| a[Lo1+1,Lo2] a[Lo1+1,Lo2+1] .. a[Lo1+1,Hi2] | Row Lo1+1
.| ................... .. ..................... | .........
Hi1 | a[Hi1 ,Lo2] a[Hi1 ,Lo2+1] .. a[Hi1, Hi2 ] | Row Hi1
+-----------------------------------------------+
Col Lo2 Col Lo2+1 .. Col Hi2 </pre> }
unit uTensors;
{$R-}
interface
uses
uMatTypes;
type
{ Interface for Basic 1D Array: Array [Lo..Hi] of Boolean}
IBTensor1D = interface(ILimits1D)
['{4849D690-1C52-11D7-82A2-00C04F2859BF}']
procedure Fill(v: boolean);
procedure AssignData(const A: IBTensor1D);
procedure Swap(i, j: TInt);
property Value[i: TInt]: boolean read GetValue write SetValue; default;
end;
{ Interface for Basic 2D Array: Array [Lo1..Hi11,Lo1..Hi12] of Boolean }
IBTensor2D = interface(ILimits2D)
['{4849D691-1C52-11D7-82A2-00C04F2859BF}']
procedure Fill(v: boolean);
procedure AssignData(const A: IBTensor2D);
procedure SwapRows(i1,j1: TInt);
procedure SwapColumns(i2, j2: TInt); // fast pointer operation
property Value[i1,i2: TInt]: boolean read GetValue write SetValue; default;
end;
{ Interface for Basic 1D Array: Array [Lo..Hi] of TInt }
IIntTensor1D = interface(ILimits1D)
['{4849D692-1C52-11D7-82A2-00C04F2859BF}']
procedure Fill(v: integer);
procedure AssignData(const A: IIntTensor1D; imin: TInt = LowInt; imax: TInt = HighInt);
procedure Swap(i,j: TInt);
property Value[i: TInt]: TInt read GetValue write SetValue; default;
end;
{ Interface for Basic 2D Array: Array [Lo1..Hi11, Lo1..Hi12] of TInt }
IIntTensor2D = interface(ILimits2D)
['{4849D693-1C52-11D7-82A2-00C04F2859BF}']
procedure Fill(v: integer);
procedure SwapRows(i1,j1: TInt);
procedure SwapColumns(i2,j2: TInt); // fast pointer operation
procedure AssignData(const A: IIntTensor2D);
property Value[i1,i2: TInt]: TInt read GetValue write SetValue; default;
end;
{ Interface for Basic 1D Array: Array [Lo..Hi] of TFloat }
ITensor1D = interface(ILimits1D)
['{4849D694-1C52-11D7-82A2-00C04F2859BF}']
procedure Fill(v: TFloat);
// default value LowInt is replaced with Lo and HighInt is replaced with Hi
procedure AssignData(const A: ITensor1D; imin: TInt = LowInt; imax: TInt = HighInt);
procedure AssignValues(const A: ITensor1D);
procedure Swap(i, j: TInt);
property Value[i: TInt]: TFloat read GetValue write SetValue; default;
end;
{ Interface for Basic 2D Array: Array [Lo1..Hi11, Lo1..Hi12] of TInt }
ITensor2D = interface(ILimits2D)
['{4849D695-1C52-11D7-82A2-00C04F2859BF}']
procedure Fill(v: TFloat);
procedure AssignData(const A: ITensor2D);
procedure SwapRows(i1,j1: TInt);
procedure SwapColumns(i2, j2: TInt); // fast pointer operation
property Value[i1,i2: TInt]: TFloat read GetValue write SetValue; default;
end;
{ Interface for Basic 3D Array: Array [Lo1..Hi11,Lo1..Hi12,Lo1..Hi13] of TFloat }
ITensor3D = interface(ILimits3D)
['{4849D696-1C52-11D7-82A2-00C04F2859BF}']
procedure Fill(v: TFloat);
procedure AssignData(const A: ITensor3D);
procedure SwapMatrices(i3, j3: TInt); // fast pointer operation
property Value[i1,i2,i3: TInt]: TFloat read GetValue write SetValue; default;
end;
{ Objects -------------------------------------------------------------------- }
{ Basic Dynamic 1D Array: Array [Lo1..Hi1] of Boolean }
TBTensor1D = class(TInterfacedObject, IBTensor1D)
public
constructor Create; overload; virtual;
constructor Create(aDim: TInt; v: boolean = false); overload; virtual;
destructor Destroy; override;
procedure SetSize(aDim: TInt);
procedure Fill(v: boolean);
procedure AssignData(const A: IBTensor1D);
procedure Swap(i, j: TInt);
property Base: TInt read GetBase write SetBase;
property Lo: TInt read GetLo;
property Hi: TInt read GetHi;
property Dim: TInt read GetDim;
property Value[i: TInt]: boolean read GetValue write SetValue; default;
end;
{ Basic Dynamic 2D Array: Array [Lo1..Hi11, Lo1..Hi12] of Boolean }
TBTensor2D = class(TInterfacedObject, IBTensor2D)
public
constructor Create; overload; virtual;
constructor Create(aDim1, aDim2: TInt; v: boolean = false); overload; virtual;
// constructor Create(aDim1, aDim2: TInt; v: boolean = false; aBase1: TInt = 1; aBase: TInt = 1); overload; virtual;
destructor Destroy; override;
procedure SetSize(aDim1, aDim2: TInt);
procedure Fill(v: boolean);
procedure AssignData(const A: IBTensor2D);
procedure SwapRows(i1,j1: TInt);
procedure SwapColumns(i2, j2: TInt);
property Lo1: TInt read GetLo1;
property Hi1: TInt read GetHi1;
property Lo2: TInt read GetLo2;
property Hi2: TInt read GetHi2;
property Base1: TInt read GetBase1 write SetBase1;
property Base2: TInt read GetBase2 write SetBase2;
property Dim1: TInt read GetDim1;
property Dim2: TInt read GetDim2;
property Value[i1,i2: TInt]: boolean read GetValue write SetValue; default;
end;
{ Basic Dynamic 1D Array: Array [Lo..Hi] of TInt }
TIntTensor1D = class(TInterfacedObject, IIntTensor1D)
public
constructor Create; overload; virtual;
constructor Create(aDim: TInt); overload; virtual;
constructor Create(V:IIntTensor1D); overload; virtual;
destructor Destroy; override;
procedure SetSize(aDim: TInt);
procedure Fill(v: integer);
procedure AssignData(const A: IIntTensor1D; imin: TInt = LowInt; imax: TInt = HighInt);
procedure Swap(i,j: TInt);
procedure SetValue(i: TInt; v: TInt);
property Lo: TInt read GetLo;
property Hi: TInt read GetHi;
property Base: TInt read GetBase write SetBase;
property Dim: TInt read GetDim;
property Value[i: TInt]: TInt read GetValue write SetValue; default;
end;
{ Basic Dynamic 2D Array: Array [Lo1..Hi11, Lo1..Hi12] of TInt }
TIntTensor2D = class(TInterfacedObject, IIntTensor2D)
public
constructor Create; overload; virtual;
constructor Create(aDim1, aDim2: TInt); overload; virtual;
constructor Create(M: IIntTensor2D); overload; virtual;
destructor Destroy; override;
procedure SetSize(aDim1, aDim2: TInt);
procedure Fill(v: integer);
procedure SwapRows(i1,j1: TInt);
procedure AssignData(const A: IIntTensor2D);
procedure SwapColumns(i2, j2: TInt);
property Lo1: TInt read GetLo1;
property Hi1: TInt read GetHi1;
property Lo2: TInt read GetLo2;
property Hi2: TInt read GetHi2;
property Base1: TInt read GetBase1 write SetBase1;
property Base2: TInt read GetBase2 write SetBase2;
property Dim1: TInt read GetDim1;
property Dim2: TInt read GetDim2;
property Value[i1,i2: TInt]: TInt read GetValue write SetValue; default;
end;
{ Basic Dynamic 1D Array: Array [Lo..Hi] of TFloat }
TTensor1D = class(TInterfacedObject, ITensor1D)
public
constructor Create; overload; virtual;
constructor Create(aDim: TInt); overload; virtual;
constructor Create(V: ITensor1D); overload; virtual;
destructor Destroy; override;
procedure SetSize(aDim: TInt);
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);
property Lo: TInt read GetLo;
property Hi: TInt read GetHi;
property Base: TInt read GetBase write SetBase;
property Dim: TInt read GetDim;
property Value[i: TInt]: TFloat read GetValue write SetValue; default;
end;
{ Basic Dynamic 2D Array: Array [Lo1..Hi11,Lo1..Hi12] of TFloat }
TTensor2D = class(TInterfacedObject, ITensor2D)
public
constructor Create; overload; virtual;
constructor Create(aDim1, aDim2: TInt); overload; virtual;
constructor Create(M: ITensor2D); overload; virtual;
destructor Destroy; override;
procedure SetSize(aDim1, aDim2: TInt);
procedure Fill(v: TFloat);
procedure SwapRows(i1,j1: TInt);
procedure AssignData(const A: ITensor2D);
procedure SwapColumns(i2, j2: TInt); // virtual;
property Lo1: TInt read GetLo1;
property Hi1: TInt read GetHi1;
property Lo2: TInt read GetLo2;
property Hi2: TInt read GetHi2;
property Base1: TInt read GetBase1 write SetBase1;
property Base2: TInt read GetBase2 write SetBase2;
property Dim1: TInt read GetDim1;
property Dim2: TInt read GetDim2;
property Value[i1,i2: TInt]: TFloat read GetValue write SetValue; default;
end;
{ Basic Dynamic 3D Array: Array [Lo1..Hi11,Lo1..Hi12,Lo1..Hi13] of TFloat }
TTensor3D = class(TInterfacedObject, ITensor3D)
public
constructor Create; overload; virtual;
constructor Create(aDim1,aDim2,aDim3: TInt); overload; virtual;
constructor Create(M: ITensor3D); overload; //virtual;
Destructor Destroy; override;
procedure Fill(v: TFloat);
procedure AssignData(const A: ITensor3D);
procedure SetSize(aDim1, aDim2, aDim3: TInt); virtual;
procedure SwapMatrices(i3, j3: TInt);
property Lo1: TInt read GetLo1;
property Hi1: TInt read GetHi1;
property Lo2: TInt read GetLo2;
property Hi2: TInt read GetHi2;
property Lo3: TInt read GetLo3;
property Hi3: TInt read GetHi3;
property Base1: TInt read GetBase1 write SetBase1;
property Base2: TInt read GetBase2 write SetBase2;
property Base3: TInt read GetBase3 write SetBase3;
property Dim1: TInt read GetDim1;
property Dim2: TInt read GetDim2;
property Dim3: TInt read GetDim3;
property Value[i1, i2, i3: TInt]: TFloat read GetValue write SetValue; default;
end;
implementation
end.
Up \ObjAlg