SNAP Library 4.0, User Reference  2017-07-27 13:18:06
SNAP, a general purpose, high performance system for analysis and manipulation of large networks
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
TLAMisc Class Reference

#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)
 

Detailed Description

Definition at line 494 of file linalg.h.

Member Function Documentation

static void TLAMisc::Fill ( TFltVV M,
const double &  Val 
)
static
void TLAMisc::FillIdentity ( TFltVV M)
static

Definition at line 1751 of file linalg.cpp.

1751  {
1752  IAssert(M.GetRows() == M.GetCols());
1753  int Len = M.GetRows();
1754  for (int i = 0; i < Len; i++) {
1755  for (int j = 0; j < Len; j++) M(i,j) = 0.0;
1756  M(i,i) = 1.0;
1757  }
1758 }
#define IAssert(Cond)
Definition: bd.h:262
TSizeTy GetRows() const
Definition: ds.h:2251
TSizeTy GetCols() const
Definition: ds.h:2252
void TLAMisc::FillIdentity ( TFltVV M,
const double &  Elt 
)
static

Definition at line 1760 of file linalg.cpp.

1760  {
1761  IAssert(M.GetRows() == M.GetCols());
1762  int Len = M.GetRows();
1763  for (int i = 0; i < Len; i++) {
1764  for (int j = 0; j < Len; j++) M(i,j) = 0.0;
1765  M(i,i) = Elt;
1766  }
1767 }
#define IAssert(Cond)
Definition: bd.h:262
TSizeTy GetRows() const
Definition: ds.h:2251
TSizeTy GetCols() const
Definition: ds.h:2252
static void TLAMisc::FillRnd ( TFltV Vec)
inlinestatic

Definition at line 521 of file linalg.h.

521 { TRnd Rnd(0); FillRnd(Vec, Rnd); }
Definition: dt.h:11
static void FillRnd(TFltV &Vec)
Definition: linalg.h:521
void TLAMisc::FillRnd ( TFltV Vec,
TRnd Rnd 
)
static

Definition at line 1745 of file linalg.cpp.

1745  {
1746  int Len = Vec.Len();
1747  for (int i = 0; i < Len; i++)
1748  Vec[i] = Rnd.GetNrmDev();
1749 }
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:575
double GetNrmDev()
Definition: dt.cpp:63
static void TLAMisc::FillZero ( TFltV Vec)
inlinestatic

Definition at line 526 of file linalg.h.

526 { Vec.PutAll(0.0); }
void PutAll(const TVal &Val)
Sets all elements of the vector to value Val.
Definition: ds.h:1229
static void TLAMisc::FillZero ( TFltVV M)
inlinestatic

Definition at line 527 of file linalg.h.

527 { Fill(M, 0.0); }
static void Fill(TFltVV &M, const double &Val)
void TLAMisc::LoadMatlabTFltVV ( const TStr FNm,
TVec< TFltV > &  ColV 
)
static

Definition at line 1670 of file linalg.cpp.

1670  {
1671  PSIn SIn = TFIn::New(FNm);
1673  int Row = 0, Col = 0; ColV.Clr();
1674  Lx.GetSym(syFlt, syEof, syEoln);
1675  //printf("%d x %d\r", Row, ColV.Len());
1676  while (Lx.Sym != syEof) {
1677  if (Lx.Sym == syFlt) {
1678  if (ColV.Len() > Col) {
1679  IAssert(ColV[Col].Len() == Row);
1680  ColV[Col].Add(Lx.Flt);
1681  } else {
1682  IAssert(Row == 0);
1683  ColV.Add(TFltV::GetV(Lx.Flt));
1684  }
1685  Col++;
1686  } else if (Lx.Sym == syEoln) {
1687  IAssert(Col == ColV.Len());
1688  Col = 0; Row++;
1689  if (Row%100 == 0) {
1690  //printf("%d x %d\r", Row, ColV.Len());
1691  }
1692  } else {
1693  Fail;
1694  }
1695  Lx.GetSym(syFlt, syEof, syEoln);
1696  }
1697  //printf("\n");
1698  IAssert(Col == ColV.Len() || Col == 0);
1699 }
#define IAssert(Cond)
Definition: bd.h:262
Definition: lx.h:127
#define Fail
Definition: bd.h:238
Definition: bits.h:119
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:575
Definition: lx.h:51
Definition: lx.h:126
static PSIn New(const TStr &FNm)
Definition: fl.cpp:290
Definition: lx.h:126
void Clr(const bool &DoDel=true, const TSizeTy &NoDelLim=-1)
Clears the contents of the vector.
Definition: ds.h:1022
Definition: lx.h:51
Definition: lx.h:129
Definition: lx.h:45
static TVec< TFlt, TSizeTy > GetV(const TFlt &Val1)
Returns a vector on element Val1.
Definition: ds.h:848
TSizeTy Add()
Adds a new element at the end of the vector, after its current last element.
Definition: ds.h:602
void TLAMisc::LoadMatlabTFltVV ( const TStr FNm,
TFltVV MatrixVV 
)
static

