You are here: Symbol Reference > Sparse Namespace > Classes > TSparseMtx Class > public > SparseToTriplets Method > TSparseMtx.SparseToTriplets Method (TIntegerArray, TIntegerArray, TDoubleArray)
MtxVec VCL
ContentsIndex
Example

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;
Copyright (c) 1999-2025 by Dew Research. All rights reserved.