Throw an exception when n=0 .

release/4.3a0
alexma3312 2020-09-28 20:52:31 -04:00
parent 2f322310cd
commit 49ba9a7990
2 changed files with 2 additions and 0 deletions

View File

@ -77,6 +77,7 @@ double dot(const Point3 &p, const Point3 &q, OptionalJacobian<1, 3> H1,
Point3Pair mean(const std::vector<Point3Pair> &abPointPairs) { Point3Pair mean(const std::vector<Point3Pair> &abPointPairs) {
const size_t n = abPointPairs.size(); const size_t n = abPointPairs.size();
if (n == 0) throw std::invalid_argument("input should have at least 1 pair of points");
Point3 aCentroid(0, 0, 0), bCentroid(0, 0, 0); Point3 aCentroid(0, 0, 0), bCentroid(0, 0, 0);
for (const Point3Pair &abPair : abPointPairs) { for (const Point3Pair &abPair : abPointPairs) {
aCentroid += abPair.first; aCentroid += abPair.first;

View File

@ -62,6 +62,7 @@ GTSAM_EXPORT double dot(const Point3& p, const Point3& q,
/// mean /// mean
template <class CONTAINER> template <class CONTAINER>
GTSAM_EXPORT Point3 mean(const CONTAINER& points) { GTSAM_EXPORT Point3 mean(const CONTAINER& points) {
if (points.size() == 0) throw std::invalid_argument("input should have at least 1 point");
Point3 sum(0, 0, 0); Point3 sum(0, 0, 0);
sum = std::accumulate(points.begin(), points.end(), sum); sum = std::accumulate(points.begin(), points.end(), sum);
return sum / points.size(); return sum / points.size();