Definition at line 1701 of file linalg.cpp.

1701  {
1702  TVec<TFltV> ColV; LoadMatlabTFltVV(FNm, ColV);
1703  if (ColV.Empty()) { MatrixVV.Clr(); return; }
1704  const int Rows = ColV[0].Len(), Cols = ColV.Len();
1705  MatrixVV.Gen(Rows, Cols);
1706  for (int RowN = 0; RowN < Rows; RowN++) {
1707  for (int ColN = 0; ColN < Cols; ColN++) {
1708  MatrixVV(RowN, ColN) = ColV[ColN][RowN];
1709  }
1710  }
1711 }
void Clr()
Definition: ds.h:2245
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:575
bool Empty() const
Tests whether the vector is empty.
Definition: ds.h:570
static void LoadMatlabTFltVV(const TStr &FNm, TVec< TFltV > &ColV)
Definition: linalg.cpp:1670
void Gen(const TSizeTy &_XDim, const TSizeTy &_YDim)
Definition: ds.h:2246
Vector is a sequence TVal objects representing an array that can change in size.
Definition: ds.h:430
void TLAMisc::PrintTFltV ( const TFltV Vec,
const TStr VecNm 
)
static

Definition at line 1714 of file linalg.cpp.

1714  {
1715  printf("%s = [", VecNm.CStr());
1716  for (int i = 0; i < Vec.Len(); i++) {
1717  printf("%.5f", Vec[i]());
1718  if (i < Vec.Len() - 1) { printf(", "); }
1719  }
1720  printf("]\n");
1721 }
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:575
char * CStr()
Definition: dt.h:476
void TLAMisc::PrintTFltVV ( const TFltVV A,
const TStr MatrixNm 
)
static

Definition at line 1724 of file linalg.cpp.

1724  {
1725  printf("%s = [\n", MatrixNm.CStr());
1726  for (int j = 0; j < A.GetRows(); j++) {
1727  for (int i = 0; i < A.GetCols(); i++) {
1728  printf("%f\t", A.At(i, j).Val);
1729  }
1730  printf("\n");
1731  }
1732  printf("]\n");
1733 }
double Val
Definition: dt.h:1385
TSizeTy GetRows() const
Definition: ds.h:2251
char * CStr()
Definition: dt.h:476
TSizeTy GetCols() const
Definition: ds.h:2252
const TVal & At(const TSizeTy &X, const TSizeTy &Y) const
Definition: ds.h:2255
void TLAMisc::PrintTIntV ( const TIntV Vec,
const TStr VecNm 
)
static

Definition at line 1735 of file linalg.cpp.

1735  {
1736  printf("%s = [", VecNm.CStr());
1737  for (int i = 0; i < Vec.Len(); i++) {
1738  printf("%d", Vec[i]());
1739  if (i < Vec.Len() - 1) printf(", ");
1740  }
1741  printf("]\n");
1742 }
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:575
char * CStr()
Definition: dt.h:476
void TLAMisc::SaveCsvTFltV ( const TFltV Vec,
TSOut SOut 
)
static

