TSparseMtx.SparseToTriplets Method

Overload List

#SignatureDescription
1procedure SparseToTriplets(var DstRow, DstColumn: TIntegerArray; var DstCValues: TCplxArray); overload;Convert sparse matrix to triplets (complex version).
2procedure SparseToTriplets(var DstRow, DstColumn: TIntegerArray; var DstValues: TDoubleArray); overload;Convert sparse matrix to triplets.
3procedure SparseToTriplets(var DstRow, DstColumn: TIntegerArray; var DstCValues: TSCplxArray); overload;
4procedure SparseToTriplets(var DstRow, DstColumn: TIntegerArray; var DstValues: TSingleArray); overload;
5procedure SparseToTriplets(const DstTriplets: TMtx; ImInRow: boolean = False); overload;Convert sparse matrix to triplets.

Overload 1: procedure SparseToTriplets(var DstRow, DstColumn: TIntegerArray; var DstCValues: TCplxArray); overload;

Convert sparse matrix to triplets (complex version).

#NameTypeDescription
1DstRowTIntegerArray
2DstColumnTIntegerArray
3DstCValuesTCplxArray

Result: stored in self (calling object)

Overload 2: procedure SparseToTriplets(var DstRow, DstColumn: TIntegerArray; var DstValues: TDoubleArray); overload;

Convert sparse matrix to triplets.

#NameTypeDescription
1DstRowTIntegerArray
2DstColumnTIntegerArray
3DstValuesTDoubleArray

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. 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.

Examples

Test sparseToTriplets, TripletsToSparse methods.

uses MtxExpr, Sparse, Math387;

procedure Example;
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.TripletsToSparse, TSparseMtx.TripletsToSparse, TSparseMtx.TripletsToSparse, TSparseMtx.TripletsToSparse, TSparseMtx.TripletsToSparse

Overload 3: procedure SparseToTriplets(var DstRow, DstColumn: TIntegerArray; var DstCValues: TSCplxArray); overload;

#NameTypeDescription
1DstRowTIntegerArray
2DstColumnTIntegerArray
3DstCValuesTSCplxArray

Result: stored in self (calling object)

Overload 4: procedure SparseToTriplets(var DstRow, DstColumn: TIntegerArray; var DstValues: TSingleArray); overload;

#NameTypeDescription
1DstRowTIntegerArray
2DstColumnTIntegerArray
3DstValuesTSingleArray

Result: stored in self (calling object)

Overload 5: procedure SparseToTriplets(const DstTriplets: TMtx; ImInRow: boolean = False); overload;

Convert sparse matrix to triplets.

#NameTypeDescription
1DstTripletsTMtxsource TMtx
2ImInRowBoolean

Result: stored in self (calling object)

Remarks:

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.