本文整理汇总了C++中CIOBuffer::read_file方法的典型用法代码示例。如果您正苦于以下问题:C++ CIOBuffer::read_file方法的具体用法?C++ CIOBuffer::read_file怎么用?C++ CIOBuffer::read_file使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CIOBuffer
的用法示例。
在下文中一共展示了CIOBuffer::read_file方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: load_regressor
void CVwRegressor::load_regressor(char* file)
{
CIOBuffer source;
int32_t fd = source.open_file(file, 'r');
if (fd < 0)
SG_SERROR("Unable to open file for loading regressor!\n")
// Read version info
vw_size_t v_length;
source.read_file((char*)&v_length, sizeof(v_length));
char* t = SG_MALLOC(char, v_length);
source.read_file(t,v_length);
if (strcmp(t,env->vw_version) != 0)
{
SG_FREE(t);
SG_SERROR("Regressor source has an incompatible VW version!\n")
}
示例2: load_regressor
void CVwRegressor::load_regressor(char* file)
{
CIOBuffer source;
int32_t fd = source.open_file(file, 'r');
if (fd < 0)
SG_SERROR("Unable to open file for loading regressor!\n");
// Read version info
size_t v_length;
source.read_file((char*)&v_length, sizeof(v_length));
char t[v_length];
source.read_file(t,v_length);
if (strcmp(t,env->vw_version) != 0)
SG_SERROR("Regressor source has an incompatible VW version!\n");
// Read min and max label
source.read_file((char*)&env->min_label, sizeof(env->min_label));
source.read_file((char*)&env->max_label, sizeof(env->max_label));
// Read num_bits, multiple sources are not supported
size_t local_num_bits;
source.read_file((char *)&local_num_bits, sizeof(local_num_bits));
if ((size_t) env->num_bits != local_num_bits)
SG_SERROR("Wrong number of bits in regressor source!\n");
env->num_bits = local_num_bits;
size_t local_thread_bits;
source.read_file((char*)&local_thread_bits, sizeof(local_thread_bits));
env->thread_bits = local_thread_bits;
int32_t len;
source.read_file((char *)&len, sizeof(len));
// Read paired namespace information
DynArray<char*> local_pairs;
for (; len > 0; len--)
{
char pair[3];
source.read_file(pair, sizeof(char)*2);
pair[2]='\0';
local_pairs.push_back(pair);
}
env->pairs = local_pairs;
// Initialize the weight vector
if (weight_vectors)
SG_FREE(weight_vectors);
init(env);
size_t local_ngram;
source.read_file((char*)&local_ngram, sizeof(local_ngram));
size_t local_skips;
source.read_file((char*)&local_skips, sizeof(local_skips));
env->ngram = local_ngram;
env->skips = local_skips;
// Read individual weights
size_t stride = env->stride;
while (true)
{
uint32_t hash;
ssize_t hash_bytes = source.read_file((char *)&hash, sizeof(hash));
if (hash_bytes <= 0)
break;
float32_t w = 0.;
ssize_t weight_bytes = source.read_file((char *)&w, sizeof(float32_t));
if (weight_bytes <= 0)
break;
size_t num_threads = env->num_threads();
weight_vectors[hash % num_threads][(hash*stride)/num_threads]
= weight_vectors[hash % num_threads][(hash*stride)/num_threads] + w;
}
source.close_file();
}