... | ... |
@@ -20,7 +20,7 @@ TEST_CASE("Test SparseIterator.h - One Dimensional") |
20 | 20 |
v.insert(7, 8.f); |
21 | 21 |
v.insert(9, 10.f); |
22 | 22 |
|
23 |
- TemplatedSparseIterator<1> it(v); |
|
23 |
+ SparseIterator<1> it(v); |
|
24 | 24 |
REQUIRE(get<1>(it) == 1.f); |
25 | 25 |
it.next(); |
26 | 26 |
REQUIRE(get<1>(it) == 5.f); |
... | ... |
@@ -51,7 +51,7 @@ TEST_CASE("Test SparseIterator.h - One Dimensional") |
51 | 51 |
for (unsigned j = 0; j < ref.nCol(); ++j) |
52 | 52 |
{ |
53 | 53 |
float colSum = 0.f; |
54 |
- TemplatedSparseIterator<1> it(mat.getCol(j)); |
|
54 |
+ SparseIterator<1> it(mat.getCol(j)); |
|
55 | 55 |
while (!it.atEnd()) |
56 | 56 |
{ |
57 | 57 |
colSum += get<1>(it); |
... | ... |
@@ -79,7 +79,7 @@ TEST_CASE("Test SparseIterator.h - Two Dimensional") |
79 | 79 |
hv.add(6, 5.f); |
80 | 80 |
hv.add(7, 6.f); |
81 | 81 |
|
82 |
- TemplatedSparseIterator<2> it(sv, hv); |
|
82 |
+ SparseIterator<2> it(sv, hv); |
|
83 | 83 |
REQUIRE(get<1>(it) == 5.f); |
84 | 84 |
REQUIRE(get<2>(it) == 3.f); |
85 | 85 |
it.next(); |
... | ... |
@@ -107,7 +107,7 @@ TEST_CASE("Test SparseIterator.h - Two Dimensional") |
107 | 107 |
hv.add(8, 9.f); |
108 | 108 |
hv.add(75, 76.f); |
109 | 109 |
|
110 |
- TemplatedSparseIterator<2> it(sv, hv); |
|
110 |
+ SparseIterator<2> it(sv, hv); |
|
111 | 111 |
REQUIRE(get<1>(it) == 75.f); |
112 | 112 |
REQUIRE(get<2>(it) == 76.f); |
113 | 113 |
it.next(); |
... | ... |
@@ -170,7 +170,7 @@ TEST_CASE("Test SparseIterator.h - Two Dimensional") |
170 | 170 |
|
171 | 171 |
// calculate dot product |
172 | 172 |
float sdot = 0.f, ddot = 0.f; |
173 |
- TemplatedSparseIterator<2> it(sv, hv); |
|
173 |
+ SparseIterator<2> it(sv, hv); |
|
174 | 174 |
unsigned i = 0; |
175 | 175 |
while (!it.atEnd()) |
176 | 176 |
{ |
... | ... |
@@ -218,7 +218,7 @@ TEST_CASE("Test SparseIterator.h - Two Dimensional") |
218 | 218 |
for (unsigned j2 = j1; j2 < ref.nCol(); ++j2) |
219 | 219 |
{ |
220 | 220 |
float dot = 0.f; |
221 |
- TemplatedSparseIterator<2> it(sMat.getCol(j1), hMat.getCol(j2)); |
|
221 |
+ SparseIterator<2> it(sMat.getCol(j1), hMat.getCol(j2)); |
|
222 | 222 |
while (!it.atEnd()) |
223 | 223 |
{ |
224 | 224 |
dot += get<1>(it) * get<2>(it); |
... | ... |
@@ -265,7 +265,7 @@ TEST_CASE("Test SparseIterator.h - Three Dimensional") |
265 | 265 |
hv2.add(8, 7.f); |
266 | 266 |
hv2.add(9, 8.f); |
267 | 267 |
|
268 |
- TemplatedSparseIterator<3> it(sv, hv1, hv2); |
|
268 |
+ SparseIterator<3> it(sv, hv1, hv2); |
|
269 | 269 |
REQUIRE(get<1>(it) == 5.f); // 4 |
270 | 270 |
REQUIRE(get<2>(it) == 3.f); |
271 | 271 |
REQUIRE(get<3>(it) == 6.f); |
... | ... |
@@ -301,7 +301,7 @@ TEST_CASE("Test SparseIterator.h - Three Dimensional") |
301 | 301 |
for (unsigned j3 = j2; j3 < ref.nCol(); ++j3) |
302 | 302 |
{ |
303 | 303 |
float prod = 0.f; |
304 |
- TemplatedSparseIterator<3> it(sMat.getCol(j1), hMat.getCol(j2), |
|
304 |
+ SparseIterator<3> it(sMat.getCol(j1), hMat.getCol(j2), |
|
305 | 305 |
hMat.getCol(j3)); |
306 | 306 |
while (!it.atEnd()) |
307 | 307 |
{ |
... | ... |
@@ -53,59 +53,59 @@ void gotoNextCommon(Iter &it) |
53 | 53 |
} |
54 | 54 |
|
55 | 55 |
template<> |
56 |
-float get<1>(const TemplatedSparseIterator<1> &it) |
|
56 |
+float get<1>(const SparseIterator<1> &it) |
|
57 | 57 |
{ |
58 | 58 |
return it.mSparse.at(it.mSparseIndex); |
59 | 59 |
} |
60 | 60 |
|
61 | 61 |
template<> |
62 |
-float get<1>(const TemplatedSparseIterator<2> &it) |
|
62 |
+float get<1>(const SparseIterator<2> &it) |
|
63 | 63 |
{ |
64 | 64 |
return it.mSparse.at(it.mSparseIndex); |
65 | 65 |
} |
66 | 66 |
|
67 | 67 |
template<> |
68 |
-float get<1>(const TemplatedSparseIterator<3> &it) |
|
68 |
+float get<1>(const SparseIterator<3> &it) |
|
69 | 69 |
{ |
70 | 70 |
return it.mSparse.at(it.mSparseIndex); |
71 | 71 |
} |
72 | 72 |
|
73 | 73 |
template<> |
74 |
-float get<2>(const TemplatedSparseIterator<2> &it) |
|
74 |
+float get<2>(const SparseIterator<2> &it) |
|
75 | 75 |
{ |
76 | 76 |
return it.mHybrid[64 * it.mBigIndex + it.mSmallIndex]; |
77 | 77 |
} |
78 | 78 |
|
79 | 79 |
template<> |
80 |
-float get<2>(const TemplatedSparseIterator<3> &it) |
|
80 |
+float get<2>(const SparseIterator<3> &it) |
|
81 | 81 |
{ |
82 | 82 |
return it.mHybrid_1[64 * it.mBigIndex + it.mSmallIndex]; |
83 | 83 |
} |
84 | 84 |
|
85 | 85 |
template<> |
86 |
-float get<3>(const TemplatedSparseIterator<3> &it) |
|
86 |
+float get<3>(const SparseIterator<3> &it) |
|
87 | 87 |
{ |
88 | 88 |
return it.mHybrid_2[64 * it.mBigIndex + it.mSmallIndex]; |
89 | 89 |
} |
90 | 90 |
|
91 | 91 |
|
92 |
-TemplatedSparseIterator<1>::TemplatedSparseIterator(const SparseVector &v) |
|
92 |
+SparseIterator<1>::SparseIterator(const SparseVector &v) |
|
93 | 93 |
: |
94 | 94 |
mSparse(v), |
95 | 95 |
mSparseIndex(0) |
96 | 96 |
{} |
97 | 97 |
|
98 |
-bool TemplatedSparseIterator<1>::atEnd() const |
|
98 |
+bool SparseIterator<1>::atEnd() const |
|
99 | 99 |
{ |
100 | 100 |
return mSparseIndex == mSparse.nElements(); |
101 | 101 |
} |
102 | 102 |
|
103 |
-void TemplatedSparseIterator<1>::next() |
|
103 |
+void SparseIterator<1>::next() |
|
104 | 104 |
{ |
105 | 105 |
++mSparseIndex; |
106 | 106 |
} |
107 | 107 |
|
108 |
-TemplatedSparseIterator<2>::TemplatedSparseIterator(const SparseVector &v, const HybridVector &h) |
|
108 |
+SparseIterator<2>::SparseIterator(const SparseVector &v, const HybridVector &h) |
|
109 | 109 |
: |
110 | 110 |
mSparse(v), |
111 | 111 |
mHybrid(h), |
... | ... |
@@ -124,33 +124,33 @@ mAtEnd(false) |
124 | 124 |
mSparseIndex -= 1; // next puts us at position 1, this resets to 0 |
125 | 125 |
} |
126 | 126 |
|
127 |
-bool TemplatedSparseIterator<2>::atEnd() const |
|
127 |
+bool SparseIterator<2>::atEnd() const |
|
128 | 128 |
{ |
129 | 129 |
return mAtEnd; |
130 | 130 |
} |
131 | 131 |
|
132 |
-void TemplatedSparseIterator<2>::next() |
|
132 |
+void SparseIterator<2>::next() |
|
133 | 133 |
{ |
134 | 134 |
gotoNextCommon(*this); |
135 | 135 |
} |
136 | 136 |
|
137 |
-void TemplatedSparseIterator<2>::calculateCommonFlags() |
|
137 |
+void SparseIterator<2>::calculateCommonFlags() |
|
138 | 138 |
{ |
139 | 139 |
mCommonFlags = mSparseFlags & mHybridFlags; |
140 | 140 |
} |
141 | 141 |
|
142 |
-void TemplatedSparseIterator<2>::getFlags() |
|
142 |
+void SparseIterator<2>::getFlags() |
|
143 | 143 |
{ |
144 | 144 |
mSparseFlags = mSparse.mIndexBitFlags[mBigIndex]; |
145 | 145 |
mHybridFlags = mHybrid.mIndexBitFlags[mBigIndex]; |
146 | 146 |
} |
147 | 147 |
|
148 |
-unsigned TemplatedSparseIterator<2>::getIndex() const |
|
148 |
+unsigned SparseIterator<2>::getIndex() const |
|
149 | 149 |
{ |
150 | 150 |
return 64 * mBigIndex + mSmallIndex; |
151 | 151 |
} |
152 | 152 |
|
153 |
-TemplatedSparseIterator<3>::TemplatedSparseIterator(const SparseVector &v, |
|
153 |
+SparseIterator<3>::SparseIterator(const SparseVector &v, |
|
154 | 154 |
const HybridVector &h1, const HybridVector &h2) |
155 | 155 |
: |
156 | 156 |
mSparse(v), |
... | ... |
@@ -173,211 +173,29 @@ mAtEnd(false) |
173 | 173 |
mSparseIndex -= 1; |
174 | 174 |
} |
175 | 175 |
|
176 |
-bool TemplatedSparseIterator<3>::atEnd() const |
|
176 |
+bool SparseIterator<3>::atEnd() const |
|
177 | 177 |
{ |
178 | 178 |
return mAtEnd; |
179 | 179 |
} |
180 | 180 |
|
181 |
-void TemplatedSparseIterator<3>::next() |
|
181 |
+void SparseIterator<3>::next() |
|
182 | 182 |
{ |
183 | 183 |
gotoNextCommon(*this); |
184 | 184 |
} |
185 | 185 |
|
186 |
-void TemplatedSparseIterator<3>::calculateCommonFlags() |
|
186 |
+void SparseIterator<3>::calculateCommonFlags() |
|
187 | 187 |
{ |
188 | 188 |
mCommonFlags = mSparseFlags & mHybridFlags_1 & mHybridFlags_2; |
189 | 189 |
} |
190 | 190 |
|
191 |
-void TemplatedSparseIterator<3>::getFlags() |
|
191 |
+void SparseIterator<3>::getFlags() |
|
192 | 192 |
{ |
193 | 193 |
mSparseFlags = mSparse.mIndexBitFlags[mBigIndex]; |
194 | 194 |
mHybridFlags_1 = mHybrid_1.mIndexBitFlags[mBigIndex]; |
195 | 195 |
mHybridFlags_2 = mHybrid_2.mIndexBitFlags[mBigIndex]; |
196 | 196 |
} |
197 | 197 |
|
198 |
-unsigned TemplatedSparseIterator<3>::getIndex() const |
|
199 |
-{ |
|
200 |
- return 64 * mBigIndex + mSmallIndex; |
|
201 |
-} |
|
202 |
- |
|
203 |
-//////////////////////////////////////////////////////////////////////////////// |
|
204 |
-//////////////////////////////////////////////////////////////////////////////// |
|
205 |
-//////////////////////////////////////////////////////////////////////////////// |
|
206 |
-//////////////////////////////////////////////////////////////////////////////// |
|
207 |
- |
|
208 |
-SparseIterator::SparseIterator(const SparseVector &v) |
|
209 |
- : |
|
210 |
-mSparse(v), |
|
211 |
-mSparseIndex(0) |
|
212 |
-{} |
|
213 |
- |
|
214 |
-bool SparseIterator::atEnd() const |
|
215 |
-{ |
|
216 |
- return mSparseIndex == mSparse.mData.size(); |
|
217 |
-} |
|
218 |
- |
|
219 |
-void SparseIterator::next() |
|
220 |
-{ |
|
221 |
- ++mSparseIndex; |
|
222 |
-} |
|
223 |
- |
|
224 |
-float SparseIterator::getValue() const |
|
225 |
-{ |
|
226 |
- return mSparse.mData[mSparseIndex]; |
|
227 |
-} |
|
228 |
- |
|
229 |
-SparseIteratorTwo::SparseIteratorTwo(const SparseVector &v1, const HybridVector &v2) |
|
230 |
- : |
|
231 |
-mSparse(v1), |
|
232 |
-mHybrid(v2), |
|
233 |
-mFlags_1(mSparse.mIndexBitFlags[0]), |
|
234 |
-mFlags_2(mHybrid.mIndexBitFlags[0]), |
|
235 |
-mCommon(mFlags_1 & mFlags_2), |
|
236 |
-mTotalIndices(mSparse.mIndexBitFlags.size()), |
|
237 |
-mBigIndex(0), |
|
238 |
-mSmallIndex(0), |
|
239 |
-mSparseIndex(0), |
|
240 |
-mAtEnd(false) |
|
241 |
-{ |
|
242 |
- GAPS_ASSERT(v1.size() == v2.size()); |
|
243 |
- |
|
244 |
- next(); |
|
245 |
- mSparseIndex -= 1; // next puts us at position 1, this resets to 0 |
|
246 |
-} |
|
247 |
- |
|
248 |
-bool SparseIteratorTwo::atEnd() const |
|
249 |
-{ |
|
250 |
- return mAtEnd; |
|
251 |
-} |
|
252 |
- |
|
253 |
-void SparseIteratorTwo::next() |
|
254 |
-{ |
|
255 |
- // get the common indices in this chunk |
|
256 |
- mCommon = mFlags_1 & mFlags_2; |
|
257 |
- |
|
258 |
- // if nothing common in this chunk, find a chunk that has common indices |
|
259 |
- while (!mCommon) |
|
260 |
- { |
|
261 |
- // first count how many sparse indices we are skipping |
|
262 |
- mSparseIndex += __builtin_popcountll(mFlags_1); |
|
263 |
- |
|
264 |
- // advance to next chunk |
|
265 |
- if (++mBigIndex == mTotalIndices) |
|
266 |
- { |
|
267 |
- mAtEnd = true; |
|
268 |
- return; |
|
269 |
- } |
|
270 |
- |
|
271 |
- // update the flags |
|
272 |
- mFlags_1 = mSparse.mIndexBitFlags[mBigIndex]; |
|
273 |
- mFlags_2 = mHybrid.mIndexBitFlags[mBigIndex]; |
|
274 |
- mCommon = mFlags_1 & mFlags_2; |
|
275 |
- } |
|
276 |
- |
|
277 |
- // must have at least one common value, this is our index |
|
278 |
- mSmallIndex = __builtin_ffsll(mCommon) - 1; |
|
279 |
- |
|
280 |
- // find the number of skipped entries in the sparse vector |
|
281 |
- mSparseIndex += 1 + countLowerBits(mFlags_1, mSmallIndex); |
|
282 |
- |
|
283 |
- // clear out all skipped indices and the current index from the bitflags |
|
284 |
- mFlags_1 = clearLowerBits(mFlags_1, mSmallIndex); |
|
285 |
-} |
|
286 |
- |
|
287 |
-float SparseIteratorTwo::getValue_1() const |
|
288 |
-{ |
|
289 |
- return mSparse.mData[mSparseIndex]; |
|
290 |
-} |
|
291 |
- |
|
292 |
-float SparseIteratorTwo::getValue_2() const |
|
293 |
-{ |
|
294 |
- return mHybrid[64 * mBigIndex + mSmallIndex]; |
|
295 |
-} |
|
296 |
- |
|
297 |
-unsigned SparseIteratorTwo::getIndex() const |
|
298 |
-{ |
|
299 |
- return 64 * mBigIndex + mSmallIndex; |
|
300 |
-} |
|
301 |
- |
|
302 |
-SparseIteratorThree::SparseIteratorThree(const SparseVector &v1, |
|
303 |
-const HybridVector &v2, const HybridVector &v3) |
|
304 |
- : |
|
305 |
-mSparse(v1), |
|
306 |
-mHybrid_1(v2), |
|
307 |
-mHybrid_2(v3), |
|
308 |
-mFlags_1(mSparse.mIndexBitFlags[0]), |
|
309 |
-mFlags_2(mHybrid_1.mIndexBitFlags[0]), |
|
310 |
-mFlags_3(mHybrid_2.mIndexBitFlags[0]), |
|
311 |
-mCommon(mFlags_1 & mFlags_2 & mFlags_3), |
|
312 |
-mTotalIndices(mSparse.mIndexBitFlags.size()), |
|
313 |
-mBigIndex(0), |
|
314 |
-mSmallIndex(0), |
|
315 |
-mSparseIndex(0), |
|
316 |
-mAtEnd(false) |
|
317 |
-{ |
|
318 |
- GAPS_ASSERT(v1.size() == v2.size()); |
|
319 |
- GAPS_ASSERT(v2.size() == v3.size()); |
|
320 |
- |
|
321 |
- next(); |
|
322 |
- mSparseIndex -= 1; |
|
323 |
-} |
|
324 |
- |
|
325 |
-bool SparseIteratorThree::atEnd() const |
|
326 |
-{ |
|
327 |
- return mAtEnd; |
|
328 |
-} |
|
329 |
- |
|
330 |
-void SparseIteratorThree::next() |
|
331 |
-{ |
|
332 |
- // get the common indices in this chunk |
|
333 |
- mCommon = mFlags_1 & mFlags_2 & mFlags_3; |
|
334 |
- |
|
335 |
- // if nothing common in this chunk, find a chunk that has common indices |
|
336 |
- while (!mCommon) |
|
337 |
- { |
|
338 |
- // first count how many sparse indices we are skipping |
|
339 |
- mSparseIndex += __builtin_popcountll(mFlags_1); |
|
340 |
- |
|
341 |
- // advance to next chunk |
|
342 |
- if (++mBigIndex == mTotalIndices) |
|
343 |
- { |
|
344 |
- mAtEnd = true; |
|
345 |
- return; |
|
346 |
- } |
|
347 |
- |
|
348 |
- // update the flags |
|
349 |
- mFlags_1 = mSparse.mIndexBitFlags[mBigIndex]; |
|
350 |
- mFlags_2 = mHybrid_1.mIndexBitFlags[mBigIndex]; |
|
351 |
- mFlags_3 = mHybrid_2.mIndexBitFlags[mBigIndex]; |
|
352 |
- mCommon = mFlags_1 & mFlags_2 & mFlags_3; |
|
353 |
- } |
|
354 |
- |
|
355 |
- // must have at least one common value, this is our index |
|
356 |
- mSmallIndex = __builtin_ffsll(mCommon) - 1; |
|
357 |
- |
|
358 |
- // find the number of skipped entries in the sparse vector |
|
359 |
- mSparseIndex += 1 + countLowerBits(mFlags_1, mSmallIndex); |
|
360 |
- |
|
361 |
- // clear out all skipped indices and the current index from the bitflags |
|
362 |
- mFlags_1 = clearLowerBits(mFlags_1, mSmallIndex); |
|
363 |
-} |
|
364 |
- |
|
365 |
-float SparseIteratorThree::getValue_1() const |
|
366 |
-{ |
|
367 |
- return mSparse.mData[mSparseIndex]; |
|
368 |
-} |
|
369 |
- |
|
370 |
-float SparseIteratorThree::getValue_2() const |
|
371 |
-{ |
|
372 |
- return mHybrid_1[64 * mBigIndex + mSmallIndex]; |
|
373 |
-} |
|
374 |
- |
|
375 |
-float SparseIteratorThree::getValue_3() const |
|
376 |
-{ |
|
377 |
- return mHybrid_2[64 * mBigIndex + mSmallIndex]; |
|
378 |
-} |
|
379 |
- |
|
380 |
-unsigned SparseIteratorThree::getIndex() const |
|
198 |
+unsigned SparseIterator<3>::getIndex() const |
|
381 | 199 |
{ |
382 | 200 |
return 64 * mBigIndex + mSmallIndex; |
383 | 201 |
} |
... | ... |
@@ -9,36 +9,36 @@ float get(const Iter &it); |
9 | 9 |
|
10 | 10 |
// only allow this class to constructed with N=1,2,3 |
11 | 11 |
template <unsigned N> |
12 |
-class TemplatedSparseIterator |
|
12 |
+class SparseIterator |
|
13 | 13 |
{ |
14 | 14 |
private: |
15 |
- TemplatedSparseIterator() {} |
|
15 |
+ SparseIterator() {} |
|
16 | 16 |
}; |
17 | 17 |
|
18 | 18 |
template<> |
19 |
-class TemplatedSparseIterator<1> |
|
19 |
+class SparseIterator<1> |
|
20 | 20 |
{ |
21 | 21 |
public: |
22 | 22 |
|
23 |
- TemplatedSparseIterator(const SparseVector &v); |
|
23 |
+ SparseIterator(const SparseVector &v); |
|
24 | 24 |
|
25 | 25 |
bool atEnd() const; |
26 | 26 |
void next(); |
27 | 27 |
|
28 | 28 |
private: |
29 | 29 |
|
30 |
- friend float get<1>(const TemplatedSparseIterator<1> &it); |
|
30 |
+ friend float get<1>(const SparseIterator<1> &it); |
|
31 | 31 |
|
32 | 32 |
const SparseVector &mSparse; |
33 | 33 |
unsigned mSparseIndex; |
34 | 34 |
}; |
35 | 35 |
|
36 | 36 |
template<> |
37 |
-class TemplatedSparseIterator<2> |
|
37 |
+class SparseIterator<2> |
|
38 | 38 |
{ |
39 | 39 |
public: |
40 | 40 |
|
41 |
- TemplatedSparseIterator(const SparseVector &v, const HybridVector &h); |
|
41 |
+ SparseIterator(const SparseVector &v, const HybridVector &h); |
|
42 | 42 |
|
43 | 43 |
bool atEnd() const; |
44 | 44 |
void next(); |
... | ... |
@@ -51,8 +51,8 @@ private: |
51 | 51 |
template <class Iter> |
52 | 52 |
friend void gotoNextCommon(Iter &it); |
53 | 53 |
|
54 |
- friend float get<1>(const TemplatedSparseIterator<2> &it); |
|
55 |
- friend float get<2>(const TemplatedSparseIterator<2> &it); |
|
54 |
+ friend float get<1>(const SparseIterator<2> &it); |
|
55 |
+ friend float get<2>(const SparseIterator<2> &it); |
|
56 | 56 |
|
57 | 57 |
const SparseVector &mSparse; |
58 | 58 |
const HybridVector &mHybrid; |
... | ... |
@@ -69,11 +69,11 @@ private: |
69 | 69 |
}; |
70 | 70 |
|
71 | 71 |
template<> |
72 |
-class TemplatedSparseIterator<3> |
|
72 |
+class SparseIterator<3> |
|
73 | 73 |
{ |
74 | 74 |
public: |
75 | 75 |
|
76 |
- TemplatedSparseIterator(const SparseVector &v, const HybridVector &h1, |
|
76 |
+ SparseIterator(const SparseVector &v, const HybridVector &h1, |
|
77 | 77 |
const HybridVector &h2); |
78 | 78 |
|
79 | 79 |
bool atEnd() const; |
... | ... |
@@ -87,9 +87,9 @@ private: |
87 | 87 |
template <class Iter> |
88 | 88 |
friend void gotoNextCommon(Iter &it); |
89 | 89 |
|
90 |
- friend float get<1>(const TemplatedSparseIterator<3> &it); |
|
91 |
- friend float get<2>(const TemplatedSparseIterator<3> &it); |
|
92 |
- friend float get<3>(const TemplatedSparseIterator<3> &it); |
|
90 |
+ friend float get<1>(const SparseIterator<3> &it); |
|
91 |
+ friend float get<2>(const SparseIterator<3> &it); |
|
92 |
+ friend float get<3>(const SparseIterator<3> &it); |
|
93 | 93 |
|
94 | 94 |
const SparseVector &mSparse; |
95 | 95 |
const HybridVector &mHybrid_1; |
... | ... |
@@ -107,91 +107,4 @@ private: |
107 | 107 |
bool mAtEnd; |
108 | 108 |
}; |
109 | 109 |
|
110 |
-//////////////////////////////////////////////////////////////////////////////// |
|
111 |
-//////////////////////////////////////////////////////////////////////////////// |
|
112 |
-//////////////////////////////////////////////////////////////////////////////// |
|
113 |
-//////////////////////////////////////////////////////////////////////////////// |
|
114 |
- |
|
115 |
-class SparseIterator |
|
116 |
-{ |
|
117 |
-public: |
|
118 |
- |
|
119 |
- SparseIterator(const SparseVector &v); |
|
120 |
- |
|
121 |
- bool atEnd() const; |
|
122 |
- void next(); |
|
123 |
- float getValue() const; |
|
124 |
- |
|
125 |
-private: |
|
126 |
- |
|
127 |
- const SparseVector &mSparse; |
|
128 |
- unsigned mSparseIndex; |
|
129 |
-}; |
|
130 |
- |
|
131 |
-class SparseIteratorTwo |
|
132 |
-{ |
|
133 |
-public: |
|
134 |
- |
|
135 |
- SparseIteratorTwo(const SparseVector &v1, const HybridVector &v2); |
|
136 |
- |
|
137 |
- bool atEnd() const; |
|
138 |
- void next(); |
|
139 |
- |
|
140 |
- float getValue_1() const; |
|
141 |
- float getValue_2() const; |
|
142 |
- unsigned getIndex() const; |
|
143 |
- |
|
144 |
-#ifndef GAPS_INTERNAL_TESTS |
|
145 |
-private: |
|
146 |
-#endif |
|
147 |
- |
|
148 |
- const SparseVector &mSparse; |
|
149 |
- const HybridVector &mHybrid; |
|
150 |
- |
|
151 |
- uint64_t mFlags_1; |
|
152 |
- uint64_t mFlags_2; |
|
153 |
- uint64_t mCommon; |
|
154 |
- |
|
155 |
- unsigned mTotalIndices; |
|
156 |
- unsigned mBigIndex; |
|
157 |
- unsigned mSmallIndex; |
|
158 |
- unsigned mSparseIndex; |
|
159 |
- |
|
160 |
- bool mAtEnd; |
|
161 |
-}; |
|
162 |
- |
|
163 |
-class SparseIteratorThree |
|
164 |
-{ |
|
165 |
-public: |
|
166 |
- |
|
167 |
- SparseIteratorThree(const SparseVector &v1, const HybridVector &v2, |
|
168 |
- const HybridVector &v3); |
|
169 |
- |
|
170 |
- bool atEnd() const; |
|
171 |
- void next(); |
|
172 |
- |
|
173 |
- float getValue_1() const; |
|
174 |
- float getValue_2() const; |
|
175 |
- float getValue_3() const; |
|
176 |
- unsigned getIndex() const; |
|
177 |
- |
|
178 |
-private: |
|
179 |
- |
|
180 |
- const SparseVector &mSparse; |
|
181 |
- const HybridVector &mHybrid_1; |
|
182 |
- const HybridVector &mHybrid_2; |
|
183 |
- |
|
184 |
- uint64_t mFlags_1; |
|
185 |
- uint64_t mFlags_2; |
|
186 |
- uint64_t mFlags_3; |
|
187 |
- uint64_t mCommon; |
|
188 |
- |
|
189 |
- unsigned mTotalIndices; |
|
190 |
- unsigned mBigIndex; |
|
191 |
- unsigned mSmallIndex; |
|
192 |
- unsigned mSparseIndex; |
|
193 |
- |
|
194 |
- bool mAtEnd; |
|
195 |
-}; |
|
196 |
- |
|
197 | 110 |
#endif // __COGAPS_SPARSE_ITERATOR_H__ |
198 | 111 |
\ No newline at end of file |
... | ... |
@@ -12,12 +12,8 @@ class SparseVector |
12 | 12 |
{ |
13 | 13 |
public: |
14 | 14 |
|
15 |
- friend class SparseIterator; |
|
16 |
- friend class SparseIteratorTwo; |
|
17 |
- friend class SparseIteratorThree; |
|
18 |
- |
|
19 | 15 |
template <unsigned N> |
20 |
- friend class TemplatedSparseIterator; |
|
16 |
+ friend class SparseIterator; |
|
21 | 17 |
|
22 | 18 |
friend class SparseMatrix; // for inserting values |
23 | 19 |
|
... | ... |
@@ -56,7 +56,7 @@ AlphaParameters SparseGibbsSampler::alphaParameters(unsigned row, unsigned col) |
56 | 56 |
float s = mZ1[col]; |
57 | 57 |
float s_mu = -1.f * gaps::dot(mMatrix.getRow(row), mZ2.getCol(col)); |
58 | 58 |
|
59 |
- TemplatedSparseIterator<2> it(mDMatrix.getCol(row), mOtherMatrix->getCol(col)); |
|
59 |
+ SparseIterator<2> it(mDMatrix.getCol(row), mOtherMatrix->getCol(col)); |
|
60 | 60 |
while (!it.atEnd()) |
61 | 61 |
{ |
62 | 62 |
s += (get<2>(it) * get<2>(it)) / (get<1>(it) * get<1>(it)) |
... | ... |
@@ -79,7 +79,7 @@ unsigned r2, unsigned c2) |
79 | 79 |
AlphaParameters a2 = alphaParameters(r2, c2); |
80 | 80 |
float s = -2.f * mBeta * mZ2(c1,c2) + a1.s + a2.s; |
81 | 81 |
|
82 |
- TemplatedSparseIterator<3> it(mDMatrix.getCol(r1), mOtherMatrix->getCol(c1), |
|
82 |
+ SparseIterator<3> it(mDMatrix.getCol(r1), mOtherMatrix->getCol(c1), |
|
83 | 83 |
mOtherMatrix->getCol(c2)); |
84 | 84 |
while (!it.atEnd()) |
85 | 85 |
{ |
... | ... |
@@ -100,7 +100,7 @@ unsigned col, float ch) |
100 | 100 |
float s_mu = -1.f * gaps::dot(mMatrix.getRow(row), mZ2.getCol(col)); |
101 | 101 |
s_mu -= ch * mZ2(col,col); |
102 | 102 |
|
103 |
- TemplatedSparseIterator<2> it(mDMatrix.getCol(row), mOtherMatrix->getCol(col)); |
|
103 |
+ SparseIterator<2> it(mDMatrix.getCol(row), mOtherMatrix->getCol(col)); |
|
104 | 104 |
while (!it.atEnd()) |
105 | 105 |
{ |
106 | 106 |
s += (get<2>(it) * get<2>(it)) |
... | ... |
@@ -72,10 +72,10 @@ mBeta(100.f) |
72 | 72 |
// check data for values less than 1 |
73 | 73 |
for (unsigned j = 0; j < mDMatrix.nCol(); ++j) |
74 | 74 |
{ |
75 |
- SparseIterator it(mDMatrix.getCol(j)); |
|
75 |
+ SparseIterator<1> it(mDMatrix.getCol(j)); |
|
76 | 76 |
while (!it.atEnd()) |
77 | 77 |
{ |
78 |
- if (it.getValue() < 1.f) |
|
78 |
+ if (get<1>(it) < 1.f) |
|
79 | 79 |
{ |
80 | 80 |
gaps_printf("\nError: Non-zero values less than 1 detected\n"); |
81 | 81 |
gaps_printf("\n Not allowed when useSparseOptimization is enabled\n"); |
... | ... |
@@ -48,10 +48,10 @@ float gaps::sum(const SparseMatrix &mat) |
48 | 48 |
float sum = 0.f; |
49 | 49 |
for (unsigned j = 0; j < mat.nCol(); ++j) |
50 | 50 |
{ |
51 |
- SparseIterator it(mat.getCol(j)); |
|
51 |
+ SparseIterator<1> it(mat.getCol(j)); |
|
52 | 52 |
while (!it.atEnd()) |
53 | 53 |
{ |
54 |
- sum += it.getValue(); |
|
54 |
+ sum += get<1>(it); |
|
55 | 55 |
it.next(); |
56 | 56 |
} |
57 | 57 |
} |
... | ... |
@@ -92,10 +92,10 @@ float gaps::nonZeroMean(const SparseMatrix &mat) |
92 | 92 |
unsigned nNonZeroes = 0; |
93 | 93 |
for (unsigned j = 0; j < mat.nCol(); ++j) |
94 | 94 |
{ |
95 |
- SparseIterator it(mat.getCol(j)); |
|
95 |
+ SparseIterator<1> it(mat.getCol(j)); |
|
96 | 96 |
while (!it.atEnd()) |
97 | 97 |
{ |
98 |
- sum += it.getValue(); |
|
98 |
+ sum += get<1>(it); |
|
99 | 99 |
++nNonZeroes; |
100 | 100 |
it.next(); |
101 | 101 |
} |
... | ... |
@@ -4,10 +4,19 @@ |
4 | 4 |
|
5 | 5 |
static float dot_helper(const float *v1, const float *v2, unsigned size) |
6 | 6 |
{ |
7 |
- float dot = 0.f; |
|
8 |
- for (unsigned i = 0; i < size; ++i) |
|
7 |
+ gaps::simd::PackedFloat partialDot(0.f), p1, p2; |
|
8 |
+ gaps::simd::Index i(0); |
|
9 |
+ for (; i <= size - gaps::simd::Index::increment(); ++i) |
|
9 | 10 |
{ |
10 |
- dot += v1[i] * v2[i]; |
|
11 |
+ p1.load(v1 + i); |
|
12 |
+ p2.load(v2 + i); |
|
13 |
+ partialDot += p1 * p2; |
|
14 |
+ } |
|
15 |
+ |
|
16 |
+ float dot = partialDot.scalar(); |
|
17 |
+ for (unsigned j = i.value(); j < size; ++j) |
|
18 |
+ { |
|
19 |
+ dot += v1[j] * v2[j]; |
|
11 | 20 |
} |
12 | 21 |
return dot; |
13 | 22 |
} |