Definition at line 1598 of file linalg.cpp.

1598  {
1599  for (int ValN = 0; ValN < Vec.Len(); ValN++) {
1600  SOut.PutFlt(Vec[ValN]); SOut.PutCh(',');
1601  }
1602  SOut.PutLn();
1603 }
virtual int PutCh(const char &Ch)=0
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:575
int PutLn(const int &Lns=1)
Definition: fl.cpp:158
int PutFlt(const double &Flt)
Definition: fl.cpp:109
void TLAMisc::SaveMatlabTFltIntKdV ( const TIntFltKdV SpV,
const int &  ColN,
TSOut SOut 
)
static

Definition at line 1605 of file linalg.cpp.

1605  {
1606  const int Len = SpV.Len();
1607  for (int ValN = 0; ValN < Len; ValN++) {
1608  SOut.PutStrLn(TStr::Fmt("%d %d %g", SpV[ValN].Key+1, ColN+1, SpV[ValN].Dat()));
1609  }
1610 }
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:575
static TStr Fmt(const char *FmtStr,...)
Definition: dt.cpp:1599
int PutStrLn(const TStr &Str, const bool &ForceInLn=false)
Definition: fl.h:161
void TLAMisc::SaveMatlabTFltV ( const TFltV m,
const TStr FName 
)
static

Definition at line 1612 of file linalg.cpp.

1612  {
1613  PSOut out = TFOut::New(FName);
1614  const int RowN = m.Len();
1615  for (int RowId = 0; RowId < RowN; RowId++) {
1616  out->PutStr(TFlt::GetStr(m[RowId], 20, 18));
1617  out->PutCh('\n');
1618  }
1619  out->Flush();
1620 }
static PSOut New(const TStr &FNm, const bool &Append=false)
Definition: fl.cpp:442
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:575
Definition: bd.h:196
TStr GetStr() const
Definition: dt.h:1459
void TLAMisc::SaveMatlabTFltVV ( const TFltVV m,
const TStr FName 
)
static

Definition at line 1643 of file linalg.cpp.

1643  {
1644  PSOut out = TFOut::New(FName);
1645  const int RowN = m.GetRows();
1646  const int ColN = m.GetCols();
1647  for (int RowId = 0; RowId < RowN; RowId++) {
1648  for (int ColId = 0; ColId < ColN; ColId++) {
1649  out->PutStr(TFlt::GetStr(m(RowId,ColId), 20, 18));
1650  out->PutCh(' ');
1651  }
1652  out->PutCh('\n');
1653  }
1654  out->Flush();
1655 }
static PSOut New(const TStr &FNm, const bool &Append=false)
Definition: fl.cpp:442
TSizeTy GetRows() const
Definition: ds.h:2251
Definition: bd.h:196
TStr GetStr() const
Definition: dt.h:1459
TSizeTy GetCols() const
Definition: ds.h:2252
void TLAMisc::SaveMatlabTFltVVCol ( const TFltVV m,
int  ColId,
const TStr FName 
)
static

Definition at line 1632 of file linalg.cpp.

1632  {
1633  PSOut out = TFOut::New(FName);
1634  const int RowN = m.GetRows();
1635  for (int RowId = 0; RowId < RowN; RowId++) {
1636  out->PutStr(TFlt::GetStr(m(RowId,ColId), 20, 18));
1637  out->PutCh('\n');
1638  }
1639  out->Flush();
1640 }
static PSOut New(const TStr &FNm, const bool &Append=false)
Definition: fl.cpp:442
TSizeTy GetRows() const
Definition: ds.h:2251
Definition: bd.h:196
TStr GetStr() const
Definition: dt.h:1459
void TLAMisc::SaveMatlabTFltVVMjrSubMtrx ( const TFltVV m,
int  rowN,
int  colN,
const TStr FName 
)
static

Definition at line 1657 of file linalg.cpp.

