GCC Code Coverage Report


Directory: gridformat/
File: gridformat/common/matrix.hpp
Date: 2024-11-10 16:24:00
Exec Total Coverage
Lines: 16 16 100.0%
Functions: 15 15 100.0%
Branches: 5 6 83.3%

Line Branch Exec Source
1 // SPDX-FileCopyrightText: 2022-2023 Dennis Gläser <dennis.glaeser@iws.uni-stuttgart.de>
2 // SPDX-License-Identifier: MIT
3 /*!
4 * \file
5 * \ingroup Common
6 * \copydoc GridFormat::Matrix
7 */
8 #ifndef GRIDFORMAT_COMMON_MATRIX_HPP_
9 #define GRIDFORMAT_COMMON_MATRIX_HPP_
10
11 #include <array>
12 #include <ranges>
13 #include <utility>
14
15 #include <gridformat/common/concepts.hpp>
16 #include <gridformat/common/type_traits.hpp>
17
18 namespace GridFormat {
19
20
21 template<typename T, std::size_t rows, std::size_t cols>
22 class Matrix {
23 public:
24 template<Concepts::StaticallySizedMDRange<2> R>
25 6630 explicit Matrix(R&& entries) {
26 static_assert(static_size<R> == rows);
27 static_assert(static_size<std::ranges::range_value_t<R>> == cols);
28
29 6630 int i = 0;
30
1/2
✓ Branch 1 taken 3363 times.
✗ Branch 2 not taken.
24652 std::ranges::for_each(entries, [&] (const auto& sub_range) {
31 9217 std::ranges::copy(sub_range, _entries[i]);
32 9217 i++;
33 });
34 6630 }
35
36 6529 void transpose() {
37
2/2
✓ Branch 0 taken 9217 times.
✓ Branch 1 taken 3363 times.
24547 for (std::size_t row = 0; row < rows; ++row)
38
2/2
✓ Branch 0 taken 8345 times.
✓ Branch 1 taken 9217 times.
34467 for (std::size_t col = row+1; col < cols; ++col)
39 16449 std::swap(_entries[row][col], _entries[col][row]);
40 6529 }
41
42 235 Matrix& transposed() {
43 235 transpose();
44 235 return *this;
45 }
46
47 6529 auto begin() const { return std::ranges::begin(_entries); }
48 6529 auto end() const { return std::ranges::end(_entries); }
49
50 private:
51 T _entries[rows][cols];
52 };
53
54
55 template<Concepts::StaticallySizedMDRange<2> Range>
56 Matrix(Range&&) -> Matrix<
57 MDRangeValueType<Range>,
58 static_size<Range>,
59 static_size<std::ranges::range_value_t<Range>>
60 >;
61
62 } // namespace GridFormat
63
64 #endif // GRIDFORMAT_COMMON_MATRIX_HPP_
65