TSparseMtx.TripletsToSparse Method

Overload List

#SignatureDescription
1void TripletsToSparse(Int32 RowCount, Int32 ColCount, TMtx SrcTriplets)Convert triplets to sparse format.
2void TripletsToSparse(Int32 RowCount, Int32 ColCount, Int32[] SrcRow, Int32[] SrcColumn, TCplx[] SrcCValues, Double Threshold, Boolean PreserveZeroDiagElem)Convert triplets to sparse format (complex version).
3void TripletsToSparse(Int32 RowCount, Int32 ColCount, Int32[] SrcRow, Int32[] SrcColumn, Double[] SrcValues, Double Threshold, Boolean PreserveZeroDiagElem)Convert triplets to sparse format.

Overload 1: void TripletsToSparse(Int32 RowCount, Int32 ColCount, TMtx SrcTriplets)

Convert triplets to sparse format.

#NameTypeDescription
1RowCountInt32
2ColCountInt32
3SrcTripletsTMtxsource TMtx

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: void TripletsToSparse(Int32 RowCount, Int32 ColCount, Int32[] SrcRow, Int32[] SrcColumn, TCplx[] SrcCValues, Double Threshold, Boolean PreserveZeroDiagElem)

Convert triplets to sparse format (complex version).

#NameTypeDescription
1RowCountInt32
2ColCountInt32
3SrcRowInt32[]
4SrcColumnInt32[]
5SrcCValuesTCplx[]
6ThresholdDoublescalar
7PreserveZeroDiagElemBoolean

Result: stored in self (calling object)

Overload 3: void TripletsToSparse(Int32 RowCount, Int32 ColCount, Int32[] SrcRow, Int32[] SrcColumn, Double[] SrcValues, Double Threshold, Boolean PreserveZeroDiagElem)

Convert triplets to sparse format.

#NameTypeDescription
1RowCountInt32
2ColCountInt32
3SrcRowInt32[]
4SrcColumnInt32[]
5SrcValuesDouble[]
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
using Dew.Math;
using Dew.Math.Units;

namespace Dew.Examples
{
    private void Example()
    {
        Matrix A = new Matrix(0,0);
        TSparseMtx SparseA = new TSparseMtx();
        TSparseMtx SparseB = new TSparseMtx();

        int[] R1 = new int[SparseA.NonZeros];
        int[] C1 = new int[SparseA.NonZeros];
        double[] V1 = new double[SparseA.NonZeros];

        SparseA.SparseToTriplets(ref R1,ref C1,ref V1);
        SparseB.TripletsToSparse(SparseA.Cols,SparseA.Cols,R1,C1,V1,0.0);

        SparseA.SparseToDense(A);
        if (!SparseB.Equal(SparseA,1E-5)) throw("Not equal");
        if (!SparseA.Equal(A,0,true)) throw("Not equal");

        SparseA.SparseToTriplets(A);
        SparseB.>TripletsToSparse(SparseA.Cols,SparseA.Cols,A,0.0);
        if (!SparseA.Equal(SparseB)) throw("Not equal");
    }
}
See Also: TSparseMtx.SparseToTriplets