forked from data61/MP-SPDZ
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Row.hpp
135 lines (120 loc) · 2.71 KB
/
Row.hpp
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#include "OT/Row.h"
#include "Tools/Exceptions.h"
template<class T>
bool Row<T>::operator ==(const Row<T>& other) const
{
return rows == other.rows;
}
template<class T>
Row<T>& Row<T>::operator +=(const Row<T>& other)
{
if (rows.size() != other.size()) {
throw invalid_length();
}
for (size_t i = 0; i < this->size(); i++)
rows[i] += other.rows[i];
return *this;
}
template<class T>
Row<T>& Row<T>::operator -=(const Row<T>& other)
{
if (rows.size() != other.size()) {
throw invalid_length();
}
for (size_t i = 0; i < this->size(); i++)
rows[i] -= other.rows[i];
return *this;
}
template<class T>
Row<T>& Row<T>::operator *=(const T& other)
{
for (size_t i = 0; i < this->size(); i++)
rows[i] = rows[i] * other;
return *this;
}
template<class T>
Row<T> Row<T>::operator *(const T& other)
{
Row<T> res = *this;
res *= other;
return res;
}
template<class T>
DeferredPlus<T, Row<T>> Row<T>::operator +(const Row<T>& other)
{
return {*this, other};
}
template<class T>
DeferredMinus<T, Row<T>> Row<T>::operator -(const Row<T>& other)
{
return {*this, other};
}
template<class T>
template<class U>
Row<T>& Row<T>::operator=(const DeferredMinus<T, U>& d)
{
size_t size = d.x.size();
rows.resize(size);
for (size_t i = 0; i < size; i++)
rows[i] = d[i];
return *this;
}
template<class T>
template<class U>
Row<T>& Row<T>::operator=(const DeferredPlus<T, U>& d)
{
size_t size = d.x.size();
rows.resize(size);
for (size_t i = 0; i < size; i++)
rows[i] = d[i];
return *this;
}
template<class T>
void Row<T>::randomize(PRNG& G, size_t size)
{
rows.clear();
rows.reserve(size);
for (size_t i = 0; i < size; i++)
rows.push_back(G.get<T>());
}
template<class T>
Row<T> Row<T>::operator<<(int i) const {
if (i >= T::size() * 8) {
throw invalid_params();
}
Row<T> res = *this;
for (size_t j = 0; j < this->size(); j++)
res.rows[j] = res.rows[j] << i;
return res;
}
template<class T, class U>
void DeferredPlus<T, U>::pack(octetStream& o) const
{
o.store(this->size());
for (size_t i = 0; i < this->size(); i++)
(*this)[i].pack(o);
}
template<class T>
void Row<T>::pack(octetStream& o) const
{
o.store(this->size());
for (size_t i = 0; i < this->size(); i++)
rows[i].pack(o);
}
template<class T>
void Row<T>::unpack(octetStream& o)
{
size_t size;
o.get(size);
rows.clear();
rows.reserve(size);
for (size_t i = 0; i < size; i++)
rows.push_back(o.get<T>());
}
template <class V>
ostream& operator<<(ostream& o, const Row<V>& x)
{
for (size_t i = 0; i < x.size(); ++i)
o << x.rows[i] << " | ";
return o;
}