Templatizing the table made this painful.
This commit is contained in:
@@ -13,9 +13,10 @@
|
||||
|
||||
namespace core {
|
||||
namespace gnp {
|
||||
template<typename TableType>
|
||||
class TripleRangeDistanceSq {
|
||||
public:
|
||||
typedef core::table::Table::TreeType TreeType;
|
||||
typedef typename TableType::TreeType TreeType;
|
||||
|
||||
private:
|
||||
arma::mat min_distance_sq_;
|
||||
@@ -28,7 +29,7 @@ class TripleRangeDistanceSq {
|
||||
|
||||
private:
|
||||
|
||||
void ComputeNumTuples_(const core::table::Table &table_in) {
|
||||
void ComputeNumTuples_(const TableType &table_in) {
|
||||
if(nodes_[0] == nodes_[1]) {
|
||||
|
||||
// node_0 = node_1 = node_2
|
||||
@@ -125,12 +126,12 @@ class TripleRangeDistanceSq {
|
||||
|
||||
void ReplaceOneNodeBackward(
|
||||
const core::metric_kernels::AbstractMetric &metric_in,
|
||||
const core::table::Table &table_in,
|
||||
const TableType &table_in,
|
||||
TreeType *new_node_in,
|
||||
int node_index_in) {
|
||||
|
||||
nodes_[node_index_in] = new_node_in;
|
||||
const TreeType::BoundType &new_node_bound =
|
||||
const typename TreeType::BoundType &new_node_bound =
|
||||
table_in.get_node_bound(new_node_in);
|
||||
|
||||
for(int existing_node_index = node_index_in + 1;
|
||||
@@ -153,12 +154,12 @@ class TripleRangeDistanceSq {
|
||||
|
||||
void ReplaceOneNodeForward(
|
||||
const core::metric_kernels::AbstractMetric &metric_in,
|
||||
const core::table::Table &table_in,
|
||||
const TableType &table_in,
|
||||
TreeType *new_node_in,
|
||||
int node_index_in) {
|
||||
|
||||
nodes_[node_index_in] = new_node_in;
|
||||
const TreeType::BoundType &new_node_bound =
|
||||
const typename TreeType::BoundType &new_node_bound =
|
||||
table_in.get_node_bound(new_node_in);
|
||||
|
||||
for(int existing_node_index = 0; existing_node_index < node_index_in;
|
||||
@@ -181,16 +182,16 @@ class TripleRangeDistanceSq {
|
||||
|
||||
void Init(
|
||||
const core::metric_kernels::AbstractMetric &metric_in,
|
||||
const core::table::Table &table,
|
||||
const TableType &table,
|
||||
const std::vector< TreeType * > &nodes_in) {
|
||||
for(unsigned int j = 0; j < nodes_.size(); j++) {
|
||||
nodes_[j] = nodes_in[j];
|
||||
}
|
||||
for(unsigned int j = 0; j < nodes_.size(); j++) {
|
||||
const TreeType::BoundType &outer_bound =
|
||||
const typename TreeType::BoundType &outer_bound =
|
||||
table.get_node_bound(nodes_[j]);
|
||||
for(unsigned int i = j + 1; i < nodes_.size(); i++) {
|
||||
const TreeType::BoundType &inner_bound =
|
||||
const typename TreeType::BoundType &inner_bound =
|
||||
table.get_node_bound(nodes_[i]);
|
||||
core::math::Range range_distance_sq =
|
||||
outer_bound.RangeDistanceSq(metric_in, inner_bound);
|
||||
|
||||
@@ -44,7 +44,7 @@ class TripletreeDfs {
|
||||
bool NodeIsAgreeable_(TreeType *node, TreeType *next_node) const;
|
||||
|
||||
typename TableType::TreeIterator GetNextNodeIterator_(
|
||||
const core::gnp::TripleRangeDistanceSq &range_sq_in,
|
||||
const core::gnp::TripleRangeDistanceSq<TableType> &range_sq_in,
|
||||
int node_index,
|
||||
const typename TableType::TreeIterator &it_in);
|
||||
|
||||
@@ -52,7 +52,7 @@ class TripletreeDfs {
|
||||
|
||||
void RecursionHelper_(
|
||||
const core::metric_kernels::AbstractMetric &metric,
|
||||
core::gnp::TripleRangeDistanceSq &triple_range_distance_sq,
|
||||
core::gnp::TripleRangeDistanceSq<TableType> &triple_range_distance_sq,
|
||||
double relative_error,
|
||||
const std::vector<double> &failure_probabilities,
|
||||
typename ProblemType::ResultType *query_results,
|
||||
@@ -67,12 +67,12 @@ class TripletreeDfs {
|
||||
|
||||
void TripletreeBase_(
|
||||
const core::metric_kernels::AbstractMetric &metric,
|
||||
const core::gnp::TripleRangeDistanceSq &range_in,
|
||||
const core::gnp::TripleRangeDistanceSq<TableType> &range_in,
|
||||
ResultType *result);
|
||||
|
||||
bool CanProbabilisticSummarize_(
|
||||
const core::metric_kernels::AbstractMetric &metric,
|
||||
const core::gnp::TripleRangeDistanceSq &range_in,
|
||||
const core::gnp::TripleRangeDistanceSq<TableType> &range_in,
|
||||
const std::vector<double> &failure_probabilities,
|
||||
int node_start_index,
|
||||
typename ProblemType::DeltaType &delta,
|
||||
@@ -81,27 +81,27 @@ class TripletreeDfs {
|
||||
void ProbabilisticSummarize_(
|
||||
const core::metric_kernels::AbstractMetric &metric,
|
||||
GlobalType &global,
|
||||
const core::gnp::TripleRangeDistanceSq &range_in,
|
||||
const core::gnp::TripleRangeDistanceSq<TableType> &range_in,
|
||||
const std::vector<double> &failure_probabilities,
|
||||
int probabilistic_node_start_index,
|
||||
const typename ProblemType::DeltaType &delta,
|
||||
typename ProblemType::ResultType *query_results);
|
||||
|
||||
bool CanSummarize_(
|
||||
const core::gnp::TripleRangeDistanceSq &range_in,
|
||||
const core::gnp::TripleRangeDistanceSq<TableType> &range_in,
|
||||
const typename ProblemType::DeltaType &delta,
|
||||
typename ProblemType::ResultType *query_results,
|
||||
int *failure_index);
|
||||
|
||||
void Summarize_(
|
||||
const core::gnp::TripleRangeDistanceSq &range_in,
|
||||
const core::gnp::TripleRangeDistanceSq<TableType> &range_in,
|
||||
int probabilistic_start_node_index,
|
||||
const typename ProblemType::DeltaType &delta,
|
||||
typename ProblemType::ResultType *query_results);
|
||||
|
||||
bool TripletreeCanonical_(
|
||||
const core::metric_kernels::AbstractMetric &metric,
|
||||
core::gnp::TripleRangeDistanceSq &triple_range_distance_sq,
|
||||
core::gnp::TripleRangeDistanceSq<TableType> &triple_range_distance_sq,
|
||||
double relative_error,
|
||||
const std::vector<double> &failure_probabilities,
|
||||
typename ProblemType::ResultType *query_results);
|
||||
|
||||
@@ -59,7 +59,7 @@ void core::gnp::TripletreeDfs<ProblemType>::Compute(
|
||||
|
||||
// Call the algorithm computation.
|
||||
std::vector< TreeType *> root_nodes(3, table_->get_tree());
|
||||
core::gnp::TripleRangeDistanceSq triple_range_distance_sq;
|
||||
core::gnp::TripleRangeDistanceSq<TableType> triple_range_distance_sq;
|
||||
triple_range_distance_sq.Init(metric, *table_, root_nodes);
|
||||
|
||||
PreProcess_(table_->get_tree());
|
||||
@@ -107,7 +107,7 @@ void core::gnp::TripletreeDfs<ProblemType>::PreProcess_(
|
||||
template<typename ProblemType>
|
||||
typename core::gnp::TripletreeDfs<ProblemType>::TableType::TreeIterator
|
||||
core::gnp::TripletreeDfs<ProblemType>::GetNextNodeIterator_(
|
||||
const core::gnp::TripleRangeDistanceSq &range_sq_in,
|
||||
const core::gnp::TripleRangeDistanceSq<TableType> &range_sq_in,
|
||||
int node_index,
|
||||
const typename TableType::TreeIterator &it_in) {
|
||||
|
||||
@@ -122,7 +122,7 @@ core::gnp::TripletreeDfs<ProblemType>::GetNextNodeIterator_(
|
||||
template<typename ProblemType>
|
||||
void core::gnp::TripletreeDfs<ProblemType>::TripletreeBase_(
|
||||
const core::metric_kernels::AbstractMetric &metric,
|
||||
const core::gnp::TripleRangeDistanceSq &range_sq_in,
|
||||
const core::gnp::TripleRangeDistanceSq<TableType> &range_sq_in,
|
||||
typename ProblemType::ResultType *query_results) {
|
||||
|
||||
// Temporary postponed objects to be used within the triple loop.
|
||||
@@ -238,7 +238,7 @@ void core::gnp::TripletreeDfs<ProblemType>::TripletreeBase_(
|
||||
template<typename ProblemType>
|
||||
bool core::gnp::TripletreeDfs<ProblemType>::CanProbabilisticSummarize_(
|
||||
const core::metric_kernels::AbstractMetric &metric,
|
||||
const core::gnp::TripleRangeDistanceSq &range_in,
|
||||
const core::gnp::TripleRangeDistanceSq<TableType> &range_in,
|
||||
const std::vector<double> &failure_probabilities,
|
||||
int node_start_index,
|
||||
typename ProblemType::DeltaType &delta,
|
||||
@@ -261,7 +261,7 @@ bool core::gnp::TripletreeDfs<ProblemType>::CanProbabilisticSummarize_(
|
||||
table_->get_node_stat(node));
|
||||
|
||||
// Loop over each point on this node.
|
||||
typename core::table::Table::TreeIterator node_it =
|
||||
typename TableType::TreeIterator node_it =
|
||||
table_->get_node_iterator(node);
|
||||
|
||||
core::table::DenseConstPoint query_point;
|
||||
@@ -291,7 +291,7 @@ template<typename ProblemType>
|
||||
void core::gnp::TripletreeDfs<ProblemType>::ProbabilisticSummarize_(
|
||||
const core::metric_kernels::AbstractMetric &metric,
|
||||
GlobalType &global,
|
||||
const core::gnp::TripleRangeDistanceSq &range_in,
|
||||
const core::gnp::TripleRangeDistanceSq<TableType> &range_in,
|
||||
const std::vector<double> &failure_probabilities,
|
||||
int probabilistic_node_start_index,
|
||||
const typename ProblemType::DeltaType &delta,
|
||||
@@ -316,7 +316,7 @@ void core::gnp::TripletreeDfs<ProblemType>::ProbabilisticSummarize_(
|
||||
|
||||
template<typename ProblemType>
|
||||
bool core::gnp::TripletreeDfs<ProblemType>::CanSummarize_(
|
||||
const core::gnp::TripleRangeDistanceSq &triple_range_distance_sq_in,
|
||||
const core::gnp::TripleRangeDistanceSq<TableType> &triple_range_distance_sq_in,
|
||||
const typename ProblemType::DeltaType &delta,
|
||||
typename ProblemType::ResultType *query_results,
|
||||
int *failure_index) {
|
||||
@@ -374,7 +374,7 @@ void core::gnp::TripletreeDfs<ProblemType>::AllocateProbabilities_(
|
||||
|
||||
template<typename ProblemType>
|
||||
void core::gnp::TripletreeDfs<ProblemType>::Summarize_(
|
||||
const core::gnp::TripleRangeDistanceSq &triple_range_distance_sq,
|
||||
const core::gnp::TripleRangeDistanceSq<TableType> &triple_range_distance_sq,
|
||||
int probabilistic_node_start_index,
|
||||
const typename ProblemType::DeltaType &delta,
|
||||
typename ProblemType::ResultType *query_results) {
|
||||
@@ -404,7 +404,7 @@ bool core::gnp::TripletreeDfs<ProblemType>::NodeIsAgreeable_(
|
||||
template<typename ProblemType>
|
||||
void core::gnp::TripletreeDfs<ProblemType>::RecursionHelper_(
|
||||
const core::metric_kernels::AbstractMetric &metric,
|
||||
core::gnp::TripleRangeDistanceSq &triple_range_distance_sq,
|
||||
core::gnp::TripleRangeDistanceSq<TableType> &triple_range_distance_sq,
|
||||
double relative_error,
|
||||
const std::vector<double> &failure_probabilities,
|
||||
typename ProblemType::ResultType *query_results,
|
||||
@@ -568,7 +568,7 @@ void core::gnp::TripletreeDfs<ProblemType>::RecursionHelper_(
|
||||
template<typename ProblemType>
|
||||
bool core::gnp::TripletreeDfs<ProblemType>::TripletreeCanonical_(
|
||||
const core::metric_kernels::AbstractMetric &metric,
|
||||
core::gnp::TripleRangeDistanceSq &triple_range_distance_sq,
|
||||
core::gnp::TripleRangeDistanceSq<TableType> &triple_range_distance_sq,
|
||||
double relative_error,
|
||||
const std::vector<double> &failure_probabilities,
|
||||
typename ProblemType::ResultType *query_results) {
|
||||
|
||||
@@ -17,12 +17,14 @@
|
||||
|
||||
namespace core {
|
||||
namespace table {
|
||||
template<TreeSpecType>
|
||||
template<typename TreeSpecType>
|
||||
class Table: public boost::noncopyable {
|
||||
|
||||
public:
|
||||
typedef core::tree::GeneralBinarySpaceTree < TreeSpecType > TreeType;
|
||||
|
||||
typedef core::table::Table<TreeSpecType> TableType;
|
||||
|
||||
public:
|
||||
|
||||
class TreeIterator {
|
||||
@@ -33,7 +35,7 @@ class Table: public boost::noncopyable {
|
||||
|
||||
int current_index_;
|
||||
|
||||
const core::table::Table *table_;
|
||||
const TableType *table_;
|
||||
|
||||
public:
|
||||
|
||||
@@ -51,21 +53,21 @@ class Table: public boost::noncopyable {
|
||||
table_ = it_in.table();
|
||||
}
|
||||
|
||||
TreeIterator(const core::table::Table &table, const TreeType *node) {
|
||||
TreeIterator(const TableType &table, const TreeType *node) {
|
||||
table_ = &table;
|
||||
begin_ = node->begin();
|
||||
end_ = node->end();
|
||||
current_index_ = begin_ - 1;
|
||||
}
|
||||
|
||||
TreeIterator(const core::table::Table &table, int begin, int count) {
|
||||
TreeIterator(const TableType &table, int begin, int count) {
|
||||
table_ = &table;
|
||||
begin_ = begin;
|
||||
end_ = begin + count;
|
||||
current_index_ = begin_ - 1;
|
||||
}
|
||||
|
||||
const core::table::Table *table() const {
|
||||
const TableType *table() const {
|
||||
return table_;
|
||||
}
|
||||
|
||||
@@ -164,11 +166,11 @@ class Table: public boost::noncopyable {
|
||||
return TreeIterator(*this, begin, count);
|
||||
}
|
||||
|
||||
const TreeType::BoundType &get_node_bound(TreeType *node) const {
|
||||
const typename TreeType::BoundType &get_node_bound(TreeType *node) const {
|
||||
return node->bound();
|
||||
}
|
||||
|
||||
TreeType::BoundType &get_node_bound(TreeType *node) {
|
||||
typename TreeType::BoundType &get_node_bound(TreeType *node) {
|
||||
return node->bound();
|
||||
}
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
#define CORE_TREE_GEN_METRIC_TREE_H
|
||||
|
||||
#include <vector>
|
||||
#include "bounds.h"
|
||||
#include "ball_bound.h"
|
||||
#include "general_spacetree.h"
|
||||
#include "core/table/dense_matrix.h"
|
||||
#include "core/table/memory_mapped_file.h"
|
||||
|
||||
+10
-5
@@ -22,8 +22,9 @@ class AxilrodTeller {
|
||||
normalizing_constant_ = normalizing_constant_in;
|
||||
}
|
||||
|
||||
template<typename TableType>
|
||||
double minimum_negative_contribution(
|
||||
const core::gnp::TripleRangeDistanceSq &range_in) const {
|
||||
const core::gnp::TripleRangeDistanceSq<TableType> &range_in) const {
|
||||
|
||||
const arma::mat &min_distance_sq = range_in.min_distance_sq();
|
||||
const arma::mat &max_distance_sq = range_in.max_distance_sq();
|
||||
@@ -39,8 +40,9 @@ class AxilrodTeller {
|
||||
return numerator / denominator / normalizing_constant_;
|
||||
}
|
||||
|
||||
template<typename TableType>
|
||||
double maximum_negative_contribution(
|
||||
const core::gnp::TripleRangeDistanceSq &range_in) const {
|
||||
const core::gnp::TripleRangeDistanceSq<TableType> &range_in) const {
|
||||
|
||||
const arma::mat &min_distance_sq = range_in.min_distance_sq();
|
||||
const arma::mat &max_distance_sq = range_in.max_distance_sq();
|
||||
@@ -56,8 +58,9 @@ class AxilrodTeller {
|
||||
return numerator / denominator / normalizing_constant_;
|
||||
}
|
||||
|
||||
template<typename TableType>
|
||||
double minimum_positive_contribution(
|
||||
const core::gnp::TripleRangeDistanceSq &range_in) const {
|
||||
const core::gnp::TripleRangeDistanceSq<TableType> &range_in) const {
|
||||
|
||||
const arma::mat &min_distance_sq = range_in.min_distance_sq();
|
||||
const arma::mat &max_distance_sq = range_in.max_distance_sq();
|
||||
@@ -82,8 +85,9 @@ class AxilrodTeller {
|
||||
denominator / normalizing_constant_;
|
||||
}
|
||||
|
||||
template<typename TableType>
|
||||
double maximum_positive_contribution(
|
||||
const core::gnp::TripleRangeDistanceSq &range_in) const {
|
||||
const core::gnp::TripleRangeDistanceSq<TableType> &range_in) const {
|
||||
|
||||
const arma::mat &min_distance_sq = range_in.min_distance_sq();
|
||||
const arma::mat &max_distance_sq = range_in.max_distance_sq();
|
||||
@@ -108,8 +112,9 @@ class AxilrodTeller {
|
||||
denominator / normalizing_constant_;
|
||||
}
|
||||
|
||||
template<typename TableType>
|
||||
void RangeUnnormOnSq(
|
||||
const core::gnp::TripleRangeDistanceSq &range_in,
|
||||
const core::gnp::TripleRangeDistanceSq<TableType> &range_in,
|
||||
core::math::Range *negative_range,
|
||||
core::math::Range *positive_range) const {
|
||||
|
||||
|
||||
+7
-3
@@ -16,9 +16,13 @@
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
|
||||
// Tree type: hard-coded for a metric tree.
|
||||
typedef core::table::Table <
|
||||
core::tree::GenMetricTree<core::table::DensePoint> > TableType;
|
||||
|
||||
// Parse arguments for Nbody.
|
||||
physpack::nbody_simulator::NbodySimulatorArguments nbody_simulator_arguments;
|
||||
physpack::nbody_simulator::NbodySimulator::ParseArguments(
|
||||
physpack::nbody_simulator::NbodySimulatorArguments<TableType> nbody_simulator_arguments;
|
||||
physpack::nbody_simulator::NbodySimulator<TableType>::ParseArguments(
|
||||
argc, argv, &nbody_simulator_arguments);
|
||||
|
||||
if(nbody_simulator_arguments.table_->n_attributes() != 3) {
|
||||
@@ -29,7 +33,7 @@ int main(int argc, char *argv[]) {
|
||||
// Instantiate a Nbody object.
|
||||
core::util::Timer tree_build_timer;
|
||||
tree_build_timer.Start();
|
||||
physpack::nbody_simulator::NbodySimulator nbody_simulator_instance;
|
||||
physpack::nbody_simulator::NbodySimulator<TableType> nbody_simulator_instance;
|
||||
nbody_simulator_instance.Init(nbody_simulator_arguments);
|
||||
tree_build_timer.End();
|
||||
std::cout << tree_build_timer.GetTotalElapsedTime() << " seconds spent on "
|
||||
|
||||
+12
-9
@@ -15,11 +15,15 @@
|
||||
|
||||
namespace physpack {
|
||||
namespace nbody_simulator {
|
||||
template<typename IncomingTableType>
|
||||
class NbodySimulator {
|
||||
public:
|
||||
|
||||
typedef IncomingTableType TableType;
|
||||
|
||||
typedef physpack::nbody_simulator::NbodySimulatorPostponed PostponedType;
|
||||
|
||||
typedef physpack::nbody_simulator::NbodySimulatorGlobal GlobalType;
|
||||
typedef physpack::nbody_simulator::NbodySimulatorGlobal<TableType> GlobalType;
|
||||
|
||||
typedef physpack::nbody_simulator::NbodySimulatorResult ResultType;
|
||||
|
||||
@@ -29,14 +33,12 @@ class NbodySimulator {
|
||||
|
||||
typedef physpack::nbody_simulator::NbodySimulatorStatistic StatisticType;
|
||||
|
||||
typedef core::table::Table TableType;
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
* @brief returns a pointer to the table
|
||||
*/
|
||||
core::table::Table *table();
|
||||
TableType *table();
|
||||
|
||||
/**
|
||||
* @brief returns a GlobalType structure that has the
|
||||
@@ -47,24 +49,25 @@ class NbodySimulator {
|
||||
/**
|
||||
* @brief Initialize a nbody simulator engine with the arguments.
|
||||
*/
|
||||
void Init(physpack::nbody_simulator::NbodySimulatorArguments &arguments_in);
|
||||
void Init(
|
||||
physpack::nbody_simulator::NbodySimulatorArguments<TableType> &arguments_in);
|
||||
|
||||
void Compute(
|
||||
const physpack::nbody_simulator::NbodySimulatorArguments &arguments_in,
|
||||
const physpack::nbody_simulator::NbodySimulatorArguments<TableType> &arguments_in,
|
||||
ResultType *result_out);
|
||||
|
||||
static void ParseArguments(
|
||||
const std::vector<std::string> &args,
|
||||
physpack::nbody_simulator::NbodySimulatorArguments *arguments_out);
|
||||
physpack::nbody_simulator::NbodySimulatorArguments<TableType> *arguments_out);
|
||||
|
||||
static void ParseArguments(
|
||||
int argc,
|
||||
char *argv[],
|
||||
physpack::nbody_simulator::NbodySimulatorArguments *arguments_out);
|
||||
physpack::nbody_simulator::NbodySimulatorArguments<TableType> *arguments_out);
|
||||
|
||||
private:
|
||||
|
||||
core::table::Table *table_;
|
||||
TableType *table_;
|
||||
GlobalType global_;
|
||||
|
||||
private:
|
||||
|
||||
+2
-1
@@ -11,6 +11,7 @@
|
||||
|
||||
namespace physpack {
|
||||
namespace nbody_simulator {
|
||||
template<typename TableType>
|
||||
class NbodySimulatorArguments {
|
||||
public:
|
||||
|
||||
@@ -18,7 +19,7 @@ class NbodySimulatorArguments {
|
||||
|
||||
int leaf_size_;
|
||||
|
||||
core::table::Table *table_;
|
||||
TableType *table_;
|
||||
|
||||
double relative_error_;
|
||||
|
||||
|
||||
+22
-16
@@ -10,23 +10,25 @@
|
||||
#include "core/gnp/tripletree_dfs_dev.h"
|
||||
#include "nbody_simulator.h"
|
||||
|
||||
physpack::nbody_simulator::NbodySimulator::TableType *
|
||||
physpack::nbody_simulator::NbodySimulator::table() {
|
||||
template<typename TableType>
|
||||
TableType *physpack::nbody_simulator::NbodySimulator<TableType>::table() {
|
||||
return table_;
|
||||
}
|
||||
|
||||
physpack::nbody_simulator::NbodySimulator::GlobalType
|
||||
&physpack::nbody_simulator::NbodySimulator::global() {
|
||||
template<typename TableType>
|
||||
typename physpack::nbody_simulator::NbodySimulator<TableType>::GlobalType
|
||||
&physpack::nbody_simulator::NbodySimulator<TableType>::global() {
|
||||
return global_;
|
||||
}
|
||||
|
||||
void physpack::nbody_simulator::NbodySimulator::Compute(
|
||||
const physpack::nbody_simulator::NbodySimulatorArguments &arguments_in,
|
||||
template<typename TableType>
|
||||
void physpack::nbody_simulator::NbodySimulator<TableType>::Compute(
|
||||
const physpack::nbody_simulator::NbodySimulatorArguments<TableType> &arguments_in,
|
||||
physpack::nbody_simulator::NbodySimulatorResult *result_out) {
|
||||
|
||||
// Instantiate a dual-tree algorithm of the KDE.
|
||||
core::gnp::TripletreeDfs<physpack::nbody_simulator::NbodySimulator>
|
||||
tripletree_dfs;
|
||||
core::gnp::TripletreeDfs < physpack::nbody_simulator::NbodySimulator <
|
||||
TableType > > tripletree_dfs;
|
||||
tripletree_dfs.Init(*this);
|
||||
|
||||
// Compute the result.
|
||||
@@ -39,8 +41,9 @@ void physpack::nbody_simulator::NbodySimulator::Compute(
|
||||
tripletree_dfs.num_monte_carlo_prunes();
|
||||
}
|
||||
|
||||
void physpack::nbody_simulator::NbodySimulator::Init(
|
||||
physpack::nbody_simulator::NbodySimulatorArguments &arguments_in) {
|
||||
template<typename TableType>
|
||||
void physpack::nbody_simulator::NbodySimulator<TableType>::Init(
|
||||
physpack::nbody_simulator::NbodySimulatorArguments<TableType> &arguments_in) {
|
||||
|
||||
table_ = arguments_in.table_;
|
||||
|
||||
@@ -50,7 +53,8 @@ void physpack::nbody_simulator::NbodySimulator::Init(
|
||||
arguments_in.summary_compute_quantile_);
|
||||
}
|
||||
|
||||
bool physpack::nbody_simulator::NbodySimulator::ConstructBoostVariableMap_(
|
||||
template<typename TableType>
|
||||
bool physpack::nbody_simulator::NbodySimulator<TableType>::ConstructBoostVariableMap_(
|
||||
const std::vector<std::string> &args,
|
||||
boost::program_options::variables_map *vm) {
|
||||
|
||||
@@ -131,9 +135,10 @@ bool physpack::nbody_simulator::NbodySimulator::ConstructBoostVariableMap_(
|
||||
return false;
|
||||
}
|
||||
|
||||
void physpack::nbody_simulator::NbodySimulator::ParseArguments(
|
||||
template<typename TableType>
|
||||
void physpack::nbody_simulator::NbodySimulator<TableType>::ParseArguments(
|
||||
const std::vector<std::string> &args,
|
||||
physpack::nbody_simulator::NbodySimulatorArguments *arguments_out) {
|
||||
physpack::nbody_simulator::NbodySimulatorArguments<TableType> *arguments_out) {
|
||||
|
||||
// A L2 metric to index the table to use.
|
||||
arguments_out->metric_ = new core::metric_kernels::LMetric<2>();
|
||||
@@ -154,7 +159,7 @@ void physpack::nbody_simulator::NbodySimulator::ParseArguments(
|
||||
// Parse the reference set and index the tree.
|
||||
std::cout << "Reading in the reference set: " <<
|
||||
vm["references_in"].as<std::string>() << "\n";
|
||||
arguments_out->table_ = new core::table::Table();
|
||||
arguments_out->table_ = new TableType();
|
||||
arguments_out->table_->Init(vm["references_in"].as<std::string>());
|
||||
std::cout << "Finished reading in the reference set.\n";
|
||||
std::cout << "Building the reference tree.\n";
|
||||
@@ -177,10 +182,11 @@ void physpack::nbody_simulator::NbodySimulator::ParseArguments(
|
||||
arguments_out->summary_compute_quantile_ << "\n";
|
||||
}
|
||||
|
||||
void physpack::nbody_simulator::NbodySimulator::ParseArguments(
|
||||
template<typename TableType>
|
||||
void physpack::nbody_simulator::NbodySimulator<TableType>::ParseArguments(
|
||||
int argc,
|
||||
char *argv[],
|
||||
physpack::nbody_simulator::NbodySimulatorArguments *arguments_out) {
|
||||
physpack::nbody_simulator::NbodySimulatorArguments<TableType> *arguments_out) {
|
||||
|
||||
// Convert C input to C++; skip executable name for Boost.
|
||||
std::vector<std::string> args(argv + 1, argv + argc);
|
||||
|
||||
+27
-16
@@ -102,7 +102,7 @@ class NbodySimulatorDelta {
|
||||
if(i == 0 || node != nodes[i - 1]) {
|
||||
|
||||
// Get the iterator for the node.
|
||||
core::table::Table::TreeIterator node_it =
|
||||
typename GlobalType::TableType::TreeIterator node_it =
|
||||
global.table()->get_node_iterator(node);
|
||||
int qpoint_index;
|
||||
for(int j = 0; j < node_it.count(); j++) {
|
||||
@@ -136,7 +136,8 @@ class NbodySimulatorDelta {
|
||||
void DeterministicCompute(
|
||||
const core::metric_kernels::AbstractMetric &metric,
|
||||
const GlobalType &global,
|
||||
const core::gnp::TripleRangeDistanceSq &triple_range_distance_sq) {
|
||||
const core::gnp::TripleRangeDistanceSq <
|
||||
typename GlobalType::TableType > &triple_range_distance_sq) {
|
||||
|
||||
// Set the mean variance pair pointer.
|
||||
mean_variance_pair_ =
|
||||
@@ -211,7 +212,8 @@ class NbodySimulatorResult {
|
||||
template<typename GlobalType>
|
||||
void ApplyProbabilisticDelta(
|
||||
GlobalType &global,
|
||||
const core::gnp::TripleRangeDistanceSq &triple_range_distance_sq_in,
|
||||
const core::gnp::TripleRangeDistanceSq <
|
||||
typename GlobalType::TableType > &triple_range_distance_sq_in,
|
||||
const std::vector<double> &failure_probabilities,
|
||||
int probabilistic_node_start_index,
|
||||
const NbodySimulatorDelta &delta_in) {
|
||||
@@ -219,13 +221,13 @@ class NbodySimulatorResult {
|
||||
for(int node_index = probabilistic_node_start_index;
|
||||
node_index < 3; node_index++) {
|
||||
|
||||
core::table::Table::TreeType *node =
|
||||
typename GlobalType::TableType::TreeType *node =
|
||||
triple_range_distance_sq_in.node(node_index);
|
||||
if(node_index == 0 || node !=
|
||||
triple_range_distance_sq_in.node(node_index - 1)) {
|
||||
|
||||
// Get the iterator for the node.
|
||||
core::table::Table::TreeIterator node_it =
|
||||
typename GlobalType::TableType::TreeIterator node_it =
|
||||
global.table()->get_node_iterator(node);
|
||||
core::table::DenseConstPoint qpoint;
|
||||
int qpoint_index;
|
||||
@@ -271,15 +273,19 @@ class NbodySimulatorResult {
|
||||
}
|
||||
};
|
||||
|
||||
template<typename IncomingTableType>
|
||||
class NbodySimulatorGlobal {
|
||||
|
||||
public:
|
||||
typedef IncomingTableType TableType;
|
||||
|
||||
private:
|
||||
|
||||
double relative_error_;
|
||||
|
||||
double probability_;
|
||||
|
||||
core::table::Table *table_;
|
||||
TableType *table_;
|
||||
|
||||
physpack::nbody_simulator::AxilrodTeller potential_;
|
||||
|
||||
@@ -346,11 +352,11 @@ class NbodySimulatorGlobal {
|
||||
}
|
||||
}
|
||||
|
||||
core::table::Table *table() {
|
||||
TableType *table() {
|
||||
return table_;
|
||||
}
|
||||
|
||||
const core::table::Table *table() const {
|
||||
const TableType *table() const {
|
||||
return table_;
|
||||
}
|
||||
|
||||
@@ -367,7 +373,7 @@ class NbodySimulatorGlobal {
|
||||
}
|
||||
|
||||
void Init(
|
||||
core::table::Table *table_in,
|
||||
TableType *table_in,
|
||||
double relative_error_in,
|
||||
double probability_in,
|
||||
double summary_compute_quantile_in) {
|
||||
@@ -404,8 +410,9 @@ class NbodySimulatorSummary {
|
||||
used_error_ = 0;
|
||||
}
|
||||
|
||||
template<typename TableType>
|
||||
void ReplacePoints_(
|
||||
const core::table::Table &table,
|
||||
const TableType &table,
|
||||
const core::metric_kernels::AbstractMetric &metric_in,
|
||||
const std::vector<int> &random_combination,
|
||||
int node_index_fix,
|
||||
@@ -420,14 +427,15 @@ class NbodySimulatorSummary {
|
||||
}
|
||||
}
|
||||
|
||||
template<typename TableType>
|
||||
void TranslateCombination_(
|
||||
core::table::Table &table,
|
||||
const core::gnp::TripleRangeDistanceSq &range_sq_in,
|
||||
TableType &table,
|
||||
const core::gnp::TripleRangeDistanceSq<TableType> &range_sq_in,
|
||||
std::vector<int> *random_combination_out) const {
|
||||
|
||||
for(int node_index = 0; node_index < 3; node_index++) {
|
||||
int real_point_id;
|
||||
core::table::Table::TreeIterator node_it =
|
||||
typename TableType::TreeIterator node_it =
|
||||
table.get_node_iterator(range_sq_in.node(node_index));
|
||||
node_it.get_id(
|
||||
(*random_combination_out)[node_index] - node_it.begin(),
|
||||
@@ -436,8 +444,9 @@ class NbodySimulatorSummary {
|
||||
}
|
||||
}
|
||||
|
||||
template<typename TableType>
|
||||
void RandomCombination_(
|
||||
const core::gnp::TripleRangeDistanceSq &range_sq_in,
|
||||
const core::gnp::TripleRangeDistanceSq<TableType> &range_sq_in,
|
||||
int node_index_fix,
|
||||
std::vector<int> *random_combination_out) const {
|
||||
|
||||
@@ -539,7 +548,8 @@ class NbodySimulatorSummary {
|
||||
bool CanProbabilisticSummarize(
|
||||
const core::metric_kernels::AbstractMetric &metric,
|
||||
GlobalType &global, DeltaType &delta,
|
||||
const core::gnp::TripleRangeDistanceSq &range_sq_in,
|
||||
const core::gnp::TripleRangeDistanceSq <
|
||||
typename GlobalType::TableType > &range_sq_in,
|
||||
const std::vector<double> &failure_probabilities,
|
||||
int node_index,
|
||||
ResultType *query_results,
|
||||
@@ -651,7 +661,8 @@ class NbodySimulatorSummary {
|
||||
template < typename GlobalType, typename DeltaType, typename ResultType >
|
||||
bool CanSummarize(
|
||||
const GlobalType &global, const DeltaType &delta,
|
||||
const core::gnp::TripleRangeDistanceSq &triple_range_distance_sq_in,
|
||||
const core::gnp::TripleRangeDistanceSq <
|
||||
typename GlobalType::TableType > &triple_range_distance_sq_in,
|
||||
int node_index, ResultType *query_results) const {
|
||||
|
||||
double left_hand_side = delta.used_error_[node_index];
|
||||
|
||||
Reference in New Issue
Block a user