SNAP Library 2.3, User Reference  2014-06-16 11:58:46
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
TUNGraphMtx Class Reference

#include <gsvd.h>

Inherits TMatrix.

Public Member Functions

 TUNGraphMtx (const PUNGraph &GraphPt)
 
 TUNGraphMtx (const TUNGraphMtx &GraphMtx)
 
TUNGraphMtxoperator= (const TUNGraphMtx &GraphMtx)
 
int PGetRows () const
 
int PGetCols () const
 
void PMultiply (const TFltVV &B, int ColId, TFltV &Result) const
 
void PMultiply (const TFltV &Vec, TFltV &Result) const
 
void PMultiplyT (const TFltVV &B, int ColId, TFltV &Result) const
 
void PMultiplyT (const TFltV &Vec, TFltV &Result) const
 
- Public Member Functions inherited from TMatrix
 TMatrix ()
 
virtual ~TMatrix ()
 
void Multiply (const TFltVV &B, int ColId, TFltV &Result) const
 
void Multiply (const TFltV &Vec, TFltV &Result) const
 
void MultiplyT (const TFltVV &B, int ColId, TFltV &Result) const
 
void MultiplyT (const TFltV &Vec, TFltV &Result) const
 
int GetRows () const
 
int GetCols () const
 
void Transpose ()
 

Private Member Functions

bool CheckNodeIds ()
 

Private Attributes

PUNGraph Graph
 

Additional Inherited Members

Detailed Description

Undirected Graph Adjacency Matrix represented as sparse {0,1} row matrix. The class is used for computing spectral properties of graph adjacency matrices. The class assumes that node IDs have the range 0...Nodes-1.

Definition at line 29 of file gsvd.h.

Constructor & Destructor Documentation

TUNGraphMtx::TUNGraphMtx ( const PUNGraph GraphPt)

Definition at line 83 of file gsvd.cpp.

83  : Graph() {
84  Graph = GraphPt;
85  if (! CheckNodeIds()) {
86  printf(" Renumbering %d nodes....", GraphPt->GetNodes());
87  TExeTm ExeTm;
88  Graph = TSnap::ConvertGraph<PUNGraph>(GraphPt, true);
89  /*TIntSet NIdSet;
90  for (TUNGraph::TNodeI NI = Graph->BegNI(); NI < Graph->EndNI(); NI++) {
91  NIdSet.AddKey(NI.GetId());
92  }
93  Graph = TUNGraph::New(); *Graph = *GraphPt; */
94  printf("done [%s]\n", ExeTm.GetStr());
95  }
96 }
Definition: tm.h:354
int GetNodes() const
Returns the number of nodes in the graph.
Definition: graph.h:162
PUNGraph Graph
Definition: gsvd.h:31
bool CheckNodeIds()
Definition: gsvd.cpp:76
TUNGraphMtx::TUNGraphMtx ( const TUNGraphMtx GraphMtx)
inline

Definition at line 35 of file gsvd.h.

35 : Graph(GraphMtx.Graph) { }
PUNGraph Graph
Definition: gsvd.h:31

Member Function Documentation

bool TUNGraphMtx::CheckNodeIds ( )
private

Definition at line 76 of file gsvd.cpp.

76  {
77  for (int NId = 0; NId < Graph->GetNodes(); NId++) {
78  if (! Graph->IsNode(NId)) { return false; }
79  }
80  return true;
81 }
int GetNodes() const
Returns the number of nodes in the graph.
Definition: graph.h:162
PUNGraph Graph
Definition: gsvd.h:31
bool IsNode(const int &NId) const
Tests whether ID NId is a node.
Definition: graph.h:199
TUNGraphMtx& TUNGraphMtx::operator= ( const TUNGraphMtx GraphMtx)
inline

Definition at line 36 of file gsvd.h.

36 { Graph=GraphMtx.Graph; return *this; }
PUNGraph Graph
Definition: gsvd.h:31
int TUNGraphMtx::PGetCols ( ) const
inlinevirtual

Implements TMatrix.

Definition at line 38 of file gsvd.h.

38 { return Graph->GetNodes(); }
int GetNodes() const
Returns the number of nodes in the graph.
Definition: graph.h:162
PUNGraph Graph
Definition: gsvd.h:31
int TUNGraphMtx::PGetRows ( ) const
inlinevirtual

Implements TMatrix.

