Skip to content

Commit

Permalink
(DNND) Clean up examples
Browse files Browse the repository at this point in the history
  • Loading branch information
Keita Iwabuchi committed Sep 5, 2024
1 parent 92d4fef commit 1f134f6
Show file tree
Hide file tree
Showing 12 changed files with 66 additions and 967 deletions.
9 changes: 5 additions & 4 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,17 @@ function(add_saltatlas_dnnd_example_feature_type example_name type_name)
PRIVATE "SALTATLAS_DNND_EXAMPLE_FEATURE_ELEMENT_TYPE=${type_name}")
endfunction()

add_saltatlas_example(dnnd_simple_example)
add_saltatlas_example(dnnd_simple_custom_distance_example)
add_saltatlas_example(dnnd_simple_custom_point_example)
add_saltatlas_example(dnnd_simple)
add_saltatlas_example(dnnd_simple_custom_distance)
add_saltatlas_example(dnnd_simple_custom_point)
add_saltatlas_example(dnnd_levenshtein)

add_saltatlas_dnnd_example_feature_type(dnnd_bench float)
add_saltatlas_dnnd_example_feature_type(dnnd_bench uint8_t)
add_saltatlas_dnnd_example_feature_type(dnnd_bench double)

if (SALTATLAS_USE_METALL)
add_saltatlas_example(dnnd_advanced_example)
add_saltatlas_example(dnnd_advanced)
endif ()

add_subdirectory(datasets)
File renamed without changes.
95 changes: 0 additions & 95 deletions examples/dnnd_custom_point_example.cpp

This file was deleted.

73 changes: 0 additions & 73 deletions examples/dnnd_example.cpp

This file was deleted.

61 changes: 61 additions & 0 deletions examples/dnnd_levenshtein.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// Copyright 2020-2024 Lawrence Livermore National Security, LLC and other
// saltatlas Project Developers. See the top-level COPYRIGHT file for details.
//
// SPDX-License-Identifier: MIT

// Usage:
// cd saltatlas/build
// mpirun -n 2 ./examples/dnnd_example

#include <iostream>
#include <string>
#include <vector>

#include <ygm/comm.hpp>
#include <ygm/utility.hpp>

#include <saltatlas/dnnd/dnnd_simple.hpp>
#include <saltatlas/dnnd/utility.hpp>

using id_type = uint32_t;
using dist_t = float;
using point_type = saltatlas::feature_vector<char>;

int main(int argc, char **argv) {
ygm::comm comm(&argc, &argv);

std::vector<std::filesystem::path> point_file_paths{
"../examples/datasets/point_string.txt"};
std::filesystem::path query_file_path{
"../examples/datasets/query_string.txt"};
std::filesystem::path ground_truth_file_path{
"../examples/datasets/ground-truth_string.txt"};
std::filesystem::path query_result_file_path{"query-results"};

saltatlas::dnnd<id_t, point_type, dist_t> g(
saltatlas::distance::id::levenshtein, comm);

comm.cout0() << "<<Read Points>>" << std::endl;
g.load_points(point_file_paths.begin(), point_file_paths.end(), "wsv");

comm.cout0() << "<<Index Construction>>" << std::endl;
int index_k{2};
g.build(index_k);

comm.cout0() << "<<Optimizing the index for query>>" << std::endl;
bool make_graph_undirected = true;
g.optimize(make_graph_undirected);

comm.cout0() << "<<Query>>" << std::endl;
int num_to_search{3};
std::vector<point_type> queries;
saltatlas::read_query(query_file_path, queries, comm);

const auto results = g.query(queries.begin(), queries.end(), num_to_search);
comm.cout0() << "Dumping query results to " << query_result_file_path
<< std::endl;
saltatlas::utility::gather_and_dump_neighbors(results, query_result_file_path,
comm);

return 0;
}
Loading

0 comments on commit 1f134f6

Please sign in to comment.