Skip to content

Commit cb6e2de

Browse files
committed
updated2
1 parent 937f276 commit cb6e2de

1 file changed

Lines changed: 38 additions & 0 deletions

File tree

src/sparse/stdlib_sparse_conversion.fypp

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,18 @@ module stdlib_sparse_conversion
8585
#:endfor
8686
end interface
8787
public :: csr2dense
88+
!! version: experimental
89+
!!
90+
!! Conversion from csc to dense
91+
!! Enables creating a dense 2D matrix from the non-zero values stored in a CSC format
92+
!! The dense matrix can be allocated on the fly if not pre-allocated by the user.
93+
!! [Specifications](../page/specs/stdlib_sparse.html#sparse_conversion)
94+
interface csc2dense
95+
#:for k1, t1, s1 in (KINDS_TYPES)
96+
module procedure :: csc2dense_${s1}$
97+
#:endfor
98+
end interface
99+
public :: csc2dense
88100

89101
!! version: experimental
90102
!!
@@ -317,6 +329,32 @@ contains
317329
end do
318330
end if
319331
end subroutine
332+
333+
#:endfor
334+
335+
#:for k1, t1, s1 in (KINDS_TYPES)
336+
subroutine csc2dense_${s1}$(CSC,dense)
337+
type(CSC_${s1}$_type), intent(in) :: CSC
338+
${t1}$, allocatable, intent(out) :: dense(:,:)
339+
integer(ilp) :: i, j
340+
341+
if(.not.allocated(dense)) allocate(dense(CSC%nrows,CSC%ncols),source=zero_${s1}$)
342+
if( CSC%storage == sparse_full) then
343+
do j = 1, CSC%ncols
344+
do i = CSC%colptr(j), CSC%colptr(j+1)-1
345+
dense(CSC%row(i),j) = CSC%data(i)
346+
end do
347+
end do
348+
else
349+
do j = 1, CSC%ncols
350+
do i = CSC%colptr(j), CSC%colptr(j+1)-1
351+
dense(CSC%row(i),j) = CSC%data(i)
352+
if( j == CSC%row(i) ) cycle
353+
dense(j,CSC%row(i)) = CSC%data(i)
354+
end do
355+
end do
356+
end if
357+
end subroutine
320358

321359
#:endfor
322360

0 commit comments

Comments
 (0)