SHOGUN  4.1.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules 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  buf=NULL;
18  init(C_NATIVE);
19 }
20 
22  : CStreamingFile()
23 {
24  init(cache_type);
25 }
26 
28  : CStreamingFile(fname, rw)
29 {
30  init(cache_type);
31 }
32 
34 {
35  SG_UNREF(env);
37 }
38 
40 {
42  len = 1;
43  else
44  len = -1;
45 }
46 
48 {
50  len = 1;
51  else
52  len = -1;
53 }
54 
56 {
57  SG_REF(env_to_use);
58  SG_UNREF(env);
59  env = env_to_use;
60 
62 
63  switch (cache_format)
64  {
65  case C_NATIVE:
67  return;
68  case C_PROTOBUF:
69  SG_ERROR("Protocol buffers cache support is not implemented yet!\n")
70  }
71 
72  SG_ERROR("Unexpected cache type to use for reading!\n")
73 }
74 
76 {
77  buf->reset_file();
78 
79  // Recheck the cache so the parser can directly proceed with the examples
80  if (cache_format == C_NATIVE)
81  ((CVwNativeCacheReader*) cache_reader)->check_cache_metadata();
82 }
83 
84 void CStreamingVwCacheFile::init(EVwCacheType cache_type)
85 {
86  cache_format = cache_type;
87  env = new CVwEnvironment();
88 
89  switch (cache_type)
90  {
91  case C_NATIVE:
92  if (buf)
94  else
95  cache_reader=NULL;
96  return;
97  case C_PROTOBUF:
98  SG_ERROR("Protocol buffers cache support is not implemented yet!\n")
99  }
100 
101  SG_ERROR("Unrecognized cache type to read from!\n")
102 }
int working_file
file descriptor
Definition: IOBuffer.h:192
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:41
virtual bool read_cached_example(VwExample *const ae)=0
#define SG_ERROR(...)
Definition: SGIO.h:129
virtual void reset_file()
Definition: IOBuffer.cpp:75
#define SG_REF(x)
Definition: SGObject.h:51
A Streaming File access class.
Definition: StreamingFile.h:34
virtual void get_vector(VwExample *&ex, int32_t &len)
CIOBuffer * buf
Buffer to hold stuff in memory.
double float64_t
Definition: common.h:50
Example class for VW.
Definition: vw_example.h:58
#define SG_UNREF(x)
Definition: SGObject.h:52
all of classes and functions are contained in the shogun namespace
Definition: class_list.h:18
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