Improve matrix logging

It now supports matrices with both storage orders and expressions
direclty in the LOG_MATRIX statement.

Change-Id: I07df0ff267e94a04b49ac8e2f17cc663006f4794
diff --git a/aos/common/logging/matrix_logging.h b/aos/common/logging/matrix_logging.h
index e763ed5..a915643 100644
--- a/aos/common/logging/matrix_logging.h
+++ b/aos/common/logging/matrix_logging.h
@@ -15,23 +15,30 @@
 
 // Logs the contents of a matrix and a constant string.
 // matrix must be an instance of an Eigen matrix (or something similar).
-#define LOG_MATRIX(level, message, matrix)                                   \
-  do {                                                                       \
-    static const ::std::string kAosLoggingMessage(                           \
-        LOG_SOURCENAME ": " STRINGIFY(__LINE__) ": " message);               \
-    ::aos::logging::DoLogMatrixTemplated(level, kAosLoggingMessage, matrix); \
-    /* so that GCC knows that it won't return */                             \
-    if (level == FATAL) {                                                    \
-      ::aos::Die("DoLogStruct(FATAL) fell through!!!!!\n");                  \
-    }                                                                        \
+#define LOG_MATRIX(level, message, matrix)                          \
+  do {                                                              \
+    static const ::std::string kAosLoggingMessage(                  \
+        LOG_SOURCENAME ": " STRINGIFY(__LINE__) ": " message);      \
+    ::aos::logging::DoLogMatrixTemplated(level, kAosLoggingMessage, \
+                                         (matrix).eval());          \
+    /* so that GCC knows that it won't return */                    \
+    if (level == FATAL) {                                           \
+      ::aos::Die("DoLogStruct(FATAL) fell through!!!!!\n");         \
+    }                                                               \
   } while (false)
 
 template <class T>
 void DoLogMatrixTemplated(log_level level, const ::std::string &message,
                           const T &matrix) {
-  static_assert(!T::IsRowMajor, "we only handle column-major storage");
-  internal::DoLogMatrix(level, message, TypeID<typename T::Scalar>::id,
-                        matrix.rows(), matrix.cols(), matrix.data(), 1);
+  if (T::IsRowMajor) {
+    typename T::Scalar data[matrix.rows() * matrix.cols()];
+    ::Eigen::Map<T>(data, matrix.rows(), matrix.cols()) = matrix;
+    internal::DoLogMatrix(level, message, TypeID<typename T::Scalar>::id,
+                          matrix.rows(), matrix.cols(), data, 1);
+  } else {
+    internal::DoLogMatrix(level, message, TypeID<typename T::Scalar>::id,
+                          matrix.rows(), matrix.cols(), matrix.data(), 1);
+  }
 }
 
 }  // namespace logging