TSparseMtx *LowerTriangle(TSparseMtx *Src, bool Diagonal = false);
Extract lower part of the Mtx.
| # | Name | Type | Description |
|---|---|---|---|
| 1 | Src | TSparseMtx * | |
| 2 | Diagonal = false | bool |
Remarks:
Copies only the lower triangular part of the Src sparse matrix. The result is stored in the calling sparse matrix. If the Diagonal boolean parameter is true then the Src matrix main diagonal elements will be copied to the calling matrix main diagonal elements. If the Diagonal parameter is false, the calling matrix main diagonal elements will be set to zero.
Examples
#include <cstdio>
#include "MtxExpr.h"
#include "sparse.h"
using namespace Dew;
using namespace Dew::Math;
void Example()
{
Vector d(0);
TSparseMtx* asp = new TSparseMtx();
TSparseMtx* bsp = new TSparseMtx();
TSparseMtx* csp = new TSparseMtx();
TSparseMtx* dsp = new TSparseMtx();
// ...
Matrix A = {{4, 1, 0}, {2, 5, 3}, {0, 1, 6}};
asp->DenseToSparse(A);
// #1 : split asp into lower(bsp), upper(csp) and diagonal(d) sections
bsp->LowerTriangle(asp);
csp->UpperTriangle(asp);
asp->Diag(d);
// now combine lower(bsp), upper, and diagonal(d) back
dsp->AddSplit(bsp, d, csp);
// should be equal
if (!asp->Equal(dsp)) std::printf("Not equal!\n");
delete asp;
delete bsp;
delete csp;
delete dsp;
}
See Also: TSparseMtx::UpperTriangle
Declared in Dew::Math::TSparseMtx · Dew.Math/sparse.h · Cross-compiler