summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArnur Nigmetov <a.nigmetov@gmail.com>2018-05-19 20:33:33 +0200
committerArnur Nigmetov <a.nigmetov@gmail.com>2018-05-19 20:33:33 +0200
commit9693f140d91e751aabe46b76b89c332c7f307e17 (patch)
tree0fc707a72eabe7496e79de4ddd46e9c945e16bf3
parent75cf0745e95a37c8d65e7a283a11cd500ab6edc2 (diff)
Add inline qualifier to Wasserstein code.
To avoid linking problems.
-rw-r--r--geom_matching/wasserstein/include/basic_defs_ws.h28
-rw-r--r--geom_matching/wasserstein/include/basic_defs_ws.hpp18
-rw-r--r--geom_matching/wasserstein/include/diagonal_heap.h2
-rw-r--r--geom_matching/wasserstein/include/diagram_reader.h32
-rw-r--r--geom_matching/wasserstein/include/wasserstein.h10
-rw-r--r--geom_matching/wasserstein/include/wasserstein_pure_geom.hpp4
6 files changed, 46 insertions, 48 deletions
diff --git a/geom_matching/wasserstein/include/basic_defs_ws.h b/geom_matching/wasserstein/include/basic_defs_ws.h
index 58d6fd2..28f7452 100644
--- a/geom_matching/wasserstein/include/basic_defs_ws.h
+++ b/geom_matching/wasserstein/include/basic_defs_ws.h
@@ -60,19 +60,19 @@ namespace hera
{
template<class Real = double>
-bool is_infinity(const Real& x)
+inline bool is_infinity(const Real& x)
{
return x == Real(-1);
};
template<class Real = double>
-Real get_infinity()
+inline Real get_infinity()
{
return Real( -1 );
}
template<class Real = double>
-bool is_p_valid_norm(const Real& p)
+inline bool is_p_valid_norm(const Real& p)
{
return is_infinity<Real>(p) or p >= Real(1);
}
@@ -101,10 +101,8 @@ namespace ws
template<class Real = double>
using IdxValPair = std::pair<IdxType, Real>;
-
-
template<class R>
- std::ostream& operator<<(std::ostream& output, const IdxValPair<R> p)
+ inline std::ostream& operator<<(std::ostream& output, const IdxValPair<R> p)
{
output << fmt::format("({0}, {1})", p.first, p.second);
return output;
@@ -112,7 +110,7 @@ namespace ws
enum class OwnerType { k_none, k_normal, k_diagonal };
- std::ostream& operator<<(std::ostream& s, const OwnerType t)
+ inline std::ostream& operator<<(std::ostream& s, const OwnerType t)
{
switch(t)
{
@@ -210,11 +208,11 @@ namespace ws
#ifndef FOR_R_TDA
template <class Real = double>
- std::ostream& operator<<(std::ostream& output, const DiagramPoint<Real> p);
+ inline std::ostream& operator<<(std::ostream& output, const DiagramPoint<Real> p);
#endif
template<class Real>
- void format_arg(fmt::BasicFormatter<char> &f, const char *&format_str, const DiagramPoint<Real>&p) {
+ inline void format_arg(fmt::BasicFormatter<char> &f, const char *&format_str, const DiagramPoint<Real>&p) {
if (p.is_diagonal()) {
f.writer().write("({0},{1}, DIAG)", p.x, p.y);
} else {
@@ -269,14 +267,14 @@ namespace ws
};
template<class R, class Pt>
- R dist_lp(const Pt& a, const Pt& b, const R p, const int dim)
+ inline R dist_lp(const Pt& a, const Pt& b, const R p, const int dim)
{
return DistImpl<R, Pt>()(a, b, p, dim);
}
// TODO
template<class Real, typename DiagPointContainer>
- double getFurthestDistance3Approx(DiagPointContainer& A, DiagPointContainer& B, const Real p)
+ inline double getFurthestDistance3Approx(DiagPointContainer& A, DiagPointContainer& B, const Real p)
{
int dim = 2;
Real result { 0.0 };
@@ -297,7 +295,7 @@ namespace ws
}
template<class Real>
- Real getFurthestDistance3Approx_pg(const hera::ws::dnn::DynamicPointVector<Real>& A, const hera::ws::dnn::DynamicPointVector<Real>& B, const Real p, const int dim)
+ inline Real getFurthestDistance3Approx_pg(const hera::ws::dnn::DynamicPointVector<Real>& A, const hera::ws::dnn::DynamicPointVector<Real>& B, const Real p, const int dim)
{
Real result { 0.0 };
int opt_b_idx = 0;
@@ -317,13 +315,13 @@ namespace ws
template<class Container>
- std::string format_container_to_log(const Container& cont);
+ inline std::string format_container_to_log(const Container& cont);
template<class Real, class IndexContainer>
- std::string format_point_set_to_log(const IndexContainer& indices, const std::vector<DiagramPoint<Real>>& points);
+ inline std::string format_point_set_to_log(const IndexContainer& indices, const std::vector<DiagramPoint<Real>>& points);
template<class T>
- std::string format_int(T i);
+ inline std::string format_int(T i);
} // ws
} // hera
diff --git a/geom_matching/wasserstein/include/basic_defs_ws.hpp b/geom_matching/wasserstein/include/basic_defs_ws.hpp
index 1750b4e..a1153af 100644
--- a/geom_matching/wasserstein/include/basic_defs_ws.hpp
+++ b/geom_matching/wasserstein/include/basic_defs_ws.hpp
@@ -64,7 +64,7 @@ bool Point<Real>::operator!=(const Point<Real>& other) const
#ifndef FOR_R_TDA
template <class Real>
-std::ostream& operator<<(std::ostream& output, const Point<Real> p)
+inline std::ostream& operator<<(std::ostream& output, const Point<Real> p)
{
output << "(" << p.x << ", " << p.y << ")";
return output;
@@ -72,20 +72,20 @@ std::ostream& operator<<(std::ostream& output, const Point<Real> p)
#endif
template <class Real>
-Real sqr_dist(const Point<Real>& a, const Point<Real>& b)
+inline Real sqr_dist(const Point<Real>& a, const Point<Real>& b)
{
return (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y);
}
template <class Real>
-Real dist(const Point<Real>& a, const Point<Real>& b)
+inline Real dist(const Point<Real>& a, const Point<Real>& b)
{
return sqrt(sqr_dist(a, b));
}
template <class Real>
-Real DiagramPoint<Real>::persistence_lp(const Real p) const
+inline Real DiagramPoint<Real>::persistence_lp(const Real p) const
{
if (is_diagonal())
return 0.0;
@@ -100,7 +100,7 @@ Real DiagramPoint<Real>::persistence_lp(const Real p) const
#ifndef FOR_R_TDA
template <class Real>
-std::ostream& operator<<(std::ostream& output, const DiagramPoint<Real> p)
+inline std::ostream& operator<<(std::ostream& output, const DiagramPoint<Real> p)
{
if ( p.type == DiagramPoint<Real>::DIAG ) {
output << "(" << p.x << ", " << p.y << ", " << 0.5 * (p.x + p.y) << " DIAG )";
@@ -142,7 +142,7 @@ Real DiagramPoint<Real>::getRealY() const
}
template<class Container>
-std::string format_container_to_log(const Container& cont)
+inline std::string format_container_to_log(const Container& cont)
{
std::stringstream result;
result << "[";
@@ -157,7 +157,7 @@ std::string format_container_to_log(const Container& cont)
}
template<class Container>
-std::string format_pair_container_to_log(const Container& cont)
+inline std::string format_pair_container_to_log(const Container& cont)
{
std::stringstream result;
result << "[";
@@ -173,7 +173,7 @@ std::string format_pair_container_to_log(const Container& cont)
template<class Real, class IndexContainer>
-std::string format_point_set_to_log(const IndexContainer& indices,
+inline std::string format_point_set_to_log(const IndexContainer& indices,
const std::vector<DiagramPoint<Real>>& points)
{
std::stringstream result;
@@ -189,7 +189,7 @@ std::string format_point_set_to_log(const IndexContainer& indices,
}
template<class T>
-std::string format_int(T i)
+inline std::string format_int(T i)
{
std::stringstream ss;
ss.imbue(std::locale(""));
diff --git a/geom_matching/wasserstein/include/diagonal_heap.h b/geom_matching/wasserstein/include/diagonal_heap.h
index 9ffee70..3b3c8bc 100644
--- a/geom_matching/wasserstein/include/diagonal_heap.h
+++ b/geom_matching/wasserstein/include/diagonal_heap.h
@@ -129,7 +129,7 @@ using LossesHeapOld = IdxValHeap<Real, CompPairsBySecondLexStruct<Real>>;
#endif
template <class Real>
-std::string losses_heap_to_string(const LossesHeapOld<Real>& h)
+inline std::string losses_heap_to_string(const LossesHeapOld<Real>& h)
{
std::stringstream result;
result << "[";
diff --git a/geom_matching/wasserstein/include/diagram_reader.h b/geom_matching/wasserstein/include/diagram_reader.h
index 84bf49c..b52fcbd 100644
--- a/geom_matching/wasserstein/include/diagram_reader.h
+++ b/geom_matching/wasserstein/include/diagram_reader.h
@@ -55,31 +55,31 @@ namespace hera {
// cannot choose stod, stof or stold based on RealType,
// lazy solution: partial specialization
template<class RealType = double>
-RealType parse_real_from_str(const std::string& s);
+inline RealType parse_real_from_str(const std::string& s);
template <>
-double parse_real_from_str<double>(const std::string& s)
+inline double parse_real_from_str<double>(const std::string& s)
{
return std::stod(s);
}
template <>
-long double parse_real_from_str<long double>(const std::string& s)
+inline long double parse_real_from_str<long double>(const std::string& s)
{
return std::stold(s);
}
template <>
-float parse_real_from_str<float>(const std::string& s)
+inline float parse_real_from_str<float>(const std::string& s)
{
return std::stof(s);
}
template<class RealType>
-RealType parse_real_from_str(const std::string& s)
+inline RealType parse_real_from_str(const std::string& s)
{
static_assert(sizeof(RealType) != sizeof(RealType), "Must be specialized for each type you want to use, see above");
}
@@ -90,7 +90,7 @@ RealType parse_real_from_str(const std::string& s)
// decPrecision is the maximal decimal precision in the input,
// it is zero if all coordinates in the input are integers
template<class RealType = double, class ContType_ = std::vector<std::pair<RealType, RealType>>>
-bool read_diagram_point_set(const char* fname, ContType_& result, int& decPrecision)
+inline bool read_diagram_point_set(const char* fname, ContType_& result, int& decPrecision)
{
size_t lineNumber { 0 };
result.clear();
@@ -182,7 +182,7 @@ bool read_diagram_point_set(const char* fname, ContType_& result, int& decPrecis
// wrappers
template<class RealType = double, class ContType_ = std::vector<std::pair<RealType, RealType>>>
-bool read_diagram_point_set(const std::string& fname, ContType_& result, int& decPrecision)
+inline bool read_diagram_point_set(const std::string& fname, ContType_& result, int& decPrecision)
{
return read_diagram_point_set<RealType, ContType_>(fname.c_str(), result, decPrecision);
}
@@ -190,21 +190,21 @@ bool read_diagram_point_set(const std::string& fname, ContType_& result, int& de
// these two functions are now just wrappers for the previous ones,
// in case someone needs them; decPrecision is ignored
template<class RealType = double, class ContType_ = std::vector<std::pair<RealType, RealType>>>
-bool read_diagram_point_set(const char* fname, ContType_& result)
+inline bool read_diagram_point_set(const char* fname, ContType_& result)
{
int decPrecision;
return read_diagram_point_set<RealType, ContType_>(fname, result, decPrecision);
}
template<class RealType = double, class ContType_ = std::vector<std::pair<RealType, RealType>>>
-bool read_diagram_point_set(const std::string& fname, ContType_& result)
+inline bool read_diagram_point_set(const std::string& fname, ContType_& result)
{
int decPrecision;
return read_diagram_point_set<RealType, ContType_>(fname.c_str(), result, decPrecision);
}
template<class RealType = double, class ContType_ = std::vector<std::pair<RealType, RealType> > >
-bool read_diagram_dipha(const std::string& fname, unsigned int dim, ContType_& result)
+inline bool read_diagram_dipha(const std::string& fname, unsigned int dim, ContType_& result)
{
std::ifstream file;
file.open(fname, std::ios::in | std::ios::binary);
@@ -274,7 +274,7 @@ bool read_diagram_dipha(const std::string& fname, unsigned int dim, ContType_& r
template<class RealType, class ContType>
-void remove_duplicates(ContType& dgm_A, ContType& dgm_B)
+inline void remove_duplicates(ContType& dgm_A, ContType& dgm_B)
{
std::map<std::pair<RealType, RealType>, int> map_A, map_B;
// copy points to maps
@@ -328,7 +328,7 @@ void remove_duplicates(ContType& dgm_A, ContType& dgm_B)
#ifdef WASSERSTEIN_PURE_GEOM
template<class Real>
-int get_point_dimension(const std::string& line)
+inline int get_point_dimension(const std::string& line)
{
Real x;
int dim = 0;
@@ -341,7 +341,7 @@ int get_point_dimension(const std::string& line)
template<class RealType = double >
-bool read_point_cloud(const char* fname, hera::ws::dnn::DynamicPointVector<RealType>& result, int& dimension, int& decPrecision)
+inline bool read_point_cloud(const char* fname, hera::ws::dnn::DynamicPointVector<RealType>& result, int& dimension, int& decPrecision)
{
using DynamicPointTraitsR = typename hera::ws::dnn::DynamicPointTraits<RealType>;
@@ -423,20 +423,20 @@ bool read_point_cloud(const char* fname, hera::ws::dnn::DynamicPointVector<RealT
// wrappers
template<class RealType = double >
-bool read_point_cloud(const char* fname, hera::ws::dnn::DynamicPointVector<RealType>& result, int& dimension)
+inline bool read_point_cloud(const char* fname, hera::ws::dnn::DynamicPointVector<RealType>& result, int& dimension)
{
int dec_precision;
return read_point_cloud<RealType>(fname, result, dimension, dec_precision);
}
template<class RealType = double >
-bool read_point_cloud(std::string fname, hera::ws::dnn::DynamicPointVector<RealType>& result, int& dimension, int& dec_precision)
+inline bool read_point_cloud(std::string fname, hera::ws::dnn::DynamicPointVector<RealType>& result, int& dimension, int& dec_precision)
{
return read_point_cloud<RealType>(fname.c_str(), result, dimension, dec_precision);
}
template<class RealType = double >
-bool read_point_cloud(std::string fname, hera::ws::dnn::DynamicPointVector<RealType>& result, int& dimension)
+inline bool read_point_cloud(std::string fname, hera::ws::dnn::DynamicPointVector<RealType>& result, int& dimension)
{
return read_point_cloud<RealType>(fname.c_str(), result, dimension);
}
diff --git a/geom_matching/wasserstein/include/wasserstein.h b/geom_matching/wasserstein/include/wasserstein.h
index b90a545..2d0cffc 100644
--- a/geom_matching/wasserstein/include/wasserstein.h
+++ b/geom_matching/wasserstein/include/wasserstein.h
@@ -73,7 +73,7 @@ namespace ws
// compare as multisets
template<class PairContainer>
- bool are_equal(const PairContainer& dgm1, const PairContainer& dgm2)
+ inline bool are_equal(const PairContainer& dgm1, const PairContainer& dgm2)
{
if (dgm1.size() != dgm2.size()) {
return false;
@@ -97,7 +97,7 @@ namespace ws
// to handle points with one coordinate = infinity
template<class RealType>
- RealType get_one_dimensional_cost(std::vector<RealType>& set_A,
+ inline RealType get_one_dimensional_cost(std::vector<RealType>& set_A,
std::vector<RealType>& set_B,
const RealType wasserstein_power)
{
@@ -210,7 +210,7 @@ namespace ws
// this function assumes that all coordinates are finite
// points at infinity are processed in wasserstein_cost
template<class RealType>
- RealType wasserstein_cost_vec(const std::vector<DiagramPoint<RealType>>& A,
+ inline RealType wasserstein_cost_vec(const std::vector<DiagramPoint<RealType>>& A,
const std::vector<DiagramPoint<RealType>>& B,
const AuctionParams<RealType>& params,
const std::string& _log_filename_prefix)
@@ -245,7 +245,7 @@ namespace ws
template<class PairContainer>
-typename DiagramTraits<PairContainer>::RealType
+inline typename DiagramTraits<PairContainer>::RealType
wasserstein_cost(const PairContainer& A,
const PairContainer& B,
const AuctionParams< typename DiagramTraits<PairContainer>::RealType >& params,
@@ -332,7 +332,7 @@ wasserstein_cost(const PairContainer& A,
}
template<class PairContainer>
-typename DiagramTraits<PairContainer>::RealType
+inline typename DiagramTraits<PairContainer>::RealType
wasserstein_dist(PairContainer& A,
PairContainer& B,
const AuctionParams<typename DiagramTraits<PairContainer>::RealType> params,
diff --git a/geom_matching/wasserstein/include/wasserstein_pure_geom.hpp b/geom_matching/wasserstein/include/wasserstein_pure_geom.hpp
index 2a57599..13a94d5 100644
--- a/geom_matching/wasserstein/include/wasserstein_pure_geom.hpp
+++ b/geom_matching/wasserstein/include/wasserstein_pure_geom.hpp
@@ -30,7 +30,7 @@ namespace ws
using AuctionRunnerJacR = typename hera::ws::AuctionRunnerJac<Real, hera::ws::AuctionOracleKDTreePureGeom<Real>, hera::ws::dnn::DynamicPointVector<Real>>;
-double wasserstein_cost(const DynamicPointVector<double>& set_A, const DynamicPointVector<double>& set_B, const AuctionParams<double>& params)
+inline double wasserstein_cost(const DynamicPointVector<double>& set_A, const DynamicPointVector<double>& set_B, const AuctionParams<double>& params)
{
if (params.wasserstein_power < 1.0) {
throw std::runtime_error("Bad q in Wasserstein " + std::to_string(params.wasserstein_power));
@@ -75,7 +75,7 @@ double wasserstein_cost(const DynamicPointVector<double>& set_A, const DynamicPo
}
-double wasserstein_dist(const DynamicPointVector<double>& set_A, const DynamicPointVector<double>& set_B, const AuctionParams<double>& params)
+inline double wasserstein_dist(const DynamicPointVector<double>& set_A, const DynamicPointVector<double>& set_B, const AuctionParams<double>& params)
{
return std::pow(wasserstein_cost(set_A, set_B, params), 1.0 / params.wasserstein_power);
}