SHOGUN
3.2.1
首页
相关页面
模块
类
文件
文件列表
文件成员
全部
类
命名空间
文件
函数
变量
类型定义
枚举
枚举值
友元
宏定义
组
页
src
shogun
io
streaming
StreamingVwCacheFile.cpp
浏览该文件的文档.
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
buf
=NULL;
18
init(
C_NATIVE
);
19
}
20
21
CStreamingVwCacheFile::CStreamingVwCacheFile
(
EVwCacheType
cache_type)
22
:
CStreamingFile
()
23
{
24
init(cache_type);
25
}
26
27
CStreamingVwCacheFile::CStreamingVwCacheFile
(
char
* fname,
char
rw,
EVwCacheType
cache_type)
28
:
CStreamingFile
(fname, rw)
29
{
30
init(cache_type);
31
}
32
33
CStreamingVwCacheFile::~CStreamingVwCacheFile
()
34
{
35
SG_UNREF
(
env
);
36
SG_UNREF
(
cache_reader
);
37
}
38
39
void
CStreamingVwCacheFile::get_vector
(
VwExample
* &ex, int32_t& len)
40
{
41
if
(
cache_reader
->
read_cached_example
(ex))
42
len = 1;
43
else
44
len = -1;
45
}
46
47
void
CStreamingVwCacheFile::get_vector_and_label
(
VwExample
* &ex, int32_t &len,
float64_t
&label)
48
{
49
if
(
cache_reader
->
read_cached_example
(ex))
50
len = 1;
51
else
52
len = -1;
53
}
54
55
void
CStreamingVwCacheFile::set_env
(
CVwEnvironment
* env_to_use)
56
{
57
SG_REF
(env_to_use);
58
SG_UNREF
(
env
);
59
env
= env_to_use;
60
61
SG_UNREF
(
cache_reader
);
62
63
switch
(
cache_format
)
64
{
65
case
C_NATIVE
:
66
cache_reader
=
new
CVwNativeCacheReader
(
buf
->
working_file
,
env
);
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
75
void
CStreamingVwCacheFile::reset_stream
()
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
)
93
cache_reader
=
new
CVwNativeCacheReader
(
buf
->
working_file
,
env
);
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
}
SHOGUN
机器学习工具包 - 项目文档