-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtriple.h
73 lines (64 loc) · 1.79 KB
/
triple.h
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
#ifndef _TRIPLE_H_
#define _TRIPLE_H_
#include <iostream>
#include <functional>
#include "utility.h"
#include "spvec.h"
using namespace std;
template <class T, class ITYPE>
struct Triple
{
ITYPE row; // row index
ITYPE col; // col index
T val; // value
};
template <class T, class ITYPE>
struct ColSortCompare: // struct instead of class so that operator() is public
public binary_function< Triple<T, ITYPE>, Triple<T, ITYPE>, bool > // (par1, par2, return_type)
{
inline bool operator()(const Triple<T, ITYPE> & lhs, const Triple<T, ITYPE> & rhs) const
{
if(lhs.col == rhs.col)
{
return lhs.row < rhs.row;
}
else
{
return lhs.col < rhs.col;
}
}
};
template <class T, class ITYPE>
struct RowSortCompare: // struct instead of class so that operator() is public
public binary_function< Triple<T, ITYPE>, Triple<T, ITYPE>, bool > // (par1, par2, return_type)
{
inline bool operator()(const Triple<T, ITYPE> & lhs, const Triple<T, ITYPE> & rhs) const
{
if(lhs.row == rhs.row)
{
return lhs.col < rhs.col;
}
else
{
return lhs.row < rhs.row;
}
}
};
template <class T, class ITYPE, class OTYPE>
struct BitSortCompare: // struct instead of class so that operator() is public
public binary_function< Triple<T, ITYPE>, Triple<T, ITYPE>, bool > // (par1, par2, return_type)
{
inline bool operator()(const Triple<T, ITYPE> & lhs, const Triple<T, ITYPE> & rhs) const
{
return BitInterleave<ITYPE, OTYPE>(lhs.row, lhs.col) < BitInterleave<ITYPE, OTYPE>(rhs.row, rhs.col);
}
};
template <typename T, typename ITYPE>
void triples_gaxpy(Triple<T, ITYPE> * triples, Spvec<T, ITYPE> & x, Spvec<T, ITYPE> & y, ITYPE nnz)
{
for(ITYPE i=0; i< nnz; ++i)
{
y [triples[i].row] += triples[i].val * x [triples[i].col] ;
}
};
#endif