Definition at line 37 of file gsvd.h.

37 { return Graph->GetNodes(); }
int GetNodes() const
Returns the number of nodes in the graph.
Definition: graph.h:162
PUNGraph Graph
Definition: gsvd.h:31
void TUNGraphMtx::PMultiply ( const TFltVV B,
int  ColId,
TFltV Result 
) const
virtual

Implements TMatrix.

Definition at line 99 of file gsvd.cpp.

99  {
100  const int RowN = GetRows();
101  Assert(B.GetRows() >= RowN && Result.Len() >= RowN);
102  const THash<TInt, TUNGraph::TNode>& NodeH = Graph->NodeH;
103  for (int j = 0; j < RowN; j++) {
104  const TIntV& RowV = NodeH[j].NIdV;
105  Result[j] = 0.0;
106  for (int i = 0; i < RowV.Len(); i++) {
107  Result[j] += B(RowV[i], ColId);
108  }
109  }
110 }
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:535
int GetRows() const
Definition: linalg.h:45
#define Assert(Cond)
Definition: bd.h:251
PUNGraph Graph
Definition: gsvd.h:31
THash< TInt, TNode > NodeH
Definition: graph.h:135
int GetRows() const
Definition: ds.h:3129
void TUNGraphMtx::PMultiply ( const TFltV Vec,
TFltV Result 
) const
virtual

Implements TMatrix.

Definition at line 113 of file gsvd.cpp.

113  {
114  const int RowN = GetRows();
115  Assert(Vec.Len() >= RowN && Result.Len() >= RowN);
116  const THash<TInt, TUNGraph::TNode>& NodeH = Graph->NodeH;
117  for (int j = 0; j < RowN; j++) {
118  const TIntV& RowV = NodeH[j].NIdV;
119  Result[j] = 0.0;
120  for (int i = 0; i < RowV.Len(); i++) {
121  Result[j] += Vec[RowV[i]];
122  }
123  }
124 }
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:535
int GetRows() const
Definition: linalg.h:45
#define Assert(Cond)
Definition: bd.h:251
PUNGraph Graph
Definition: gsvd.h:31
THash< TInt, TNode > NodeH
Definition: graph.h:135
void TUNGraphMtx::PMultiplyT ( const TFltVV B,
int  ColId,
TFltV Result 
) const
virtual

Implements TMatrix.

Definition at line 127 of file gsvd.cpp.

127  {
128  const int ColN = GetCols();
129  Assert(B.GetRows() >= ColN && Result.Len() >= ColN);
130  const THash<TInt, TUNGraph::TNode>& NodeH = Graph->NodeH;
131  for (int i = 0; i < ColN; i++) Result[i] = 0.0;
132  for (int j = 0; j < ColN; j++) {
133  const TIntV& RowV = NodeH[j].NIdV;
134  for (int i = 0; i < RowV.Len(); i++) {
135  Result[RowV[i]] += B(j, ColId);
136  }
137  }
138 }
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:535
#define Assert(Cond)
Definition: bd.h:251
int GetCols() const
Definition: linalg.h:47
PUNGraph Graph
Definition: gsvd.h:31
THash< TInt, TNode > NodeH
Definition: graph.h:135
int GetRows() const
Definition: ds.h:3129
void TUNGraphMtx::PMultiplyT ( const TFltV Vec,
TFltV Result 
) const
virtual

Implements TMatrix.

Definition at line 141 of file gsvd.cpp.

141  {
142  const int RowN = GetRows();
143  Assert(Vec.Len() >= RowN && Result.Len() >= RowN);
144  const THash<TInt, TUNGraph::TNode>& NodeH = Graph->NodeH;
145  for (int i = 0; i < RowN; i++) Result[i] = 0.0;
146  for (int j = 0; j < RowN; j++) {
147  const TIntV& RowV = NodeH[j].NIdV;
148  for (int i = 0; i < RowV.Len(); i++) {
149  Result[RowV[i]] += Vec[j];
150  }
151  }
152 }
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:535
int GetRows() const
Definition: linalg.h:45
#define Assert(Cond)
Definition: bd.h:251
PUNGraph Graph
Definition: gsvd.h:31
THash< TInt, TNode > NodeH
Definition: graph.h:135

Member Data Documentation

PUNGraph TUNGraphMtx::Graph
private

Definition at line 31 of file gsvd.h.


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