John Park | 33858a3 | 2018-09-28 23:05:48 -0700 | [diff] [blame] | 1 | #ifndef AOS_LOGGING_MATRIX_LOGGING_H_ |
| 2 | #define AOS_LOGGING_MATRIX_LOGGING_H_ |
Brian Silverman | fd5e2a3 | 2014-02-22 20:02:39 -0800 | [diff] [blame] | 3 | |
| 4 | #include <string> |
Brian Silverman | cb5da1f | 2015-12-05 22:19:58 -0500 | [diff] [blame] | 5 | #include <functional> |
Brian Silverman | fd5e2a3 | 2014-02-22 20:02:39 -0800 | [diff] [blame] | 6 | |
| 7 | #include "Eigen/Dense" |
| 8 | |
John Park | 33858a3 | 2018-09-28 23:05:48 -0700 | [diff] [blame] | 9 | #include "aos/logging/interface.h" |
| 10 | #include "aos/die.h" |
| 11 | #include "aos/queue_primitives.h" |
Brian Silverman | fd5e2a3 | 2014-02-22 20:02:39 -0800 | [diff] [blame] | 12 | |
| 13 | namespace aos { |
| 14 | namespace logging { |
| 15 | |
| 16 | // Logs the contents of a matrix and a constant string. |
| 17 | // matrix must be an instance of an Eigen matrix (or something similar). |
Austin Schuh | f257f3c | 2019-10-27 21:00:43 -0700 | [diff] [blame] | 18 | #define AOS_LOG_MATRIX(level, message, matrix) \ |
Brian Silverman | cda8666 | 2016-01-08 01:00:41 -0800 | [diff] [blame] | 19 | do { \ |
| 20 | static const ::std::string kAosLoggingMessage( \ |
| 21 | LOG_SOURCENAME ": " STRINGIFY(__LINE__) ": " message); \ |
| 22 | ::aos::logging::DoLogMatrixTemplated(level, kAosLoggingMessage, \ |
| 23 | (matrix).eval()); \ |
| 24 | /* so that GCC knows that it won't return */ \ |
| 25 | if (level == FATAL) { \ |
| 26 | ::aos::Die("DoLogStruct(FATAL) fell through!!!!!\n"); \ |
| 27 | } \ |
Brian Silverman | fd5e2a3 | 2014-02-22 20:02:39 -0800 | [diff] [blame] | 28 | } while (false) |
| 29 | |
| 30 | template <class T> |
Brian Silverman | cb5da1f | 2015-12-05 22:19:58 -0500 | [diff] [blame] | 31 | void DoLogMatrixTemplated(log_level level, const ::std::string &message, |
| 32 | const T &matrix) { |
Brian Silverman | cda8666 | 2016-01-08 01:00:41 -0800 | [diff] [blame] | 33 | if (T::IsRowMajor) { |
| 34 | typename T::Scalar data[matrix.rows() * matrix.cols()]; |
| 35 | ::Eigen::Map<T>(data, matrix.rows(), matrix.cols()) = matrix; |
| 36 | internal::DoLogMatrix(level, message, TypeID<typename T::Scalar>::id, |
| 37 | matrix.rows(), matrix.cols(), data, 1); |
| 38 | } else { |
| 39 | internal::DoLogMatrix(level, message, TypeID<typename T::Scalar>::id, |
| 40 | matrix.rows(), matrix.cols(), matrix.data(), 1); |
| 41 | } |
Brian Silverman | cb5da1f | 2015-12-05 22:19:58 -0500 | [diff] [blame] | 42 | } |
Brian Silverman | fd5e2a3 | 2014-02-22 20:02:39 -0800 | [diff] [blame] | 43 | |
| 44 | } // namespace logging |
| 45 | } // namespace aos |
| 46 | |
John Park | 33858a3 | 2018-09-28 23:05:48 -0700 | [diff] [blame] | 47 | #endif // AOS_LOGGING_MATRIX_LOGGING_H_ |