-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSigVCol.cpp
101 lines (86 loc) · 3.24 KB
/
SigVCol.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/*
* File: SigVCol.cpp
* Author: ivek
*
* Created on January 19, 2012, 3:48 PM
*/
#include "SigVCol.h"
#include "TRow.h"
#include "TmpCol.h"
#include "VCol.h"
#include "VertexVisitor.h"
#include <cblas.h>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
SigVCol::SigVCol()
{
this->values = new element_type[VertexProxy::K->get_val()];
memset(this->values, 0, sizeof (element_type) * VertexProxy::K->get_val());
}
SigVCol::SigVCol(const SigVCol& orig)
{
this->values = new element_type[VertexProxy::K->get_val()];
memcpy(this->values, orig.values, sizeof (element_type) * VertexProxy::K->get_val());
}
SigVCol::~SigVCol() {
delete(this->values);
}
UpdateFunctionDelegator* SigVCol::clone() {
UpdateFunctionDelegator* clone = new SigVCol(*this);
return (UpdateFunctionDelegator*) clone;
}
void SigVCol::accept(VertexVisitor &v, gl::iscope& scope, gl::icallback& schedule) {
v.visit(this, scope, schedule);
}
void SigVCol::updateFunction(gl::iscope& scope, gl::icallback& scheduler) {
/* Get a reference to the vertex data and visible edges */
// vertex_data& us = scope.vertex_data();
gl::edge_list in_edges = scope.in_edge_ids();
/*
* The order in which vertices are fetched is important here - as in
* ModelNMF's initgraph()
*
* one VCol object followed by
* (in_edges.size()-2) TRow objects followed by
* one TmpCol object
*/
unsigned int numPasses = in_edges.size() - 2; // #neigboring LtRows == sparsity of tmpCol neighbor
unsigned int vColOffset = 0;
unsigned int tRowOffset = vColOffset + 1;
unsigned int tmpColOffset = tRowOffset + numPasses;
// buffer to be filled with neigboring LtRows, rowwise, (corresponds to CblasRowMajor)
element_type buffer[VertexProxy::K->get() * numPasses];
element_type* location = buffer;
/* Collecting TRows
*/
for (size_t i = tRowOffset; i < tRowOffset + numPasses; ++i) {
const VertexProxy& neighbor = scope.neighbor_vertex_data(scope.source(in_edges[ i ]));
const TRow& delegator = (const TRow&) *neighbor.getDelegator();
memcpy(location, &delegator.expELogValues[0], sizeof (element_type) * VertexProxy::K->get());
location += VertexProxy::K->get();
}
/* Fetching TmpCol neighbor...
*/
{
const VertexProxy& neighbor = scope.neighbor_vertex_data(scope.source(in_edges[ tmpColOffset ]));
const TmpCol& delegator = (const TmpCol&) *neighbor.getDelegator();
/* ... and performing matrix multiplication
*/
cblas_dgemv(CblasRowMajor, CblasTrans, numPasses, VertexProxy::K->get(), 1.0,
buffer, VertexProxy::K->get(), &delegator.values[0], 1, 0.0, &this->values[0], 1);
}
/* Fetching VCol...
* ( TODO: use SIMD for elementwise multiplication )
*/
{
const VertexProxy& neighbor = scope.neighbor_vertex_data(scope.source(in_edges[ vColOffset ]));
const VCol& delegator = (const VCol&) *neighbor.getDelegator();
/* ... and performing elementwise product with what we got previously
*/
for (unsigned int row = 0; row < VertexProxy::K->get_val(); ++row) {
this->values[row] *= delegator.expELogValues[row];
}
}
}