summaryrefslogtreecommitdiff
path: root/utils/fast_sparse_vector.h
diff options
context:
space:
mode:
authorChris Dyer <cdyer@cs.cmu.edu>2012-05-13 16:18:43 -0700
committerChris Dyer <cdyer@cs.cmu.edu>2012-05-13 16:18:43 -0700
commitb56da6f08c4f59b562a102671ac3deb135b0538a (patch)
treee97badb0a2e8c4ceff9468bcbc0d9458f935381c /utils/fast_sparse_vector.h
parent5d2fba19f7989b8a2c55834a5735f5fd5b60197c (diff)
fast creg training code for univariate linear and logistic regression
Diffstat (limited to 'utils/fast_sparse_vector.h')
-rw-r--r--utils/fast_sparse_vector.h16
1 files changed, 13 insertions, 3 deletions
diff --git a/utils/fast_sparse_vector.h b/utils/fast_sparse_vector.h
index af832950..68caa704 100644
--- a/utils/fast_sparse_vector.h
+++ b/utils/fast_sparse_vector.h
@@ -7,8 +7,6 @@
// important: indexes are integers
// important: iterators may return elements in any order
-#include "config.h"
-
#include <cmath>
#include <cstring>
#include <climits>
@@ -16,8 +14,9 @@
#include <cassert>
#include <vector>
-#include <boost/static_assert.hpp>
+#include "config.h"
+#include <boost/static_assert.hpp>
#if HAVE_BOOST_ARCHIVE_TEXT_OARCHIVE_HPP
#include <boost/serialization/map.hpp>
#endif
@@ -119,6 +118,17 @@ class FastSparseVector {
std::memcpy(this, &other, sizeof(FastSparseVector));
if (is_remote_) data_.rbmap = new std::map<int, T>(*data_.rbmap);
}
+ FastSparseVector(std::pair<int, T>* first, std::pair<int, T>* last) {
+ const ptrdiff_t n = last - first;
+ if (n <= LOCAL_MAX) {
+ is_remote_ = false;
+ local_size_ = n;
+ std::memcpy(data_.local, first, sizeof(std::pair<int, T>) * n);
+ } else {
+ is_remote_ = true;
+ data_.rbmap = new std::map<int, T>(first, last);
+ }
+ }
void erase(int k) {
if (is_remote_) {
data_.rbmap->erase(k);