Skip to content

Commit

Permalink
(DNND) Minor internal update.
Browse files Browse the repository at this point in the history
  • Loading branch information
Keita Iwabuchi committed Jun 12, 2024
1 parent 02bd48b commit ec20f52
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 20 deletions.
26 changes: 13 additions & 13 deletions include/saltatlas/dnnd/detail/base_dnnd.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ struct data_core {
knn_index(allocator) {}

saltatlas::distance::id distance_id;
uint64_t rnd_seed;
uint64_t rnd_seed; // TODO: does not have to hold?
point_store_type pstore;
knn_index_type knn_index;
std::size_t index_k{0};
Expand Down Expand Up @@ -122,6 +122,7 @@ class base_dnnd {
/// \return A point partitioner instance.
point_partitioner get_point_partitioner() const {
const int size = m_comm.size();
// TODO: hash id?
return [size](const id_type& id) { return id % size; };
};

Expand Down Expand Up @@ -275,8 +276,8 @@ class base_dnnd {
protected:
/// \brief Initialize the internal data core instance.
/// \param data_core A data core instance.
void init_data_core(data_core_type& data_core,
const distance_function_type& distance_function) {
void set_data_core(data_core_type& data_core,
const distance_function_type& distance_function) {
if (m_data_core) {
m_comm.cerr0() << "Data core is already initialized." << std::endl;
MPI_Abort(MPI_COMM_WORLD, EXIT_FAILURE);
Expand All @@ -286,12 +287,12 @@ class base_dnnd {
m_distance_function = distance_function;
}

/// \brief init_data_core for using a pre-defined distance function.
/// \brief set_data_core for using a pre-defined distance function.
/// The data core argument must contain a valid distance function ID.
void init_data_core(data_core_type& data_core) {
init_data_core(data_core,
distance::distance_function<point_type, distance_type>(
data_core.distance_id));
void set_data_core(data_core_type& data_core) {
set_data_core(data_core,
distance::distance_function<point_type, distance_type>(
data_core.distance_id));
}

private:
Expand Down Expand Up @@ -323,11 +324,10 @@ class base_dnnd {
return ret;
}

data_core_type* m_data_core{nullptr};
ygm::comm& m_comm;
bool m_verbose{false};
ygm::ygm_ptr<self_type> m_self{this};
distance_function_type m_distance_function;
data_core_type* m_data_core{nullptr};
ygm::comm& m_comm;
bool m_verbose{false}; // TODO: make this changeable after construction
distance_function_type m_distance_function;
};

} // namespace saltatlas::dndetail
4 changes: 2 additions & 2 deletions include/saltatlas/dnnd/dnnd.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class dnnd : public dndetail::base_dnnd<Id, Point, Distance> {
const bool verbose = false)
: base_type(verbose, comm),
m_data_core(distance::convert_to_distance_id(distance_name), rnd_seed) {
base_type::init_data_core(m_data_core);
base_type::set_data_core(m_data_core);
}

/// \brief Constructor.
Expand All @@ -62,7 +62,7 @@ class dnnd : public dndetail::base_dnnd<Id, Point, Distance> {
const uint64_t rnd_seed = std::random_device{}(),
const bool verbose = false)
: base_type(verbose, comm), m_data_core(distance::id::custom, rnd_seed) {
base_type::init_data_core(m_data_core, distance_func);
base_type::set_data_core(m_data_core, distance_func);
}

private:
Expand Down
6 changes: 3 additions & 3 deletions include/saltatlas/dnnd/dnnd_pm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class dnnd_pm : public dndetail::base_dnnd<
const bool verbose = false)
: base_type(verbose, comm) {
priv_create(datastore_path, distance_name, rnd_seed);
base_type::init_data_core(*m_data_core);
base_type::set_data_core(*m_data_core);
comm.cf_barrier();
}

Expand All @@ -90,7 +90,7 @@ class dnnd_pm : public dndetail::base_dnnd<
const bool verbose = false)
: base_type(verbose, comm) {
priv_open(datastore_path);
base_type::init_data_core(*m_data_core);
base_type::set_data_core(*m_data_core);
comm.cf_barrier();
}

Expand All @@ -102,7 +102,7 @@ class dnnd_pm : public dndetail::base_dnnd<
ygm::comm& comm, const bool verbose = false)
: base_type(verbose, comm) {
priv_open_read_only(datastore_path);
base_type::init_data_core(*m_data_core);
base_type::set_data_core(*m_data_core);
comm.cf_barrier();
}

Expand Down
4 changes: 2 additions & 2 deletions include/saltatlas/dnnd/dnnd_simple.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class dnnd : public dndetail::base_dnnd<Id, Point, Distance> {
const bool verbose = false)
: base_type(verbose, comm), m_data_core(distance::id::custom, rnd_seed) {
m_data_core.distance_id = did;
base_type::init_data_core(m_data_core);
base_type::set_data_core(m_data_core);
}

/// \brief Constructor.
Expand All @@ -86,7 +86,7 @@ class dnnd : public dndetail::base_dnnd<Id, Point, Distance> {
const uint64_t rnd_seed = std::random_device{}(),
const bool verbose = false)
: base_type(verbose, comm), m_data_core(distance::id::custom, rnd_seed) {
base_type::init_data_core(m_data_core, distance_func);
base_type::set_data_core(m_data_core, distance_func);
}

/// \brief Add points to the internal point store.
Expand Down

0 comments on commit ec20f52

Please sign in to comment.