1658  {
1659 
1660  PSOut out = TFOut::New(FName);
1661  for (int RowId = 0; RowId < RowN; RowId++) {
1662  for (int ColId = 0; ColId < ColN; ColId++) {
1663  out->PutStr(TFlt::GetStr(m(RowId,ColId), 20, 18)); out->PutCh(' ');
1664  }
1665  out->PutCh('\n');
1666  }
1667  out->Flush();
1668 }
static PSOut New(const TStr &FNm, const bool &Append=false)
Definition: fl.cpp:442
Definition: bd.h:196
TStr GetStr() const
Definition: dt.h:1459
void TLAMisc::SaveMatlabTIntV ( const TIntV m,
const TStr FName 
)
static

Definition at line 1622 of file linalg.cpp.

1622  {
1623  PSOut out = TFOut::New(FName);
1624  const int RowN = m.Len();
1625  for (int RowId = 0; RowId < RowN; RowId++) {
1626  out->PutInt(m[RowId]);
1627  out->PutCh('\n');
1628  }
1629  out->Flush();
1630 }
static PSOut New(const TStr &FNm, const bool &Append=false)
Definition: fl.cpp:442
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:575
Definition: bd.h:196
int TLAMisc::SumVec ( const TIntV Vec)
static

Definition at line 1769 of file linalg.cpp.

1769  {
1770  const int Len = Vec.Len();
1771  int res = 0;
1772  for (int i = 0; i < Len; i++)
1773  res += Vec[i];
1774  return res;
1775 }
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:575
double TLAMisc::SumVec ( const TFltV Vec)
static

Definition at line 1777 of file linalg.cpp.

1777  {
1778  const int Len = Vec.Len();
1779  double res = 0.0;
1780  for (int i = 0; i < Len; i++)
1781  res += Vec[i];
1782  return res;
1783 }
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:575
void TLAMisc::ToSpVec ( const TFltV Vec,
TIntFltKdV SpVec,
const double &  CutWordWgtSumPrc = 0.0 
)
static

Definition at line 1785 of file linalg.cpp.

1786  {
1787 
1788  // determine minimal element value
1789  IAssert(0.0 <= CutSumPrc && CutSumPrc <= 1.0);
1790  const int Elts = Vec.Len();
1791  double EltSum = 0.0;
1792  for (int EltN = 0; EltN < Elts; EltN++) {
1793  EltSum += TFlt::Abs(Vec[EltN]); }
1794  const double MnEltVal = CutSumPrc * EltSum;
1795  // create sparse vector
1796  SpVec.Clr();
1797  for (int EltN = 0; EltN < Elts; EltN++) {
1798  if (TFlt::Abs(Vec[EltN]) > MnEltVal) {
1799  SpVec.Add(TIntFltKd(EltN, Vec[EltN]));
1800  }
1801  }
1802  SpVec.Pack();
1803 }
#define IAssert(Cond)
Definition: bd.h:262
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:575
TKeyDat< TInt, TFlt > TIntFltKd
Definition: ds.h:381
void Clr(const bool &DoDel=true, const TSizeTy &NoDelLim=-1)
Clears the contents of the vector.
Definition: ds.h:1022
static double Abs(const double &Flt)
Definition: dt.h:1427
void Pack()
Reduces vector capacity (frees memory) to match its size.
Definition: ds.h:1057
TSizeTy Add()
Adds a new element at the end of the vector, after its current last element.
Definition: ds.h:602
void TLAMisc::ToVec ( const TIntFltKdV SpVec,
TFltV Vec,
const int &  VecLen 
)
static

Definition at line 1805 of file linalg.cpp.

1805  {
1806  Vec.Gen(VecLen); Vec.PutAll(0.0);
1807  int Elts = SpVec.Len();
1808  for (int EltN = 0; EltN < Elts; EltN++) {
1809  if (SpVec[EltN].Key < VecLen) {
1810  Vec[SpVec[EltN].Key] = SpVec[EltN].Dat;
1811  }
1812  }
1813 }
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:575
void PutAll(const TVal &Val)
Sets all elements of the vector to value Val.
Definition: ds.h:1229
void Gen(const TSizeTy &_Vals)
Constructs a vector (an array) of _Vals elements.
Definition: ds.h:523

The documentation for this class was generated from the following files: