/*! \brief Three-by-three real number matrix.
* \note will replace the C-style real[3][3] "matrix"
*/
-using Matrix3x3 = BasicMatrix3x3<real>;
+using Matrix3x3 = BasicMatrix3x3<real>;
+//! Convenience alias for a matrix view
+using Matrix3x3Span = Matrix3x3::view_type;
+//! Convenience alias for a const matrix view
+using Matrix3x3ConstSpan = Matrix3x3::const_view_type;
//! Determinant of a 3x3 matrix
template <class ElementType>
+matrix(2, 0)*(matrix(0, 1)*matrix(1, 2)-matrix(1, 1)*matrix(0, 2)));
}
+//! Calculates the trace of a 3x3 matrix view
+constexpr real trace(Matrix3x3ConstSpan matrixView)
+{
+ return matrixView(0, 0) + matrixView(1, 1) + matrixView(2, 2);
+}
} // namespace gmx
#endif
EXPECT_EQ(determinant(mat), 24);
}
+TEST_F(MatrixTest, traceWorks)
+{
+ const Matrix3x3 mat = {{1.5, 9, 9, 9, 2.0, 9, 9, 9, 0.25}};
+ EXPECT_EQ(trace(mat), 3.75);
+}
+
} // namespace
} // namespace test