|
SNAP Library 2.1, Developer Reference
2013-09-25 10:47:25
SNAP, a general purpose, high performance system for analysis and manipulation of large networks
|
#include <linalg.h>
Static Public Member Functions | |
| static void | SaveCsvTFltV (const TFltV &Vec, TSOut &SOut) |
| static void | SaveMatlabTFltIntKdV (const TIntFltKdV &SpV, const int &ColN, TSOut &SOut) |
| static void | SaveMatlabTFltV (const TFltV &m, const TStr &FName) |
| static void | SaveMatlabTIntV (const TIntV &m, const TStr &FName) |
| static void | SaveMatlabTFltVVCol (const TFltVV &m, int ColId, const TStr &FName) |
| static void | SaveMatlabTFltVV (const TFltVV &m, const TStr &FName) |
| static void | SaveMatlabTFltVVMjrSubMtrx (const TFltVV &m, int rowN, int colN, const TStr &FName) |
| static void | LoadMatlabTFltVV (const TStr &FNm, TVec< TFltV > &ColV) |
| static void | LoadMatlabTFltVV (const TStr &FNm, TFltVV &MatrixVV) |
| static void | PrintTFltV (const TFltV &Vec, const TStr &VecNm) |
| static void | PrintTFltVV (const TFltVV &A, const TStr &MatrixNm) |
| static void | PrintTIntV (const TIntV &Vec, const TStr &VecNm) |
| static void | FillRnd (TFltV &Vec) |
| static void | FillRnd (TFltV &Vec, TRnd &Rnd) |
| static void | Fill (TFltVV &M, const double &Val) |
| static void | FillZero (TFltV &Vec) |
| static void | FillZero (TFltVV &M) |
| static void | FillIdentity (TFltVV &M) |
| static void | FillIdentity (TFltVV &M, const double &Elt) |
| static int | SumVec (const TIntV &Vec) |
| static double | SumVec (const TFltV &Vec) |
| static void | ToSpVec (const TFltV &Vec, TIntFltKdV &SpVec, const double &CutWordWgtSumPrc=0.0) |
| static void | ToVec (const TIntFltKdV &SpVec, TFltV &Vec, const int &VecLen) |
| static void TLAMisc::Fill | ( | TFltVV & | M, |
| const double & | Val | ||
| ) | [static] |
| void TLAMisc::FillIdentity | ( | TFltVV & | M | ) | [static] |
Definition at line 1741 of file linalg.cpp.
References TVVec< TVal >::GetCols(), TVVec< TVal >::GetRows(), and IAssert.
Referenced by TSparseSVD::SimpleLanczos().
{
IAssert(M.GetRows() == M.GetCols());
int Len = M.GetRows();
for (int i = 0; i < Len; i++) {
for (int j = 0; j < Len; j++) M(i,j) = 0.0;
M(i,i) = 1.0;
}
}


| void TLAMisc::FillIdentity | ( | TFltVV & | M, |
| const double & | Elt | ||
| ) | [static] |
Definition at line 1750 of file linalg.cpp.
References TVVec< TVal >::GetCols(), TVVec< TVal >::GetRows(), and IAssert.
{
IAssert(M.GetRows() == M.GetCols());
int Len = M.GetRows();
for (int i = 0; i < Len; i++) {
for (int j = 0; j < Len; j++) M(i,j) = 0.0;
M(i,i) = Elt;
}
}

| static void TLAMisc::FillRnd | ( | TFltV & | Vec | ) | [inline, static] |
| void TLAMisc::FillRnd | ( | TFltV & | Vec, |
| TRnd & | Rnd | ||
| ) | [static] |
Definition at line 1735 of file linalg.cpp.
References TRnd::GetNrmDev(), and TVec< TVal, TSizeTy >::Len().

| static void TLAMisc::FillZero | ( | TFltV & | Vec | ) | [inline, static] |
Definition at line 526 of file linalg.h.
References TVec< TVal, TSizeTy >::PutAll().
{ Vec.PutAll(0.0); }

