From 69b0bf8d618338c82fda17878defff77fb35a69f Mon Sep 17 00:00:00 2001 From: Chris Dyer Date: Sun, 13 May 2012 16:18:43 -0700 Subject: fast creg training code for univariate linear and logistic regression --- utils/fast_sparse_vector.h | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'utils/fast_sparse_vector.h') 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 #include #include @@ -16,8 +14,9 @@ #include #include -#include +#include "config.h" +#include #if HAVE_BOOST_ARCHIVE_TEXT_OARCHIVE_HPP #include #endif @@ -119,6 +118,17 @@ class FastSparseVector { std::memcpy(this, &other, sizeof(FastSparseVector)); if (is_remote_) data_.rbmap = new std::map(*data_.rbmap); } + FastSparseVector(std::pair* first, std::pair* 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) * n); + } else { + is_remote_ = true; + data_.rbmap = new std::map(first, last); + } + } void erase(int k) { if (is_remote_) { data_.rbmap->erase(k); -- cgit v1.2.3