diff --git a/gtsam/base/Matrix.cpp b/gtsam/base/Matrix.cpp index 213b6bdf1..1e5da7d86 100644 --- a/gtsam/base/Matrix.cpp +++ b/gtsam/base/Matrix.cpp @@ -339,7 +339,7 @@ weighted_eliminate(Matrix& A, Vector& b, const Vector& sigmas) { list > results; Vector pseudo(m); // allocate storage for pseudo-inverse - Vector weights = reciprocal(sigmas.array().square()); // calculate weights once + Vector weights = sigmas.array().square().inverse(); // calculate weights once // We loop over all columns, because the columns that can be eliminated // are not necessarily contiguous. For each one, estimate the corresponding diff --git a/gtsam/base/Vector.cpp b/gtsam/base/Vector.cpp index 205f48839..ce3f0a7b0 100644 --- a/gtsam/base/Vector.cpp +++ b/gtsam/base/Vector.cpp @@ -214,11 +214,6 @@ double norm_2(const Vector& v) { return v.norm(); } -/* ************************************************************************* */ -Vector reciprocal(const Vector &a) { - return a.array().inverse(); -} - /* ************************************************************************* */ Vector esqrt(const Vector& v) { return v.cwiseSqrt(); diff --git a/gtsam/base/Vector.h b/gtsam/base/Vector.h index 8b61e32f0..5bb732f5c 100644 --- a/gtsam/base/Vector.h +++ b/gtsam/base/Vector.h @@ -243,13 +243,6 @@ GTSAM_EXPORT double sum(const Vector &a); */ GTSAM_EXPORT double norm_2(const Vector& v); -/** - * Elementwise reciprocal of vector elements - * @param a vector - * @return [1/a(i)] - */ -GTSAM_EXPORT Vector reciprocal(const Vector &a); - /** * Elementwise sqrt of vector elements * @param v is a vector @@ -349,8 +342,10 @@ GTSAM_EXPORT Vector concatVectors(size_t nrVectors, ...); #ifdef GTSAM_ALLOW_DEPRECATED_SINCE_V4 GTSAM_EXPORT inline Vector emul(const Vector &a, const Vector &b) {assert (b.size()==a.size()); return a.cwiseProduct(b);} +GTSAM_EXPORT inline Vector reciprocal(const Vector &a) {return a.array().inverse();} #endif + } // namespace gtsam #include diff --git a/gtsam/base/tests/testVector.cpp b/gtsam/base/tests/testVector.cpp index 6ea1627a5..a2620ef0c 100644 --- a/gtsam/base/tests/testVector.cpp +++ b/gtsam/base/tests/testVector.cpp @@ -198,7 +198,7 @@ TEST(Vector, weightedPseudoinverse ) // create sigmas Vector sigmas(2); sigmas(0) = 0.1; sigmas(1) = 0.2; - Vector weights = reciprocal(sigmas.array().square()); + Vector weights = sigmas.array().square().inverse(); // perform solve Vector actual; double precision; @@ -224,7 +224,7 @@ TEST(Vector, weightedPseudoinverse_constraint ) // create sigmas Vector sigmas(2); sigmas(0) = 0.0; sigmas(1) = 0.2; - Vector weights = reciprocal(sigmas.array().square()); + Vector weights = sigmas.array().square().inverse(); // perform solve Vector actual; double precision; boost::tie(actual, precision) = weightedPseudoinverse(x, weights); @@ -243,7 +243,7 @@ TEST(Vector, weightedPseudoinverse_nan ) { Vector a = (Vector(4) << 1., 0., 0., 0.).finished(); Vector sigmas = (Vector(4) << 0.1, 0.1, 0., 0.).finished(); - Vector weights = reciprocal(sigmas.array().square()); + Vector weights = sigmas.array().square().inverse(); Vector pseudo; double precision; boost::tie(pseudo, precision) = weightedPseudoinverse(a, weights); @@ -306,7 +306,7 @@ TEST(Vector, greater_than ) TEST(Vector, reciprocal ) { Vector v = Vector3(1.0, 2.0, 4.0); - EXPECT(assert_equal(Vector3(1.0, 0.5, 0.25),reciprocal(v))); + EXPECT(assert_equal(Vector3(1.0, 0.5, 0.25), (Vector) v.array().inverse())); } /* ************************************************************************* */ diff --git a/gtsam/linear/NoiseModel.h b/gtsam/linear/NoiseModel.h index c76db1b55..2f229cb22 100644 --- a/gtsam/linear/NoiseModel.h +++ b/gtsam/linear/NoiseModel.h @@ -309,7 +309,7 @@ namespace gtsam { * i.e. the diagonal of the information matrix, i.e., weights */ static shared_ptr Precisions(const Vector& precisions, bool smart = true) { - return Variances(reciprocal(precisions), smart); + return Variances(precisions.array().inverse(), smart); } virtual void print(const std::string& name) const; @@ -443,10 +443,10 @@ namespace gtsam { * precisions, some of which might be inf */ static shared_ptr MixedPrecisions(const Vector& mu, const Vector& precisions) { - return MixedVariances(mu, reciprocal(precisions)); + return MixedVariances(mu, precisions.array().inverse()); } static shared_ptr MixedPrecisions(const Vector& precisions) { - return MixedVariances(reciprocal(precisions)); + return MixedVariances(precisions.array().inverse()); } /**