1#ifndef LP_METRIC_IMPL_H
2#define LP_METRIC_IMPL_H
15template <
int P,
bool TTakeRoot>
18 static_assert(P >= 1,
"LpMetric needs P >= 1");
20 if (v1.size() != v2.size())
22 throw std::invalid_argument(
"LpMetric: the vectors have sizes " +
23 std::to_string(v1.size()) +
" and " +
24 std::to_string(v2.size()));
27 const auto diff = (v1 - v2).cwiseAbs();
33 else if constexpr (P == 2)
35 const auto sqr_norm = diff.squaredNorm();
36 return TTakeRoot ? std::sqrt(sqr_norm) : sqr_norm;
41 return TTakeRoot ? std::pow(
sum, 1.0 / P) :
sum;
45template <
int P,
bool TTakeRoot>
47 const std::vector<real_t> &v2)
49 using map_type = Eigen::Map<const DynVec<real_t>>;
51 DynVec<real_t>(map_type(v2.data(),
static_cast<Eigen::Index
>(v2.size()))));
54template <
int P,
bool TTakeRoot>
static real_t tolerance_value
Definition lp_metric.h:21
real_t operator()(const DynVec< real_t > &v1, const DynVec< real_t > &v2) const
Overload operator().
Definition lp_metric_impl.h:55
static real_t evaluate(const DynVec< real_t > &v1, const DynVec< real_t > &v2)
evaluate
Definition lp_metric_impl.h:16
Definition lp_metric.h:10
std::iterator_traits< IteratorType >::value_type sum(IteratorType begin, IteratorType end, bool parallel=true)
Definition vector_math.h:89
Various utilities used when working with RL problems.
Definition bitrl_log.h:25
double real_t
real_t
Definition bitsim_types.h:20
Eigen::RowVectorX< T > DynVec
Dynamically sized row vector.
Definition bitsim_types.h:101