GCC Code Coverage Report


Directory: ./
File: Converters/Gauss.cpp
Date: 2022-10-15 05:10:18
Warnings: 1 unchecked decisions!
Exec Total Coverage
Lines: 32 42 76.2%
Functions: 8 9 88.9%
Branches: 40 72 55.6%
Decisions: 23 30 76.7%

Line Branch Decision Exec Source
1 // Copyright 2019-2022 Cambridge Quantum Computing
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 #include "Gauss.hpp"
16
17 namespace tket {
18
19 1312 void CXMaker::row_add(unsigned r0, unsigned r1) {
20
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1312 times.
1/2
✗ Decision 'true' not taken.
✓ Decision 'false' taken 1312 times.
1312 if (_reverse_cx_dirs)
21 _circ.add_op<unsigned>(OpType::CX, {r1, r0});
22 else
23
2/4
✓ Branch 3 taken 1312 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 1312 times.
✗ Branch 7 not taken.
1312 _circ.add_op<unsigned>(OpType::CX, {r0, r1});
24 1312 }
25
26 4755 void DiagMatrix::row_add(unsigned r0, unsigned r1) {
27
2/2
✓ Branch 2 taken 52843 times.
✓ Branch 3 taken 4755 times.
2/2
✓ Decision 'true' taken 52843 times.
✓ Decision 'false' taken 4755 times.
57598 for (unsigned i = 0; i < _matrix.row(r0).size(); ++i) {
28
3/6
✓ Branch 2 taken 52843 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 52843 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 52843 times.
✗ Branch 9 not taken.
52843 _matrix.row(r1)[i] ^= _matrix.row(r0)[i];
29 }
30 4755 }
31
32 1089 void DiagMatrix::col_add(unsigned c0, unsigned c1) {
33
2/2
✓ Branch 2 taken 9395 times.
✓ Branch 3 taken 1089 times.
2/2
✓ Decision 'true' taken 9395 times.
✓ Decision 'false' taken 1089 times.
10484 for (unsigned i = 0; i < _matrix.col(c0).size(); ++i) {
34
3/6
✓ Branch 2 taken 9395 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 9395 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 9395 times.
✗ Branch 9 not taken.
9395 _matrix.col(c1)[i] ^= _matrix.col(c0)[i];
35 }
36 1089 }
37
38 265 void DiagMatrix::gauss(CXMaker& cxmaker, unsigned blocksize) {
39 std::vector<std::pair<unsigned, unsigned>> row_ops =
40
1/2
✓ Branch 1 taken 265 times.
✗ Branch 2 not taken.
265 gaussian_elimination_row_ops(_matrix, blocksize);
41
2/2
✓ Branch 5 taken 1312 times.
✓ Branch 6 taken 265 times.
2/2
✓ Decision 'true' taken 1312 times.
✓ Decision 'false' taken 265 times.
1577 for (std::pair<unsigned, unsigned> op : row_ops) {
42
1/2
✓ Branch 1 taken 1312 times.
✗ Branch 2 not taken.
1312 row_add(op.first, op.second);
43
1/2
✓ Branch 1 taken 1312 times.
✗ Branch 2 not taken.
1312 cxmaker.row_add(op.first, op.second);
44 }
45 265 }
46
47
1/2
✓ Branch 2 taken 80 times.
✗ Branch 3 not taken.
80 bool DiagMatrix::is_id() const { return _matrix.isIdentity(); }
48
49 682 bool DiagMatrix::is_id_until_columns(unsigned limit) const {
50 TKET_ASSERT(limit <= n_rows());
51
52
2/2
✓ Branch 1 taken 5280 times.
✓ Branch 2 taken 682 times.
2/2
✓ Decision 'true' taken 5280 times.
✓ Decision 'false' taken 682 times.
5962 for (unsigned i = 0; i < n_rows(); ++i) {
53
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 5280 times.
0/1
? Decision couldn't be analyzed.
5280 if (_matrix(i, i) == 0) return false;
54 }
55
56
2/2
✓ Branch 1 taken 5280 times.
✓ Branch 2 taken 682 times.
2/2
✓ Decision 'true' taken 5280 times.
✓ Decision 'false' taken 682 times.
5962 for (unsigned i = 0; i < n_rows(); ++i) {
57
2/2
✓ Branch 1 taken 50388 times.
✓ Branch 2 taken 5280 times.
2/2
✓ Decision 'true' taken 50388 times.
✓ Decision 'false' taken 5280 times.
55668 for (unsigned j = 0; j < n_cols(); ++j) {
58
4/6
✓ Branch 0 taken 22554 times.
✓ Branch 1 taken 27834 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 22554 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 50388 times.
2/2
✓ Decision 'true' taken 5962 times.
✓ Decision 'false' taken 44426 times.
50388 if ((i > j) && (_matrix(i, j) == 1)) return false;
59 }
60 }
61
62
2/2
✓ Branch 1 taken 5280 times.
✓ Branch 2 taken 682 times.
2/2
✓ Decision 'true' taken 5280 times.
✓ Decision 'false' taken 682 times.
5962 for (unsigned i = 0; i < n_rows(); ++i) {
63
2/2
✓ Branch 1 taken 50388 times.
✓ Branch 2 taken 5280 times.
2/2
✓ Decision 'true' taken 50388 times.
✓ Decision 'false' taken 5280 times.
55668 for (unsigned j = 0; j < n_cols(); ++j) {
64
2/2
✓ Branch 0 taken 22554 times.
✓ Branch 1 taken 27834 times.
2/2
✓ Decision 'true' taken 22554 times.
✓ Decision 'false' taken 27834 times.
50388 if (j > limit) {
65
4/6
✓ Branch 0 taken 14596 times.
✓ Branch 1 taken 7958 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 14596 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 22554 times.
2/2
✓ Decision 'true' taken 682 times.
✓ Decision 'false' taken 21872 times.
22554 if ((i < j) && (_matrix(i, j) == 1)) return false;
66 }
67 }
68 }
69
70 682 return true;
71 }
72
73 21565 unsigned DiagMatrix::n_rows() const { return _matrix.rows(); }
74
75 111752 unsigned DiagMatrix::n_cols() const { return _matrix.cols(); }
76
77 std::ostream& operator<<(std::ostream& out, const DiagMatrix& diam) {
78 out << "give the DiagMatrix: " << std::endl;
79
0/2
✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
for (unsigned i = 0; i < diam._matrix.row(0).size(); ++i) {
80 out << " ";
81
0/2
✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
for (unsigned j = 0; j < diam._matrix.row(0).size(); ++j) {
82 out << diam._matrix.row(i)[j] << ", ";
83 }
84 out << std::endl;
85 }
86 out << std::endl;
87
88 return out;
89 }
90
91 } // namespace tket
92