TSparseMtx.TripletsToSparse Method

Overload List

#SignatureDescription
1procedure TripletsToSparse(RowCount: Integer; ColCount: Integer; const SrcTriplets: TMtx);Convert triplets to sparse format.
2procedure TripletsToSparse(RowCount: Integer; ColCount: Integer; const SrcRow: TIntegerArray; const SrcColumn: TIntegerArray; const SrcCValues: TCplxArray; Threshold: Double; PreserveZeroDiagElem: Boolean);Convert triplets to sparse format (complex version).
3procedure TripletsToSparse(RowCount: Integer; ColCount: Integer; const SrcRow: TIntegerArray; const SrcColumn: TIntegerArray; const SrcValues: TDoubleArray; Threshold: Double; PreserveZeroDiagElem: Boolean);Convert triplets to sparse format.

Overload 1: procedure TripletsToSparse(RowCount: Integer; ColCount: Integer; const SrcTriplets: TMtx);

Convert triplets to sparse format.

#NameTypeDescription
1RowCountInteger
2ColCountInteger
3SrcTripletsTMtx

Result: stored in self (calling object)

Remarks:

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.

Overload 2: procedure TripletsToSparse(RowCount: Integer; ColCount: Integer; const SrcRow: TIntegerArray; const SrcColumn: TIntegerArray; const SrcCValues: TCplxArray; Threshold: Double; PreserveZeroDiagElem: Boolean);

Convert triplets to sparse format (complex version).

#NameTypeDescription
1RowCountInteger
2ColCountInteger
3SrcRowTIntegerArray
4SrcColumnTIntegerArray
5SrcCValuesTCplxArray
6ThresholdDoublescalar
7PreserveZeroDiagElemBoolean

Result: stored in self (calling object)

Overload 3: procedure TripletsToSparse(RowCount: Integer; ColCount: Integer; const SrcRow: TIntegerArray; const SrcColumn: TIntegerArray; const SrcValues: TDoubleArray; Threshold: Double; PreserveZeroDiagElem: Boolean);

Convert triplets to sparse format.

#NameTypeDescription
1RowCountInteger
2ColCountInteger
3SrcRowTIntegerArray
4SrcColumnTIntegerArray
5SrcValuesTDoubleArray
6ThresholdDoublescalar
7PreserveZeroDiagElemBoolean

Result: stored in self (calling object)

Remarks:

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.

Examples
var R1,C1: TIntArray;
V1: TDoubleArray;
SparseA, SparseB: TSparseMtx;
A: Matrix;
begin
    SparseA := TSparseMtx.Create;
    SparseB := TSparseMtx.Create;
    try
        // setup sparse , rows, cols, non-zero elements
        SetLength(R1,SparseA.NonZeros);
        SetLength(C1,SparseA.NonZeros);
        SetLength(V1,SparseA.NonZeros);
        SparseA.SparseToTriplets(R1,C1,V1);
        SparseB.TripletsToSparse(SparseA.Cols,SparseA.Cols,R1,C1,V1);

        SparseA.SparseToDense(A);
        if not SparseB.Equal(SparseA,1E-5) then ERaise('Not equal');
        if not SparseA.Equal(A,0,True) then ERaise('Not equal');

        SparseA.SparseToTriplets(A);
        SparseB.TripletsToSparse(SparseA.Cols,SparseA.Cols,A);
        if not SparseA.Equal(SparseB) then ERaise('Not equal');
    finally
        SparseA.Free;
        SparseB.Free;
    end;
end;
See Also: TSparseMtx.SparseToTriplets