| static void TLAMisc::FillZero | ( | TFltVV & | M | ) | [inline, static] |
| void TLAMisc::LoadMatlabTFltVV | ( | const TStr & | FNm, |
| TVec< TFltV > & | ColV | ||
| ) | [static] |
Definition at line 1660 of file linalg.cpp.
References TVec< TVal, TSizeTy >::Add(), TVec< TVal, TSizeTy >::Clr(), Fail, TILx::Flt, TILx::GetSym(), TVec< TFlt >::GetV(), IAssert, iloExcept, iloRetEoln, iloSigNum, TVec< TVal, TSizeTy >::Len(), TFIn::New(), syEof, syEoln, syFlt, and TILx::Sym.
Referenced by LoadMatlabTFltVV(), and TFullColMatrix::TFullColMatrix().
{
PSIn SIn = TFIn::New(FNm);
TILx Lx(SIn, TFSet()|iloRetEoln|iloSigNum|iloExcept);
int Row = 0, Col = 0; ColV.Clr();
Lx.GetSym(syFlt, syEof, syEoln);
//printf("%d x %d\r", Row, ColV.Len());
while (Lx.Sym != syEof) {
if (Lx.Sym == syFlt) {
if (ColV.Len() > Col) {
IAssert(ColV[Col].Len() == Row);
ColV[Col].Add(Lx.Flt);
} else {
IAssert(Row == 0);
ColV.Add(TFltV::GetV(Lx.Flt));
}
Col++;
} else if (Lx.Sym == syEoln) {
IAssert(Col == ColV.Len());
Col = 0; Row++;
if (Row%100 == 0) {
//printf("%d x %d\r", Row, ColV.Len());
}
} else {
Fail;
}
Lx.GetSym(syFlt, syEof, syEoln);
}
//printf("\n");
IAssert(Col == ColV.Len() || Col == 0);
}


| void TLAMisc::LoadMatlabTFltVV | ( | const TStr & | FNm, |
| TFltVV & | MatrixVV | ||
| ) | [static] |
Definition at line 1691 of file linalg.cpp.
References TVVec< TVal >::Clr(), TVec< TVal, TSizeTy >::Empty(), TVVec< TVal >::Gen(), TVec< TVal, TSizeTy >::Len(), and LoadMatlabTFltVV().
{
TVec<TFltV> ColV; LoadMatlabTFltVV(FNm, ColV);
if (ColV.Empty()) { MatrixVV.Clr(); return; }
const int Rows = ColV[0].Len(), Cols = ColV.Len();
MatrixVV.Gen(Rows, Cols);
for (int RowN = 0; RowN < Rows; RowN++) {
for (int ColN = 0; ColN < Cols; ColN++) {
MatrixVV(RowN, ColN) = ColV[ColN][RowN];
}
}
}

| void TLAMisc::PrintTFltV | ( | const TFltV & | Vec, |
| const TStr & | VecNm | ||
| ) | [static] |
Definition at line 1704 of file linalg.cpp.
References TStr::CStr(), and TVec< TVal, TSizeTy >::Len().
{
printf("%s = [", VecNm.CStr());
for (int i = 0; i < Vec.Len(); i++) {
printf("%.5f", Vec[i]());
if (i < Vec.Len() - 1) { printf(", "); }
}
printf("]\n");
}

| void TLAMisc::PrintTFltVV | ( | const TFltVV & | A, |
| const TStr & | MatrixNm | ||
| ) | [static] |
Definition at line 1714 of file linalg.cpp.
References TVVec< TVal >::At(), TStr::CStr(), TVVec< TVal >::GetCols(), TVVec< TVal >::GetRows(), and TFlt::Val.
{
printf("%s = [\n", MatrixNm.CStr());
for (int j = 0; j < A.GetRows(); j++) {
for (int i = 0; i < A.GetCols(); i++) {
printf("%f\t", A.At(i, j).Val);
}
printf("\n");
}
printf("]\n");
}

