Vowpal Wabbit
Classes | Namespaces | Typedefs | Enumerations | Functions
global_data.h File Reference
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <cfloat>
#include <stdint.h>
#include <cstdio>
#include <inttypes.h>
#include <climits>
#include <stack>
#include <array>
#include <thread>
#include "v_array.h"
#include "array_parameters.h"
#include "parse_primitives.h"
#include "loss_functions.h"
#include "comp_io.h"
#include "example.h"
#include "config.h"
#include "learner.h"
#include "v_hashmap.h"
#include <time.h>
#include "hash.h"
#include "crossplat_compat.h"
#include "error_reporting.h"
#include "constant.h"
#include "rand48.h"
#include "options.h"
#include "version.h"
#include <memory>

Go to the source code of this file.

Classes

struct  dictionary_info
 
class  namedlabels
 
struct  shared_data
 
struct  rand_state
 
struct  vw
 

Namespaces

 label_type
 

Typedefs

typedef float weight
 
typedef v_hashmap< substring, features * > feature_dict
 

Enumerations

enum  AllReduceType { Socket, Thread }
 
enum  label_type::label_type_t {
  label_type::simple, label_type::cb, label_type::cb_eval, label_type::cs,
  label_type::multi, label_type::mc, label_type::ccb
}
 

Functions

void deleter (substring ss, uint64_t)
 
void print_result (int f, float res, float weight, v_array< char > tag)
 
void binary_print_result (int f, float res, float weight, v_array< char > tag)
 
void noop_mm (shared_data *, float label)
 
void get_prediction (int sock, float &res, float &weight)
 
void compile_gram (std::vector< std::string > grams, std::array< uint32_t, NUM_NAMESPACES > &dest, char *descriptor, bool quiet)
 
void compile_limits (std::vector< std::string > limits, std::array< uint32_t, NUM_NAMESPACES > &dest, bool quiet)
 
int print_tag (std::stringstream &ss, v_array< char > tag)
 

Typedef Documentation

◆ feature_dict

Definition at line 53 of file global_data.h.

◆ weight

typedef float weight

Definition at line 51 of file global_data.h.

Enumeration Type Documentation

◆ AllReduceType

Enumerator
Socket 
Thread 

Definition at line 332 of file global_data.h.

333 {
334  Socket,
335  Thread
336 };

Function Documentation

◆ binary_print_result()

void binary_print_result ( int  f,
float  res,
float  weight,
v_array< char >  tag 
)

Definition at line 72 of file global_data.cc.

References send_prediction().

Referenced by enable_sources(), vw::get_random_state(), and reset_source().

73 {
74  if (f >= 0)
75  {
76  global_prediction ps = {res, weight};
77  send_prediction(f, ps);
78  }
79 }
float weight
void send_prediction(int sock, global_prediction p)
Definition: global_data.cc:60
float f
Definition: cache.cc:40

◆ compile_gram()

void compile_gram ( std::vector< std::string >  grams,
std::array< uint32_t, NUM_NAMESPACES > &  dest,
char *  descriptor,
bool  quiet 
)

Definition at line 191 of file global_data.cc.

Referenced by vw::get_random_state(), and parse_feature_tweaks().

193 {
194  for (size_t i = 0; i < grams.size(); i++)
195  {
196  std::string ngram = grams[i];
197  if (isdigit(ngram[0]))
198  {
199  int n = atoi(ngram.c_str());
200  if (!quiet)
201  std::cerr << "Generating " << n << "-" << descriptor << " for all namespaces." << std::endl;
202  for (size_t j = 0; j < 256; j++) dest[j] = n;
203  }
204  else if (ngram.size() == 1)
205  std::cout << "You must specify the namespace index before the n" << std::endl;
206  else
207  {
208  int n = atoi(ngram.c_str() + 1);
209  dest[(uint32_t)(unsigned char)*ngram.c_str()] = n;
210  if (!quiet)
211  std::cerr << "Generating " << n << "-" << descriptor << " for " << ngram[0] << " namespaces." << std::endl;
212  }
213  }
214 }

