-
Notifications
You must be signed in to change notification settings - Fork 0
/
SigTRow.cpp
108 lines (88 loc) · 3.6 KB
/
SigTRow.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
102
103
104
105
106
107
/*
* File: SigTRow.cpp
* Author: ivek
*
* Created on January 19, 2012, 11:27 AM
*/
#include "SigTRow.h"
#include "TmpCol.h"
#include "VCol.h"
#include "TRow.h"
#include "SupportXCol.h"
#include "VertexVisitor.h"
#include <cblas.h>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
SigTRow::SigTRow()
{
this->values = new element_type[VertexProxy::K->get_val()];
memset(this->values, 0, sizeof (element_type) * VertexProxy::K->get_val());
}
SigTRow::SigTRow(const SigTRow& orig)
{
this->values = new element_type[VertexProxy::K->get_val()];
memcpy(this->values, orig.values, sizeof (element_type) * VertexProxy::K->get_val());
}
SigTRow::~SigTRow() {
delete(this->values);
}
UpdateFunctionDelegator* SigTRow::clone() {
UpdateFunctionDelegator* clone = new SigTRow(*this);
return (UpdateFunctionDelegator*) clone;
}
void SigTRow::accept(VertexVisitor &v, gl::iscope& scope, gl::icallback& schedule) {
v.visit(this, scope, schedule);
}
void SigTRow::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();
/* init accumulator to allzeros */
memset(&this->values[0], 0, sizeof(element_type)*VertexProxy::K->get_val());
// Iterate through neighboring vertices
/*
* The order in which vertices are fetched is important here - as in
* ModelNMF's initgraph()
*
* (in_edges.size()-1)/3 VCol objects followed by
* a TRow object followed by
* (in_edges.size()-1)/3 TmpCol objects followed by
* (in_edges.size()-1)/3 SupportXCol objects followed by
*/
unsigned int helper = (in_edges.size()-1)/3;
unsigned int vColOffset = 0;
unsigned int tRowOffset = vColOffset + helper;
unsigned int tmpColOffset = tRowOffset + 1 ;
unsigned int supportXColOffset = tmpColOffset + helper;
const element_type* buffer;
/* Fetching triplets of SupportXCol, LvCols and TmpCols
* TODO: use SIMD for elementwise multiplication
*/
unsigned int numPasses = (in_edges.size() - 1)/3;
const VertexProxy& tneighbor = scope.neighbor_vertex_data(scope.source(in_edges[ tRowOffset ]));
const TRow& tdelegator = (const TRow&) *tneighbor.getDelegator();
for (size_t i = 0; i < numPasses; ++i) {
// SupportXCol:
const VertexProxy& neighbor = scope.neighbor_vertex_data(scope.source(in_edges[ i+supportXColOffset ]));
const SupportXCol& delegator = (const SupportXCol&) *neighbor.getDelegator();
unsigned int location = delegator.binarySearch(tdelegator.row);
// VCol:
const VertexProxy& neighbor1 = scope.neighbor_vertex_data(scope.source(in_edges[ i+vColOffset ]));
const VCol& delegator1 = (const VCol&) *neighbor1.getDelegator();
buffer = &delegator1.expELogValues[0];
// TmpCol:
const VertexProxy& neighbor3 = scope.neighbor_vertex_data(scope.source(in_edges[ i+tmpColOffset ]));
const TmpCol& delegator3 = (const TmpCol&) *neighbor3.getDelegator();
const element_type& multiplier = delegator3.values[location];
cblas_daxpy(VertexProxy::K->get_val(), multiplier, buffer, 1, &this->values[0], 1);
}
/* Fetching TRow
* TODO: use SIMD for elementwise multiplication
*/
buffer = &tdelegator.expELogValues[0];
for (unsigned int col = 0; col < VertexProxy::K->get_val(); ++col) {
this->values[col] *= buffer[col];
}
}