SNAP Library 2.0, User Reference  2013-05-13 16:33:57
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>

Inherits TMatrix.

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.

                                                              {
   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++;
     }
   }
}

Member Function Documentation

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

Definition at line 119 of file linalg.h.

                         {
        SIn.Load(RowN); SIn.Load(ColN); RowSpVV = TVec<TIntFltKdV>(SIn); }
int TSparseRowMatrix::PGetCols ( ) const [inline, protected, virtual]

Implements TMatrix.

Definition at line 107 of file linalg.h.

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

Implements TMatrix.

Definition at line 106 of file linalg.h.

{ 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.

                                                                                {
    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.

                                                                      {
    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.

                                                                                 {
    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.

                                                                       {
    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 117 of file linalg.h.

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

Member Data Documentation

Definition at line 93 of file linalg.h.

Definition at line 93 of file linalg.h.

Definition at line 95 of file linalg.h.


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