SHOGUN
v2.0.0
Main Page
Related Pages
Modules
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Groups
Pages
src
shogun
io
streaming
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
*/
10
#include <
shogun/io/streaming/StreamingVwCacheFile.h
>
11
12
using namespace
shogun;
13
14
CStreamingVwCacheFile::CStreamingVwCacheFile
()
15
:
CStreamingFile
()
16
{
17
init(
C_NATIVE
);
18
}
19
20
CStreamingVwCacheFile::CStreamingVwCacheFile
(
EVwCacheType
cache_type)
21
:
CStreamingFile
()
22
{
23
init(cache_type);
24
}
25
26
CStreamingVwCacheFile::CStreamingVwCacheFile
(
char
* fname,
char
rw,
EVwCacheType
cache_type)
27
:
CStreamingFile
(fname, rw)
28
{
29
init(cache_type);
30
}
31
32
CStreamingVwCacheFile::~CStreamingVwCacheFile
()
33
{
34
SG_UNREF
(
env
);
35
SG_UNREF
(
cache_reader
);
36
}
37
38
void
CStreamingVwCacheFile::get_vector
(
VwExample
* &ex, int32_t& len)
39
{
40
if
(
cache_reader
->
read_cached_example
(ex))
41
len = 1;
42
else
43
len = -1;
44
}
45
46
void
CStreamingVwCacheFile::get_vector_and_label
(
VwExample
* &ex, int32_t &len,
float64_t
&label)
47
{
48
if
(
cache_reader
->
read_cached_example
(ex))
49
len = 1;
50
else
51
len = -1;
52
}
53
54
void
CStreamingVwCacheFile::set_env
(
CVwEnvironment
* env_to_use)
55
{
56
if
(
env
)
57
SG_UNREF
(
env
);
58
59
env
= env_to_use;
60
SG_REF
(
env
);
61
62
SG_UNREF
(
cache_reader
);
63
64
switch
(
cache_format
)
65
{
66
case
C_NATIVE
:
67
cache_reader
=
new
CVwNativeCacheReader
(
buf
->
working_file
,
env
);
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
76
void
CStreamingVwCacheFile::reset_stream
()
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
:
93
cache_reader
=
new
CVwNativeCacheReader
(
buf
->
working_file
,
env
);
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
}
SHOGUN
Machine Learning Toolbox - Documentation