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
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
TSparseRowMatrix Class Reference

#include <linalg.h>

Inheritance diagram for TSparseRowMatrix:
Collaboration diagram for TSparseRowMatrix:

List of all members.

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< TIntFltKdVRowSpVV

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

Detailed Description

Definition at line 90 of file linalg.h.


Constructor & Destructor Documentation

Definition at line 110 of file linalg.h.

: TMatrix() {}

Definition at line 111 of file linalg.h.

: TMatrix(), RowSpVV(_RowSpVV) {}
TSparseRowMatrix::TSparseRowMatrix ( TVec< TIntFltKdV _RowSpVV,
const int &  _RowN,
const int &  _ColN 
) [inline]

Definition at line 112 of file linalg.h.

                                                                                   : 
                TMatrix(), RowN(_RowN), ColN(_ColN), RowSpVV(_RowSpVV) {}
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++;
     }
   }
}

Here is the call graph for this function:


Member Function Documentation

void TSparseRowMatrix::Load ( TSIn SIn) [inline]

Definition at line 119 of file linalg.h.

References ColN, TSIn::Load(), RowN, and RowSpVV.

                         {
        SIn.Load(RowN); SIn.Load(ColN); RowSpVV = TVec<TIntFltKdV>(SIn); }

Here is the call graph for this function:

int TSparseRowMatrix::PGetCols ( ) const [inline, protected, virtual]

Implements TMatrix.

Definition at line 107 of file linalg.h.

References ColN.

{ return ColN; }
int TSparseRowMatrix::PGetRows ( ) const [inline, protected, virtual]

Implements TMatrix.

Definition at line 106 of file linalg.h.

References RowN.

{ return RowN; }
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);
        }
    }
}

Here is the call graph for this function:

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];
        }
    }
}

Here is the call graph for this function:

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);
        }
    }
}

Here is the call graph for this function:

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];
        }
    }
}

Here is the call graph for this function:

void TSparseRowMatrix::Save ( TSOut SOut) [inline]

Definition at line 117 of file linalg.h.

References ColN, RowN, RowSpVV, TSOut::Save(), and TVec< TVal, TSizeTy >::Save().

                           {
        SOut.Save(RowN); SOut.Save(ColN); RowSpVV.Save(SOut); }

Here is the call graph for this function:


Member Data Documentation

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().


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