TSparseMtx.SparseToTriplets Method

Overload List

#SignatureDescription
1void SparseToTriplets(TMtx DstTriplets, Boolean ImInRow)Convert sparse matrix to triplets.
2void SparseToTriplets(ref Int32[] dstRow, ref Int32[] DstColumn, ref TCplx[] DstCValues)Convert sparse matrix to triplets (complex version).
3void SparseToTriplets(ref Int32[] dstRow, ref Int32[] DstColumn, ref Double[] DstValues)Convert sparse matrix to triplets.

Overload 1: void SparseToTriplets(TMtx DstTriplets, Boolean ImInRow)

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.

Overload 2: void SparseToTriplets(ref Int32[] dstRow, ref Int32[] DstColumn, ref TCplx[] DstCValues)

Convert sparse matrix to triplets (complex version).

#NameTypeDescription
1dstRowInt32[] (ref)
2DstColumnInt32[] (ref)
3DstCValuesTCplx[] (ref)

Result: stored in self (calling object)

Overload 3: void SparseToTriplets(ref Int32[] dstRow, ref Int32[] DstColumn, ref Double[] DstValues)

Convert sparse matrix to triplets.

#NameTypeDescription
1dstRowInt32[] (ref)
2DstColumnInt32[] (ref)
3DstValuesDouble[] (ref)

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
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];

Matrix A = new Matrix(0,0);

sarseA.SparseToTriplets(ref R1,ref C1,ref V1);
sparseB.TripletsToSparse(sparseA.Cols,sparseA.Cols,R1,C1,V1,0.0);

sparseA.SparseToDense(A,10000000);
if (!sparseB.Equal(sparseA,1.0E-5)) throw("Not equal");
if (!sparseA.Equal(A,0,true)) throw("Not equal");

sparseA.SparseToTriplets(A,false);
sparseB.TripletsToSparse(sparseA.Cols,sparseA.Cols,A);
if (!sparseA.Equal(sparseB)) throw("Not equal");
See Also: TSparseMtx.TripletsToSparse