This repository has been archived by the owner on Mar 22, 2023. It is now read-only.
/
BlockDiagonalMatrixTests.cc
76 lines (63 loc) · 2.35 KB
/
BlockDiagonalMatrixTests.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
//
// Copyright (C) 2016 by the linalgwrap authors
//
// This file is part of linalgwrap.
//
// linalgwrap is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published
// by the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// linalgwrap is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with linalgwrap. If not, see <http://www.gnu.org/licenses/>.
//
#include <catch.hpp>
#include <linalgwrap/BlockDiagonalMatrix.hh>
#include <linalgwrap/LazyMatrixWrapper.hh>
#include <linalgwrap/SmallMatrix.hh>
#include <rapidcheck.h>
namespace linalgwrap {
namespace tests {
using namespace rc;
TEST_CASE("BlockDiagonalMatrix class", "[BlockDiagonalMatrix]") {
// Make sure that the program does not get aborted
AssertDbgEffect::set(ExceptionEffect::THROW);
typedef double scalar_type;
typedef SmallMatrix<scalar_type> stored_matrix_type;
typedef LazyMatrixWrapper<stored_matrix_type, stored_matrix_type>
lazy_matrix_type;
SECTION("Simple function test") {
stored_matrix_type stored{{1.0, 2.0}, {3.0, 4.0}};
lazy_matrix_type lazy{stored};
auto diag1 = make_block_diagonal(stored_matrix_type{stored},
stored_matrix_type{stored});
auto diag2 = make_block_diagonal(std::move(lazy), std::move(stored));
auto res = diag1 + diag2;
auto res2 = diag2 * diag1;
CHECK(diag1.n_rows() == 4u);
CHECK(diag2.n_rows() == 4u);
CHECK(res.n_rows() == 4u);
CHECK(diag1(0, 0) == 1.);
CHECK(diag1(0, 1) == 2.);
CHECK(diag1(2, 2) == 1.);
CHECK(diag1(2, 3) == 2.);
CHECK(diag1(1, 3) == 0.);
CHECK(diag2(0, 0) == 1.);
CHECK(diag2(0, 1) == 2.);
CHECK(diag2(2, 2) == 1.);
CHECK(diag2(2, 3) == 2.);
CHECK(diag2(1, 3) == 0.);
CHECK(res(2, 2) == 2.);
CHECK(res(0, 0) == 2.);
CHECK(res(1, 3) == 0.);
CHECK(res2(2, 2) == 7.);
CHECK(res2(2, 3) == 10.);
}
}
} // tests
} // linalgwrap