The SDL Component Suite is an industry leading collection of components supporting scientific and engineering computing. Please visit the SDL Web site for more information....



Interface of SDL_Matrix

const
{$IFDEF PAIDVERS}
  SDLVersionInfo = 'matrix_r900_full';
  IsLightEd = false;
{$ELSE}
  SDLVersionInfo = 'matrix_r900_lighted';
  IsLightEd = true;
{$ENDIF}
  Release = 900;

type
  ESDLMatrixError = class(ESDLError);      { exception type to indicate errors }
  TMatXmlTag = (xmlMatNumCols, xmlMatNumRows, xmlMatNumPlanes, xmlMatCell,
                xmlMatBegin, xmlMatEnd, xmlInvalid);
  TDistMode = (dmJaccard, dmManhattan, dmEuclid, dmEuclidSqr, dmDice, dmUserDef);
  TOnCalcDistanceEvent = procedure (Sender: TObject; Row1, Row2: integer;
                                    var Distance: double) of object;
  TSpMatElemInt = record
                    colidx  : longint;
                    rowidx  : longint;
                    value   : longint;
                  end;

const
  DistModeId : array[TDistMode] of string =
                  ('Jaccard coefficient', 'Manhattan', 'Euclidean',
                   'squared Euclidean', 'Dice coefficient', 'user defined');

