Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //submatrix first version
- constexpr Matrix2 submatrix(const Matrix3& m, Matrix3::size_type row_, Matrix3::size_type column_) {
- assert(row_ < m.rows() && column_ < m.columns() && "invalid submatrix specification. row and column must be inside the input matrix.");
- using size_type = Matrix3::size_type;
- Matrix2 r;
- size_type i = 0;
- for (size_type k = 0; k < m.rows(); k++) {
- if (k == row_) {
- continue;
- }
- size_type j = 0;
- for (size_type l = 0; l < m.columns(); l++) {
- if (l == column_) {
- continue;
- }
- r(i, j) = m(k, l);
- j++;
- }
- i++;
- }
- return r;
- }
- TEST(Matrix, submatrixOf3x3is2x2) {
- const Matrix3 a{
- 1,5,0,
- -3,2,7,
- 0,6,-3
- };
- const Matrix2 truth{
- -3, 2,
- 0, 6
- };
- const auto b = submatrix(a, 0, 2);
- EXPECT_TRUE(b == truth);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement