本文整理汇总了C++中Points::InitializeFromFile方法的典型用法代码示例。如果您正苦于以下问题:C++ Points::InitializeFromFile方法的具体用法?C++ Points::InitializeFromFile怎么用?C++ Points::InitializeFromFile使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Points
的用法示例。
在下文中一共展示了Points::InitializeFromFile方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Format0
/**
* binary to txt
*/
int Format0(int argc, char** argv)
{
assert(argv[1][0] == '0' && argv[1][1] == 0);
if (argc != 6) {
cout
<< "-- For type 0, read txt file and output binary file, [size] and [dimension] is essential"
<< endl;
cout << " " << argv[0] << " 0 txt_file_in binary_file_out size dimension"
<< endl;
return -1;
}
int size = atoi(argv[4]);
int dimension = atoi(argv[5]);
Points<DefaultDataTypes> points;
points.InitializeFromFile(argv[2], size, dimension);
points.SavePoints(argv[3]);
return 0;
}
示例2: main
int main(int argc, char** argv)
{
typedef typename DefaultDataTypes::Value ValueType;
typedef typename DefaultDataTypes::Dist DistType;
typedef typename DefaultDataTypes::Index IndexType;
typedef typename DefaultDataTypes::Dim DimType;
const size_t BitLength = DefaultHashTypes::BitLength;
if (argc < 2) {
cout << "Usage: " << argv[0]
<< " config_file_name [config_key=config_value ...]" << endl;
return -1;
}
//load config from config file
Config config(argv[1]);
//load config from argv, note that this may override the key_value of the original
for (int i = 2; i < argc; i++) {
string k_v(argv[i]);
size_t pos = k_v.find("=");
if (pos == string::npos) {
cout << "Unrecognized arg:" << k_v << endl;
cout << "Usage: " << argv[0]
<< " config_file_name [config_key=config_value ...]" << endl;
return -1;
} else {
string key = k_v.substr(0, pos);
string value = k_v.substr(pos + 1);
config.Add(key, value);
}
}
if (config.Read<bool>(kShowConfigKey)) {
cout << "==============config content=============" << endl;
cout << config;
cout << "=========================================" << endl;
}
#ifdef NNPLUS_DEBUG
std::cout << "DEBUG mode on" << std::endl;
#else
std::cout << "DEBUG mode off" << std::endl;
#endif
#ifdef USE_PARALLELIZATION
//control threads used in the whole program
int open_MPI_threads = config.Read<int>(kOpenMPIThreadsNumKey);
if (open_MPI_threads != -1 && open_MPI_threads > 0) {
omp_set_num_threads(open_MPI_threads);
cout << "omp_set_num_threads:" << open_MPI_threads << endl;
} else {
cout << "use default omp_threads" << endl;
}
#endif
unsigned int random_seed = config.Read<unsigned int>(kRandomSeedKey);
srand(random_seed);
Stopwatch timer("");
timer.Reset();
timer.Start();
bool data_format_binary_flag = config.Read<bool>(kDataFormatBinaryKey);
Points<DefaultDataTypes> dps;
string input_data_file_name = config.Read<string>(kDataFileNameKey);
if (data_format_binary_flag) {
dps.LoadPoints(input_data_file_name.c_str());
} else {
dps.InitializeFromFile(input_data_file_name.c_str(),
config.Read<IndexType>(kTextDataSizeKey),
config.Read<DimType>(kTextDataDimKey));
}
Points<DefaultDataTypes> qps;
string input_query_file_name = config.Read<string>(kQueryFileNameKey);
if (data_format_binary_flag) {
qps.LoadPoints(input_query_file_name.c_str());
} else {
qps.InitializeFromFile(input_query_file_name.c_str(),
config.Read<IndexType>(kTextQuerySizeKey),
config.Read<DimType>(kTextQueryDimKey));
}
assert(dps.dim_ == qps.dim_);
cout << "- Reading Data Finished (" << timer.GetTime() << " seconds)" << endl;
// check expansion and save kg_load time
SearchEngine<DefaultHashTypes, DefaultDataTypes>::BuildParams bp;
string search_algorithm = config.Read<string>(kSearchAlgorithm);
if (search_algorithm == "HashHKM") {
bp.algorithm = SearchEngine<DefaultHashTypes, DefaultDataTypes>::HashHKM;
bp.forest_size = config.Read<size_t>(kForestTreeCountKey);
bp.tree_height = config.Read<size_t>(kTreeHeightKey);
bp.branches = config.ReadVector<size_t>(kTreeBranchesKey);
} else if (search_algorithm == "HGNNS") {
bp.algorithm = SearchEngine<DefaultHashTypes, DefaultDataTypes>::HGNNS;
bp.k_neighbor = config.Read<size_t>(kKnnGraphNeighborKey);
bp.forest_size = config.Read<size_t>(kForestTreeCountKey);
bp.tree_height = config.Read<size_t>(kTreeHeightKey);
bp.branches = config.ReadVector<size_t>(kTreeBranchesKey);
bp.keep_branches = config.ReadVector<size_t>(kKeepBranchesKey);
bp.hamming_keep_branches = config.ReadVector<size_t>(
//.........这里部分代码省略.........
示例3: main
int main(int argc, char** argv)
{
typedef typename DefaultDataTypes::Value ValueType;
typedef typename DefaultDataTypes::Dist DistType;
typedef typename DefaultDataTypes::Index IndexType;
typedef typename DefaultDataTypes::Dim DimType;
if (argc < 2) {
cout << "Usage: " << argv[0]
<< " config_file_name [config_key=config_value ...]" << endl;
return -1;
}
//load config from config file
Config config(argv[1]);
//load config from argv, note that this may override the key_value of the original
for (int i = 2; i < argc; i++) {
string k_v(argv[i]);
size_t pos = k_v.find("=");
if (pos == string::npos) {
cout << "Unrecognized arg:" << k_v << endl;
cout << "Usage: " << argv[0]
<< " config_file_name [config_key=config_value ...]" << endl;
return -1;
} else {
string key = k_v.substr(0, pos);
string value = k_v.substr(pos + 1);
config.Add(key, value);
}
}
if (config.Read<bool>(kShowConfigKey)) {
cout << "==============config content=============" << endl;
cout << config;
cout << "=========================================" << endl;
}
unsigned int random_seed = config.Read<unsigned int>(kRandomSeedKey);
srand(random_seed);
Stopwatch timer("");
timer.Reset();
timer.Start();
Points<DefaultDataTypes> dps;
string input_data_file_name = config.Read<string>(kDataFileNameKey);
bool data_format_binary_flag = config.Read<bool>(kDataFormatBinaryKey);
if (data_format_binary_flag) {
dps.LoadPoints(input_data_file_name.c_str());
} else {
dps.InitializeFromFile(input_data_file_name.c_str(),
config.Read<IndexType>(kTextDataSizeKey),
config.Read<DimType>(kTextDataDimKey));
}
Points<DefaultDataTypes> qps;
string input_query_file_name = config.Read<string>(kQueryFileNameKey);
if (data_format_binary_flag) {
qps.LoadPoints(input_query_file_name.c_str());
} else {
qps.InitializeFromFile(input_query_file_name.c_str(),
config.Read<IndexType>(kTextQuerySizeKey),
config.Read<DimType>(kTextQueryDimKey));
}
assert(dps.dim_ == qps.dim_);
cout << "- Reading Data Finished (" << timer.GetTime() << " seconds)" << endl;
if (config.Read<bool>(kSavePointsKey)) {
cout << "Saving data points to "
<< config.Read<string>(kSaveDataPointsFileName) << endl;
dps.SavePoints(config.Read<string>(kSaveDataPointsFileName).c_str());
cout << "Saving query points to "
<< config.Read<string>(kSaveQueryPointsFileName) << endl;
qps.SavePoints(config.Read<string>(kSaveQueryPointsFileName).c_str());
}
size_t knn = config.Read<size_t>(kNearKey);
timer.Reset();
timer.Start();
// load ground truth
Groundtruth<DefaultDataTypes> groundtruth;
groundtruth.Initialize(dps, qps, knn,
&ComputeEuclideanDistance<ValueType, DistType>);
string gt_file_name_prefix = config.Read<string>(
kGroundtruthFileNamePrefixKey);
const size_t kMaxFileNameLength = 256;
char gt_file_name[kMaxFileNameLength];
sprintf(gt_file_name, "%s_d%d_q%d_k%d", gt_file_name_prefix.c_str(),
(int) dps.size_, (int) qps.size_, (int) knn);
FILE *gt_file = fopen(gt_file_name, "rb");
if (gt_file != NULL) {
std::cout << "-- Groundtruth file exists, " << gt_file_name << std::endl;
std::cout << "-- Loading Groundtruth ..." << std::endl;
groundtruth.Load(gt_file);
fclose(gt_file);
} else {
std::cout << "-- Groundtruth file not exists, " << gt_file_name
<< std::endl;
//.........这里部分代码省略.........