type
  TMatrix = class (TComponent)
            private
              FNCol           : longint;                   { number of columns }
              FNRow           : longint;                      { number of rows }
              FDataID         : string;             { tag to identify the data }
              Mat             : array of array of double;
              FPrecis         : array[1..2] of integer; { format used in StoreOnFile }
              FOnChange       : TNotifyEvent;
              FOnSortExchange : TSortExchgEvent;
              FOnCalcDist     : TOnCalcDistanceEvent;
{$IFDEF PAIDVERS}
              FirstCell       : boolean; {flag to resize matrix during XML input }
              function    ProcessXmlTag (xmlTag: TMatXmlTag;
                                         attr, cont: string): integer;
{$ENDIF}
              function    GetVal (Nc,Nr: longint): double;
              procedure   SetVal (Nc,Nr: longint; Value: double);
              function    GetFPrecis (ix: integer): integer;
              procedure   SetFPrecis (ix: integer; value: integer);
              procedure   SetNCols (value: longint);
              procedure   SetNRows (value: longint);
              procedure   SkewKurtIntern (LowCol, LowRow, HighCol, HighRow: integer;
                              var Skewness, Kurtosis: double; var NumData: longint);
            protected
              procedure   SortExchange (ExchgWhat: byte; index1, index2,
                                        first, last: longint);
            public
              constructor Create (AOwner: TComponent); override;
              destructor  Destroy; override;
              property    Elem[ix,iy: longint]: double
                              read GetVal write SetVal; default;
              function    Add (MatB: TMatrix): boolean;
              function    CalcDistMat (Mode: TDistMode; DMat: TMatrix): integer;
              procedure   Changed;
              procedure   CopyColToVec (DestVec: TVector;
                              Col, FirstRow, LastRow: integer);
              procedure   CopyFrom (MatSource: TMatrix;
                              SourceColLo, SourceRowLo,
                              SourceColHi, SourceRowHi,
                              DestCol, DestRow: integer);
              procedure   Clone (MatSource: TMatrix);
              procedure   CopyFromVec (VecSource: TVector;
                              Source1stElem, SourceLastElem,
                              DestCol, DestRow: integer);
              procedure   CopyRowToVec (DestVec: TVector;
                              Row, FirstCol, LastCol: integer);
              function    Determinant: double;
              procedure   Fill (value: double);
              procedure   Free;
              function    GeometricMean (LowCol, LowRow, HighCol,
                              HighRow: integer): double;
              function    HarmonicMean (LowCol, LowRow, HighCol,
                              HighRow: integer): double;
              function    Histogram (LoX, LoY, HiX, HiY: longint;
                              FirstBin, LastBin, BinWidth: double;
                              Histo: TIntVector; var Underflow, Overflow,
                              MaxCnt: longint): boolean;
              function    Invert: boolean;
              function    LoadFromFile (FileName: string;
                              AdjustMatrixSize: boolean): boolean;
              function    LoadFromStream (InStream: TMemoryStream;
                              AdjustMatrixSize: boolean): boolean;
              function    LoadFromXMLFile (FName: string; DataID: string): boolean;
              function    LUdecomposition (var MatL, MatU: TMatrix): boolean;
              procedure   MeanVar (LowCol, LowRow, HighCol,
                              HighRow: integer; var Mean,
                              Variance: double);
              procedure   MinMax (LowCol, LowRow, HighCol,
                              HighRow: integer; var Minimum,
                              Maximum: double);
              function    Multiply (MatB, MatRes: TMatrix): boolean;
              function    Percentile (prob: double; LowCol, LowRow,
                              HighCol, HighRow: integer): double;
              property    Precision [Index: integer]: integer
                              read GetFPrecis write SetFPrecis;
              function    Quartiles (LowCol, LowRow, HighCol,
                              HighRow: integer; var Q1, Q2, Q3: double): boolean;
              function    ReadFromXMLStream (InStream: TStream;
                              DataID: string): boolean;
              function    ReadFromOpenXMLFile (var InFile: TextFile;
                              DataID: string): boolean;
              function    Resize (Nc, Nr: longint): boolean;
              procedure   SaveAsXMLFile (FName: string; DataID: string);
              procedure   SaveToStream (var OutStream: TMemoryStream;
                              LoC,LoR,HiC,HiR: integer);
              procedure   SkewKurt (LowCol, LowRow, HighCol,
                              HighRow: integer; var Skewness, Kurtosis: double);
              procedure   SkewKurtSample (LowCol, LowRow, HighCol,
                              HighRow: integer; var Skewness, Kurtosis: double);
              procedure   SMult (Scalar: double);
              procedure   SortCols (SortRowIx: integer; Ascending: boolean;
                              LowCol, LowRow, HighCol, HighRow: integer);
              procedure   SortRows (SortColIx: integer; Ascending: boolean;
                              LowCol, LowRow, HighCol,
                              HighRow: integer);
              procedure   StandardizeColumns (Means, StdDevs: TVector);
              procedure   StandardizeRows (Means, StdDevs: TVector);
              function    StoreOnFile
                              (LoC,LoR,HiC,HiR: integer;
                              FileName:string): boolean;
              function    Subtract (MatB: TMatrix): boolean;
              function    Sum (LoC,LoR,HiC,HiR: integer): double;
              function    Transpose: boolean;
              function    Trace: double;
              procedure   WriteToOpenXMLFile (var OutFile : TextFile;
                              CreateHeader: boolean; DataID: string);
              procedure   WriteToXMLStream (OutStream: TStream;
                              CreateHeader: boolean; DataID: string);
            published
              property    NrOfColumns: longint read FNCol write SetNCols;
              property    NrOfRows: longint read FNRow write SetNRows;
              property    DataID: string read FDataID write FDataID;
              property    OnChange: TNotifyEvent read FOnChange write FOnChange;
              property    OnSortExchange: TSortExchgEvent
                              read FOnSortExchange write FOnSortExchange;
              property    OnCalcDistance: TOnCalcDistanceEvent
                              read FOnCalcDist write FOnCalcDist;
            end;

  TIntMatrix = class (TComponent)
            private
              FNCol           : longint;                   { number of columns }
              FNRow           : longint;                      { number of rows }
              FDataID         : string;             { tag to identify the data }
              FIsSparse       : boolean;                 { TRUE: sparse matrix }
              FNumAllocated   : longint; { number of allocated sparse elements }
              FAllocBy        : longint;   { incr. of alloc. for sparse matrix }
              FSparseNumElem  : longint; { number of elements in sparse matrix }
              FSparseLowCol   : longint;{ index of lowest column in sparse mat }
              FSparseHighCol  : longint;{index of highest column in sparse mat }
              FSparseLowRow   : longint;   { index of lowest row in sparse mat }
              FSparseHighRow  : longint;  { index of highest row in sparse mat }
              SpMat           : array of TSpMatElemInt;{ sparse matrix container }
              Mat             : array of array of integer;       { matrix data }
              FOnChange       : TNotifyEvent;
              FOnSortExchange : TSortExchgEvent;
{$IFDEF PAIDVERS}
              FirstCell       : boolean;{flag to resize matrix during XML input }
              function  ProcessXmlTag (xmlTag: TMatXmlTag;
                            attr, cont: string): integer;
{$ENDIF}
              function  GetVal (Nc,Nr: longint): integer;
              procedure SetVal (Nc,Nr: longint; Value: integer);
              procedure SetNCols (value: longint);
              procedure SetNRows (value: longint);
              procedure SkewKurtIntern (LowCol, LowRow, HighCol, HighRow: integer;
                              var Skewness, Kurtosis: double; var NumData: longint);
            protected
              procedure   SortExchange (ExchgWhat: byte; index1, index2,
                              first, last: longint);
            public
              constructor Create (AOwner: TComponent); override;
              constructor CreateSparse (AOwner: TComponent; AllocBy: longint);
              destructor  Destroy; override;
              property    Elem[ix,iy: longint]: integer
                              read GetVal write SetVal; default;
              function    Add (MatB: TIntMatrix): boolean;
              procedure   ArrayToSparse (AllocBy: longint);
              procedure   Changed;
              procedure   Clone (MatSource: TIntMatrix);
              procedure   CopyColToVec (DestVec: TIntVector;
                             Col, FirstRow, LastRow: integer);
              procedure   CopyFrom (MatSource: TIntMatrix; SourceColLo,
                             SourceRowLo, SourceColHi, SourceRowHi,
                             DestCol, DestRow: integer);
              procedure   CopyRowToVec (DestVec: TIntVector;
                             Row, FirstCol, LastCol: integer);
              procedure   Fill (value: integer);
              function    GeometricMean (LowCol, LowRow, HighCol,
                             HighRow: integer): double;
              function    HarmonicMean (LowCol, LowRow, HighCol,
                             HighRow: integer): double;
              function    LoadFromFile (FileName: string;
                             AdjustMatrixSize: boolean): boolean;
              function    LoadFromStream (InStream: TMemoryStream;
                             AdjustMatrixSize: boolean): boolean;
              function    LoadFromXMLFile (FName: string; DataID: string): boolean;
              function    LoadSparseMat (FileName:string): boolean;
              procedure   MeanVar (LowCol, LowRow, HighCol, HighRow: integer;
                             var Mean, Variance: double);
              procedure   MinMax (LowCol, LowRow, HighCol, HighRow: integer;
                             var Minimum, Maximum: integer);
              function    Multiply (MatB, MatRes: TIntMatrix): boolean;
              function    Percentile (prob: double; LowCol, LowRow, HighCol,
                             HighRow: integer): double;
              function    Quartiles (LowCol, LowRow, HighCol,
                             HighRow: integer; var Q1, Q2, Q3: double): boolean;
              function    ReadFromOpenXMLFile (var InFile: TextFile;
                             DataID: string): boolean;
              function    ReadFromXMLStream (InStream: TStream;
                             DataID: string): boolean;
              function    Resize (Nc, Nr: longint): boolean;
              procedure   SaveAsXMLFile (FName: string; DataID: string);
              procedure   SaveToStream (var OutStream: TMemoryStream;
                             LoC,LoR,HiC,HiR: integer);
              procedure   SkewKurt (LowCol, LowRow, HighCol,
                             HighRow: integer; var Skewness, Kurtosis: double);
              procedure   SkewKurtSample (LowCol, LowRow, HighCol, HighRow: integer;
                             var Skewness, Kurtosis: double);
              procedure   SMult (Scalar: integer);
              procedure   SortCols (SortRowIx: integer; Ascending: boolean;
                             LowCol, LowRow, HighCol, HighRow: integer);
              procedure   SortRows (SortColIx: integer; Ascending: boolean;
                             LowCol, LowRow, HighCol,
                             HighRow: integer);
              procedure   SparseToArray;
              function    StoreOnFile
                             (LoC,LoR,HiC,HiR: integer;
                             FileName:string): boolean;
              function    StoreSparseMat (FileName:string): boolean;
              function    Subtract (MatB: TIntMatrix): boolean;
              function    Sum (LoC,LoR,HiC,HiR: integer): longint;
              function    Trace: longint;
              function    Transpose: boolean;
              procedure   WriteToOpenXMLFile (var OutFile : TextFile;
                              CreateHeader: boolean; DataID: string);
              procedure   WriteToXMLStream (OutStream: TStream;
                              CreateHeader: boolean; DataID: string);
            published
              property    DataID: string read FDataID write FDataID;
              property    NrOfColumns: longint read FNCol write SetNCols;
              property    NrOfRows: longint read FNRow write SetNRows;
              property    OnChange: TNotifyEvent read FOnChange write FOnChange;
              property    OnSortExchange: TSortExchgEvent
                              read FOnSortExchange write FOnSortExchange;
            end;

   TMat3D = class (TComponent)
            private
              FNumX     : longint;                         { number of columns }
              FNumY     : longint;                            { number of rows }
              FNumZ     : longint;                          { number of layers }
              FDataID   : string;                   { tag to identify the data }
              Mat       : array of array of array of double;
              FOnChange : TNotifyEvent;
{$IFDEF PAIDVERS}
              FirstCell : boolean;{flag to resize matrix during input from XML }
              function    ProcessXmlTag (xmlTag: TMatXmlTag; attr,
                              cont: string): integer;
{$ENDIF}
              function    GetVal (Nx,Ny,Nz: longint): double;
              procedure   SetVal (Nx,Ny,Nz: longint; Value: double);
              procedure   SetNCols (value: longint);
              procedure   SetNRows (value: longint);
              procedure   SetNLayers (value: longint);
            public
              constructor Create (AOwner: TComponent); override;
              destructor  Destroy; override;
              procedure   Changed;
              property    Elem[ix,iy,iz: longint]: double
                              read GetVal write SetVal; default;
              procedure   Fill (value: double);
              function    LoadFromXMLFile (FName: string; DataID: string): boolean;
              function    ReadFromOpenXMLFile (var InFile: TextFile;
                              DataID: string): boolean;
              function    ReadFromXMLStream (InStream: TStream;
                              DataID: string): boolean;
              function    Resize (Nc, Nr, Nl: longint): boolean;
              procedure   SaveAsXMLFile (FName: string; DataID: string);
              procedure   WriteToOpenXMLFile (var OutFile : TextFile;
                              CreateHeader: boolean; DataID: string);
              procedure   WriteToXMLStream (OutStream: TStream;
                              CreateHeader: boolean; DataID: string);
            published
              property    DataID: string read FDataID write FDataID;
              property    NrOfColumns: longint read FNumX write SetNCols;
              property    NrOfRows: longint read FNumY write SetNRows;
              property    NrOfLayers: longint read FNumZ write SetNLayers;
              property    OnChange: TNotifyEvent read FOnChange write FOnChange;
            end;




Last Update: 2006-Jän-30