Permalink
Browse files

expose save_text

  • Loading branch information...
aaalgo committed Mar 16, 2018
1 parent 83e53ea commit 6e097d3cdf38543414e0d5b4528f1763f0a49018
Showing with 25 additions and 1 deletion.
  1. +15 −0 kgraph.cpp
  2. +2 −1 kgraph.h
  3. +8 −0 python/pykgraph.cpp
View
@@ -334,6 +334,21 @@ namespace kgraph {
}
virtual void save (char const *path, int format) const {
if (format == FORMAT_TEXT) {
std::cerr << "Saving to text file; you won't be able to load text file." << std::endl;
ofstream os(path);
os << graph.size() << endl;
for (unsigned i = 0; i < graph.size(); ++i) {
auto const &knn = graph[i];
uint32_t K = knn.size();
os << K;
for (unsigned k = 0; k < K; ++k) {
os << ' ' << knn[k].id << ' ' << knn[k].dist;
}
os << endl;
}
return;
}
ofstream os(path, ios::binary);
uint32_t N = graph.size();
os.write(KGRAPH_MAGIC, KGRAPH_MAGIC_SIZE);
View
@@ -127,7 +127,8 @@ namespace kgraph {
enum {
FORMAT_DEFAULT = 0,
FORMAT_NO_DIST = 1
FORMAT_NO_DIST = 1,
FORMAT_TEXT = 128
};
/// Information and statistics of the indexing algorithm.
View
@@ -269,6 +269,9 @@ namespace {
void save (char const *path) const {
index->save(path);
}
void save_text (char const *path) const {
index->save(path, kgraph::KGraph::FORMAT_TEXT);
}
};
template <typename DATA_TYPE, typename METRIC_TYPE>
@@ -400,6 +403,10 @@ class KGraph {
impl->save(path);
}
void save_text (char const *path) const {
impl->save_text(path);
}
void build (unsigned iterations,
unsigned L,
unsigned K,
@@ -468,6 +475,7 @@ BOOST_PYTHON_MODULE(pykgraph)
// (python::arg("data"), python::arg("metric") = "euclidean")))
.def("load", &KGraph::load)
.def("save", &KGraph::save)
.def("save_text", &KGraph::save_text)
.def("build", &KGraph::build,
(python::arg("data"),
python::arg("iterations") = kgraph::default_iterations,

0 comments on commit 6e097d3

Please sign in to comment.