GCC Code Coverage Report


Directory: src/
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 50.0% 1 / 0 / 2
Functions: 50.0% 1 / 0 / 2
Branches: 34.6% 9 / 0 / 26

other/m_sparsemat.f90
Line Branch Exec Source
1 !> @brief Module for sparse matrix operations
2 module m_sparsemat
3 use m_common, only: wp
4 implicit none
5
6 private
7 public :: SparseMat
8
9 !> @brief Type for a sparse matrix in Compressed Sparse Row (CSR) format
10 type SparseMat
11 !> @brief Number of rows
12 integer :: nr_rows
13
14 !> @brief Number of columns
15 integer :: nr_cols
16
17 !> @brief Number of non-zero elements
18 integer :: nr_nonzero
19
20 !> @brief Array indicating the start of each row in the non-zero elements
21 integer, allocatable :: row_starts_at_nz(:)
22
23 !> @brief Array of column indices for each non-zero element
24 integer, allocatable :: col_idx(:)
25
26 !> @brief Array of non-zero values
27 real(wp), allocatable :: values(:)
28
29 !> @brief Previous row index for insertion
30 integer, private :: row_prev
31
32 !> @brief Current index of the non-zero element being inserted
33 integer, private :: nonzero_curr
34
35 contains
36 procedure :: init => init_sparsemat
37 procedure :: insert => insert_sparsemat
38 procedure :: finalize => finalize_sparsemat
39 procedure :: get_dense => get_dense_sparsemat
40 procedure :: destroy => destroy_sparsemat
41 procedure :: copy => copy_sparsemat
42 procedure :: hcat => hcat_sparsemat
43 end type SparseMat
44
45 ! Module procedure interfaces for submodule
46 interface
47 !> @brief Initialize a sparse matrix with the given number of rows, columns, and non-zero elements
48 !>
49 !> @param[inout] this The sparse matrix object to initialize
50 !> @param[in] nr_rows The number of rows in the sparse matrix
51 !> @param[in] nr_cols The number of columns in the sparse matrix
52 !> @param[in] nr_nonzero The number of non-zero elements in the sparse matrix
53 module subroutine init_sparsemat(this, nr_rows, nr_cols, nr_nonzero)
54 class(SparseMat), intent(inout) :: this
55 integer, intent(in) :: nr_rows, nr_cols, nr_nonzero
56 end subroutine
57
58 !> @brief Insert a value into the sparse matrix
59 !>
60 !> Values must be inserted in increasing order of rows. Within a row, values can be inserted in any order.
61 !>
62 !> @param[inout] this The sparse matrix object
63 !> @param[in] row The row index (0-based)
64 !> @param[in] col The column index (0-based)
65 !> @param[in] val The value to insert
66 module subroutine insert_sparsemat(this, row, col, val)
67 class(SparseMat), intent(inout) :: this
68 integer, intent(in) :: row, col
69 real(wp), intent(in) :: val
70 end subroutine
71
72 !> @brief Finalize the sparse matrix assembly
73 !>
74 !> @param[inout] this The sparse matrix object to finalize
75 module subroutine finalize_sparsemat(this)
76 class(SparseMat), intent(inout) :: this
77 end subroutine
78
79 !> @brief Convert the sparse matrix to a dense matrix
80 !>
81 !> @param[in] this The sparse matrix object
82 !> @param[out] dense_mat The output dense matrix
83 module subroutine get_dense_sparsemat(this, dense_mat)
84 class(SparseMat), intent(in) :: this
85 real(wp), intent(out) :: dense_mat(0:, 0:)
86 end subroutine
87
88 !> @brief Create a copy of the sparse matrix
89 !>
90 !> @param[out] out The copied sparse matrix object
91 !> @param[in] in The sparse matrix object to copy
92 module subroutine copy_sparsemat(out, in)
93 class(SparseMat), intent(out) :: out
94 type(SparseMat), intent(in) :: in
95 end subroutine
96
97 !> @brief Horizontally concatenate two sparse matrices
98 !>
99 !> @param[out] out The resulting concatenated sparse matrix
100 !> @param[in] A The first sparse matrix
101 !> @param[in] B The second sparse matrix
102 module subroutine hcat_sparsemat(out, A, B)
103 class(SparseMat), intent(out) :: out
104 type(SparseMat), intent(in) :: A, B
105 end subroutine
106
107 !> @brief Destroy the sparse matrix object
108 !>
109 !> @param[inout] this The sparse matrix object to destroy
110 module subroutine destroy_sparsemat(this)
111 class(SparseMat), intent(inout) :: this
112 end subroutine
113 end interface
114
115
9/26
__m_sparsemat_MOD___copy_m_sparsemat_Sparsemat:
✗ Branch 2 → 3 not taken.
✗ Branch 2 → 12 not taken.
✗ Branch 3 → 4 not taken.
✗ Branch 3 → 5 not taken.
✗ Branch 6 → 7 not taken.
✗ Branch 6 → 8 not taken.
✗ Branch 9 → 10 not taken.
✗ Branch 9 → 11 not taken.
__m_sparsemat_MOD___final_m_sparsemat_Sparsemat:
✗ Branch 3 → 4 not taken.
✓ Branch 3 → 7 taken 2 times.
✗ Branch 4 → 5 not taken.
✗ Branch 4 → 6 not taken.
✓ Branch 8 → 9 taken 2 times.
✓ Branch 8 → 23 taken 2 times.
✗ Branch 10 → 11 not taken.
✓ Branch 10 → 12 taken 2 times.
✓ Branch 12 → 13 taken 2 times.
✗ Branch 12 → 18 not taken.
✗ Branch 13 → 14 not taken.
✓ Branch 13 → 15 taken 2 times.
✗ Branch 15 → 16 not taken.
✓ Branch 15 → 17 taken 2 times.
✓ Branch 18 → 19 taken 2 times.
✗ Branch 18 → 22 not taken.
✗ Branch 19 → 20 not taken.
✓ Branch 19 → 21 taken 2 times.
6 end module m_sparsemat
116