Fix alignment issues with Jets.
1. Test that reproduces the failure on macos.
2. Move the alignment macros from manual_constructor.h
to macros.h and rename them to prevent conflicts.
3. The inline array used by FixedArray is now aligned.
4. Jet has been modified to be eigen friendly.
Change-Id: I4563847a767a92156dabab1ab420f0cdddb8ba77
diff --git a/include/ceres/jet.h b/include/ceres/jet.h
index e42abb5..50b5555 100644
--- a/include/ceres/jet.h
+++ b/include/ceres/jet.h
@@ -210,8 +210,20 @@
return *this;
}
- T a; // The scalar part.
+ // The infinitesimal part comes before the scalar part to ensure
+ // alignment. Jets get allocated as an array of type FixedArray
+ // which can allocate memory on the stack or on the heap depending
+ // upon the size of the array. We force the memory allocated on the
+ // stack to be 16 byte boundary aligned, but we also need to ensure
+ // that the elements of the struct are themselves aligned.
Eigen::Matrix<T, N, 1> v; // The infinitesimal part.
+ T a; // The scalar part.
+
+ // Needed to make sure that new instances of Jets are properly
+ // aligned. For more details see
+ //
+ // http://eigen.tuxfamily.org/dox/TopicStructHavingEigenMembers.html
+ EIGEN_MAKE_ALIGNED_OPERATOR_NEW
};
// Unary +