| void TLAMisc::PrintTIntV | ( | const TIntV & | Vec, |
| const TStr & | VecNm | ||
| ) | [static] |
Definition at line 1725 of file linalg.cpp.
References TStr::CStr(), and TVec< TVal, TSizeTy >::Len().
{
printf("%s = [", VecNm.CStr());
for (int i = 0; i < Vec.Len(); i++) {
printf("%d", Vec[i]());
if (i < Vec.Len() - 1) printf(", ");
}
printf("]\n");
}

| void TLAMisc::SaveCsvTFltV | ( | const TFltV & | Vec, |
| TSOut & | SOut | ||
| ) | [static] |
Definition at line 1588 of file linalg.cpp.
References TVec< TVal, TSizeTy >::Len(), TSOut::PutCh(), TSOut::PutFlt(), and TSOut::PutLn().
{
for (int ValN = 0; ValN < Vec.Len(); ValN++) {
SOut.PutFlt(Vec[ValN]); SOut.PutCh(',');
}
SOut.PutLn();
}

| void TLAMisc::SaveMatlabTFltIntKdV | ( | const TIntFltKdV & | SpV, |
| const int & | ColN, | ||
| TSOut & | SOut | ||
| ) | [static] |
Definition at line 1595 of file linalg.cpp.
References TStr::Fmt(), TVec< TVal, TSizeTy >::Len(), and TSOut::PutStrLn().
{
const int Len = SpV.Len();
for (int ValN = 0; ValN < Len; ValN++) {
SOut.PutStrLn(TStr::Fmt("%d %d %g", SpV[ValN].Key+1, ColN+1, SpV[ValN].Dat()));
}
}

| void TLAMisc::SaveMatlabTFltV | ( | const TFltV & | m, |
| const TStr & | FName | ||
| ) | [static] |
Definition at line 1602 of file linalg.cpp.
References TSOut::Flush(), TFlt::GetStr(), TVec< TVal, TSizeTy >::Len(), TFOut::New(), TSOut::PutCh(), and TSOut::PutStr().
{
PSOut out = TFOut::New(FName);
const int RowN = m.Len();
for (int RowId = 0; RowId < RowN; RowId++) {
out->PutStr(TFlt::GetStr(m[RowId], 20, 18));
out->PutCh('\n');
}
out->Flush();
}

| void TLAMisc::SaveMatlabTFltVV | ( | const TFltVV & | m, |
| const TStr & | FName | ||
| ) | [static] |
Definition at line 1633 of file linalg.cpp.
References TSOut::Flush(), TVVec< TVal >::GetCols(), TVVec< TVal >::GetRows(), TFlt::GetStr(), TFOut::New(), TSOut::PutCh(), and TSOut::PutStr().
{
PSOut out = TFOut::New(FName);
const int RowN = m.GetRows();
const int ColN = m.GetCols();
for (int RowId = 0; RowId < RowN; RowId++) {
for (int ColId = 0; ColId < ColN; ColId++) {
out->PutStr(TFlt::GetStr(m(RowId,ColId), 20, 18));
out->PutCh(' ');
}
out->PutCh('\n');
}
out->Flush();
}

| void TLAMisc::SaveMatlabTFltVVCol | ( | const TFltVV & | m, |
| int | ColId, | ||
| const TStr & | FName | ||
| ) | [static] |
Definition at line 1622 of file linalg.cpp.
References TSOut::Flush(), TVVec< TVal >::GetRows(), TFlt::GetStr(), TFOut::New(), TSOut::PutCh(), and TSOut::PutStr().
{
PSOut out = TFOut::New(FName);
const int RowN = m.GetRows();
for (int RowId = 0; RowId < RowN; RowId++) {
out->PutStr(TFlt::GetStr(m(RowId,ColId), 20, 18));
out->PutCh('\n');
}
out->Flush();
}

