Vowpal Wabbit
vw_slim_predict.cc
Go to the documentation of this file.
1 #include "vw_slim_predict.h"
2 
3 #include <cctype>
4 #include <algorithm>
5 
6 namespace vw_slim
7 {
8 uint64_t ceil_log_2(uint64_t v)
9 {
10  if (v == 0)
11  return 0;
12  else
13  return 1 + ceil_log_2(v >> 1);
14 }
15 
16 namespace_copy_guard::namespace_copy_guard(example_predict& ex, unsigned char ns) : _ex(ex), _ns(ns)
17 {
18  if (std::end(_ex.indices) == std::find(std::begin(_ex.indices), std::end(_ex.indices), ns))
19  {
21  _remove_ns = true;
22  }
23  else
24  _remove_ns = false;
25 }
26 
28 {
29  _ex.indices.pop();
30  if (_remove_ns)
31  _ex.feature_space[_ns].clear();
32 }
33 
35 {
36  _ex.feature_space[_ns].push_back(v, idx);
37 }
38 
40  : _ex(ex), _old_ft_offset(ex.ft_offset)
41 {
42  _ex.ft_offset = ft_offset;
43 }
44 
46 
47 stride_shift_guard::stride_shift_guard(example_predict& ex, uint64_t shift) : _ex(ex), _shift(shift)
48 {
49  if (_shift > 0)
50  for (auto ns : _ex.indices)
51  for (auto& f : _ex.feature_space[ns]) f.index() <<= _shift;
52 }
53 
55 {
56  if (_shift > 0)
57  for (auto ns : _ex.indices)
58  for (auto& f : _ex.feature_space[ns]) f.index() >>= _shift;
59 }
60 
61 }; // namespace vw_slim
namespace_copy_guard(example_predict &ex, unsigned char ns)
v_array< namespace_index > indices
T pop()
Definition: v_array.h:58
float feature_value
Definition: feature_group.h:20
void feature_push_back(feature_value v, feature_index idx)
stride_shift_guard(example_predict &ex, uint64_t shift)
std::array< features, NUM_NAMESPACES > feature_space
void push_back(const T &new_ele)
Definition: v_array.h:107
feature_offset_guard(example_predict &ex, uint64_t ft_offset)
uint64_t feature_index
Definition: feature_group.h:21
node_pred * find(recall_tree &b, uint32_t cn, example &ec)
Definition: recall_tree.cc:126
uint64_t ceil_log_2(uint64_t v)
float f
Definition: cache.cc:40