◆ compile_limits()

void compile_limits ( std::vector< std::string >  limits,
std::array< uint32_t, NUM_NAMESPACES > &  dest,
bool  quiet 
)

Definition at line 216 of file global_data.cc.

Referenced by vw::get_random_state(), and parse_feature_tweaks().

217 {
218  for (size_t i = 0; i < limits.size(); i++)
219  {
220  std::string limit = limits[i];
221  if (isdigit(limit[0]))
222  {
223  int n = atoi(limit.c_str());
224  if (!quiet)
225  std::cerr << "limiting to " << n << "features for each namespace." << std::endl;
226  for (size_t j = 0; j < 256; j++) dest[j] = n;
227  }
228  else if (limit.size() == 1)
229  std::cout << "You must specify the namespace index before the n" << std::endl;
230  else
231  {
232  int n = atoi(limit.c_str() + 1);
233  dest[(uint32_t)limit[0]] = n;
234  if (!quiet)
235  std::cerr << "limiting to " << n << " for namespaces " << limit[0] << std::endl;
236  }
237  }
238 }

◆ deleter()

void deleter ( substring  ss,
uint64_t   
)
inline

Definition at line 62 of file global_data.h.

References substring::begin, and free_it().

Referenced by namedlabels::~namedlabels().

62 { free_it(ss.begin); }
char * begin
Definition: hashstring.h:9
void free_it(void *ptr)
Definition: memory.h:94

◆ get_prediction()

void get_prediction ( int  sock,
float &  res,
float &  weight 
)

Definition at line 52 of file global_data.cc.

References global_prediction::p, really_read(), and global_prediction::weight.

Referenced by vw::get_random_state().

53 {
55  really_read(sock, &p, sizeof(p));
56  res = p.p;
57  weight = p.weight;
58 }
float weight
size_t really_read(int sock, void *in, size_t count)
Definition: global_data.cc:24

◆ noop_mm()

void noop_mm ( shared_data ,
float  label 
)

◆ print_result()

void print_result ( int  f,
float  res,
float  weight,
v_array< char >  tag 
)

Definition at line 91 of file global_data.cc.

References print_tag(), and io_buf::write_file_or_socket().

Referenced by vw::get_random_state(), and vw::vw().

92 {
93  if (f >= 0)
94  {
95  std::stringstream ss;
96  auto saved_precision = ss.precision();
97  if (floorf(res) == res)
98  ss << std::setprecision(0);
99  ss << std::fixed << res << std::setprecision(saved_precision);
100  print_tag(ss, tag);
101  ss << '\n';
102  ssize_t len = ss.str().size();
103  ssize_t t = io_buf::write_file_or_socket(f, ss.str().c_str(), (unsigned int)len);
104  if (t != len)
105  {
106  std::cerr << "write error: " << strerror(errno) << std::endl;
107  }
108  }
109 }
static ssize_t write_file_or_socket(int f, const void *buf, size_t nbytes)
Definition: io_buf.cc:140
int print_tag(std::stringstream &ss, v_array< char > tag)
Definition: global_data.cc:81
float f
Definition: cache.cc:40

◆ print_tag()

int print_tag ( std::stringstream &  ss,
v_array< char >  tag 
)

Definition at line 81 of file global_data.cc.

References v_array< T >::begin(), v_array< T >::end(), and v_array< T >::size().

Referenced by active_print_result(), confidence_print_result(), vw::get_random_state(), ACTION_SCORE::print_action_score(), print_raw_text(), and print_result().

82 {
83  if (tag.begin() != tag.end())
84  {
85  ss << ' ';
86  ss.write(tag.begin(), sizeof(char) * tag.size());
87  }
88  return tag.begin() != tag.end();
89 }
T *& begin()
Definition: v_array.h:42
size_t size() const
Definition: v_array.h:68
T *& end()
Definition: v_array.h:43