SHOGUN  6.0.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules
VwNativeCacheReader.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2009 Yahoo! Inc. All rights reserved. The copyrights
3  * embodied in the content of this file are licensed under the BSD
4  * (revised) open source license.
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * Written (W) 2011 Shashwat Lal Das
12  * Adaptation of Vowpal Wabbit v5.1.
13  * Copyright (C) 2011 Berlin Institute of Technology and Max-Planck-Society.
14  */
15 
16 #ifndef _VW_NATIVECACHE_READ_H__
17 #define _VW_NATIVECACHE_READ_H__
18 
20 
21 namespace shogun
22 {
23 
24 #ifndef DOXYGEN_SHOULD_SKIP_THIS
25 #ifdef __GNUC__
26 #define PACKED( class_to_pack ) class_to_pack __attribute__((__packed__))
27 #else
28 #define PACKED( class_to_pack ) __pragma( pack(push, 1) ) class_to_pack __pragma( pack(pop) )
29 #endif
30 
31 // Packed structure for efficient storage
32 PACKED(
33 struct one_float
34 {
35  // The float to store
36  float32_t f;
37 }
38 );
39 
40 #endif // DOXYGEN_SHOULD_SKIP_THIS
41 
48 {
49 public:
54 
61  CVwNativeCacheReader(char * fname, CVwEnvironment* env_to_use);
62 
69  CVwNativeCacheReader(int32_t f, CVwEnvironment* env_to_use);
70 
74  virtual ~CVwNativeCacheReader();
75 
81  virtual void set_file(int32_t f);
82 
88  virtual bool read_cached_example(VwExample* const ae);
89 
93  void check_cache_metadata();
94 
100  virtual const char* get_name() const { return "VwNativeCacheReader"; }
101 
102 private:
106  void init();
107 
116  char* run_len_decode(char *p, vw_size_t& i);
117 
125  inline int32_t ZigZagDecode(uint32_t n)
126  {
127  return (n >> 1) ^ -static_cast<int32_t>(n & 1);
128  }
129 
138  char* bufread_label(VwLabel* const ld, char* c);
139 
147  vw_size_t read_cached_label(VwLabel* const ld);
148 
156  vw_size_t read_cached_tag(VwExample* const ae);
157 
158 
159 protected:
162 
163 private:
164  // Used while parsing
165  const vw_size_t char_size;
166  vw_size_t neg_1;
167  vw_size_t general;
168 };
169 
170 }
171 #endif // _VW_NATIVECACHE_READ_H__
An I/O buffer class.
Definition: IOBuffer.h:41
uint32_t vw_size_t
vw_size_t typedef to work across platforms
Definition: vw_constants.h:26
Class CVwNativeCacheReader reads from a cache exactly as that which has been produced by VW's default...
CIOBuffer buf
Buffer to read from.
Base class from which all cache readers for VW should be derived.
Definition: VwCacheReader.h:43
Class CVwEnvironment is the environment used by VW.
Definition: VwEnvironment.h:41
virtual void set_file(int32_t f)
Example class for VW.
Definition: vw_example.h:58
float float32_t
Definition: common.h:59
all of classes and functions are contained in the shogun namespace
Definition: class_list.h:18
virtual bool read_cached_example(VwExample *const ae)
virtual const char * get_name() const

SHOGUN Machine Learning Toolbox - Documentation