SHOGUN  v1.1.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
StreamingVwCacheFile.cpp
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or modify
3  * it under the terms of the GNU General Public License as published by
4  * the Free Software Foundation; either version 3 of the License, or
5  * (at your option) any later version.
6  *
7  * Written (W) 2011 Shashwat Lal Das
8  * Copyright (C) 2011 Berlin Institute of Technology and Max-Planck-Society
9  */
11 
12 using namespace shogun;
13 
15  : CStreamingFile()
16 {
17  init(C_NATIVE);
18 }
19 
21  : CStreamingFile()
22 {
23  init(cache_type);
24 }
25 
27  : CStreamingFile(fname, rw)
28 {
29  init(cache_type);
30 }
31 
33 {
34  SG_UNREF(env);
36 }
37 
39 {
41  len = 1;
42  else
43  len = -1;
44 }
45 
47 {
49  len = 1;
50  else
51  len = -1;
52 }
53 
55 {
56  if (env)
57  SG_UNREF(env);
58 
59  env = env_to_use;
60  SG_REF(env);
61 
63 
64  switch (cache_format)
65  {
66  case C_NATIVE:
68  return;
69  case C_PROTOBUF:
70  SG_ERROR("Protocol buffers cache support is not implemented yet!\n");
71  }
72 
73  SG_ERROR("Unexpected cache type to use for reading!\n");
74 }
75 
77 {
78  buf->reset_file();
79 
80  // Recheck the cache so the parser can directly proceed with the examples
81  if (cache_format == C_NATIVE)
82  ((CVwNativeCacheReader*) cache_reader)->check_cache_metadata();
83 }
84 
85 void CStreamingVwCacheFile::init(EVwCacheType cache_type)
86 {
87  cache_format = cache_type;
88  env = new CVwEnvironment();
89 
90  switch (cache_type)
91  {
92  case C_NATIVE:
94  return;
95  case C_PROTOBUF:
96  SG_ERROR("Protocol buffers cache support is not implemented yet!\n");
97  }
98 
99  SG_ERROR("Unrecognized cache type to read from!\n");
100 }
int working_file
file descriptor
Definition: IOBuffer.h:195
EVwCacheType cache_format
Cache type.
Class CVwNativeCacheReader reads from a cache exactly as that which has been produced by VW's default...
CVwCacheReader * cache_reader
Cache reader.
Class CVwEnvironment is the environment used by VW.
Definition: VwEnvironment.h:39
virtual bool read_cached_example(VwExample *const ae)=0
#define SG_ERROR(...)
Definition: SGIO.h:75
virtual void reset_file()
Definition: IOBuffer.cpp:69
#define SG_REF(x)
Definition: SGObject.h:44
A Streaming File access class.
Definition: StreamingFile.h:38
virtual void get_vector(VwExample *&ex, int32_t &len)
CIOBuffer * buf
Buffer to hold stuff in memory.
double float64_t
Definition: common.h:56
Example class for VW.
Definition: vw_example.h:56
#define SG_UNREF(x)
Definition: SGObject.h:45
void set_env(CVwEnvironment *env_to_use)
virtual void get_vector_and_label(VwExample *&ex, int32_t &len, float64_t &label)
CVwEnvironment * env
Environment used for vw.

SHOGUN Machine Learning Toolbox - Documentation