| void TLAMisc::SaveMatlabTFltVVMjrSubMtrx | ( | const TFltVV & | m, |
| int | rowN, | ||
| int | colN, | ||
| const TStr & | FName | ||
| ) | [static] |
Definition at line 1647 of file linalg.cpp.
References TSOut::Flush(), TFlt::GetStr(), TFOut::New(), TSOut::PutCh(), and TSOut::PutStr().
{
PSOut out = TFOut::New(FName);
for (int RowId = 0; RowId < RowN; RowId++) {
for (int ColId = 0; ColId < ColN; ColId++) {
out->PutStr(TFlt::GetStr(m(RowId,ColId), 20, 18)); out->PutCh(' ');
}
out->PutCh('\n');
}
out->Flush();
}

| void TLAMisc::SaveMatlabTIntV | ( | const TIntV & | m, |
| const TStr & | FName | ||
| ) | [static] |
Definition at line 1612 of file linalg.cpp.
References TSOut::Flush(), TVec< TVal, TSizeTy >::Len(), TFOut::New(), TSOut::PutCh(), and TSOut::PutInt().
{
PSOut out = TFOut::New(FName);
const int RowN = m.Len();
for (int RowId = 0; RowId < RowN; RowId++) {
out->PutInt(m[RowId]);
out->PutCh('\n');
}
out->Flush();
}

| int TLAMisc::SumVec | ( | const TIntV & | Vec | ) | [static] |
Definition at line 1759 of file linalg.cpp.
References TVec< TVal, TSizeTy >::Len().
{
const int Len = Vec.Len();
int res = 0;
for (int i = 0; i < Len; i++)
res += Vec[i];
return res;
}

| double TLAMisc::SumVec | ( | const TFltV & | Vec | ) | [static] |
Definition at line 1767 of file linalg.cpp.
References TVec< TVal, TSizeTy >::Len().
{
const int Len = Vec.Len();
double res = 0.0;
for (int i = 0; i < Len; i++)
res += Vec[i];
return res;
}

| void TLAMisc::ToSpVec | ( | const TFltV & | Vec, |
| TIntFltKdV & | SpVec, | ||
| const double & | CutWordWgtSumPrc = 0.0 |
||
| ) | [static] |
Definition at line 1775 of file linalg.cpp.
References TFlt::Abs(), TVec< TVal, TSizeTy >::Add(), TVec< TVal, TSizeTy >::Clr(), IAssert, TVec< TVal, TSizeTy >::Len(), and TVec< TVal, TSizeTy >::Pack().
{
// determine minimal element value
IAssert(0.0 <= CutSumPrc && CutSumPrc <= 1.0);
const int Elts = Vec.Len();
double EltSum = 0.0;
for (int EltN = 0; EltN < Elts; EltN++) {
EltSum += TFlt::Abs(Vec[EltN]); }
const double MnEltVal = CutSumPrc * EltSum;
// create sparse vector
SpVec.Clr();
for (int EltN = 0; EltN < Elts; EltN++) {
if (TFlt::Abs(Vec[EltN]) > MnEltVal) {
SpVec.Add(TIntFltKd(EltN, Vec[EltN]));
}
}
SpVec.Pack();
}

| void TLAMisc::ToVec | ( | const TIntFltKdV & | SpVec, |
| TFltV & | Vec, | ||
| const int & | VecLen | ||
| ) | [static] |
Definition at line 1795 of file linalg.cpp.
References TVec< TVal, TSizeTy >::Gen(), TVec< TVal, TSizeTy >::Len(), and TVec< TVal, TSizeTy >::PutAll().
{
Vec.Gen(VecLen); Vec.PutAll(0.0);
int Elts = SpVec.Len();
for (int EltN = 0; EltN < Elts; EltN++) {
if (SpVec[EltN].Key < VecLen) {
Vec[SpVec[EltN].Key] = SpVec[EltN].Dat;
}
}
}
