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 | #pragma once | |||
16 | ||||
17 | /** | |||
18 | * @file | |||
19 | * @brief Include this file rather than including the Eigen headers directly | |||
20 | */ | |||
21 | ||||
22 | #include "Utils/Json.hpp" | |||
23 | ||||
24 | #if !defined(_MSC_VER) | |||
25 | #pragma GCC diagnostic push | |||
26 | ||||
27 | #if defined(__clang__) | |||
28 | #if __has_warning("-Wdeprecated-copy") | |||
29 | #pragma GCC diagnostic ignored "-Wdeprecated-copy" | |||
30 | #endif | |||
31 | #elif __GNUC__ >= 11 | |||
32 | #pragma GCC diagnostic ignored "-Wmaybe-uninitialized" | |||
33 | #endif | |||
34 | #endif | |||
35 | ||||
36 | #include <Eigen/Dense> | |||
37 | #include <Eigen/SparseCore> | |||
38 | #include <unsupported/Eigen/KroneckerProduct> | |||
39 | #include <unsupported/Eigen/MatrixFunctions> | |||
40 | ||||
41 | #if !defined(_MSC_VER) | |||
42 | #pragma GCC diagnostic pop | |||
43 | #endif | |||
44 | ||||
45 | namespace Eigen { | |||
46 | ||||
47 | template <typename _Scalar, int _Rows, int _Cols> | |||
48 | 13 | void to_json(nlohmann::json& j, const Matrix<_Scalar, _Rows, _Cols>& matrix) { | ||
49 |
2/2✓ Branch 2 taken 38 times.
✓ Branch 3 taken 8 times.
|
2/2✓ Decision 'true' taken 38 times.
✓ Decision 'false' taken 8 times.
|
75 | for (Index i = 0; i < matrix.rows(); ++i) { |
50 |
1/2✓ Branch 1 taken 38 times.
✗ Branch 2 not taken.
|
62 | nlohmann::json row = nlohmann::json::array(); | |
51 |
2/2✓ Branch 1 taken 146 times.
✓ Branch 2 taken 38 times.
|
2/2✓ Decision 'true' taken 146 times.
✓ Decision 'false' taken 38 times.
|
314 | for (Index j = 0; j < matrix.cols(); ++j) { |
52 |
4/7✓ Branch 1 taken 146 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 100 times.
✓ Branch 5 taken 46 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 100 times.
✗ Branch 8 not taken.
|
252 | row.push_back(matrix(i, j)); | |
53 | } | |||
54 |
1/2✓ Branch 1 taken 38 times.
✗ Branch 2 not taken.
|
62 | j.push_back(row); | |
55 | } | |||
56 | 13 | } | ||
57 | ||||
58 | template <typename _Scalar, int _Rows, int _Cols> | |||
59 | 14 | void from_json(const nlohmann::json& j, Matrix<_Scalar, _Rows, _Cols>& matrix) { | ||
60 |
2/2✓ Branch 1 taken 36 times.
✓ Branch 2 taken 7 times.
|
2/2✓ Decision 'true' taken 36 times.
✓ Decision 'false' taken 7 times.
|
86 | for (size_t i = 0; i < j.size(); ++i) { |
61 | 72 | const auto& j_row = j.at(i); | ||
62 |
2/2✓ Branch 1 taken 142 times.
✓ Branch 2 taken 36 times.
|
2/2✓ Decision 'true' taken 142 times.
✓ Decision 'false' taken 36 times.
|
356 | for (size_t j = 0; j < j_row.size(); ++j) { |
63 | 284 | matrix(i, j) = | ||
64 | 284 | j_row.at(j).get<typename Matrix<_Scalar, _Rows, _Cols>::Scalar>(); | ||
65 | } | |||
66 | } | |||
67 | 14 | } | ||
68 | ||||
69 | } // namespace Eigen | |||
70 |