Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an expression for normalize() #1330

Merged
merged 2 commits into from
Dec 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions gtsam/slam/expressions.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ inline Line3_ transformTo(const Pose3_ &wTc, const Line3_ &wL) {
return Line3_(f, wTc, wL);
}

inline Point3_ normalize(const Point3_& a){
Point3 (*f)(const Point3 &, OptionalJacobian<3, 3>) = &normalize;
return Point3_(f, a);
}

inline Point3_ cross(const Point3_& a, const Point3_& b) {
Point3 (*f)(const Point3 &, const Point3 &,
OptionalJacobian<3, 3>, OptionalJacobian<3, 3>) = &cross;
Expand Down
13 changes: 13 additions & 0 deletions tests/testExpressionFactor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -731,6 +731,19 @@ TEST(ExpressionFactor, variadicTemplate) {
EXPECT_CORRECT_FACTOR_JACOBIANS(f, values, 1e-8, 1e-5);
}

TEST(ExpressionFactor, normalize) {
auto model = noiseModel::Isotropic::Sigma(3, 1);

// Create expression
const auto x = Vector3_(1);
Vector3_ f_expr = normalize(x);

// Check derivatives
Values values;
values.insert(1, Vector3(1, 2, 3));
ExpressionFactor<Vector3> factor(model, Vector3(1.0/sqrt(14), 2.0/sqrt(14), 3.0/sqrt(14)), f_expr);
EXPECT_CORRECT_FACTOR_JACOBIANS(factor, values, 1e-5, 1e-5);
}

TEST(ExpressionFactor, crossProduct) {
auto model = noiseModel::Isotropic::Sigma(3, 1);
Expand Down