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>
Public Member Functions | |
TSparseRowMatrix () | |
TSparseRowMatrix (TVec< TIntFltKdV > _RowSpVV) | |
TSparseRowMatrix (TVec< TIntFltKdV > _RowSpVV, const int &_RowN, const int &_ColN) | |
TSparseRowMatrix (const TStr &MatlabMatrixFNm) | |
void | Save (TSOut &SOut) |
void | Load (TSIn &SIn) |
Public Attributes | |
int | RowN |
int | ColN |
TVec< TIntFltKdV > | RowSpVV |
Protected Member Functions | |
virtual void | PMultiply (const TFltVV &B, int ColId, TFltV &Result) const |
virtual void | PMultiply (const TFltV &Vec, TFltV &Result) const |
virtual void | PMultiplyT (const TFltVV &B, int ColId, TFltV &Result) const |
virtual void | PMultiplyT (const TFltV &Vec, TFltV &Result) const |
int | PGetRows () const |
int | PGetCols () const |
TSparseRowMatrix::TSparseRowMatrix | ( | ) | [inline] |
TSparseRowMatrix::TSparseRowMatrix | ( | TVec< TIntFltKdV > | _RowSpVV | ) | [inline] |
TSparseRowMatrix::TSparseRowMatrix | ( | TVec< TIntFltKdV > | _RowSpVV, |
const int & | _RowN, | ||
const int & | _ColN | ||
) | [inline] |
TSparseRowMatrix::TSparseRowMatrix | ( | const TStr & | MatlabMatrixFNm | ) |
Definition at line 53 of file linalg.cpp.
References TVec< TVal, TSizeTy >::Add(), ColN, TStr::CStr(), TVec< TVal, TSizeTy >::Gen(), IAssert, TVec< TVal, TSizeTy >::Len(), TMath::Mx(), RowN, RowSpVV, and TVec< TVal, TSizeTy >::Sort().
{ FILE *F = fopen(MatlabMatrixFNm.CStr(), "rt"); IAssert(F != NULL); TVec<TTriple<TInt, TInt, TSFlt> > MtxV; RowN = 0; ColN = 0; while (! feof(F)) { int row=-1, col=-1; float val; if (fscanf(F, "%d %d %f\n", &row, &col, &val) == 3) { IAssert(row > 0 && col > 0); MtxV.Add(TTriple<TInt, TInt, TSFlt>(row, col, val)); RowN = TMath::Mx(RowN, row); ColN = TMath::Mx(ColN, col); } } fclose(F); // create matrix MtxV.Sort(); RowSpVV.Gen(RowN); int cnt = 0; for (int row = 1; row <= RowN; row++) { while (cnt < MtxV.Len() && MtxV[cnt].Val1 == row) { RowSpVV[row-1].Add(TIntFltKd(MtxV[cnt].Val2-1, MtxV[cnt].Val3())); cnt++; } } }
void TSparseRowMatrix::Load | ( | TSIn & | SIn | ) | [inline] |
int TSparseRowMatrix::PGetCols | ( | ) | const [inline, protected, virtual] |
int TSparseRowMatrix::PGetRows | ( | ) | const [inline, protected, virtual] |
void TSparseRowMatrix::PMultiply | ( | const TFltVV & | B, |
int | ColId, | ||
TFltV & | Result | ||
) | const [protected, virtual] |
Implements TMatrix.
Definition at line 101 of file linalg.cpp.
References Assert, ColN, TVVec< TVal >::GetRows(), TVec< TVal, TSizeTy >::Len(), RowN, and RowSpVV.
{ Assert(B.GetRows() >= ColN && Result.Len() >= RowN); for (int j = 0; j < RowN; j++) { const TIntFltKdV& RowV = RowSpVV[j]; int len = RowV.Len(); Result[j] = 0.0; for (int i = 0; i < len; i++) { Result[j] += RowV[i].Dat * B(RowV[i].Key, ColId); } } }
void TSparseRowMatrix::PMultiply | ( | const TFltV & | Vec, |
TFltV & | Result | ||
) | const [protected, virtual] |
Implements TMatrix.
Definition at line 112 of file linalg.cpp.
References Assert, ColN, TVec< TVal, TSizeTy >::Len(), RowN, and RowSpVV.
{ Assert(Vec.Len() >= ColN && Result.Len() >= RowN); for (int j = 0; j < RowN; j++) { const TIntFltKdV& RowV = RowSpVV[j]; int len = RowV.Len(); Result[j] = 0.0; for (int i = 0; i < len; i++) { Result[j] += RowV[i].Dat * Vec[RowV[i].Key]; } } }
void TSparseRowMatrix::PMultiplyT | ( | const TFltVV & | B, |
int | ColId, | ||
TFltV & | Result | ||
) | const [protected, virtual] |
Implements TMatrix.
Definition at line 79 of file linalg.cpp.
References Assert, ColN, TVVec< TVal >::GetRows(), TVec< TVal, TSizeTy >::Len(), RowN, and RowSpVV.
{ Assert(B.GetRows() >= RowN && Result.Len() >= ColN); for (int i = 0; i < ColN; i++) Result[i] = 0.0; for (int j = 0; j < RowN; j++) { const TIntFltKdV& RowV = RowSpVV[j]; int len = RowV.Len(); for (int i = 0; i < len; i++) { Result[RowV[i].Key] += RowV[i].Dat * B(j,ColId); } } }
void TSparseRowMatrix::PMultiplyT | ( | const TFltV & | Vec, |
TFltV & | Result | ||
) | const [protected, virtual] |
Implements TMatrix.
Definition at line 90 of file linalg.cpp.
References Assert, ColN, TVec< TVal, TSizeTy >::Len(), RowN, and RowSpVV.
{ Assert(Vec.Len() >= RowN && Result.Len() >= ColN); for (int i = 0; i < ColN; i++) Result[i] = 0.0; for (int j = 0; j < RowN; j++) { const TIntFltKdV& RowV = RowSpVV[j]; int len = RowV.Len(); for (int i = 0; i < len; i++) { Result[RowV[i].Key] += RowV[i].Dat * Vec[j]; } } }
void TSparseRowMatrix::Save | ( | TSOut & | SOut | ) | [inline] |
Definition at line 93 of file linalg.h.
Referenced by Load(), PGetCols(), PMultiply(), PMultiplyT(), Save(), and TSparseRowMatrix().
Definition at line 93 of file linalg.h.
Referenced by Load(), PGetRows(), PMultiply(), PMultiplyT(), Save(), and TSparseRowMatrix().
Definition at line 95 of file linalg.h.
Referenced by Load(), PMultiply(), PMultiplyT(), Save(), and TSparseRowMatrix().